Add Window Size Dialog

This commit is contained in:
daleclack 2021-06-29 15:51:26 +08:00
parent ff09b74fa1
commit 6c0b05e8af
6 changed files with 83 additions and 14 deletions

View File

@ -1,5 +1,4 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"cmake.configureOnOpen": false,
"C_Cpp.dimInactiveRegions": false
}

View File

@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<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">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Window size config</property>
@ -65,9 +75,11 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="entry_width">
<object class="GtkSpinButton" id="width_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="value">800</property>
</object>
<packing>
<property name="expand">False</property>
@ -88,9 +100,11 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_height">
<object class="GtkSpinButton" id="height_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment2</property>
<property name="value">450</property>
</object>
<packing>
<property name="expand">False</property>

View File

@ -1,17 +1,16 @@
#include "MyWin.hh"
#include "winpe.xpm"
#include "image_types.hh"
#include "winconf.hh"
MyWin::MyWin():
main_box(Gtk::ORIENTATION_VERTICAL),
conf_dlg(this),
width(800),
height(450)
{
//Initalize Window
set_icon_name("My_GtkUI");
get_config(&width,&height);
set_default_size(width,height);
conf_dlg.get_config(&width,&height);
overlay.add_overlay(draw_area);
default_background();
overlay.add(background);
@ -25,6 +24,7 @@ height(450)
add_action("quit",sigc::mem_fun(*this,&MyWin::win_quit));
add_action("default",sigc::mem_fun(*this,&MyWin::default_background));
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));
//Set Popover Menu
@ -52,6 +52,10 @@ void MyWin::btn_pressed(int n_press,double x,double y){
popover.popup();
}
void MyWin::size_dialog(){
conf_dlg.show_dialog();
}
void MyWin::default_background(){
//Default background
Glib::RefPtr<Gdk::Pixbuf> pixbuf=Gdk::Pixbuf::create_from_xpm_data(winpe);

View File

@ -2,6 +2,7 @@
#include <gtkmm.h>
#include "MyStack.hh"
#include "winconf.hh"
class MyWin : public Gtk::ApplicationWindow{
public:
@ -22,6 +23,7 @@ private:
//Window Proprties
int width,height;
WinConf conf_dlg;
//Gesture Widgets
Glib::RefPtr<Gtk::GestureMultiPress> gesture;
@ -30,6 +32,7 @@ private:
//Signal Handlers
void default_background();
void back_dialog();
void size_dialog();
void change_background(int response);
void about_dialog();
void win_quit();

View File

@ -2,14 +2,58 @@
#include <cstdio>
WinConf::WinConf(Gtk::Window *window){
//Ininalize the Config Dialog
confwin=window;
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+");
if(fp){
fscanf(fp,"%d%d",width,height);
fscanf(fp,"%d%d",&width,&height);
}
confwin->set_default_size(width,height);
*width1=width;
*height1=height;
}

View File

@ -5,15 +5,20 @@
class WinConf{
public:
WinConf(Gtk::Window *window);
void get_config(int *width1,int *height1);
void show_dialog();
void dialog_response(int response_id);
private:
//Window size
int width,height;
//The window to change config
Gtk::Window *confwin;
//Main Widgets
Glib::RefPtr<Gtk::Builder> conf_builder;
Gtk::Dialog *dialog;
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);