コード例 #1
0
HLAmodule::HLAmodule(const SimulatorConfig& config) 
    : _connected(false),
    _localSettingsDesignator(config.getLocalSettingsDesignator()),
    _federateName           (config.getFederateName()),
    _federationName         (config.getFederationName()),
    _FOM                    (config.getFOM())
{ /* void */ }
コード例 #2
0
void ProjectConfigDialog::onScreenSizeChanged(void)
{
    HWND list = GetDlgItem(m_hwndDialog, IDC_COMBO_SCREEN_SIZE);
    int index = ComboBox_GetCurSel(list);
    SimulatorConfig *defaults = SimulatorConfig::sharedDefaults();

    int w, h;
    if (index < defaults->numScreenSize())
    {
        const SimulatorScreenSize &size = defaults->getScreenSize(index);
        w = size.width;
        h = size.height;

        if (IsDlgButtonChecked(m_hwndDialog, IDC_RADIO_LANDSCAPE) == BST_CHECKED)
        {
            int w2 = w;
            w = h;
            h = w2;
        }
    }
    else
    {
        w = -1; h = -1;
    }

    if (w > 0)
    {
        char buff[32];
        sprintf_s(buff, "%d", w);
        SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH, buff);
        sprintf_s(buff, "%d", h);
        SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT, buff);

        Edit_Enable(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH), FALSE);
        Edit_Enable(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT), FALSE);
    }
    else
    {
        Edit_Enable(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH), TRUE);
        Edit_Enable(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT), TRUE);
        SetFocus(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH));
    }
}
コード例 #3
0
ファイル: SimulatorWin.cpp プロジェクト: hugohuang1111/Bird
void SimulatorWin::setupUI()
{
    auto menuBar = player::PlayerProtocol::getInstance()->getMenuService();

    // FILE
    menuBar->addItem("FILE_MENU", tr("File"));
    menuBar->addItem("EXIT_MENU", tr("Exit"), "FILE_MENU");

    // VIEW
    menuBar->addItem("VIEW_MENU", tr("View"));
    SimulatorConfig *config = SimulatorConfig::getInstance();
    int current = config->checkScreenSize(_project.getFrameSize());
    for (int i = 0; i < config->getScreenSizeCount(); i++)
    {
        SimulatorScreenSize size = config->getScreenSize(i);
        std::stringstream menuId;
        menuId << "VIEWSIZE_ITEM_MENU_" << i;
        auto menuItem = menuBar->addItem(menuId.str(), size.title.c_str(), "VIEW_MENU");

        if (i == current)
        {
            menuItem->setChecked(true);
        }
    }

    menuBar->addItem("DIRECTION_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("DIRECTION_PORTRAIT_MENU", tr("Portrait"), "VIEW_MENU")
        ->setChecked(_project.isPortraitFrame());
    menuBar->addItem("DIRECTION_LANDSCAPE_MENU", tr("Landscape"), "VIEW_MENU")
        ->setChecked(_project.isLandscapeFrame());

    menuBar->addItem("VIEW_SCALE_MENU_SEP", "-", "VIEW_MENU");
    std::vector<player::PlayerMenuItem*> scaleMenuVector;
    auto scale100Menu = menuBar->addItem("VIEW_SCALE_MENU_100", tr("Zoom Out").append(" (100%)"), "VIEW_MENU");
    auto scale75Menu = menuBar->addItem("VIEW_SCALE_MENU_75", tr("Zoom Out").append(" (75%)"), "VIEW_MENU");
    auto scale50Menu = menuBar->addItem("VIEW_SCALE_MENU_50", tr("Zoom Out").append(" (50%)"), "VIEW_MENU");
    auto scale25Menu = menuBar->addItem("VIEW_SCALE_MENU_25", tr("Zoom Out").append(" (25%)"), "VIEW_MENU");
    int frameScale = int(_project.getFrameScale() * 100);
    if (frameScale == 100)
    {
        scale100Menu->setChecked(true);
    }
    else if (frameScale == 75)
    {
        scale75Menu->setChecked(true);
    }
    else if (frameScale == 50)
    {
        scale50Menu->setChecked(true);
    }
    else if (frameScale == 25)
    {
        scale25Menu->setChecked(true);
    }
    else
    {
        scale100Menu->setChecked(true);
    }

    scaleMenuVector.push_back(scale100Menu);
    scaleMenuVector.push_back(scale75Menu);
    scaleMenuVector.push_back(scale50Menu);
    scaleMenuVector.push_back(scale25Menu);

    menuBar->addItem("REFRESH_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("REFRESH_MENU", tr("Refresh"), "VIEW_MENU");

    HWND &hwnd = _hwnd;
    ProjectConfig &project = _project;
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    dispatcher->addEventListenerWithFixedPriority(EventListenerCustom::create("APP.EVENT", [&project, &hwnd, scaleMenuVector](EventCustom* event){
        auto menuEvent = dynamic_cast<AppEvent*>(event);
        if (menuEvent)
        {
            rapidjson::Document dArgParse;
            dArgParse.Parse<0>(menuEvent->getDataString().c_str());
            if (dArgParse.HasMember("name"))
            {
                string strcmd = dArgParse["name"].GetString();

                if (strcmd == "menuClicked")
                {
                    player::PlayerMenuItem *menuItem = static_cast<player::PlayerMenuItem*>(menuEvent->getUserData());
                    if (menuItem)
                    {
                        if (menuItem->isChecked())
                        {
                            return;
                        }

                        string data = dArgParse["data"].GetString();
                        auto player = player::PlayerProtocol::getInstance();

                        if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
                        {
                            player->quit();
                        }
                        else if (data == "REFRESH_MENU")
                        {
                            player->relaunch();
                        }
                        else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEW_SCALE_MENU_"));
                            float scale = atof(tmp.c_str()) / 100.0f;
                            project.setFrameScale(scale);

                            auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView());
                            glview->setFrameZoomFactor(scale);

                            // update scale menu state
                            for (auto &it : scaleMenuVector)
                            {
                                it->setChecked(false);
                            }
                            menuItem->setChecked(true);

                            // update window size
                            RECT rect;
                            GetWindowRect(hwnd, &rect);
                            MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
                        
                            // fix: can not update window on some windows system 
                            ::SendMessage(hwnd, WM_MOVE, NULL, NULL);
                        }
                        else if (data.find("VIEWSIZE_ITEM_MENU_") == 0) // begin with VIEWSIZE_ITEM_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEWSIZE_ITEM_MENU_"));
                            int index = atoi(tmp.c_str());
                            SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);

                            if (project.isLandscapeFrame())
                            {
                                std::swap(size.width, size.height);
                            }

                            project.setFrameSize(cocos2d::Size(size.width, size.height));
                            project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY()));
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_PORTRAIT_MENU")
                        {
                            project.changeFrameOrientationToPortait();
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_LANDSCAPE_MENU")
                        {
                            project.changeFrameOrientationToLandscape();
                            player->openProjectWithProjectConfig(project);
                        }
                    }
                }
            }
        }
    }), 1);

    AppDelegate *app = _app;
    auto listener = EventListenerCustom::create(kAppEventDropName, [&project, app](EventCustom* event)
    {
        AppEvent *dropEvent = dynamic_cast<AppEvent*>(event);
        if (dropEvent)
        {
            string dirPath = dropEvent->getDataString() + "/";
            string configFilePath = dirPath + CONFIG_FILE;

            if (FileUtils::getInstance()->isDirectoryExist(dirPath) &&
                FileUtils::getInstance()->isFileExist(configFilePath))
            {
                // parse config.json
                ConfigParser::getInstance()->readConfig(configFilePath);

                project.setProjectDir(dirPath);
                project.setScriptFile(ConfigParser::getInstance()->getEntryFile());
                project.setWritablePath(dirPath);

                app->setProjectConfig(project);
                app->reopenProject();
            }
        }
    });
    dispatcher->addEventListenerWithFixedPriority(listener, 1);
}
コード例 #4
0
bool ProjectConfigDialog::checkConfig(void)
{
    bool isOK = false;
    char buff[MAX_PATH + 1] = {0};

    do
    {
        // check project dir and script file
        GetDlgItemTextA(m_hwndDialog, IDC_EDIT_PROJECT_DIR, buff, MAX_PATH);
        m_project.setProjectDir(buff);
        GetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCRIPT_FILE, buff, MAX_PATH);
        m_project.setScriptFile(buff);

        if (!DirectoryExists(m_project.getProjectDir().c_str()))
        {
            MessageBox(m_hwndDialog, L"Invalid Project Directory, please check it", L"Error", MB_OK);
            SetFocus(GetDlgItem(m_hwndDialog, IDC_EDIT_PROJECT_DIR));
            break;
        }

        if (!FileExists(m_project.getScriptFilePath().c_str()))
        {
            MessageBox(m_hwndDialog, L"Invalid Script File, please check it", L"Error", MB_OK);
            SetFocus(GetDlgItem(m_hwndDialog, IDC_EDIT_SCRIPT_FILE));
            break;
        }

        // check screen size
        HWND list = GetDlgItem(m_hwndDialog, IDC_COMBO_SCREEN_SIZE);
        int index = ComboBox_GetCurSel(list);
        SimulatorConfig *defaults = SimulatorConfig::sharedDefaults();

        int w, h;
        if (index < defaults->numScreenSize())
        {
            const SimulatorScreenSize &size = defaults->getScreenSize(index);
            w = size.width;
            h = size.height;

            if (IsDlgButtonChecked(m_hwndDialog, IDC_RADIO_LANDSCAPE) == BST_CHECKED)
            {
                int w2 = w;
                w = h;
                h = w2;
            }
        }
        else
        {
            GetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH, buff, MAX_PATH);
            w = atoi(buff);
            GetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT, buff, MAX_PATH);
            h = atoi(buff);

            if (w <= 0)
            {

                MessageBox(m_hwndDialog, L"Invalid Screen Width, please check it", L"Error", MB_OK);
                SetFocus(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH));
                break;
            }
            else if (h <= 0)
            {
                MessageBox(m_hwndDialog, L"Invalid Screen Height, please check it", L"Error", MB_OK);
                SetFocus(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT));
                break;
            }
        }

        // ok
        m_project.setFrameSize(CCSize(w, h));
        m_project.setShowConsole(IsDlgButtonChecked(m_hwndDialog, IDC_CHECK_SHOW_DEBUG_CONSOLE) == TRUE);
        isOK = true;
    } while (false);

    return isOK;
}
コード例 #5
0
void ProjectConfigDialog::onInitDialog(HWND hwndDialog)
{
    SimulatorConfig *defaults = SimulatorConfig::sharedDefaults();
    m_hwndDialog = hwndDialog;
    HWND list = GetDlgItem(m_hwndDialog, IDC_COMBO_SCREEN_SIZE);

    updateProjectDir();
    updateScriptFile();
    updatePackagePath();

    BOOL isLandscape = FALSE;
    int currentSizeIndex = defaults->checkScreenSize(m_project.getFrameSize());
    if (currentSizeIndex < 0)
    {
        currentSizeIndex = 0;
    }
    else
    {
        isLandscape = m_project.isLandscapeFrame();
    }

    for (int i = 0; i < defaults->numScreenSize(); ++i)
    {
        const SimulatorScreenSize &size = defaults->getScreenSize(i);
        wstring title;
        title.assign(size.title.begin(), size.title.end());
        ComboBox_AddString(list, title.c_str());

        if (i == currentSizeIndex)
        {
            char buff[32];
            sprintf_s(buff, "%d", isLandscape ? size.height : size.width);
            SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH, buff);
            sprintf_s(buff, "%d", isLandscape ? size.width : size.height);
            SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT, buff);
        }
    }
    ComboBox_AddString(list, L"Custom Size");
    ComboBox_SetCurSel(list, currentSizeIndex);

    Edit_LimitText(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH), 4);
    Edit_LimitText(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT), 4);

    HWND direction = GetDlgItem(m_hwndDialog, IDC_RADIO_PORTRAIT);
    CheckRadioButton(m_hwndDialog, IDC_RADIO_PORTRAIT, IDC_RADIO_LANDSCAPE, isLandscape ? IDC_RADIO_LANDSCAPE : IDC_RADIO_PORTRAIT);

    Button_SetCheck(GetDlgItem(m_hwndDialog, IDC_CHECK_SHOW_DEBUG_CONSOLE), m_project.isShowConsole());

    // set dialog caption, button caption
    SetWindowTextA(m_hwndDialog, m_dialogCaption.c_str());
    SetDlgItemTextA(m_hwndDialog, IDOK, m_buttonCaption.c_str());
    
    // center a dialog box within its owner window
    RECT rc, rcOwner, rcDlg;
    GetWindowRect(m_hwnd, &rcOwner); 
    GetWindowRect(m_hwndDialog, &rcDlg); 
    CopyRect(&rc, &rcOwner); 

    OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 
    OffsetRect(&rc, -rc.left, -rc.top); 
    OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 

    SetWindowPos(m_hwndDialog,
                 HWND_TOP,
                 rcOwner.left + (rc.right / 2),
                 rcOwner.top + (rc.bottom / 2),
                 0, 0,          // Ignores size arguments. 
                 SWP_NOSIZE);
}