From a609f89e5f7a53bd52e7b623b686184f0d87125b Mon Sep 17 00:00:00 2001 From: daleclack Date: Mon, 5 Jul 2021 20:26:13 +0800 Subject: [PATCH] Add gtk93 --- .../meson.build | 0 .../src/MyWin.cc | 0 .../src/MyWin.hh | 0 .../src/main.cc | 0 Gtkmm4/gtk93_fontdialog/meson.build | 26 +++++++++++++++ Gtkmm4/gtk93_fontdialog/src/MyWin.cc | 33 +++++++++++++++++++ Gtkmm4/gtk93_fontdialog/src/MyWin.hh | 15 +++++++++ Gtkmm4/gtk93_fontdialog/src/main.cc | 6 ++++ Gtkmm4/vscode_meson/launch.json | 28 ++++++++++++++++ Gtkmm4/vscode_meson/tasks.json | 13 ++++++++ 10 files changed, 121 insertions(+) rename Gtkmm3/{gtk91_fontdialog => gtk92_fontdialog}/meson.build (100%) rename Gtkmm3/{gtk91_fontdialog => gtk92_fontdialog}/src/MyWin.cc (100%) rename Gtkmm3/{gtk91_fontdialog => gtk92_fontdialog}/src/MyWin.hh (100%) rename Gtkmm3/{gtk91_fontdialog => gtk92_fontdialog}/src/main.cc (100%) create mode 100644 Gtkmm4/gtk93_fontdialog/meson.build create mode 100644 Gtkmm4/gtk93_fontdialog/src/MyWin.cc create mode 100644 Gtkmm4/gtk93_fontdialog/src/MyWin.hh create mode 100644 Gtkmm4/gtk93_fontdialog/src/main.cc create mode 100644 Gtkmm4/vscode_meson/launch.json create mode 100644 Gtkmm4/vscode_meson/tasks.json diff --git a/Gtkmm3/gtk91_fontdialog/meson.build b/Gtkmm3/gtk92_fontdialog/meson.build similarity index 100% rename from Gtkmm3/gtk91_fontdialog/meson.build rename to Gtkmm3/gtk92_fontdialog/meson.build diff --git a/Gtkmm3/gtk91_fontdialog/src/MyWin.cc b/Gtkmm3/gtk92_fontdialog/src/MyWin.cc similarity index 100% rename from Gtkmm3/gtk91_fontdialog/src/MyWin.cc rename to Gtkmm3/gtk92_fontdialog/src/MyWin.cc diff --git a/Gtkmm3/gtk91_fontdialog/src/MyWin.hh b/Gtkmm3/gtk92_fontdialog/src/MyWin.hh similarity index 100% rename from Gtkmm3/gtk91_fontdialog/src/MyWin.hh rename to Gtkmm3/gtk92_fontdialog/src/MyWin.hh diff --git a/Gtkmm3/gtk91_fontdialog/src/main.cc b/Gtkmm3/gtk92_fontdialog/src/main.cc similarity index 100% rename from Gtkmm3/gtk91_fontdialog/src/main.cc rename to Gtkmm3/gtk92_fontdialog/src/main.cc diff --git a/Gtkmm4/gtk93_fontdialog/meson.build b/Gtkmm4/gtk93_fontdialog/meson.build new file mode 100644 index 0000000..56289bc --- /dev/null +++ b/Gtkmm4/gtk93_fontdialog/meson.build @@ -0,0 +1,26 @@ +#A Simple Project Test +project('gtk93', 'cpp', + default_options : ['c_std=c17', 'cpp_std=c++17']) + +#Initalize variants +# gnome=import('gnome') + +#Compile Resource +# gresources = gnome.compile_resources( +# 'resources', 'res/gtk91.resource.xml', +# source_dir: 'res', +# c_name: 'resources' +# ) + +#The Gtkmm Library as a dependency +gtkdep = dependency('gtkmm-4.0') + +#Use Different Build Opinions in windows and Linux +if host_machine.system() == 'windows' + win=import('windows') + icon_res=win.compile_resources('icon.rc') + executable('gtk93', icon_res, 'src/main.cc', 'src/MyWin.cc', dependencies : gtkdep, + win_subsystem : 'windows') +else + executable('gtk93', 'src/main.cc', 'src/MyWin.cc', dependencies : gtkdep) +endif diff --git a/Gtkmm4/gtk93_fontdialog/src/MyWin.cc b/Gtkmm4/gtk93_fontdialog/src/MyWin.cc new file mode 100644 index 0000000..657493c --- /dev/null +++ b/Gtkmm4/gtk93_fontdialog/src/MyWin.cc @@ -0,0 +1,33 @@ +#include "MyWin.hh" +#include + +MyWin::MyWin() +:fontbtn("Sans 10"), +label1("Simple Text"), +main_box(Gtk::Orientation::VERTICAL,5) +{ + //Ininalize window + set_icon_name("org.gtk.daleclack"); + set_default_size(400,300); + set_title("Font Dialog"); + + //Add Button + fontbtn.set_use_font(); + fontbtn.signal_font_set().connect(sigc::mem_fun(*this,&MyWin::font_changed)); + main_box.append(label1); + main_box.append(fontbtn); + main_box.set_halign(Gtk::Align::CENTER); + main_box.set_valign(Gtk::Align::CENTER); + + //Add everything + set_child(main_box); + //show_all_children(); +} + +void MyWin::font_changed(){ + Pango::FontDescription descript(fontbtn.get_font()); + auto font=Pango::AttrFontDesc::create_attr_font_desc(descript); + Pango::AttrList list; + list.insert(font); + label1.set_attributes(list); +} diff --git a/Gtkmm4/gtk93_fontdialog/src/MyWin.hh b/Gtkmm4/gtk93_fontdialog/src/MyWin.hh new file mode 100644 index 0000000..f250ecf --- /dev/null +++ b/Gtkmm4/gtk93_fontdialog/src/MyWin.hh @@ -0,0 +1,15 @@ +#pragma once + +#include + +class MyWin : public Gtk::Window{ +public: + MyWin(); +private: + //Child Widgets + Gtk::FontButton fontbtn; + Gtk::Label label1; + Gtk::Box main_box; + //Signal Handlers + void font_changed(); +}; diff --git a/Gtkmm4/gtk93_fontdialog/src/main.cc b/Gtkmm4/gtk93_fontdialog/src/main.cc new file mode 100644 index 0000000..ed2d922 --- /dev/null +++ b/Gtkmm4/gtk93_fontdialog/src/main.cc @@ -0,0 +1,6 @@ +#include "MyWin.hh" + +int main(int argc,char **argv){ + auto app=Gtk::Application::create("org.gtk.daleclack"); + return app->make_window_and_run(argc,argv); +} diff --git a/Gtkmm4/vscode_meson/launch.json b/Gtkmm4/vscode_meson/launch.json new file mode 100644 index 0000000..c60d9d6 --- /dev/null +++ b/Gtkmm4/vscode_meson/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) 启动", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/builddir/gtk91", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "preLaunchTask": "Meson: Build target", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "为 gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/Gtkmm4/vscode_meson/tasks.json b/Gtkmm4/vscode_meson/tasks.json new file mode 100644 index 0000000..8e31391 --- /dev/null +++ b/Gtkmm4/vscode_meson/tasks.json @@ -0,0 +1,13 @@ +{ + "tasks": [ + { + "type": "meson", + "target": "gtk91", + "mode": "build", + "group": "build", + "problemMatcher": [], + "label": "Meson: Build target" + } + ], + "version": "2.0.0" +} \ No newline at end of file