void GuiElementList::selectElement(GuiElement* element, bool skipredraw) { GuiElement* backupParent = parent; // deselect all elements apart from the last selected element GuiNode *tmphead = children.head(); while (tmphead != NULL) { GuiElement* element = (GuiElement*)tmphead->element(); // the callback wants to go somewhere else, or otherwise doesn't want a redraw. // we are going to cheat here and tell this widget it has no parent, set the flags, and then restore the parent // TODO maybe bring back those nodraw options to the setters if (skipredraw) parent = NULL; if (element != selectedElement) element->pressed(false); else { element->pressed(true); } parent = backupParent; if (tmphead->next() == NULL) break; tmphead = tmphead->next(); } }
bool GuiFilesystemList::mouseMove(int mx, int my) { GuiElement *element = getElementAt((int)(mx-x), (int)(my-y)); if (element != NULL && element != background) { // Call mouseExit, if we're leaving if (element != highlightedElement && highlightedElement != NULL) { highlightedElement->mouseIn = false; if (highlightedElement->onMouseExit != NULL) { highlightedElement->onMouseExit(); } } // We're now in a new element highlightedElement = element; // Call mouseEnter, if we haven't yet. if (!element->mouseIn) { element->mouseIn = true; if (element->onMouseEnter != NULL) { element->onMouseEnter(); } } } return true; }
bool GuiScroll::OnMouseButtonEvent(const MouseButtonEvent& mbe) { Assert(m_children.size() >= 1); GuiElement* child = m_children[0]; if (mbe.button == AMJU_BUTTON_MOUSE_LEFT) { leftDrag = mbe.isDown; } return child->OnMouseButtonEvent(mbe); }
bool GuiScroll::OnCursorEvent(const CursorEvent& ce) { Assert(m_children.size() >= 1); GuiElement* child = m_children[0]; if (leftDrag) { OnScrollVelEvent(Vec2f(ce.dx * 10.0f, ce.dy * 10.0f)); // TODO TEMP TEST x/y scroll flags } return child->OnCursorEvent(ce); }
void Master::update(Tuple<ELocation, ELocation, GenericTask> message) { if (message.first != this->local && message.second == this->local) { if (message.third.getTask() == ETask::SWITCH_SCREEN && message.third.hasParameters()) { EWindows value = this->getScreen(message.third.getParameters()[0]); if (value != EWindows::NONE) this->switchScreen(value); } else if (message.third.getTask() == ETask::ACTIVE_MUSIC) { SoundMixer::reverseMute(); GuiElement *elem = nullptr; if (message.first == ELocation::GAME_GUI) { elem = this->windows[EWindows::WINDOW_HOME]->getUserInterface()->getElementById("buttonMusicHome"); } else if (message.first == ELocation::HOME_GUI) { elem = this->windows[EWindows::WINDOW_GAME]->getUserInterface()->getElementById("buttonMusicGame"); } if (elem != nullptr) { elem->doTask(GenericTask(ETask::SWITCH_ACTIVATED)); } } else if (message.third.getTask() == ETask::SWITCH_MUSIC) { SoundMixer::launchNext(); } else if (message.third.getTask() == ETask::CHANGE_IA_METHOD && message.third.hasParameters()) { std::vector<std::string> param = message.third.getParameters(); if (param.size() > 1) { if (param[0] == "A1") { RuleManager::p1IAMethod = param[1]; } else if (param[0] == "A2") { RuleManager::p2IAMethod = param[1]; } } } } }
void GSMain::OnActive() { GameState::OnActive(); TheEventPoller::Instance()->AddListener(m_gui); TheLurker::Instance()->SetAsListener(true); TheSoundManager::Instance()->PlaySong("sound/apz2.it"); SceneNode::SetGlobalShowAABB(s_showAABBs); TheCollisionManager::Instance()->GetCollisionDetector()->Clear(); // Clear Text scene graph GetTextSceneGraph()->Clear(); // Set clear colour for game, TODO depends on skybox //AmjuGL::SetClearColour(Colour(0.0f, 0.0f, 1.0f, 1.0f)); m_exitState = NOT_EXITED; m_exitTimer = 0; GuiElement* splitLine = m_gui->GetElementByName("split-screen-line"); Assert(splitLine); splitLine->SetVisible(TheScores::Instance()->GetNumPlayers() == 2); m_pauseButton = (GuiButton*)m_gui->GetElementByName("pause-button"); Assert(m_pauseButton); m_pauseButton->SetCommand(OnPause); m_pauseButton->SetIsCancelButton(true); m_pauseButton->SetShowIfFocus(true); AmjuGL::SetClearColour(m_clearColour); // When we are in the play state, we DO want to go to the paused state // if we are interrupted (e.g. answer phone) TheGame::Instance()->RegisterPauseState(TheGSPaused::Instance()); NetSendMarkSessionStart(); }
void Gui::sendEventToWidget(int16_t x, int16_t y, int8_t eventid) { // do collision detection GuiNode *tmphead = children.head(); if (tmphead != NULL) { // get the last element while (tmphead != NULL) { GuiElement* element = (GuiElement*)tmphead->element(); GuiElement *found = element->pointInWidget(x, y); if (found != NULL) { found->callbackProcess(found, eventid); return; } if (tmphead->next() == NULL) break; tmphead = tmphead->next(); } } }
ServerCreationScreen::ServerCreationScreen() { assert(game_server); new GuiOverlay(this, "", colorConfig.background); (new GuiOverlay(this, "", sf::Color::White))->setTextureTiled("gui/BackgroundCrosses"); // Set defaults from preferences. gameGlobalInfo->player_warp_jump_drive_setting = EPlayerWarpJumpDrive(PreferencesManager::get("server_config_warp_jump_drive_setting", "0").toInt()); gameGlobalInfo->long_range_radar_range = PreferencesManager::get("server_config_long_range_radar_range", "30000").toInt(); gameGlobalInfo->scanning_complexity = EScanningComplexity(PreferencesManager::get("server_config_scanning_complexity", "2").toInt()); gameGlobalInfo->use_beam_shield_frequencies = PreferencesManager::get("server_config_use_beam_shield_frequencies", "1").toInt(); gameGlobalInfo->use_system_damage = PreferencesManager::get("server_config_use_system_damage", "1").toInt(); gameGlobalInfo->allow_main_screen_tactical_radar = PreferencesManager::get("server_config_allow_main_screen_tactical_radar", "1").toInt(); gameGlobalInfo->allow_main_screen_long_range_radar = PreferencesManager::get("server_config_allow_main_screen_long_range_radar", "1").toInt(); // Create a two-column layout. GuiElement* container = new GuiAutoLayout(this, "", GuiAutoLayout::ELayoutMode::LayoutVerticalColumns); container->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); GuiElement* left_container = new GuiElement(container, ""); GuiElement* right_container = new GuiElement(container, ""); GuiElement* left_panel = new GuiAutoLayout(left_container, "", GuiAutoLayout::LayoutVerticalTopToBottom); left_panel->setPosition(0, 20, ATopCenter)->setSize(550, GuiElement::GuiSizeMax); GuiElement* right_panel = new GuiAutoLayout(right_container, "", GuiAutoLayout::LayoutVerticalTopToBottom); right_panel->setPosition(0, 20, ATopCenter)->setSize(550, GuiElement::GuiSizeMax); // Left column contents. // General section. (new GuiLabel(left_panel, "GENERAL_LABEL", "Server configuration", 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50); // Server name row. GuiElement* row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "NAME_LABEL", "Server name: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiTextEntry(row, "SERVER_NAME", game_server->getServerName()))->callback([](string text){game_server->setServerName(text);})->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Server password row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "PASSWORD_LABEL", "Server password: "******"SERVER_PASSWORD", ""))->callback([](string text){game_server->setPassword(text);})->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Server IP row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "IP_LABEL", "Server IP: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiLabel(row, "IP", sf::IpAddress::getLocalAddress().toString(), 30))->setAlignment(ACenterLeft)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // LAN/Internet row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "LAN_INTERNET_LABEL", "Server visibility: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiSelector(row, "LAN_INTERNET_SELECT", [](int index, string value) { if (index == 1) game_server->registerOnMasterServer("http://daid.eu/ee/register.php"); else game_server->stopMasterServerRegistry(); }))->setOptions({"LAN only", "Internet"})->setSelectionIndex(0)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Player Ships section. (new GuiLabel(left_panel, "PLAYER_SHIP_LABEL", "Player ship options", 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50); // Warp/Jump drive row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "WARP_JUMP_LABEL", "Warp/Jump: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiSelector(row, "WARP_JUMP_SELECT", [](int index, string value) { gameGlobalInfo->player_warp_jump_drive_setting = EPlayerWarpJumpDrive(index); }))->setOptions({"Ship default", "Warp drive", "Jump drive", "Both", "Neither"})->setSelectionIndex((int)gameGlobalInfo->player_warp_jump_drive_setting)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Radar range limit row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "RADAR_LABEL", "Radar range: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiSelector(row, "RADAR_SELECT", [](int index, string value) { gameGlobalInfo->long_range_radar_range = index * 5000 + 10000; }))->setOptions({"10U", "15U", "20U", "25U", "30U", "35U", "40U", "45U", "50U"})->setSelectionIndex((gameGlobalInfo->long_range_radar_range - 10000.0) / 5000.0)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Main screen section. (new GuiLabel(left_panel, "MAIN_SCREEN_LABEL", "Main screen options", 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50); // Radar row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiToggleButton(row, "MAIN_TACTICAL_TOGGLE", "Tactical radar", [](bool value) { gameGlobalInfo->allow_main_screen_tactical_radar = value == 1; }))->setValue(gameGlobalInfo->allow_main_screen_tactical_radar)->setSize(275, GuiElement::GuiSizeMax)->setPosition(0, 0, ACenterLeft); (new GuiToggleButton(row, "MAIN_LONG_RANGE_TOGGLE", "Long range radar", [](bool value) { gameGlobalInfo->allow_main_screen_long_range_radar = value == 1; }))->setValue(gameGlobalInfo->allow_main_screen_long_range_radar)->setSize(275, GuiElement::GuiSizeMax)->setPosition(0, 0, ACenterRight); // Game rules section. (new GuiLabel(left_panel, "GAME_RULES_LABEL", "Game rules", 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50); // Science scan complexity selector. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "GAME_SCANNING_COMPLEXITY_LABEL", "Scan complexity: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiSelector(row, "GAME_SCANNING_COMPLEXITY", [](int index, string value) { gameGlobalInfo->scanning_complexity = EScanningComplexity(index); }))->setOptions({"None (delay)", "Simple", "Normal", "Advanced"})->setSelectionIndex((int)gameGlobalInfo->scanning_complexity)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Frequency and system damage row. row = new GuiAutoLayout(left_panel, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiToggleButton(row, "GAME_FREQUENCIES_TOGGLE", "Beam/shield frequencies", [](bool value) { gameGlobalInfo->use_beam_shield_frequencies = value == 1; }))->setValue(gameGlobalInfo->use_beam_shield_frequencies)->setSize(275, GuiElement::GuiSizeMax)->setPosition(0, 0, ACenterLeft); (new GuiToggleButton(row, "GAME_SYS_DAMAGE_TOGGLE", "Per-system damage", [](bool value) { gameGlobalInfo->use_system_damage = value == 1; }))->setValue(gameGlobalInfo->use_system_damage)->setSize(275, GuiElement::GuiSizeMax)->setPosition(0, 0, ACenterRight); // Right column contents. // Scenario section. (new GuiLabel(right_panel, "SCENARIO_LABEL", "Scenario", 30))->addBackground()->setSize(GuiElement::GuiSizeMax, 50); // List each scenario derived from scenario_*.lua files in Resources. GuiListbox* scenario_list = new GuiListbox(right_panel, "SCENARIO_LIST", [this](int index, string value) { selectScenario(value); }); scenario_list->setSize(GuiElement::GuiSizeMax, 300); // Show the scenario description text. GuiPanel* panel = new GuiPanel(right_panel, "SCENARIO_DESCRIPTION_BOX"); panel->setSize(GuiElement::GuiSizeMax, 200); scenario_description = new GuiScrollText(panel, "SCENARIO_DESCRIPTION", ""); scenario_description->setTextSize(24)->setMargins(15)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // If the scenario has variations, show and select from them. variation_container = new GuiAutoLayout(right_panel, "VARIATION_CONTAINER", GuiAutoLayout::LayoutVerticalTopToBottom); variation_container->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); row = new GuiAutoLayout(variation_container, "", GuiAutoLayout::LayoutHorizontalLeftToRight); row->setSize(GuiElement::GuiSizeMax, 50); (new GuiLabel(row, "VARIATION_LABEL", "Variation: ", 30))->setAlignment(ACenterRight)->setSize(250, GuiElement::GuiSizeMax); variation_selection = new GuiSelector(row, "VARIATION_SELECT", [this](int index, string value) { gameGlobalInfo->variation = variation_names_list.at(index); variation_description->setText(variation_descriptions_list.at(index)); }); variation_selection->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); panel = new GuiPanel(variation_container, "VARIATION_DESCRIPTION_BOX"); panel->setSize(GuiElement::GuiSizeMax, 150); variation_description = new GuiScrollText(panel, "VARIATION_DESCRIPTION", ""); variation_description->setTextSize(24)->setMargins(15)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); // Buttons beneath the columns. // Close server button. (new GuiButton(left_container, "CLOSE_SERVER", "Close server", [this]() { destroy(); disconnectFromServer(); returnToMainMenu(); }))->setPosition(0, -50, ABottomCenter)->setSize(300, 50); // Start server button. (new GuiButton(right_container, "START_SERVER", "Start scenario", [this]() { startScenario(); }))->setPosition(0, -50, ABottomCenter)->setSize(300, 50); // Fetch and sort all Lua files starting with "scenario_". std::vector<string> scenario_filenames = findResources("scenario_*.lua"); std::sort(scenario_filenames.begin(), scenario_filenames.end()); // For each scenario file, extract its name, then add it to the list. for(string filename : scenario_filenames) { ScenarioInfo info(filename); scenario_list->addEntry(info.name, filename); } // Select the first scenario in the list by default. scenario_list->setSelectionIndex(0); selectScenario(scenario_list->getSelectionValue()); gameGlobalInfo->reset(); }
void Hud::Draw() { float dt = TheTimer::Instance()->GetDt(); static const char* SCORE_NAME[3] = { "p1-score-text", "p2-score-text", "hi-score-text" }; static const float origSize[3] = { dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[0]))->GetFontSize(), dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[1]))->GetFontSize(), dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[2]))->GetFontSize() }; for (int i = 0; i < 3; i++) { if (s_scoreExpandTimer[i] > 0) { s_scoreExpandTimer[i] -= dt; if (s_scoreExpandTimer[i] < 0) { s_scoreExpandTimer[i] = 0; } GuiText* text = dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[i])); Assert(text); static const float EXPAND_SCALE = ROConfig()->GetFloat("hud-expand-scale"); text->SetFontSize(origSize[i] * (s_scoreExpandTimer[i] * EXPAND_SCALE + 1.0f)); std::string s = text->GetText(); text->SetText(""); text->SetText(s); // force tri list rebuild } } if (s_lifeTimer > 0) { s_lifeTimer -= dt; if (s_lifeTimer < 0) { s_lifeTimer = 0; } static const char* GUI_NAME[4] = { "heart-img1", "p1-lives-text", "heart-img2", "p2-lives-text" }; float t = s_lifeTimer * 10; bool vis = (((int)t % 2) == 0); for (int i = 0; i < 4; i++) { GuiElement* elem = m_gui->GetElementByName(GUI_NAME[i]); Assert(elem); elem->SetVisible(vis); } } m_gui->Draw(); }
void Hud::SetNumPlayers(int num) { GuiElement* elem = m_gui->GetElementByName("p2-comp"); Assert(elem); elem->SetVisible(num == 2); }
void List::DrawSelf() { const float opacity = Opacity(); font->Begin(); float hf = font->GetSize() / ScaleFactor(); font->SetTextColor(1,1,0.4f,opacity); int nCurIndex = 0; // The item we're on int nDrawOffset = 0; // The offset to the first draw item GuiElement b; b.SetPos(pos[0] + borderSpacing, pos[1] + size[1] - borderSpacing - itemHeight); b.SetSize(size[0] - 2.0f * borderSpacing - ((scrollbar.GetSize()[0] < 0) ? 0 : (itemHeight + itemSpacing)), itemHeight); // Get list started up here std::vector<std::string>::iterator ii = filteredItems->begin(); // Skip to current selection - 3; ie: scroll UpdateTopIndex(); while (nCurIndex < topIndex) { ++ii; nCurIndex++; } const int numDisplay = NumDisplay(); font->SetTextColor(1.0f, 1.0f, 1.0f, opacity); //default font->SetOutlineColor(0.0f, 0.0f, 0.0f, opacity); glLineWidth(1.0f); float sbX = b.GetPos()[0]; float sbY1 = b.GetPos()[1] + (itemHeight + itemSpacing); for (/*ii = items.begin()*/; ii != filteredItems->end() && nDrawOffset < numDisplay; ++ii) { glColor4f(1,1,1,opacity/4.f); b.DrawBox(GL_LINE_LOOP); if (nCurIndex == place) { glBlendFunc(GL_ONE, GL_ONE); // additive blending glColor4f(0.2f,0,0,opacity); b.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,0,0,opacity/2.f); glLineWidth(1.49f); b.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } else if (b.MouseOver(mx, my)) { glBlendFunc(GL_ONE, GL_ONE); // additive blending glColor4f(0,0,0.2f,opacity); b.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,opacity/2.f); glLineWidth(1.49f); b.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } font->glPrint(pos[0]+borderSpacing + 0.002f, b.GetMidY() - hf * 0.15f, itemFontScale, FONT_BASELINE | FONT_SHADOW | FONT_SCALE | FONT_NORM, *ii); // Up our index's nCurIndex++; nDrawOffset++; b.Move(0.0, - (itemHeight + itemSpacing)); } //scrollbar if(nDrawOffset < filteredItems->size()) { float sbY2 = b.GetPos()[1] + (itemHeight + itemSpacing); float sbHeight = sbY1 - sbY2; float sbSize = ((float)nDrawOffset / (float)filteredItems->size()) * sbHeight; if(activeScrollbar) { topIndex = std::max(0, std::min((int)(((float)filteredItems->size() * ((sbY1 - sbSize) - (my - std::min(scrollbarGrabPos, sbSize))) / sbHeight) + 0.5f), (int)filteredItems->size() - numDisplay)); } scrollbar.SetPos(sbX + (size[0] - 2.0f * borderSpacing) - (itemHeight + itemSpacing), sbY1 - sbSize - ((float)topIndex / (float)filteredItems->size()) * sbHeight); scrollbar.SetSize((itemHeight + itemSpacing) , sbSize); b.SetPos(scrollbar.GetPos()[0], sbY2); b.SetSize(itemHeight + itemSpacing, sbHeight); glColor4f(1,1,1,opacity/4.f); b.DrawBox(GL_LINE_LOOP); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.8f,0.8f,0.8f,opacity); scrollbar.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,opacity/2.f); glLineWidth(1.49f); scrollbar.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } else scrollbar.SetSize(-1,-1); /************** * End insert * **************/ font->End(); }
bool List::MouseUpdate(int x, int y) { int nCurIndex = 0; // The item we're on int nDrawOffset = 0; // The offset to the first draw item GuiElement b; b.SetPos(pos[0] + borderSpacing, pos[1] + size[1] - borderSpacing - itemHeight); b.SetSize(size[0] - 2.0f * borderSpacing - ((scrollbar.GetSize()[0] < 0) ? 0 : (itemHeight + itemSpacing)), itemHeight); // Get list started up here std::vector<std::string>::iterator ii = filteredItems->begin(); UpdateTopIndex(); while (nCurIndex < topIndex) { ++ii; ++nCurIndex; } const int numDisplay = NumDisplay(); float sbX = b.GetPos()[0]; float sbY1 = b.GetPos()[1] + (itemHeight + itemSpacing); for (/*ii = items.begin()*/; ii != filteredItems->end() && nDrawOffset < numDisplay; ++ii) { if (b.MouseOver(mx, my)) { if (nCurIndex == place && clickedTime + 250 > SDL_GetTicks()) { FinishSelection(); } clickedTime = SDL_GetTicks(); place = nCurIndex; return true; } // Up our index's nCurIndex++; nDrawOffset++; b.Move(0.0, - (itemHeight + itemSpacing)); } if(nDrawOffset < filteredItems->size()) { if (scrollbar.MouseOver(mx, my)) { activeScrollbar = true; scrollbarGrabPos = my - scrollbar.GetPos()[1]; } else { float sbY2 = b.GetPos()[1] + (itemHeight + itemSpacing); float sbHeight = sbY1 - sbY2; b.SetPos(sbX + (size[0] - 2.0f * borderSpacing) - (itemHeight + itemSpacing), sbY2); b.SetSize(itemHeight + itemSpacing, sbHeight); if (b.MouseOver(mx, my)) { if(my > scrollbar.GetPos()[1] + scrollbar.GetSize()[1]) topIndex = std::max(0, std::min(topIndex - NumDisplay(), (int)filteredItems->size() - NumDisplay())); else if(my < scrollbar.GetPos()[1]) topIndex = std::max(0, std::min(topIndex + NumDisplay(), (int)filteredItems->size() - NumDisplay())); } } } return false; }
void GuiScroll::Draw() { Assert(m_children.size() >= 1); GuiElement* child = m_children[0]; // Update not called. TODO float dt = TheTimer::Instance()->GetDt(); static const float DECEL = 0.5f; // TODO m_scrollVel *= std::max(0.0f, (1.0f - DECEL * dt)); m_scrollPos += m_scrollVel * dt; // x-axis float chSizeX = child->GetSize().x; float sizeX = GetSize().x; float maxx = std::max(0.0f, chSizeX - sizeX); // Bounce or stop on end reached if (m_scrollPos.x < -maxx) { m_scrollPos.x = -maxx; #ifdef BOUNCE m_scrollVel.x = -0.25f * m_scrollVel.x; #else m_scrollVel.x = 0; #endif } // depends on size of child and how much space there is to display it if (m_scrollPos.x > 0) { m_scrollPos.x = 0; #ifdef BOUNCE m_scrollVel.x = -0.25f * m_scrollVel.x; #else m_scrollVel.x = 0; #endif } // Y axis if (m_scrollPos.y < 0) { std::cout << "Scroll: hit m_scrollPos.y = 0, stopping.\n"; m_scrollPos.y = 0; #ifdef BOUNCE m_scrollVel.y = -0.25f * m_scrollVel.y; #else m_scrollVel.y = 0; #endif } float maxy = std::max(0.0f, child->GetSize().y - GetSize().y); // depends on size of child and how much space there is to display it //std::cout << "Scroll: m_scrollPos.y: " << m_scrollPos.y << " Size.y: " << GetSize().y << " Child->Size.y: " << child->GetSize().y << " maxy=" << maxy << "\n"; if (m_scrollPos.y > maxy) { std::cout << "Hit maxy (" << maxy << "), stopping. My height: " << GetSize().y << " Child height: " << child->GetSize().y << "\n"; m_scrollPos.y = maxy; #ifdef BOUNCE m_scrollVel.y = -0.25f * m_scrollVel.y; #else m_scrollVel.y = 0; #endif } SetLocalPos(m_scrollPos); // so combined pos for child is updated GuiComposite::Draw(); //child->Draw(); }
//-------------------------------------------------------------- MainWindow::MainWindow(){ ofAddListener(PdEvent::events, this, &MainWindow::onPdEvent); // this->setPosition(200, 200); // this->setSize(ofGetWidth() - 400, ofGetHeight() - 400); this->setPosition(0, 0); this->setSize(ofGetWidth(), ofGetHeight()); Button* btn; //-------top-bar------- GuiElement* topBar = new GuiElement("bar"); topBar->setPosition(0, 0); btn = new Button("settings", Button::TYPE_TOGGLE); btn->setPosition(this->width - btn->width, 0); topBar->addChild(btn); this->addChild(topBar); //-------top-bar------- //-------bottom-bar------- GuiElement* bottomBar = new GuiElement("bar"); btn = new Button("edit", Button::TYPE_TOGGLE); btn->setPosition((this->width - btn->width) / 2, 0); bottomBar->addChild(btn); btn = new Button("menu-tab", Button::TYPE_TOGGLE); btn->setPosition(0, 0); bottomBar->addChild(btn); btn = new Button("object-tab", Button::TYPE_TOGGLE); btn->setPosition(this->width - btn->width, 0); bottomBar->addChild(btn); bottomBar->setPosition(0, this->height - bottomBar->height); this->addChild(bottomBar); //-------bottom-bar------- //------- menu-tab------- SideTab* leftTab = new SideTab(SideTab::DOCK_SIDE_LEFT); leftTab->id = "menu-tab"; leftTab->setPosition(0, topBar->getBottom()); leftTab->setHeight(this->height - topBar->height - bottomBar->height); leftTab->expandedX = 0; vector<string> zoomBtns = { "zoom-in", "zoom-out", "grid" }; for (int i = 0; i < zoomBtns.size(); i++) { btn = new Button(zoomBtns[i]); btn->setPosition(0, btn->height * (i + 1)); leftTab->addChild(btn); } vector<string> buttons = { "trash", "undo", "paste", "copy" }; for (int i = 0; i < buttons.size(); i++) { btn = new Button(buttons[i]); btn->setPosition(0, leftTab->height - btn->height * (i + 2)); leftTab->addChild(btn); } // btn = new Button("grid", Button::TYPE_TOGGLE); // btn->setPosition(0, leftTab->height - btn->height * 7); // leftTab->addChild(btn); this->children.insert(this->children.begin(), leftTab); //------- menu-tab------- //------- object-tab------- SideTab* rightTab = new SideTab(SideTab::DOCK_SIDE_RIGHT); rightTab->id = "object-tab"; rightTab->setHeight(leftTab->height); // vector<string> sections = { "+-", "UI", "AB" }; vector<string> sections = { "+-" }; for (char letter = 'Z'; letter >= 'A'; --letter){ sections.insert(sections.begin() + 1, string(1, letter)); } ListScroller* scroller = new ListScroller(); scroller->setPosition(0, 0); scroller->setHeight(leftTab->height); scroller->backgroundColor.set(130); scroller->setContent(sections, true); scroller->setContent(PdGui::instance().getNodeNames(), false); ofLogVerbose() << "temp"; ofLogVerbose() << scroller->width; ofLogVerbose() << scroller->height; IndexScroller* index = new IndexScroller(); index->x = rightTab->width; index->setPosition(scroller->width, 0); index->setHeight(rightTab->height); index->setContent(sections); rightTab->addChild(scroller); rightTab->addChild(index); rightTab->setPosition(this->width - rightTab->width, topBar->getBottom()); rightTab->expandedX = this->width - rightTab->width + 1; this->children.insert(this->children.begin(), rightTab); //------- object-tab------- //-------canvas------- Canvas* cnv = new Canvas(this->width, this->height - topBar->height - bottomBar->height); cnv->setPosition(leftTab->collapsedX + leftTab->width, topBar->getBottom()); this->children.insert(this->children.begin(), cnv); // //-------canvas------- cnv->set(PdGui::instance().getCanvases()[0]); }
bool GuiKeyboard::Load(File* file) { if (!GuiElement::Load(file)) { return false; } // Get filename for KB layout. This string can be localised, giving language-specific keyboards. std::string filename; // = "gui-kb.txt"; // TODO global KB choice, depending on Language setting if (!file->GetLocalisedString(&filename)) { file->ReportError("Expected keyboard file name"); return false; } File f; if (!f.OpenRead(filename)) { return false; } if (!GuiComposite::Load(&f)) { return false; } GuiElement* elem = 0; // Set command on each key. // Printable characters: try to find a key for each printable character. // TODO For localisation, this string must be loaded from string table. const std::string CHARS = "!@£$%^&*()_-+={[}]:;\"'|\\~`<,>.?/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#"; for (unsigned int i = 0; i < CHARS.size(); i++) { // We use the member function GetElementByName, which fails without asserting. // So chars not in this keyboard are just ignored. elem = GetElementByName(std::string(1, CHARS[i])); if (elem) { KeyEvent ke; // Printable char ke.keyType = AMJU_KEY_CHAR; ke.key = CHARS[i]; ke.modifier = AMJU_KEY_MOD_NONE; elem->SetCommand(new KbCommand(ke)); } } // Special keys - enter, space, mode, delete, shift. elem = GetElementByName("space"); if (elem) { KeyEvent ke; ke.keyType = AMJU_KEY_SPACE; elem->SetCommand(new KbCommand(ke)); } elem = GetElementByName("enter"); if (elem) { KeyEvent ke; ke.keyType = AMJU_KEY_ENTER; elem->SetCommand(new KbCommand(ke)); } elem = GetElementByName("del"); if (elem) { KeyEvent ke; ke.keyType = AMJU_KEY_BACKSPACE; elem->SetCommand(new KbCommand(ke)); } // TODO Shift, mode // Arrow keys etc ? GetChild(0)->SetVisible(true); for (int i = 1; i < GetNumChildren(); i++) { GetChild(i)->SetVisible(false); } return true; }