• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂fcbd616b097d039c69b5a294fb364c980cbdf556 (tree)
時間2012-09-04 02:44:21
作者h2so5 <h2so5@git....>
Commiterh2so5

Log Message

InputBoxのソースを整理、挙動のバグを修正
例外発生時の処理をいくつか追加

Change Summary

差異

Binary files a/client/CardManager.cpp and b/client/CardManager.cpp differ
--- a/client/Client.cpp
+++ b/client/Client.cpp
@@ -58,9 +58,12 @@ Client::Client(const std::string& host,
5858 std::stringstream port_str;
5959 port_str << remote_tcp_port;
6060
61- {
61+ try {
6262 tcp::resolver::query query(host, port_str.str());
6363 iterator_ = resolver_.resolve(query);
64+ } catch (const std::exception& e) {
65+ Logger::Error(_T("%s"), unicode::ToTString(e.what()));
66+ return;
6467 }
6568
6669 udp::resolver resolver(io_service_);
--- a/client/scene/MainLoop.cpp
+++ b/client/scene/MainLoop.cpp
@@ -66,11 +66,11 @@ void MainLoop::Update()
6666 player_manager_->ProcessInput(&input);
6767 player_manager_->Update();
6868
69- card_manager_->ProcessInput(&input);
70- card_manager_->Update();
71-
7269 world_manager_->ProcessInput(&input);
7370 world_manager_->Update();
71+
72+ card_manager_->ProcessInput(&input);
73+ card_manager_->Update();
7474 }
7575
7676 void MainLoop::Draw()
--- a/client/ui/Input.cpp
+++ b/client/ui/Input.cpp
@@ -6,15 +6,8 @@
66 #include <DxLib.h>
77 #include <stdint.h>
88
9+const size_t Input::TEXT_BUFFER_SIZE = 1024;
910 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-
1811 const int Input::KEY_REPEAT_FRAME = 6;
1912
2013 const int Input::INPUT_MARGIN_X = 8;
@@ -26,7 +19,8 @@ const int Input::IME_MARGIN_Y = 16;
2619 const int Input::IME_MAX_PAGE_SIZE = 6;
2720 const int Input::IME_MIN_WIDTH = 120;
2821
29-Input::Input()
22+Input::Input() :
23+ reverse_color_(false)
3024 {
3125 input_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
3226 _T("resources/images/gui/gui_inputbox_input_bg.png"), 2, 2, 12, 12);
@@ -54,7 +48,13 @@ Input::Input()
5448 void Input::Draw()
5549 {
5650 {
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+ }
5858
5959 DrawGraph(x_, y_, *input_bg_image_handle_[0], TRUE);
6060 DrawGraph(x_ + width_ - 12, y_, *input_bg_image_handle_[1], TRUE);
@@ -142,7 +142,7 @@ void Input::Draw()
142142 current_line++;
143143 }
144144
145- int text_color = GetColor(0, 0, 0);
145+ int text_color = reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0);
146146 current_line = 0;
147147
148148 if (message_lines_.size() > 0) {
@@ -292,20 +292,16 @@ void Input::ProcessInput(InputManager* input)
292292 + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0;
293293 // bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5);
294294
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) {
299297 set_active(true);
300298 } else {
301299 if (push_key_shift && first_key_return) {
302300 SetActiveKeyInput(input_handle_);
303301 } 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) {
307303 if (on_enter_) {
308- if (on_enter_(input_text)) {
304+ if (on_enter_(unicode::ToString(input_text))) {
309305 SetKeyInputString(_T(""), input_handle_);
310306 }
311307 }
@@ -314,57 +310,6 @@ void Input::ProcessInput(InputManager* input)
314310 }
315311 }
316312
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-
368313 if (push_repeat_key_up) {
369314 cursor_moveto_y_ = cursor_y_ - font_height_ / 2;
370315 cursor_moveto_x_ = cursor_x_ + 2;
@@ -375,12 +320,12 @@ void Input::ProcessInput(InputManager* input)
375320
376321 if (push_key_shift && push_repeat_key_return && multiline_) {
377322
378- auto buffer = GetInputString();
323+ auto buffer = text();
379324 uint32_t pos = GetKeyInputCursorPosition(input_handle_);
380325
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;
384329
385330 SetKeyInputString(unicode::ToTString(new_string).c_str(), input_handle_);
386331 SetKeyInputCursorPosition(pos + 1, input_handle_);
@@ -391,14 +336,14 @@ void Input::ProcessInput(InputManager* input)
391336 int cursor_byte_pos, cursor_dot_pos;
392337 int draw_dot_pos = 0;
393338
394- TCHAR String[1024];
339+ TCHAR String[TEXT_BUFFER_SIZE];
395340 GetKeyInputString(String, input_handle_);
396341
397342 // 単一行設定の時、最初の行だけを表示
398343 if (!multiline_) {
399344 tstring buffer(String, _tcslen(String));
400345 size_t pos;
401- if ((pos = buffer.find('\n')) != std::string::npos) {
346+ if ((pos = buffer.find(_T('\n'))) != std::string::npos) {
402347 SetKeyInputString(buffer.substr(0, pos).c_str(), input_handle_);
403348 }
404349 }
@@ -443,7 +388,7 @@ void Input::ProcessInput(InputManager* input)
443388 #endif
444389
445390 line_width += width;
446- if (c == '\n'
391+ if (c == _T('\n')
447392 || line_width > internal_width - font_height_ / 2) {
448393 message_lines_.push_back(line_buffer);
449394 current_line++;
@@ -567,14 +512,14 @@ void Input::ProcessInput(InputManager* input)
567512 }
568513
569514 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) {
571516 lines_.push_back(line_buffer);
572517
573518 if (cursor_moveto_x_ >= line_width
574519 && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_
575520 && cursor_moveto_y_
576521 <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) {
577- if (c == '\n') {
522+ if (c == _T('\n')) {
578523 SetKeyInputCursorPosition(char_count - 1,
579524 input_handle_);
580525 } else {
@@ -703,14 +648,14 @@ void Input::ProcessInput(InputManager* input)
703648 }
704649
705650 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) {
707652 lines_.push_back(line_buffer);
708653
709654 if (cursor_moveto_x_ >= line_width
710655 && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_
711656 && cursor_moveto_y_
712657 <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) {
713- if (c == '\n') {
658+ if (c == _T('\n')) {
714659 SetKeyInputCursorPosition(char_count - 1,
715660 input_handle_);
716661 } else {
@@ -753,13 +698,6 @@ void Input::ProcessInput(InputManager* input)
753698 }
754699 }
755700
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-
763701 bool Input::active()
764702 {
765703 return GetActiveKeyInput() == input_handle_;
@@ -830,7 +768,7 @@ void Input::set_height(int height)
830768
831769 tstring Input::text() const
832770 {
833- TCHAR String[1024];
771+ TCHAR String[TEXT_BUFFER_SIZE];
834772 GetKeyInputString(String, input_handle_);
835773 return tstring(String, _tcslen(String));
836774 }
@@ -854,3 +792,13 @@ void Input::set_on_enter(const CallbackFunc& func)
854792 {
855793 on_enter_ = func;
856794 }
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
--- a/client/ui/Input.hpp
+++ b/client/ui/Input.hpp
@@ -19,8 +19,6 @@ class Input {
1919 void Update();
2020 void ProcessInput(InputManager* input);
2121
22- std::string GetInputString();
23-
2422 bool active();
2523 void set_active(bool flag);
2624
@@ -39,11 +37,16 @@ class Input {
3937 tstring message() const;
4038 void set_message(const tstring& message);
4139
40+ bool reverse_color() const;
41+ void set_reverse_color(bool flag);
42+
4243 void set_on_enter(const CallbackFunc& func);
4344
45+ public:
46+ void CancelSelect();
47+
4448 private:
4549 void ResetCursorCount();
46- void CancelSelect();
4750
4851 private:
4952 int x_, y_, width_, height_;
@@ -71,18 +74,12 @@ class Input {
7174 CallbackFunc on_enter_;
7275 tstring message_;
7376
77+ bool reverse_color_;
7478 int blink_count_;
7579
7680 private:
81+ const static size_t TEXT_BUFFER_SIZE;
7782 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-
8683 const static int KEY_REPEAT_FRAME;
8784
8885 const static int INPUT_MARGIN_X;
--- a/client/ui/InputBox.cpp
+++ b/client/ui/InputBox.cpp
@@ -38,20 +38,13 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) :
3838 width_(800),
3939 height_(100),
4040 multiline_(true),
41- input_handle_(MakeKeyInput(400, FALSE, FALSE, FALSE)),
4241 font_height_(ResourceManager::default_font_size()),
4342 drag_offset_x_(-1),
4443 drag_offset_y_(-1),
4544 drag_resize_offset_x_(-1),
4645 drag_resize_offset_y_(-1),
4746 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),
5347 selecting_tab_index_(0),
54- blink_count_(0),
5548 manager_accessor_(manager_accessor),
5649 card_(std::make_shared<Card>(manager_accessor_, "", "immo", "", "", "",
5750 std::vector<std::string>(), false, false))
@@ -60,8 +53,6 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) :
6053 font_handle_ = ResourceManager::default_font_handle();
6154 bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
6255 _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);
6556 tab_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
6657 _T("resources/images/gui/gui_inputbox_tab_bg.png"), 2, 2, 12, 12);
6758 tab_bg_inactive_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
@@ -71,26 +62,52 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) :
7162
7263 script_icon_image_handle_ = ResourceManager::LoadCachedGraph(_T("resources/images/gui/gui_inputbox_tab_script_icon.png"));
7364
74- input_height_ = font_height_ + INPUT_MARGIN_Y * 2;
75-
7665 int screen_width, screen_height;
7766 GetScreenState(&screen_width, &screen_height, nullptr);
7867 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;
8069 x_ = (screen_width - width_) / 2;
8170 y_ = screen_height - height_ - BOX_BOTTOM_MARGIN;
8271
8372 selecting_tab_index_ = 0;
8473
85-
74+ Activate();
8675 if (auto card_manager = manager_accessor_->card_manager().lock()) {
8776 card_manager->AddCard(card_);
8877 }
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+ });
89107 }
90108
91109 InputBox::~InputBox()
92110 {
93- DeleteKeyInput(input_handle_);
94111 }
95112
96113 void InputBox::DrawTabs()
@@ -99,8 +116,7 @@ void InputBox::DrawTabs()
99116 {
100117 int tab_index = 0;
101118 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_) {
104120
105121 std::array<ImageHandlePtr, 4>* image_handle;
106122 if (selecting_tab_index_ == tab_index) {
@@ -232,232 +248,11 @@ void InputBox::DrawBase()
232248 SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
233249 }
234250
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-
453251 void InputBox::Draw()
454252 {
455253 DrawBase();
456- DrawInputBase();
457- DrawInputText();
458254 DrawTabs();
459- DrawCandidates();
460- // card_->Draw();
255+ input_.Draw();
461256 }
462257
463258 int InputBox::multiline() const
@@ -472,20 +267,7 @@ void InputBox::set_multiline(int multiline)
472267
473268 void InputBox::CancelSelect()
474269 {
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();
489271 }
490272
491273 bool InputBox::IsScriptMode()
@@ -510,29 +292,22 @@ void InputBox::SwitchTab(int index)
510292
511293 if (selecting_tab_index_ == -1) {
512294 SetInputString(script_tab_.text);
295+ input_.set_message(script_tab_.message);
296+ input_.set_reverse_color(true);
513297 } else if (!tabs_.empty()) {
514298 SetInputString(tabs_.at(selecting_tab_index_).text);
299+ input_.set_message(tabs_.at(selecting_tab_index_).message);
300+ input_.set_reverse_color(false);
515301 }
516302 }
517303
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();
527306 }
528307
529-
530-void InputBox::AddInputHistory(const std::string& text)
308+void InputBox::SetInputString(const tstring& text)
531309 {
532- history_.push_back(text);
533- if (history_.size() > HISTORY_MAX_SIZE) {
534- history_.pop_front();
535- }
310+ input_.set_text(text);
536311 }
537312
538313 void InputBox::ProcessInput(InputManager* input)
@@ -563,496 +338,46 @@ void InputBox::ProcessInput(InputManager* input)
563338 + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0;
564339 bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5);
565340
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) {
568347 Activate();
569348 } else if (!IsActive() && push_key_v && push_key_ctrl) {
570349 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- }
609350 }
610351
611352 ProcessInputTabs(input);
612353 UpdateBase(input);
613354 UpdateTabs();
614355
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_) {
666356
667- auto buffer = GetInputString();
668- uint32_t pos = GetKeyInputCursorPosition(input_handle_);
357+ int new_height = input_.height() + BOX_TOP_MARGIN + BOX_BOTTOM_MARGIN;
669358
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);
751364 }
752365
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);
1046371
1047- line_buffer.clear();
1048- line_width = 0;
372+ //line_buffer.clear();
373+ //line_width = 0;
1049374
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+ //}
1054379
1055- }
380+ //}
1056381
1057382 if (IsActive()) {
1058383 input->CancelKeyCountAll();
@@ -1061,8 +386,7 @@ void InputBox::ProcessInput(InputManager* input)
1061386
1062387 void InputBox::Update()
1063388 {
1064- UpdateCursorCount();
1065- // if (IsActive) {
389+ input_.Update();
1066390 }
1067391
1068392 void InputBox::ReloadTabs()
@@ -1076,7 +400,7 @@ void InputBox::ReloadTabs()
1076400 if (card->HasInputEvent()) {
1077401 InputBox::Tab tab;
1078402 tab.card = card;
1079- tab.name = card->name();
403+ tab.name = unicode::ToTString(card->name());
1080404
1081405 tab.x = x_ + TAB_SIDE_MARGIN + tab_offset_x - 9;
1082406 tab.y = y_ - 3;
@@ -1136,8 +460,7 @@ void InputBox::UpdateTabs()
1136460
1137461 // タブ選択
1138462 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_) {
1141464 tab.x = x_ + TAB_SIDE_MARGIN + tab_offset_x - 9;
1142465 tab.y = y_ - 3;
1143466 tab.height = font_height_ + TAB_TOP_MARGIN * 2 + 3 * 2;
@@ -1164,10 +487,10 @@ void InputBox::UpdateBase(InputManager* input)
1164487 bool hover = (x_ <= input->GetMouseX() && input->GetMouseX() <= x_ + width_
1165488 && y_ <= input->GetMouseY() && input->GetMouseY() <= y_ + height_);
1166489
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_);
1171494
1172495 bool corner_hover = (x_ + width_ - 18 <= input->GetMouseX()
1173496 && input->GetMouseX() <= x_ + width_
@@ -1177,7 +500,7 @@ void InputBox::UpdateBase(InputManager* input)
1177500 // ドラッグ処理
1178501 if (input->GetMouseLeft()) {
1179502 if (input->GetPrevMouseLeft() == 0 && drag_offset_x_ < 0 && hover
1180- && !input_hover && !corner_hover) {
503+ && !corner_hover) {
1181504 drag_offset_x_ = input->GetMouseX() - x_;
1182505 drag_offset_y_ = input->GetMouseY() - y_;
1183506 }
@@ -1217,17 +540,15 @@ void InputBox::UpdateBase(InputManager* input)
1217540
1218541 bool InputBox::IsActive()
1219542 {
1220- return GetActiveKeyInput() == input_handle_;
543+ return input_.active();
1221544 }
1222545
1223546 void InputBox::Activate()
1224547 {
1225- SetActiveKeyInput(input_handle_);
1226- ResetCursorCount();
548+ input_.set_active(true);
1227549 }
1228550
1229551 void InputBox::Inactivate()
1230552 {
1231- ReStartKeyInput(input_handle_);
1232- SetActiveKeyInput(-1);
553+ input_.set_active(false);
1233554 }
--- a/client/ui/InputBox.hpp
+++ b/client/ui/InputBox.hpp
@@ -12,6 +12,7 @@
1212 #include "../ScriptEnvironment.hpp"
1313 #include "../ResourceManager.hpp"
1414 #include "../Card.hpp"
15+#include "Input.hpp"
1516
1617 class InputBox {
1718 public:
@@ -33,25 +34,17 @@ class InputBox {
3334 private:
3435 void CancelSelect();
3536
36- void UpdateCursorCount();
37- void ResetCursorCount();
38-
3937 void DrawBase();
4038 void DrawTabs();
41- void DrawInputBase();
42- void DrawInputText();
43- void DrawCandidates();
4439
4540 void ProcessInputTabs(InputManager* input);
4641 void UpdateTabs();
4742
4843 void UpdateBase(InputManager* input);
4944
50- void AddInputHistory(const std::string& text);
51-
5245 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);
5548
5649 bool IsScriptMode();
5750 void SetScriptMode();
@@ -63,17 +56,17 @@ class InputBox {
6356 private:
6457 struct Tab {
6558 CardWeakPtr card;
66- std::string name;
67- std::string message;
68- std::string text;
59+ tstring name;
60+ tstring message;
61+ tstring text;
6962 int x, y, width, height;
7063 };
7164
72- int input_handle_;
65+ Input input_;
66+
7367 int font_handle_;
7468 int font_height_;
7569 std::array<ImageHandlePtr, 4> bg_image_handle_;
76- std::array<ImageHandlePtr, 4> input_bg_image_handle_;
7770 std::array<ImageHandlePtr, 4> tab_bg_image_handle_;
7871 std::array<ImageHandlePtr, 4> tab_bg_inactive_image_handle_;
7972 std::array<ImageHandlePtr, 4> ime_image_handle_;
@@ -83,30 +76,12 @@ class InputBox {
8376 int drag_resize_offset_x_, drag_resize_offset_y_;
8477 int min_input_height_;
8578
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-
9379 int selecting_tab_index_;
9480 std::vector<InputBox::Tab> tabs_;
9581 Tab script_tab_;
9682
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-
10783 std::vector<std::string> tab_texts_;
10884
109- int blink_count_;
11085 ManagerAccessorPtr manager_accessor_;
11186 CardPtr card_;
11287
--- a/common/network/Command.hpp
+++ b/common/network/Command.hpp
@@ -1,4 +1,4 @@
1-//
1+//
22 // Command.hpp
33 //
44
--- a/common/network/Encrypter.cpp
+++ b/common/network/Encrypter.cpp
@@ -1,4 +1,4 @@
1-//
1+//
22 // Encrypter.cpp
33 //
44
--- a/common/network/Encrypter.hpp
+++ b/common/network/Encrypter.hpp
@@ -1,4 +1,4 @@
1-//
1+//
22 // Encrypter.hpp
33 //
44
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -299,7 +299,7 @@ int main(int argc, char* argv[])
299299 shm(boost::interprocess::open_read_only, "MMO_SERVER_WITH_CLIENT");
300300 execute_with_client = true;
301301 } catch(std::exception& e) {
302- Logger::Info("Standalone Mode");
302+ Logger::Info("Stand-alone Mode");
303303 execute_with_client = false;
304304 }
305305