Revisión | 1d78cbbdd797c021fececdedc54d2acb7e74c6cf (tree) |
---|---|
Tiempo | 2012-10-13 23:46:59 |
Autor | angeart <angeart@git....> |
Commiter | angeart |
Inputのみコピペ機能搭載
GenJSONで作者名末尾に半角スペースが含まれていた場合の不具合修正
その他いろいろ
@@ -24,6 +24,12 @@ | ||
24 | 24 | #include "GenerateJSON.hpp" |
25 | 25 | #include "Music.hpp" |
26 | 26 | |
27 | +#pragma comment(lib,"libctemplate.lib") | |
28 | + | |
29 | +#define CTEMPLATE_DLL_DECL | |
30 | +#include <config.h> | |
31 | +#include <ctemplate/template.h> | |
32 | + | |
27 | 33 | |
28 | 34 | char Card::STORAGE_DIR[] = "storage"; |
29 | 35 | char Card::SCRIPT_PATH[] = "system/js"; |
@@ -75,6 +81,7 @@ Card::Card( | ||
75 | 81 | context->Global()->Set(String::New("Model"), script_object->Clone()); |
76 | 82 | context->Global()->Set(String::New("Account"), script_object->Clone()); |
77 | 83 | context->Global()->Set(String::New("Music"), script_object->Clone()); |
84 | + context->Global()->Set(String::New("Plugin"), script_object->Clone()); | |
78 | 85 | context->Global()->Set(String::New("InputBox"), script_object->Clone()); |
79 | 86 | context->Global()->Set(String::New("Card"), script_object->Clone()); |
80 | 87 | context->Global()->Set(String::New("Screen"), script_object->Clone()); |
@@ -101,11 +108,39 @@ Card::Card( | ||
101 | 108 | assert(!ui_board_obj_.IsEmpty() && ui_board_obj_->IsObject()); |
102 | 109 | }); |
103 | 110 | |
104 | - ui_board_ = *static_cast<UIBasePtr*>(ui_board_obj_->GetPointerFromInternalField(0)); | |
111 | + ui_board_ = *static_cast<UISuperPtr*>(ui_board_obj_->GetPointerFromInternalField(0)); | |
105 | 112 | } |
106 | 113 | |
107 | 114 | ui_board_->set_icon_image_handle( |
108 | 115 | ResourceManager::LoadCachedGraph(unicode::ToTString(source_folder_ + "/" + icon_))); |
116 | + | |
117 | + | |
118 | + auto sprit = [](const std::string &str, const std::string &delim)->std::vector<std::string> | |
119 | + { | |
120 | + std::vector<std::string> res; | |
121 | + size_t current = 0, found, delimlen = delim.size(); | |
122 | + while((found = str.find(delim, current)) != std::string::npos){ | |
123 | + res.push_back(std::string(str, current, found - current)); | |
124 | + current = found + delimlen; | |
125 | + } | |
126 | + res.push_back(std::string(str, current, str.size() - current)); | |
127 | + return res; | |
128 | + }; | |
129 | + | |
130 | + | |
131 | + auto ui_board_tmp = *static_cast<UIBoardPtr*>(ui_board_obj_->GetPointerFromInternalField(0)); | |
132 | + auto pos = name_.find_first_of("@"); | |
133 | + if ( pos != std::string::npos ) | |
134 | + { | |
135 | + std::string plug_dat = name_.substr(pos,name_.length() - pos); | |
136 | + auto str_array = sprit(plug_dat,","); | |
137 | + BOOST_FOREACH(auto str,str_array) | |
138 | + { | |
139 | + if(str == "plugin")ui_board_tmp->set_boardvisible(false); | |
140 | + if(str == "uiplugin")ui_board_tmp->set_boardvisible(true); | |
141 | + } | |
142 | + } | |
143 | + | |
109 | 144 | } |
110 | 145 | |
111 | 146 | Card::~Card() |
@@ -297,6 +332,26 @@ Handle<Value> Card::Function_Music_IsLoadingDone(const Arguments& args) | ||
297 | 332 | return Boolean::New(false); |
298 | 333 | } |
299 | 334 | |
335 | +Handle<Value> Card::Function_Plugin_Run(const Arguments& args) | |
336 | +{ | |
337 | + auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0)); | |
338 | + if (auto card_manager = self->manager_accessor_->card_manager().lock()) { | |
339 | + if ( args[0]->IsString() ) { | |
340 | + auto name = std::string(*String::Utf8Value(args[0]->ToString())); | |
341 | + BOOST_FOREACH(auto card,card_manager->cards()) { | |
342 | + auto pos = card->name().find_first_of("@"); | |
343 | + if( pos != std::string::npos ) { | |
344 | + if ( name == card->name().substr(0,pos) ) { | |
345 | + card->Run(); | |
346 | + } | |
347 | + } | |
348 | + } | |
349 | + } | |
350 | + } | |
351 | + return Undefined(); | |
352 | +} | |
353 | + | |
354 | + | |
300 | 355 | Handle<Value> Card::Function_Account_id(const Arguments& args) |
301 | 356 | { |
302 | 357 | auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0)); |
@@ -890,6 +945,15 @@ void Card::SetFunctions() | ||
890 | 945 | script_.SetFunction("Music.rebuild", Function_Music_Rebuild); |
891 | 946 | |
892 | 947 | script_.SetProperty("Music.onReload", Property_Music_onReload, Property_set_Music_onReload); |
948 | + | |
949 | + /** | |
950 | + * 非自動実行プラグインを走らせます | |
951 | + * | |
952 | + * @method run | |
953 | + * @static | |
954 | + */ | |
955 | + script_.SetFunction("Plugin.run", Function_Plugin_Run); | |
956 | + | |
893 | 957 | /** |
894 | 958 | * アカウント |
895 | 959 | * |
@@ -1347,8 +1411,9 @@ UISuperPtr Card::GetWindow() const | ||
1347 | 1411 | return ui_board_; |
1348 | 1412 | } else { |
1349 | 1413 | if (ui_board_obj_->IsObject()) { |
1350 | - auto ptr = *static_cast<UIBasePtr*>(ui_board_obj_->GetPointerFromInternalField(0)); | |
1351 | - if (ptr->children_size() > 0) { | |
1414 | + auto ptr = *static_cast<UIBoardPtr*>(ui_board_obj_->GetPointerFromInternalField(0)); | |
1415 | + assert(ptr); | |
1416 | + if (ptr->children_size() > 0 && ptr->boardvisible()) { | |
1352 | 1417 | return ptr; |
1353 | 1418 | } |
1354 | 1419 | } |
@@ -160,6 +160,31 @@ _error: | ||
160 | 160 | return RemoveDirectory( lpPathName ); |
161 | 161 | } |
162 | 162 | |
163 | + int Trim(char *s) { | |
164 | + int i; | |
165 | + int count = 0; | |
166 | + | |
167 | + /* 空ポインタか? */ | |
168 | + if ( s == NULL ) { /* yes */ | |
169 | + return -1; | |
170 | + } | |
171 | + | |
172 | + /* 文字列長を取得する */ | |
173 | + i = strlen(s); | |
174 | + | |
175 | + /* 末尾から順に空白でない位置を探す */ | |
176 | + while ( --i >= 0 && s[i] == ' ' ) count++; | |
177 | + | |
178 | + /* 終端ナル文字を付加する */ | |
179 | + s[i+1] = '\0'; | |
180 | + | |
181 | + /* 先頭から順に空白でない位置を探す */ | |
182 | + i = 0; | |
183 | + while ( s[i] != '\0' && s[i] == ' ' ) i++; | |
184 | + strcpy(s, &s[i]); | |
185 | + | |
186 | + return i + count; | |
187 | + } | |
163 | 188 | }; |
164 | 189 | |
165 | 190 | JsonGen::JsonGen() |
@@ -209,7 +234,7 @@ JsonGen::JsonGen() | ||
209 | 234 | { |
210 | 235 | ZeroMemory(tcsTmpPath_Pmd,MAX_PATH); |
211 | 236 | _tcscpy_s(tcsTmpPath_Pmd,tcsTmpDir); |
212 | - _tcscat_s(tcsTmpPath_Pmd,_T("*.pmd")); | |
237 | + _tcscat_s(tcsTmpPath_Pmd,_T("*.pm?")); | |
213 | 238 | hPmdFind = FindFirstFile(tcsTmpPath_Pmd, &win32fd_pmd); |
214 | 239 | if(hPmdFind == (HANDLE)0xffffffff) |
215 | 240 | { |
@@ -247,6 +272,7 @@ JsonGen::JsonGen() | ||
247 | 272 | |
248 | 273 | // モデル名取得 |
249 | 274 | strcpy_s(pmd_model_name_,pmd_info+7); |
275 | + Trim(pmd_model_name_); | |
250 | 276 | int cnt = 0x1b; |
251 | 277 | size_t info_size = ADFUNC_DXconvAnsiToWide(0,0,pmd_info+cnt); |
252 | 278 | TCHAR *pmd_info_t = new TCHAR[info_size + 1]; |
@@ -8,7 +8,7 @@ | ||
8 | 8 | |
9 | 9 | const size_t Input::TEXT_BUFFER_SIZE = 1024; |
10 | 10 | const size_t Input::HISTORY_MAX_SIZE = 50; |
11 | -const int Input::KEY_REPEAT_FRAME = 6; | |
11 | +const int Input::KEY_REPEAT_FRAME = 8; | |
12 | 12 | |
13 | 13 | const int Input::INPUT_MARGIN_X = 8; |
14 | 14 | const int Input::INPUT_MARGIN_Y = 6; |
@@ -19,9 +19,12 @@ const int Input::IME_MARGIN_Y = 16; | ||
19 | 19 | const int Input::IME_MAX_PAGE_SIZE = 6; |
20 | 20 | const int Input::IME_MIN_WIDTH = 120; |
21 | 21 | |
22 | -Input::Input() : | |
22 | +Input::Input(ConfigManagerPtr config_manager) : | |
23 | 23 | multiline_(true), |
24 | - reverse_color_(false) | |
24 | + reverse_color_(false), | |
25 | + drag_flag_(false), | |
26 | + rightmenu_show_(false), | |
27 | + config_manager_(config_manager) | |
25 | 28 | { |
26 | 29 | input_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
27 | 30 | _T("system/images/gui/gui_inputbox_input_bg.png"), 2, 2, 12, 12); |
@@ -45,6 +48,104 @@ Input::Input() : | ||
45 | 48 | y_ = 100; |
46 | 49 | width_ = 160; |
47 | 50 | height_ = font_height_ + 4; |
51 | + | |
52 | +} | |
53 | + | |
54 | +void Input::Init() | |
55 | +{ | |
56 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
57 | + UILabel label; | |
58 | + label.set_input_adaptor(this); | |
59 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("切り取り"))); | |
60 | + label.set_width(120); | |
61 | + label.set_top(12); | |
62 | + label.set_left(0); | |
63 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
64 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
65 | + label.set_on_click_function_([](UIBase* ptr)->void{ | |
66 | + auto input_ = ptr->input_adpator(); | |
67 | + auto sel_txt = input_->selecting_text(); | |
68 | + SetClipboardText(sel_txt.c_str()); | |
69 | + auto text = input_->text(); | |
70 | + auto pos = text.find(sel_txt); | |
71 | + tstring res; | |
72 | + if( pos != std::string::npos ) | |
73 | + { | |
74 | + res = text.substr(0,pos); | |
75 | + res += text.substr(pos + sel_txt.size(),text.size() - pos + sel_txt.size()); | |
76 | + } | |
77 | + input_->set_text(res); | |
78 | + }); | |
79 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
80 | + auto label_ptr = (UILabel *)ptr; | |
81 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
82 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
83 | + }); | |
84 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
85 | + auto label_ptr = (UILabel *)ptr; | |
86 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
87 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
88 | + }); | |
89 | + return label; | |
90 | + }()))); | |
91 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
92 | + UILabel label; | |
93 | + label.set_input_adaptor(this); | |
94 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("コピー"))); | |
95 | + label.set_width(120); | |
96 | + label.set_top(12); | |
97 | + label.set_left(0); | |
98 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
99 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
100 | + label.set_on_click_function_([&](UIBase* ptr)->void{ | |
101 | + auto input_ = ptr->input_adpator(); | |
102 | + SetClipboardText(input_->selecting_text().c_str()); | |
103 | + }); | |
104 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
105 | + auto label_ptr = (UILabel *)ptr; | |
106 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
107 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
108 | + }); | |
109 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
110 | + auto label_ptr = (UILabel *)ptr; | |
111 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
112 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
113 | + }); | |
114 | + return label; | |
115 | + }()))); | |
116 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
117 | + UILabel label; | |
118 | + label.set_input_adaptor(this); | |
119 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("貼り付け"))); | |
120 | + label.set_width(120); | |
121 | + label.set_top(12); | |
122 | + label.set_left(0); | |
123 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
124 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
125 | + label.set_on_click_function_([&](UIBase* ptr)->void{ | |
126 | + auto input_ = ptr->input_adpator(); | |
127 | + auto size = GetClipboardText(NULL); | |
128 | + if(size > 0){ | |
129 | + TCHAR *buf = new TCHAR[size]; | |
130 | + GetClipboardText(buf); | |
131 | + input_->paste_text(buf); | |
132 | + delete []buf; | |
133 | + } | |
134 | + }); | |
135 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
136 | + auto label_ptr = (UILabel *)ptr; | |
137 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
138 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
139 | + }); | |
140 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
141 | + auto label_ptr = (UILabel *)ptr; | |
142 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
143 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
144 | + }); | |
145 | + return label; | |
146 | + }()))); | |
147 | + right_click_list_.set_height((font_height_ + 2)* 3); | |
148 | + right_click_list_.set_width(120); | |
48 | 149 | } |
49 | 150 | |
50 | 151 | void Input::Draw() |
@@ -159,12 +260,98 @@ void Input::Draw() | ||
159 | 260 | } |
160 | 261 | } |
161 | 262 | |
162 | - for (auto it = lines_.begin(); it != lines_.end(); ++it) { | |
163 | - auto line = *it; | |
164 | - DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
165 | - line.c_str(), text_color, font_handle_); | |
166 | - current_line++; | |
167 | - } | |
263 | + int select_start = 0,select_end = 0; | |
264 | + GetKeyInputSelectArea(&select_start,&select_end,input_handle_); | |
265 | + if( select_start > select_end )std::swap(select_start,select_end); | |
266 | + | |
267 | + if( select_start > -1 && select_end != select_start ) { | |
268 | + if ( multiline_ ) { | |
269 | + BOOST_FOREACH(auto it,lines_){ | |
270 | + int width = 0; | |
271 | + TCHAR c[2] = {0}; | |
272 | + if( select_start >= it.size() && select_start != -1 ) { | |
273 | + DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
274 | + it.c_str(), text_color, font_handle_); | |
275 | + if(select_start == it.size()){ | |
276 | + select_start -= it.size(); | |
277 | + }else{ | |
278 | + select_start -= it.size() + 1; | |
279 | + } | |
280 | + select_end -= it.size() + 1; | |
281 | + ++current_line; | |
282 | + }else if(select_start != -1){ | |
283 | + for(int i = 0;i < select_start;++i){ | |
284 | + c[0] = it[i]; | |
285 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
286 | + c, text_color, font_handle_); | |
287 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
288 | + } | |
289 | + for(int i = select_start;i < ((select_end > it.size()) ? it.size() : select_end); ++i){ | |
290 | + c[0] = it[i]; | |
291 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180); | |
292 | + DrawBox(internal_x + width,internal_y + current_line * font_height_, | |
293 | + internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1); | |
294 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
295 | + c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_); | |
296 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
297 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
298 | + } | |
299 | + for(int i = ((select_end > it.size()) ? it.size() : select_end);i < it.size(); ++i){ | |
300 | + c[0] = it[i]; | |
301 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
302 | + c, text_color, font_handle_); | |
303 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
304 | + } | |
305 | + if(select_end > it.size()){ | |
306 | + select_end -= it.size() + 1; | |
307 | + select_start = 0; | |
308 | + }else{ | |
309 | + select_start = -1; | |
310 | + } | |
311 | + ++current_line; | |
312 | + }else if(select_start == -1){ | |
313 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
314 | + it.c_str(), text_color, font_handle_); | |
315 | + ++current_line; | |
316 | + } | |
317 | + } | |
318 | + }else{ | |
319 | + BOOST_FOREACH(auto it,lines_){ | |
320 | + int width = 0; | |
321 | + TCHAR c[2] = {0}; | |
322 | + for(int i = 0;i < select_start;++i){ | |
323 | + c[0] = it[i]; | |
324 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
325 | + c, text_color, font_handle_); | |
326 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
327 | + } | |
328 | + for(int i = select_start;i < select_end; ++i){ | |
329 | + c[0] = it[i]; | |
330 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180); | |
331 | + DrawBox(internal_x + width,internal_y + current_line * font_height_, | |
332 | + internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1); | |
333 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
334 | + c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_); | |
335 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
336 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
337 | + } | |
338 | + for(int i = select_end;i < it.size(); ++i){ | |
339 | + c[0] = it[i]; | |
340 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
341 | + c, text_color, font_handle_); | |
342 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
343 | + } | |
344 | + } | |
345 | + } | |
346 | + }else{ | |
347 | + for (auto it = lines_.begin(); it != lines_.end(); ++it) { | |
348 | + auto line = *it; | |
349 | + DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
350 | + line.c_str(), text_color, font_handle_); | |
351 | + current_line++; | |
352 | + } | |
353 | + } | |
354 | + | |
168 | 355 | |
169 | 356 | // カーソルを描画 |
170 | 357 | if (clause_lines_.size() <= 0 && active() && blink_count_ < 30) { |
@@ -258,11 +445,21 @@ void Input::Draw() | ||
258 | 445 | } |
259 | 446 | } |
260 | 447 | } |
448 | + { | |
449 | + if ( rightmenu_show_ ) { | |
450 | + right_click_list_.Draw(); | |
451 | + } | |
452 | + } | |
261 | 453 | } |
262 | 454 | |
263 | 455 | void Input::Update() |
264 | 456 | { |
265 | 457 | blink_count_ = (blink_count_ + 1) % 60; |
458 | + { | |
459 | + if ( rightmenu_show_ ) { | |
460 | + right_click_list_.Update(); | |
461 | + } | |
462 | + } | |
266 | 463 | } |
267 | 464 | |
268 | 465 | void Input::ProcessInput(InputManager* input) |
@@ -271,7 +468,15 @@ void Input::ProcessInput(InputManager* input) | ||
271 | 468 | return; |
272 | 469 | } |
273 | 470 | |
274 | - // bool push_mouse_left = (input->GetMouseLeftCount() > 0); | |
471 | + if ( rightmenu_show_ ) { | |
472 | + right_click_list_.ProcessInput(input); | |
473 | + } | |
474 | + | |
475 | + bool push_mouse_left = (input->GetMouseLeftCount() > 0); | |
476 | + bool prev_mouse_left = input->GetPrevMouseLeft(); | |
477 | + | |
478 | + bool push_mouse_right = (input->GetMouseRightCount() > 0); | |
479 | + bool prev_mouse_right = input->GetPrevMouseRight(); | |
275 | 480 | |
276 | 481 | // bool first_key_shift = (input->GetKeyCount(KEY_INPUT_RSHIFT) == 1 |
277 | 482 | // || input->GetKeyCount(KEY_INPUT_LSHIFT) == 1); |
@@ -292,6 +497,7 @@ void Input::ProcessInput(InputManager* input) | ||
292 | 497 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
293 | 498 | bool push_repeat_key_down = (input->GetKeyCount(KEY_INPUT_DOWN) |
294 | 499 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
500 | + | |
295 | 501 | // bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5); |
296 | 502 | |
297 | 503 | auto input_text = text(); |
@@ -407,7 +613,185 @@ void Input::ProcessInput(InputManager* input) | ||
407 | 613 | } |
408 | 614 | |
409 | 615 | if (active()) { |
410 | - // カーソル位置(byte)を取得 | |
616 | + if ( !rightmenu_show_ && | |
617 | + !( rightmenu_show_ && right_click_list_.absolute_x()<= input->GetMouseX() && input->GetMouseX() <= right_click_list_.absolute_x()+ right_click_list_.absolute_width() | |
618 | + && right_click_list_.absolute_y() <= input->GetMouseY() && input->GetMouseY() <= right_click_list_.absolute_y() + right_click_list_.absolute_height())) { | |
619 | + // マウス左ボタンが押された時 | |
620 | + if (push_mouse_left && !prev_mouse_left) { | |
621 | + auto mpos = input->GetMousePos(); | |
622 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
623 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
624 | + // カレット変更 | |
625 | + if( multiline_ ) { | |
626 | + auto line_num = offset_y / font_height_; | |
627 | + //if( ( offset_y % font_height_ ) != 0 )++line_num; | |
628 | + int tmp = 0,cnt = 0; | |
629 | + if( line_num < (int)lines_.size() && line_num >= 0 ){ | |
630 | + for(int i = 0;i < line_num; ++i){ | |
631 | + cnt += lines_[i].size(); | |
632 | + } | |
633 | + for(int i = 0;i < lines_[line_num].size(); ++i){ | |
634 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
635 | + if( tmp + tmp_x < offset_x ){ | |
636 | + tmp += tmp_x; | |
637 | + ++cnt; | |
638 | + } | |
639 | + } | |
640 | + SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
641 | + } | |
642 | + }else{ | |
643 | + int tmp = 0,cnt = 0; | |
644 | + for(int i = 0;i < lines_[0].size(); ++i){ | |
645 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
646 | + if( tmp + tmp_x < offset_x ){ | |
647 | + tmp += tmp_x; | |
648 | + ++cnt; | |
649 | + } | |
650 | + } | |
651 | + if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
652 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
653 | + }else{ | |
654 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
655 | + } | |
656 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
657 | + } | |
658 | + } | |
659 | + // マウス左ボタンがドラッグされた時 | |
660 | + if (push_mouse_left && prev_mouse_left ) { | |
661 | + int prev_cursor_pos = 0; | |
662 | + if( !drag_flag_ ){ | |
663 | + prev_cursor_pos = GetKeyInputCursorPosition(input_handle_); | |
664 | + }else{ | |
665 | + prev_cursor_pos = selecting_coursorpoint_.first; | |
666 | + } | |
667 | + auto mpos = input->GetMousePos(); | |
668 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
669 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
670 | + // カレット変更 | |
671 | + if( multiline_ ) { | |
672 | + auto line_num = offset_y / font_height_; | |
673 | + int tmp = 0,cnt = 0; | |
674 | + if( line_num < (int)lines_.size() && line_num >= 0){ | |
675 | + for(int i = 0;i < line_num; ++i,++cnt){ | |
676 | + cnt += lines_[i].size(); | |
677 | + } | |
678 | + for(int i = 0;i < lines_[line_num].size(); ++i){ | |
679 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
680 | + if( tmp + tmp_x < offset_x ){ | |
681 | + tmp += tmp_x; | |
682 | + ++cnt; | |
683 | + } | |
684 | + } | |
685 | + } | |
686 | + selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); | |
687 | + }else{ | |
688 | + int tmp = 0,cnt = 0; | |
689 | + for(int i = 0;i < lines_[0].size(); ++i){ | |
690 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
691 | + if( tmp + tmp_x < offset_x ){ | |
692 | + tmp += tmp_x; | |
693 | + ++cnt; | |
694 | + } | |
695 | + } | |
696 | + selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); | |
697 | + } | |
698 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
699 | + SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
700 | + drag_flag_ = true; | |
701 | + } | |
702 | + // マウス左ボタンが離され、且つ前回ドラッグされていた時 | |
703 | + if (!push_mouse_left && prev_mouse_left && drag_flag_ ) { | |
704 | + drag_flag_ = false; | |
705 | + if( selecting_coursorpoint_.first == selecting_coursorpoint_.second ) { | |
706 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
707 | + }else{ | |
708 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
709 | + } | |
710 | + SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
711 | + } | |
712 | + }else{ | |
713 | + if( push_mouse_left ){ | |
714 | + rightmenu_show_ = false; | |
715 | + auto mpos = input->GetMousePos(); | |
716 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
717 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
718 | + // カレット変更 | |
719 | + if( multiline_ ) { | |
720 | + auto line_num = offset_y / font_height_; | |
721 | + //if( ( offset_y % font_height_ ) != 0 )++line_num; | |
722 | + int tmp = 0,cnt = 0; | |
723 | + if( line_num < (int)lines_.size() && line_num >= 0 ){ | |
724 | + for(int i = 0;i < line_num; ++i){ | |
725 | + cnt += lines_[i].size(); | |
726 | + } | |
727 | + for(int i = 0;i < lines_[line_num].size(); ++i){ | |
728 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
729 | + if( tmp + tmp_x < offset_x ){ | |
730 | + tmp += tmp_x; | |
731 | + ++cnt; | |
732 | + } | |
733 | + } | |
734 | + SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
735 | + } | |
736 | + }else{ | |
737 | + int tmp = 0,cnt = 0; | |
738 | + for(int i = 0;i < lines_[0].size(); ++i){ | |
739 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
740 | + if( tmp + tmp_x < offset_x ){ | |
741 | + tmp += tmp_x; | |
742 | + ++cnt; | |
743 | + } | |
744 | + } | |
745 | + if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
746 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
747 | + }else{ | |
748 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
749 | + } | |
750 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
751 | + } | |
752 | + } | |
753 | + } | |
754 | + // マウス右ボタンが押されたとき | |
755 | + if ( push_mouse_right && !prev_mouse_right ) { | |
756 | + if( x() <= input->GetMouseX() && input->GetMouseX() <= x() + width() && | |
757 | + y() <= input->GetMouseY() && input->GetMouseY() <= y() + height()){ | |
758 | + mouse_pos_ = input->GetMousePos(); | |
759 | + if( mouse_pos_.second + right_click_list_.absolute_height() > config_manager_->screen_height()){ | |
760 | + right_click_list_.set_top(mouse_pos_.second - right_click_list_.absolute_height()); | |
761 | + if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){ | |
762 | + right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
763 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
764 | + it->set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
765 | + it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12); | |
766 | + } | |
767 | + }else{ | |
768 | + right_click_list_.set_left(mouse_pos_.first); | |
769 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
770 | + it->set_left(mouse_pos_.first); | |
771 | + it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12); | |
772 | + } | |
773 | + } | |
774 | + }else{ | |
775 | + right_click_list_.set_top(mouse_pos_.second); | |
776 | + if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){ | |
777 | + right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
778 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
779 | + it->set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
780 | + it->set_top(mouse_pos_.second + 12); | |
781 | + } | |
782 | + }else{ | |
783 | + right_click_list_.set_left(mouse_pos_.first); | |
784 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
785 | + it->set_left(mouse_pos_.first); | |
786 | + it->set_top(mouse_pos_.second + 12); | |
787 | + } | |
788 | + } | |
789 | + } | |
790 | + rightmenu_show_ = true; | |
791 | + } | |
792 | + } | |
793 | + | |
794 | + // カーソル位置(文字単位)を取得 | |
411 | 795 | cursor_byte_pos = GetKeyInputCursorPosition(input_handle_); |
412 | 796 | if (prev_cursor_pos_ != cursor_byte_pos) { |
413 | 797 | ResetCursorCount(); |
@@ -415,6 +799,7 @@ void Input::ProcessInput(InputManager* input) | ||
415 | 799 | |
416 | 800 | prev_cursor_pos_ = cursor_byte_pos; |
417 | 801 | |
802 | + | |
418 | 803 | // カーソルのドット単位の位置を取得する |
419 | 804 | cursor_dot_pos = GetDrawStringWidthToHandle(String, cursor_byte_pos, |
420 | 805 | font_handle_); |
@@ -621,6 +1006,7 @@ void Input::ProcessInput(InputManager* input) | ||
621 | 1006 | TCHAR c = *it; |
622 | 1007 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
623 | 1008 | line_buffer += tstring(&c, 1); |
1009 | + char_count++; | |
624 | 1010 | #else |
625 | 1011 | unsigned char c = *it; |
626 | 1012 | TCHAR string[2] = { 0, 0 }; |
@@ -659,7 +1045,7 @@ void Input::ProcessInput(InputManager* input) | ||
659 | 1045 | && cursor_moveto_x_ <= line_width + width |
660 | 1046 | && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ |
661 | 1047 | && cursor_moveto_y_ <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { |
662 | - SetKeyInputCursorPosition(prev_char_count, input_handle_); | |
1048 | + SetKeyInputCursorPosition(char_count - 1, input_handle_); | |
663 | 1049 | cursor_moveto_x_ = -1; |
664 | 1050 | cursor_moveto_y_ = -1; |
665 | 1051 | } |
@@ -815,6 +1201,51 @@ void Input::set_on_enter(const CallbackFunc& func) | ||
815 | 1201 | on_enter_ = func; |
816 | 1202 | } |
817 | 1203 | |
1204 | +tstring Input::selecting_text() const | |
1205 | +{ | |
1206 | + int select_start = 0,select_end = 0; | |
1207 | + GetKeyInputSelectArea(&select_start,&select_end,input_handle_); | |
1208 | + if( select_start > select_end )std::swap(select_start,select_end); | |
1209 | + tstring selecting_text; | |
1210 | + | |
1211 | + if( select_start > -1 && select_end != select_start ) { | |
1212 | + if ( multiline_ ) { | |
1213 | + BOOST_FOREACH(auto it,lines_){ | |
1214 | + TCHAR c[2] = {0}; | |
1215 | + if( select_start > it.size() && select_start != -1 ) { | |
1216 | + select_start -= it.size(); | |
1217 | + select_end -= it.size(); | |
1218 | + }else{ | |
1219 | + for(int i = select_start;i < select_end; ++i){ | |
1220 | + c[0] = it[i]; | |
1221 | + selecting_text += c; | |
1222 | + } | |
1223 | + select_start = -1; | |
1224 | + } | |
1225 | + } | |
1226 | + }else{ | |
1227 | + BOOST_FOREACH(auto it,lines_){ | |
1228 | + TCHAR c[2] = {0}; | |
1229 | + for(int i = select_start;i < select_end; ++i){ | |
1230 | + c[0] = it[i]; | |
1231 | + selecting_text += c; | |
1232 | + } | |
1233 | + } | |
1234 | + } | |
1235 | + } | |
1236 | + return selecting_text; | |
1237 | +} | |
1238 | + | |
1239 | +void Input::paste_text(tstring text) | |
1240 | +{ | |
1241 | + auto pos = GetKeyInputCursorPosition(input_handle_); | |
1242 | + TCHAR String[TEXT_BUFFER_SIZE]; | |
1243 | + GetKeyInputString(String, input_handle_); | |
1244 | + tstring dat(String, _tcslen(String)); | |
1245 | + dat.insert(pos,text); | |
1246 | + SetKeyInputString(dat.c_str(), input_handle_); | |
1247 | +} | |
1248 | + | |
818 | 1249 | bool Input::reverse_color() const |
819 | 1250 | { |
820 | 1251 | return reverse_color_; |
@@ -8,16 +8,20 @@ | ||
8 | 8 | #include <functional> |
9 | 9 | #include "../ResourceManager.hpp" |
10 | 10 | #include "../InputManager.hpp" |
11 | +#include "../ConfigManager.hpp" | |
12 | +#include "include.hpp" | |
13 | +#include <boost/enable_shared_from_this.hpp> | |
11 | 14 | |
12 | -class Input { | |
15 | +class Input{ | |
13 | 16 | typedef std::function<bool(const std::string&)> CallbackFunc; |
14 | 17 | |
15 | 18 | public: |
16 | - Input(); | |
19 | + Input(ConfigManagerPtr config_manager); | |
17 | 20 | |
18 | 21 | void Draw(); |
19 | 22 | void Update(); |
20 | 23 | void ProcessInput(InputManager* input); |
24 | + void Init(); | |
21 | 25 | |
22 | 26 | bool active(); |
23 | 27 | void set_active(bool flag); |
@@ -45,6 +49,9 @@ class Input { | ||
45 | 49 | |
46 | 50 | void set_on_enter(const CallbackFunc& func); |
47 | 51 | |
52 | + tstring selecting_text() const; | |
53 | + void paste_text(tstring text); | |
54 | + | |
48 | 55 | public: |
49 | 56 | void CancelSelect(); |
50 | 57 |
@@ -73,12 +80,20 @@ class Input { | ||
73 | 80 | std::vector<std::pair<int, int>> selecting_lines_; |
74 | 81 | std::vector<std::pair<int, int>> clause_lines_; |
75 | 82 | std::vector<std::pair<int, int>> selecting_clause_lines_; |
83 | + std::pair<int, int> selecting_coursorpoint_; | |
84 | + bool drag_flag_; | |
76 | 85 | |
77 | 86 | CallbackFunc on_enter_; |
78 | 87 | tstring message_; |
79 | 88 | |
80 | 89 | bool reverse_color_; |
81 | 90 | int blink_count_; |
91 | + bool rightmenu_show_; | |
92 | + std::pair<int, int> mouse_pos_; | |
93 | + | |
94 | + UIList right_click_list_; | |
95 | + | |
96 | + ConfigManagerPtr config_manager_; | |
82 | 97 | |
83 | 98 | private: |
84 | 99 | const static size_t TEXT_BUFFER_SIZE; |
@@ -43,7 +43,8 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) : | ||
43 | 43 | selecting_tab_index_(0), |
44 | 44 | manager_accessor_(manager_accessor), |
45 | 45 | card_(std::make_shared<Card>(manager_accessor_, "", "immo", "", |
46 | - std::vector<std::string>())) | |
46 | + std::vector<std::string>())), | |
47 | + input_(manager_accessor->config_manager().lock()) | |
47 | 48 | |
48 | 49 | { |
49 | 50 | absolute_rect_ = Rect(100, 100, 800, 100); |
@@ -102,6 +103,7 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) : | ||
102 | 103 | |
103 | 104 | return true; |
104 | 105 | }); |
106 | + input_.Init(); | |
105 | 107 | } |
106 | 108 | |
107 | 109 | InputBox::~InputBox() |
@@ -19,7 +19,8 @@ | ||
19 | 19 | #include <DxLib.h> |
20 | 20 | #include <algorithm> |
21 | 21 | |
22 | -UIBase::UIBase() | |
22 | +UIBase::UIBase() : | |
23 | +hover_flag_(false) | |
23 | 24 | { |
24 | 25 | |
25 | 26 | } |
@@ -38,6 +39,17 @@ void UIBase::ProcessInput(InputManager* input) | ||
38 | 39 | |
39 | 40 | } |
40 | 41 | |
42 | +void UIBase::Update() | |
43 | +{ | |
44 | +}; | |
45 | + | |
46 | +void UIBase::Draw() | |
47 | +{ | |
48 | + if(!children_.empty()){ | |
49 | + DrawChildren(); | |
50 | + } | |
51 | +} | |
52 | + | |
41 | 53 | void UIBase::AsyncUpdate() |
42 | 54 | { |
43 | 55 | AsyncUpdateChildren(); |
@@ -469,6 +481,26 @@ void UIBase::set_parent(const Handle<Object>& parent) | ||
469 | 481 | parent_ = Persistent<Object>::New(parent); |
470 | 482 | } |
471 | 483 | |
484 | +UIBasePtr UIBase::parent_c() const | |
485 | +{ | |
486 | + return parent_c_; | |
487 | +} | |
488 | + | |
489 | +void UIBase::set_parent_c(const UIBasePtr& parent) | |
490 | +{ | |
491 | + parent_c_ = parent; | |
492 | +} | |
493 | + | |
494 | +Input* UIBase::input_adpator() const | |
495 | +{ | |
496 | + return input_adaptor_; | |
497 | +} | |
498 | + | |
499 | +void UIBase::set_input_adaptor(Input* adaptor) | |
500 | +{ | |
501 | + input_adaptor_ = adaptor; | |
502 | +} | |
503 | + | |
472 | 504 | size_t UIBase::children_size() const |
473 | 505 | { |
474 | 506 | return children_.size(); |
@@ -7,6 +7,7 @@ | ||
7 | 7 | #include "UISuper.hpp" |
8 | 8 | #include <v8.h> |
9 | 9 | #include "../InputManager.hpp" |
10 | +#include <functional> | |
10 | 11 | |
11 | 12 | using namespace v8; |
12 | 13 |
@@ -14,8 +15,10 @@ class ScriptEnvironment; | ||
14 | 15 | typedef std::weak_ptr<ScriptEnvironment> ScriptEnvironmentWeakPtr; |
15 | 16 | |
16 | 17 | class UIBase; |
18 | +class Input; | |
17 | 19 | typedef std::shared_ptr<UIBase> UIBasePtr; |
18 | 20 | typedef std::weak_ptr<UIBase> UIBaseWeakPtr; |
21 | +typedef std::function<void(UIBase*)> CallbackFuncWithThisPointer; | |
19 | 22 | |
20 | 23 | class UIBase : public UISuper { |
21 | 24 |
@@ -24,8 +27,8 @@ class UIBase : public UISuper { | ||
24 | 27 | virtual ~UIBase(); |
25 | 28 | |
26 | 29 | virtual void ProcessInput(InputManager* input); |
27 | - virtual void Update() = 0; | |
28 | - virtual void Draw() = 0; | |
30 | + virtual void Update(); | |
31 | + virtual void Draw(); | |
29 | 32 | virtual void AsyncUpdate(); // 毎ループ実行する必要のない処理 |
30 | 33 | |
31 | 34 | /* function */ |
@@ -57,6 +60,10 @@ class UIBase : public UISuper { | ||
57 | 60 | |
58 | 61 | Handle<Object> parent() const; |
59 | 62 | void set_parent(const Handle<Object>& parent); |
63 | + UIBasePtr parent_c() const; | |
64 | + void set_parent_c(const UIBasePtr &parent_c); | |
65 | + Input* input_adpator() const; | |
66 | + void set_input_adaptor(Input * adaptor); | |
60 | 67 | |
61 | 68 | size_t children_size() const; |
62 | 69 |
@@ -92,12 +99,30 @@ class UIBase : public UISuper { | ||
92 | 99 | |
93 | 100 | void Focus(); |
94 | 101 | |
102 | + public: | |
103 | + /* Property */ | |
104 | + template<class F> | |
105 | + void set_on_click_function_(F function); | |
106 | + template<class F> | |
107 | + void set_on_hover_function_(F function); | |
108 | + template<class F> | |
109 | + void set_on_out_function_(F function); | |
110 | + | |
95 | 111 | protected: |
96 | 112 | |
97 | 113 | Persistent<Object> parent_; |
98 | 114 | std::vector<Persistent<Object>> children_; |
99 | 115 | |
100 | 116 | Persistent<Function> on_click_; |
117 | + CallbackFuncWithThisPointer on_click_function_; | |
118 | + CallbackFuncWithThisPointer on_hover_function_; | |
119 | + CallbackFuncWithThisPointer on_out_function_; | |
120 | + | |
121 | + bool hover_flag_; | |
122 | + | |
123 | + /*C++からクラスを伝達するためのメンバ*/ | |
124 | + UIBasePtr parent_c_; | |
125 | + Input* input_adaptor_; | |
101 | 126 | |
102 | 127 | }; |
103 | 128 |
@@ -155,3 +180,21 @@ void UIBase::SetConstant(Handle<ObjectTemplate>* object, const std::string& name | ||
155 | 180 | Handle<ObjectTemplate>& instance_template = *object; |
156 | 181 | instance_template->Set(String::New(name.c_str()), value); |
157 | 182 | } |
183 | + | |
184 | +template<class F> | |
185 | +void UIBase::set_on_click_function_(F function) | |
186 | +{ | |
187 | + on_click_function_ = function; | |
188 | +} | |
189 | + | |
190 | +template<class F> | |
191 | +void UIBase::set_on_hover_function_(F function) | |
192 | +{ | |
193 | + on_hover_function_ = function; | |
194 | +} | |
195 | + | |
196 | +template<class F> | |
197 | +void UIBase::set_on_out_function_(F function) | |
198 | +{ | |
199 | + on_out_function_ = function; | |
200 | +} | |
\ No newline at end of file |
@@ -25,7 +25,8 @@ UIBoard::UIBoard() : | ||
25 | 25 | max_height_(800), |
26 | 26 | min_height_(100), |
27 | 27 | drag_offset_rect_(-1, -1, -1, -1), |
28 | - drag_resize_offset_rect_(-1, -1, -1, -1) | |
28 | + drag_resize_offset_rect_(-1, -1, -1, -1), | |
29 | + boardvisible_(true) | |
29 | 30 | { |
30 | 31 | base_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
31 | 32 | _T("system/images/gui/gui_board_bg.png"), 2, 2, 24, 24); |
@@ -247,40 +248,42 @@ void UIBoard::Draw() | ||
247 | 248 | if (!visible_) { |
248 | 249 | return; |
249 | 250 | } |
251 | + | |
252 | + if (boardvisible_) { | |
253 | + SetDrawBlendMode(DX_BLENDMODE_ADD, 255); | |
250 | 254 | |
251 | - SetDrawBlendMode(DX_BLENDMODE_ADD, 255); | |
255 | + int x = absolute_x(); | |
256 | + int y = absolute_y(); | |
257 | + int width = absolute_width(); | |
258 | + int height = absolute_height(); | |
252 | 259 | |
253 | - int x = absolute_x(); | |
254 | - int y = absolute_y(); | |
255 | - int width = absolute_width(); | |
256 | - int height = absolute_height(); | |
260 | + DrawGraph(x, y, *base_image_handle_[0], TRUE); | |
261 | + DrawGraph(x + width - BASE_BLOCK_SIZE, y, *base_image_handle_[1], TRUE); | |
262 | + DrawGraph(x, y + height - BASE_BLOCK_SIZE, *base_image_handle_[2], TRUE); | |
263 | + DrawGraph(x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE); | |
257 | 264 | |
258 | - DrawGraph(x, y, *base_image_handle_[0], TRUE); | |
259 | - DrawGraph(x + width - BASE_BLOCK_SIZE, y, *base_image_handle_[1], TRUE); | |
260 | - DrawGraph(x, y + height - BASE_BLOCK_SIZE, *base_image_handle_[2], TRUE); | |
261 | - DrawGraph(x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE); | |
265 | + DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y, | |
266 | + x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
267 | + 0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[1], TRUE); | |
262 | 268 | |
263 | - DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y, | |
264 | - x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
265 | - 0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[1], TRUE); | |
269 | + DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
270 | + x + width - BASE_BLOCK_SIZE, y + height, | |
271 | + 0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE); | |
266 | 272 | |
267 | - DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
268 | - x + width - BASE_BLOCK_SIZE, y + height, | |
269 | - 0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE); | |
273 | + DrawRectExtendGraphF(x, y + BASE_BLOCK_SIZE, | |
274 | + x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
275 | + 0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[2], TRUE); | |
270 | 276 | |
271 | - DrawRectExtendGraphF(x, y + BASE_BLOCK_SIZE, | |
272 | - x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
273 | - 0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[2], TRUE); | |
277 | + DrawRectExtendGraphF(x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
278 | + x + width, y + height - BASE_BLOCK_SIZE, | |
279 | + 0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[3], TRUE); | |
274 | 280 | |
275 | - DrawRectExtendGraphF(x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
276 | - x + width, y + height - BASE_BLOCK_SIZE, | |
277 | - 0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[3], TRUE); | |
281 | + DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
282 | + x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
283 | + 0, 0, 1, 1, *base_image_handle_[3], TRUE); | |
278 | 284 | |
279 | - DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE, | |
280 | - x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, | |
281 | - 0, 0, 1, 1, *base_image_handle_[3], TRUE); | |
282 | - | |
283 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
285 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
286 | + } | |
284 | 287 | |
285 | 288 | DrawChildren(); |
286 | 289 | } |
@@ -290,6 +293,16 @@ bool UIBoard::resizable() const | ||
290 | 293 | return resizable_; |
291 | 294 | } |
292 | 295 | |
296 | +bool UIBoard::boardvisible() const | |
297 | +{ | |
298 | + return boardvisible_; | |
299 | +} | |
300 | + | |
301 | +void UIBoard::set_boardvisible(bool visible) | |
302 | +{ | |
303 | + boardvisible_ = visible; | |
304 | +} | |
305 | + | |
293 | 306 | void UIBoard::set_resizable(bool resizable) |
294 | 307 | { |
295 | 308 | resizable_ = resizable; |
@@ -16,7 +16,9 @@ class UIBoard : public UIBase { | ||
16 | 16 | void Draw(); |
17 | 17 | |
18 | 18 | bool resizable() const; |
19 | + bool boardvisible() const; | |
19 | 20 | void set_resizable(bool resizable); |
21 | + void set_boardvisible(bool visible); | |
20 | 22 | |
21 | 23 | public: |
22 | 24 | static void DefineInstanceTemplate(Handle<ObjectTemplate>* object); |
@@ -38,6 +40,7 @@ class UIBoard : public UIBase { | ||
38 | 40 | std::array<ImageHandlePtr,4> base_image_handle_; |
39 | 41 | |
40 | 42 | bool resizable_; |
43 | + bool boardvisible_; | |
41 | 44 | |
42 | 45 | int max_width_, min_width_; |
43 | 46 | int max_height_, min_height_; |
@@ -47,3 +50,5 @@ class UIBoard : public UIBase { | ||
47 | 50 | private: |
48 | 51 | const static int BASE_BLOCK_SIZE; |
49 | 52 | }; |
53 | + | |
54 | +typedef std::shared_ptr<UIBoard> UIBoardPtr; | |
\ No newline at end of file |
@@ -96,7 +96,8 @@ void UICustom::DefineInstanceTemplate(Handle<ObjectTemplate>* object) | ||
96 | 96 | SetProperty(object, "_update", Property_update, Property_set_update); |
97 | 97 | SetProperty(object, "_draw", Property_draw, Property_set_draw); |
98 | 98 | |
99 | - SetFunction(object, "drawLine", Function_drawLine); | |
99 | + SetFunction(object, "DrawLine", Function_DrawLine); | |
100 | + SetFunction(object, "DrawBox", Function_DrawBox); | |
100 | 101 | } |
101 | 102 | |
102 | 103 | void UICustom::ProcessInput(InputManager* input) |
@@ -131,16 +132,527 @@ void UICustom::Draw() | ||
131 | 132 | } |
132 | 133 | } |
133 | 134 | |
134 | -Handle<Value> UICustom::Function_drawLine(const Arguments& args) | |
135 | + | |
136 | +Handle<Value> UICustom::Function_DrawLine(const Arguments& args) | |
137 | +{ | |
138 | + assert(args.This()->InternalFieldCount() > 0); | |
139 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
140 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
141 | + ); | |
142 | + assert(self); | |
143 | + if( args[0]->IsInt32() && | |
144 | + args[1]->IsInt32() && | |
145 | + args[2]->IsInt32() && | |
146 | + args[3]->IsInt32() && | |
147 | + args[4]->IsInt32() && | |
148 | + args[5]->IsInt32() && | |
149 | + args[6]->IsInt32() ) | |
150 | + { | |
151 | + auto x0 = args[0]->Int32Value(); | |
152 | + auto y0 = args[1]->Int32Value(); | |
153 | + auto x1 = args[2]->Int32Value(); | |
154 | + auto y1 = args[3]->Int32Value(); | |
155 | + auto r = args[4]->Int32Value(); | |
156 | + auto g = args[5]->Int32Value(); | |
157 | + auto b = args[6]->Int32Value(); | |
158 | + | |
159 | + if( args[7]->IsInt32() ) | |
160 | + { | |
161 | + auto t = args[7]->Int32Value(); | |
162 | + DrawLine(x0, y0, x1, y1, GetColor(r, g, b),t); | |
163 | + }else{ | |
164 | + DrawLine(x0, y0, x1, y1, GetColor(r, g, b)); | |
165 | + } | |
166 | + | |
167 | + } | |
168 | + | |
169 | + return Undefined(); | |
170 | +} | |
171 | + | |
172 | +Handle<Value> UICustom::Function_DrawBox(const Arguments& args) | |
173 | +{ | |
174 | + assert(args.This()->InternalFieldCount() > 0); | |
175 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
176 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
177 | + ); | |
178 | + assert(self); | |
179 | + if( args[0]->IsInt32() && | |
180 | + args[1]->IsInt32() && | |
181 | + args[2]->IsInt32() && | |
182 | + args[3]->IsInt32() && | |
183 | + args[4]->IsInt32() && | |
184 | + args[5]->IsInt32() && | |
185 | + args[6]->IsInt32() ) | |
186 | + { | |
187 | + auto x0 = args[0]->Int32Value(); | |
188 | + auto y0 = args[1]->Int32Value(); | |
189 | + auto x1 = args[2]->Int32Value(); | |
190 | + auto y1 = args[3]->Int32Value(); | |
191 | + auto r = args[4]->Int32Value(); | |
192 | + auto g = args[5]->Int32Value(); | |
193 | + auto b = args[6]->Int32Value(); | |
194 | + | |
195 | + if( args[7]->IsBoolean() ) | |
196 | + { | |
197 | + auto fillflag = args[7]->BooleanValue(); | |
198 | + DrawBox(x0, y0, x1, y1, GetColor(r, g, b),fillflag ? 1 : 0); | |
199 | + }else{ | |
200 | + DrawBox(x0, y0, x1, y1, GetColor(r, g, b),1); | |
201 | + } | |
202 | + } | |
203 | + | |
204 | + return Undefined(); | |
205 | +} | |
206 | + | |
207 | +Handle<Value> UICustom::Function_DrawEdgeBox(const Arguments& args) | |
208 | +{ | |
209 | + assert(args.This()->InternalFieldCount() > 0); | |
210 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
211 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
212 | + ); | |
213 | + assert(self); | |
214 | + if( args[0]->IsInt32() && | |
215 | + args[1]->IsInt32() && | |
216 | + args[2]->IsInt32() && | |
217 | + args[3]->IsInt32() && | |
218 | + args[4]->IsInt32() && | |
219 | + args[5]->IsInt32() && | |
220 | + args[6]->IsInt32() ) | |
221 | + { | |
222 | + auto x0 = args[0]->Int32Value(); | |
223 | + auto y0 = args[1]->Int32Value(); | |
224 | + auto x1 = args[2]->Int32Value(); | |
225 | + auto y1 = args[3]->Int32Value(); | |
226 | + auto r = args[4]->Int32Value(); | |
227 | + auto g = args[5]->Int32Value(); | |
228 | + auto b = args[6]->Int32Value(); | |
229 | + | |
230 | + auto DrawOfOnlyEdge = [](int x, int y, int width, int height, int Color, int thickness) | |
231 | + { | |
232 | + DrawBox( x, y, x + width, y + thickness, Color, TRUE); | |
233 | + DrawBox( x, y, x + thickness, y + height, Color, TRUE); | |
234 | + DrawBox( x + width - thickness, y, x + width, y + height, Color, TRUE); | |
235 | + DrawBox( x, y + height - thickness, x + width, y + height, Color, TRUE); | |
236 | + };// thicknessで示した太さで縁のみの四角形を描画 | |
237 | + | |
238 | + if( args[7]->IsInt32() ) | |
239 | + { | |
240 | + auto t = args[7]->Int32Value(); | |
241 | + if( args[8]->IsBoolean() ) | |
242 | + { | |
243 | + auto fillflag = args[8]->BooleanValue(); | |
244 | + DrawOfOnlyEdge(x0 - t, y0 - t, x1 + t, y1 + t, GetColor(r, g, b),t); | |
245 | + DrawBox(x0, y0, x1, y1, GetColor(r, g, b),fillflag ? 1 : 0); | |
246 | + }else{ | |
247 | + DrawOfOnlyEdge(x0 - t, y0 - t, x1 + t, y1 + t, GetColor(r, g, b),t); | |
248 | + } | |
249 | + }else{ | |
250 | + DrawOfOnlyEdge(x0 - 1, y0 - 1, x1 + 1, y1 + 1, GetColor(r, g, b),1); | |
251 | + } | |
252 | + | |
253 | + } | |
254 | + | |
255 | + return Undefined(); | |
256 | +} | |
257 | + | |
258 | +Handle<Value> UICustom::Function_DrawCircle(const Arguments& args) | |
259 | +{ | |
260 | + assert(args.This()->InternalFieldCount() > 0); | |
261 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
262 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
263 | + ); | |
264 | + assert(self); | |
265 | + if( args[0]->IsInt32() && | |
266 | + args[1]->IsInt32() && | |
267 | + args[2]->IsInt32() && | |
268 | + args[3]->IsInt32() && | |
269 | + args[4]->IsInt32() && | |
270 | + args[5]->IsInt32() ) | |
271 | + { | |
272 | + auto x0 = args[0]->Int32Value(); | |
273 | + auto y0 = args[1]->Int32Value(); | |
274 | + auto r0 = args[2]->Int32Value(); | |
275 | + auto r = args[3]->Int32Value(); | |
276 | + auto g = args[4]->Int32Value(); | |
277 | + auto b = args[5]->Int32Value(); | |
278 | + | |
279 | + if( args[6]->IsBoolean() ) | |
280 | + { | |
281 | + auto fillflag = args[6]->BooleanValue(); | |
282 | + DrawCircle(x0, y0, r0, GetColor(r, g, b),fillflag ? 1 : 0); | |
283 | + }else{ | |
284 | + DrawCircle(x0, y0, r0, GetColor(r, g, b),1); | |
285 | + } | |
286 | + } | |
287 | + | |
288 | + return Undefined(); | |
289 | +} | |
290 | + | |
291 | +Handle<Value> UICustom::Function_DrawOval(const Arguments& args) | |
292 | +{ | |
293 | + assert(args.This()->InternalFieldCount() > 0); | |
294 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
295 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
296 | + ); | |
297 | + assert(self); | |
298 | + if( args[0]->IsInt32() && | |
299 | + args[1]->IsInt32() && | |
300 | + args[2]->IsInt32() && | |
301 | + args[3]->IsInt32() && | |
302 | + args[4]->IsInt32() && | |
303 | + args[5]->IsInt32() && | |
304 | + args[6]->IsInt32() ) | |
305 | + { | |
306 | + auto x0 = args[0]->Int32Value(); | |
307 | + auto y0 = args[1]->Int32Value(); | |
308 | + auto rx = args[2]->Int32Value(); | |
309 | + auto ry = args[3]->Int32Value(); | |
310 | + auto r = args[4]->Int32Value(); | |
311 | + auto g = args[5]->Int32Value(); | |
312 | + auto b = args[6]->Int32Value(); | |
313 | + | |
314 | + if( args[7]->IsBoolean() ) | |
315 | + { | |
316 | + auto fillflag = args[7]->BooleanValue(); | |
317 | + DrawOval(x0, y0, rx, ry, GetColor(r, g, b),fillflag ? 1 : 0); | |
318 | + }else{ | |
319 | + DrawOval(x0, y0, rx, ry, GetColor(r, g, b),1); | |
320 | + } | |
321 | + | |
322 | + } | |
323 | + | |
324 | + return Undefined(); | |
325 | +} | |
326 | + | |
327 | +Handle<Value> UICustom::Function_DrawTriangle(const Arguments& args) | |
328 | +{ | |
329 | + assert(args.This()->InternalFieldCount() > 0); | |
330 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
331 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
332 | + ); | |
333 | + assert(self); | |
334 | + if( args[0]->IsInt32() && | |
335 | + args[1]->IsInt32() && | |
336 | + args[2]->IsInt32() && | |
337 | + args[3]->IsInt32() && | |
338 | + args[4]->IsInt32() && | |
339 | + args[5]->IsInt32() && | |
340 | + args[6]->IsInt32() && | |
341 | + args[7]->IsInt32() && | |
342 | + args[8]->IsInt32() ) | |
343 | + { | |
344 | + auto x0 = args[0]->Int32Value(); | |
345 | + auto y0 = args[1]->Int32Value(); | |
346 | + auto x1 = args[2]->Int32Value(); | |
347 | + auto y1 = args[3]->Int32Value(); | |
348 | + auto x2 = args[4]->Int32Value(); | |
349 | + auto y2 = args[5]->Int32Value(); | |
350 | + auto r = args[6]->Int32Value(); | |
351 | + auto g = args[7]->Int32Value(); | |
352 | + auto b = args[8]->Int32Value(); | |
353 | + | |
354 | + if( args[9]->IsBoolean() ) | |
355 | + { | |
356 | + auto fillflag = args[9]->BooleanValue(); | |
357 | + DrawTriangle(x0, y0, x1, y1, x2, y2, GetColor(r, g, b),fillflag ? 1 : 0); | |
358 | + }else{ | |
359 | + DrawTriangle(x0, y0, x1, y1, x2, y2, GetColor(r, g, b),1); | |
360 | + } | |
361 | + | |
362 | + } | |
363 | + | |
364 | + return Undefined(); | |
365 | +} | |
366 | + | |
367 | +Handle<Value> UICustom::Function_DrawQuadrangle(const Arguments& args) | |
368 | +{ | |
369 | + assert(args.This()->InternalFieldCount() > 0); | |
370 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
371 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
372 | + ); | |
373 | + assert(self); | |
374 | + if( args[0]->IsInt32() && | |
375 | + args[1]->IsInt32() && | |
376 | + args[2]->IsInt32() && | |
377 | + args[3]->IsInt32() && | |
378 | + args[4]->IsInt32() && | |
379 | + args[5]->IsInt32() && | |
380 | + args[6]->IsInt32() && | |
381 | + args[7]->IsInt32() && | |
382 | + args[8]->IsInt32() ) | |
383 | + { | |
384 | + auto x0 = args[0]->Int32Value(); | |
385 | + auto y0 = args[1]->Int32Value(); | |
386 | + auto x1 = args[2]->Int32Value(); | |
387 | + auto y1 = args[3]->Int32Value(); | |
388 | + auto x2 = args[4]->Int32Value(); | |
389 | + auto y2 = args[5]->Int32Value(); | |
390 | + auto x3 = args[6]->Int32Value(); | |
391 | + auto y3 = args[7]->Int32Value(); | |
392 | + auto r = args[8]->Int32Value(); | |
393 | + auto g = args[9]->Int32Value(); | |
394 | + auto b = args[10]->Int32Value(); | |
395 | + | |
396 | + if( args[11]->IsBoolean() ) | |
397 | + { | |
398 | + auto fillflag = args[9]->BooleanValue(); | |
399 | + DrawQuadrangle(x0, y0, x1, y1, x2, y2, x3, y3, GetColor(r, g, b),fillflag ? 1 : 0); | |
400 | + }else{ | |
401 | + DrawQuadrangle(x0, y0, x1, y1, x2, y2, x3, y3, GetColor(r, g, b),1); | |
402 | + } | |
403 | + | |
404 | + } | |
405 | + | |
406 | + return Undefined(); | |
407 | +} | |
408 | + | |
409 | +Handle<Value> UICustom::Function_DrawPixel(const Arguments& args) | |
135 | 410 | { |
136 | 411 | assert(args.This()->InternalFieldCount() > 0); |
137 | 412 | auto self = std::dynamic_pointer_cast<UICustom>( |
138 | 413 | *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) |
139 | 414 | ); |
140 | 415 | assert(self); |
416 | + if( args[0]->IsInt32() && | |
417 | + args[1]->IsInt32() && | |
418 | + args[2]->IsInt32() && | |
419 | + args[3]->IsInt32() && | |
420 | + args[4]->IsInt32() ) | |
421 | + { | |
422 | + auto x0 = args[0]->Int32Value(); | |
423 | + auto y0 = args[1]->Int32Value(); | |
424 | + auto r = args[2]->Int32Value(); | |
425 | + auto g = args[3]->Int32Value(); | |
426 | + auto b = args[4]->Int32Value(); | |
427 | + | |
428 | + DrawPixel(x0, y0, GetColor(r, g, b)); | |
141 | 429 | |
142 | - DrawLine(100, 100, 200, 200, GetColor(255,255,255)); | |
430 | + } | |
143 | 431 | |
144 | 432 | return Undefined(); |
145 | 433 | } |
146 | 434 | |
435 | +Handle<Value> UICustom::Function_Paint(const Arguments& args) | |
436 | +{ | |
437 | + assert(args.This()->InternalFieldCount() > 0); | |
438 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
439 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
440 | + ); | |
441 | + assert(self); | |
442 | + if( args[0]->IsInt32() && | |
443 | + args[1]->IsInt32() && | |
444 | + args[2]->IsInt32() && | |
445 | + args[3]->IsInt32() && | |
446 | + args[4]->IsInt32() ) | |
447 | + { | |
448 | + auto x0 = args[0]->Int32Value(); | |
449 | + auto y0 = args[1]->Int32Value(); | |
450 | + auto r0 = args[2]->Int32Value(); | |
451 | + auto g0 = args[3]->Int32Value(); | |
452 | + auto b0 = args[4]->Int32Value(); | |
453 | + if( args[5]->IsInt32() && | |
454 | + args[6]->IsInt32() && | |
455 | + args[7]->IsInt32() ) | |
456 | + { | |
457 | + auto r1 = args[5]->Int32Value(); | |
458 | + auto g1 = args[6]->Int32Value(); | |
459 | + auto b1 = args[7]->Int32Value(); | |
460 | + Paint(x0, y0, GetColor(r0, g0, b0), GetColor(r1, g1, b1)); | |
461 | + }else{ | |
462 | + Paint(x0, y0, GetColor(r0, g0, b0)); | |
463 | + } | |
464 | + | |
465 | + } | |
466 | + | |
467 | + return Undefined(); | |
468 | +} | |
469 | + | |
470 | +Handle<Value> UICustom::Function_DrawPixelSet(const Arguments& args) | |
471 | +{ | |
472 | + assert(args.This()->InternalFieldCount() > 0); | |
473 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
474 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
475 | + ); | |
476 | + assert(self); | |
477 | + if( args[0]->IsArray() ) | |
478 | + { | |
479 | + auto array = Local<Array>::Cast(args[0]); | |
480 | + auto length = array->Length(); | |
481 | + auto data = static_cast<POINTDATA*>(array->GetPointerFromInternalField(0)); | |
482 | + | |
483 | + DrawPixelSet(data,length); | |
484 | + } | |
485 | + | |
486 | + return Undefined(); | |
487 | +} | |
488 | + | |
489 | +Handle<Value> UICustom::Function_DrawLineSet(const Arguments& args) | |
490 | +{ | |
491 | + assert(args.This()->InternalFieldCount() > 0); | |
492 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
493 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
494 | + ); | |
495 | + assert(self); | |
496 | + if( args[0]->IsArray() ) | |
497 | + { | |
498 | + auto array = Local<Array>::Cast(args[0]); | |
499 | + auto length = array->Length(); | |
500 | + auto data = static_cast<LINEDATA*>(array->GetPointerFromInternalField(0)); | |
501 | + | |
502 | + DrawLineSet(data,length); | |
503 | + } | |
504 | + | |
505 | + return Undefined(); | |
506 | +} | |
507 | + | |
508 | +Handle<Value> UICustom::Function_DrawPixel3D(const Arguments& args) | |
509 | +{ | |
510 | + assert(args.This()->InternalFieldCount() > 0); | |
511 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
512 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
513 | + ); | |
514 | + assert(self); | |
515 | + if( args[0]->IsInt32() && | |
516 | + args[1]->IsInt32() && | |
517 | + args[2]->IsInt32() && | |
518 | + args[3]->IsInt32() && | |
519 | + args[4]->IsInt32() && | |
520 | + args[5]->IsInt32() ) | |
521 | + { | |
522 | + auto x0 = args[0]->Int32Value(); | |
523 | + auto y0 = args[1]->Int32Value(); | |
524 | + auto z0 = args[2]->Int32Value(); | |
525 | + auto r = args[3]->Int32Value(); | |
526 | + auto g = args[4]->Int32Value(); | |
527 | + auto b = args[5]->Int32Value(); | |
528 | + | |
529 | + DrawPixel3D(VGet(x0, y0, z0), GetColor(r, g, b)); | |
530 | + | |
531 | + } | |
532 | + | |
533 | + return Undefined(); | |
534 | +} | |
535 | + | |
536 | +Handle<Value> UICustom::Function_DrawLine3D(const Arguments& args) | |
537 | +{ | |
538 | + assert(args.This()->InternalFieldCount() > 0); | |
539 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
540 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
541 | + ); | |
542 | + assert(self); | |
543 | + if( args[0]->IsInt32() && | |
544 | + args[1]->IsInt32() && | |
545 | + args[2]->IsInt32() && | |
546 | + args[3]->IsInt32() && | |
547 | + args[4]->IsInt32() && | |
548 | + args[5]->IsInt32() && | |
549 | + args[6]->IsInt32() && | |
550 | + args[7]->IsInt32() && | |
551 | + args[8]->IsInt32() ) | |
552 | + { | |
553 | + auto x0 = args[0]->Int32Value(); | |
554 | + auto y0 = args[1]->Int32Value(); | |
555 | + auto z0 = args[2]->Int32Value(); | |
556 | + auto x1 = args[3]->Int32Value(); | |
557 | + auto y1 = args[4]->Int32Value(); | |
558 | + auto z1 = args[5]->Int32Value(); | |
559 | + auto r = args[6]->Int32Value(); | |
560 | + auto g = args[7]->Int32Value(); | |
561 | + auto b = args[8]->Int32Value(); | |
562 | + | |
563 | + DrawLine3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(r, g, b)); | |
564 | + | |
565 | + } | |
566 | + | |
567 | + return Undefined(); | |
568 | +} | |
569 | + | |
570 | +Handle<Value> UICustom::Function_DrawCube3D(const Arguments& args) | |
571 | +{ | |
572 | + assert(args.This()->InternalFieldCount() > 0); | |
573 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
574 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
575 | + ); | |
576 | + assert(self); | |
577 | + if( args[0]->IsInt32() && | |
578 | + args[1]->IsInt32() && | |
579 | + args[2]->IsInt32() && | |
580 | + args[3]->IsInt32() && | |
581 | + args[4]->IsInt32() && | |
582 | + args[5]->IsInt32() && | |
583 | + args[6]->IsInt32() && | |
584 | + args[7]->IsInt32() && | |
585 | + args[8]->IsInt32() && | |
586 | + args[9]->IsInt32() && | |
587 | + args[10]->IsInt32() && | |
588 | + args[11]->IsInt32() ) | |
589 | + { | |
590 | + auto x0 = args[0]->Int32Value(); | |
591 | + auto y0 = args[1]->Int32Value(); | |
592 | + auto z0 = args[2]->Int32Value(); | |
593 | + auto x1 = args[3]->Int32Value(); | |
594 | + auto y1 = args[4]->Int32Value(); | |
595 | + auto z1 = args[5]->Int32Value(); | |
596 | + auto dr = args[6]->Int32Value(); | |
597 | + auto dg = args[7]->Int32Value(); | |
598 | + auto db = args[8]->Int32Value(); | |
599 | + auto sr = args[9]->Int32Value(); | |
600 | + auto sg = args[10]->Int32Value(); | |
601 | + auto sb = args[11]->Int32Value(); | |
602 | + | |
603 | + if( args[12]->IsBoolean() ) | |
604 | + { | |
605 | + auto fillflag = args[9]->BooleanValue(); | |
606 | + DrawCube3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(dr, dg, db), GetColor(sr, sg, db), fillflag ? 1 : 0); | |
607 | + }else{ | |
608 | + DrawCube3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(dr, dg, db), GetColor(sr, sg, db), 1); | |
609 | + } | |
610 | + | |
611 | + } | |
612 | + | |
613 | + return Undefined(); | |
614 | +} | |
615 | + | |
616 | +Handle<Value> UICustom::Function_DrawSphere3D(const Arguments& args) | |
617 | +{ | |
618 | + assert(args.This()->InternalFieldCount() > 0); | |
619 | + auto self = std::dynamic_pointer_cast<UICustom>( | |
620 | + *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0)) | |
621 | + ); | |
622 | + assert(self); | |
623 | + if( args[0]->IsInt32() && | |
624 | + args[1]->IsInt32() && | |
625 | + args[2]->IsInt32() && | |
626 | + args[3]->IsInt32() && | |
627 | + args[4]->IsInt32() && | |
628 | + args[5]->IsInt32() && | |
629 | + args[6]->IsInt32() && | |
630 | + args[7]->IsInt32() && | |
631 | + args[8]->IsInt32() && | |
632 | + args[9]->IsInt32() && | |
633 | + args[10]->IsInt32() ) | |
634 | + { | |
635 | + auto x0 = args[0]->Int32Value(); | |
636 | + auto y0 = args[1]->Int32Value(); | |
637 | + auto z0 = args[2]->Int32Value(); | |
638 | + auto r = args[3]->Int32Value(); | |
639 | + auto divnum = args[4]->Int32Value(); | |
640 | + auto dr = args[5]->Int32Value(); | |
641 | + auto dg = args[6]->Int32Value(); | |
642 | + auto db = args[7]->Int32Value(); | |
643 | + auto sr = args[8]->Int32Value(); | |
644 | + auto sg = args[9]->Int32Value(); | |
645 | + auto sb = args[10]->Int32Value(); | |
646 | + | |
647 | + if( args[11]->IsBoolean() ) | |
648 | + { | |
649 | + auto fillflag = args[9]->BooleanValue(); | |
650 | + DrawSphere3D(VGet(x0, y0, z0), r, divnum, GetColor(dr, dg, db), GetColor(sr, sg, db), fillflag ? 1 : 0); | |
651 | + }else{ | |
652 | + DrawSphere3D(VGet(x0, y0, z0), r, divnum, GetColor(dr, dg, db), GetColor(sr, sg, db), 1); | |
653 | + } | |
654 | + | |
655 | + } | |
656 | + | |
657 | + return Undefined(); | |
658 | +} |
@@ -28,7 +28,26 @@ class UICustom : public UIBase { | ||
28 | 28 | static void Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info); |
29 | 29 | |
30 | 30 | private: |
31 | - static Handle<Value> Function_drawLine(const Arguments& args); | |
31 | + /* function */ | |
32 | + static Handle<Value> Function_DrawLine(const Arguments& args); | |
33 | + static Handle<Value> Function_DrawBox(const Arguments& args); | |
34 | + static Handle<Value> Function_DrawEdgeBox(const Arguments& args); | |
35 | + static Handle<Value> Function_DrawCircle(const Arguments& args); | |
36 | + static Handle<Value> Function_DrawOval(const Arguments& args); | |
37 | + static Handle<Value> Function_DrawTriangle(const Arguments& args); | |
38 | + static Handle<Value> Function_DrawQuadrangle(const Arguments& args); | |
39 | + static Handle<Value> Function_DrawPixel(const Arguments& args); | |
40 | + static Handle<Value> Function_Paint(const Arguments& args); | |
41 | + static Handle<Value> Function_DrawPixelSet(const Arguments& args); | |
42 | + static Handle<Value> Function_DrawLineSet(const Arguments& args); | |
43 | + static Handle<Value> Function_DrawPixel3D(const Arguments& args); | |
44 | + static Handle<Value> Function_DrawLine3D(const Arguments& args); | |
45 | + static Handle<Value> Function_DrawCube3D(const Arguments& args); | |
46 | + static Handle<Value> Function_DrawSphere3D(const Arguments& args); | |
47 | + static Handle<Value> Function_DrawCapsule3D(const Arguments& args); | |
48 | + static Handle<Value> Function_DrawCone3D(const Arguments& args); | |
49 | + | |
50 | + static Handle<Value> Function_LoadGraph(const Arguments& args); | |
32 | 51 | |
33 | 52 | }; |
34 | 53 |
@@ -189,6 +189,19 @@ void UILabel::ProcessInput(InputManager* input) | ||
189 | 189 | if (input->GetMouseLeftCount() == 1 && hover) { |
190 | 190 | if (!on_click_.IsEmpty() && on_click_->IsFunction()) { |
191 | 191 | on_click_.As<Function>()->CallAsFunction(Context::GetCurrent()->Global(), 0, nullptr); |
192 | + }else if(!on_click_function_._Empty()) { | |
193 | + on_click_function_(this); | |
194 | + input->CancelMouseLeft(); | |
195 | + } | |
196 | + }else if(hover && !hover_flag_){ | |
197 | + if(!on_hover_function_._Empty()) { | |
198 | + on_hover_function_(this); | |
199 | + hover_flag_ = true; | |
200 | + } | |
201 | + }else if(!hover && hover_flag_){ | |
202 | + if(!on_out_function_._Empty()) { | |
203 | + on_out_function_(this); | |
204 | + hover_flag_ = false; | |
192 | 205 | } |
193 | 206 | } |
194 | 207 | } |
@@ -169,6 +169,41 @@ void UIList::ProcessInput(InputManager* input) | ||
169 | 169 | |
170 | 170 | } |
171 | 171 | |
172 | +void UIList::addItem(UIBasePtr item) | |
173 | +{ | |
174 | + item->set_parent_c(UIBasePtr(new UIList(*this))); | |
175 | + items_.push_back(item); | |
176 | +} | |
177 | + | |
178 | +void UIList::removeItem(UIBasePtr item) | |
179 | +{ | |
180 | + auto it = std::find(items_.begin(), items_.end(), item); | |
181 | + if (it != items_.end()) { | |
182 | + UIBasePtr chid_ptr = *it; | |
183 | + chid_ptr->set_parent_c(nullptr); | |
184 | + items_.erase(it); | |
185 | + } | |
186 | +} | |
187 | + | |
188 | +void UIList::clearItems() | |
189 | +{ | |
190 | + BOOST_FOREACH(auto it, items_) { | |
191 | + UIBasePtr chid_ptr = it; | |
192 | + chid_ptr->set_parent_c(nullptr); | |
193 | + } | |
194 | + items_.clear(); | |
195 | +} | |
196 | + | |
197 | +std::vector<UIBasePtr> UIList::getItems() const | |
198 | +{ | |
199 | + return items_; | |
200 | +} | |
201 | + | |
202 | +void UIList::set_scroll_y(int scroll_y) | |
203 | +{ | |
204 | + scroll_y_ = scroll_y; | |
205 | +} | |
206 | + | |
172 | 207 | void UIList::UpdateScrollBar(InputManager* input) |
173 | 208 | { |
174 | 209 | int screen_width, screen_height; |
@@ -18,7 +18,7 @@ class UIList : public UIBase { | ||
18 | 18 | void Draw(); |
19 | 19 | |
20 | 20 | public: |
21 | - static void DefineInstanceTemplate(Handle<ObjectTemplate>* object); | |
21 | + static void DefineInstanceTemplate(Handle<ObjectTemplate>* object); | |
22 | 22 | |
23 | 23 | private: |
24 | 24 | /* function */ |
@@ -30,6 +30,16 @@ class UIList : public UIBase { | ||
30 | 30 | static Handle<Value> Property_scroll_y(Local<String> property, const AccessorInfo &info); |
31 | 31 | static void Property_set_scroll_y(Local<String> property, Local<Value> value, const AccessorInfo& info); |
32 | 32 | |
33 | + public: | |
34 | + /* function */ | |
35 | + void addItem(UIBasePtr item); | |
36 | + void removeItem(UIBasePtr item); | |
37 | + void clearItems(); | |
38 | + std::vector<UIBasePtr> getItems() const; | |
39 | + | |
40 | + /* property */ | |
41 | + void set_scroll_y(int scroll_y); | |
42 | + | |
33 | 43 | private: |
34 | 44 | std::array<ImageHandlePtr,4> scrollbar_base_image_handle_; |
35 | 45 |