OSDN Git Service

Inputのみコピペ機能搭載
authorangeart <angeart@git.sourceforge.jp>
Sat, 13 Oct 2012 14:46:59 +0000 (23:46 +0900)
committerangeart <angeart@git.sourceforge.jp>
Sat, 13 Oct 2012 14:46:59 +0000 (23:46 +0900)
GenJSONで作者名末尾に半角スペースが含まれていた場合の不具合修正
その他いろいろ

16 files changed:
client/Card.cpp
client/Card.hpp
client/GenerateJSON.cpp
client/scene/Title.cpp
client/ui/Input.cpp
client/ui/Input.hpp
client/ui/InputBox.cpp
client/ui/UIBase.cpp
client/ui/UIBase.hpp
client/ui/UIBoard.cpp
client/ui/UIBoard.hpp
client/ui/UICustom.cpp
client/ui/UICustom.hpp
client/ui/UILabel.cpp
client/ui/UIList.cpp
client/ui/UIList.hpp

index 1bfbe7a..be89e46 100644 (file)
 #include "GenerateJSON.hpp"\r
 #include "Music.hpp"\r
 \r
+#pragma comment(lib,"libctemplate.lib")\r
+\r
+#define CTEMPLATE_DLL_DECL\r
+#include <config.h>\r
+#include <ctemplate/template.h>\r
+\r
 \r
 char Card::STORAGE_DIR[] = "storage";\r
 char Card::SCRIPT_PATH[] = "system/js";\r
@@ -75,6 +81,7 @@ Card::Card(
         context->Global()->Set(String::New("Model"),  script_object->Clone());\r
         context->Global()->Set(String::New("Account"), script_object->Clone());\r
         context->Global()->Set(String::New("Music"),  script_object->Clone());\r
+        context->Global()->Set(String::New("Plugin"),  script_object->Clone());\r
         context->Global()->Set(String::New("InputBox"),   script_object->Clone());\r
         context->Global()->Set(String::New("Card"),    script_object->Clone());\r
         context->Global()->Set(String::New("Screen"),  script_object->Clone());\r
@@ -101,11 +108,39 @@ Card::Card(
                                        assert(!ui_board_obj_.IsEmpty() && ui_board_obj_->IsObject());\r
                                });\r
 \r
-               ui_board_ = *static_cast<UIBasePtr*>(ui_board_obj_->GetPointerFromInternalField(0));\r
+               ui_board_ = *static_cast<UISuperPtr*>(ui_board_obj_->GetPointerFromInternalField(0));\r
        }\r
        \r
        ui_board_->set_icon_image_handle(\r
                ResourceManager::LoadCachedGraph(unicode::ToTString(source_folder_ + "/" + icon_)));\r
+\r
+\r
+       auto sprit = [](const std::string &str, const std::string &delim)->std::vector<std::string>\r
+       {\r
+               std::vector<std::string> res;\r
+               size_t current = 0, found, delimlen = delim.size();\r
+               while((found = str.find(delim, current)) != std::string::npos){\r
+                       res.push_back(std::string(str, current, found - current));\r
+                       current = found + delimlen;\r
+               }\r
+               res.push_back(std::string(str, current, str.size() - current));\r
+               return res;\r
+       };\r
+\r
+\r
+       auto ui_board_tmp = *static_cast<UIBoardPtr*>(ui_board_obj_->GetPointerFromInternalField(0));\r
+       auto pos = name_.find_first_of("@");\r
+       if ( pos != std::string::npos )\r
+       {\r
+               std::string plug_dat = name_.substr(pos,name_.length() - pos);\r
+               auto str_array = sprit(plug_dat,",");\r
+               BOOST_FOREACH(auto str,str_array)\r
+               {\r
+                       if(str == "plugin")ui_board_tmp->set_boardvisible(false);\r
+                       if(str == "uiplugin")ui_board_tmp->set_boardvisible(true);\r
+               }\r
+       }\r
+\r
 }\r
 \r
 Card::~Card()\r
@@ -297,6 +332,26 @@ Handle<Value> Card::Function_Music_IsLoadingDone(const Arguments& args)
        return Boolean::New(false);\r
 }\r
 \r
