Add calc app

This commit is contained in:
daleclack 2022-06-09 14:00:21 +08:00
parent d4d09adb33
commit c8c5cbaca9
7 changed files with 50 additions and 4 deletions

View File

@ -1,6 +1,6 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(My_GtkUI VERSION 5.2.0)
project(My_GtkUI VERSION 5.3.0)
#Add GCR_CMake
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../GCR_CMake/macros)

View File

@ -101,6 +101,7 @@ void CalcApp::btnanswer_clicked(){
//std::cout<<text<<std::endl;
// Calculation
calc_reset();
int result = calc_expression_value(text.c_str());
char result_str[40];
sprintf(result_str,"%d",result);

View File

@ -5,6 +5,9 @@
static int pos = 0;
void calc_reset(){
pos = 0;
}
int calc_factor_value(const char * factor){
int result = 0;

View File

@ -1,3 +1,5 @@
#pragma once
int calc_expression_value(const char * expression);
void calc_reset();

View File

@ -80,7 +80,7 @@ void MyWin::about_activated()
// Version information
char *version;
version = g_strdup_printf("5.2\nRunning Against: Gtkmm %d.%d.%d",
version = g_strdup_printf("5.3\nRunning Against: Gtkmm %d.%d.%d",
GTKMM_MAJOR_VERSION,
GTKMM_MINOR_VERSION,
GTKMM_MICRO_VERSION);

View File

@ -17,6 +17,7 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
ref_builder->get_widget("btnimage", btnimage);
ref_builder->get_widget("btnset", btnset);
ref_builder->get_widget("btngame24",btngame24);
ref_builder->get_widget("btncalc",btncalc);
ref_builder->get_widget("separator_start", separator_start);
ref_builder->get_widget("separator_end", separator_end);
ref_builder->get_widget("launchpad_stack", launchpad_stack);
@ -37,10 +38,12 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
ref_builder->get_widget("padedit", padedit);
ref_builder->get_widget("padrun", padrun);
ref_builder->get_widget("padgame24",padgame24);
ref_builder->get_widget("padcalc",padcalc);
// Create window
game_win = Game::create();
game24_win = Game24Win::create();
calc_win = CalcApp::create();
// Link signals
btnlaunch->signal_clicked().connect(sigc::mem_fun(*this, &MyDock::btnlaunch_clicked));
@ -74,6 +77,11 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
game24_win->signal_delete_event().connect(sigc::mem_fun(*this,&MyDock::game24_win_closed));
game24_win->signal_hide().connect(sigc::mem_fun(*this,&MyDock::game24_win_hide));
btncalc->signal_clicked().connect(sigc::mem_fun(*this,&MyDock::btncalc_clicked));
padcalc->signal_clicked().connect(sigc::mem_fun(*this,&MyDock::padcalc_clicked));
calc_win->signal_delete_event().connect(sigc::mem_fun(*this,&MyDock::calc_win_closed));
calc_win->signal_hide().connect(sigc::mem_fun(*this,&MyDock::calc_win_hide));
btnimage->signal_clicked().connect(sigc::mem_fun(*this, &MyDock::btnimage_clicked));
padimage->signal_clicked().connect(sigc::mem_fun(*this, &MyDock::padimage_clicked));
image_win.signal_delete_event().connect(sigc::mem_fun(*this, &MyDock::image_win_closed));
@ -299,6 +307,30 @@ void MyDock::game24_win_hide(){
game24_win->hide();
}
// Signal Handlers for Calc App
bool MyDock::calc_win_closed(GdkEventAny *event){
btncalc->set_image_from_icon_name("calcapp",Gtk::ICON_SIZE_DIALOG);
calc_win->hide();
return true;
}
void MyDock::btncalc_clicked(){
btncalc->set_image_from_icon_name("calcapp_running",Gtk::ICON_SIZE_DIALOG);
window_ctrl(*calc_win);
}
void MyDock::padcalc_clicked(){
btncalc->set_image_from_icon_name("calcapp_running",Gtk::ICON_SIZE_DIALOG);
window_ctrl(*calc_win);
btnlaunch_clicked();
}
void MyDock::calc_win_hide(){
btncalc->set_image_from_icon_name("calcapp",Gtk::ICON_SIZE_DIALOG);
calc_win->hide();
}
// Signal Handlers for image app window
bool MyDock::image_win_closed(GdkEventAny *event)

View File

@ -10,6 +10,7 @@
#include "Runner.hh"
#include "TextEditor.hh"
#include "Game24Win.hh"
#include "CalcApp.hh"
enum class DockMode{
MODE_DOCK,
@ -28,7 +29,7 @@ public:
private:
// Child widgets
Gtk::Box *finder_box, *dock_box;
Gtk::Button *btnlaunch, *btndraw, *btnfiles,
Gtk::Button *btnlaunch, *btndraw, *btnfiles, *btncalc,
*btngame, *btnedit, *btnimage, *btnset, *btngame24;
Gtk::Separator *separator_start, *separator_end;
@ -39,7 +40,7 @@ private:
bool launchpad_shown;
Gtk::Stack *launchpad_stack;
Gtk::Grid *default_page, *launchpad_page, *apps_grid;
Gtk::Button *padaud, *paddraw, *padfile, *padgedit, *padgame, *padset,
Gtk::Button *padaud, *paddraw, *padfile, *padgedit, *padgame, *padset, *padcalc,
*padimage, *padnote, *padedit, *padvlc, *padvlc_win32, *padrun, *padgame24;
Gtk::Label label1;
@ -61,6 +62,13 @@ private:
void btnfile_clicked();
void padfile_clicked();
// Calculator App
CalcApp *calc_win;
bool calc_win_closed(GdkEventAny *event);
void calc_win_hide();
void btncalc_clicked();
void padcalc_clicked();
// Guess Game
Game *game_win;
bool game_win_closed(GdkEventAny *event);