Add 24game

This commit is contained in:
daleclack 2022-04-21 16:25:07 +08:00
parent 63bfda7371
commit ced2d49d45
11 changed files with 990 additions and 7 deletions

View File

@ -15,7 +15,7 @@ set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
include_directories(.)
include_directories(..)
include_directories(src/core src/ui src/apps src/panels src/image_app)
include_directories(src/core src/ui src/apps src/panels src/image_app src/game24_app)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
@ -25,6 +25,7 @@ link_directories (${GTKMM3_LIBRARY_DIRS})
set(SOURCES src/core/main.cc src/core/MyWin.cc src/core/MyStack.cc src/cfgfile/cfgfile.cc
src/ui/MyFinder.cc src/ui/MyPrefs.cc src/ui/MyDock.cc
src/draw_app/drawing.cc src/file_app/FileWindow.cc src/game_app/Game.cc
src/game24_app/Game24.cc src/game24_app/Game24Win.cc
src/image_app/ImageApp.cc src/image_app/MyImage.cc
src/run_app/Runner.cc src/text_app/TextEditor.cc)
@ -38,6 +39,7 @@ set(RESOURCE_LIST
STRIPBLANKS prefs_stack.ui
STRIPBLANKS mydock.ui
STRIPBLANKS game1.ui
STRIPBLANKS game24.ui
style.css
reset.css
dock_style.css
@ -58,6 +60,8 @@ set(RESOURCE_LIST
icons/48x48/actions/game_running.png
icons/48x48/actions/btnabout.png
icons/48x48/actions/My_GtkUI.png
icons/scalable/status/24game.svg
icons/scalable/status/24game_running.svg
icons/scalable/status/audacious_whitesur.svg
icons/scalable/status/my_prefs.svg
icons/scalable/status/my_prefs_running.svg

389
Gtkmm3_Mac/res/game24.ui Normal file
View File

@ -0,0 +1,389 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="window">
<property name="can-focus">False</property>
<property name="default-width">440</property>
<property name="default-height">260</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">The Numbers:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_numbers">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Input answer, for example, ((6+6)+6)+6 is an answer,
"None" for no answer</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_ans">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<!-- n-columns=4 n-rows=4 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="row-homogeneous">True</property>
<property name="column-homogeneous">True</property>
<child>
<object class="GtkButton" id="btn7">
<property name="label" translatable="yes">7</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn8">
<property name="label" translatable="yes">8</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn9">
<property name="label" translatable="yes">9</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnadd">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn4">
<property name="label" translatable="yes">4</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn5">
<property name="label" translatable="yes">5</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn6">
<property name="label" translatable="yes">6</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnsubb">
<property name="label" translatable="yes">-</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn1">
<property name="label" translatable="yes">1</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn2">
<property name="label" translatable="yes">2</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn3">
<property name="label" translatable="yes">3</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnmul">
<property name="label" translatable="yes">*</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnleft">
<property name="label" translatable="yes">(</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn0">
<property name="label" translatable="yes">0</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnright">
<property name="label" translatable="yes">)</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btndiv">
<property name="label" translatable="yes">/</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="spacing">10</property>
<child>
<object class="GtkButton" id="btnstart">
<property name="label" translatable="yes">Start</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnnext">
<property name="label" translatable="yes">Next</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btncheck">
<property name="label" translatable="yes">Check</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnclear">
<property name="label" translatable="yes">Clear</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnexit">
<property name="label" translatable="yes">Exit</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="48"
height="48"
viewBox="0 0 48 48"
version="1.1"
id="svg5"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04, custom)"
sodipodi:docname="24game.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="px"
showgrid="false"
inkscape:snap-smooth-nodes="false"
inkscape:zoom="16.543545"
inkscape:cx="20.763385"
inkscape:cy="30.948626"
inkscape:window-width="1844"
inkscape:window-height="1045"
inkscape:window-x="76"
inkscape:window-y="35"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="图层 1"
inkscape:groupmode="layer"
id="layer1">
<path
id="rect23227"
style="fill:#1a70e0;stroke-width:0.974598"
d="m 5.8524966,5.8374733 c 5.6887584,-5.75987392 31.6953694,-5.80667424 36.2003754,0 5.927763,7.6405197 5.931245,31.2845797 0,36.2849207 -6.955401,5.863759 -31.823657,5.809794 -36.2003754,0 -5.76249505,-7.649316 -5.84401942,-30.367845 0,-36.2849207 z"
sodipodi:nodetypes="sssss" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:21.3333px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none"
x="12.064167"
y="31.957142"
id="text27175"><tspan
sodipodi:role="line"
id="tspan27173"
x="12.064167"
y="31.957142">24</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="48"
height="48"
viewBox="0 0 48 48"
version="1.1"
id="svg5"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04, custom)"
sodipodi:docname="24game_running.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="px"
showgrid="false"
inkscape:snap-smooth-nodes="false"
inkscape:zoom="16.543545"
inkscape:cx="20.15892"
inkscape:cy="25.145759"
inkscape:window-width="1844"
inkscape:window-height="1045"
inkscape:window-x="76"
inkscape:window-y="35"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="图层 1"
inkscape:groupmode="layer"
id="layer1">
<path
id="rect23227"
style="fill:#1a70e0;stroke-width:0.974598"
d="m 5.8524966,5.8374733 c 5.6887584,-5.75987392 31.6953694,-5.80667424 36.2003754,0 5.927763,7.6405197 5.931245,31.2845797 0,36.2849207 -6.955401,5.863759 -31.823657,5.809794 -36.2003754,0 -5.76249505,-7.649316 -5.84401942,-30.367845 0,-36.2849207 z"
sodipodi:nodetypes="sssss" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:21.3333px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none"
x="12.064167"
y="31.957142"
id="text27175"><tspan
sodipodi:role="line"
id="tspan27173"
x="12.064167"
y="31.957142">24</tspan></text>
<rect
style="fill:#1a70e0;stroke-width:0.999215"
id="rect31"
width="2"
height="48"
x="0"
y="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -89,6 +89,20 @@
<property name="pixel-size">48</property>
<property name="icon-name">my_trash</property>
</object>
<object class="GtkImage" id="image22">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">48</property>
<property name="icon-name">24game</property>
<property name="icon_size">6</property>
</object>
<object class="GtkImage" id="image23">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">48</property>
<property name="icon-name">24game</property>
<property name="icon_size">6</property>
</object>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -294,6 +308,21 @@
<property name="position">8</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btngame24">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image23</property>
<property name="relief">none</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">9</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
@ -302,7 +331,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">9</property>
<property name="position">10</property>
</packing>
</child>
<child>
@ -317,7 +346,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">10</property>
<property name="position">11</property>
</packing>
</child>
<child>
@ -332,9 +361,12 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">11</property>
<property name="position">12</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -613,7 +645,20 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkButton" id="padgame24">
<property name="label" translatable="yes">24Game</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image22</property>
<property name="relief">none</property>
<property name="image-position">top</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="left-attach">6</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<placeholder/>