+Handle<Value> Card::Function_Plugin_Run(const Arguments& args)\r
+{\r
+    auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0));\r
+    if (auto card_manager = self->manager_accessor_->card_manager().lock()) {\r
+               if ( args[0]->IsString() ) {\r
+                       auto name = std::string(*String::Utf8Value(args[0]->ToString()));\r
+                       BOOST_FOREACH(auto card,card_manager->cards()) {\r
+                               auto pos = card->name().find_first_of("@");\r
+                               if( pos != std::string::npos ) {\r
+                                       if ( name == card->name().substr(0,pos) ) {\r
+                                               card->Run();\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return Undefined();\r
+}\r
+\r
+\r
 Handle<Value> Card::Function_Account_id(const Arguments& args)\r
 {\r
     auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0));\r
@@ -890,6 +945,15 @@ void Card::SetFunctions()
        script_.SetFunction("Music.rebuild", Function_Music_Rebuild);\r
 \r
     script_.SetProperty("Music.onReload", Property_Music_onReload, Property_set_Music_onReload);\r
+\r
+    /**\r
+     * 非自動実行プラグインを走らせます\r
+     *\r
+     * @method run\r
+     * @static\r
+     */\r
+       script_.SetFunction("Plugin.run", Function_Plugin_Run);\r
+\r
        /**\r
      * アカウント\r
      *\r
@@ -1347,8 +1411,9 @@ UISuperPtr Card::GetWindow() const
                return ui_board_;\r
        } else {\r
            if (ui_board_obj_->IsObject()) {\r
-                   auto ptr = *static_cast<UIBasePtr*>(ui_board_obj_->GetPointerFromInternalField(0));\r
-                   if (ptr->children_size() > 0) {\r
+                   auto ptr = *static_cast<UIBoardPtr*>(ui_board_obj_->GetPointerFromInternalField(0));\r
+                       assert(ptr);\r
+                   if (ptr->children_size() > 0 && ptr->boardvisible()) {\r
                                return ptr;\r
                    }\r
            }\r
index 28aea34..b5357b2 100644 (file)
Binary files a/client/Card.hpp and b/client/Card.hpp differ
index 49d9c5e..ae980c5 100644 (file)
@@ -160,6 +160,31 @@ _error:
                return RemoveDirectory( lpPathName );\r
        }\r
 \r
+       int Trim(char *s) {\r
+    int i;\r
+    int count = 0;\r
+\r
+    /* \8bó\83|\83C\83\93\83^\82©? */\r
+    if ( s == NULL ) { /* yes */\r
+        return -1;\r
+    }\r
+\r
+    /* \95\8e\9a\97ñ\92·\82ð\8eæ\93¾\82·\82é */\r
+    i = strlen(s);\r
+\r
+    /* \96\96\94ö\82©\82ç\8f\87\82É\8bó\94\92\82Å\82È\82¢\88Ê\92u\82ð\92T\82· */\r
+    while ( --i >= 0 && s[i] == ' ' ) count++;\r
+\r
+    /* \8fI\92[\83i\83\8b\95\8e\9a\82ð\95t\89Á\82·\82é */\r
+    s[i+1] = '\0';\r
+\r
+    /* \90æ\93ª\82©\82ç\8f\87\82É\8bó\94\92\82Å\82È\82¢\88Ê\92u\82ð\92T\82· */\r
+    i = 0;\r
+    while ( s[i] != '\0' && s[i] == ' ' ) i++;\r
+    strcpy(s, &s[i]);\r
+\r
+    return i + count;\r
+       }\r
 };\r
 \r
 JsonGen::JsonGen()\r
@@ -209,7 +234,7 @@ JsonGen::JsonGen()
                        {\r
                                ZeroMemory(tcsTmpPath_Pmd,MAX_PATH);\r
                                _tcscpy_s(tcsTmpPath_Pmd,tcsTmpDir);\r
-                               _tcscat_s(tcsTmpPath_Pmd,_T("*.pmd"));\r
+                               _tcscat_s(tcsTmpPath_Pmd,_T("*.pm?"));\r
                                hPmdFind = FindFirstFile(tcsTmpPath_Pmd, &win32fd_pmd);\r
                                if(hPmdFind == (HANDLE)0xffffffff)\r
                                {\r
@@ -247,6 +272,7 @@ JsonGen::JsonGen()
 \r
                                        // \83\82\83f\83\8b\96¼\8eæ\93¾\r
                                        strcpy_s(pmd_model_name_,pmd_info+7);\r
+                                       Trim(pmd_model_name_);\r
                                        int cnt = 0x1b;\r
                                        size_t info_size = ADFUNC_DXconvAnsiToWide(0,0,pmd_info+cnt);\r
                                        TCHAR *pmd_info_t = new TCHAR[info_size + 1];\r
index d352a4c..3be32ca 100644 (file)
Binary files a/client/scene/Title.cpp and b/client/scene/Title.cpp differ
index 97a2a3e..c89df55 100644 (file)
@@ -8,7 +8,7 @@
 
 const size_t Input::TEXT_BUFFER_SIZE = 1024;
 const size_t Input::HISTORY_MAX_SIZE = 50;
-const int Input::KEY_REPEAT_FRAME = 6;
+const int Input::KEY_REPEAT_FRAME = 8;
 
 const int Input::INPUT_MARGIN_X = 8;
 const int Input::INPUT_MARGIN_Y = 6;
@@ -19,9 +19,12 @@ const int Input::IME_MARGIN_Y = 16;
 const int Input::IME_MAX_PAGE_SIZE = 6;
 const int Input::IME_MIN_WIDTH = 120;
 
-Input::Input() :
+Input::Input(ConfigManagerPtr config_manager) :
        multiline_(true),
-    reverse_color_(false)
+    reverse_color_(false),
+       drag_flag_(false),
+       rightmenu_show_(false),
+       config_manager_(config_manager)
 {
     input_bg_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
             _T("system/images/gui/gui_inputbox_input_bg.png"), 2, 2, 12, 12);
@@ -45,6 +48,104 @@ Input::Input() :
     y_ = 100;
     width_ = 160;
     height_ = font_height_ + 4;
+
+}
+
+void Input::Init()
+{
+       right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{
+               UILabel label;
+               label.set_input_adaptor(this);
+               label.set_text(unicode::ToTString(unicode::sjis2utf8("切り取り")));
+               label.set_width(120);
+               label.set_top(12);
+               label.set_left(0);
+               label.set_textcolor(UISuper::Color(0,0,0,255));
+               label.set_bgcolor(UISuper::Color(255,255,255,180));
+               label.set_on_click_function_([](UIBase* ptr)->void{
+                       auto input_ = ptr->input_adpator();
+                       auto sel_txt = input_->selecting_text();
+                       SetClipboardText(sel_txt.c_str());
+                       auto text = input_->text();
+                       auto pos = text.find(sel_txt);
+                       tstring res;
+                       if( pos != std::string::npos )
+                       {
+                               res = text.substr(0,pos);
+                               res += text.substr(pos + sel_txt.size(),text.size() - pos + sel_txt.size());
+                       }
+                       input_->set_text(res);
+               });
+               label.set_on_hover_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(0,0,0,180));
+                       label_ptr->set_textcolor(UISuper::Color(255,255,255));
+               });
+               label.set_on_out_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(255,255,255,180));
+                       label_ptr->set_textcolor(UISuper::Color(0,0,0));
+               });
+               return label;
+       }())));
+       right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{
+               UILabel label;
+               label.set_input_adaptor(this);
+               label.set_text(unicode::ToTString(unicode::sjis2utf8("コピー")));
+               label.set_width(120);
+               label.set_top(12);
+               label.set_left(0);
+               label.set_textcolor(UISuper::Color(0,0,0,255));
+               label.set_bgcolor(UISuper::Color(255,255,255,180));
+               label.set_on_click_function_([&](UIBase* ptr)->void{
+                       auto input_ = ptr->input_adpator();
+                       SetClipboardText(input_->selecting_text().c_str());
+               });
+               label.set_on_hover_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(0,0,0,180));
+                       label_ptr->set_textcolor(UISuper::Color(255,255,255));
+               });
+               label.set_on_out_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(255,255,255,180));
+                       label_ptr->set_textcolor(UISuper::Color(0,0,0));
+               });
+               return label;
+       }())));
+       right_click_list_.addItem(UIBasePtr(new UILabel([&]()->UILabel{
+               UILabel label;
+               label.set_input_adaptor(this);
+               label.set_text(unicode::ToTString(unicode::sjis2utf8("貼り付け")));
+               label.set_width(120);
+               label.set_top(12);
+               label.set_left(0);
+               label.set_textcolor(UISuper::Color(0,0,0,255));
+               label.set_bgcolor(UISuper::Color(255,255,255,180));
+               label.set_on_click_function_([&](UIBase* ptr)->void{
+                       auto input_ = ptr->input_adpator();
+                       auto size = GetClipboardText(NULL);
+                       if(size > 0){
+                               TCHAR *buf = new TCHAR[size];
+                               GetClipboardText(buf);
+                               input_->paste_text(buf);
+                               delete []buf;
+                       }
+               });
+               label.set_on_hover_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(0,0,0,180));
+                       label_ptr->set_textcolor(UISuper::Color(255,255,255));
+               });
+               label.set_on_out_function_([](UIBase* ptr)->void{
+                       auto label_ptr = (UILabel *)ptr;
+                       label_ptr->set_bgcolor(UISuper::Color(255,255,255,180));
+                       label_ptr->set_textcolor(UISuper::Color(0,0,0));
+               });
+               return label;
+       }())));
+       right_click_list_.set_height((font_height_ + 2)* 3);
+       right_click_list_.set_width(120);
 }
 
 void Input::Draw()
@@ -159,12 +260,98 @@ void Input::Draw()
             }
         }
 
