Révision | e6756353200e20fe86b5155ea83c7ccaeb7d3b07 (tree) |
---|---|
l'heure | 2012-09-04 03:23:59 |
Auteur | h2so5 <h2so5@git....> |
Commiter | h2so5 |
InputとUILabelの改行時の不具合を修正
@@ -150,7 +150,7 @@ void Input::Draw() | ||
150 | 150 | auto line = *it; |
151 | 151 | SetDrawBlendMode(DX_BLENDMODE_ALPHA, 140); |
152 | 152 | 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(), | |
154 | 154 | text_color, font_handle_); |
155 | 155 | SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); |
156 | 156 | current_line++; |
@@ -160,7 +160,7 @@ void Input::Draw() | ||
160 | 160 | for (auto it = lines_.begin(); it != lines_.end(); ++it) { |
161 | 161 | auto line = *it; |
162 | 162 | 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_); | |
164 | 164 | current_line++; |
165 | 165 | } |
166 | 166 |
@@ -190,7 +190,7 @@ void Input::Draw() | ||
190 | 190 | int height = (end_index - start_index) * font_height_; |
191 | 191 | |
192 | 192 | for (int i = start_index; i < end_index; i++) { |
193 | - auto candidate = unicode::ToTString(candidates_[i]); | |
193 | + auto candidate = candidates_[i]; | |
194 | 194 | width = std::max(width, |
195 | 195 | GetDrawStringWidthToHandle(candidate.c_str(), |
196 | 196 | candidate.size(), font_handle_)); |
@@ -250,7 +250,7 @@ void Input::Draw() | ||
250 | 250 | } |
251 | 251 | DrawStringToHandle(internal_x + x, |
252 | 252 | 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), | |
254 | 254 | font_handle_); |
255 | 255 | line_top += font_height_; |
256 | 256 | } |
@@ -327,7 +327,7 @@ void Input::ProcessInput(InputManager* input) | ||
327 | 327 | tstring cursor_back_str = buffer.substr(pos); // カーソル後の文字列 |
328 | 328 | auto new_string = cursor_front_str + _T('\n') + cursor_back_str; |
329 | 329 | |
330 | - SetKeyInputString(unicode::ToTString(new_string).c_str(), input_handle_); | |
330 | + SetKeyInputString(new_string.c_str(), input_handle_); | |
331 | 331 | SetKeyInputCursorPosition(pos + 1, input_handle_); |
332 | 332 | CancelSelect(); |
333 | 333 | cursor_drag_count_ = 0; |
@@ -355,7 +355,7 @@ void Input::ProcessInput(InputManager* input) | ||
355 | 355 | |
356 | 356 | if (message_.size() > 0) { |
357 | 357 | int current_line = 0; |
358 | - std::string line_buffer; | |
358 | + tstring line_buffer; | |
359 | 359 | int line_width = 0; |
360 | 360 | int char_count = 0; |
361 | 361 | for (auto it = message_.begin(); it != message_.end(); ++it) { |
@@ -363,7 +363,7 @@ void Input::ProcessInput(InputManager* input) | ||
363 | 363 | #ifdef UNICODE |
364 | 364 | TCHAR c = *it; |
365 | 365 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
366 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
366 | + line_buffer += c; | |
367 | 367 | #else |
368 | 368 | unsigned char c = *it; |
369 | 369 | TCHAR string[2] = { 0, 0 }; |
@@ -390,6 +390,9 @@ void Input::ProcessInput(InputManager* input) | ||
390 | 390 | line_width += width; |
391 | 391 | if (c == _T('\n') |
392 | 392 | || line_width > internal_width - font_height_ / 2) { |
393 | + if (!line_buffer.empty() && line_buffer.back() == _T('\n')) { | |
394 | + line_buffer.pop_back(); | |
395 | + } | |
393 | 396 | message_lines_.push_back(line_buffer); |
394 | 397 | current_line++; |
395 | 398 | line_buffer.clear(); |
@@ -454,7 +457,7 @@ void Input::ProcessInput(InputManager* input) | ||
454 | 457 | std::swap(select_start, select_end); |
455 | 458 | } |
456 | 459 | |
457 | - std::string line_buffer; | |
460 | + tstring line_buffer; | |
458 | 461 | int line_width = 0; |
459 | 462 | int char_count = 0; |
460 | 463 |
@@ -467,7 +470,7 @@ void Input::ProcessInput(InputManager* input) | ||
467 | 470 | #ifdef UNICODE |
468 | 471 | TCHAR c = *it; |
469 | 472 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
470 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
473 | + line_buffer += c; | |
471 | 474 | #else |
472 | 475 | unsigned char c = *it; |
473 | 476 | TCHAR string[2] = { 0, 0 }; |
@@ -513,6 +516,10 @@ void Input::ProcessInput(InputManager* input) | ||
513 | 516 | |
514 | 517 | line_width += width; |
515 | 518 | 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 | + | |
516 | 523 | lines_.push_back(line_buffer); |
517 | 524 | |
518 | 525 | if (cursor_moveto_x_ >= line_width |
@@ -544,7 +551,7 @@ void Input::ProcessInput(InputManager* input) | ||
544 | 551 | #ifdef UNICODE |
545 | 552 | TCHAR c = *it; |
546 | 553 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
547 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
554 | + line_buffer += tstring(&c, 1); | |
548 | 555 | #else |
549 | 556 | unsigned char c = *it; |
550 | 557 | TCHAR string[2] = { 0, 0 }; |
@@ -603,7 +610,7 @@ void Input::ProcessInput(InputManager* input) | ||
603 | 610 | #ifdef UNICODE |
604 | 611 | TCHAR c = *it; |
605 | 612 | int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); |
606 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
613 | + line_buffer += tstring(&c, 1); | |
607 | 614 | #else |
608 | 615 | unsigned char c = *it; |
609 | 616 | TCHAR string[2] = { 0, 0 }; |
@@ -649,6 +656,9 @@ void Input::ProcessInput(InputManager* input) | ||
649 | 656 | |
650 | 657 | line_width += width; |
651 | 658 | 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 | + } | |
652 | 662 | lines_.push_back(line_buffer); |
653 | 663 | |
654 | 664 | if (cursor_moveto_x_ >= line_width |
@@ -57,8 +57,8 @@ class Input { | ||
57 | 57 | |
58 | 58 | int input_handle_, font_handle_, font_height_; |
59 | 59 | |
60 | - std::vector<std::string> message_lines_; | |
61 | - std::vector<std::string> lines_; | |
60 | + std::vector<tstring> message_lines_; | |
61 | + std::vector<tstring> lines_; | |
62 | 62 | std::vector<tstring> candidates_; |
63 | 63 | |
64 | 64 | int candidate_x_, candidate_y_; |
@@ -32,25 +32,30 @@ UILabel::~UILabel() | ||
32 | 32 | |
33 | 33 | void UILabel::set_text(const tstring& text) |
34 | 34 | { |
35 | - text_ = unicode::ToString(text); | |
35 | + text_ = text; | |
36 | 36 | |
37 | 37 | // 文字幅を計算 |
38 | 38 | char_width_list_.clear(); |
39 | 39 | 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); | |
54 | 59 | } |
55 | 60 | } |
56 | 61 |
@@ -220,7 +225,7 @@ void UILabel::UpdatePosition() | ||
220 | 225 | auto text_cursor = 0; |
221 | 226 | |
222 | 227 | 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')) { | |
224 | 229 | line_num++; |
225 | 230 | substr_list_.push_back(text_cursor); |
226 | 231 | substr_list_.push_back(text_cursor + 1); |
@@ -233,12 +238,7 @@ void UILabel::UpdatePosition() | ||
233 | 238 | line_width += *it; |
234 | 239 | } |
235 | 240 | |
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++; | |
242 | 242 | } |
243 | 243 | |
244 | 244 | // if (!stable_width) { |
@@ -41,7 +41,7 @@ class UILabel : public UIBase { | ||
41 | 41 | void UpdatePosition(); |
42 | 42 | |
43 | 43 | private: |
44 | - std::string text_; | |
44 | + tstring text_; | |
45 | 45 | std::vector<int> substr_list_; |
46 | 46 | std::vector<int> char_width_list_; |
47 | 47 | int font_handle_; |