From ddebc59336b71accc9887004b0f5c9a4bb17eb6b Mon Sep 17 00:00:00 2001 From: neoraider Date: Thu, 18 Oct 2007 22:07:02 +0000 Subject: zoomedit: UIManager gekapselt + einige kleine Fixes. --- EditManager.cpp | 6 ++-- Makefile.am | 2 +- Makefile.in | 26 +++++++-------- UIManager.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++ UIManager.h | 34 +++++++++++++++++++ Window.cpp | 7 ++-- Window.h | 3 ++ ui.cpp | 102 -------------------------------------------------------- ui.h | 11 ------ 9 files changed, 139 insertions(+), 134 deletions(-) create mode 100644 UIManager.cpp create mode 100644 UIManager.h delete mode 100644 ui.cpp delete mode 100644 ui.h diff --git a/EditManager.cpp b/EditManager.cpp index d2e65ce..5822ffc 100644 --- a/EditManager.cpp +++ b/EditManager.cpp @@ -61,10 +61,10 @@ void EditManager::finishRoom() { } void EditManager::addVertex(const Vertex &v) { - if(mode != ADD || !activeRoom) + if(mode != ADD) return; - activeRoom->push_back(v); + newRoom.push_back(v); window->update(); } @@ -103,7 +103,7 @@ void EditManager::buttonPress(unsigned int button) { switch(mode) { case VIEW: - activeRoom = getHoveredRoom();; + activeRoom = getHoveredRoom(); break; case ADD: diff --git a/Makefile.am b/Makefile.am index a95c2ae..e1bfcce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ bin_PROGRAMS = zoomedit -zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.cpp Vertex.cpp \ +zoomedit_SOURCES = zoomedit.cpp UIManager.cpp draw.cpp Vertex.cpp \ Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ diff --git a/Makefile.in b/Makefile.in index db8f2e6..e3f4308 100644 --- a/Makefile.in +++ b/Makefile.in @@ -49,7 +49,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \ - zoomedit-ui.$(OBJEXT) zoomedit-draw.$(OBJEXT) \ + zoomedit-UIManager.$(OBJEXT) zoomedit-draw.$(OBJEXT) \ zoomedit-Vertex.$(OBJEXT) zoomedit-Line.$(OBJEXT) \ zoomedit-Polygon.$(OBJEXT) zoomedit-Rectangle.$(OBJEXT) \ zoomedit-Room.$(OBJEXT) zoomedit-Triangle.$(OBJEXT) \ @@ -176,7 +176,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -zoomedit_SOURCES = zoomedit.cpp ui.cpp draw.cpp Vertex.cpp \ +zoomedit_SOURCES = zoomedit.cpp UIManager.cpp draw.cpp Vertex.cpp \ Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ @@ -283,11 +283,11 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarView.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Triangle.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-UIManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Window.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-WindowManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-draw.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-zoomedit.Po@am__quote@ .cpp.o: @@ -318,19 +318,19 @@ zoomedit-zoomedit.obj: zoomedit.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-zoomedit.obj `if test -f 'zoomedit.cpp'; then $(CYGPATH_W) 'zoomedit.cpp'; else $(CYGPATH_W) '$(srcdir)/zoomedit.cpp'; fi` -zoomedit-ui.o: ui.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ui.o -MD -MP -MF $(DEPDIR)/zoomedit-ui.Tpo -c -o zoomedit-ui.o `test -f 'ui.cpp' || echo '$(srcdir)/'`ui.cpp -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ui.Tpo $(DEPDIR)/zoomedit-ui.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ui.cpp' object='zoomedit-ui.o' libtool=no @AMDEPBACKSLASH@ +zoomedit-UIManager.o: UIManager.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-UIManager.o -MD -MP -MF $(DEPDIR)/zoomedit-UIManager.Tpo -c -o zoomedit-UIManager.o `test -f 'UIManager.cpp' || echo '$(srcdir)/'`UIManager.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-UIManager.Tpo $(DEPDIR)/zoomedit-UIManager.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='UIManager.cpp' object='zoomedit-UIManager.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-ui.o `test -f 'ui.cpp' || echo '$(srcdir)/'`ui.cpp +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-UIManager.o `test -f 'UIManager.cpp' || echo '$(srcdir)/'`UIManager.cpp -zoomedit-ui.obj: ui.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-ui.obj -MD -MP -MF $(DEPDIR)/zoomedit-ui.Tpo -c -o zoomedit-ui.obj `if test -f 'ui.cpp'; then $(CYGPATH_W) 'ui.cpp'; else $(CYGPATH_W) '$(srcdir)/ui.cpp'; fi` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-ui.Tpo $(DEPDIR)/zoomedit-ui.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ui.cpp' object='zoomedit-ui.obj' libtool=no @AMDEPBACKSLASH@ +zoomedit-UIManager.obj: UIManager.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-UIManager.obj -MD -MP -MF $(DEPDIR)/zoomedit-UIManager.Tpo -c -o zoomedit-UIManager.obj `if test -f 'UIManager.cpp'; then $(CYGPATH_W) 'UIManager.cpp'; else $(CYGPATH_W) '$(srcdir)/UIManager.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-UIManager.Tpo $(DEPDIR)/zoomedit-UIManager.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='UIManager.cpp' object='zoomedit-UIManager.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-ui.obj `if test -f 'ui.cpp'; then $(CYGPATH_W) 'ui.cpp'; else $(CYGPATH_W) '$(srcdir)/ui.cpp'; fi` +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-UIManager.obj `if test -f 'UIManager.cpp'; then $(CYGPATH_W) 'UIManager.cpp'; else $(CYGPATH_W) '$(srcdir)/UIManager.cpp'; fi` zoomedit-draw.o: draw.cpp @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-draw.o -MD -MP -MF $(DEPDIR)/zoomedit-draw.Tpo -c -o zoomedit-draw.o `test -f 'draw.cpp' || echo '$(srcdir)/'`draw.cpp diff --git a/UIManager.cpp b/UIManager.cpp new file mode 100644 index 0000000..e78898b --- /dev/null +++ b/UIManager.cpp @@ -0,0 +1,82 @@ +#include "UIManager.h" + + +const gchar* const UIManager::uiData = (const gchar*) +"" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" +""; + +void UIManager::handleAction(GtkAction *action, UIManager *uiManager) { + //const gchar* name = gtk_action_get_name(action); + + /*if(!strcmp(name, "zoomIn")) + zoomInCentered(1.2f); + else if(!strcmp(name, "zoomOut")) + zoomOutCentered(1.2f);*/ +} + +GtkActionGroup* UIManager::createActions() { + GtkActionGroup *actionGroup = gtk_action_group_new("actions"); + GtkAction *action; + + action = gtk_action_new("fileMenu", "_File", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("toolbar1", "Toolbar", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("new", "_New", NULL, GTK_STOCK_NEW); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("open", "_Open", NULL, GTK_STOCK_OPEN); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("save", "_Save", NULL, GTK_STOCK_SAVE); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("saveAs", "Save _As", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("zoomIn", "Zoom _in", NULL, GTK_STOCK_ZOOM_IN); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("zoomOut", "Zoom _out", NULL, GTK_STOCK_ZOOM_OUT); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("quit", "_Quit", NULL, GTK_STOCK_QUIT); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(gtk_main_quit), NULL); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + return actionGroup; +} + +UIManager::UIManager() { + uiManager = gtk_ui_manager_new(); + + gtk_ui_manager_add_ui_from_string(uiManager, uiData, -1, NULL); + + gtk_ui_manager_insert_action_group(uiManager, createActions(), 0); + + gtk_ui_manager_ensure_update(uiManager); +} + +UIManager::~UIManager() { + g_object_unref(G_OBJECT(uiManager)); +} diff --git a/UIManager.h b/UIManager.h new file mode 100644 index 0000000..09000ac --- /dev/null +++ b/UIManager.h @@ -0,0 +1,34 @@ +#ifndef UIMANAGER_H_ +#define UIMANAGER_H_ + +#include + + +class UIManager { + private: + static const gchar* const uiData; + + GtkUIManager *uiManager; + + static void handleAction(GtkAction *action, UIManager *uiManager); + + GtkActionGroup* createActions(); + + public: + UIManager(); + virtual ~UIManager(); + + GtkWidget* getMenu() { + return gtk_ui_manager_get_widget(uiManager, "/ui/menubar"); + } + + GtkWidget* getToolbar() { + return gtk_ui_manager_get_widget(uiManager, "/ui/toolbar1"); + } + + GtkAccelGroup* getAccels() { + return gtk_ui_manager_get_accel_group(uiManager); + } +}; + +#endif /*UIMANAGER_H_*/ diff --git a/Window.cpp b/Window.cpp index 74cfdb2..a1e3917 100644 --- a/Window.cpp +++ b/Window.cpp @@ -1,6 +1,5 @@ #include "Window.h" #include "WindowManager.h" -#include "ui.h" gboolean Window::deleteEvent(GtkWidget *widget, GdkEvent *event, Window *window) { @@ -23,10 +22,10 @@ Window::Window(GdkGLConfig *glconfig, WindowManager *manager) GtkWidget *vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_box_pack_start(GTK_BOX(vbox), getMenu(), FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), getToolbar(), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), uiManager.getMenu(), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), uiManager.getToolbar(), FALSE, FALSE, 0); - gtk_window_add_accel_group(GTK_WINDOW(window), getAccels()); + gtk_window_add_accel_group(GTK_WINDOW(window), uiManager.getAccels()); GtkWidget *hPaned = gtk_hpaned_new(); gtk_box_pack_end(GTK_BOX(vbox), hPaned, TRUE, TRUE, 0); diff --git a/Window.h b/Window.h index 1b44439..e58b786 100644 --- a/Window.h +++ b/Window.h @@ -3,6 +3,7 @@ #include #include +#include "UIManager.h" #include "Drawer.h" #include "SidebarManager.h" #include "EditManager.h" @@ -16,6 +17,8 @@ class Window { private: GtkWidget *window; + UIManager uiManager; + EditManager editor; Drawer drawer; diff --git a/ui.cpp b/ui.cpp deleted file mode 100644 index 3ed249a..0000000 --- a/ui.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "ui.h" -#include "draw.h" -#include -#include - - -static const gchar *uiData = -"" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" -""; - - -static void handleAction(GtkAction *action, gpointer user_data) { - //const gchar* name = gtk_action_get_name(action); - - /*if(!strcmp(name, "zoomIn")) - zoomInCentered(1.2f); - else if(!strcmp(name, "zoomOut")) - zoomOutCentered(1.2f);*/ -} - -static GtkActionGroup *createActions() { - GtkActionGroup *actionGroup = gtk_action_group_new("actions"); - GtkAction *action; - - action = gtk_action_new("fileMenu", "_File", NULL, NULL); - gtk_action_group_add_action(actionGroup, action); - - action = gtk_action_new("toolbar1", "Toolbar", NULL, NULL); - gtk_action_group_add_action(actionGroup, action); - - action = gtk_action_new("new", "_New", NULL, GTK_STOCK_NEW); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - action = gtk_action_new("open", "_Open", NULL, GTK_STOCK_OPEN); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - action = gtk_action_new("save", "_Save", NULL, GTK_STOCK_SAVE); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - action = gtk_action_new("saveAs", "Save _As", NULL, NULL); - gtk_action_group_add_action(actionGroup, action); - - action = gtk_action_new("zoomIn", "Zoom _in", NULL, GTK_STOCK_ZOOM_IN); - g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), NULL); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - action = gtk_action_new("zoomOut", "Zoom _out", NULL, GTK_STOCK_ZOOM_OUT); - g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), NULL); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - action = gtk_action_new("quit", "_Quit", NULL, GTK_STOCK_QUIT); - g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(gtk_main_quit), NULL); - gtk_action_group_add_action_with_accel(actionGroup, action, NULL); - - return actionGroup; -} - -static GtkUIManager* getUIManager() { - static GtkUIManager *uiManager = NULL; - - if(!uiManager) { - - - uiManager = gtk_ui_manager_new(); - gtk_ui_manager_add_ui_from_string(uiManager, uiData, -1, NULL); - - gtk_ui_manager_insert_action_group(uiManager, createActions(), 0); - - gtk_ui_manager_ensure_update(uiManager); - } - - return uiManager; -} - - -GtkWidget* getMenu() { - return gtk_ui_manager_get_widget(getUIManager(), "/ui/menubar"); -} - -GtkWidget* getToolbar() { - return gtk_ui_manager_get_widget(getUIManager(), "/ui/toolbar1"); -} - -GtkAccelGroup *getAccels() { - return gtk_ui_manager_get_accel_group(getUIManager()); -} diff --git a/ui.h b/ui.h deleted file mode 100644 index c400b5d..0000000 --- a/ui.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef UI_H_ -#define UI_H_ - -#include - - -GtkWidget* getMenu(); -GtkWidget* getToolbar(); -GtkAccelGroup *getAccels(); - -#endif /*MENU_H_*/ -- cgit v1.2.3