-        for (auto it = lines_.begin(); it != lines_.end(); ++it) {
-            auto line = *it;
-            DrawStringToHandle(internal_x, internal_y + current_line * font_height_,
-                    line.c_str(), text_color, font_handle_);
-            current_line++;
-        }
+               int select_start = 0,select_end = 0;
+               GetKeyInputSelectArea(&select_start,&select_end,input_handle_);
+               if( select_start > select_end )std::swap(select_start,select_end);
+
+               if( select_start > -1 && select_end != select_start ) {
+                       if ( multiline_ ) {
+                               BOOST_FOREACH(auto it,lines_){
+                                       int width = 0;
+                                       TCHAR c[2] = {0};
+                                       if( select_start >= it.size() && select_start != -1 ) {
+                                               DrawStringToHandle(internal_x, internal_y + current_line * font_height_,
+                                                       it.c_str(), text_color, font_handle_);
+                                               if(select_start == it.size()){
+                                                       select_start -= it.size();
+                                               }else{
+                                                       select_start -= it.size() + 1;
+                                               }
+                                               select_end -= it.size() + 1;
+                                               ++current_line;
+                                       }else if(select_start != -1){
+                                               for(int i = 0;i < select_start;++i){
+                                                       c[0] = it[i];
+                                                       DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                               c, text_color, font_handle_);
+                                                       width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                               }
+                                               for(int i = select_start;i < ((select_end > it.size()) ? it.size() : select_end); ++i){
+                                                       c[0] = it[i];
+                                                       SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180);
+                                                       DrawBox(internal_x + width,internal_y + current_line * font_height_,
+                                                               internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1);
+                                                       DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                               c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_);
+                                                       width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                                       SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
+                                               }
+                                               for(int i = ((select_end > it.size()) ? it.size() : select_end);i < it.size(); ++i){
+                                                       c[0] = it[i];
+                                                       DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                               c, text_color, font_handle_);
+                                                       width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                               }
+                                               if(select_end > it.size()){
+                                                       select_end -= it.size() + 1;
+                                                       select_start = 0;
+                                               }else{
+                                                       select_start = -1;
+                                               }
+                                               ++current_line;
+                                       }else if(select_start == -1){
+                                               DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                       it.c_str(), text_color, font_handle_);
+                                               ++current_line;
+                                       }
+                               }
+                       }else{
+                               BOOST_FOREACH(auto it,lines_){
+                                       int width = 0;
+                                       TCHAR c[2] = {0};
+                                       for(int i = 0;i < select_start;++i){
+                                               c[0] = it[i];
+                                               DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                       c, text_color, font_handle_);
+                                               width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                       }
+                                       for(int i = select_start;i < select_end; ++i){
+                                               c[0] = it[i];
+                                       SetDrawBlendMode(DX_BLENDMODE_ALPHA, 180);
+                                               DrawBox(internal_x + width,internal_y + current_line * font_height_,
+                                                       internal_x + width + GetDrawStringWidthToHandle(c,1,font_handle_),internal_y + ( current_line + 1 ) * font_height_,text_color,1);
+                                               DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                       c, !reverse_color_ ? GetColor(255, 255, 255) : GetColor(0, 0, 0), font_handle_);
+                                               width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                               SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
+                                       }
+                                       for(int i = select_end;i < it.size(); ++i){
+                                               c[0] = it[i];
+                                               DrawStringToHandle(internal_x + width, internal_y + current_line * font_height_,
+                                                       c, text_color, font_handle_);
+                                               width += GetDrawStringWidthToHandle(c,1,font_handle_);
+                                       }
+                               }
+                       }
+               }else{
+                       for (auto it = lines_.begin(); it != lines_.end(); ++it) {
+                               auto line = *it;
+                               DrawStringToHandle(internal_x, internal_y + current_line * font_height_,
+                                       line.c_str(), text_color, font_handle_);
+                               current_line++;
+                       }
+               }
+
 
         // カーソルを描画
         if (clause_lines_.size() <= 0 && active() && blink_count_ < 30) {
@@ -258,11 +445,21 @@ void Input::Draw()
             }
         }
     }
+       {
+               if ( rightmenu_show_ ) {
+                       right_click_list_.Draw();
+               }
+       }
 }
 
 void Input::Update()
 {
     blink_count_ = (blink_count_ + 1) % 60;
+       {
+               if ( rightmenu_show_ ) {
+                       right_click_list_.Update();
+               }
+       }
 }
 
 void Input::ProcessInput(InputManager* input)
@@ -271,7 +468,15 @@ void Input::ProcessInput(InputManager* input)
         return;
     }
 
-    // bool push_mouse_left = (input->GetMouseLeftCount() > 0);
+       if ( rightmenu_show_ ) {
+               right_click_list_.ProcessInput(input);
+       }
+
+    bool push_mouse_left = (input->GetMouseLeftCount() > 0);
+       bool prev_mouse_left = input->GetPrevMouseLeft();
+
+       bool push_mouse_right = (input->GetMouseRightCount() > 0);
+       bool prev_mouse_right = input->GetPrevMouseRight();
 
     // bool first_key_shift = (input->GetKeyCount(KEY_INPUT_RSHIFT) == 1
     //        || input->GetKeyCount(KEY_INPUT_LSHIFT) == 1);
@@ -292,6 +497,7 @@ void Input::ProcessInput(InputManager* input)
             + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0;
     bool push_repeat_key_down = (input->GetKeyCount(KEY_INPUT_DOWN)
             + KEY_REPEAT_FRAME) % (KEY_REPEAT_FRAME + 1) == 0;
+
     // bool push_long_backspace = (input->GetKeyCount(KEY_INPUT_BACK) > 60 * 1.5);
 
     auto input_text = text();
