Update gtk128

This commit is contained in:
daleclack 2022-04-16 15:12:09 +08:00
parent 858ba84940
commit e7ff7fa9a9
9 changed files with 810 additions and 1 deletions

3
.gitignore vendored
View File

@ -43,8 +43,9 @@ gschemas.compiled
#backend source
backend/*
#The binary
#The binary files
FiveRow
24game
# Prerequisites
*.d

View File

@ -0,0 +1,72 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk128_24game VERSION 1.0.0)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
include(GlibCompileResourcesSupport)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
include_directories(.)
include_directories(..)
#Find PkgConfig to use gtkmm3
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_DIRS})
#Find Gettext
find_package (Gettext REQUIRED)
set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
#Source files
set(SOURCE_FILE src/main.cc src/MyWin.cc src/Game24.cc)
#Compile Resource
set(RESOURCE_LIST
window.ui)
compile_gresources(RESOURCE_FILE
XML_OUT
TYPE EMBED_C
RESOURCES ${RESOURCE_LIST}
PREFIX "/org/gtk/daleclack"
SOURCE_DIR ${PROJECT_SOURCE_DIR}/res)
# Add a custom target to the makefile. Now make builds our resource file.
# It depends on the output RESOURCE_FILE.
add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
#For win32 platform,use rc resource and .ico icon
if(WIN32)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(app_WINRC ../icon.rc)
set_property(SOURCE ../icon.rc APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
)
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} ${SOURCE_FILE} ${RESOURCE_FILE})
add_custom_command( TARGET ${PROJECT_NAME}
COMMAND echo * > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo **/* > ${CMAKE_BINARY_DIR}/.hgignore)
else()
add_executable(${PROJECT_NAME} ${SOURCE_FILE} ${RESOURCE_FILE})
add_custom_command( TARGET ${PROJECT_NAME}
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
endif(WIN32)
#Add command to generate .gitignore and .mo files
# add_custom_command( TARGET ${PROJECT_NAME}
# COMMAND mkdir -p ${PO_DIR}
# COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${CMAKE_SOURCE_DIR}/po/zh_CN.po -o ${PO_DIR}/${PROJECT_NAME}.mo)
SET (CMAKE_EXTRA_CXX_FLAGS ${GTKMM3_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES} -lpthread)

View File

@ -0,0 +1,67 @@
#: src/MyWin.cc:8
msgid "Open Image"
msgstr "打开图像文件"
#: src/MyWin.cc:11
msgid "Position"
msgstr "位置"
#: src/MyWin.cc:12
msgid "rgb()/rgba() for css3"
msgstr "用于css3的rgb()/rgba()代码"
#: src/MyWin.cc:13
msgid "(A)RGB Code"
msgstr "(A)RGB代码"
#: src/MyWin.cc:16
msgid "Color Settings And Position info"
msgstr "颜色与位置信息"
#: src/MyWin.cc:18
msgid "Copy Css3 Code"
msgstr "复制css3代码"
#: src/MyWin.cc:19
msgid "Copy (A)RGB String"
msgstr "复制(A)RGB代码"
#: src/MyWin.cc:20
msgid "Pick Color"
msgstr "拾取颜色"
#: src/MyWin.cc:22
msgid "Color Picker"
msgstr "颜色拾取器"
#: src/MyWin.cc:152
msgid "Open a image file"
msgstr "打开图像文件"
#: src/MyWin.cc:153
msgid "OK"
msgstr "确定"
#: src/MyWin.cc:153
msgid "Cancel"
msgstr "取消"
#: src/MyWin.cc:157
msgid "Image Files"
msgstr "图像文件"
#: src/MyWin.cc:172
msgid "Any Files"
msgstr "所有文件"
msgid "Color Panel"
msgstr "调色板"
msgid "Color Reference"
msgstr "颜色参考"
msgid "Color:"
msgstr "颜色:"
msgid "Copy Color Code"
msgstr "复制颜色代码"

View File

@ -0,0 +1,385 @@
<?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="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Input answer:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</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">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=4 n-rows=5 -->
<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">1</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">1</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">1</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">2</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">2</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">2</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">3</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">3</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">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">4</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">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">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">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">4</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">4</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">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</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="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">1</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">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,156 @@
// 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
void Game24::startgame(string user_result)
{
bool winned = false;
// Format result number
if (user_result[user_result.length()] != ')' || user_result[0] != '(')
{
user_result = '(' + user_result + ')';
}
// Check user input and the results
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;
}
}
// If lost, output information
if (!winned)
{
std::cout << "Lost" << std::endl;
}
}
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:
void 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,63 @@
#include "MyWin.hh"
MyWin::MyWin(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade)
: Gtk::Window(cobject),
ref_builder(ref_Glade)
{
// Get Widgets
ref_builder->get_widget("label_numbers",label_numbers);
ref_builder->get_widget("btnstart",btnstart);
ref_builder->get_widget("btncheck",btncheck);
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,&MyWin::btnstart_clicked));
btnexit->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::hide));
btncheck->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btncheck_clicked));
for(int i = 0 ; i < 16;i++){
btns[i]->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,&MyWin::btns_clicked),btns[i]));
}
}
void MyWin::btns_clicked(Gtk::Button *button){
// Get Original text and add number from button
//Glib::ustring text = entry_ans->get_text();
Glib::ustring label = button->get_label();
//entry_ans->set_text(text+label);
}
void MyWin::btnstart_clicked(){
// Start Game
main_game.getnumbers();
label_numbers->set_label(main_game.numbers_char);
}
void MyWin::btncheck_clicked(){
// Check Answer
}
MyWin *MyWin::create()
{
// Create a new window
MyWin * window = nullptr;
auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/window.ui");
builder->get_widget_derived("window",window);
return window;
}

View File

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

View File

@ -0,0 +1,9 @@
#include "MyWin.hh"
int main(int argc,char **argv){
auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack");
auto window = MyWin::create();
return app->run(*window);
}