View File

@ -0,0 +1,34 @@
#pragma once
#include <gtkmm.h>
#include "Game24.hh"
class Game24Win : public Gtk::Window
{
public:
static Game24Win *create();
Game24Win(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade);
private:
// Main GtkBuilder
Glib::RefPtr<Gtk::Builder> ref_builder;
// 24-Game Class
Game24 main_game;
int pos;
bool focused, winned;
Glib::ustring tmp;
// Child widgets
Gtk::Entry *entry_ans;
Gtk::Label *label_numbers;
Gtk::Button *btns[16], *btnstart, *btnnext, *btncheck, *btnclear, *btnexit;
// Signal Handlers
void btns_clicked(Gtk::Button *button);
void btnstart_clicked();
void btnnext_clicked();
void btncheck_clicked();
void btnclear_clicked();
void entry_ans_focus();
};

View File

@ -0,0 +1,173 @@
// Reference code: https://www.jb51.net/article/182079.htm
#include "Game24.hh"
// Generate a number in [begin,end]
static double randnum(int begin = 0, int end = 1)
{
return rand() % (end - begin + 1) + begin;
}
// The Game Class
bool Game24::startgame(string user_result)
{
bool winned = false;
// Format result number
if (user_result != "")
{
if (user_result.length() < (*(result_strings.begin())).length())
{
user_result = '(' + user_result + ')';
}
}
std::cout << user_result << std::endl;
// Check user input and the results
if (count > 0)
{
for (std::vector<string>::iterator it = result_strings.begin(); it != result_strings.end(); it++)
{
if (*it == user_result)
{
std::cout << "Winned!" << std::endl;
winned = true;
break;
}
else
{
continue;
}
}
}
else
{
if (user_result == "(None)")
{
winned = true;
}
}
// If lost, output information
if (!winned)
{
std::cout << "Lost" << std::endl;
}
return winned;
}
void Game24::getnumbers()
{
srand(time(NULL));
for (int i = 0; i < n; i++)
{
// Get Number and output
number[i] = randnum(1, 13);
// std::cout << number[i] << " ";
// Process number to string for display
switch ((int)number[i])
{
case 10:
result[i] = "10";
break;
case 11:
result[i] = "11";
break;
case 12:
result[i] = "12";
break;
case 13:
result[i] = "13";
break;
default:
result[i] = '0' + number[i];
}
}
// std::cout << std::endl;
// Get the algorithm that can get the result
F(n);
// std::cout << "Has" << count << "Results" << std::endl;
sprintf(numbers_char, "%d %d %d %d", (int)number[0], (int)number[1], (int)number[2], (int)number[3]);
}
void Game24::F(int n)
{
// Calculate for three times
if (n == 1)
{
if (number[0] == 24)
{
// std::cout << result[0] << std::endl;
result_strings.push_back(result[0]);
count++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
double a, b;
string x, y;
// Save number
a = number[i];
b = number[j];
number[j] = number[n - 1];
// Save Result String
x = result[i];
y = result[j];
result[j] = result[n - 1];
// Add
number[i] = a + b;
result[i] = '(' + x + '+' + y + ')';
F(n - 1);
// Minus
number[i] = a - b;
result[i] = '(' + x + '-' + y + ')';
F(n - 1);
number[i] = b - a;
result[i] = '(' + y + '-' + x + ')';
F(n - 1);
// multiply
number[i] = a * b;
result[i] = '(' + x + '*' + y + ')';
F(n - 1);
// divide
if (b != 0)
{
number[i] = a / b;
result[i] = '(' + x + '/' + y + ')';
F(n - 1);
}
if (a != 0)
{
number[i] = b / a;
result[i] = '(' + y + '/' + x + ')';
F(n - 1);
}
// if the result is not 24, make the numbers back
number[i] = a;
number[j] = b;
result[i] = x;
result[j] = y;
}
}
}
// int main(int argc, char **argv)
// {
// Game24 game1;
// game1.startgame();
// return 0;
// }