@@ -407,7 +613,185 @@ void Input::ProcessInput(InputManager* input)
     }
 
     if (active()) {
-        // カーソル位置(byte)を取得
+               if ( !rightmenu_show_ &&
+                       !( rightmenu_show_ && right_click_list_.absolute_x()<= input->GetMouseX() && input->GetMouseX() <= right_click_list_.absolute_x()+ right_click_list_.absolute_width()
+                       && right_click_list_.absolute_y() <= input->GetMouseY() && input->GetMouseY() <= right_click_list_.absolute_y() + right_click_list_.absolute_height())) {
+                               // マウス左ボタンが押された時
+                               if (push_mouse_left && !prev_mouse_left) {
+                                       auto mpos = input->GetMousePos();
+                                       auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X);
+                                       auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y);
+                                       // カレット変更
+                                       if( multiline_ ) {
+                                               auto line_num = offset_y / font_height_;
+                                               //if( ( offset_y % font_height_ ) != 0 )++line_num;
+                                               int tmp = 0,cnt = 0;
+                                               if( line_num < (int)lines_.size() && line_num >= 0 ){
+                                                       for(int i = 0;i < line_num; ++i){
+                                                               cnt += lines_[i].size();
+                                                       }
+                                                       for(int i = 0;i < lines_[line_num].size(); ++i){
+                                                               auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_);
+                                                               if( tmp + tmp_x < offset_x ){
+                                                                       tmp += tmp_x;
+                                                                       ++cnt;
+                                                               }
+                                                       }
+                                                       SetKeyInputCursorPosition(line_num + cnt,input_handle_);
+                                               }
+                                       }else{
+                                               int tmp = 0,cnt = 0;
+                                               for(int i = 0;i < lines_[0].size(); ++i){
+                                                       auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_);
+                                                       if( tmp + tmp_x < offset_x ){
+                                                               tmp += tmp_x;
+                                                               ++cnt;
+                                                       }
+                                               }
+                                               if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) {
+                                                       SetKeyInputSelectArea( -1, -1, input_handle_ );
+                                               }else{
+                                                       SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_);
+                                               }
+                                               SetKeyInputCursorPosition(cnt,input_handle_);
+                                       }
+                               }
+                               // マウス左ボタンがドラッグされた時
+                               if (push_mouse_left && prev_mouse_left ) {
+                                       int prev_cursor_pos = 0;
+                                       if( !drag_flag_ ){
+                                               prev_cursor_pos = GetKeyInputCursorPosition(input_handle_);
+                                       }else{
+                                               prev_cursor_pos = selecting_coursorpoint_.first;
+                                       }
+                                       auto mpos = input->GetMousePos();
+                                       auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X);
+                                       auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y);
+                                       // カレット変更
+                                       if( multiline_ ) {
+                                               auto line_num = offset_y / font_height_;
+                                               int tmp = 0,cnt = 0;
+                                               if( line_num < (int)lines_.size() && line_num >= 0){
+                                                       for(int i = 0;i < line_num; ++i,++cnt){
+                                                               cnt += lines_[i].size();
+                                                       }
+                                                       for(int i = 0;i < lines_[line_num].size(); ++i){
+                                                               auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_);
+                                                               if( tmp + tmp_x < offset_x ){
+                                                                       tmp += tmp_x;
+                                                                       ++cnt;
+                                                               }
+                                                       }
+                                               }
+                                               selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt);
+                                       }else{
+                                               int tmp = 0,cnt = 0;
+                                               for(int i = 0;i < lines_[0].size(); ++i){
+                                                       auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_);
+                                                       if( tmp + tmp_x < offset_x ){
+                                                               tmp += tmp_x;
+                                                               ++cnt;
+                                                       }
+                                               }
+                                               selecting_coursorpoint_ = std::make_pair<int,int>(prev_cursor_pos,cnt);
+                                       }
+                                       SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_);
+                                       SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_);
+                                       drag_flag_ = true;
+                               }
+                               // マウス左ボタンが離され、且つ前回ドラッグされていた時
+                               if (!push_mouse_left && prev_mouse_left && drag_flag_ ) {
+                                       drag_flag_ = false;
+                                       if( selecting_coursorpoint_.first == selecting_coursorpoint_.second ) {
+                                               SetKeyInputSelectArea( -1, -1, input_handle_ );
+                                       }else{
+                                               SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_);
+                                       }
+                                       SetKeyInputCursorPosition(selecting_coursorpoint_.second,input_handle_);
+                               }
+               }else{
+                       if( push_mouse_left ){
+                               rightmenu_show_ = false;
+                               auto mpos = input->GetMousePos();
+                               auto offset_x = mpos.first - (x_ + INPUT_MARGIN_X);
+                               auto offset_y = mpos.second - (y_ + INPUT_MARGIN_Y);
+                               // カレット変更
+                               if( multiline_ ) {
+                                       auto line_num = offset_y / font_height_;
+                                       //if( ( offset_y % font_height_ ) != 0 )++line_num;
+                                       int tmp = 0,cnt = 0;
+                                       if( line_num < (int)lines_.size() && line_num >= 0 ){
+                                               for(int i = 0;i < line_num; ++i){
+                                                       cnt += lines_[i].size();
+                                               }
+                                               for(int i = 0;i < lines_[line_num].size(); ++i){
+                                                       auto tmp_x = GetDrawStringWidthToHandle(&lines_[line_num][i],1,font_handle_);
+                                                       if( tmp + tmp_x < offset_x ){
+                                                               tmp += tmp_x;
+                                                               ++cnt;
+                                                       }
+                                               }
+                                               SetKeyInputCursorPosition(line_num + cnt,input_handle_);
+                                       }
+                               }else{
+                                       int tmp = 0,cnt = 0;
+                                       for(int i = 0;i < lines_[0].size(); ++i){
+                                               auto tmp_x = GetDrawStringWidthToHandle(&lines_[0][i],1,font_handle_);
+                                               if( tmp + tmp_x < offset_x ){
+                                                       tmp += tmp_x;
+                                                       ++cnt;
+                                               }
+                                       }
+                                       if( selecting_coursorpoint_.first = selecting_coursorpoint_.second ) {
+                                               SetKeyInputSelectArea( -1, -1, input_handle_ );
+                                       }else{
+                                               SetKeyInputSelectArea(selecting_coursorpoint_.first,selecting_coursorpoint_.second,input_handle_);
+                                       }
+                                       SetKeyInputCursorPosition(cnt,input_handle_);
+                               }
+                       }
+               }
+               // マウス右ボタンが押されたとき
+               if ( push_mouse_right && !prev_mouse_right ) {
+                       if( x() <= input->GetMouseX() && input->GetMouseX() <= x() + width() && 
+                               y() <= input->GetMouseY() && input->GetMouseY() <= y() + height()){
+                                       mouse_pos_ = input->GetMousePos();
+                                       if( mouse_pos_.second + right_click_list_.absolute_height() > config_manager_->screen_height()){
+                                               right_click_list_.set_top(mouse_pos_.second - right_click_list_.absolute_height());
+                                               if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){
+                                                       right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width());
+                                                       BOOST_FOREACH(auto it,right_click_list_.getItems()){
+                                                               it->set_left(mouse_pos_.first - right_click_list_.absolute_width());
+                                                               it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12);
+                                                       }
+                                               }else{
+                                                       right_click_list_.set_left(mouse_pos_.first);
+                                                       BOOST_FOREACH(auto it,right_click_list_.getItems()){
+                                                               it->set_left(mouse_pos_.first);
+                                                               it->set_top(mouse_pos_.second - right_click_list_.absolute_height() + 12);
+                                                       }
+                                               }
+                                       }else{
+                                               right_click_list_.set_top(mouse_pos_.second);
+                                               if ( mouse_pos_.first + right_click_list_.absolute_width() > config_manager_->screen_width()){
+                                                       right_click_list_.set_left(mouse_pos_.first - right_click_list_.absolute_width());
+                                                       BOOST_FOREACH(auto it,right_click_list_.getItems()){
+                                                               it->set_left(mouse_pos_.first - right_click_list_.absolute_width());
+                                                               it->set_top(mouse_pos_.second + 12);
+                                                       }
+                                               }else{
+                                                       right_click_list_.set_left(mouse_pos_.first);
+                                                       BOOST_FOREACH(auto it,right_click_list_.getItems()){
+                                                               it->set_left(mouse_pos_.first);
+                                                               it->set_top(mouse_pos_.second + 12);
+                                                       }
+                                               }
+                                       }
+                                       rightmenu_show_ = true;
+                       }
+               }
+
+        // カーソル位置(文字単位)を取得
         cursor_byte_pos = GetKeyInputCursorPosition(input_handle_);
                if (prev_cursor_pos_ != cursor_byte_pos) {
                        ResetCursorCount();
@@ -415,6 +799,7 @@ void Input::ProcessInput(InputManager* input)
 
                prev_cursor_pos_ = cursor_byte_pos;
 
+
         // カーソルのドット単位の位置を取得する
         cursor_dot_pos = GetDrawStringWidthToHandle(String, cursor_byte_pos,
                 font_handle_);
@@ -621,6 +1006,7 @@ void Input::ProcessInput(InputManager* input)
             TCHAR c = *it;
             int width = GetDrawStringWidthToHandle(&c, 1, font_handle_);
             line_buffer += tstring(&c, 1);
+                       char_count++;
         #else
             unsigned char c = *it;
             TCHAR string[2] = { 0, 0 };
@@ -659,7 +1045,7 @@ void Input::ProcessInput(InputManager* input)
                     && cursor_moveto_x_ <= line_width + width
                     && static_cast<int>(lines_.size() + message_lines_.size()) * font_height_ <= cursor_moveto_y_
                     && cursor_moveto_y_ <= (static_cast<int>(lines_.size() + message_lines_.size()) + 1) * font_height_) {
-                SetKeyInputCursorPosition(prev_char_count, input_handle_);
+                SetKeyInputCursorPosition(char_count - 1, input_handle_);
                 cursor_moveto_x_ = -1;
                 cursor_moveto_y_ = -1;
             }
