修訂 | 11411bfdf86affd4ee794fc31eaaf95cadecc649 (tree) |
---|---|
時間 | 2012-10-29 21:19:41 |
作者 | angeart <angeart@git....> |
Commiter | angeart |
コピペ機能を復活
カメラに影響する問題を修正
@@ -955,17 +955,51 @@ void* tlsf_realloc(tlsf_pool tlsf, void* ptr, size_t size) | ||
955 | 955 | return p; |
956 | 956 | } |
957 | 957 | |
958 | +#include <map> | |
959 | +static std::map<int,int> tlsf_addresses; | |
960 | + | |
958 | 961 | void * tlsf_new(tlsf_pool mempool,size_t size){ |
959 | 962 | void *p = tlsf_malloc(mempool,size); |
960 | 963 | if(!p){ |
961 | 964 | std::bad_alloc b; |
962 | 965 | throw b; |
963 | 966 | } |
967 | + TCHAR tmp[32],str[128]; | |
968 | + _itot_s((int)p,tmp,10); | |
969 | + _tcscpy_s(str,L"tlsf new address : "); | |
970 | + _tcscat_s(str,tmp); | |
971 | + _tcscat_s(str,L"\r\n"); | |
972 | + OutputDebugString(str); | |
973 | + tlsf_addresses.insert(std::make_pair<int,int>((int)p,size)); | |
964 | 974 | return p; |
965 | 975 | } |
966 | 976 | |
967 | 977 | |
968 | 978 | void tlsf_delete(tlsf_pool mempool,void *p) |
969 | 979 | { |
980 | + TCHAR tmp[32],str[128]; | |
981 | + _itot_s((int)p,tmp,10); | |
982 | + _tcscpy_s(str,L"tlsf delete address : "); | |
983 | + _tcscat_s(str,tmp); | |
984 | + _tcscat_s(str,L"\r\n"); | |
985 | + OutputDebugString(str); | |
986 | + auto it = tlsf_addresses.find((int)p); | |
987 | + tlsf_addresses.erase(it); | |
970 | 988 | if(p)tlsf_free(mempool,p); |
971 | 989 | } |
990 | + | |
991 | +void output_tlsf_leak() | |
992 | +{ | |
993 | + for(auto it = tlsf_addresses.begin();it != tlsf_addresses.end();++it) | |
994 | + { | |
995 | + TCHAR tmp[32],str[128]; | |
996 | + _itot_s(it->first,tmp,10); | |
997 | + _tcscpy_s(str,L"leak address : "); | |
998 | + _tcscat_s(str,tmp); | |
999 | + _itot_s(it->second,tmp,10); | |
1000 | + _tcscat_s(str,L"\tsize : "); | |
1001 | + _tcscat_s(str,tmp); | |
1002 | + _tcscat_s(str,L"\r\n"); | |
1003 | + OutputDebugString(str); | |
1004 | + } | |
1005 | +} | |
\ No newline at end of file |
@@ -51,6 +51,7 @@ size_t tlsf_overhead(); | ||
51 | 51 | |
52 | 52 | void *tlsf_new(tlsf_pool mempool,size_t size); |
53 | 53 | void tlsf_delete(tlsf_pool mempool,void *p); |
54 | +void output_tlsf_leak(); | |
54 | 55 | |
55 | 56 | template<typename T> |
56 | 57 | T *tlsf_new(tlsf_pool mempool,size_t size){ |
@@ -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,114 @@ Input::Input() : | ||
45 | 48 | y_ = 100; |
46 | 49 | width_ = 160; |
47 | 50 | height_ = font_height_ + 4; |
51 | + | |
52 | + click_cancel_count_ = 0; | |
53 | + | |
54 | +} | |
55 | + | |
56 | +void Input::Init() | |
57 | +{ | |
58 | + auto shd_right_click_list_ = std::make_shared<UIList>(right_click_list_); | |
59 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
60 | + UILabel label; | |
61 | + label.set_parent_c(shd_right_click_list_); | |
62 | + label.set_input_adaptor(this); | |
63 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("切り取り"))); | |
64 | + label.set_width(120); | |
65 | + label.set_top(12); | |
66 | + label.set_left(0); | |
67 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
68 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
69 | + label.set_on_click_function_([](UIBase* ptr)->void{ | |
70 | + auto input_ = ptr->input_adpator(); | |
71 | + auto sel_txt = input_->selecting_text(); | |
72 | + SetClipboardText(sel_txt.c_str()); | |
73 | + auto text = input_->text(); | |
74 | + auto pos = text.find(sel_txt); | |
75 | + tstring res; | |
76 | + if( pos != std::string::npos ) | |
77 | + { | |
78 | + res = text.substr(0,pos); | |
79 | + res += text.substr(pos + sel_txt.size(),text.size() - pos + sel_txt.size()); | |
80 | + } | |
81 | + input_->set_text(res); | |
82 | + input_->set_click_chancel_count(8); | |
83 | + }); | |
84 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
85 | + auto label_ptr = (UILabel *)ptr; | |
86 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
87 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
88 | + }); | |
89 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
90 | + auto label_ptr = (UILabel *)ptr; | |
91 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
92 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
93 | + }); | |
94 | + return label; | |
95 | + }()))); | |
96 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
97 | + UILabel label; | |
98 | + label.set_parent_c(shd_right_click_list_); | |
99 | + label.set_input_adaptor(this); | |
100 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("コピー"))); | |
101 | + label.set_width(120); | |
102 | + label.set_top(12); | |
103 | + label.set_left(0); | |
104 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
105 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
106 | + label.set_on_click_function_([&](UIBase* ptr)->void{ | |
107 | + auto input_ = ptr->input_adpator(); | |
108 | + SetClipboardText(input_->selecting_text().c_str()); | |
109 | + input_->set_click_chancel_count(8); | |
110 | + }); | |
111 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
112 | + auto label_ptr = (UILabel *)ptr; | |
113 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
114 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
115 | + }); | |
116 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
117 | + auto label_ptr = (UILabel *)ptr; | |
118 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
119 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
120 | + }); | |
121 | + return label; | |
122 | + }()))); | |
123 | + right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{ | |
124 | + UILabel label; | |
125 | + label.set_parent_c(shd_right_click_list_); | |
126 | + label.set_input_adaptor(this); | |
127 | + label.set_text(unicode::ToTString(unicode::sjis2utf8("貼り付け"))); | |
128 | + label.set_width(120); | |
129 | + label.set_top(12); | |
130 | + label.set_left(0); | |
131 | + label.set_textcolor(UISuper::Color(0,0,0,255)); | |
132 | + label.set_bgcolor(UISuper::Color(255,255,255,180)); | |
133 | + label.set_on_click_function_([&](UIBase* ptr)->void{ | |
134 | + auto input_ = ptr->input_adpator(); | |
135 | + auto size = GetClipboardText(NULL); | |
136 | + if(size > 0){ | |
137 | + TCHAR *buf = new TCHAR[size]; | |
138 | + GetClipboardText(buf); | |
139 | + input_->paste_text(buf); | |
140 | + delete []buf; | |
141 | + } | |
142 | + input_->set_click_chancel_count(8); | |
143 | + }); | |
144 | + label.set_on_hover_function_([](UIBase* ptr)->void{ | |
145 | + auto label_ptr = (UILabel *)ptr; | |
146 | + label_ptr->set_bgcolor(UISuper::Color(0,0,0,180)); | |
147 | + label_ptr->set_textcolor(UISuper::Color(255,255,255)); | |
148 | + }); | |
149 | + label.set_on_out_function_([](UIBase* ptr)->void{ | |
150 | + auto label_ptr = (UILabel *)ptr; | |
151 | + label_ptr->set_bgcolor(UISuper::Color(255,255,255,180)); | |
152 | + label_ptr->set_textcolor(UISuper::Color(0,0,0)); | |
153 | + }); | |
154 | + return label; | |
155 | + }()))); | |
156 | + right_click_list_.set_height((font_height_ + 2)* 3); | |
157 | + right_click_list_.set_width(120); | |
158 | + right_click_list_.set_visible(false); | |
48 | 159 | } |
49 | 160 | |
50 | 161 | void Input::Draw() |
@@ -159,12 +270,98 @@ void Input::Draw() | ||
159 | 270 | } |
160 | 271 | } |
161 | 272 | |
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 | - } | |
273 | + int select_start = 0,select_end = 0; | |
274 | + GetKeyInputSelectArea(&select_start,&select_end,input_handle_); | |
275 | + if( select_start > select_end )std::swap(select_start,select_end); | |
276 | + | |
277 | + if( select_start > -1 && select_end != select_start ) { | |
278 | + if ( multiline_ ) { | |
279 | + BOOST_FOREACH(auto it,lines_){ | |
280 | + int width = 0; | |
281 | + TCHAR c[2] = {0}; | |
282 | + if( select_start >= it.size() && select_start != -1 ) { | |
283 | + DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
284 | + it.c_str(), text_color, font_handle_); | |
285 | + if(select_start == it.size()){ | |
286 | + select_start -= it.size(); | |
287 | + }else{ | |
288 | + select_start -= it.size() + 1; | |
289 | + } | |
290 | + select_end -= it.size() + 1; | |
291 | + ++current_line; | |
292 | + }else if(select_start != -1){ | |
293 | + for(int i = 0;i < select_start;++i){ | |
294 | + c[0] = it[i]; | |
295 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
296 | + c, text_color, font_handle_); | |
297 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
298 | + } | |
299 | + for(int i = select_start;i < ((select_end > static_cast<int>(it.size())) ? it.size() : select_end); ++i){ | |
300 | + c[0] = it[i]; | |
301 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180); | |
302 | + DrawBox(internal_x + width,internal_y + current_line * font_height_, | |
303 | + internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1); | |
304 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
305 | + c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_); | |
306 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
307 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
308 | + } | |
309 | + for(int i = ((select_end > static_cast<int>(it.size())) ? it.size() : select_end);i < it.size(); ++i){ | |
310 | + c[0] = it[i]; | |
311 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
312 | + c, text_color, font_handle_); | |
313 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
314 | + } | |
315 | + if(select_end > it.size()){ | |
316 | + select_end -= it.size() + 1; | |
317 | + select_start = 0; | |
318 | + }else{ | |
319 | + select_start = -1; | |
320 | + } | |
321 | + ++current_line; | |
322 | + }else if(select_start == -1){ | |
323 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
324 | + it.c_str(), text_color, font_handle_); | |
325 | + ++current_line; | |
326 | + } | |
327 | + } | |
328 | + }else{ | |
329 | + BOOST_FOREACH(auto it,lines_){ | |
330 | + int width = 0; | |
331 | + TCHAR c[2] = {0}; | |
332 | + for(int i = 0;i < select_start;++i){ | |
333 | + c[0] = it[i]; | |
334 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
335 | + c, text_color, font_handle_); | |
336 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
337 | + } | |
338 | + for(int i = select_start;i < select_end; ++i){ | |
339 | + c[0] = it[i]; | |
340 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180); | |
341 | + DrawBox(internal_x + width,internal_y + current_line * font_height_, | |
342 | + internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1); | |
343 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
344 | + c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_); | |
345 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
346 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
347 | + } | |
348 | + for(unsigned int i = select_end;i < it.size(); ++i){ | |
349 | + c[0] = it[i]; | |
350 | + DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_, | |
351 | + c, text_color, font_handle_); | |
352 | + width += GetDrawStringWidthToHandle(c,1,font_handle_); | |
353 | + } | |
354 | + } | |
355 | + } | |
356 | + }else{ | |
357 | + for (auto it = lines_.begin(); it != lines_.end(); ++it) { | |
358 | + auto line = *it; | |
359 | + DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
360 | + line.c_str(), text_color, font_handle_); | |
361 | + current_line++; | |
362 | + } | |
363 | + } | |
364 | + | |
168 | 365 | |
169 | 366 | // カーソルを描画 |
170 | 367 | if (clause_lines_.size() <= 0 && active() && blink_count_ < 30) { |
@@ -258,11 +455,21 @@ void Input::Draw() | ||
258 | 455 | } |
259 | 456 | } |
260 | 457 | } |
458 | + { | |
459 | + if ( right_click_list_.visible() ) { | |
460 | + right_click_list_.Draw(); | |
461 | + } | |
462 | + } | |
261 | 463 | } |
262 | 464 | |
263 | 465 | void Input::Update() |
264 | 466 | { |
265 | 467 | blink_count_ = (blink_count_ + 1) % 60; |
468 | + { | |
469 | + if ( right_click_list_.visible() ) { | |
470 | + right_click_list_.Update(); | |
471 | + } | |
472 | + } | |
266 | 473 | } |
267 | 474 | |
268 | 475 | void Input::ProcessInput(InputManager* input) |
@@ -271,7 +478,18 @@ void Input::ProcessInput(InputManager* input) | ||
271 | 478 | return; |
272 | 479 | } |
273 | 480 | |
274 | - // bool push_mouse_left = (input->GetMouseLeftCount() > 0); | |
481 | + if (click_cancel_count_ > 0) | |
482 | + { | |
483 | + input->CancelMouseLeft(); | |
484 | + input->CancelMouseRight(); | |
485 | + --click_cancel_count_; | |
486 | + } | |
487 | + | |
488 | + bool push_mouse_left = (input->GetMouseLeftCount() > 0); | |
489 | + bool prev_mouse_left = input->GetPrevMouseLeft(); | |
490 | + | |
491 | + bool push_mouse_right = (input->GetMouseRightCount() > 0); | |
492 | + bool prev_mouse_right = input->GetPrevMouseRight(); | |
275 | 493 | |
276 | 494 | // bool first_key_shift = (input->GetKeyCount(KEY_INPUT_RSHIFT) == 1 |
277 | 495 | // || input->GetKeyCount(KEY_INPUT_LSHIFT) == 1); |
@@ -292,6 +510,7 @@ void Input::ProcessInput(InputManager* input) | ||
292 | 510 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
293 | 511 | bool push_repeat_key_down = (input->GetKeyCount(KEY_INPUT_DOWN) |
294 | 512 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
513 | + | |
295 | 514 | // bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5); |
296 | 515 | |
297 | 516 | auto input_text = text(); |
@@ -312,6 +531,13 @@ void Input::ProcessInput(InputManager* input) | ||
312 | 531 | } |
313 | 532 | } |
314 | 533 | |
534 | + if ( right_click_list_.visible() ) { | |
535 | + right_click_list_.ProcessInput(input); | |
536 | + if( push_mouse_left ) { | |
537 | + //rightmenu_show_ = false; | |
538 | + right_click_list_.set_visible(false); | |
539 | + } | |
540 | + } | |
315 | 541 | if (push_repeat_key_up) { |
316 | 542 | cursor_moveto_y_ = cursor_y_ - font_height_ / 2; |
317 | 543 | cursor_moveto_x_ = cursor_x_ + 2; |
@@ -407,7 +633,189 @@ void Input::ProcessInput(InputManager* input) | ||
407 | 633 | } |
408 | 634 | |
409 | 635 | if (active()) { |
410 | - // カーソル位置(byte)を取得 | |
636 | + if ( !right_click_list_.visible() && | |
637 | + !( right_click_list_.visible() && right_click_list_.absolute_x()<= input->GetMouseX() && input->GetMouseX() <= right_click_list_.absolute_x()+ right_click_list_.absolute_width() | |
638 | + && right_click_list_.absolute_y() <= input->GetMouseY() && input->GetMouseY() <= right_click_list_.absolute_y() + right_click_list_.absolute_height())) { | |
639 | + // マウス左ボタンが押された時 | |
640 | + if (push_mouse_left && !prev_mouse_left) { | |
641 | + auto mpos = input->GetMousePos(); | |
642 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
643 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
644 | + // カレット変更 | |
645 | + if( multiline_ ) { | |
646 | + auto line_num = offset_y / font_height_; | |
647 | + //if( ( offset_y % font_height_ ) != 0 )++line_num; | |
648 | + int tmp = 0,cnt = 0; | |
649 | + if( line_num < (int)lines_.size() && line_num >= 0 ){ | |
650 | + for(int i = 0;i < line_num; ++i){ | |
651 | + cnt += lines_[i].size(); | |
652 | + } | |
653 | + for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ | |
654 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
655 | + if( tmp + tmp_x < offset_x ){ | |
656 | + tmp += tmp_x; | |
657 | + ++cnt; | |
658 | + } | |
659 | + } | |
660 | + SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
661 | + } | |
662 | + }else{ | |
663 | + int tmp = 0,cnt = 0; | |
664 | + for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
665 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
666 | + if( tmp + tmp_x < offset_x ){ | |
667 | + tmp += tmp_x; | |
668 | + ++cnt; | |
669 | + } | |
670 | + } | |
671 | + if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
672 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
673 | + }else{ | |
674 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
675 | + } | |
676 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
677 | + } | |
678 | + } | |
679 | + // マウス左ボタンがドラッグされた時 | |
680 | + if (push_mouse_left && prev_mouse_left ) { | |
681 | + int prev_cursor_pos = 0; | |
682 | + if( !drag_flag_ ){ | |
683 | + prev_cursor_pos = GetKeyInputCursorPosition(input_handle_); | |
684 | + }else{ | |
685 | + prev_cursor_pos = selecting_coursorpoint_.first; | |
686 | + } | |
687 | + auto mpos = input->GetMousePos(); | |
688 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
689 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
690 | + // カレット変更 | |
691 | + if( multiline_ ) { | |
692 | + auto line_num = offset_y / font_height_; | |
693 | + int tmp = 0,cnt = 0; | |
694 | + if( line_num < (int)lines_.size() && line_num >= 0){ | |
695 | + for(int i = 0;i < line_num; ++i,++cnt){ | |
696 | + cnt += lines_[i].size(); | |
697 | + } | |
698 | + for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ | |
699 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
700 | + if( tmp + tmp_x < offset_x ){ | |
701 | + tmp += tmp_x; | |
702 | + ++cnt; | |
703 | + } | |
704 | + } | |
705 | + } | |
706 | + selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); | |
707 | + }else{ | |
708 | + int tmp = 0,cnt = 0; | |
709 | + for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
710 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
711 | + if( tmp + tmp_x < offset_x ){ | |
712 | + tmp += tmp_x; | |
713 | + ++cnt; | |
714 | + } | |
715 | + } | |
716 | + selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); | |
717 | + } | |
718 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
719 | + SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
720 | + drag_flag_ = true; | |
721 | + } | |
722 | + // マウス左ボタンが離され、且つ前回ドラッグされていた時 | |
723 | + if (!push_mouse_left && prev_mouse_left && drag_flag_ ) { | |
724 | + drag_flag_ = false; | |
725 | + if( selecting_coursorpoint_.first == selecting_coursorpoint_.second ) { | |
726 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
727 | + }else{ | |
728 | + if(selecting_coursorpoint_.first > selecting_coursorpoint_.second) | |
729 | + { | |
730 | + std::swap(selecting_coursorpoint_.first , selecting_coursorpoint_.second); | |
731 | + } | |
732 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
733 | + } | |
734 | + SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
735 | + } | |
736 | + }else{ | |
737 | + if( push_mouse_left ){ | |
738 | + auto mpos = input->GetMousePos(); | |
739 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
740 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y); | |
741 | + // カレット変更 | |
742 | + if( multiline_ ) { | |
743 | + auto line_num = offset_y / font_height_; | |
744 | + //if( ( offset_y % font_height_ ) != 0 )++line_num; | |
745 | + int tmp = 0,cnt = 0; | |
746 | + if( line_num < (int)lines_.size() && line_num >= 0 ){ | |
747 | + for(int i = 0;i < line_num; ++i){ | |
748 | + cnt += lines_[i].size(); | |
749 | + } | |
750 | + for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ | |
751 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); | |
752 | + if( tmp + tmp_x < offset_x ){ | |
753 | + tmp += tmp_x; | |
754 | + ++cnt; | |
755 | + } | |
756 | + } | |
757 | + SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
758 | + } | |
759 | + }else{ | |
760 | + int tmp = 0,cnt = 0; | |
761 | + for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
762 | + auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
763 | + if( tmp + tmp_x < offset_x ){ | |
764 | + tmp += tmp_x; | |
765 | + ++cnt; | |
766 | + } | |
767 | + } | |
768 | + if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
769 | + SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
770 | + }else{ | |
771 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
772 | + } | |
773 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
774 | + } | |
775 | + } | |
776 | + } | |
777 | + // マウス右ボタンが押されたとき | |
778 | + if ( push_mouse_right && !prev_mouse_right ) { | |
779 | + if( x() <= input->GetMouseX() && input->GetMouseX() <= x() + width() && | |
780 | + y() <= input->GetMouseY() && input->GetMouseY() <= y() + height()){ | |
781 | + auto mouse_pos_ = input->GetMousePos(); | |
782 | + if( mouse_pos_.second + right_click_list_.absolute_height() > config_manager_->screen_height()){ | |
783 | + right_click_list_.set_top(mouse_pos_.second - right_click_list_.absolute_height()); | |
784 | + if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){ | |
785 | + right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
786 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
787 | + it->set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
788 | + it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12); | |
789 | + } | |
790 | + }else{ | |
791 | + right_click_list_.set_left(mouse_pos_.first); | |
792 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
793 | + it->set_left(mouse_pos_.first); | |
794 | + it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12); | |
795 | + } | |
796 | + } | |
797 | + }else{ | |
798 | + right_click_list_.set_top(mouse_pos_.second); | |
799 | + if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){ | |
800 | + right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
801 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
802 | + it->set_left(mouse_pos_.first - right_click_list_.absolute_width()); | |
803 | + it->set_top(mouse_pos_.second + 12); | |
804 | + } | |
805 | + }else{ | |
806 | + right_click_list_.set_left(mouse_pos_.first); | |
807 | + BOOST_FOREACH(auto it,right_click_list_.getItems()){ | |
808 | + it->set_left(mouse_pos_.first); | |
809 | + it->set_top(mouse_pos_.second + 12); | |
810 | + } | |
811 | + } | |
812 | + } | |
813 | + right_click_list_.set_visible(true); | |
814 | + //rightmenu_show_ = true; | |
815 | + } | |
816 | + } | |
817 | + | |
818 | + // カーソル位置(文字単位)を取得 | |
411 | 819 | cursor_byte_pos = GetKeyInputCursorPosition(input_handle_); |
412 | 820 | if (prev_cursor_pos_ != cursor_byte_pos) { |
413 | 821 | ResetCursorCount(); |
@@ -415,6 +823,7 @@ void Input::ProcessInput(InputManager* input) | ||
415 | 823 | |
416 | 824 | prev_cursor_pos_ = cursor_byte_pos; |
417 | 825 | |
826 | + | |
418 | 827 | // カーソルのドット単位の位置を取得する |
419 | 828 | cursor_dot_pos = GetDrawStringWidthToHandle(String, cursor_byte_pos, |
420 | 829 | font_handle_); |
@@ -621,6 +1030,7 @@ void Input::ProcessInput(InputManager* input) | ||
621 | 1030 | TCHAR c = *it; |
622 | 1031 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
623 | 1032 | line_buffer += tstring(&c, 1); |
1033 | + char_count++; | |
624 | 1034 | #else |
625 | 1035 | unsigned char c = *it; |
626 | 1036 | TCHAR string[2] = { 0, 0 }; |
@@ -659,7 +1069,7 @@ void Input::ProcessInput(InputManager* input) | ||
659 | 1069 | && cursor_moveto_x_ <= line_width + width |
660 | 1070 | && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ |
661 | 1071 | && cursor_moveto_y_ <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { |
662 | - SetKeyInputCursorPosition(prev_char_count, input_handle_); | |
1072 | + SetKeyInputCursorPosition(char_count - 1, input_handle_); | |
663 | 1073 | cursor_moveto_x_ = -1; |
664 | 1074 | cursor_moveto_y_ = -1; |
665 | 1075 | } |
@@ -716,6 +1126,7 @@ void Input::ProcessInput(InputManager* input) | ||
716 | 1126 | if (active()) { |
717 | 1127 | input->CancelKeyCountAll(); |
718 | 1128 | } |
1129 | + | |
719 | 1130 | } |
720 | 1131 | |
721 | 1132 | bool Input::active() |
@@ -815,6 +1226,51 @@ void Input::set_on_enter(const CallbackFunc& func) | ||
815 | 1226 | on_enter_ = func; |
816 | 1227 | } |
817 | 1228 | |
1229 | +tstring Input::selecting_text() const | |
1230 | +{ | |
1231 | + int select_start = 0,select_end = 0; | |
1232 | + GetKeyInputSelectArea(&select_start,&select_end,input_handle_); | |
1233 | + if( select_start > select_end )std::swap(select_start,select_end); | |
1234 | + tstring selecting_text; | |
1235 | + | |
1236 | + if( select_start > -1 && select_end != select_start ) { | |
1237 | + if ( multiline_ ) { | |
1238 | + BOOST_FOREACH(auto it,lines_){ | |
1239 | + TCHAR c[2] = {0}; | |
1240 | + if( select_start > it.size() && select_start != -1 ) { | |
1241 | + select_start -= it.size(); | |
1242 | + select_end -= it.size(); | |
1243 | + }else{ | |
1244 | + for(int i = select_start;i < select_end; ++i){ | |
1245 | + c[0] = it[i]; | |
1246 | + selecting_text += c; | |
1247 | + } | |
1248 | + select_start = -1; | |
1249 | + } | |
1250 | + } | |
1251 | + }else{ | |
1252 | + BOOST_FOREACH(auto it,lines_){ | |
1253 | + TCHAR c[2] = {0}; | |
1254 | + for(int i = select_start;i < select_end; ++i){ | |
1255 | + c[0] = it[i]; | |
1256 | + selecting_text += c; | |
1257 | + } | |
1258 | + } | |
1259 | + } | |
1260 | + } | |
1261 | + return selecting_text; | |
1262 | +} | |
1263 | + | |
1264 | +void Input::paste_text(tstring text) | |
1265 | +{ | |
1266 | + auto pos = GetKeyInputCursorPosition(input_handle_); | |
1267 | + TCHAR String[TEXT_BUFFER_SIZE]; | |
1268 | + GetKeyInputString(String, input_handle_); | |
1269 | + tstring dat(String, _tcslen(String)); | |
1270 | + dat.insert(pos,text); | |
1271 | + SetKeyInputString(dat.c_str(), input_handle_); | |
1272 | +} | |
1273 | + | |
818 | 1274 | bool Input::reverse_color() const |
819 | 1275 | { |
820 | 1276 | return reverse_color_; |
@@ -833,4 +1289,9 @@ bool Input::multiline() const | ||
833 | 1289 | void Input::set_multiline(bool flag) |
834 | 1290 | { |
835 | 1291 | multiline_ = flag; |
1292 | +} | |
1293 | + | |
1294 | +void Input::set_click_chancel_count(int count) | |
1295 | +{ | |
1296 | + click_cancel_count_ = count; | |
836 | 1297 | } |
\ No newline at end of file |
@@ -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,11 @@ 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 | + | |
55 | + void set_click_chancel_count(int count); | |
56 | + | |
48 | 57 | public: |
49 | 58 | void CancelSelect(); |
50 | 59 |
@@ -73,12 +82,22 @@ class Input { | ||
73 | 82 | std::vector<std::pair<int, int>> selecting_lines_; |
74 | 83 | std::vector<std::pair<int, int>> clause_lines_; |
75 | 84 | std::vector<std::pair<int, int>> selecting_clause_lines_; |
85 | + std::pair<int, int> selecting_coursorpoint_; | |
86 | + bool drag_flag_; | |
76 | 87 | |
77 | 88 | CallbackFunc on_enter_; |
78 | 89 | tstring message_; |
79 | 90 | |
80 | 91 | bool reverse_color_; |
81 | 92 | int blink_count_; |
93 | + bool rightmenu_show_; | |
94 | + //std::pair<int, int> mouse_pos_; | |
95 | + | |
96 | + UIList right_click_list_; | |
97 | + | |
98 | + ConfigManagerPtr config_manager_; | |
99 | + | |
100 | + int click_cancel_count_; | |
82 | 101 | |
83 | 102 | private: |
84 | 103 | const static size_t TEXT_BUFFER_SIZE; |
@@ -137,7 +137,7 @@ Handle<Value> Construct(const Arguments& args) { | ||
137 | 137 | UIBasePtr* instance = new UIBasePtr(new T()); |
138 | 138 | Local<v8::Object> thisObject = args.This(); |
139 | 139 | assert(thisObject->InternalFieldCount() > 0); |
140 | - thisObject->SetInternalField(0, External::New(instance)); | |
140 | + thisObject->SetInternalField(0, External::New(instance)); | |
141 | 141 | Persistent<v8::Object> holder = Persistent<v8::Object>::New(thisObject); |
142 | 142 | holder.MakeWeak(instance, Destruct); |
143 | 143 | return thisObject; |
@@ -23,6 +23,11 @@ UICustom::UICustom() | ||
23 | 23 | |
24 | 24 | UICustom::~UICustom() |
25 | 25 | { |
26 | + if( !graphic_handles_.empty() ){ | |
27 | + BOOST_FOREACH(auto handle,graphic_handles_){ | |
28 | + DeleteGraph(handle); | |
29 | + } | |
30 | + } | |
26 | 31 | } |
27 | 32 | |
28 | 33 | Handle<Value> UICustom::Property_processinput(Local<String> property, const AccessorInfo &info) |
@@ -98,6 +103,25 @@ void UICustom::DefineInstanceTemplate(Handle<ObjectTemplate>* object) | ||
98 | 103 | |
99 | 104 | SetFunction(object, "DrawLine", Function_DrawLine); |
100 | 105 | SetFunction(object, "DrawBox", Function_DrawBox); |
106 | + SetFunction(object, "DrawEdgeBox", Function_DrawEdgeBox); | |
107 | + SetFunction(object, "DrawCircle", Function_DrawCircle); | |
108 | + SetFunction(object, "DrawOval", Function_DrawOval); | |
109 | + SetFunction(object, "DrawTriangle", Function_DrawTriangle); | |
110 | + SetFunction(object, "DrawQuadrangle", Function_DrawQuadrangle); | |
111 | + SetFunction(object, "DrawPixel", Function_DrawPixel); | |
112 | + SetFunction(object, "Paint", Function_DrawLine); | |
113 | + SetFunction(object, "DrawPixelSet", Function_DrawBox); | |
114 | + SetFunction(object, "DrawLineSet", Function_DrawEdgeBox); | |
115 | + SetFunction(object, "DrawPixel3D", Function_DrawCircle); | |
116 | + SetFunction(object, "DrawCube", Function_DrawOval); | |
117 | + SetFunction(object, "DrawSphere", Function_DrawTriangle); | |
118 | + SetFunction(object, "DrawCapsule3D", Function_DrawQuadrangle); | |
119 | + SetFunction(object, "DrawCone3D", Function_DrawPixel); | |
120 | + | |
121 | + SetFunction(object, "LoadGraph", Function_LoadGraph); | |
122 | + SetFunction(object, "DeleteGraph", Function_DeleteGraph); | |
123 | + | |
124 | + SetFunction(object, "DrawText", Function_DrawText); | |
101 | 125 | } |
102 | 126 | |
103 | 127 | void UICustom::ProcessInput(InputManager* input) |
@@ -22,8 +22,7 @@ | ||
22 | 22 | const int UILabel::BASE_BLOCK_SIZE = 12; |
23 | 23 | |
24 | 24 | UILabel::UILabel() : |
25 | - font_handle_(ResourceManager::default_font_handle()), | |
26 | - clickchancel_count_(-1) | |
25 | + font_handle_(ResourceManager::default_font_handle()) | |
27 | 26 | { |
28 | 27 | } |
29 | 28 |
@@ -192,12 +191,9 @@ void UILabel::ProcessInput(InputManager* input) | ||
192 | 191 | on_click_.As<Function>()->CallAsFunction(Context::GetCurrent()->Global(), 0, nullptr); |
193 | 192 | }else if(!on_click_function_._Empty()) { |
194 | 193 | on_click_function_(this); |
194 | + parent_c_->set_visible(false); | |
195 | 195 | input->CancelMouseLeft(); |
196 | - clickchancel_count_ = 8; | |
197 | 196 | } |
198 | - }else if(clickchancel_count_ >= 0 ){ | |
199 | - input->CancelMouseLeft(); | |
200 | - --clickchancel_count_; | |
201 | 197 | }else if(hover && !hover_flag_){ |
202 | 198 | if(!on_hover_function_._Empty()) { |
203 | 199 | on_hover_function_(this); |
@@ -255,7 +251,6 @@ void UILabel::UpdatePosition() | ||
255 | 251 | |
256 | 252 | for (auto it = char_width_list_.begin(); it != char_width_list_.end(); ++it) { |
257 | 253 | if ( text_[text_cursor] == _T('\n')) { |
258 | - line_width = 0; | |
259 | 254 | line_num++; |
260 | 255 | substr_list_.push_back(text_cursor); |
261 | 256 | substr_list_.push_back(text_cursor + 1); |
@@ -46,8 +46,6 @@ class UILabel : public UIBase { | ||
46 | 46 | std::vector<int> char_width_list_; |
47 | 47 | int font_handle_; |
48 | 48 | |
49 | - int clickchancel_count_; | |
50 | - | |
51 | 49 | Color textcolor_, bgcolor_; |
52 | 50 | |
53 | 51 | private: |