File: main.cpp

package info (click to toggle)
clanlib 1.0~svn3827-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 24,600 kB
  • sloc: cpp: 101,591; xml: 6,410; makefile: 1,743; ansic: 463; perl: 424; php: 247; sh: 53
file content (145 lines) | stat: -rw-r--r-- 5,688 bytes parent folder | download | duplicates (7)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

#include "precomp.h"
#include "main.h"
#include "form_view.h"
#include "property_list.h"

/////////////////////////////////////////////////////////////////////////////
// GUIEditor startup:

GUIEditor app;

int GUIEditor::main(int argc, char **argv)
{
	CL_SetupCore::init();
	CL_SetupDisplay::init();
	CL_SetupGL::init();
	CL_SetupGUI::init();

	try
	{
		CL_DisplayWindow window("ClanLib GUI Editor", 1024, 768, false, true);

		CL_ResourceManager resources("../../Resources/GUIStyleSilver/gui.xml", false);
		CL_StyleManager_Silver style(&resources);
		gui = new CL_GUIManager(&style);

		menubar = new CL_Menu(CL_Point(0, 0), gui, &style);
		menunode_file = new CL_MenuNode(menubar);
		menuitem_file = new CL_MenuItem("File", menunode_file, false, false);
		menunode_edit = new CL_MenuNode(menubar);
		menuitem_edit = new CL_MenuItem("Edit", menunode_edit, false, false);
		menunode_view = new CL_MenuNode(menubar);
		menuitem_view = new CL_MenuItem("View", menunode_view, false, false);
		menunode_help = new CL_MenuNode(menubar);
		menuitem_help = new CL_MenuItem("Help", menunode_help, false, false);

		menu_file = new CL_Menu(menunode_file, gui);
		menunode_new = new CL_MenuNode(menu_file);
		menuitem_new = new CL_MenuItem("New", menunode_new);
		menunode_open = new CL_MenuNode(menu_file);
		menuitem_open = new CL_MenuItem("Open", menunode_open);
		menunode_save = new CL_MenuNode(menu_file);
		menuitem_save = new CL_MenuItem("Save", menunode_save);
		menunode_exit = new CL_MenuNode(menu_file);
		menuitem_exit = new CL_MenuItem("Exit", menunode_exit);

		menu_edit = new CL_Menu(menunode_edit, gui);
		menunode_undo = new CL_MenuNode(menu_edit);
		menuitem_undo = new CL_MenuItem("Undo", menunode_undo);
		menunode_redo = new CL_MenuNode(menu_edit);
		menuitem_redo = new CL_MenuItem("Redo", menunode_redo);
		menunode_cut = new CL_MenuNode(menu_edit);
		menuitem_cut = new CL_MenuItem("Cut", menunode_cut);
		menunode_copy = new CL_MenuNode(menu_edit);
		menuitem_copy = new CL_MenuItem("Copy", menunode_copy);
		menunode_paste = new CL_MenuNode(menu_edit);
		menuitem_paste = new CL_MenuItem("Paste", menunode_paste);
		menunode_delete = new CL_MenuNode(menu_edit);
		menuitem_delete = new CL_MenuItem("Delete", menunode_delete);

		menu_view = new CL_Menu(menunode_view, gui);
		menunode_components = new CL_MenuNode(menu_view);
		menuitem_components = new CL_MenuItem("Components", menunode_components);
		menunode_connections = new CL_MenuNode(menu_view);
		menuitem_connections = new CL_MenuItem("Connections", menunode_connections);
		menunode_properties = new CL_MenuNode(menu_view);
		menuitem_properties = new CL_MenuItem("Properties", menunode_properties);
		menunode_tools = new CL_MenuNode(menu_view);
		menuitem_tools = new CL_MenuItem("Tools", menunode_tools);

		menu_help = new CL_Menu(menunode_help, gui);
		menunode_about = new CL_MenuNode(menu_help);
		menuitem_about = new CL_MenuItem("About ClanLib GUI Editor", menunode_about);

		frame_toolbox = new CL_Frame(CL_Rect(8, 8+20, 200, CL_Display::get_height()-8), gui);
		label_toolbox = new CL_Label(CL_Point(12, 8), "Tools:", frame_toolbox);
		list_tools = new CL_ListBox(CL_Rect(8, 24, frame_toolbox->get_width()-8, frame_toolbox->get_height()-8), frame_toolbox);

		frame_form = new CL_Frame(CL_Rect(208, 8+20, CL_Display::get_width()-208, CL_Display::get_height()-8), gui);
		label_form = new CL_Label(CL_Point(12, 8), "Form Layout:", frame_form);
		form_view = new FormView(CL_Rect(8, 24, frame_form->get_width()-8, frame_form->get_height()-8), frame_form);

		frame_propertylist = new CL_Frame(CL_Rect(CL_Display::get_width()-200, 8+20, CL_Display::get_width()-8, CL_Display::get_height()-8), gui);
		label_properties = new CL_Label(CL_Point(12, 8), "Properties:", frame_propertylist);
		property_list = new PropertyList(CL_Rect(8, 24, frame_propertylist->get_width()-8, frame_propertylist->get_height()-8), frame_propertylist);

		list_tools->insert_item("Select");
		std::map<std::string, CL_ComponentType *>::iterator it;
		for (it = CL_ComponentType::component_types.begin(); it != CL_ComponentType::component_types.end(); ++it)
		{
			list_tools->insert_item(it->first);
		}

		CL_SlotContainer slots;
		slots.connect(window.sig_window_close(), this, &GUIEditor::on_window_close);
		slots.connect(gui->sig_paint(), this, &GUIEditor::on_paint);
		slots.connect(gui->sig_resize(), this, &GUIEditor::on_resize);

		gui->show();
		gui->run();

		delete gui;
	}
	catch (CL_Error err)
	{
#ifdef WIN32
		MessageBox(0, err.message.c_str(), "ClanLib GUI Editor Fatal Error", MB_OK);
#else
		std::cout << "ClanLib GUI Editor Fatal Error" << err.message.c_str() << std::endl;
#endif
	}

	CL_SetupGL::deinit();
	CL_SetupDisplay::deinit();
	CL_SetupCore::deinit();

	return 0;
}

void GUIEditor::on_window_close()
{
	gui->quit();
}

void GUIEditor::on_paint()
{
	CL_Display::clear(CL_Color(240, 242, 244));
}

void GUIEditor::on_resize(int old_width, int old_height)
{
	int width = gui->get_width();
	int height = gui->get_height();

	menubar->set_width(width);

	frame_toolbox->set_position(CL_Rect(8, 8+20, 200, CL_Display::get_height()-8));
	list_tools->set_position(CL_Rect(8, 24, frame_toolbox->get_width()-8, frame_toolbox->get_height()-8));

	frame_form->set_position(CL_Rect(208, 8+20, CL_Display::get_width()-208, CL_Display::get_height()-8));
	form_view->set_position(CL_Rect(8, 24, frame_form->get_width()-8, frame_form->get_height()-8));

	frame_propertylist->set_position(CL_Rect(CL_Display::get_width()-200, 8+20, CL_Display::get_width()-8, CL_Display::get_height()-8));
	property_list->set_position(CL_Rect(8, 24, frame_propertylist->get_width()-8, frame_propertylist->get_height()-8));
}