@@ -815,6 +1201,51 @@ void Input::set_on_enter(const CallbackFunc& func)
     on_enter_ = func;
 }
 
+tstring Input::selecting_text() const
+{
+               int select_start = 0,select_end = 0;
+               GetKeyInputSelectArea(&select_start,&select_end,input_handle_);
+               if( select_start > select_end )std::swap(select_start,select_end);
+               tstring selecting_text;
+
+               if( select_start > -1 && select_end != select_start ) {
+                       if ( multiline_ ) {
+                               BOOST_FOREACH(auto it,lines_){
+                                       TCHAR c[2] = {0};
+                                       if( select_start > it.size() && select_start != -1 ) {
+                                               select_start -= it.size();
+                                               select_end -= it.size();
+                                       }else{
+                                               for(int i = select_start;i < select_end; ++i){
+                                                       c[0] = it[i];
+                                                   selecting_text += c;
+                                               }
+                                               select_start = -1;
+                                       }
+                               }
+                       }else{
+                               BOOST_FOREACH(auto it,lines_){
+                                       TCHAR c[2] = {0};
+                                       for(int i = select_start;i < select_end; ++i){
+                                               c[0] = it[i];
+                                       selecting_text += c;
+                                       }
+                               }
+                       }
+               }
+               return selecting_text;
+}
+
+void Input::paste_text(tstring text)
+{
+       auto pos = GetKeyInputCursorPosition(input_handle_);
+       TCHAR String[TEXT_BUFFER_SIZE];
+    GetKeyInputString(String, input_handle_);
+    tstring dat(String, _tcslen(String));
+       dat.insert(pos,text);
+       SetKeyInputString(dat.c_str(), input_handle_);
+}
+
 bool Input::reverse_color() const
 {
     return reverse_color_;
index 47ea084..cde1bea 100644 (file)
@@ -8,16 +8,20 @@
 #include <functional>
 #include "../ResourceManager.hpp"
 #include "../InputManager.hpp"
+#include "../ConfigManager.hpp"
+#include "include.hpp"
+#include <boost/enable_shared_from_this.hpp>
 
-class Input {
+class Input{
         typedef std::function<bool(const std::string&)> CallbackFunc;
 
     public:
-        Input();
+        Input(ConfigManagerPtr config_manager);
 
         void Draw();
         void Update();
         void ProcessInput(InputManager* input);
+               void Init();
 
         bool active();
         void set_active(bool flag);
@@ -45,6 +49,9 @@ class Input {
 
         void set_on_enter(const CallbackFunc& func);
 
+               tstring selecting_text() const;
+               void paste_text(tstring text);
+
     public:    
         void CancelSelect();
 
@@ -73,12 +80,20 @@ class Input {
         std::vector<std::pair<int, int>> selecting_lines_;
         std::vector<std::pair<int, int>> clause_lines_;
         std::vector<std::pair<int, int>> selecting_clause_lines_;
+               std::pair<int, int> selecting_coursorpoint_;
+               bool drag_flag_;
 
         CallbackFunc on_enter_;
         tstring message_;
 
         bool reverse_color_;
         int blink_count_;
+               bool rightmenu_show_;
+               std::pair<int, int> mouse_pos_;
+
+               UIList right_click_list_;
+
+               ConfigManagerPtr config_manager_;
 
     private:
         const static size_t TEXT_BUFFER_SIZE;
index 5d80ea4..ad83315 100644 (file)
@@ -43,7 +43,8 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) :
                 selecting_tab_index_(0),
                 manager_accessor_(manager_accessor),
                 card_(std::make_shared<Card>(manager_accessor_, "", "immo", "",
-                            std::vector<std::string>()))
+                            std::vector<std::string>())),
+                               input_(manager_accessor->config_manager().lock())
 
 {
        absolute_rect_ = Rect(100, 100, 800, 100);
@@ -102,6 +103,7 @@ InputBox::InputBox(const ManagerAccessorPtr& manager_accessor) :
 
         return true;
     });
+       input_.Init();
 }
 
 InputBox::~InputBox()
index d101c2f..8282700 100644 (file)
@@ -19,7 +19,8 @@
 #include <DxLib.h>
 #include <algorithm>
 
-UIBase::UIBase()
+UIBase::UIBase() :
+hover_flag_(false)
 {
 
 }
@@ -38,6 +39,17 @@ void UIBase::ProcessInput(InputManager* input)
 
 }
 
+void UIBase::Update()
+{
+};
+
+void UIBase::Draw()
+{
+       if(!children_.empty()){
+               DrawChildren();
+       }
+}
+
 void UIBase::AsyncUpdate()
 {
     AsyncUpdateChildren();
@@ -469,6 +481,26 @@ void UIBase::set_parent(const Handle<Object>& parent)
     parent_ = Persistent<Object>::New(parent);
 }
 