View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
typedef std::string string;
class Game24
{
public:
bool startgame(string user_result);
void getnumbers();
char numbers_char[20];
private:
const int n = 4; // Flag of third calculate
double number[4] = {0}; // Numbers
char oper[4] = {'+', '-', '*', '/'}; // operators
string result[4];
int count = 0;
std::vector<std::string> result_strings;
// Handlers
void F(int n);
};

View File

@ -0,0 +1,124 @@
#include "Game24Win.hh"
Game24Win::Game24Win(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade)
: Gtk::Window(cobject),
ref_builder(ref_Glade),
winned(true)
{
set_icon_name("24game");
// Get Widgets
ref_builder->get_widget("label_numbers", label_numbers);
ref_builder->get_widget("entry_ans", entry_ans);
ref_builder->get_widget("btnstart", btnstart);
ref_builder->get_widget("btnnext",btnnext);
ref_builder->get_widget("btncheck", btncheck);
ref_builder->get_widget("btnclear",btnclear);
ref_builder->get_widget("btnexit", btnexit);
ref_builder->get_widget("btn0", btns[0]);
ref_builder->get_widget("btn1", btns[1]);
ref_builder->get_widget("btn2", btns[2]);
ref_builder->get_widget("btn3", btns[3]);
ref_builder->get_widget("btn4", btns[4]);
ref_builder->get_widget("btn5", btns[5]);
ref_builder->get_widget("btn6", btns[6]);
ref_builder->get_widget("btn7", btns[7]);
ref_builder->get_widget("btn8", btns[8]);
ref_builder->get_widget("btn9", btns[9]);
ref_builder->get_widget("btnadd", btns[10]);
ref_builder->get_widget("btnsubb", btns[11]);
ref_builder->get_widget("btnmul", btns[12]);
ref_builder->get_widget("btndiv", btns[13]);
ref_builder->get_widget("btnleft", btns[14]);
ref_builder->get_widget("btnright", btns[15]);
// Link Signals
btnstart->signal_clicked().connect(sigc::mem_fun(*this, &Game24Win::btnstart_clicked));
btnexit->signal_clicked().connect(sigc::mem_fun(*this, &Game24Win::hide));
btnnext->signal_clicked().connect(sigc::mem_fun(*this, &Game24Win::btnnext_clicked));
btncheck->signal_clicked().connect(sigc::mem_fun(*this, &Game24Win::btncheck_clicked));
btnclear->signal_clicked().connect(sigc::mem_fun(*this,&Game24Win::btnclear_clicked));
for (int i = 0; i < 16; i++)
{
btns[i]->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Game24Win::btns_clicked), btns[i]));
}
entry_ans->signal_grab_focus().connect(sigc::mem_fun(*this, &Game24Win::entry_ans_focus));
}
void Game24Win::btns_clicked(Gtk::Button *button)
{
// Get Original text and add number from button
// 1.Get text buffer for insert
auto buffer = entry_ans->get_buffer();
// 2.Get text to insert
Glib::ustring label = button->get_label();
if (focused)
{
pos = entry_ans->get_position();
}
// 3.Get Position
buffer->insert_text(pos, label);
pos++;
focused = false;
}
void Game24Win::entry_ans_focus()
{
focused = true;
}
void Game24Win::btnstart_clicked()
{
// Start Game
if (winned)
{
main_game.getnumbers();
label_numbers->set_label(main_game.numbers_char);
}
else
{
label_numbers->set_label(tmp);
}
// Save the numbers
tmp = label_numbers->get_label();
}
void Game24Win::btncheck_clicked()
{
// Check Answer
Glib::ustring answer = entry_ans->get_text();
winned = main_game.startgame(std::string(answer.c_str()));
if (winned)
{
label_numbers->set_label("You Winned!");
}
else
{
label_numbers->set_label("You Lost!");
}
}
void Game24Win::btnnext_clicked(){
main_game.getnumbers();
label_numbers->set_label(main_game.numbers_char);
}
void Game24Win::btnclear_clicked(){
// Clear the text
entry_ans->set_text("");
}
Game24Win *Game24Win::create()
{
// Create a new window
Game24Win *window = nullptr;
auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/game24.ui");
builder->get_widget_derived("window", window);
return window;
}

