Change lib of gtk158 to Gtk 4

This commit is contained in:
daleclack 2024-02-20 11:01:20 +08:00
parent 2092bd53fe
commit c18e22a667
4 changed files with 56 additions and 8 deletions

View File

@ -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)

View File

@ -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));
}

View File

@ -0,0 +1,7 @@
#pragma once
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE(MineSweeper, mine_sweeper, MINE, SWEEPER, GtkApplicationWindow)
MineSweeper *mine_sweeper_new();

View File

@ -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);
}