Add gtk147

This commit is contained in:
daleclack 2023-03-17 18:08:15 +08:00
parent eb0b0bd55e
commit 01893c600d
6 changed files with 113 additions and 1 deletions

View File

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

View File

@ -0,0 +1,61 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk147 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_package (PkgConfig REQUIRED)
pkg_check_modules (GTK4 REQUIRED gtk4)
include_directories (${GTK4_INCLUDE_DIRS})
link_directories (${GTK4_LIBRARY_DIRS})
#Compile Resource
#[[
set(RESOURCE_LIST
Yanni-Nightingale.mp3)
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})]]
#SOURCE FILES LIST
set(SOURCES src/main.cpp src/FileManager.cpp)
#For win32 platform,use rc resource and .ico icon
if(WIN32)
SET(CMAKE_RC_COMPILER 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} ${SOURCES})
else()
add_executable(${PROJECT_NAME} ${SOURCES})
endif(WIN32)
#Add command to generate .gitignore
add_custom_command(TARGET ${PROJECT_NAME}
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
SET (CMAKE_EXTRA_CXX_FLAGS ${GTK4_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTK4_LIBRARIES} -lpthread)

View File

@ -0,0 +1,19 @@
#include "FileManager.h"
struct _FileManager{
GtkWindow parent_instance;
};
G_DEFINE_TYPE(FileManager, file_manager, GTK_TYPE_WINDOW)
static void file_manager_init(FileManager *self){
}
static void file_manager_class_init(FileManagerClass *klass){
}
FileManager *file_manager_new(){
return FILE_MANAGER(g_object_new(file_manager_get_type(), NULL));
}

View File

@ -0,0 +1,7 @@
#pragma once
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE(FileManager, file_manager, FILE, MANAGER, GtkWindow)
FileManager *file_manager_new();

View File

@ -0,0 +1,20 @@
#include "FileManager.h"
static void gtkmain(GtkApplication *app, gpointer user_data){
// Create a main window
FileManager *file_win = file_manager_new();
// Add the window to the application
gtk_application_add_window(app, GTK_WINDOW(file_win));
// Show the window
gtk_window_present(GTK_WINDOW(file_win));
}
int main(int argc, char **argv)
{
// Create a application and run
GtkApplication *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);
}

View File

@ -59,8 +59,10 @@ MainWin::MainWin()
label1.set_valign(Gtk::Align::FILL); label1.set_valign(Gtk::Align::FILL);
main_box.append(label1); main_box.append(label1);
// Add buttons] // Background color for btn_box
btn_box.add_css_class("accdoration"); btn_box.add_css_class("accdoration");
// Add buttons
btn_main.set_has_frame(false); btn_main.set_has_frame(false);
btn_win1.set_has_frame(false); btn_win1.set_has_frame(false);
btn_win2.set_has_frame(false); btn_win2.set_has_frame(false);