diff --git a/Gtk4/gtk158_minesweeper4/CMakeLists.txt b/Gtk4/gtk158_minesweeper4/CMakeLists.txt index 823df84..b883d37 100644 --- a/Gtk4/gtk158_minesweeper4/CMakeLists.txt +++ b/Gtk4/gtk158_minesweeper4/CMakeLists.txt @@ -26,7 +26,7 @@ link_directories (${GTK4_LIBRARY_DIRS}) # set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES) #Source files -set(SOURCE_FILE src/main.cpp src/MineSweeper.cpp) +set(SOURCE_FILE src/main.cpp src/MineSweeper.cpp src/MineCell.cpp) #Compile Resource diff --git a/Gtk4/gtk158_minesweeper4/src/MineCell.cpp b/Gtk4/gtk158_minesweeper4/src/MineCell.cpp new file mode 100644 index 0000000..ed8fe18 --- /dev/null +++ b/Gtk4/gtk158_minesweeper4/src/MineCell.cpp @@ -0,0 +1,50 @@ +#include "MineCell.h" + +struct _MineCell +{ + GtkButton parent_instance; + gboolean has_mine = FALSE; + gboolean cleared = FALSE; + int mines_around; + int x, y; +}; + +G_DEFINE_TYPE(MineCell, mine_cell, GTK_TYPE_BUTTON) + +static void mine_cell_init(MineCell *self) +{ + gtk_button_set_icon_name(GTK_BUTTON(self), ""); + gtk_button_set_has_frame(GTK_BUTTON(self), FALSE); + gtk_widget_set_size_request(GTK_WIDGET(self), 40, 40); + self->mines_around = 0; + self->has_mine = FALSE; +} + +static void mine_cell_class_init(MineCellClass *klass) +{ +} + +void mine_cell_get_configs(MineCell *cell, gboolean &cell_has_mine, gboolean &cell_cleared, + int &cell_mines_around, int &cell_x, int &cell_y) +{ + cell_has_mine = cell->has_mine; + cell_cleared = cell->cleared; + cell_mines_around = cell->mines_around; + cell_x = cell->x; + cell_y = cell->y; +} + +void mine_cell_set_configs(MineCell *cell, gboolean cell_has_mine, gboolean cell_cleared, + int cell_mines_around, int cell_x, int cell_y) +{ + cell->has_mine = cell_has_mine; + cell->cleared = cell_cleared; + cell->mines_around = cell_mines_around; + cell->x = cell_x; + cell->y = cell->y; +} + +MineCell *mine_cell_new() +{ + return Mine_Cell(g_object_new(mine_cell_get_type(), NULL)); +} diff --git a/Gtk4/gtk158_minesweeper4/src/MineCell.h b/Gtk4/gtk158_minesweeper4/src/MineCell.h new file mode 100644 index 0000000..f537c98 --- /dev/null +++ b/Gtk4/gtk158_minesweeper4/src/MineCell.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +G_DECLARE_FINAL_TYPE(MineCell, mine_cell, Mine, Cell, GtkButton) + +MineCell *mine_cell_new(); + +void mine_cell_get_configs(MineCell *cell, gboolean &cell_has_mine, gboolean &cell_cleared, + int &cell_mines_around, int &cell_x, int &cell_y); + +void mine_cell_set_configs(MineCell *cell, gboolean cell_has_mine, gboolean cell_cleared, + int cell_mines_around, int cell_x, int cell_y); diff --git a/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp b/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp index 62ddf79..dbe42bf 100644 --- a/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp +++ b/Gtk4/gtk158_minesweeper4/src/MineSweeper.cpp @@ -1,4 +1,5 @@ #include "MineSweeper.h" +#include "MineCell.h" struct _MineSweeper {