Update gtk39

This commit is contained in:
daleclack 2021-02-01 11:31:55 +08:00
parent c43336b962
commit 4b58709814
7 changed files with 105 additions and 19 deletions

Binary file not shown.

View File

@ -0,0 +1 @@
glib-compile-resources gtk39.resource.xml --target=../src/resources.cpp --generate-source

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="gtk39">
<file>icon.jpg</file>
<file preprocess="xml-stripblanks">window.ui</file>
</gresource>
</gresources>

BIN
Gtk3/gtk39/res/icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -31,7 +31,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="scale1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
@ -51,7 +51,7 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">10</property> <property name="spacing">10</property>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="scale2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="adjustment">adjustment1</property> <property name="adjustment">adjustment1</property>
@ -93,11 +93,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkCheckButton"> <object class="GtkCheckButton" id="btnshow">
<property name="label" translatable="yes">Display Value on scale widgets</property> <property name="label" translatable="yes">Display Value on scale widgets</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">False</property> <property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property> <property name="draw-indicator">True</property>
</object> </object>
<packing> <packing>
@ -132,7 +133,7 @@
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<object class="GtkComboBoxText"> <object class="GtkComboBoxText" id="combo_pos">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="active">0</property> <property name="active">0</property>
@ -190,10 +191,10 @@
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<object class="GtkComboBoxText"> <object class="GtkComboBoxText" id="combo_update">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="active">0</property> <property name="active">1</property>
<items> <items>
<item>Continuous</item> <item>Continuous</item>
<item>Discontinuous</item> <item>Discontinuous</item>
@ -238,7 +239,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="digit_scale">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="adjustment">adjustment2</property> <property name="adjustment">adjustment2</property>
@ -275,7 +276,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="size_scale">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="adjustment">adjustment3</property> <property name="adjustment">adjustment3</property>

View File

@ -19,19 +19,19 @@
</object> </object>
<object class="GtkWindow" id="window"> <object class="GtkWindow" id="window">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="border-width">10</property> <property name="border-width">5</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">10</property> <property name="spacing">20</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="scale1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
@ -51,7 +51,7 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">10</property> <property name="spacing">10</property>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="scale2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="adjustment">adjustment1</property> <property name="adjustment">adjustment1</property>
@ -93,11 +93,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkCheckButton"> <object class="GtkCheckButton" id="btnshow">
<property name="label" translatable="yes">Display Value on scale widgets</property> <property name="label" translatable="yes">Display Value on scale widgets</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">False</property> <property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property> <property name="draw-indicator">True</property>
</object> </object>
<packing> <packing>
@ -132,7 +133,7 @@
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<object class="GtkComboBoxText"> <object class="GtkComboBoxText" id="combo_pos">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="active">0</property> <property name="active">0</property>
@ -190,10 +191,10 @@
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<object class="GtkComboBoxText"> <object class="GtkComboBoxText" id="combo_update">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="active">0</property> <property name="active">1</property>
<items> <items>
<item>Continuous</item> <item>Continuous</item>
<item>Discontinuous</item> <item>Discontinuous</item>
@ -238,7 +239,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="digit_scale">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="adjustment">adjustment2</property> <property name="adjustment">adjustment2</property>

View File

@ -1,10 +1,86 @@
#include "gtk/gtk.h" #include <gtk/gtk.h>
/*void change_update(GtkWidget *widget,GtkBuilder *builder){
//Get scale widgets
GObject *scale1=gtk_builder_get_object(builder,"scale1");
GObject *scale2=gtk_builder_get_object(builder,"scale2");
}*/
void show_value(GtkWidget *widget,GtkBuilder *builder){
//Get scale widgets
GObject *scale1=gtk_builder_get_object(builder,"scale1");
GObject *scale2=gtk_builder_get_object(builder,"scale2");
//Get checkbutton status and set scale widgets
gboolean checked=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
gtk_scale_set_draw_value(GTK_SCALE(scale1),checked);
gtk_scale_set_draw_value(GTK_SCALE(scale2),checked);
}
void change_pos(GtkWidget *widget,GtkBuilder *builder){
//Get scale widgets
GObject *scale1=gtk_builder_get_object(builder,"scale1");
GObject *scale2=gtk_builder_get_object(builder,"scale2");
//Get selection and set the value position
gint pos=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
//g_print("%d\n",pos);
GtkPositionType position;
switch(pos){
case 0:
position=GTK_POS_TOP;
break;
case 1:
position=GTK_POS_BOTTOM;
break;
case 2:
position=GTK_POS_LEFT;
break;
case 3:
position=GTK_POS_RIGHT;
break;
}
gtk_scale_set_value_pos(GTK_SCALE(scale1),position);
gtk_scale_set_value_pos(GTK_SCALE(scale2),position);
}
void change_digit(GtkWidget *widget,GtkBuilder *builder){
//Get scale widgets
GObject *scale1=gtk_builder_get_object(builder,"scale1");
GObject *scale2=gtk_builder_get_object(builder,"scale2");
gint digits=gtk_range_get_value(GTK_RANGE(widget));
//Set the scale digits
gtk_scale_set_digits(GTK_SCALE(scale1),digits);
gtk_scale_set_digits(GTK_SCALE(scale2),digits);
}
void page_size(GtkWidget *widget,GtkBuilder *builder){
GObject *set=gtk_builder_get_object(builder,"adjustment1");
gdouble page_size;
page_size=gtk_range_get_value(GTK_RANGE(widget));
gtk_adjustment_set_page_size(GTK_ADJUSTMENT(set),page_size);
}
static void gtkmain(GtkApplication *app,gpointer user_data){ static void gtkmain(GtkApplication *app,gpointer user_data){
//Main window //Main window
GtkBuilder *builder=gtk_builder_new_from_file("res/window.ui"); GtkBuilder *builder=gtk_builder_new_from_resource("/gtk39/window.ui");
GObject *window=gtk_builder_get_object(builder,"window"); GObject *window=gtk_builder_get_object(builder,"window");
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_resource("/gtk39/icon.jpg",NULL);
gtk_window_set_icon(GTK_WINDOW(window),pixbuf);
gtk_application_add_window(app,GTK_WINDOW(window)); gtk_application_add_window(app,GTK_WINDOW(window));
//Show value setting
GObject *btn_show=gtk_builder_get_object(builder,"btnshow");
g_signal_connect(btn_show,"clicked",G_CALLBACK(show_value),builder);
//Update policy settings,Gtk3 deprecated
//Scale Value Position Settings
GObject *combo_pos=gtk_builder_get_object(builder,"combo_pos");
g_signal_connect(combo_pos,"changed",G_CALLBACK(change_pos),builder);
//Scale Digits settings
GObject *digit_scale=gtk_builder_get_object(builder,"digit_scale");
g_signal_connect(digit_scale,"value-changed",G_CALLBACK(change_digit),builder);
//Scroll bar page setting
GObject *size_scale=gtk_builder_get_object(builder,"size_scale");
g_signal_connect(size_scale,"value-changed",G_CALLBACK(page_size),builder);
//"Exit" button //"Exit" button
GObject *btn_exit=gtk_builder_get_object(builder,"btnexit"); GObject *btn_exit=gtk_builder_get_object(builder,"btnexit");
g_signal_connect_swapped(btn_exit,"clicked",G_CALLBACK(gtk_widget_destroy),window); g_signal_connect_swapped(btn_exit,"clicked",G_CALLBACK(gtk_widget_destroy),window);