diff options
author | neoraider <devnull@localhost> | 2007-10-05 01:38:05 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-10-05 01:38:05 +0200 |
commit | b660b965bcb679e53cc89e7b8903190d2d162ff6 (patch) | |
tree | 31d2e3309e0906e03a8e415f430a99f8716b23b6 /SidebarView.cpp | |
parent | ea3fc9f27f6feb14ea3b7cfc8b1e921195dd3c3f (diff) | |
download | zoomedit-b660b965bcb679e53cc89e7b8903190d2d162ff6.tar zoomedit-b660b965bcb679e53cc89e7b8903190d2d162ff6.zip |
zoomedit: Gro?e Teile der GUI in Klassen gekapselt.
Diffstat (limited to 'SidebarView.cpp')
-rw-r--r-- | SidebarView.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/SidebarView.cpp b/SidebarView.cpp new file mode 100644 index 0000000..82d4713 --- /dev/null +++ b/SidebarView.cpp @@ -0,0 +1,88 @@ +#include "SidebarView.h" +#include "edit.h" + + +void SidebarView::buttonClicked(GtkButton *button, SidebarView *sidebar) { + sidebar->editor->addRoom(); +} + +SidebarView::SidebarView(EditManager *editor) { + this->editor = editor; + + sidebar = gtk_vbox_new(FALSE, 0); + g_object_ref_sink(G_OBJECT(sidebar)); + + GtkWidget *labelRoomInfo = gtk_label_new(NULL); + gtk_label_set_markup(GTK_LABEL(labelRoomInfo), "<b>Room info:</b>"); + gtk_misc_set_alignment(GTK_MISC(labelRoomInfo), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(sidebar), labelRoomInfo, FALSE, FALSE, 5); + + gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5); + + GtkWidget *labelName = gtk_label_new("Name:"); + gtk_misc_set_alignment(GTK_MISC(labelName), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(sidebar), labelName, FALSE, FALSE, 0); + + entryName = gtk_entry_new(); + gtk_widget_set_sensitive(entryName, FALSE); + //g_signal_connect(G_OBJECT(entryName), "focus-out-event", G_CALLBACK(sidebarNameFocusOutEvent), NULL); + //gtk_widget_add_events(entryName, GDK_FOCUS_CHANGE_MASK); + gtk_box_pack_start(GTK_BOX(sidebar), entryName, FALSE, FALSE, 0); + + GtkWidget *tableRoomData = gtk_table_new(2, 2, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(tableRoomData), 5); + gtk_table_set_col_spacings(GTK_TABLE(tableRoomData), 10); + gtk_box_pack_start(GTK_BOX(sidebar), tableRoomData, FALSE, FALSE, 5); + + GtkWidget *labelAreaLabel = gtk_label_new("Room area:"); + gtk_misc_set_alignment(GTK_MISC(labelAreaLabel), 0.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelAreaLabel, 0, 1, 0, 1); + + labelArea = gtk_label_new(NULL); + gtk_misc_set_alignment(GTK_MISC(labelArea), 1.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelArea, 1, 2, 0, 1); + + GtkWidget *labelPerimeterLabel = gtk_label_new("Room perimeter:"); + gtk_misc_set_alignment(GTK_MISC(labelPerimeterLabel), 0.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeterLabel, 0, 1, 1, 2); + + labelPerimeter = gtk_label_new(NULL); + gtk_misc_set_alignment(GTK_MISC(labelPerimeter), 1.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeter, 1, 2, 1, 2); + + buttonAdd = gtk_button_new_with_label("Add room"); + g_signal_connect(G_OBJECT(buttonAdd), "clicked", G_CALLBACK(buttonClicked), this); + gtk_box_pack_end(GTK_BOX(sidebar), buttonAdd, FALSE, FALSE, 0); + + gtk_widget_show_all(sidebar); +} + +SidebarView::~SidebarView() { + g_object_unref(G_OBJECT(sidebar)); +} + +GtkWidget* SidebarView::getWidget() { + return sidebar; +} + +void SidebarView::update() { + if(getActiveRoom()) { + gtk_entry_set_text(GTK_ENTRY(entryName), getActiveRoom()->getName().c_str()); + gtk_widget_set_sensitive(entryName, TRUE); + + gchar *string = g_strdup_printf("%.2f", getActiveRoom()->area()); + gtk_label_set_text(GTK_LABEL(labelArea), string); + g_free(string); + + string = g_strdup_printf("%.2f", getActiveRoom()->perimeter()); + gtk_label_set_text(GTK_LABEL(labelPerimeter), string); + g_free(string); + } + else { + gtk_entry_set_text(GTK_ENTRY(entryName), ""); + gtk_widget_set_sensitive(entryName, FALSE); + + gtk_label_set_text(GTK_LABEL(labelArea), NULL); + gtk_label_set_text(GTK_LABEL(labelPerimeter), NULL); + } +} |