1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include "SidebarView.h"
void SidebarView::spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView *view) {
if(!view->editor->getActiveRoom())
return;
view->editor->getActiveRoom()->setHeight(gtk_spin_button_get_value(spinbutton));
}
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, 3, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(tableRoomData), 5);
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);
GtkWidget *labelHeight = gtk_label_new("Height:");
gtk_misc_set_alignment(GTK_MISC(labelHeight), 0.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelHeight, 0, 1, 2, 3);
spinButtonHeight = gtk_spin_button_new_with_range(0, 10000, 0.1f);
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonHeight), 2);
gtk_entry_set_alignment(GTK_ENTRY(spinButtonHeight), 1.0);
gtk_table_attach(GTK_TABLE(tableRoomData), spinButtonHeight, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL),
(GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0);
g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonHeightChanged), this);
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(editor->getActiveRoom()) {
gtk_entry_set_text(GTK_ENTRY(entryName), editor->getActiveRoom()->getName().c_str());
gtk_widget_set_sensitive(entryName, TRUE);
gchar *string = g_strdup_printf("%.2f", editor->getActiveRoom()->area());
gtk_label_set_text(GTK_LABEL(labelArea), string);
g_free(string);
string = g_strdup_printf("%.2f", editor->getActiveRoom()->perimeter());
gtk_label_set_text(GTK_LABEL(labelPerimeter), string);
g_free(string);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), editor->getActiveRoom()->getHeight());
gtk_widget_set_sensitive(spinButtonHeight, TRUE);
}
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);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), 0.0);
gtk_widget_set_sensitive(spinButtonHeight, FALSE);
}
}
|