From 7323fd15e825a747786e9a34e24e0b519a439dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 2 Apr 2020 00:32:11 +0200 Subject: [PATCH] Create basic GObject structure for GraphView --- app/src/main.c | 36 +++++++++++++++++++++-- lib/CMakeLists.txt | 6 ++-- lib/include/gtk-graph-view.h | 49 +++++++++++++++++++++++++++++++ lib/src/gtk-graph-view.c | 56 ++++++++++++++++++++++++++++++++++-- 4 files changed, 139 insertions(+), 8 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 1c2e57d..9279e65 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -1,18 +1,48 @@ +/* + * This file is part of GtkGraphView. + * +* Foobar is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* GtkGraphView is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GtkGraphView. If not, see . +*/ + #include #include #include +static gboolean main_window_delete_event(GtkWidget *window, gpointer user) +{ + (void)user; + + gtk_widget_destroy(window); + gtk_main_quit(); + + return FALSE; +} + int main(int argc, char **argv) { GtkWidget *main_window; - - printf("Hello World!\n"); + GtkWidget *graph_view; gtk_init(&argc, &argv); main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_show(main_window); + gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 800); + g_signal_connect(main_window, "delete-event", G_CALLBACK(main_window_delete_event), NULL); + graph_view = gtk_graph_view_new(); + gtk_container_add(GTK_CONTAINER(main_window), graph_view); + + gtk_widget_show_all(main_window); gtk_main(); return 0; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7c42e86..c208d70 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,12 +4,14 @@ project(gtkgraphview LANGUAGES C) find_package(PkgConfig REQUIRED) pkg_search_module(GLIB REQUIRED glib-2.0) pkg_check_modules(GTK3 REQUIRED gtk+-3.0) +pkg_check_modules(EPOXY REQUIRED epoxy) add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) aux_source_directory("src" SRC_DIR) add_library(${PROJECT_NAME} SHARED ${SRC_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${GTK3_LDFLAGS}) -target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS}) +target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${EPOXY_LDFLAGS}) +target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${EPOXY_LINK_DIRS}) target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS}) diff --git a/lib/include/gtk-graph-view.h b/lib/include/gtk-graph-view.h index e69de29..703cad5 100644 --- a/lib/include/gtk-graph-view.h +++ b/lib/include/gtk-graph-view.h @@ -0,0 +1,49 @@ +/* + * This file is part of GtkGraphView. + * + * Foobar is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GtkGraphView is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GtkGraphView. If not, see . + */ + +/** + * @file gtk-graph-view.h + * @brief header file for the GtkGraphView Widget + * @author Mario Hüttel + */ + +/** + * @addtogroup GtkGraphView + * @{ + */ + +#ifndef __GTK_GRAPH_VIEW_H__ +#define __GTK_GRAPH_VIEW_H__ + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_GRAPH_VIEW (gtk_graph_view_get_type()) + +G_DECLARE_FINAL_TYPE(GtkGraphView, gtk_graph_view, GTK, GRAPH_VIEW, GtkGLArea) + +/** + * @brief Instanciate new GtkGraphView object + * @return created object + */ +GtkWidget *gtk_graph_view_new(); + +G_END_DECLS + +#endif /* __GTK_GRAPH_VIEW_H__ */ + +/** @} */ diff --git a/lib/src/gtk-graph-view.c b/lib/src/gtk-graph-view.c index fff58e5..7f9a766 100644 --- a/lib/src/gtk-graph-view.c +++ b/lib/src/gtk-graph-view.c @@ -1,6 +1,56 @@ -#include +/* + * This file is part of GtkGraphView. + * +* Foobar is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* GtkGraphView is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GtkGraphView. If not, see . +*/ -int test() +#include +#include + +struct _GtkGraphView { + GtkGLArea parent; +}; + +typedef struct { + int i; /**< @note This is just a dummy. Remove! */ +} GtkGraphViewPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE(GtkGraphView, gtk_graph_view, GTK_TYPE_GL_AREA) + +/** + * @brief Init class structure of GtkGraphView + * @param klass Class structure + */ +static void gtk_graph_view_class_init(GtkGraphViewClass *klass) { - return 1; + (void)klass; + + return; +} + +/** + * @brief Init a new GtkGraphView GObject + * @param obj Object to initialize + */ +static void gtk_graph_view_init(GtkGraphView *obj) +{ + GtkGraphViewPrivate *priv; + + priv = gtk_graph_view_get_instance_private(obj); + priv->i = 0; +} + +GtkWidget *gtk_graph_view_new() +{ + return gtk_widget_new(GTK_TYPE_GRAPH_VIEW, NULL); }