mirror of https://github.com/daleclack/My_GtkUi
Add Window Size Dialog
This commit is contained in:
parent
ff09b74fa1
commit
6c0b05e8af
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
"C_Cpp.errorSquiggles": "Disabled",
|
|
||||||
"cmake.configureOnOpen": false,
|
"cmake.configureOnOpen": false,
|
||||||
"C_Cpp.dimInactiveRegions": false
|
"C_Cpp.dimInactiveRegions": false
|
||||||
}
|
}
|
|
@ -1,7 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.38.2 -->
|
<!-- Generated with glade 3.38.2 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.24"/>
|
<requires lib="gtk+" version="3.0"/>
|
||||||
|
<object class="GtkAdjustment" id="adjustment1">
|
||||||
|
<property name="upper">9999</property>
|
||||||
|
<property name="step-increment">1</property>
|
||||||
|
<property name="page-increment">10</property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="adjustment2">
|
||||||
|
<property name="upper">9999</property>
|
||||||
|
<property name="step-increment">1</property>
|
||||||
|
<property name="page-increment">10</property>
|
||||||
|
</object>
|
||||||
<object class="GtkDialog" id="dialog">
|
<object class="GtkDialog" id="dialog">
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="title" translatable="yes">Window size config</property>
|
<property name="title" translatable="yes">Window size config</property>
|
||||||
|
@ -65,9 +75,11 @@
|
||||||
<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="GtkEntry" id="entry_width">
|
<object class="GtkSpinButton" id="width_spin">
|
||||||
<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="value">800</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
@ -88,9 +100,11 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEntry" id="entry_height">
|
<object class="GtkSpinButton" id="height_spin">
|
||||||
<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="value">450</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
#include "MyWin.hh"
|
#include "MyWin.hh"
|
||||||
#include "winpe.xpm"
|
#include "winpe.xpm"
|
||||||
#include "image_types.hh"
|
#include "image_types.hh"
|
||||||
#include "winconf.hh"
|
|
||||||
|
|
||||||
MyWin::MyWin():
|
MyWin::MyWin():
|
||||||
main_box(Gtk::ORIENTATION_VERTICAL),
|
main_box(Gtk::ORIENTATION_VERTICAL),
|
||||||
|
conf_dlg(this),
|
||||||
width(800),
|
width(800),
|
||||||
height(450)
|
height(450)
|
||||||
{
|
{
|
||||||
//Initalize Window
|
//Initalize Window
|
||||||
set_icon_name("My_GtkUI");
|
set_icon_name("My_GtkUI");
|
||||||
get_config(&width,&height);
|
conf_dlg.get_config(&width,&height);
|
||||||
set_default_size(width,height);
|
|
||||||
overlay.add_overlay(draw_area);
|
overlay.add_overlay(draw_area);
|
||||||
default_background();
|
default_background();
|
||||||
overlay.add(background);
|
overlay.add(background);
|
||||||
|
@ -25,6 +24,7 @@ height(450)
|
||||||
add_action("quit",sigc::mem_fun(*this,&MyWin::win_quit));
|
add_action("quit",sigc::mem_fun(*this,&MyWin::win_quit));
|
||||||
add_action("default",sigc::mem_fun(*this,&MyWin::default_background));
|
add_action("default",sigc::mem_fun(*this,&MyWin::default_background));
|
||||||
add_action("back",sigc::mem_fun(*this,&MyWin::back_dialog));
|
add_action("back",sigc::mem_fun(*this,&MyWin::back_dialog));
|
||||||
|
add_action("size",sigc::mem_fun(*this,&MyWin::size_dialog));
|
||||||
add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog));
|
add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog));
|
||||||
|
|
||||||
//Set Popover Menu
|
//Set Popover Menu
|
||||||
|
@ -52,6 +52,10 @@ void MyWin::btn_pressed(int n_press,double x,double y){
|
||||||
popover.popup();
|
popover.popup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyWin::size_dialog(){
|
||||||
|
conf_dlg.show_dialog();
|
||||||
|
}
|
||||||
|
|
||||||
void MyWin::default_background(){
|
void MyWin::default_background(){
|
||||||
//Default background
|
//Default background
|
||||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf=Gdk::Pixbuf::create_from_xpm_data(winpe);
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf=Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include "MyStack.hh"
|
#include "MyStack.hh"
|
||||||
|
#include "winconf.hh"
|
||||||
|
|
||||||
class MyWin : public Gtk::ApplicationWindow{
|
class MyWin : public Gtk::ApplicationWindow{
|
||||||
public:
|
public:
|
||||||
|
@ -22,6 +23,7 @@ private:
|
||||||
|
|
||||||
//Window Proprties
|
//Window Proprties
|
||||||
int width,height;
|
int width,height;
|
||||||
|
WinConf conf_dlg;
|
||||||
|
|
||||||
//Gesture Widgets
|
//Gesture Widgets
|
||||||
Glib::RefPtr<Gtk::GestureMultiPress> gesture;
|
Glib::RefPtr<Gtk::GestureMultiPress> gesture;
|
||||||
|
@ -30,6 +32,7 @@ private:
|
||||||
//Signal Handlers
|
//Signal Handlers
|
||||||
void default_background();
|
void default_background();
|
||||||
void back_dialog();
|
void back_dialog();
|
||||||
|
void size_dialog();
|
||||||
void change_background(int response);
|
void change_background(int response);
|
||||||
void about_dialog();
|
void about_dialog();
|
||||||
void win_quit();
|
void win_quit();
|
||||||
|
|
|
@ -2,14 +2,58 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
WinConf::WinConf(Gtk::Window *window){
|
WinConf::WinConf(Gtk::Window *window){
|
||||||
|
//Ininalize the Config Dialog
|
||||||
confwin=window;
|
confwin=window;
|
||||||
conf_builder=Gtk::Builder::create_from_resource("/GtkUI/win_size.ui");
|
conf_builder=Gtk::Builder::create_from_resource("/GtkUI/win_size.ui");
|
||||||
conf_builder->get_widget("")
|
conf_builder->get_widget("dialog",dialog);
|
||||||
|
conf_builder->get_widget("width_spin",width_spin);
|
||||||
|
conf_builder->get_widget("height_spin",height_spin);
|
||||||
|
conf_builder->get_widget("btnGet",btnget);
|
||||||
|
conf_builder->get_widget("btn_default",btn_default);
|
||||||
|
btnget->signal_clicked().connect(sigc::mem_fun(*this,&WinConf::get_size));
|
||||||
|
dialog->signal_response().connect(sigc::mem_fun(*this,&WinConf::dialog_response));
|
||||||
|
btn_default->signal_clicked().connect(sigc::mem_fun(*this,&WinConf::default_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_config(int *width,int *height){
|
void WinConf::get_size(){
|
||||||
|
//Get Current Size
|
||||||
|
confwin->get_size(width,height);
|
||||||
|
width_spin->set_value(width);
|
||||||
|
height_spin->set_value(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinConf::default_size(){
|
||||||
|
//Reset the size to default
|
||||||
|
width_spin->set_value(800);
|
||||||
|
height_spin->set_value(450);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinConf::show_dialog(){
|
||||||
|
dialog->show_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinConf::dialog_response(int response){
|
||||||
|
if(response==Gtk::RESPONSE_OK){
|
||||||
|
//Get Config in Dialog
|
||||||
|
width=width_spin->get_value_as_int();
|
||||||
|
height=height_spin->get_value_as_int();
|
||||||
|
//Write the Config to a file
|
||||||
|
FILE *fp=fopen("winsize.conf","wt+");
|
||||||
|
if(fp){
|
||||||
|
fprintf(fp,"%d %d",width,height);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dialog->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WinConf::get_config(int *width1,int *height1){
|
||||||
|
//Get Config from a file named "winsize.conf"
|
||||||
FILE *fp=fopen("winsize.conf","rt+");
|
FILE *fp=fopen("winsize.conf","rt+");
|
||||||
if(fp){
|
if(fp){
|
||||||
fscanf(fp,"%d%d",width,height);
|
fscanf(fp,"%d%d",&width,&height);
|
||||||
}
|
}
|
||||||
|
confwin->set_default_size(width,height);
|
||||||
|
*width1=width;
|
||||||
|
*height1=height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,20 @@
|
||||||
class WinConf{
|
class WinConf{
|
||||||
public:
|
public:
|
||||||
WinConf(Gtk::Window *window);
|
WinConf(Gtk::Window *window);
|
||||||
|
void get_config(int *width1,int *height1);
|
||||||
void show_dialog();
|
void show_dialog();
|
||||||
void dialog_response(int response_id);
|
|
||||||
private:
|
private:
|
||||||
|
//Window size
|
||||||
|
int width,height;
|
||||||
//The window to change config
|
//The window to change config
|
||||||
Gtk::Window *confwin;
|
Gtk::Window *confwin;
|
||||||
//Main Widgets
|
//Main Widgets
|
||||||
Glib::RefPtr<Gtk::Builder> conf_builder;
|
Glib::RefPtr<Gtk::Builder> conf_builder;
|
||||||
|
Gtk::Dialog *dialog;
|
||||||
Gtk::SpinButton *width_spin,*height_spin;
|
Gtk::SpinButton *width_spin,*height_spin;
|
||||||
Gtk::Button *btnget;
|
Gtk::Button *btnget,*btn_default;
|
||||||
|
//Signal Handlers
|
||||||
|
void get_size();
|
||||||
|
void default_size();
|
||||||
|
void dialog_response(int response_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_config(int *width,int *height);
|
|
||||||
|
|
Loading…
Reference in New Issue