From 7c94f23189e46b3825e3c34eb2ebda0977825916 Mon Sep 17 00:00:00 2001 From: daleclack Date: Fri, 29 Jan 2021 11:18:01 +0800 Subject: [PATCH] Add gtk38 --- Gtk3/gtk38/.vscode/c_cpp_properties.json | 59 +++++++++++++++ Gtk3/gtk38/.vscode/launch.json | 29 ++++++++ Gtk3/gtk38/.vscode/settings.json | 4 + Gtk3/gtk38/.vscode/tasks.json | 81 ++++++++++++++++++++ Gtk3/gtk38/main.cpp | 54 ++++++++++++++ Gtk3/gtk38/res/InputBox.ui | 94 ++++++++++++++++++++++++ Gtk3/gtk38/res/InputBox.ui~ | 94 ++++++++++++++++++++++++ Gtk3/gtk38/res/window.ui | 61 +++++++++++++++ Gtk3/gtk38/res/window.ui~ | 62 ++++++++++++++++ 9 files changed, 538 insertions(+) create mode 100644 Gtk3/gtk38/.vscode/c_cpp_properties.json create mode 100644 Gtk3/gtk38/.vscode/launch.json create mode 100644 Gtk3/gtk38/.vscode/settings.json create mode 100644 Gtk3/gtk38/.vscode/tasks.json create mode 100644 Gtk3/gtk38/main.cpp create mode 100644 Gtk3/gtk38/res/InputBox.ui create mode 100644 Gtk3/gtk38/res/InputBox.ui~ create mode 100644 Gtk3/gtk38/res/window.ui create mode 100644 Gtk3/gtk38/res/window.ui~ diff --git a/Gtk3/gtk38/.vscode/c_cpp_properties.json b/Gtk3/gtk38/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..99fbbb6 --- /dev/null +++ b/Gtk3/gtk38/.vscode/c_cpp_properties.json @@ -0,0 +1,59 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + //For linux amd64 and linux on arm64,some include path may different + //Commet and uncomment these lines to compile on a specificed archtiecture + //Arm64 linux libs + /* + "/usr/lib/aarch64-linux-gnu/dbus-1.0/include/**", + "/usr/lib/aarch64-linux-gnu/glib-2.0/include", + */ + //amd64 linux libs(For ubuntu) + /* + "/usr/lib/x86_64-linux-gnu/dbus-1.0/include", + "/usr/lib/x86_64-linux-gnu/glib-2.0/include", + */ + //For debian and ubuntu,kali + /* + "/usr/include/gtk-3.0/gtk/**", + "/usr/include/uuid/**", + */ + //For manjaro(Arch linux) + "/usr/lib/dbus-1.0/include/**", + "/usr/lib/glib-2.0/include/**", + "/usr/include/lzo/**", + "/usr/include/cloudproviders/**", + "${workspaceFolder}/**", + "/usr/include/gtk-3.0/**", + "/usr/include/at-spi2-atk/2.0/**", + "/usr/include/at-spi-2.0/**", + "/usr/include/dbus-1.0/**", + "/usr/include/gio-unix-2.0/**", + "/usr/include/cairo/**", + "/usr/include/pango-1.0/**", + "/usr/include/fribidi/**", + "/usr/include/harfbuzz/**", + "/usr/include/atk-1.0/**", + "/usr/include/pixman-1/**", + "/usr/include/freetype2/**", + "/usr/include/libpng16/**", + "/usr/include/gdk-pixbuf-2.0/**", + "/usr/include/libmount/**", + "/usr/include/blkid/**", + "/usr/include/glib-2.0/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "gcc-arm64", + "compilerArgs": [ + "`pkg-config --cflags --libs gtk+-3.0`" + ], + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Gtk3/gtk38/.vscode/launch.json b/Gtk3/gtk38/.vscode/launch.json new file mode 100644 index 0000000..2a0197d --- /dev/null +++ b/Gtk3/gtk38/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // 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": "g++ - Build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/bin/gtk38", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: g++ build active file", + "miDebuggerPath": "/usr/bin/gdb" + } + ] +} diff --git a/Gtk3/gtk38/.vscode/settings.json b/Gtk3/gtk38/.vscode/settings.json new file mode 100644 index 0000000..0baae3a --- /dev/null +++ b/Gtk3/gtk38/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "C_Cpp.errorSquiggles": "Disabled", + "cmake.configureOnOpen": false +} \ No newline at end of file diff --git a/Gtk3/gtk38/.vscode/tasks.json b/Gtk3/gtk38/.vscode/tasks.json new file mode 100644 index 0000000..ae2bb18 --- /dev/null +++ b/Gtk3/gtk38/.vscode/tasks.json @@ -0,0 +1,81 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-g", + "*.cpp", + "-o", + "${fileDirname}/bin/gtk38", + "-pthread", + //For Arm64 linux + /* + "-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include", + "-I/usr/lib/aarch64-linux-gnu/glib-2.0/include", + */ + //For amd64 linux + /* + "-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include", + "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include", + */ + //Ubuntu and kali include paths + /* + "-I/usr/include/uuid", + */ + //Manjaro linux and Arch linux include args + + "-I/usr/lib/glib-2.0/include", + "-I/usr/lib/dbus-1.0/include", + "-I/usr/include/lzo", + "-I/usr/include/cloudproviders", + + "-I/usr/include/gtk-3.0", + "-I/usr/include/at-spi2-atk/2.0", + "-I/usr/include/at-spi-2.0", + "-I/usr/include/dbus-1.0", + "-I/usr/include/gio-unix-2.0", + "-I/usr/include/cairo", + "-I/usr/include/pango-1.0", + "-I/usr/include/fribidi", + "-I/usr/include/harfbuzz", + "-I/usr/include/atk-1.0", + "-I/usr/include/pixman-1", + "-I/usr/include/freetype2", + "-I/usr/include/libpng16", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-I/usr/include/glib-2.0", + //Manjaro linux lib args + "-lz", + + "-lgtk-3", + "-lgdk-3", + "-lpangocairo-1.0", + "-lpango-1.0", + "-lharfbuzz", + "-latk-1.0", + "-lcairo-gobject", + "-lcairo", + "-lgdk_pixbuf-2.0", + "-lgio-2.0", + "-lgobject-2.0", + "-lglib-2.0", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} diff --git a/Gtk3/gtk38/main.cpp b/Gtk3/gtk38/main.cpp new file mode 100644 index 0000000..44a4ce6 --- /dev/null +++ b/Gtk3/gtk38/main.cpp @@ -0,0 +1,54 @@ +#include + +void entry_activate(GtkWidget *widget,GtkDialog *dialog){ + gtk_dialog_response(dialog,GTK_RESPONSE_OK); +} + +double InputBox(void){ + //Get dialog and initalize + GtkBuilder *builder=gtk_builder_new_from_file("res/InputBox.ui"); + GObject *dialog=gtk_builder_get_object(builder,"inputbox"); + GObject *entry=gtk_builder_get_object(builder,"entrymax"); + g_signal_connect(entry,"activate",G_CALLBACK(entry_activate),dialog); + int res=gtk_dialog_run(GTK_DIALOG(dialog)); + //if clicked "OK" button,get text and change the text to a number + double maxinum; + if(res==GTK_RESPONSE_OK){ + const gchar *text; + text=gtk_entry_get_text(GTK_ENTRY(entry)); + maxinum=atof(text); + //g_print("OK\n"); + } + gtk_widget_destroy(GTK_WIDGET(dialog)); + return maxinum; +} + +void scale_change(GtkWidget *widget,GtkBuilder *builder){ + //Change the maxinum of the adjustment + double max=InputBox(); + GObject *adjust=gtk_builder_get_object(builder,"adjustment1"); + gtk_adjustment_set_upper(GTK_ADJUSTMENT(adjust),max); + //g_print("%d\n",max); +} + +static void gtkmain(GtkApplication *app,gpointer *user_data){ + //Main window + GtkBuilder *builder=gtk_builder_new_from_file("res/window.ui"); + GObject *window=gtk_builder_get_object(builder,"window"); + gtk_application_add_window(app,GTK_WINDOW(window)); + //"Change" button + GObject *btn_change=gtk_builder_get_object(builder,"btnchange"); + g_signal_connect(btn_change,"clicked",G_CALLBACK(scale_change),builder); + //"Exit" button + GObject *btn_exit=gtk_builder_get_object(builder,"btnexit"); + g_signal_connect_swapped(btn_exit,"clicked",G_CALLBACK(gtk_widget_destroy),window); + gtk_widget_show_all(GTK_WIDGET(window)); +} + +int main(int argc,char *argv[]){ + //Start a gtk application + GtkApplication *app; + app=gtk_application_new("com.github.daleclack.gtk38",G_APPLICATION_FLAGS_NONE); + g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL); + return g_application_run(G_APPLICATION(app),argc,argv); +} diff --git a/Gtk3/gtk38/res/InputBox.ui b/Gtk3/gtk38/res/InputBox.ui new file mode 100644 index 0000000..4e9a946 --- /dev/null +++ b/Gtk3/gtk38/res/InputBox.ui @@ -0,0 +1,94 @@ + + + + + + False + 300 + 200 + dialog + + + False + vertical + 2 + + + False + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + OK + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + + + False + True + 0 + + + + + True + False + Input maxinum + + + False + True + 2 + + + + + True + True + number + + + False + True + 2 + + + + + + button1 + button2 + + + diff --git a/Gtk3/gtk38/res/InputBox.ui~ b/Gtk3/gtk38/res/InputBox.ui~ new file mode 100644 index 0000000..cb1e636 --- /dev/null +++ b/Gtk3/gtk38/res/InputBox.ui~ @@ -0,0 +1,94 @@ + + + + + + False + 300 + 200 + dialog + + + False + vertical + 2 + + + False + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + OK + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + + + False + True + 0 + + + + + True + False + Input maxinum + + + False + True + 2 + + + + + True + True + number + + + False + True + 2 + + + + + + button1 + button2 + + + diff --git a/Gtk3/gtk38/res/window.ui b/Gtk3/gtk38/res/window.ui new file mode 100644 index 0000000..6ebfeea --- /dev/null +++ b/Gtk3/gtk38/res/window.ui @@ -0,0 +1,61 @@ + + + + + + 100 + 1 + 10 + + + False + 300 + 200 + + + True + False + vertical + + + True + True + adjustment1 + 1 + + + False + True + 0 + + + + + Change maxinum of scale + True + True + True + + + False + True + 1 + + + + + Exit + True + True + True + + + False + True + 2 + + + + + + diff --git a/Gtk3/gtk38/res/window.ui~ b/Gtk3/gtk38/res/window.ui~ new file mode 100644 index 0000000..8892051 --- /dev/null +++ b/Gtk3/gtk38/res/window.ui~ @@ -0,0 +1,62 @@ + + + + + + 100 + 1 + 10 + + + False + center-always + 300 + 200 + + + True + False + vertical + + + True + True + adjustment1 + 1 + + + False + True + 0 + + + + + Change maxinum of scale + True + True + True + + + False + True + 1 + + + + + Exit + True + True + True + + + False + True + 2 + + + + + +