Add gtk122

This commit is contained in:
daleclack 2022-01-29 14:57:49 +08:00
parent 6e196e06fe
commit ccde4afeec
7 changed files with 213 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -0,0 +1,58 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk122 VERSION 1.0.0)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
include(GlibCompileResourcesSupport)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
include_directories(.)
include_directories(..)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_DIRS})
#Compile Resource
#set(RESOURCE_LIST
#stack.ui)
#compile_gresources(RESOURCE_FILE
#XML_OUT
#TYPE EMBED_C
#RESOURCES ${RESOURCE_LIST}
#PREFIX "/org/gtk/daleclack"
#SOURCE_DIR ${PROJECT_SOURCE_DIR}/res)
# Add a custom target to the makefile. Now make builds our resource file.
# It depends on the output RESOURCE_FILE.
#add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
#For win32 platform,use rc resource and .ico icon
if(WIN32)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(app_WINRC ../icon.rc)
set_property(SOURCE ../icon.rc APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
)
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc src/MyPrefs.cc)
else()
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc src/MyPrefs.cc)
endif(WIN32)
#Add command to generate .gitignore
add_custom_command(TARGET ${PROJECT_NAME}
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
SET (CMAKE_EXTRA_CXX_FLAGS ${GTKMM3_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES} -lpthread)

View File

@ -0,0 +1,50 @@
#include "MyPrefs.hh"
MyPrefs::MyPrefs()
:main_box(Gtk::ORIENTATION_VERTICAL,10),
views_box(Gtk::ORIENTATION_HORIZONTAL,5),
btnbox(Gtk::ORIENTATION_HORIZONTAL,5)
{
//Initalize Window
set_title("Background Preferences");
set_default_size(800,450);
//Initalize Stores
folders_store = Gtk::ListStore::create(n_columns);
folders_view.set_model(folders_store);
images_store = Gtk::ListStore::create(n_columns);
images_view.set_model(images_store);
//Add Default Value for folders view
auto row = *(folders_store->append());
row[n_columns.m_col_name] = Glib::get_home_dir();
folders_view.append_column("Folders",n_columns.m_col_name);
//Default Value for imags view
row = *(images_store->append());
row[n_columns.m_col_name] = "Test";
images_view.append_column("Images",n_columns.m_col_name);
//Add Views
main_box.pack_start(views_box);
sw_folders.add(folders_view);
views_box.pack_start(sw_folders);
sw_images.add(images_view);
views_box.pack_start(sw_images);
//Add Control Buttons
main_box.pack_start(btnbox,Gtk::PACK_SHRINK);
//Add Main Box to window
const int margin_value = 15;
main_box.set_margin_top(margin_value);
main_box.set_margin_bottom(margin_value);
main_box.set_margin_start(margin_value);
main_box.set_margin_end(margin_value);
add(main_box);
show_all_children();
}
void MyPrefs::set_background(Gtk::Image *back){
background1 = back;
}

View File

@ -0,0 +1,34 @@
#pragma once
#include <gtkmm.h>
class MyPrefs : public Gtk::Window
{
public:
MyPrefs();
void set_background(Gtk::Image *back);
protected:
class ModelColumns : public Gtk::TreeModelColumnRecord
{
public:
ModelColumns()
{
add(m_col_name);
}
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
};
ModelColumns n_columns;
Glib::RefPtr<Gtk::ListStore> folders_store, images_store;
private:
// Widget for parent window
Gtk::Image *background1;
// Child Widgets
Gtk::TreeView folders_view, images_view;
Gtk::ScrolledWindow sw_folders, sw_images;
Gtk::Box main_box, views_box, btnbox;
Gtk::Button btnadd, btnremove;
};

View File

@ -0,0 +1,38 @@
#include "MyWin.hh"
#include "winpe.xpm"
MyWin::MyWin()
{
//Initalize Window
set_icon_name("org.gtk.daleclack");
set_default_size(1024,576);
set_title("Background Preferences Test");
//Add Background
auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
auto sized = pixbuf->scale_simple(1024,576,Gdk::INTERP_BILINEAR);
gtk_image_set_from_pixbuf(m_back.gobj(),sized->gobj());
pixbuf.reset();
sized.reset();
//Button for background
btnback.set_label("Change Background");
btnback.set_halign(Gtk::ALIGN_CENTER);
btnback.set_valign(Gtk::ALIGN_CENTER);
btnback.set_relief(Gtk::RELIEF_NONE);
m_overlay.add_overlay(btnback);
btnback.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnback_clicked));
//Add widgets
m_overlay.add(m_back);
add(m_overlay);
//Initalize MyPrefs
prefs_win.set_background(&m_back);
show_all_children();
}
void MyWin::btnback_clicked(){
prefs_win.show_all();
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <gtkmm.h>
#include "MyPrefs.hh"
class MyWin : public Gtk::Window
{
public:
MyWin();
private:
//Child Widgets
Gtk::Overlay m_overlay;
Gtk::Image m_back;
Gtk::Button btnback;
//Background Preferences
MyPrefs prefs_win;
//Signal Handlers
void btnback_clicked();
};

View File

@ -0,0 +1,8 @@
#include "MyWin.hh"
int main(int argc,char ** argv){
// Create application and run
auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack");
MyWin window;
return app->run(window);
}