• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisione6756353200e20fe86b5155ea83c7ccaeb7d3b07 (tree)
Time2012-09-04 03:23:59
Authorh2so5 <h2so5@git....>
Commiterh2so5

Log Message

InputとUILabelの改行時の不具合を修正

Change Summary

Incremental Difference

--- a/client/ui/Input.cpp
+++ b/client/ui/Input.cpp
@@ -150,7 +150,7 @@ void Input::Draw()
150150 auto line = *it;
151151 SetDrawBlendMode(DX_BLENDMODE_ALPHA, 140);
152152 DrawStringToHandle(internal_x,
153- internal_y + current_line * font_height_ - 3, unicode::ToTString(line).c_str(),
153+ internal_y + current_line * font_height_ - 3, line.c_str(),
154154 text_color, font_handle_);
155155 SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
156156 current_line++;
@@ -160,7 +160,7 @@ void Input::Draw()
160160 for (auto it = lines_.begin(); it != lines_.end(); ++it) {
161161 auto line = *it;
162162 DrawStringToHandle(internal_x, internal_y + current_line * font_height_,
163- unicode::ToTString(line).c_str(), text_color, font_handle_);
163+ line.c_str(), text_color, font_handle_);
164164 current_line++;
165165 }
166166
@@ -190,7 +190,7 @@ void Input::Draw()
190190 int height = (end_index - start_index) * font_height_;
191191
192192 for (int i = start_index; i < end_index; i++) {
193- auto candidate = unicode::ToTString(candidates_[i]);
193+ auto candidate = candidates_[i];
194194 width = std::max(width,
195195 GetDrawStringWidthToHandle(candidate.c_str(),
196196 candidate.size(), font_handle_));
@@ -250,7 +250,7 @@ void Input::Draw()
250250 }
251251 DrawStringToHandle(internal_x + x,
252252 internal_y + line_top + y,
253- unicode::ToTString(candidates_[i]).c_str(), GetColor(0, 0, 0),
253+ candidates_[i].c_str(), GetColor(0, 0, 0),
254254 font_handle_);
255255 line_top += font_height_;
256256 }
@@ -327,7 +327,7 @@ void Input::ProcessInput(InputManager* input)
327327 tstring cursor_back_str = buffer.substr(pos); // カーソル後の文字列
328328 auto new_string = cursor_front_str + _T('\n') + cursor_back_str;
329329
330- SetKeyInputString(unicode::ToTString(new_string).c_str(), input_handle_);
330+ SetKeyInputString(new_string.c_str(), input_handle_);
331331 SetKeyInputCursorPosition(pos + 1, input_handle_);
332332 CancelSelect();
333333 cursor_drag_count_ = 0;
@@ -355,7 +355,7 @@ void Input::ProcessInput(InputManager* input)
355355
356356 if (message_.size() > 0) {
357357 int current_line = 0;
358- std::string line_buffer;
358+ tstring line_buffer;
359359 int line_width = 0;
360360 int char_count = 0;
361361 for (auto it = message_.begin(); it != message_.end(); ++it) {
@@ -363,7 +363,7 @@ void Input::ProcessInput(InputManager* input)
363363 #ifdef UNICODE
364364 TCHAR c = *it;
365365 int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
366- line_buffer += unicode::ToString(tstring(&c, 1));
366+ line_buffer += c;
367367 #else
368368 unsigned char c = *it;
369369 TCHAR string[2] = { 0, 0 };
@@ -390,6 +390,9 @@ void Input::ProcessInput(InputManager* input)
390390 line_width += width;
391391 if (c == _T('\n')
392392 || line_width > internal_width - font_height_ / 2) {
393+ if (!line_buffer.empty() && line_buffer.back() == _T('\n')) {
394+ line_buffer.pop_back();
395+ }
393396 message_lines_.push_back(line_buffer);
394397 current_line++;
395398 line_buffer.clear();
@@ -454,7 +457,7 @@ void Input::ProcessInput(InputManager* input)
454457 std::swap(select_start, select_end);
455458 }
456459
457- std::string line_buffer;
460+ tstring line_buffer;
458461 int line_width = 0;
459462 int char_count = 0;
460463
@@ -467,7 +470,7 @@ void Input::ProcessInput(InputManager* input)
467470 #ifdef UNICODE
468471 TCHAR c = *it;
469472 int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
470- line_buffer += unicode::ToString(tstring(&c, 1));
473+ line_buffer += c;
471474 #else
472475 unsigned char c = *it;
473476 TCHAR string[2] = { 0, 0 };
@@ -513,6 +516,10 @@ void Input::ProcessInput(InputManager* input)
513516
514517 line_width += width;
515518 if (c == _T('\n') || line_width > internal_width - font_height_ / 2) {
519+ if (!line_buffer.empty() && line_buffer.back() == _T('\n')) {
520+ line_buffer.pop_back();
521+ }
522+
516523 lines_.push_back(line_buffer);
517524
518525 if (cursor_moveto_x_ >= line_width
@@ -544,7 +551,7 @@ void Input::ProcessInput(InputManager* input)
544551 #ifdef UNICODE
545552 TCHAR c = *it;
546553 int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
547- line_buffer += unicode::ToString(tstring(&c, 1));
554+ line_buffer += tstring(&c, 1);
548555 #else
549556 unsigned char c = *it;
550557 TCHAR string[2] = { 0, 0 };
@@ -603,7 +610,7 @@ void Input::ProcessInput(InputManager* input)
603610 #ifdef UNICODE
604611 TCHAR c = *it;
605612 int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
606- line_buffer += unicode::ToString(tstring(&c, 1));
613+ line_buffer += tstring(&c, 1);
607614 #else
608615 unsigned char c = *it;
609616 TCHAR string[2] = { 0, 0 };
@@ -649,6 +656,9 @@ void Input::ProcessInput(InputManager* input)
649656
650657 line_width += width;
651658 if (c == _T('\n') || line_width > internal_width - font_height_ / 2) {
659+ if (!line_buffer.empty() && line_buffer.back() == _T('\n')) {
660+ line_buffer.pop_back();
661+ }
652662 lines_.push_back(line_buffer);
653663
654664 if (cursor_moveto_x_ >= line_width
--- a/client/ui/Input.hpp
+++ b/client/ui/Input.hpp
@@ -57,8 +57,8 @@ class Input {
5757
5858 int input_handle_, font_handle_, font_height_;
5959
60- std::vector<std::string> message_lines_;
61- std::vector<std::string> lines_;
60+ std::vector<tstring> message_lines_;
61+ std::vector<tstring> lines_;
6262 std::vector<tstring> candidates_;
6363
6464 int candidate_x_, candidate_y_;
--- a/client/ui/UILabel.cpp
+++ b/client/ui/UILabel.cpp
@@ -32,25 +32,30 @@ UILabel::~UILabel()
3232
3333 void UILabel::set_text(const tstring& text)
3434 {
35- text_ = unicode::ToString(text);
35+ text_ = text;
3636
3737 // 文字幅を計算
3838 char_width_list_.clear();
3939 for (auto it = text_.begin(); it != text_.end(); ++it) {
40- unsigned char c = *it;
41- TCHAR string[2] = {0, 0};
42-
43- int width;
44- if (((c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc)) && (it + 1) != text_.end()) {
45- string[0] = c;
46- string[1] = *(it + 1);
47- ++it;
48- width = GetDrawStringWidthToHandle(string, 2, font_handle_);
49- } else {
50- string[0] = c;
51- width = GetDrawStringWidthToHandle(string, 1, font_handle_);
52- }
53- char_width_list_.push_back(width);
40+ #ifdef UNICODE
41+ TCHAR c = *it;
42+ int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
43+ #else
44+ unsigned char c = *it;
45+ TCHAR string[2] = {0, 0};
46+
47+ int width;
48+ if (((c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc)) && (it + 1) != text_.end()) {
49+ string[0] = c;
50+ string[1] = *(it + 1);
51+ ++it;
52+ width = GetDrawStringWidthToHandle(string, 2, font_handle_);
53+ } else {
54+ string[0] = c;
55+ width = GetDrawStringWidthToHandle(string, 1, font_handle_);
56+ }
57+ #endif
58+ char_width_list_.push_back(width);
5459 }
5560 }
5661
@@ -220,7 +225,7 @@ void UILabel::UpdatePosition()
220225 auto text_cursor = 0;
221226
222227 for (auto it = char_width_list_.begin(); it != char_width_list_.end(); ++it) {
223- if ( text_[text_cursor] == '\n') {
228+ if ( text_[text_cursor] == _T('\n')) {
224229 line_num++;
225230 substr_list_.push_back(text_cursor);
226231 substr_list_.push_back(text_cursor + 1);
@@ -233,12 +238,7 @@ void UILabel::UpdatePosition()
233238 line_width += *it;
234239 }
235240
236- unsigned char c = text_[text_cursor];
237- if ((c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc)) {
238- text_cursor += 2;
239- } else {
240- text_cursor++;
241- }
241+ text_cursor++;
242242 }
243243
244244 // if (!stable_width) {
--- a/client/ui/UILabel.hpp
+++ b/client/ui/UILabel.hpp
@@ -41,7 +41,7 @@ class UILabel : public UIBase {
4141 void UpdatePosition();
4242
4343 private:
44- std::string text_;
44+ tstring text_;
4545 std::vector<int> substr_list_;
4646 std::vector<int> char_width_list_;
4747 int font_handle_;