diff options
author | neoraider <devnull@localhost> | 2007-10-19 00:07:02 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-10-19 00:07:02 +0200 |
commit | ddebc59336b71accc9887004b0f5c9a4bb17eb6b (patch) | |
tree | f6fec8577a50e536167c1352e8148a18c2e2f0b7 | |
parent | 2bc9bb15dcc9691f6946eaa7a03370814bad0b8e (diff) | |
download | zoomedit-ddebc59336b71accc9887004b0f5c9a4bb17eb6b.tar zoomedit-ddebc59336b71accc9887004b0f5c9a4bb17eb6b.zip |
zoomedit: UIManager gekapselt + einige kleine Fixes.
-rw-r--r-- | EditManager.cpp | 6 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | Makefile.in | 26 | ||||
-rw-r--r-- | UIManager.cpp (renamed from ui.cpp) | 52 | ||||
-rw-r--r-- | UIManager.h | 34 | ||||
-rw-r--r-- | Window.cpp | 7 | ||||
-rw-r--r-- | Window.h | 3 | ||||
-rw-r--r-- | ui.h | 11 |
8 files changed, 73 insertions, 68 deletions
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 @@ -1,10 +1,7 @@ -#include "ui.h" -#include "draw.h" -#include <gtk/gtk.h> -#include <string.h> +#include "UIManager.h" -static const gchar *uiData = +const gchar* const UIManager::uiData = (const gchar*) "<ui>" "<menubar>" "<menu action=\"fileMenu\">" @@ -18,14 +15,13 @@ static const gchar *uiData = "</menubar>" "<toolbar action=\"toolbar1\">" "<separator/>" - "<toolitem action=\"zoomIn\"/>" - "<toolitem action=\"zoomOut\"/>" + "<toolitem action=\"zoomIn\"/>" + "<toolitem action=\"zoomOut\"/>" "<separator/>" "</toolbar>" "</ui>"; - -static void handleAction(GtkAction *action, gpointer user_data) { +void UIManager::handleAction(GtkAction *action, UIManager *uiManager) { //const gchar* name = gtk_action_get_name(action); /*if(!strcmp(name, "zoomIn")) @@ -34,7 +30,7 @@ static void handleAction(GtkAction *action, gpointer user_data) { zoomOutCentered(1.2f);*/ } -static GtkActionGroup *createActions() { +GtkActionGroup* UIManager::createActions() { GtkActionGroup *actionGroup = gtk_action_group_new("actions"); GtkAction *action; @@ -57,11 +53,11 @@ static GtkActionGroup *createActions() { 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); + 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), NULL); + 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); @@ -71,32 +67,16 @@ static GtkActionGroup *createActions() { return actionGroup; } -static GtkUIManager* getUIManager() { - static GtkUIManager *uiManager = NULL; +UIManager::UIManager() { + uiManager = gtk_ui_manager_new(); - 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); - } + gtk_ui_manager_add_ui_from_string(uiManager, uiData, -1, NULL); - return uiManager; -} - - -GtkWidget* getMenu() { - return gtk_ui_manager_get_widget(getUIManager(), "/ui/menubar"); -} - -GtkWidget* getToolbar() { - return gtk_ui_manager_get_widget(getUIManager(), "/ui/toolbar1"); + gtk_ui_manager_insert_action_group(uiManager, createActions(), 0); + + gtk_ui_manager_ensure_update(uiManager); } -GtkAccelGroup *getAccels() { - return gtk_ui_manager_get_accel_group(getUIManager()); +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 <gtk/gtk.h> + + +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_*/ @@ -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); @@ -3,6 +3,7 @@ #include <gtk/gtk.h> #include <gtk/gtkgl.h> +#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; @@ -1,11 +0,0 @@ -#ifndef UI_H_ -#define UI_H_ - -#include <gtk/gtk.h> - - -GtkWidget* getMenu(); -GtkWidget* getToolbar(); -GtkAccelGroup *getAccels(); - -#endif /*MENU_H_*/ |