+UIBasePtr UIBase::parent_c() const
+{
+    return parent_c_;
+}
+
+void UIBase::set_parent_c(const UIBasePtr& parent)
+{
+    parent_c_ = parent;
+}
+
+Input* UIBase::input_adpator() const
+{
+       return input_adaptor_;
+}
+
+void UIBase::set_input_adaptor(Input* adaptor)
+{
+       input_adaptor_ = adaptor;
+}
+
 size_t UIBase::children_size() const
 {
     return children_.size();
index 4b61ea9..d80f97a 100644 (file)
@@ -7,6 +7,7 @@
 #include "UISuper.hpp"
 #include <v8.h>
 #include "../InputManager.hpp"
+#include <functional>
 
 using namespace v8;
 
@@ -14,8 +15,10 @@ class ScriptEnvironment;
 typedef std::weak_ptr<ScriptEnvironment> ScriptEnvironmentWeakPtr;
 
 class UIBase;
+class Input;
 typedef std::shared_ptr<UIBase> UIBasePtr;
 typedef std::weak_ptr<UIBase> UIBaseWeakPtr;
+typedef std::function<void(UIBase*)> CallbackFuncWithThisPointer;
 
 class UIBase : public UISuper {
 
@@ -24,8 +27,8 @@ class UIBase : public UISuper {
         virtual ~UIBase();
 
         virtual void ProcessInput(InputManager* input);
-        virtual void Update() = 0;
-        virtual void Draw() = 0;
+        virtual void Update();
+        virtual void Draw();
         virtual void AsyncUpdate(); // 毎ループ実行する必要のない処理
 
         /* function */
@@ -57,6 +60,10 @@ class UIBase : public UISuper {
 
         Handle<Object> parent() const;
         void set_parent(const Handle<Object>& parent);
+               UIBasePtr parent_c() const;
+               void set_parent_c(const UIBasePtr &parent_c);
+               Input* input_adpator() const;
+               void set_input_adaptor(Input * adaptor);
 
         size_t children_size() const;
 
@@ -92,12 +99,30 @@ class UIBase : public UISuper {
 
         void Focus();
 
+       public:
+               /* Property */
+               template<class F>
+               void set_on_click_function_(F function);
+               template<class F>
+               void set_on_hover_function_(F function);
+               template<class F>
+               void set_on_out_function_(F function);
+
     protected:
 
         Persistent<Object> parent_;
         std::vector<Persistent<Object>> children_;
 
         Persistent<Function> on_click_;
+               CallbackFuncWithThisPointer on_click_function_;
+               CallbackFuncWithThisPointer on_hover_function_;
+               CallbackFuncWithThisPointer on_out_function_;
+
+               bool hover_flag_;
+
+               /*C++からクラスを伝達するためのメンバ*/
+               UIBasePtr parent_c_;
+               Input* input_adaptor_;
 
 };
 
@@ -155,3 +180,21 @@ void UIBase::SetConstant(Handle<ObjectTemplate>* object, const std::string& name
     Handle<ObjectTemplate>& instance_template = *object;
     instance_template->Set(String::New(name.c_str()), value);
 }
+
+template<class F>
+void UIBase::set_on_click_function_(F function)
+{
+       on_click_function_ = function;
+}
+
+template<class F>
+void UIBase::set_on_hover_function_(F function)
+{
+       on_hover_function_ = function;
+}
+
+template<class F>
+void UIBase::set_on_out_function_(F function)
+{
+       on_out_function_ = function;
+}
\ No newline at end of file
index 02ba84f..de37899 100644 (file)
@@ -25,7 +25,8 @@ UIBoard::UIBoard() :
                 max_height_(800),
                 min_height_(100),
                 drag_offset_rect_(-1, -1, -1, -1),
-                drag_resize_offset_rect_(-1, -1, -1, -1)
+                drag_resize_offset_rect_(-1, -1, -1, -1),
+                               boardvisible_(true)
 {
     base_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
             _T("system/images/gui/gui_board_bg.png"), 2, 2, 24, 24);
@@ -247,40 +248,42 @@ void UIBoard::Draw()
     if (!visible_) {
         return;
     }
+       
+       if (boardvisible_) {
+               SetDrawBlendMode(DX_BLENDMODE_ADD, 255);
 
-    SetDrawBlendMode(DX_BLENDMODE_ADD, 255);
+               int x = absolute_x();
+               int y = absolute_y();
+               int width = absolute_width();
+               int height = absolute_height();
 
-    int x = absolute_x();
-    int y = absolute_y();
-    int width = absolute_width();
-    int height = absolute_height();
+               DrawGraph(x, y, *base_image_handle_[0], TRUE);
+               DrawGraph(x + width - BASE_BLOCK_SIZE, y, *base_image_handle_[1], TRUE);
+               DrawGraph(x, y + height - BASE_BLOCK_SIZE, *base_image_handle_[2], TRUE);
+               DrawGraph(x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE);
 
-    DrawGraph(x, y, *base_image_handle_[0], TRUE);
-    DrawGraph(x + width - BASE_BLOCK_SIZE, y, *base_image_handle_[1], TRUE);
-    DrawGraph(x, y + height - BASE_BLOCK_SIZE, *base_image_handle_[2], TRUE);
-    DrawGraph(x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE);
+               DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y,
+                       x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
+                       0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[1], TRUE);
 
-    DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y,
-                         x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
-                         0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[1], TRUE);
+               DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
+                       x + width - BASE_BLOCK_SIZE, y + height,
+                       0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE);
 
-    DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
-                         x + width - BASE_BLOCK_SIZE, y + height,
-                         0, 0, 1, BASE_BLOCK_SIZE, *base_image_handle_[3], TRUE);
+               DrawRectExtendGraphF(x, y + BASE_BLOCK_SIZE,
+                       x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
+                       0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[2], TRUE);
 
-    DrawRectExtendGraphF(x, y + BASE_BLOCK_SIZE,
-                         x + BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
-                         0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[2], TRUE);
+               DrawRectExtendGraphF(x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
+                       x + width, y + height - BASE_BLOCK_SIZE,
+                       0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[3], TRUE);
 
-    DrawRectExtendGraphF(x + width - BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
-                         x + width, y + height - BASE_BLOCK_SIZE,
-                         0, 0, BASE_BLOCK_SIZE, 1, *base_image_handle_[3], TRUE);
+               DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
+                       x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
+                       0, 0, 1, 1, *base_image_handle_[3], TRUE);
 
-    DrawRectExtendGraphF(x + BASE_BLOCK_SIZE, y + BASE_BLOCK_SIZE,
-                         x + width - BASE_BLOCK_SIZE, y + height - BASE_BLOCK_SIZE,
-                         0, 0, 1, 1, *base_image_handle_[3], TRUE);
-
-    SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
+               SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
+       }
 
     DrawChildren();
 }
@@ -290,6 +293,16 @@ bool UIBoard::resizable() const
     return resizable_;
 }
 
+bool UIBoard::boardvisible() const
+{
+       return boardvisible_;
+}
+
+void UIBoard::set_boardvisible(bool visible)
+{
+       boardvisible_ = visible;
+}
+
 void UIBoard::set_resizable(bool resizable)
 {
     resizable_ = resizable;
index d826948..f80ec76 100644 (file)
@@ -16,7 +16,9 @@ class UIBoard : public UIBase {
         void Draw();
 
         bool resizable() const;
+               bool boardvisible() const;
         void set_resizable(bool resizable);
+               void set_boardvisible(bool visible);
 
     public:
         static void DefineInstanceTemplate(Handle<ObjectTemplate>* object);
@@ -38,6 +40,7 @@ class UIBoard : public UIBase {
         std::array<ImageHandlePtr,4> base_image_handle_;
 
         bool resizable_;
+               bool boardvisible_;
 
         int max_width_, min_width_;
         int max_height_, min_height_;
@@ -47,3 +50,5 @@ class UIBoard : public UIBase {
     private:
         const static int BASE_BLOCK_SIZE;
 };
+
+typedef std::shared_ptr<UIBoard> UIBoardPtr;
\ No newline at end of file
index a76ca3a..1f1db79 100644 (file)
@@ -96,7 +96,8 @@ void UICustom::DefineInstanceTemplate(Handle<ObjectTemplate>* object)
        SetProperty(object, "_update", Property_update, Property_set_update);
        SetProperty(object, "_draw", Property_draw, Property_set_draw);
 
-       SetFunction(object, "drawLine", Function_drawLine);
+       SetFunction(object, "DrawLine", Function_DrawLine);
+       SetFunction(object, "DrawBox", Function_DrawBox);
 }
 
 void UICustom::ProcessInput(InputManager* input)
@@ -131,16 +132,527 @@ void UICustom::Draw()
        }
 }
 
