Revision | fcbd616b097d039c69b5a294fb364c980cbdf556 (tree) |
---|---|
Time | 2012-09-04 02:44:21 |
Author | h2so5 <h2so5@git....> |
Commiter | h2so5 |
InputBoxのソースを整理、挙動のバグを修正
例外発生時の処理をいくつか追加
@@ -58,9 +58,12 @@ Client::Client(const std::string& host, | ||
58 | 58 | std::stringstream port_str; |
59 | 59 | port_str << remote_tcp_port; |
60 | 60 | |
61 | - { | |
61 | + try { | |
62 | 62 | tcp::resolver::query query(host, port_str.str()); |
63 | 63 | iterator_ = resolver_.resolve(query); |
64 | + } catch (const std::exception& e) { | |
65 | + Logger::Error(_T("%s"), unicode::ToTString(e.what())); | |
66 | + return; | |
64 | 67 | } |
65 | 68 | |
66 | 69 | udp::resolver resolver(io_service_); |
@@ -66,11 +66,11 @@ void MainLoop::Update() | ||
66 | 66 | player_manager_->ProcessInput(&input); |
67 | 67 | player_manager_->Update(); |
68 | 68 | |
69 | - card_manager_->ProcessInput(&input); | |
70 | - card_manager_->Update(); | |
71 | - | |
72 | 69 | world_manager_->ProcessInput(&input); |
73 | 70 | world_manager_->Update(); |
71 | + | |
72 | + card_manager_->ProcessInput(&input); | |
73 | + card_manager_->Update(); | |
74 | 74 | } |
75 | 75 | |
76 | 76 | void MainLoop::Draw() |
@@ -6,15 +6,8 @@ | ||
6 | 6 | #include <DxLib.h> |
7 | 7 | #include <stdint.h> |
8 | 8 | |
9 | +const size_t Input::TEXT_BUFFER_SIZE = 1024; | |
9 | 10 | const size_t Input::HISTORY_MAX_SIZE = 50; |
10 | - | |
11 | -const int Input::DEFAULT_MAX_WIDTH = 600; | |
12 | - | |
13 | -const int Input::BOX_MIN_WIDTH = 200; | |
14 | -const int Input::BOX_TOP_MARGIN = 36; | |
15 | -const int Input::BOX_BOTTOM_MARGIN = 24; | |
16 | -const int Input::BOX_SIDE_MARGIN = 24; | |
17 | - | |
18 | 11 | const int Input::KEY_REPEAT_FRAME = 6; |
19 | 12 | |
20 | 13 | const int Input::INPUT_MARGIN_X = 8; |
@@ -26,7 +19,8 @@ const int Input::IME_MARGIN_Y = 16; | ||
26 | 19 | const int Input::IME_MAX_PAGE_SIZE = 6; |
27 | 20 | const int Input::IME_MIN_WIDTH = 120; |
28 | 21 | |
29 | -Input::Input() | |
22 | +Input::Input() : | |
23 | + reverse_color_(false) | |
30 | 24 | { |
31 | 25 | input_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
32 | 26 | _T("resources/images/gui/gui_inputbox_input_bg.png"), 2, 2, 12, 12); |
@@ -54,7 +48,13 @@ Input::Input() | ||
54 | 48 | void Input::Draw() |
55 | 49 | { |
56 | 50 | { |
57 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 200); | |
51 | + int alpha = active() ? 255 : 150; | |
52 | + | |
53 | + if (reverse_color_) { | |
54 | + SetDrawBlendMode(DX_BLENDMODE_INVSRC, alpha); | |
55 | + } else { | |
56 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha); | |
57 | + } | |
58 | 58 | |
59 | 59 | DrawGraph(x_, y_, *input_bg_image_handle_[0], TRUE); |
60 | 60 | DrawGraph(x_ + width_ - 12, y_, *input_bg_image_handle_[1], TRUE); |
@@ -142,7 +142,7 @@ void Input::Draw() | ||
142 | 142 | current_line++; |
143 | 143 | } |
144 | 144 | |
145 | - int text_color = GetColor(0, 0, 0); | |
145 | + int text_color = reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0); | |
146 | 146 | current_line = 0; |
147 | 147 | |
148 | 148 | if (message_lines_.size() > 0) { |
@@ -292,20 +292,16 @@ void Input::ProcessInput(InputManager* input) | ||
292 | 292 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
293 | 293 | // bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5); |
294 | 294 | |
295 | - auto input_text = GetInputString(); | |
296 | - if (!active() && first_key_return && CheckKeyInput(input_handle_) == 0) { | |
297 | - set_active(true); | |
298 | - } else if (!active() && push_key_v && push_key_ctrl) { | |
295 | + auto input_text = text(); | |
296 | + if (!active() && push_key_v && push_key_ctrl) { | |
299 | 297 | set_active(true); |
300 | 298 | } else { |
301 | 299 | if (push_key_shift && first_key_return) { |
302 | 300 | SetActiveKeyInput(input_handle_); |
303 | 301 | } else if (first_key_return) { |
304 | - if (input_text.size() == 0) { | |
305 | - set_active(false); | |
306 | - } else if (CheckKeyInput(input_handle_) == 1) { | |
302 | + if (CheckKeyInput(input_handle_) == 1) { | |
307 | 303 | if (on_enter_) { |
308 | - if (on_enter_(input_text)) { | |
304 | + if (on_enter_(unicode::ToString(input_text))) { | |
309 | 305 | SetKeyInputString(_T(""), input_handle_); |
310 | 306 | } |
311 | 307 | } |
@@ -314,57 +310,6 @@ void Input::ProcessInput(InputManager* input) | ||
314 | 310 | } |
315 | 311 | } |
316 | 312 | |
317 | -// if (active() && push_long_backspace && GetKeyInputCursorPosition(input_handle_) == 0) { | |
318 | -// if (selecting_tab_index_ == -1) { | |
319 | -// script_tab_.message.clear(); | |
320 | -// } else { | |
321 | -// tabs_.at(selecting_tab_index_).message.clear(); | |
322 | -// } | |
323 | -// } | |
324 | -// | |
325 | -// ProcessInputTabs(input); | |
326 | -// UpdateBase(input); | |
327 | -// UpdateTabs(); | |
328 | -// | |
329 | -// if (push_mouse_left) { | |
330 | -// if (cursor_drag_count == 1) { | |
331 | -// prev_cursor_pos_ = GetKeyInputCursorPosition(input_handle_); | |
332 | -// } | |
333 | -// cursor_drag_count++; | |
334 | -// input->CancelMouseLeft(); | |
335 | -// } else { | |
336 | -// cursor_drag_count = 0; | |
337 | -// } | |
338 | -// | |
339 | -// if (first_key_shift) { | |
340 | -// prev_cursor_pos_ = GetKeyInputCursorPosition(input_handle_); | |
341 | -// } | |
342 | -// | |
343 | -// x_ = x_ + BOX_SIDE_MARGIN; | |
344 | -// y_ = y_ + BOX_TOP_MARGIN; | |
345 | -// width_ = width_ - BOX_SIDE_MARGIN * 2; | |
346 | -// | |
347 | -// if (push_mouse_left) { | |
348 | -// auto pos = input->GetMousePos(); | |
349 | -// int internal_x = x_ + INPUT_MARGIN_X; | |
350 | -// int internal_y = y_ + INPUT_MARGIN_Y; | |
351 | -// cursor_moveto_x_ = pos.first - internal_x; | |
352 | -// cursor_moveto_y_ = pos.second - internal_y; | |
353 | -// ResetCursorCount(); | |
354 | -// } | |
355 | -// | |
356 | -// if (cursor_drag_count > 1) { | |
357 | -// SetKeyInputSelectArea(GetKeyInputCursorPosition(input_handle_), | |
358 | -// prev_cursor_pos_, input_handle_); | |
359 | -// } | |
360 | -// | |
361 | -// // カーソル移動中は強制表示 | |
362 | -// if (input->GetKeyCount(KEY_INPUT_RIGHT) > 0 | |
363 | -// || input->GetKeyCount(KEY_INPUT_LEFT) > 0) { | |
364 | -// | |
365 | -// ResetCursorCount(); | |
366 | -// } | |
367 | - | |
368 | 313 | if (push_repeat_key_up) { |
369 | 314 | cursor_moveto_y_ = cursor_y_ - font_height_ / 2; |
370 | 315 | cursor_moveto_x_ = cursor_x_ + 2; |
@@ -375,12 +320,12 @@ void Input::ProcessInput(InputManager* input) | ||
375 | 320 | |
376 | 321 | if (push_key_shift && push_repeat_key_return && multiline_) { |
377 | 322 | |
378 | - auto buffer = GetInputString(); | |
323 | + auto buffer = text(); | |
379 | 324 | uint32_t pos = GetKeyInputCursorPosition(input_handle_); |
380 | 325 | |
381 | - std::string cursor_front_str = buffer.substr(0, pos); // カーソル前の文字列 | |
382 | - std::string cursor_back_str = buffer.substr(pos); // カーソル後の文字列 | |
383 | - auto new_string = cursor_front_str + '\n' + cursor_back_str; | |
326 | + tstring cursor_front_str = buffer.substr(0, pos); // カーソル前の文字列 | |
327 | + tstring cursor_back_str = buffer.substr(pos); // カーソル後の文字列 | |
328 | + auto new_string = cursor_front_str + _T('\n') + cursor_back_str; | |
384 | 329 | |
385 | 330 | SetKeyInputString(unicode::ToTString(new_string).c_str(), input_handle_); |
386 | 331 | SetKeyInputCursorPosition(pos + 1, input_handle_); |
@@ -391,14 +336,14 @@ void Input::ProcessInput(InputManager* input) | ||
391 | 336 | int cursor_byte_pos, cursor_dot_pos; |
392 | 337 | int draw_dot_pos = 0; |
393 | 338 | |
394 | - TCHAR String[1024]; | |
339 | + TCHAR String[TEXT_BUFFER_SIZE]; | |
395 | 340 | GetKeyInputString(String, input_handle_); |
396 | 341 | |
397 | 342 | // 単一行設定の時、最初の行だけを表示 |
398 | 343 | if (!multiline_) { |
399 | 344 | tstring buffer(String, _tcslen(String)); |
400 | 345 | size_t pos; |
401 | - if ((pos = buffer.find('\n')) != std::string::npos) { | |
346 | + if ((pos = buffer.find(_T('\n'))) != std::string::npos) { | |
402 | 347 | SetKeyInputString(buffer.substr(0, pos).c_str(), input_handle_); |
403 | 348 | } |
404 | 349 | } |
@@ -443,7 +388,7 @@ void Input::ProcessInput(InputManager* input) | ||
443 | 388 | #endif |
444 | 389 | |
445 | 390 | line_width += width; |
446 | - if (c == '\n' | |
391 | + if (c == _T('\n') | |
447 | 392 | || line_width > internal_width - font_height_ / 2) { |
448 | 393 | message_lines_.push_back(line_buffer); |
449 | 394 | current_line++; |
@@ -567,14 +512,14 @@ void Input::ProcessInput(InputManager* input) | ||
567 | 512 | } |
568 | 513 | |
569 | 514 | line_width += width; |
570 | - if (c == '\n' || line_width > internal_width - font_height_ / 2) { | |
515 | + if (c == _T('\n') || line_width > internal_width - font_height_ / 2) { | |
571 | 516 | lines_.push_back(line_buffer); |
572 | 517 | |
573 | 518 | if (cursor_moveto_x_ >= line_width |
574 | 519 | && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ |
575 | 520 | && cursor_moveto_y_ |
576 | 521 | <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { |
577 | - if (c == '\n') { | |
522 | + if (c == _T('\n')) { | |
578 | 523 | SetKeyInputCursorPosition(char_count - 1, |
579 | 524 | input_handle_); |
580 | 525 | } else { |
@@ -703,14 +648,14 @@ void Input::ProcessInput(InputManager* input) | ||
703 | 648 | } |
704 | 649 | |
705 | 650 | line_width += width; |
706 | - if (c == '\n' || line_width > internal_width - font_height_ / 2) { | |
651 | + if (c == _T('\n') || line_width > internal_width - font_height_ / 2) { | |
707 | 652 | lines_.push_back(line_buffer); |
708 | 653 | |
709 | 654 | if (cursor_moveto_x_ >= line_width |
710 | 655 | && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ |
711 | 656 | && cursor_moveto_y_ |
712 | 657 | <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { |
713 | - if (c == '\n') { | |
658 | + if (c == _T('\n')) { | |
714 | 659 | SetKeyInputCursorPosition(char_count - 1, |
715 | 660 | input_handle_); |
716 | 661 | } else { |
@@ -753,13 +698,6 @@ void Input::ProcessInput(InputManager* input) | ||
753 | 698 | } |
754 | 699 | } |
755 | 700 | |
756 | -std::string Input::GetInputString() | |
757 | -{ | |
758 | - TCHAR String[1024]; | |
759 | - GetKeyInputString(String, input_handle_); | |
760 | - return unicode::ToString(tstring(String, _tcslen(String))); | |
761 | -} | |
762 | - | |
763 | 701 | bool Input::active() |
764 | 702 | { |
765 | 703 | return GetActiveKeyInput() == input_handle_; |
@@ -830,7 +768,7 @@ void Input::set_height(int height) | ||
830 | 768 | |
831 | 769 | tstring Input::text() const |
832 | 770 | { |
833 | - TCHAR String[1024]; | |
771 | + TCHAR String[TEXT_BUFFER_SIZE]; | |
834 | 772 | GetKeyInputString(String, input_handle_); |
835 | 773 | return tstring(String, _tcslen(String)); |
836 | 774 | } |
@@ -854,3 +792,13 @@ void Input::set_on_enter(const CallbackFunc& func) | ||
854 | 792 | { |
855 | 793 | on_enter_ = func; |
856 | 794 | } |
795 | + | |
796 | +bool Input::reverse_color() const | |
797 | +{ | |
798 | + return reverse_color_; | |
799 | +} | |
800 | + | |
801 | +void Input::set_reverse_color(bool flag) | |
802 | +{ | |
803 | + reverse_color_ = flag; | |
804 | +} | |
\ No newline at end of file |
@@ -19,8 +19,6 @@ class Input { | ||
19 | 19 | void Update(); |
20 | 20 | void ProcessInput(InputManager* input); |
21 | 21 | |
22 | - std::string GetInputString(); | |
23 | - | |
24 | 22 | bool active(); |
25 | 23 | void set_active(bool flag); |
26 | 24 |
@@ -39,11 +37,16 @@ class Input { | ||
39 | 37 | tstring message() const; |
40 | 38 | void set_message(const tstring& message); |
41 | 39 | |
40 | + bool reverse_color() const; | |
41 | + void set_reverse_color(bool flag); | |
42 | + | |
42 | 43 | void set_on_enter(const CallbackFunc& func); |
43 | 44 | |
45 | + public: | |
46 | + void CancelSelect(); | |
47 | + | |
44 | 48 | private: |
45 | 49 | void ResetCursorCount(); |
46 | - void CancelSelect(); | |
47 | 50 | |
48 | 51 | private: |
49 | 52 | int x_, y_, width_, height_; |
@@ -71,18 +74,12 @@ class Input { | ||
71 | 74 | CallbackFunc on_enter_; |
72 | 75 | tstring message_; |
73 | 76 | |
77 | + bool reverse_color_; | |
74 | 78 | int blink_count_; |
75 | 79 | |
76 | 80 | private: |
81 | + const static size_t TEXT_BUFFER_SIZE; | |
77 | 82 | const static size_t HISTORY_MAX_SIZE; |
78 | - | |
79 | - const static int DEFAULT_MAX_WIDTH; | |
80 | - | |
81 | - const static int BOX_MIN_WIDTH; | |
82 | - const static int BOX_TOP_MARGIN; | |
83 | - const static int BOX_BOTTOM_MARGIN; | |
84 | - const static int BOX_SIDE_MARGIN; | |
85 | - | |
86 | 83 | const static int KEY_REPEAT_FRAME; |
87 | 84 | |
88 | 85 | const static int INPUT_MARGIN_X; |
@@ -38,20 +38,13 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) : | ||
38 | 38 | width_(800), |
39 | 39 | height_(100), |
40 | 40 | multiline_(true), |
41 | - input_handle_(MakeKeyInput(400, FALSE, FALSE, FALSE)), | |
42 | 41 | font_height_(ResourceManager::default_font_size()), |
43 | 42 | drag_offset_x_(-1), |
44 | 43 | drag_offset_y_(-1), |
45 | 44 | drag_resize_offset_x_(-1), |
46 | 45 | drag_resize_offset_y_(-1), |
47 | 46 | min_input_height_(font_height_ + INPUT_MARGIN_Y * 2), |
48 | - cursor_moveto_x_(-1), | |
49 | - cursor_moveto_y_(-1), | |
50 | - selecting_candidate_(-1), | |
51 | - candidate_x_(-1), | |
52 | - candidate_y_(-1), | |
53 | 47 | selecting_tab_index_(0), |
54 | - blink_count_(0), | |
55 | 48 | manager_accessor_(manager_accessor), |
56 | 49 | card_(std::make_shared<Card>(manager_accessor_, "", "immo", "", "", "", |
57 | 50 | std::vector<std::string>(), false, false)) |
@@ -60,8 +53,6 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) : | ||
60 | 53 | font_handle_ = ResourceManager::default_font_handle(); |
61 | 54 | bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
62 | 55 | _T("resources/images/gui/gui_inputbox_bg.png"), 2, 2, 24, 24); |
63 | - input_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( | |
64 | - _T("resources/images/gui/gui_inputbox_input_bg.png"), 2, 2, 12, 12); | |
65 | 56 | tab_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
66 | 57 | _T("resources/images/gui/gui_inputbox_tab_bg.png"), 2, 2, 12, 12); |
67 | 58 | tab_bg_inactive_image_handle_ = ResourceManager::LoadCachedDivGraph<4>( |
@@ -71,26 +62,52 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) : | ||
71 | 62 | |
72 | 63 | script_icon_image_handle_ = ResourceManager::LoadCachedGraph(_T("resources/images/gui/gui_inputbox_tab_script_icon.png")); |
73 | 64 | |
74 | - input_height_ = font_height_ + INPUT_MARGIN_Y * 2; | |
75 | - | |
76 | 65 | int screen_width, screen_height; |
77 | 66 | GetScreenState(&screen_width, &screen_height, nullptr); |
78 | 67 | width_ = std::min(DEFAULT_MAX_WIDTH + 0, (int)(screen_width * 0.4)); |
79 | - height_ = input_height_ + BOX_TOP_MARGIN + BOX_BOTTOM_MARGIN; | |
68 | + height_ = input_.height() + BOX_TOP_MARGIN + BOX_BOTTOM_MARGIN; | |
80 | 69 | x_ = (screen_width - width_) / 2; |
81 | 70 | y_ = screen_height - height_ - BOX_BOTTOM_MARGIN; |
82 | 71 | |
83 | 72 | selecting_tab_index_ = 0; |
84 | 73 | |
85 | - | |
74 | + Activate(); | |
86 | 75 | if (auto card_manager = manager_accessor_->card_manager().lock()) { |
87 | 76 | card_manager->AddCard(card_); |
88 | 77 | } |
78 | + | |
79 | + input_.set_on_enter([this](const std::string& text) -> bool{ | |
80 | + | |
81 | + if (input_.text().empty()) { | |
82 | + input_.set_active(false); | |
83 | + } else { | |
84 | + if (selecting_tab_index_ == -1) { | |
85 | + card_->Execute(unicode::ToString(input_.text()), "mmo", | |
86 | + [&](const v8::Handle<v8::Value>& result, const std::string& error){ | |
87 | + if (error.size() > 0) { | |
88 | + script_tab_.message = unicode::ToTString(error); | |
89 | + } else if (!result.IsEmpty()) { | |
90 | + script_tab_.message = _T("=> ") + | |
91 | + unicode::ToTString(std::string(*String::Utf8Value(result->ToString()))); | |
92 | + } else { | |
93 | + script_tab_.message = _T(""); | |
94 | + } | |
95 | + input_.set_message(script_tab_.message); | |
96 | + }); | |
97 | + } else if (!tabs_.empty()) { | |
98 | + if (auto card = | |
99 | + tabs_.at(selecting_tab_index_).card.lock()) { | |
100 | + card->onEnter(unicode::ToString(input_.text())); | |
101 | + } | |
102 | + } | |
103 | + } | |
104 | + | |
105 | + return true; | |
106 | + }); | |
89 | 107 | } |
90 | 108 | |
91 | 109 | InputBox::~InputBox() |
92 | 110 | { |
93 | - DeleteKeyInput(input_handle_); | |
94 | 111 | } |
95 | 112 | |
96 | 113 | void InputBox::DrawTabs() |
@@ -99,8 +116,7 @@ void InputBox::DrawTabs() | ||
99 | 116 | { |
100 | 117 | int tab_index = 0; |
101 | 118 | SetDrawArea(x_, script_tab_.y, script_tab_.x, script_tab_.y + script_tab_.height); |
102 | - for (auto it = tabs_.begin(); it != tabs_.end(); ++it) { | |
103 | - auto tab = *it; | |
119 | + BOOST_FOREACH(auto& tab, tabs_) { | |
104 | 120 | |
105 | 121 | std::array<ImageHandlePtr, 4>* image_handle; |
106 | 122 | if (selecting_tab_index_ == tab_index) { |
@@ -232,232 +248,11 @@ void InputBox::DrawBase() | ||
232 | 248 | SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); |
233 | 249 | } |
234 | 250 | |
235 | -void InputBox::DrawInputBase() | |
236 | -{ | |
237 | - int input_bg_alpha; | |
238 | - if (IsActive()) { | |
239 | - input_bg_alpha = 255; | |
240 | - } else { | |
241 | - input_bg_alpha = 100; | |
242 | - } | |
243 | - | |
244 | - if (IsScriptMode()) { | |
245 | - SetDrawBlendMode(DX_BLENDMODE_INVSRC, input_bg_alpha); | |
246 | - } else { | |
247 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, input_bg_alpha); | |
248 | - } | |
249 | - | |
250 | - DrawGraph(input_x_, input_y_, *input_bg_image_handle_[0], TRUE); | |
251 | - DrawGraph(input_x_ + input_width_ - 12, input_y_, *input_bg_image_handle_[1], TRUE); | |
252 | - DrawGraph(input_x_, input_y_ + input_height_ - 12, *input_bg_image_handle_[2], TRUE); | |
253 | - DrawGraph(input_x_ + input_width_ - 12, input_y_ + input_height_ - 12, *input_bg_image_handle_[3], TRUE); | |
254 | - | |
255 | - DrawRectExtendGraphF(input_x_ + 12, input_y_, | |
256 | - input_x_ + input_width_ - 12, input_y_ + 12, | |
257 | - 0, 0, 1, 12, *input_bg_image_handle_[1], TRUE); | |
258 | - | |
259 | - DrawRectExtendGraphF(input_x_ + 12, input_y_ + input_height_ - 12, | |
260 | - input_x_ + input_width_ - 12, input_y_ + input_height_, | |
261 | - 0, 0, 1, 12, *input_bg_image_handle_[3], TRUE); | |
262 | - | |
263 | - DrawRectExtendGraphF(input_x_, input_y_ + 12, | |
264 | - input_x_ + 12, input_y_ + input_height_ - 12, | |
265 | - 0, 0, 12, 1, *input_bg_image_handle_[2], TRUE); | |
266 | - | |
267 | - DrawRectExtendGraphF(input_x_ + input_width_ - 12, input_y_ + 12, | |
268 | - input_x_ + input_width_, input_y_ + input_height_ - 12, | |
269 | - 0, 0, 12, 1, *input_bg_image_handle_[3], TRUE); | |
270 | - | |
271 | - DrawRectExtendGraphF(input_x_ + 12, input_y_ + 12, | |
272 | - input_x_ + input_width_ - 12, input_y_ + input_height_ - 12, | |
273 | - 0, 0, 1, 1, *input_bg_image_handle_[3], TRUE); | |
274 | - | |
275 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
276 | -} | |
277 | - | |
278 | -void InputBox::DrawInputText() | |
279 | -{ | |
280 | - int internal_x = input_x_ + INPUT_MARGIN_X; | |
281 | - int internal_y = input_y_ + INPUT_MARGIN_Y; | |
282 | - // int internal_width = input_width_ - INPUT_MARGIN * 2; | |
283 | - // int internal_height = input_height_ - INPUT_MARGIN * 2; | |
284 | - | |
285 | - // 選択範囲の背景を描画 | |
286 | - int current_line = 0; | |
287 | - for (auto it = selecting_lines_.begin(); it != selecting_lines_.end(); ++it) { | |
288 | - auto line = *it; | |
289 | - if (line.first < line.second) { | |
290 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 100); | |
291 | - DrawBox(internal_x + line.first, | |
292 | - internal_y + current_line * font_height_, | |
293 | - internal_x + line.second, | |
294 | - internal_y + (current_line + 1) * font_height_, | |
295 | - GetColor(255, 0, 255), TRUE); | |
296 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
297 | - } | |
298 | - current_line++; | |
299 | - } | |
300 | - | |
301 | - current_line = 0; | |
302 | - for (auto it = clause_lines_.begin(); it != clause_lines_.end(); ++it) { | |
303 | - auto line = *it; | |
304 | - if (line.first < line.second) { | |
305 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 100); | |
306 | - DrawBox(internal_x + line.first, | |
307 | - internal_y + current_line * font_height_, | |
308 | - internal_x + line.second, | |
309 | - internal_y + (current_line + 1) * font_height_, | |
310 | - GetColor(0, 255, 255), TRUE); | |
311 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
312 | - } | |
313 | - current_line++; | |
314 | - } | |
315 | - | |
316 | - current_line = 0; | |
317 | - candidate_x_ = -1, candidate_y_ = -1; | |
318 | - for (auto it = selecting_clause_lines_.begin(); it != selecting_clause_lines_.end(); ++it) { | |
319 | - auto line = *it; | |
320 | - if (line.first < line.second) { | |
321 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 100); | |
322 | - DrawBox(internal_x + line.first, | |
323 | - internal_y + current_line * font_height_, | |
324 | - internal_x + line.second, | |
325 | - internal_y + (current_line + 1) * font_height_, | |
326 | - GetColor(255, 0, 255), TRUE); | |
327 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
328 | - | |
329 | - if (candidate_x_ < 0) { | |
330 | - candidate_x_ = line.first; | |
331 | - candidate_y_ = (current_line + 1) * font_height_; | |
332 | - } | |
333 | - } | |
334 | - current_line++; | |
335 | - } | |
336 | - | |
337 | - int text_color = IsScriptMode() ? GetColor(255, 255, 255) : GetColor(0, 0, 0); | |
338 | - current_line = 0; | |
339 | - | |
340 | - if (message_lines_.size() > 0) { | |
341 | - for (auto it = message_lines_.begin(); it != message_lines_.end(); ++it) { | |
342 | - auto line = *it; | |
343 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 140); | |
344 | - DrawStringToHandle(internal_x, | |
345 | - internal_y + current_line * font_height_ - 3, unicode::ToTString(line).c_str(), | |
346 | - text_color, font_handle_); | |
347 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
348 | - current_line++; | |
349 | - } | |
350 | - } | |
351 | - | |
352 | - for (auto it = lines_.begin(); it != lines_.end(); ++it) { | |
353 | - auto line = *it; | |
354 | - DrawStringToHandle(internal_x, internal_y + current_line * font_height_, | |
355 | - unicode::ToTString(line).c_str(), text_color, font_handle_); | |
356 | - current_line++; | |
357 | - } | |
358 | - | |
359 | - // カーソルを描画 | |
360 | - if (clause_lines_.size() <= 0 && IsActive() && blink_count_ < 30) { | |
361 | - DrawBox(internal_x + cursor_x_, internal_y + cursor_y_, | |
362 | - internal_x + cursor_x_ + 2, | |
363 | - internal_y + cursor_y_ + font_height_, text_color, | |
364 | - TRUE); | |
365 | - } | |
366 | -} | |
367 | - | |
368 | -void InputBox::DrawCandidates() | |
369 | -{ | |
370 | - int internal_x = input_x_ + INPUT_MARGIN_X; | |
371 | - int internal_y = input_y_ + INPUT_MARGIN_Y; | |
372 | - | |
373 | - if (selecting_candidate_ >= 0) { | |
374 | - | |
375 | - int start_index = (selecting_candidate_ / IME_MAX_PAGE_SIZE) | |
376 | - * IME_MAX_PAGE_SIZE; | |
377 | - int end_index = std::min(start_index + IME_MAX_PAGE_SIZE, | |
378 | - static_cast<int>(candidates_.size() - 1)); | |
379 | - | |
380 | - int x = candidate_x_; | |
381 | - int y; | |
382 | - int width = IME_MIN_WIDTH; | |
383 | - int height = (end_index - start_index) * font_height_; | |
384 | - | |
385 | - for (int i = start_index; i < end_index; i++) { | |
386 | - auto candidate = unicode::ToTString(candidates_[i]); | |
387 | - width = std::max(width, | |
388 | - GetDrawStringWidthToHandle(candidate.c_str(), | |
389 | - candidate.size(), font_handle_)); | |
390 | - } | |
391 | - | |
392 | - int screen_height; | |
393 | - GetScreenState(nullptr, &screen_height, nullptr); | |
394 | - | |
395 | - if (internal_y + height + candidate_x_ >= screen_height - IME_MARGIN_Y * 2) { | |
396 | - y = candidate_y_ - font_height_ - height - IME_MARGIN_Y; | |
397 | - } else { | |
398 | - y = candidate_y_ + IME_MARGIN_Y; | |
399 | - } | |
400 | - | |
401 | - if (height > 0) { | |
402 | - int base_x = internal_x + x - IME_MARGIN_BASE; | |
403 | - int base_y = internal_y + y - IME_MARGIN_BASE; | |
404 | - int base_width = width + IME_MARGIN_BASE * 2; | |
405 | - int base_height = height + IME_MARGIN_BASE * 2; | |
406 | - | |
407 | - DrawGraph(base_x, base_y, *ime_image_handle_[0], TRUE); | |
408 | - DrawGraph(base_x + base_width - 12, base_y, *ime_image_handle_[1], TRUE); | |
409 | - DrawGraph(base_x, base_y + base_height - 12, *ime_image_handle_[2], TRUE); | |
410 | - DrawGraph(base_x + base_width - 12, base_y + base_height - 12, | |
411 | - *ime_image_handle_[3], TRUE); | |
412 | - | |
413 | - DrawRectExtendGraphF(base_x + 12, base_y, base_x + base_width - 12, | |
414 | - base_y + 12, 0, 0, 1, 12, *ime_image_handle_[1], TRUE); | |
415 | - | |
416 | - DrawRectExtendGraphF(base_x + 12, base_y + base_height - 12, | |
417 | - base_x + base_width - 12, base_y + base_height, 0, 0, 1, 12, | |
418 | - *ime_image_handle_[3], TRUE); | |
419 | - | |
420 | - DrawRectExtendGraphF(base_x, base_y + 12, base_x + 12, | |
421 | - base_y + base_height - 12, 0, 0, 12, 1, *ime_image_handle_[2], | |
422 | - TRUE); | |
423 | - | |
424 | - DrawRectExtendGraphF(base_x + base_width - 12, base_y + 12, | |
425 | - base_x + base_width, base_y + base_height - 12, 0, 0, 12, 1, | |
426 | - *ime_image_handle_[3], TRUE); | |
427 | - | |
428 | - DrawRectExtendGraphF(base_x + 12, base_y + 12, base_x + base_width - 12, | |
429 | - base_y + base_height - 12, 0, 0, 1, 1, *ime_image_handle_[3], | |
430 | - TRUE); | |
431 | - } | |
432 | - | |
433 | - int line_top = 0; | |
434 | - for (int i = start_index; i < end_index; i++) { | |
435 | - if (i == selecting_candidate_) { | |
436 | - SetDrawBlendMode(DX_BLENDMODE_ALPHA, 100); | |
437 | - DrawBox(internal_x + x - 2, | |
438 | - internal_y + line_top + y, | |
439 | - internal_x + x + width + 2, | |
440 | - internal_y + line_top + y + font_height_, | |
441 | - GetColor(255, 0, 255), TRUE); | |
442 | - SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
443 | - } | |
444 | - DrawStringToHandle(internal_x + x, | |
445 | - internal_y + line_top + y, | |
446 | - unicode::ToTString(candidates_[i]).c_str(), GetColor(0, 0, 0), | |
447 | - font_handle_); | |
448 | - line_top += font_height_; | |
449 | - } | |
450 | - } | |
451 | -} | |
452 | - | |
453 | 251 | void InputBox::Draw() |
454 | 252 | { |
455 | 253 | DrawBase(); |
456 | - DrawInputBase(); | |
457 | - DrawInputText(); | |
458 | 254 | DrawTabs(); |
459 | - DrawCandidates(); | |
460 | - // card_->Draw(); | |
255 | + input_.Draw(); | |
461 | 256 | } |
462 | 257 | |
463 | 258 | int InputBox::multiline() const |
@@ -472,20 +267,7 @@ void InputBox::set_multiline(int multiline) | ||
472 | 267 | |
473 | 268 | void InputBox::CancelSelect() |
474 | 269 | { |
475 | - int pos = GetKeyInputCursorPosition(input_handle_); | |
476 | - prev_cursor_pos_ = pos; | |
477 | - SetKeyInputSelectArea(-1, -1, input_handle_); | |
478 | -} | |
479 | - | |
480 | -void InputBox::UpdateCursorCount() | |
481 | -{ | |
482 | - blink_count_ += 1; | |
483 | - blink_count_ %= 60; | |
484 | -} | |
485 | - | |
486 | -void InputBox::ResetCursorCount() | |
487 | -{ | |
488 | - blink_count_ = 0; | |
270 | + input_.CancelSelect(); | |
489 | 271 | } |
490 | 272 | |
491 | 273 | bool InputBox::IsScriptMode() |
@@ -510,29 +292,22 @@ void InputBox::SwitchTab(int index) | ||
510 | 292 | |
511 | 293 | if (selecting_tab_index_ == -1) { |
512 | 294 | SetInputString(script_tab_.text); |
295 | + input_.set_message(script_tab_.message); | |
296 | + input_.set_reverse_color(true); | |
513 | 297 | } else if (!tabs_.empty()) { |
514 | 298 | SetInputString(tabs_.at(selecting_tab_index_).text); |
299 | + input_.set_message(tabs_.at(selecting_tab_index_).message); | |
300 | + input_.set_reverse_color(false); | |
515 | 301 | } |
516 | 302 | } |
517 | 303 | |
518 | -std::string InputBox::GetInputString() const { | |
519 | - TCHAR String[1024]; | |
520 | - GetKeyInputString(String, input_handle_); | |
521 | - return unicode::ToString(tstring(String, _tcslen(String))); | |
522 | -} | |
523 | - | |
524 | -void InputBox::SetInputString(const std::string& text) | |
525 | -{ | |
526 | - SetKeyInputString(unicode::ToTString(text).c_str(), input_handle_); | |
304 | +tstring InputBox::GetInputString() const { | |
305 | + return input_.text(); | |
527 | 306 | } |
528 | 307 | |
529 | - | |
530 | -void InputBox::AddInputHistory(const std::string& text) | |
308 | +void InputBox::SetInputString(const tstring& text) | |
531 | 309 | { |
532 | - history_.push_back(text); | |
533 | - if (history_.size() > HISTORY_MAX_SIZE) { | |
534 | - history_.pop_front(); | |
535 | - } | |
310 | + input_.set_text(text); | |
536 | 311 | } |
537 | 312 | |
538 | 313 | void InputBox::ProcessInput(InputManager* input) |
@@ -563,496 +338,46 @@ void InputBox::ProcessInput(InputManager* input) | ||
563 | 338 | + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0; |
564 | 339 | bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5); |
565 | 340 | |
566 | - auto input_text = GetInputString(); | |
567 | - if (!IsActive() && first_key_return && CheckKeyInput(input_handle_) == 0) { | |
341 | + bool empty = input_.text().empty(); | |
342 | + input_.ProcessInput(input); | |
343 | + | |
344 | + if (IsActive() && first_key_return && empty) { | |
345 | + Inactivate(); | |
346 | + } else if (!IsActive() && first_key_return) { | |
568 | 347 | Activate(); |
569 | 348 | } else if (!IsActive() && push_key_v && push_key_ctrl) { |
570 | 349 | Activate(); |
571 | - } else { | |
572 | - if (push_key_shift && first_key_return) { | |
573 | - SetActiveKeyInput(input_handle_); | |
574 | - } else if (first_key_return) { | |
575 | - if (input_text.size() == 0) { | |
576 | - Inactivate(); | |
577 | - } else if (CheckKeyInput(input_handle_) == 1) { | |
578 | - AddInputHistory(input_text); | |
579 | - if (selecting_tab_index_ == -1) { | |
580 | - SetKeyInputString(_T(""), input_handle_); | |
581 | - card_->Execute(input_text, "immo", | |
582 | - [&](const v8::Handle<v8::Value>& result, const std::string& error){ | |
583 | - if (error.size() > 0) { | |
584 | - script_tab_.message = error; | |
585 | - } else if (!result.IsEmpty()) { | |
586 | - script_tab_.message = "=> " + std::string(*String::Utf8Value(result->ToString())); | |
587 | - } else { | |
588 | - script_tab_.message = ""; | |
589 | - } | |
590 | - }); | |
591 | - } else if (!tabs_.empty()) { | |
592 | - SetKeyInputString(_T(""), input_handle_); | |
593 | - if (auto card = | |
594 | - tabs_.at(selecting_tab_index_).card.lock()) { | |
595 | - card->onEnter(input_text); | |
596 | - } | |
597 | - } | |
598 | - SetActiveKeyInput(input_handle_); | |
599 | - } | |
600 | - } | |
601 | - } | |
602 | - | |
603 | - if (IsActive() && push_long_backspace && GetKeyInputCursorPosition(input_handle_) == 0) { | |
604 | - if (selecting_tab_index_ == -1) { | |
605 | - script_tab_.message.clear(); | |
606 | - } else { | |
607 | - tabs_.at(selecting_tab_index_).message.clear(); | |
608 | - } | |
609 | 350 | } |
610 | 351 | |
611 | 352 | ProcessInputTabs(input); |
612 | 353 | UpdateBase(input); |
613 | 354 | UpdateTabs(); |
614 | 355 | |
615 | - if (push_mouse_left) { | |
616 | - if (cursor_drag_count == 1) { | |
617 | - prev_cursor_pos_ = GetKeyInputCursorPosition(input_handle_); | |
618 | - } | |
619 | - cursor_drag_count++; | |
620 | - //input->CancelMouseLeft(); | |
621 | - } else { | |
622 | - cursor_drag_count = 0; | |
623 | - } | |
624 | - | |
625 | - if (first_key_shift) { | |
626 | - prev_cursor_pos_ = GetKeyInputCursorPosition(input_handle_); | |
627 | - } | |
628 | - | |
629 | - input_x_ = x_ + BOX_SIDE_MARGIN; | |
630 | - input_y_ = y_ + BOX_TOP_MARGIN; | |
631 | - input_width_ = width_ - BOX_SIDE_MARGIN * 2; | |
632 | - | |
633 | - bool hover = (x_ <= input->GetMouseX() && input->GetMouseX() <= x_ + width_ | |
634 | - && y_ <= input->GetMouseY() && input->GetMouseY() <= y_ + height_); | |
635 | - if (push_mouse_left && hover) { | |
636 | - auto pos = input->GetMousePos(); | |
637 | - int internal_x = input_x_ + INPUT_MARGIN_X; | |
638 | - int internal_y = input_y_ + INPUT_MARGIN_Y; | |
639 | - cursor_moveto_x_ = pos.first - internal_x; | |
640 | - cursor_moveto_y_ = pos.second - internal_y; | |
641 | - ResetCursorCount(); | |
642 | - input->CancelMouseLeft(); | |
643 | - } | |
644 | - | |
645 | - if (cursor_drag_count > 1) { | |
646 | - SetKeyInputSelectArea(GetKeyInputCursorPosition(input_handle_), | |
647 | - prev_cursor_pos_, input_handle_); | |
648 | - } | |
649 | - | |
650 | - // カーソル移動中は強制表示 | |
651 | - if (input->GetKeyCount(KEY_INPUT_RIGHT) > 0 | |
652 | - || input->GetKeyCount(KEY_INPUT_LEFT) > 0) { | |
653 | - | |
654 | - ResetCursorCount(); | |
655 | - } | |
656 | - | |
657 | - if (push_repeat_key_up) { | |
658 | - cursor_moveto_y_ = cursor_y_ - font_height_ / 2; | |
659 | - cursor_moveto_x_ = cursor_x_ + 2; | |
660 | - } else if (push_repeat_key_down) { | |
661 | - cursor_moveto_y_ = cursor_y_ + font_height_ + font_height_ / 2; | |
662 | - cursor_moveto_x_ = cursor_x_ + 2; | |
663 | - } | |
664 | - | |
665 | - if (push_key_shift && push_repeat_key_return && multiline_) { | |
666 | 356 | |
667 | - auto buffer = GetInputString(); | |
668 | - uint32_t pos = GetKeyInputCursorPosition(input_handle_); | |
357 | + int new_height = input_.height() + BOX_TOP_MARGIN + BOX_BOTTOM_MARGIN; | |
669 | 358 | |
670 | - std::string cursor_front_str = buffer.substr(0, pos); // カーソル前の文字列 | |
671 | - std::string cursor_back_str = buffer.substr(pos); // カーソル後の文字列 | |
672 | - auto new_string = cursor_front_str + '\n' + cursor_back_str; | |
673 | - | |
674 | - SetKeyInputString(unicode::ToTString(new_string).c_str(), input_handle_); | |
675 | - SetKeyInputCursorPosition(pos + 1, input_handle_); | |
676 | - CancelSelect(); | |
677 | - cursor_drag_count = 0; | |
678 | - } | |
679 | - | |
680 | - int cursor_byte_pos, cursor_dot_pos; | |
681 | - int draw_dot_pos = 0; | |
682 | - | |
683 | - TCHAR String[1024]; | |
684 | - GetKeyInputString(String, input_handle_); | |
685 | - | |
686 | - // 単一行設定の時、最初の行だけを表示 | |
687 | - if (!multiline_) { | |
688 | - tstring buffer(String, _tcslen(String)); | |
689 | - size_t pos; | |
690 | - if ((pos = buffer.find('\n')) != std::string::npos) { | |
691 | - SetKeyInputString(buffer.substr(0, pos).c_str(), input_handle_); | |
692 | - } | |
693 | - } | |
694 | - | |
695 | - int internal_width = input_width_ - INPUT_MARGIN_X * 2; | |
696 | - // int internal_height = input_height_ - INPUT_MARGIN * 2; | |
697 | - | |
698 | - std::string* message = nullptr; | |
699 | - if (selecting_tab_index_ == -1) { | |
700 | - message = &script_tab_.message; | |
701 | - } else if (!tabs_.empty()) { | |
702 | - message = &tabs_[selecting_tab_index_].message; | |
703 | - } | |
704 | - | |
705 | - message_lines_.clear(); | |
706 | - | |
707 | - if (message && message->size() > 0) { | |
708 | - int current_line = 0; | |
709 | - std::string line_buffer; | |
710 | - int line_width = 0; | |
711 | - int char_count = 0; | |
712 | - for (auto it = message->begin(); it != message->end(); ++it) { | |
713 | - #ifdef UNICODE | |
714 | - TCHAR c = *it; | |
715 | - int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); | |
716 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
717 | - #else | |
718 | - unsigned char c = *it; | |
719 | - TCHAR string[2] = { 0, 0 }; | |
720 | - | |
721 | - int width = 0; | |
722 | - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) { | |
723 | - string[0] = c; | |
724 | - string[1] = *(it + 1); | |
725 | - ++it; | |
726 | - width = GetDrawStringWidthToHandle(string, 2, font_handle_); | |
727 | - line_buffer += string[0]; | |
728 | - line_buffer += string[1]; | |
729 | - char_count += 2; | |
730 | - } else if (c == '\n') { | |
731 | - char_count++; | |
732 | - } else { | |
733 | - string[0] = c; | |
734 | - width = GetDrawStringWidthToHandle(string, 1, font_handle_); | |
735 | - line_buffer += string[0]; | |
736 | - char_count++; | |
737 | - } | |
738 | - #endif | |
739 | - | |
740 | - line_width += width; | |
741 | - if (c == '\n' | |
742 | - || line_width > internal_width - font_height_ / 2) { | |
743 | - message_lines_.push_back(line_buffer); | |
744 | - current_line++; | |
745 | - line_buffer.clear(); | |
746 | - line_width = 0; | |
747 | - } | |
748 | - } | |
749 | - | |
750 | - message_lines_.push_back(line_buffer); | |
359 | + int screen_height; | |
360 | + GetScreenState(nullptr, &screen_height, nullptr); | |
361 | + if (y_ + height_ > screen_height - BOX_TOP_MARGIN) { | |
362 | + y_ -= new_height - height_; | |
363 | + // input_.set_y(y_ + BOX_TOP_MARGIN); | |
751 | 364 | } |
752 | 365 | |
753 | - if (IsActive()) { | |
754 | - // カーソル位置(byte)を取得 | |
755 | - cursor_byte_pos = GetKeyInputCursorPosition(input_handle_); | |
756 | - | |
757 | - // カーソルのドット単位の位置を取得する | |
758 | - cursor_dot_pos = GetDrawStringWidthToHandle(String, cursor_byte_pos, | |
759 | - font_handle_); | |
760 | - draw_dot_pos += cursor_dot_pos; | |
761 | - | |
762 | - tstring cursor_front_str(String, cursor_byte_pos); // カーソル前の文字列 | |
763 | - tstring cursor_back_str(String + cursor_byte_pos); // カーソル後の文字列 | |
764 | - | |
765 | - std::vector<tstring> clauses; // 入力中の文節 | |
766 | - std::vector<tstring> candidates; // 変換候補 | |
767 | - | |
768 | - lines_.clear(); | |
769 | - selecting_lines_.clear(); | |
770 | - clause_lines_.clear(); | |
771 | - selecting_clause_lines_.clear(); | |
772 | - candidates_.clear(); | |
773 | - | |
774 | - // 文節データを取得 | |
775 | - // int selecting_clause = -1; | |
776 | - selecting_candidate_ = -1; | |
777 | - | |
778 | - IMEINPUTDATA *ImeData = GetIMEInputData(); | |
779 | - if (ImeData && IsActive()) { | |
780 | - for (int i = 0; i < ImeData->ClauseNum; i++) { | |
781 | - clauses.push_back( | |
782 | - tstring( | |
783 | - ImeData->InputString | |
784 | - + ImeData->ClauseData[i].Position, | |
785 | - ImeData->ClauseData[i].Length)); | |
786 | - } | |
787 | - selecting_clause_ = ImeData->SelectClause; | |
788 | - | |
789 | - if (ImeData->CandidateNum > 0) { | |
790 | - for (int i = 0; i < ImeData->CandidateNum; i++) { | |
791 | - candidates_.push_back( | |
792 | - tstring(ImeData->CandidateList[i], | |
793 | - _tcslen(ImeData->CandidateList[i]))); | |
794 | - } | |
795 | - | |
796 | - selecting_candidate_ = ImeData->SelectCandidate; | |
797 | - } | |
798 | - } | |
799 | - | |
800 | - // 選択範囲を取得 | |
801 | - int select_start, select_end; | |
802 | - GetKeyInputSelectArea(&select_start, &select_end, input_handle_); | |
803 | - if (select_start > select_end) { | |
804 | - std::swap(select_start, select_end); | |
805 | - } | |
806 | - | |
807 | - std::string line_buffer; | |
808 | - int line_width = 0; | |
809 | - int char_count = 0; | |
810 | - | |
811 | - // カーソル前のデータを描画 | |
812 | - for (auto it = cursor_front_str.begin(); it != cursor_front_str.end(); | |
813 | - ++it) { | |
814 | - int prev_char_count = char_count; | |
815 | - | |
816 | - #ifdef UNICODE | |
817 | - TCHAR c = *it; | |
818 | - int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); | |
819 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
820 | - #else | |
821 | - unsigned char c = *it; | |
822 | - TCHAR string[2] = { 0, 0 }; | |
823 | - | |
824 | - int width = 0; | |
825 | - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) { | |
826 | - string[0] = c; | |
827 | - string[1] = *(it + 1); | |
828 | - ++it; | |
829 | - width = GetDrawStringWidthToHandle(string, 2, font_handle_); | |
830 | - line_buffer += string[0]; | |
831 | - line_buffer += string[1]; | |
832 | - char_count += 2; | |
833 | - } else if (c == '\n') { | |
834 | - char_count++; | |
835 | - } else { | |
836 | - string[0] = c; | |
837 | - width = GetDrawStringWidthToHandle(string, 1, font_handle_); | |
838 | - line_buffer += string[0]; | |
839 | - char_count++; | |
840 | - } | |
841 | - #endif | |
842 | - | |
843 | - // 選択範囲を記録 | |
844 | - if (select_start < char_count && char_count <= select_end) { | |
845 | - selecting_lines_.resize(static_cast<int>(lines_.size() + message_lines_.size()) + 1, | |
846 | - std::pair<int, int>(99999, 0)); | |
847 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first = std::min( | |
848 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first, line_width); | |
849 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second = std::max( | |
850 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second, | |
851 | - line_width + std::max(width, 3)); | |
852 | - } | |
853 | - | |
854 | - if (line_width - width / 2 <= cursor_moveto_x_ | |
855 | - && cursor_moveto_x_ <= line_width + width | |
856 | - && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ | |
857 | - && cursor_moveto_y_ <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { | |
858 | - SetKeyInputCursorPosition(prev_char_count, input_handle_); | |
859 | - cursor_moveto_x_ = -1; | |
860 | - cursor_moveto_y_ = -1; | |
861 | - } | |
862 | - | |
863 | - line_width += width; | |
864 | - if (c == '\n' || line_width > internal_width - font_height_ / 2) { | |
865 | - lines_.push_back(line_buffer); | |
866 | - | |
867 | - if (cursor_moveto_x_ >= line_width | |
868 | - && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ | |
869 | - && cursor_moveto_y_ | |
870 | - <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { | |
871 | - if (c == '\n') { | |
872 | - SetKeyInputCursorPosition(char_count - 1, | |
873 | - input_handle_); | |
874 | - } else { | |
875 | - SetKeyInputCursorPosition(char_count, input_handle_); | |
876 | - } | |
877 | - cursor_moveto_x_ = -1; | |
878 | - cursor_moveto_y_ = -1; | |
879 | - } | |
880 | - | |
881 | - line_buffer.clear(); | |
882 | - line_width = 0; | |
883 | - } | |
884 | - } | |
885 | - | |
886 | - cursor_x_ = line_width; | |
887 | - cursor_y_ = static_cast<int>(lines_.size() + message_lines_.size()) * font_height_; | |
888 | - | |
889 | - // 変換中データを描画 | |
890 | - for (uint32_t index = 0; index < clauses.size(); index++) { | |
891 | - for (auto it = clauses[index].begin(); it != clauses[index].end(); | |
892 | - ++it) { | |
893 | - #ifdef UNICODE | |
894 | - TCHAR c = *it; | |
895 | - int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); | |
896 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
897 | - #else | |
898 | - unsigned char c = *it; | |
899 | - TCHAR string[2] = { 0, 0 }; | |
900 | - | |
901 | - int width = 0; | |
902 | - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) { | |
903 | - string[0] = c; | |
904 | - string[1] = *(it + 1); | |
905 | - ++it; | |
906 | - width = GetDrawStringWidthToHandle(string, 2, font_handle_); | |
907 | - line_buffer += string[0]; | |
908 | - line_buffer += string[1]; | |
909 | - char_count += 2; | |
910 | - } else if (c == '\n') { | |
911 | - char_count++; | |
912 | - } else { | |
913 | - string[0] = c; | |
914 | - width = GetDrawStringWidthToHandle(string, 1, font_handle_); | |
915 | - line_buffer += string[0]; | |
916 | - char_count++; | |
917 | - } | |
918 | - #endif | |
919 | - | |
920 | - clause_lines_.resize(static_cast<int>(lines_.size() + message_lines_.size()) + 1, | |
921 | - std::pair<int, int>(99999, 0)); | |
922 | - clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first = std::min( | |
923 | - clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first, line_width); | |
924 | - clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second = std::max( | |
925 | - clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second, line_width + width); | |
926 | - | |
927 | - if (index == static_cast<uint32_t>(selecting_clause_)) { | |
928 | - selecting_clause_lines_.resize(static_cast<int>(lines_.size() + message_lines_.size()) + 1, | |
929 | - std::pair<int, int>(99999, 0)); | |
930 | - selecting_clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first = std::min( | |
931 | - selecting_clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first, | |
932 | - line_width); | |
933 | - selecting_clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second = std::max( | |
934 | - selecting_clause_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second, | |
935 | - line_width + width); | |
936 | - } | |
937 | - | |
938 | - line_width += width; | |
939 | - if (line_width > internal_width - font_height_ / 2) { | |
940 | - lines_.push_back(line_buffer); | |
941 | - line_buffer.clear(); | |
942 | - line_width = 0; | |
943 | - } | |
944 | - } | |
945 | - } | |
946 | - | |
947 | - // カーソル後のデータを描画 | |
948 | - for (auto it = cursor_back_str.begin(); it != cursor_back_str.end(); | |
949 | - ++it) { | |
950 | - | |
951 | - int prev_char_count = char_count; | |
952 | - | |
953 | - #ifdef UNICODE | |
954 | - TCHAR c = *it; | |
955 | - int width = GetDrawStringWidthToHandle(&c, 1, font_handle_); | |
956 | - line_buffer += unicode::ToString(tstring(&c, 1)); | |
957 | - #else | |
958 | - unsigned char c = *it; | |
959 | - TCHAR string[2] = { 0, 0 }; | |
960 | - | |
961 | - int width = 0; | |
962 | - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) { | |
963 | - string[0] = c; | |
964 | - string[1] = *(it + 1); | |
965 | - ++it; | |
966 | - width = GetDrawStringWidthToHandle(string, 2, font_handle_); | |
967 | - line_buffer += string[0]; | |
968 | - line_buffer += string[1]; | |
969 | - char_count += 2; | |
970 | - } else if (c == '\n') { | |
971 | - char_count++; | |
972 | - } else { | |
973 | - string[0] = c; | |
974 | - width = GetDrawStringWidthToHandle(string, 1, font_handle_); | |
975 | - line_buffer += string[0]; | |
976 | - char_count++; | |
977 | - } | |
978 | - #endif | |
979 | - | |
980 | - // 選択範囲を記録 | |
981 | - if (select_start < char_count && char_count <= select_end) { | |
982 | - selecting_lines_.resize(static_cast<int>(lines_.size() + message_lines_.size()) + 1, | |
983 | - std::pair<int, int>(99999, 0)); | |
984 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first = std::min( | |
985 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].first, line_width); | |
986 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second = std::max( | |
987 | - selecting_lines_[static_cast<int>(lines_.size() + message_lines_.size())].second, | |
988 | - line_width + std::max(width, 3)); | |
989 | - } | |
990 | - | |
991 | - if (line_width - width / 2 <= cursor_moveto_x_ | |
992 | - && cursor_moveto_x_ <= line_width + width | |
993 | - && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ | |
994 | - && cursor_moveto_y_ <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { | |
995 | - SetKeyInputCursorPosition(prev_char_count, input_handle_); | |
996 | - cursor_moveto_x_ = -1; | |
997 | - cursor_moveto_y_ = -1; | |
998 | - } | |
999 | - | |
1000 | - line_width += width; | |
1001 | - if (c == '\n' || line_width > internal_width - font_height_ / 2) { | |
1002 | - lines_.push_back(line_buffer); | |
1003 | - | |
1004 | - if (cursor_moveto_x_ >= line_width | |
1005 | - && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ | |
1006 | - && cursor_moveto_y_ | |
1007 | - <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) { | |
1008 | - if (c == '\n') { | |
1009 | - SetKeyInputCursorPosition(char_count - 1, | |
1010 | - input_handle_); | |
1011 | - } else { | |
1012 | - SetKeyInputCursorPosition(char_count, input_handle_); | |
1013 | - } | |
1014 | - cursor_moveto_x_ = -1; | |
1015 | - cursor_moveto_y_ = -1; | |
1016 | - } | |
1017 | - line_buffer.clear(); | |
1018 | - line_width = 0; | |
1019 | - } | |
1020 | - } | |
1021 | - | |
1022 | - // バッファの残りを描画 | |
1023 | - lines_.push_back(line_buffer); | |
1024 | - | |
1025 | - if (cursor_moveto_x_ >= line_width | |
1026 | - && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_ | |
1027 | - && static_cast<int>(cursor_moveto_y_) <= static_cast<int>(lines_.size() + message_lines_.size()) * font_height_) { | |
1028 | - SetKeyInputCursorPosition(char_count, input_handle_); | |
1029 | - cursor_moveto_x_ = -1; | |
1030 | - cursor_moveto_y_ = -1; | |
1031 | - } | |
1032 | - | |
1033 | - input_height_ = static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ + INPUT_MARGIN_Y * 2; | |
1034 | - input_height_ = std::max(input_height_, min_input_height_); | |
1035 | - | |
1036 | - int new_height = input_height_ + BOX_TOP_MARGIN + BOX_BOTTOM_MARGIN; | |
1037 | - | |
1038 | - int screen_height; | |
1039 | - GetScreenState(nullptr, &screen_height, nullptr); | |
1040 | - if (y_ + height_ > screen_height - BOX_TOP_MARGIN) { | |
1041 | - y_ -= new_height - height_; | |
1042 | - input_y_ = y_ + BOX_TOP_MARGIN; | |
1043 | - } | |
1044 | - | |
1045 | - height_ = new_height; | |
366 | + height_ = new_height; | |
367 | + | |
368 | + input_.set_y(y_ + BOX_TOP_MARGIN); | |
369 | + input_.set_x(x_ + INPUT_MARGIN_X); | |
370 | + input_.set_width(width_ - INPUT_MARGIN_X * 2); | |
1046 | 371 | |
1047 | - line_buffer.clear(); | |
1048 | - line_width = 0; | |
372 | + //line_buffer.clear(); | |
373 | + //line_width = 0; | |
1049 | 374 | |
1050 | - if (push_key_shift && (push_repeat_key_up || push_repeat_key_down)) { | |
1051 | - SetKeyInputSelectArea(GetKeyInputCursorPosition(input_handle_), | |
1052 | - prev_cursor_pos_, input_handle_); | |
1053 | - } | |
375 | + //if (push_key_shift && (push_repeat_key_up || push_repeat_key_down)) { | |
376 | + // SetKeyInputSelectArea(GetKeyInputCursorPosition(input_handle_), | |
377 | + // prev_cursor_pos_, input_handle_); | |
378 | + //} | |
1054 | 379 | |
1055 | - } | |
380 | + //} | |
1056 | 381 | |
1057 | 382 | if (IsActive()) { |
1058 | 383 | input->CancelKeyCountAll(); |
@@ -1061,8 +386,7 @@ void InputBox::ProcessInput(InputManager* input) | ||
1061 | 386 | |
1062 | 387 | void InputBox::Update() |
1063 | 388 | { |
1064 | - UpdateCursorCount(); | |
1065 | - // if (IsActive) { | |
389 | + input_.Update(); | |
1066 | 390 | } |
1067 | 391 | |
1068 | 392 | void InputBox::ReloadTabs() |
@@ -1076,7 +400,7 @@ void InputBox::ReloadTabs() | ||
1076 | 400 | if (card->HasInputEvent()) { |
1077 | 401 | InputBox::Tab tab; |
1078 | 402 | tab.card = card; |
1079 | - tab.name = card->name(); | |
403 | + tab.name = unicode::ToTString(card->name()); | |
1080 | 404 | |
1081 | 405 | tab.x = x_ + TAB_SIDE_MARGIN + tab_offset_x - 9; |
1082 | 406 | tab.y = y_ - 3; |
@@ -1136,8 +460,7 @@ void InputBox::UpdateTabs() | ||
1136 | 460 | |
1137 | 461 | // タブ選択 |
1138 | 462 | int tab_offset_x = 0; |
1139 | - for (auto it = tabs_.begin(); it != tabs_.end(); ++it) { | |
1140 | - auto tab = *it; | |
463 | + BOOST_FOREACH(auto& tab, tabs_) { | |
1141 | 464 | tab.x = x_ + TAB_SIDE_MARGIN + tab_offset_x - 9; |
1142 | 465 | tab.y = y_ - 3; |
1143 | 466 | tab.height = font_height_ + TAB_TOP_MARGIN * 2 + 3 * 2; |
@@ -1164,10 +487,10 @@ void InputBox::UpdateBase(InputManager* input) | ||
1164 | 487 | bool hover = (x_ <= input->GetMouseX() && input->GetMouseX() <= x_ + width_ |
1165 | 488 | && y_ <= input->GetMouseY() && input->GetMouseY() <= y_ + height_); |
1166 | 489 | |
1167 | - bool input_hover = (input_x_ <= input->GetMouseX() | |
1168 | - && input->GetMouseX() <= input_x_ + input_width_ | |
1169 | - && input_y_ <= input->GetMouseY() | |
1170 | - && input->GetMouseY() <= input_y_ + input_height_); | |
490 | + //bool input_hover = (input_x_ <= input->GetMouseX() | |
491 | + // && input->GetMouseX() <= input_x_ + input_width_ | |
492 | + // && input_y_ <= input->GetMouseY() | |
493 | + // && input->GetMouseY() <= input_y_ + input_height_); | |
1171 | 494 | |
1172 | 495 | bool corner_hover = (x_ + width_ - 18 <= input->GetMouseX() |
1173 | 496 | && input->GetMouseX() <= x_ + width_ |
@@ -1177,7 +500,7 @@ void InputBox::UpdateBase(InputManager* input) | ||
1177 | 500 | // ドラッグ処理 |
1178 | 501 | if (input->GetMouseLeft()) { |
1179 | 502 | if (input->GetPrevMouseLeft() == 0 && drag_offset_x_ < 0 && hover |
1180 | - && !input_hover && !corner_hover) { | |
503 | + && !corner_hover) { | |
1181 | 504 | drag_offset_x_ = input->GetMouseX() - x_; |
1182 | 505 | drag_offset_y_ = input->GetMouseY() - y_; |
1183 | 506 | } |
@@ -1217,17 +540,15 @@ void InputBox::UpdateBase(InputManager* input) | ||
1217 | 540 | |
1218 | 541 | bool InputBox::IsActive() |
1219 | 542 | { |
1220 | - return GetActiveKeyInput() == input_handle_; | |
543 | + return input_.active(); | |
1221 | 544 | } |
1222 | 545 | |
1223 | 546 | void InputBox::Activate() |
1224 | 547 | { |
1225 | - SetActiveKeyInput(input_handle_); | |
1226 | - ResetCursorCount(); | |
548 | + input_.set_active(true); | |
1227 | 549 | } |
1228 | 550 | |
1229 | 551 | void InputBox::Inactivate() |
1230 | 552 | { |
1231 | - ReStartKeyInput(input_handle_); | |
1232 | - SetActiveKeyInput(-1); | |
553 | + input_.set_active(false); | |
1233 | 554 | } |
@@ -12,6 +12,7 @@ | ||
12 | 12 | #include "../ScriptEnvironment.hpp" |
13 | 13 | #include "../ResourceManager.hpp" |
14 | 14 | #include "../Card.hpp" |
15 | +#include "Input.hpp" | |
15 | 16 | |
16 | 17 | class InputBox { |
17 | 18 | public: |
@@ -33,25 +34,17 @@ class InputBox { | ||
33 | 34 | private: |
34 | 35 | void CancelSelect(); |
35 | 36 | |
36 | - void UpdateCursorCount(); | |
37 | - void ResetCursorCount(); | |
38 | - | |
39 | 37 | void DrawBase(); |
40 | 38 | void DrawTabs(); |
41 | - void DrawInputBase(); | |
42 | - void DrawInputText(); | |
43 | - void DrawCandidates(); | |
44 | 39 | |
45 | 40 | void ProcessInputTabs(InputManager* input); |
46 | 41 | void UpdateTabs(); |
47 | 42 | |
48 | 43 | void UpdateBase(InputManager* input); |
49 | 44 | |
50 | - void AddInputHistory(const std::string& text); | |
51 | - | |
52 | 45 | void SwitchTab(int index); |
53 | - std::string GetInputString() const; | |
54 | - void SetInputString(const std::string& text); | |
46 | + tstring GetInputString() const; | |
47 | + void SetInputString(const tstring& text); | |
55 | 48 | |
56 | 49 | bool IsScriptMode(); |
57 | 50 | void SetScriptMode(); |
@@ -63,17 +56,17 @@ class InputBox { | ||
63 | 56 | private: |
64 | 57 | struct Tab { |
65 | 58 | CardWeakPtr card; |
66 | - std::string name; | |
67 | - std::string message; | |
68 | - std::string text; | |
59 | + tstring name; | |
60 | + tstring message; | |
61 | + tstring text; | |
69 | 62 | int x, y, width, height; |
70 | 63 | }; |
71 | 64 | |
72 | - int input_handle_; | |
65 | + Input input_; | |
66 | + | |
73 | 67 | int font_handle_; |
74 | 68 | int font_height_; |
75 | 69 | std::array<ImageHandlePtr, 4> bg_image_handle_; |
76 | - std::array<ImageHandlePtr, 4> input_bg_image_handle_; | |
77 | 70 | std::array<ImageHandlePtr, 4> tab_bg_image_handle_; |
78 | 71 | std::array<ImageHandlePtr, 4> tab_bg_inactive_image_handle_; |
79 | 72 | std::array<ImageHandlePtr, 4> ime_image_handle_; |
@@ -83,30 +76,12 @@ class InputBox { | ||
83 | 76 | int drag_resize_offset_x_, drag_resize_offset_y_; |
84 | 77 | int min_input_height_; |
85 | 78 | |
86 | - int input_x_, input_y_, input_width_, input_height_; | |
87 | - int cursor_x_, cursor_y_; | |
88 | - int cursor_moveto_x_, cursor_moveto_y_; | |
89 | - int prev_cursor_pos_, cursor_drag_count; | |
90 | - int selecting_candidate_, selecting_clause_; | |
91 | - int candidate_x_, candidate_y_; | |
92 | - | |
93 | 79 | int selecting_tab_index_; |
94 | 80 | std::vector<InputBox::Tab> tabs_; |
95 | 81 | Tab script_tab_; |
96 | 82 | |
97 | - std::vector<std::string> message_lines_; | |
98 | - std::vector<std::string> lines_; | |
99 | - std::vector<tstring> candidates_; | |
100 | - | |
101 | - std::list<std::string> history_; | |
102 | - | |
103 | - std::vector<std::pair<int, int>> selecting_lines_; | |
104 | - std::vector<std::pair<int, int>> clause_lines_; | |
105 | - std::vector<std::pair<int, int>> selecting_clause_lines_; | |
106 | - | |
107 | 83 | std::vector<std::string> tab_texts_; |
108 | 84 | |
109 | - int blink_count_; | |
110 | 85 | ManagerAccessorPtr manager_accessor_; |
111 | 86 | CardPtr card_; |
112 | 87 |
@@ -1,4 +1,4 @@ | ||
1 | -// | |
1 | +// | |
2 | 2 | // Command.hpp |
3 | 3 | // |
4 | 4 |
@@ -1,4 +1,4 @@ | ||
1 | -// | |
1 | +// | |
2 | 2 | // Encrypter.cpp |
3 | 3 | // |
4 | 4 |
@@ -1,4 +1,4 @@ | ||
1 | -// | |
1 | +// | |
2 | 2 | // Encrypter.hpp |
3 | 3 | // |
4 | 4 |
@@ -299,7 +299,7 @@ int main(int argc, char* argv[]) | ||
299 | 299 | shm(boost::interprocess::open_read_only, "MMO_SERVER_WITH_CLIENT"); |
300 | 300 | execute_with_client = true; |
301 | 301 | } catch(std::exception& e) { |
302 | - Logger::Info("Standalone Mode"); | |
302 | + Logger::Info("Stand-alone Mode"); | |
303 | 303 | execute_with_client = false; |
304 | 304 | } |
305 | 305 |