Add gtk130

This commit is contained in:
daleclack 2022-05-26 18:45:23 +08:00
parent c89ed7e1ae
commit 9327827e59
8 changed files with 717 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -0,0 +1,73 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk130_calc 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)
#Compile Resource
set(RESOURCE_LIST
icons/scalable/status/24game.svg
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,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,353 @@
<?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="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Input expression to calculate:</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,123 @@
#include "MyWin.hh"
MyWin::MyWin(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, &MyWin::btnstart_clicked));
btnexit->signal_clicked().connect(sigc::mem_fun(*this, &MyWin::hide));
btnnext->signal_clicked().connect(sigc::mem_fun(*this, &MyWin::btnnext_clicked));
btncheck->signal_clicked().connect(sigc::mem_fun(*this, &MyWin::btncheck_clicked));
btnclear->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnclear_clicked));
for (int i = 0; i < 16; i++)
{
btns[i]->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &MyWin::btns_clicked), btns[i]));
}
entry_ans->signal_grab_focus().connect(sigc::mem_fun(*this, &MyWin::entry_ans_focus));
}
void MyWin::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 MyWin::entry_ans_focus()
{
focused = true;
}
void MyWin::btnstart_clicked()
{
// Start Game
if (winned)
{
//label_numbers->set_label(main_game.numbers_char);
}
else
{
//label-numbers->set_label(tmp);
}
// Save the numbers
//tmp = label_numbers->get_label();
}
void MyWin::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 MyWin::btnnext_clicked(){
//main_game.getnumbers();
//label_numbers->set_label(main_game.numbers_char);
}
void MyWin::btnclear_clicked(){
// Clear the text
entry_ans->set_text("");
}
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,31 @@
#pragma once
#include <gtkmm.h>
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;
// Calculator Class
int pos;
bool focused, winned;
Glib::ustring tmp;
// Child widgets
Gtk::Entry *entry_ans;
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,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);
}