-Handle<Value> UICustom::Function_drawLine(const Arguments& args)
+
+Handle<Value> UICustom::Function_DrawLine(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto x1 = args[2]->Int32Value();
+               auto y1 = args[3]->Int32Value();
+               auto r = args[4]->Int32Value();
+               auto g = args[5]->Int32Value();
+               auto b = args[6]->Int32Value();
+
+               if( args[7]->IsInt32() )
+               {
+                       auto t = args[7]->Int32Value();
+                       DrawLine(x0, y0, x1, y1, GetColor(r, g, b),t);
+               }else{
+                       DrawLine(x0, y0, x1, y1, GetColor(r, g, b));
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawBox(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto x1 = args[2]->Int32Value();
+               auto y1 = args[3]->Int32Value();
+               auto r = args[4]->Int32Value();
+               auto g = args[5]->Int32Value();
+               auto b = args[6]->Int32Value();
+
+               if( args[7]->IsBoolean() )
+               {
+                       auto fillflag = args[7]->BooleanValue();
+                       DrawBox(x0, y0, x1, y1, GetColor(r, g, b),fillflag ? 1 : 0);
+               }else{
+                       DrawBox(x0, y0, x1, y1, GetColor(r, g, b),1);
+               }
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawEdgeBox(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto x1 = args[2]->Int32Value();
+               auto y1 = args[3]->Int32Value();
+               auto r = args[4]->Int32Value();
+               auto g = args[5]->Int32Value();
+               auto b = args[6]->Int32Value();
+
+               auto DrawOfOnlyEdge = [](int x, int y, int width, int height, int Color, int thickness)
+               {
+                       DrawBox( x, y, x + width, y + thickness, Color, TRUE);
+                       DrawBox( x, y, x + thickness, y + height, Color, TRUE);
+                       DrawBox( x + width - thickness, y, x + width, y + height, Color, TRUE);
+                       DrawBox( x, y + height - thickness, x + width, y + height, Color, TRUE);
+               };// thickness\82Å\8e¦\82µ\82½\91¾\82³\82Å\89\8f\82Ì\82Ý\82Ì\8el\8ap\8c`\82ð\95`\89æ
+
+               if( args[7]->IsInt32() )
+               {
+                       auto t = args[7]->Int32Value();
+                       if( args[8]->IsBoolean() )
+                       {
+                               auto fillflag = args[8]->BooleanValue();
+                               DrawOfOnlyEdge(x0 - t, y0 - t, x1 + t, y1 + t, GetColor(r, g, b),t);
+                               DrawBox(x0, y0, x1, y1, GetColor(r, g, b),fillflag ? 1 : 0);
+                       }else{
+                               DrawOfOnlyEdge(x0 - t, y0 - t, x1 + t, y1 + t, GetColor(r, g, b),t);
+                       }
+               }else{
+                       DrawOfOnlyEdge(x0 - 1, y0 - 1, x1 + 1, y1 + 1, GetColor(r, g, b),1);
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawCircle(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto r0 = args[2]->Int32Value();
+               auto r = args[3]->Int32Value();
+               auto g = args[4]->Int32Value();
+               auto b = args[5]->Int32Value();
+
+               if( args[6]->IsBoolean() )
+               {
+                       auto fillflag = args[6]->BooleanValue();
+                       DrawCircle(x0, y0, r0, GetColor(r, g, b),fillflag ? 1 : 0);
+               }else{
+                       DrawCircle(x0, y0, r0, GetColor(r, g, b),1);
+               }
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawOval(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto rx = args[2]->Int32Value();
+               auto ry = args[3]->Int32Value();
+               auto r = args[4]->Int32Value();
+               auto g = args[5]->Int32Value();
+               auto b = args[6]->Int32Value();
+
+               if( args[7]->IsBoolean() )
+               {
+                       auto fillflag = args[7]->BooleanValue();
+                       DrawOval(x0, y0, rx, ry, GetColor(r, g, b),fillflag ? 1 : 0);
+               }else{
+                       DrawOval(x0, y0, rx, ry, GetColor(r, g, b),1);
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawTriangle(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() &&
+               args[7]->IsInt32() &&
+               args[8]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto x1 = args[2]->Int32Value();
+               auto y1 = args[3]->Int32Value();
+               auto x2 = args[4]->Int32Value();
+               auto y2 = args[5]->Int32Value();
+               auto r = args[6]->Int32Value();
+               auto g = args[7]->Int32Value();
+               auto b = args[8]->Int32Value();
+
+               if( args[9]->IsBoolean() )
+               {
+                       auto fillflag = args[9]->BooleanValue();
+                       DrawTriangle(x0, y0, x1, y1, x2, y2, GetColor(r, g, b),fillflag ? 1 : 0);
+               }else{
+                       DrawTriangle(x0, y0, x1, y1, x2, y2, GetColor(r, g, b),1);
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawQuadrangle(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() &&
+               args[7]->IsInt32() &&
+               args[8]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto x1 = args[2]->Int32Value();
+               auto y1 = args[3]->Int32Value();
+               auto x2 = args[4]->Int32Value();
+               auto y2 = args[5]->Int32Value();
+               auto x3 = args[6]->Int32Value();
+               auto y3 = args[7]->Int32Value();
+               auto r = args[8]->Int32Value();
+               auto g = args[9]->Int32Value();
+               auto b = args[10]->Int32Value();
+
+               if( args[11]->IsBoolean() )
+               {
+                       auto fillflag = args[9]->BooleanValue();
+                       DrawQuadrangle(x0, y0, x1, y1, x2, y2, x3, y3, GetColor(r, g, b),fillflag ? 1 : 0);
+               }else{
+                       DrawQuadrangle(x0, y0, x1, y1, x2, y2, x3, y3, GetColor(r, g, b),1);
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawPixel(const Arguments& args)
 {
     assert(args.This()->InternalFieldCount() > 0);
     auto self = std::dynamic_pointer_cast<UICustom>(
             *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
     );
     assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto r = args[2]->Int32Value();
+               auto g = args[3]->Int32Value();
+               auto b = args[4]->Int32Value();
+
+               DrawPixel(x0, y0, GetColor(r, g, b));
 
-       DrawLine(100, 100, 200, 200, GetColor(255,255,255));
+       }
 
     return Undefined();
 }
 
+Handle<Value> UICustom::Function_Paint(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto r0 = args[2]->Int32Value();
+               auto g0 = args[3]->Int32Value();
+               auto b0 = args[4]->Int32Value();
+               if(     args[5]->IsInt32() &&
+                       args[6]->IsInt32() &&
+                       args[7]->IsInt32() )
+               {
+                       auto r1 = args[5]->Int32Value();
+                       auto g1 = args[6]->Int32Value();
+                       auto b1 = args[7]->Int32Value();
+                       Paint(x0, y0, GetColor(r0, g0, b0), GetColor(r1, g1, b1));
+               }else{
+                       Paint(x0, y0, GetColor(r0, g0, b0));
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawPixelSet(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsArray() )
+       {
+               auto array = Local<Array>::Cast(args[0]);
+               auto length = array->Length();
+               auto data = static_cast<POINTDATA*>(array->GetPointerFromInternalField(0));
+               
+               DrawPixelSet(data,length);
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawLineSet(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsArray() )
+       {
+               auto array = Local<Array>::Cast(args[0]);
+               auto length = array->Length();
+               auto data = static_cast<LINEDATA*>(array->GetPointerFromInternalField(0));
+               
+               DrawLineSet(data,length);
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawPixel3D(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto z0 = args[2]->Int32Value();
+               auto r = args[3]->Int32Value();
+               auto g = args[4]->Int32Value();
+               auto b = args[5]->Int32Value();
+
+               DrawPixel3D(VGet(x0, y0, z0), GetColor(r, g, b));
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawLine3D(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() &&
+               args[7]->IsInt32() &&
+               args[8]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto z0 = args[2]->Int32Value();
+               auto x1 = args[3]->Int32Value();
+               auto y1 = args[4]->Int32Value();
+               auto z1 = args[5]->Int32Value();
+               auto r = args[6]->Int32Value();
+               auto g = args[7]->Int32Value();
+               auto b = args[8]->Int32Value();
+
+               DrawLine3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(r, g, b));
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawCube3D(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() &&
+               args[7]->IsInt32() &&
+               args[8]->IsInt32() &&
+               args[9]->IsInt32() &&
+               args[10]->IsInt32() &&
+               args[11]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto z0 = args[2]->Int32Value();
+               auto x1 = args[3]->Int32Value();
+               auto y1 = args[4]->Int32Value();
+               auto z1 = args[5]->Int32Value();
+               auto dr = args[6]->Int32Value();
+               auto dg = args[7]->Int32Value();
+               auto db = args[8]->Int32Value();
+               auto sr = args[9]->Int32Value();
+               auto sg = args[10]->Int32Value();
+               auto sb = args[11]->Int32Value();
+
+               if( args[12]->IsBoolean() )
+               {
+                       auto fillflag = args[9]->BooleanValue();
+                       DrawCube3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(dr, dg, db), GetColor(sr, sg, db), fillflag ? 1 : 0);
+               }else{
+                       DrawCube3D(VGet(x0, y0, z0), VGet(x1, y1, z1), GetColor(dr, dg, db), GetColor(sr, sg, db), 1);
+               }
+
+       }
+
+    return Undefined();
+}
+
+Handle<Value> UICustom::Function_DrawSphere3D(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+       if(     args[0]->IsInt32() &&
+               args[1]->IsInt32() &&
+               args[2]->IsInt32() &&
+               args[3]->IsInt32() &&
+               args[4]->IsInt32() &&
+               args[5]->IsInt32() &&
+               args[6]->IsInt32() &&
+               args[7]->IsInt32() &&
+               args[8]->IsInt32() &&
+               args[9]->IsInt32() &&
+               args[10]->IsInt32() )
+       {
+               auto x0 = args[0]->Int32Value();
+               auto y0 = args[1]->Int32Value();
+               auto z0 = args[2]->Int32Value();
+               auto r = args[3]->Int32Value();
+               auto divnum = args[4]->Int32Value();
+               auto dr = args[5]->Int32Value();
+               auto dg = args[6]->Int32Value();
+               auto db = args[7]->Int32Value();
+               auto sr = args[8]->Int32Value();
+               auto sg = args[9]->Int32Value();
+               auto sb = args[10]->Int32Value();
+
+               if( args[11]->IsBoolean() )
+               {
+                       auto fillflag = args[9]->BooleanValue();
+                       DrawSphere3D(VGet(x0, y0, z0), r, divnum, GetColor(dr, dg, db), GetColor(sr, sg, db), fillflag ? 1 : 0);
+               }else{
+                       DrawSphere3D(VGet(x0, y0, z0), r, divnum, GetColor(dr, dg, db), GetColor(sr, sg, db), 1);
+               }
+
+       }
+
+    return Undefined();
+}
index e9488dd..523aa44 100644 (file)
@@ -28,7 +28,26 @@ class UICustom : public UIBase {
                static void Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info);
 
        private:
-               static Handle<Value> Function_drawLine(const Arguments& args);
+               /* function */
+               static Handle<Value> Function_DrawLine(const Arguments& args);
+               static Handle<Value> Function_DrawBox(const Arguments& args);
+               static Handle<Value> Function_DrawEdgeBox(const Arguments& args);
+               static Handle<Value> Function_DrawCircle(const Arguments& args);
+               static Handle<Value> Function_DrawOval(const Arguments& args);
+               static Handle<Value> Function_DrawTriangle(const Arguments& args);
+               static Handle<Value> Function_DrawQuadrangle(const Arguments& args);
+               static Handle<Value> Function_DrawPixel(const Arguments& args);
+               static Handle<Value> Function_Paint(const Arguments& args);
+               static Handle<Value> Function_DrawPixelSet(const Arguments& args);
+               static Handle<Value> Function_DrawLineSet(const Arguments& args);
+               static Handle<Value> Function_DrawPixel3D(const Arguments& args);
+               static Handle<Value> Function_DrawLine3D(const Arguments& args);
+               static Handle<Value> Function_DrawCube3D(const Arguments& args);
+               static Handle<Value> Function_DrawSphere3D(const Arguments& args);
+               static Handle<Value> Function_DrawCapsule3D(const Arguments& args);
+               static Handle<Value> Function_DrawCone3D(const Arguments& args);
+       
+               static Handle<Value> Function_LoadGraph(const Arguments& args);
 
 };
 
index 369e113..96e6e33 100644 (file)
@@ -189,6 +189,19 @@ void UILabel::ProcessInput(InputManager* input)
        if (input->GetMouseLeftCount() == 1 && hover) {  
                if (!on_click_.IsEmpty() && on_click_->IsFunction()) {
                        on_click_.As<Function>()->CallAsFunction(Context::GetCurrent()->Global(), 0, nullptr);
+               }else if(!on_click_function_._Empty()) {
+                       on_click_function_(this);
+                       input->CancelMouseLeft();
+               }
+       }else if(hover && !hover_flag_){
+               if(!on_hover_function_._Empty()) {
+                       on_hover_function_(this);
+                       hover_flag_ = true;
+               }
+       }else if(!hover && hover_flag_){
+               if(!on_out_function_._Empty()) {
+                       on_out_function_(this);
+                       hover_flag_ = false;
                }
        }
 }
index 75cc097..975d51f 100644 (file)
@@ -169,6 +169,41 @@ void UIList::ProcessInput(InputManager* input)
 
 }
 
+void UIList::addItem(UIBasePtr item)
+{
+       item->set_parent_c(UIBasePtr(new UIList(*this)));
+       items_.push_back(item);
+}
+
+void UIList::removeItem(UIBasePtr item)
+{
+       auto it = std::find(items_.begin(), items_.end(), item);
+       if (it != items_.end()) {
+               UIBasePtr chid_ptr = *it;
+               chid_ptr->set_parent_c(nullptr);
+               items_.erase(it);
+       }
+}
+
+void UIList::clearItems()
+{
+    BOOST_FOREACH(auto it, items_) {
+        UIBasePtr chid_ptr = it;
+        chid_ptr->set_parent_c(nullptr);
+    }
+       items_.clear();
+}
+
+std::vector<UIBasePtr> UIList::getItems() const
+{
+       return items_;
+}
+
+void UIList::set_scroll_y(int scroll_y)
+{
+       scroll_y_ = scroll_y;
+}
+
 void UIList::UpdateScrollBar(InputManager* input)
 {
     int screen_width, screen_height;
index 5418783..7f688a5 100644 (file)
@@ -18,7 +18,7 @@ class UIList : public UIBase {
         void Draw();
 
     public:
-        static void                           DefineInstanceTemplate(Handle<ObjectTemplate>* object);
+        static void DefineInstanceTemplate(Handle<ObjectTemplate>* object);
 
     private:
         /* function */
@@ -30,6 +30,16 @@ class UIList : public UIBase {
         static Handle<Value> Property_scroll_y(Local<String> property, const AccessorInfo &info);
         static void Property_set_scroll_y(Local<String> property, Local<Value> value, const AccessorInfo& info);
 
+       public:
+        /* function */
+               void addItem(UIBasePtr item);
+               void removeItem(UIBasePtr item);
+               void clearItems();
+               std::vector<UIBasePtr> getItems() const;
+
+        /* property */
+               void set_scroll_y(int scroll_y);
+
     private:
         std::array<ImageHandlePtr,4> scrollbar_base_image_handle_;