File: create_component_window.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (131 lines) | stat: -rw-r--r-- 3,534 bytes parent folder | download
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
#include "create_component_window.h"

CreateComponentWindow::CreateComponentWindow(
									std::string type,
									CL_Component *parent, 
									ComponentStore *store,
									CL_StyleManager *style)
:
	CL_Window(
		CL_Rect(180, 100,  600, 300),
		"Create " + type + " component",
		parent,
		style),
	store(store)
{
	this->type=type;

	label_name=new CL_Label(CL_Rect(5,5,80,25),"Name:",get_client_area());
	component_name=new CL_InputBox(CL_Rect(90,5,200,25),get_client_area());

	but_create=new CL_Button(CL_Rect(210,5,300,25),"Create",get_client_area());
	slot_create=but_create->sig_clicked().connect(this, &CreateComponentWindow::on_create);

	but_cancel=new CL_Button(CL_Rect(310,5,400,25),"Cancel",get_client_area());
	slot_cancel=but_cancel->sig_clicked().connect(this, &CreateComponentWindow::on_cancel);

	fill_optionvalues_list();
	set_client_size(420, 50 + option_values.size() * 20);

	create_optionvalue_edit_list();
}

CreateComponentWindow::~CreateComponentWindow()
{

}


void CreateComponentWindow::fill_optionvalues_list()
{
	option_values.clear();

	CL_ComponentManager::component_type_map_t::iterator i;

	i=CL_ComponentManager::component_types.find(type);

	if (i!=CL_ComponentManager::component_types.end())
	{
		CL_ComponentType *comp_type=(*i).second;

		CL_ComponentType::option_map_t::iterator j;
		
		for (j=comp_type->options.begin();
			 j!=comp_type->options.end();
			 j++)
		{
			 option_values[(*j).first].type = (*j).second.type;
		}
	}
	
}

void CreateComponentWindow::create_optionvalue_edit_list()
{
	option_map_t::iterator it(option_values.begin());
	option_map_t::iterator it_end(option_values.end());

	// ok, we need to dynamicly create the list of labels and inputboxes so we can present them later on a on_paint
	for (int pos=0;it!=it_end;++it, ++pos)
	{
		new CL_Label(CL_Rect(5,35+pos*20,80,55+pos*20),(*it).first, get_client_area());
		switch ((*it).second.type)
		{
		case CL_ComponentType::SOptionType::STRING:
			{
				CL_InputBox *input = new CL_InputBox(CL_Rect(85,35+pos*20, 225, 55+pos*20), "", get_client_area());
				(*it).second.component = input;
			}
			break;
		case CL_ComponentType::SOptionType::NUMBER:
			{
				CL_InputBox *input = new CL_InputBox(CL_Rect(85,35+pos*20, 225, 55+pos*20), "0", get_client_area());
				input->set_text("0");
				(*it).second.component = input;
			}
			break;
		case CL_ComponentType::SOptionType::BOOL:
			{
				CL_CheckBox *box = new CL_CheckBox(CL_Point(85,35+pos*20), "", get_client_area());
				box->set_checked(false);
				(*it).second.component = box;
			}
			break;
		}
	} 
}

void CreateComponentWindow::on_create()
{
	ComponentStore::component_data_t c;
	c.name = component_name->get_text();

	// add component options
	CL_ComponentOptions options;
	option_map_t::iterator it(option_values.begin());
	option_map_t::iterator it_end(option_values.end());
	for (;it!=it_end;++it)
	{
		switch ((*it).second.type)
		{
		case CL_ComponentType::SOptionType::STRING:
		case CL_ComponentType::SOptionType::NUMBER:
			options.add_option((*it).first, ((CL_InputBox*) (*it).second.component)->get_text());
			break;
		case CL_ComponentType::SOptionType::BOOL:
			options.add_option((*it).first, ((CL_CheckBox*) (*it).second.component)->is_checked()?"1":"0");
			break;
		}
	}

	c.component = CL_ComponentManager::create_component(type, NULL, get_style_manager());
	c.component->sig_set_options().call(options);

	// add created component to component store
	store->push_back(c);
}

void CreateComponentWindow::on_cancel()
{
	quit();
}