From c18e22a667fa3189e6055547df96ff57749bfbef Mon Sep 17 00:00:00 2001 From: daleclack Date: Tue, 20 Feb 2024 11:01:20 +0800 Subject: [PATCH] Change lib of gtk158 to Gtk 4 --- Gtk4/gtk158_minesweeper4/CMakeLists.txt | 16 +++++++------- Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp | 23 ++++++++++++++++++++ Gtk4/gtk158_minesweeper4/src/MineSweeper.h | 7 ++++++ Gtk4/gtk158_minesweeper4/src/main.cpp | 18 +++++++++++++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp create mode 100644 Gtk4/gtk158_minesweeper4/src/MineSweeper.h create mode 100644 Gtk4/gtk158_minesweeper4/src/main.cpp diff --git a/Gtk4/gtk158_minesweeper4/CMakeLists.txt b/Gtk4/gtk158_minesweeper4/CMakeLists.txt index bb583f4..823df84 100644 --- a/Gtk4/gtk158_minesweeper4/CMakeLists.txt +++ b/Gtk4/gtk158_minesweeper4/CMakeLists.txt @@ -1,6 +1,6 @@ set(CMAKE_CXX_STANDARD 17) -cmake_minimum_required(VERSION 3.0.0) -project(gtk142_minesweeper3 VERSION 1.0.0) +cmake_minimum_required(VERSION 3.5.0) +project(gtk158_minesweeper4 VERSION 1.0.0) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros) include(GlibCompileResourcesSupport) @@ -17,16 +17,16 @@ include_directories(..) #Find PkgConfig to use gtkmm3 find_package (PkgConfig REQUIRED) -pkg_check_modules (GTKMM4 REQUIRED gtkmm-4.0) -include_directories (${GTKMM4_INCLUDE_DIRS}) -link_directories (${GTKMM4_LIBRARY_DIRS}) +pkg_check_modules (GTK4 REQUIRED gtk4) +include_directories (${GTK4_INCLUDE_DIRS}) +link_directories (${GTK4_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/MineSweeper.cc src/InputBox.cc src/ScoresWin.cc) +set(SOURCE_FILE src/main.cpp src/MineSweeper.cpp) #Compile Resource @@ -84,5 +84,5 @@ endif(WIN32) # 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 ${GTKMM4_CFLAGS_OTHER}) -target_link_libraries (${PROJECT_NAME} ${GTKMM4_LIBRARIES} -lpthread) +SET (CMAKE_EXTRA_CXX_FLAGS ${GTK4_CFLAGS_OTHER}) +target_link_libraries (${PROJECT_NAME} ${GTK4_LIBRARIES} -lpthread) diff --git a/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp b/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp new file mode 100644 index 0000000..62ddf79 --- /dev/null +++ b/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp @@ -0,0 +1,23 @@ +#include "MineSweeper.h" + +struct _MineSweeper +{ + GtkApplicationWindow parent_instance; +}; + +G_DEFINE_TYPE(MineSweeper, mine_sweeper, GTK_TYPE_APPLICATION_WINDOW) + +static void mine_sweeper_init(MineSweeper *self) +{ + +} + +static void mine_sweeper_class_init(MineSweeperClass *klass) +{ + +} + +MineSweeper *mine_sweeper_new() +{ + return MINE_SWEEPER(g_object_new(mine_sweeper_get_type(), NULL)); +} diff --git a/Gtk4/gtk158_minesweeper4/src/MineSweeper.h b/Gtk4/gtk158_minesweeper4/src/MineSweeper.h new file mode 100644 index 0000000..17996f2 --- /dev/null +++ b/Gtk4/gtk158_minesweeper4/src/MineSweeper.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +G_DECLARE_FINAL_TYPE(MineSweeper, mine_sweeper, MINE, SWEEPER, GtkApplicationWindow) + +MineSweeper *mine_sweeper_new(); diff --git a/Gtk4/gtk158_minesweeper4/src/main.cpp b/Gtk4/gtk158_minesweeper4/src/main.cpp new file mode 100644 index 0000000..a495845 --- /dev/null +++ b/Gtk4/gtk158_minesweeper4/src/main.cpp @@ -0,0 +1,18 @@ +#include "MineSweeper.h" + +static void gtkmain(GtkApplication *app, gpointer user_data) +{ + // Create MineSweeper window + MineSweeper *mine_sweeper = mine_sweeper_new(); + gtk_application_add_window(app, GTK_WINDOW(mine_sweeper)); + gtk_window_present(GTK_WINDOW(mine_sweeper)); +} + +int main(int argc, char **argv) +{ + // Create a app and run + GtkApplication *app; + app = gtk_application_new("org.gtk.daleclack", G_APPLICATION_NON_UNIQUE); + g_signal_connect(app, "activate", G_CALLBACK(gtkmain), NULL); + return g_application_run(G_APPLICATION(app), argc, argv); +} \ No newline at end of file