Revisión | b77388ed941250301c5a9f6112a314361d006341 (tree) |
---|---|
Tiempo | 2012-10-31 01:34:42 |
Autor | angeart <angeart@git....> |
Commiter | angeart |
Inputの挙動を修正
@@ -273,21 +273,27 @@ void Input::Draw() | ||
273 | 273 | int select_start = 0,select_end = 0; |
274 | 274 | GetKeyInputSelectArea(&select_start,&select_end,input_handle_); |
275 | 275 | if( select_start > select_end )std::swap(select_start,select_end); |
276 | - | |
276 | + tstring str = text(); | |
277 | 277 | if( select_start > -1 && select_end != select_start ) { |
278 | - if ( multiline_ ) { | |
278 | + int cnt = 0; | |
279 | 279 | BOOST_FOREACH(auto it,lines_){ |
280 | 280 | int width = 0; |
281 | 281 | TCHAR c[2] = {0}; |
282 | 282 | if( select_start >= it.size() && select_start != -1 ) { |
283 | 283 | DrawStringToHandle(internal_x, internal_y + current_line * font_height_, |
284 | 284 | it.c_str(), text_color, font_handle_); |
285 | + cnt += it.size(); | |
285 | 286 | if(select_start == it.size()){ |
286 | 287 | select_start -= it.size(); |
287 | - }else{ | |
288 | + select_end -= it.size() + 1; | |
289 | + }else if(str[cnt] == _T('\n')){ | |
288 | 290 | select_start -= it.size() + 1; |
291 | + select_end -= it.size() + 1; | |
292 | + ++cnt; | |
293 | + }else{ | |
294 | + select_start -= it.size(); | |
295 | + select_end -= it.size(); | |
289 | 296 | } |
290 | - select_end -= it.size() + 1; | |
291 | 297 | ++current_line; |
292 | 298 | }else if(select_start != -1){ |
293 | 299 | for(int i = 0;i < select_start;++i){ |
@@ -312,11 +318,31 @@ void Input::Draw() | ||
312 | 318 | c, text_color, font_handle_); |
313 | 319 | width += GetDrawStringWidthToHandle(c,1,font_handle_); |
314 | 320 | } |
315 | - if(select_end > it.size()){ | |
316 | - select_end -= it.size() + 1; | |
317 | - select_start = 0; | |
321 | + cnt += it.size(); | |
322 | + if(cnt < str.size()) | |
323 | + { | |
324 | + if(str[cnt] == '\n'){ | |
325 | + select_end -= it.size() + 1; | |
326 | + select_start = 0; | |
327 | + if(select_end <= 0) | |
328 | + { | |
329 | + select_start = -1; | |
330 | + } | |
331 | + }else if(select_end > it.size()){ | |
332 | + select_end -= it.size(); | |
333 | + select_start = 0; | |
334 | + ++cnt; | |
335 | + }else{ | |
336 | + select_start = -1; | |
337 | + } | |
318 | 338 | }else{ |
319 | - select_start = -1; | |
339 | + if(select_end > it.size()){ | |
340 | + select_end -= it.size() + 1; | |
341 | + select_start = 0; | |
342 | + ++cnt; | |
343 | + }else{ | |
344 | + select_start = -1; | |
345 | + } | |
320 | 346 | } |
321 | 347 | ++current_line; |
322 | 348 | }else if(select_start == -1){ |
@@ -325,34 +351,6 @@ void Input::Draw() | ||
325 | 351 | ++current_line; |
326 | 352 | } |
327 | 353 | } |
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 | 354 | }else{ |
357 | 355 | for (auto it = lines_.begin(); it != lines_.end(); ++it) { |
358 | 356 | auto line = *it; |
@@ -642,84 +640,87 @@ void Input::ProcessInput(InputManager* input) | ||
642 | 640 | if (push_mouse_left && !prev_mouse_left) { |
643 | 641 | auto mpos = input->GetMousePos(); |
644 | 642 | auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); |
645 | - auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) + ResourceManager::default_font_size() * message_lines_.size(); | |
643 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) - ResourceManager::default_font_size() * message_lines_.size(); | |
646 | 644 | // カレット変更 |
647 | - if( multiline_ ) { | |
648 | 645 | auto line_num = offset_y / font_height_; |
649 | 646 | //if( ( offset_y % font_height_ ) != 0 )++line_num; |
650 | 647 | int tmp = 0,cnt = 0; |
648 | + auto str = text(); | |
651 | 649 | if( line_num < (int)lines_.size() && line_num >= 0 ){ |
652 | - for(int i = 0;i < line_num; ++i){ | |
650 | + for(int i = 0;i < line_num; ++i,++cnt){ | |
653 | 651 | cnt += lines_[i].size(); |
652 | + if(str[cnt] != '\n') | |
653 | + { | |
654 | + --cnt; | |
655 | + } | |
654 | 656 | } |
655 | 657 | for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ |
656 | 658 | auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); |
657 | - if( tmp + tmp_x < offset_x ){ | |
659 | + if( tmp + tmp_x <= offset_x ){ | |
658 | 660 | tmp += tmp_x; |
659 | 661 | ++cnt; |
660 | 662 | } |
661 | 663 | } |
662 | - SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
663 | - } | |
664 | - }else{ | |
665 | - int tmp = 0,cnt = 0; | |
666 | - for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
667 | - auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
668 | - if( tmp + tmp_x < offset_x ){ | |
669 | - tmp += tmp_x; | |
670 | - ++cnt; | |
671 | - } | |
664 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
672 | 665 | } |
673 | - if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
674 | - SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
675 | - }else{ | |
676 | - SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
677 | - } | |
678 | - SetKeyInputCursorPosition(cnt,input_handle_); | |
679 | - } | |
680 | 666 | } |
681 | 667 | // マウス左ボタンがドラッグされた時 |
682 | - if (push_mouse_left && prev_mouse_left ) { | |
668 | + if (push_mouse_left && prev_mouse_left) { | |
669 | + static std::vector<int> prev_line_size; | |
683 | 670 | int prev_cursor_pos = 0; |
671 | + bool clear_select = false; | |
684 | 672 | if( !drag_flag_ ){ |
685 | 673 | prev_cursor_pos = GetKeyInputCursorPosition(input_handle_); |
674 | + prev_line_size.clear(); | |
675 | + BOOST_FOREACH(auto line,lines_) | |
676 | + { | |
677 | + prev_line_size.push_back(line.size()); | |
678 | + } | |
686 | 679 | }else{ |
687 | 680 | prev_cursor_pos = selecting_coursorpoint_.first; |
681 | + auto prev_line = prev_line_size.begin(); | |
682 | + auto line = lines_.begin(); | |
683 | + for(;line != lines_.end() && prev_line != prev_line_size.end();++line,++prev_line) | |
684 | + { | |
685 | + if((*line).size() != (*prev_line)) | |
686 | + { | |
687 | + clear_select = true; | |
688 | + } | |
689 | + } | |
688 | 690 | } |
689 | - auto mpos = input->GetMousePos(); | |
690 | - auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
691 | - auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) + ResourceManager::default_font_size() * message_lines_.size(); | |
692 | - // カレット変更 | |
693 | - if( multiline_ ) { | |
691 | + if(!clear_select) | |
692 | + { | |
693 | + auto mpos = input->GetMousePos(); | |
694 | + auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); | |
695 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) - ResourceManager::default_font_size() * message_lines_.size(); | |
696 | + // カレット変更 | |
694 | 697 | auto line_num = offset_y / font_height_; |
695 | 698 | int tmp = 0,cnt = 0; |
699 | + auto str = text(); | |
696 | 700 | if( line_num < (int)lines_.size() && line_num >= 0){ |
697 | 701 | for(int i = 0;i < line_num; ++i,++cnt){ |
698 | 702 | cnt += lines_[i].size(); |
703 | + if(str[cnt] != '\n') | |
704 | + { | |
705 | + --cnt; | |
706 | + } | |
699 | 707 | } |
700 | 708 | for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ |
701 | 709 | auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); |
702 | - if( tmp + tmp_x < offset_x ){ | |
710 | + if( tmp + tmp_x <= offset_x ){ | |
703 | 711 | tmp += tmp_x; |
704 | 712 | ++cnt; |
705 | 713 | } |
706 | 714 | } |
707 | 715 | } |
708 | 716 | selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); |
717 | + SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
718 | + SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
719 | + drag_flag_ = true; | |
709 | 720 | }else{ |
710 | - int tmp = 0,cnt = 0; | |
711 | - for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
712 | - auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
713 | - if( tmp + tmp_x < offset_x ){ | |
714 | - tmp += tmp_x; | |
715 | - ++cnt; | |
716 | - } | |
717 | - } | |
718 | - selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt); | |
721 | + SetKeyInputSelectArea(-1,-1,input_handle_); | |
722 | + selecting_coursorpoint_.first = selecting_coursorpoint_.second; | |
719 | 723 | } |
720 | - SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
721 | - SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_); | |
722 | - drag_flag_ = true; | |
723 | 724 | input->CancelMouseLeft(); |
724 | 725 | } |
725 | 726 | // マウス左ボタンが離され、且つ前回ドラッグされていた時 |
@@ -740,42 +741,30 @@ void Input::ProcessInput(InputManager* input) | ||
740 | 741 | if( push_mouse_left ){ |
741 | 742 | auto mpos = input->GetMousePos(); |
742 | 743 | auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X); |
743 | - auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) + ResourceManager::default_font_size() * message_lines_.size(); | |
744 | + auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y) - ResourceManager::default_font_size() * message_lines_.size(); | |
744 | 745 | // カレット変更 |
745 | - if( multiline_ ) { | |
746 | 746 | auto line_num = offset_y / font_height_; |
747 | 747 | //if( ( offset_y % font_height_ ) != 0 )++line_num; |
748 | 748 | int tmp = 0,cnt = 0; |
749 | + auto str = text(); | |
749 | 750 | if( line_num < (int)lines_.size() && line_num >= 0 ){ |
750 | - for(int i = 0;i < line_num; ++i){ | |
751 | + for(int i = 0;i < line_num; ++i,++cnt){ | |
751 | 752 | cnt += lines_[i].size(); |
753 | + if(str[cnt] != '\n') | |
754 | + { | |
755 | + --cnt; | |
756 | + } | |
752 | 757 | } |
753 | 758 | for(unsigned int i = 0;i < lines_[line_num].size(); ++i){ |
754 | 759 | auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_); |
755 | - if( tmp + tmp_x < offset_x ){ | |
760 | + if( tmp + tmp_x <= offset_x ){ | |
756 | 761 | tmp += tmp_x; |
757 | 762 | ++cnt; |
758 | 763 | } |
759 | 764 | } |
760 | - SetKeyInputCursorPosition(line_num + cnt,input_handle_); | |
765 | + SetKeyInputCursorPosition(cnt,input_handle_); | |
761 | 766 | } |
762 | 767 | input->CancelMouseLeft(); |
763 | - }else{ | |
764 | - int tmp = 0,cnt = 0; | |
765 | - for(unsigned int i = 0;i < lines_[0].size(); ++i){ | |
766 | - auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_); | |
767 | - if( tmp + tmp_x < offset_x ){ | |
768 | - tmp += tmp_x; | |
769 | - ++cnt; | |
770 | - } | |
771 | - } | |
772 | - if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) { | |
773 | - SetKeyInputSelectArea( -1, -1, input_handle_ ); | |
774 | - }else{ | |
775 | - SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_); | |
776 | - } | |
777 | - SetKeyInputCursorPosition(cnt,input_handle_); | |
778 | - } | |
779 | 768 | } |
780 | 769 | } |
781 | 770 | // マウス右ボタンが押されたとき |
@@ -1239,27 +1228,17 @@ tstring Input::selecting_text() const | ||
1239 | 1228 | tstring selecting_text; |
1240 | 1229 | |
1241 | 1230 | if( select_start > -1 && select_end != select_start ) { |
1242 | - if ( multiline_ ) { | |
1243 | - BOOST_FOREACH(auto it,lines_){ | |
1244 | - TCHAR c[2] = {0}; | |
1245 | - if( select_start > it.size() && select_start != -1 ) { | |
1246 | - select_start -= it.size(); | |
1247 | - select_end -= it.size(); | |
1248 | - }else{ | |
1249 | - for(int i = select_start;i < select_end; ++i){ | |
1250 | - c[0] = it[i]; | |
1251 | - selecting_text += c; | |
1252 | - } | |
1253 | - select_start = -1; | |
1254 | - } | |
1255 | - } | |
1256 | - }else{ | |
1257 | - BOOST_FOREACH(auto it,lines_){ | |
1258 | - TCHAR c[2] = {0}; | |
1231 | + BOOST_FOREACH(auto it,lines_){ | |
1232 | + TCHAR c[2] = {0}; | |
1233 | + if( select_start > it.size() && select_start != -1 ) { | |
1234 | + select_start -= it.size(); | |
1235 | + select_end -= it.size(); | |
1236 | + }else{ | |
1259 | 1237 | for(int i = select_start;i < select_end; ++i){ |
1260 | 1238 | c[0] = it[i]; |
1261 | - selecting_text += c; | |
1239 | + selecting_text += c; | |
1262 | 1240 | } |
1241 | + select_start = -1; | |
1263 | 1242 | } |
1264 | 1243 | } |
1265 | 1244 | } |