• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révisionb77388ed941250301c5a9f6112a314361d006341 (tree)
l'heure2012-10-31 01:34:42
Auteurangeart <angeart@git....>
Commiterangeart

Message de Log

Inputの挙動を修正

Change Summary

Modification

--- a/client/ui/Input.cpp
+++ b/client/ui/Input.cpp
@@ -273,21 +273,27 @@ void Input::Draw()
273273 int select_start = 0,select_end = 0;
274274 GetKeyInputSelectArea(&select_start,&select_end,input_handle_);
275275 if( select_start > select_end )std::swap(select_start,select_end);
276-
276+ tstring str = text();
277277 if( select_start > -1 && select_end != select_start ) {
278- if ( multiline_ ) {
278+ int cnt = 0;
279279 BOOST_FOREACH(auto it,lines_){
280280 int width = 0;
281281 TCHAR c[2] = {0};
282282 if( select_start >= it.size() && select_start != -1 ) {
283283 DrawStringToHandle(internal_x, internal_y + current_line * font_height_,
284284 it.c_str(), text_color, font_handle_);
285+ cnt += it.size();
285286 if(select_start == it.size()){
286287 select_start -= it.size();
287- }else{
288+ select_end -= it.size() + 1;
289+ }else if(str[cnt] == _T('\n')){
288290 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();
289296 }
290- select_end -= it.size() + 1;
291297 ++current_line;
292298 }else if(select_start != -1){
293299 for(int i = 0;i < select_start;++i){
@@ -312,11 +318,31 @@ void Input::Draw()
312318 c, text_color, font_handle_);
313319 width += GetDrawStringWidthToHandle(c,1,font_handle_);
314320 }
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+ }
318338 }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+ }
320346 }
321347 ++current_line;
322348 }else if(select_start == -1){
@@ -325,34 +351,6 @@ void Input::Draw()
325351 ++current_line;
326352 }
327353 }
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- }
356354 }else{
357355 for (auto it = lines_.begin(); it != lines_.end(); ++it) {
358356 auto line = *it;
@@ -642,84 +640,87 @@ void Input::ProcessInput(InputManager* input)
642640 if (push_mouse_left && !prev_mouse_left) {
643641 auto mpos = input->GetMousePos();
644642 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();
646644 // カレット変更
647- if( multiline_ ) {
648645 auto line_num = offset_y / font_height_;
649646 //if( ( offset_y % font_height_ ) != 0 )++line_num;
650647 int tmp = 0,cnt = 0;
648+ auto str = text();
651649 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){
653651 cnt += lines_[i].size();
652+ if(str[cnt] != '\n')
653+ {
654+ --cnt;
655+ }
654656 }
655657 for(unsigned int i = 0;i < lines_[line_num].size(); ++i){
656658 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 ){
658660 tmp += tmp_x;
659661 ++cnt;
660662 }
661663 }
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_);
672665 }
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- }
680666 }
681667 // マウス左ボタンがドラッグされた時
682- if (push_mouse_left && prev_mouse_left ) {
668+ if (push_mouse_left && prev_mouse_left) {
669+ static std::vector<int> prev_line_size;
683670 int prev_cursor_pos = 0;
671+ bool clear_select = false;
684672 if( !drag_flag_ ){
685673 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+ }
686679 }else{
687680 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+ }
688690 }
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+ // カレット変更
694697 auto line_num = offset_y / font_height_;
695698 int tmp = 0,cnt = 0;
699+ auto str = text();
696700 if( line_num < (int)lines_.size() && line_num >= 0){
697701 for(int i = 0;i < line_num; ++i,++cnt){
698702 cnt += lines_[i].size();
703+ if(str[cnt] != '\n')
704+ {
705+ --cnt;
706+ }
699707 }
700708 for(unsigned int i = 0;i < lines_[line_num].size(); ++i){
701709 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 ){
703711 tmp += tmp_x;
704712 ++cnt;
705713 }
706714 }
707715 }
708716 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;
709720 }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;
719723 }
720- SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_);
721- SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_);
722- drag_flag_ = true;
723724 input->CancelMouseLeft();
724725 }
725726 // マウス左ボタンが離され、且つ前回ドラッグされていた時
@@ -740,42 +741,30 @@ void Input::ProcessInput(InputManager* input)
740741 if( push_mouse_left ){
741742 auto mpos = input->GetMousePos();
742743 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();
744745 // カレット変更
745- if( multiline_ ) {
746746 auto line_num = offset_y / font_height_;
747747 //if( ( offset_y % font_height_ ) != 0 )++line_num;
748748 int tmp = 0,cnt = 0;
749+ auto str = text();
749750 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){
751752 cnt += lines_[i].size();
753+ if(str[cnt] != '\n')
754+ {
755+ --cnt;
756+ }
752757 }
753758 for(unsigned int i = 0;i < lines_[line_num].size(); ++i){
754759 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 ){
756761 tmp += tmp_x;
757762 ++cnt;
758763 }
759764 }
760- SetKeyInputCursorPosition(line_num + cnt,input_handle_);
765+ SetKeyInputCursorPosition(cnt,input_handle_);
761766 }
762767 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- }
779768 }
780769 }
781770 // マウス右ボタンが押されたとき
@@ -1239,27 +1228,17 @@ tstring Input::selecting_text() const
12391228 tstring selecting_text;
12401229
12411230 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{
12591237 for(int i = select_start;i < select_end; ++i){
12601238 c[0] = it[i];
1261- selecting_text += c;
1239+ selecting_text += c;
12621240 }
1241+ select_start = -1;
12631242 }
12641243 }
12651244 }