View File

@ -16,6 +16,7 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
ref_builder->get_widget("btnedit", btnedit);
ref_builder->get_widget("btnimage", btnimage);
ref_builder->get_widget("btnset", btnset);
ref_builder->get_widget("btngame24",btngame24);
ref_builder->get_widget("separator_start", separator_start);
ref_builder->get_widget("separator_end", separator_end);
ref_builder->get_widget("launchpad_stack", launchpad_stack);
@ -35,9 +36,11 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
ref_builder->get_widget("padimage", padimage);
ref_builder->get_widget("padedit", padedit);
ref_builder->get_widget("padrun", padrun);
ref_builder->get_widget("padgame24",padgame24);
// Create window
game_win = Game::create();
game24_win = Game24Win::create();
// Link signals
btnlaunch->signal_clicked().connect(sigc::mem_fun(*this, &MyDock::btnlaunch_clicked));
@ -65,6 +68,11 @@ MyDock::MyDock(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Gl
game_win->signal_delete_event().connect(sigc::mem_fun(*this, &MyDock::game_win_closed));
game_win->signal_hide().connect(sigc::mem_fun(*this, &MyDock::game_win_hide));
btngame24->signal_clicked().connect(sigc::mem_fun(*this,&MyDock::btngame24_clicked));
padgame24->signal_clicked().connect(sigc::mem_fun(*this,&MyDock::padgame24_clicked));
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));
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));
@ -128,6 +136,7 @@ void MyDock::mydock_init(Gtk::Window *window, Gtk::Image *background1)
void MyDock::padaud_clicked()
{
// Start audacious app
std::thread first(system, "audacious");
first.detach();
btnlaunch_clicked();
@ -135,6 +144,7 @@ void MyDock::padaud_clicked()
void MyDock::padgedit_clicked()
{
// Start gedit app
std::thread second(system, "gedit");
second.detach();
btnlaunch_clicked();
@ -142,6 +152,7 @@ void MyDock::padgedit_clicked()
void MyDock::padvlc_clicked()
{
// Start vlc app
std::thread third(system, "vlc");
third.detach();
btnlaunch_clicked();
@ -149,6 +160,7 @@ void MyDock::padvlc_clicked()
void MyDock::padvlc_win32_clicked()
{
// Start vlc on windows
std::thread fourth(system, "start notepad");
fourth.detach();
btnlaunch_clicked();
@ -156,6 +168,7 @@ void MyDock::padvlc_win32_clicked()
void MyDock::padnote_clicked()
{
// Start Notepad on windows
std::thread fifth(system, "start ..\\vlc\\vlc.exe");
fifth.detach();
btnlaunch_clicked();
@ -163,6 +176,7 @@ void MyDock::padnote_clicked()
bool MyDock::prefs_win_closed(GdkEventAny *event)
{
// Handle the "closed" signal of preference window
btnset->set_image_from_icon_name("my_prefs", Gtk::ICON_SIZE_DIALOG);
prefs_win.hide();
return true;
@ -170,17 +184,21 @@ bool MyDock::prefs_win_closed(GdkEventAny *event)
void MyDock::btnset_clicked()
{
// Show settings window (preferences)
btnset->set_image_from_icon_name("my_prefs_running", Gtk::ICON_SIZE_DIALOG);
window_ctrl(prefs_win);
}
void MyDock::padset_clicked()
{
// Function for button on launchpad
btnset->set_image_from_icon_name("my_prefs_running", Gtk::ICON_SIZE_DIALOG);
window_ctrl(prefs_win, false);
btnlaunch_clicked();
}
//Signal Handlers for drawing app window
bool MyDock::draw_win_closed(GdkEventAny *event)
{
btndraw->set_image_from_icon_name("drawing_app", Gtk::ICON_SIZE_DIALOG);
@ -201,6 +219,8 @@ void MyDock::paddraw_clicked()
btnlaunch_clicked();
}
// Signal Handlers for file window
bool MyDock::file_win_closed(GdkEventAny *event)
{
btnfiles->set_image_from_icon_name("file-app", Gtk::ICON_SIZE_DIALOG);
@ -213,6 +233,7 @@ void MyDock::btnfile_clicked()
btnfiles->set_image_from_icon_name("file-app_running", Gtk::ICON_SIZE_DIALOG);
window_ctrl(file_app);
}
void MyDock::padfile_clicked()
{
btnfiles->set_image_from_icon_name("file-app_running", Gtk::ICON_SIZE_DIALOG);
@ -220,6 +241,8 @@ void MyDock::padfile_clicked()
btnlaunch_clicked();
}
// Signal Handlers for game window
bool MyDock::game_win_closed(GdkEventAny *event)
{
btngame->set_image_from_icon_name("game", Gtk::ICON_SIZE_DIALOG);
@ -246,6 +269,32 @@ void MyDock::padgame_clicked()
btnlaunch_clicked();
}
// Signal Handlers for game24 window
bool MyDock::game24_win_closed(GdkEventAny *event){
btngame24->set_image_from_icon_name("24game",Gtk::ICON_SIZE_DIALOG);
game24_win->hide();
return true;
}
void MyDock::btngame24_clicked(){
btngame24->set_image_from_icon_name("24game_running",Gtk::ICON_SIZE_DIALOG);
window_ctrl(*game24_win);
}
void MyDock::padgame24_clicked(){
btngame24->set_image_from_icon_name("24game_running",Gtk::ICON_SIZE_DIALOG);
window_ctrl(*game24_win,false);
btnlaunch_clicked();
}
void MyDock::game24_win_hide(){
btngame24->set_image_from_icon_name("24game",Gtk::ICON_SIZE_DIALOG);
game24_win->hide();
}
// Signal Handlers for image app window
bool MyDock::image_win_closed(GdkEventAny *event)
{
btnimage->set_image_from_icon_name("image_app", Gtk::ICON_SIZE_DIALOG);
@ -258,6 +307,7 @@ void MyDock::btnimage_clicked()
btnimage->set_image_from_icon_name("image_app_running", Gtk::ICON_SIZE_DIALOG);
window_ctrl(image_win);
}
void MyDock::padimage_clicked()
{
btnimage->set_image_from_icon_name("image_app_running", Gtk::ICON_SIZE_DIALOG);
@ -265,6 +315,8 @@ void MyDock::padimage_clicked()
btnlaunch_clicked();
}
// Signal Handlers for editor window
bool MyDock::editor_win_closed(GdkEventAny *event)
{
btnedit->set_image_from_icon_name("my_textedit", Gtk::ICON_SIZE_DIALOG);
@ -277,6 +329,7 @@ void MyDock::btnedit_clicked()
btnedit->set_image_from_icon_name("my_textedit_running", Gtk::ICON_SIZE_DIALOG);
window_ctrl(editor_win);
}
void MyDock::padedit_clicked()
{
btnedit->set_image_from_icon_name("my_textedit_running", Gtk::ICON_SIZE_DIALOG);
@ -284,6 +337,8 @@ void MyDock::padedit_clicked()
btnlaunch_clicked();
}
// Signal Handler for run window
void MyDock::btnrun_clicked()
{
runner1.show();

View File

@ -9,6 +9,7 @@
#include "ImageApp.hh"
#include "Runner.hh"
#include "TextEditor.hh"
#include "Game24Win.hh"
enum class DockMode{
MODE_DOCK,
@ -28,7 +29,7 @@ private:
// Child widgets
Gtk::Box *finder_box, *dock_box;
Gtk::Button *btnlaunch, *btndraw, *btnfiles,
*btngame, *btnedit, *btnimage, *btnset;
*btngame, *btnedit, *btnimage, *btnset, *btngame24;
Gtk::Separator *separator_start, *separator_end;
// Finder
@ -39,7 +40,7 @@ private:
Gtk::Stack *launchpad_stack;
Gtk::Grid *default_page, *launchpad_page, *apps_grid;
Gtk::Button *padaud, *paddraw, *padfile, *padgedit, *padgame, *padset,
*padimage, *padnote, *padedit, *padvlc, *padvlc_win32, *padrun;
*padimage, *padnote, *padedit, *padvlc, *padvlc_win32, *padrun, *padgame24;
Gtk::Label label1;
// Window Preferences
@ -66,6 +67,13 @@ private:
void btngame_clicked();
void padgame_clicked();
// 24-Game
Game24Win *game24_win;
bool game24_win_closed(GdkEventAny *event);
void game24_win_hide();
void btngame24_clicked();
void padgame24_clicked();
// Image Viewer
ImageApp image_win;
bool image_win_closed(GdkEventAny *event);