// Update loop. Gone trought once per frame. bool MenuScene::Update(float dt) { if (drawHelp) { if (uthInput.Keyboard.IsKeyDown(uth::Keyboard::Escape)) drawHelp = false; } else { bool click = uthInput.Common.Event() == uth::InputEvent::CLICK; static float sine = 0.f; sine += 6.f * dt; float wave = 0.22f * std::sinf(sine); jumpText.transform.SetScale(0.9f + std::abs(wave)); if (MouseOver(startButton) && click) { uthSceneM.GoToScene(1); } else if (MouseOver(helpButton) && click) { drawHelp = true; } else if (MouseOver(exitButton) && click) { return false; } } return true; // Update succeeded. }
bool List::HandleEventSelf(const SDL_Event& ev) { switch (ev.type) { case SDL_MOUSEBUTTONDOWN: { if (gui->MouseOverElement(GetRoot(), ev.motion.x, ev.motion.y)) { if(!hasFocus) { hasFocus = true; MouseMove(ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel, ev.motion.state); } } else { hasFocus = false; } if(MouseOver(ev.button.x, ev.button.y)) { if(hasFocus) { MousePress(ev.button.x, ev.button.y, ev.button.button); return true; } } break; } case SDL_MOUSEBUTTONUP: { if (!hasFocus) break; if (MouseOver(ev.button.x, ev.button.y) || activeScrollbar) { MouseRelease(ev.button.x, ev.button.y, ev.button.button); return true; } break; } case SDL_MOUSEMOTION: { if (!hasFocus) break; if (MouseOver(ev.button.x, ev.button.y) || activeScrollbar) { MouseMove(ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel, ev.motion.state); return true; } break; } case SDL_KEYDOWN: { if (!hasFocus) break; if(ev.key.keysym.sym == SDLK_ESCAPE) { hasFocus = false; break; } return KeyPressed(ev.key.keysym.sym, false); } } return false; }
bool Button::HandleEventSelf(const SDL_Event& ev) { switch (ev.type) { case SDL_MOUSEBUTTONDOWN: { if ((ev.button.button == SDL_BUTTON_LEFT) && MouseOver(ev.button.x, ev.button.y) && gui->MouseOverElement(GetRoot(), ev.motion.x, ev.motion.y)) { clicked = true; } break; } case SDL_MOUSEBUTTONUP: { if ((ev.button.button == SDL_BUTTON_LEFT) && MouseOver(ev.button.x, ev.button.y) && clicked) { if (!Clicked.empty()) { Clicked(); } else { LOG_L(L_WARNING, "Button %s clicked without callback", label.c_str()); } clicked = false; return true; } break; } case SDL_MOUSEMOTION: { if (MouseOver(ev.motion.x, ev.motion.y) && gui->MouseOverElement(GetRoot(), ev.motion.x, ev.motion.y)) { hovered = true; } else { hovered = false; clicked = false; } break; } } return false; }
bool Window::HandleEventSelf(const SDL_Event& ev) { switch (ev.type) { case SDL_MOUSEBUTTONDOWN: { if (MouseOver(ev.button.x, ev.button.y)) { float mouse[2] = {PixelToGlX(ev.button.x), PixelToGlY(ev.button.y)}; if (mouse[1] > pos[1]+size[1]-titleHeight) { dragPos[0] = mouse[0] - pos[0]; dragPos[1] = mouse[1] - pos[1]; dragging = true; return true; }; } break; } case SDL_MOUSEBUTTONUP: { if (dragging) { dragging = false; return true; } break; } case SDL_MOUSEMOTION: { if (dragging) { Move(PixelToGlX(ev.motion.xrel), PixelToGlY(ev.motion.yrel)-1); return true; } break; } case SDL_KEYDOWN: { if (ev.key.keysym.sym == SDLK_ESCAPE) { WantClose(); return true; } break; } } return false; }
GSGUI_BUTTON GSGUI_SWAPBUTTON::PlaceMenu(Vector2 v2Pos) { m_video->SetZBuffer(false); m_video->SetZWrite(false); const Vector2 size(m_current->sprite->GetBitmapSizeF()); GS_DWORD top, bottom; m_mouseOver = MouseOver(v2Pos, size); if (m_mouseOver) { top = m_style.focused_top; bottom = m_style.focused_bottom; } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; } if (m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT) { GSGUI_SWAPSPRITE_PTR_LIST::iterator iter = Find(m_current->fileName); if (++iter == m_sprites.end()) iter = m_sprites.begin(); m_current = *iter; } } m_video->DrawRectangle(v2Pos, size, top, top, bottom, bottom); DrawOutline(v2Pos, size); m_current->sprite->Draw(v2Pos); GSGUI_BUTTON r; r.text = m_current->fileName; r.active = true; r.onFocus = m_mouseOver; r.value.nValue = 0; r.visible = true; r.extText.clear(); return r; }
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject) { if (!MouseOver()) return; // Check if we've got competition at all if (pObject == NULL) { pObject = this; return; } // Or if it's closer if (GetBufferedZ() >= pObject->GetBufferedZ()) { pObject = this; return; } }
void CCheckBox::Update() { if (IsOn == true) { IsOff = false; } else if (IsOff == true) { IsOn = false; } if (MouseOver() == true) { if (IsClicked() == true && IsOff == true) { CurrentState = BOX_IS_ON; } else if (IsClicked() == true && IsOn == true) { CurrentState = BOX_NOT_ON; } else { CurrentState = MOUSE_OVER_BOX; } } else { CurrentState = BOX_NOT_ON; } int TempWidth = 0; int TempHeight = 0; SDL_QueryTexture(m_tCheckBox,NULL,NULL,&TempWidth,&TempHeight); m_Width = TempWidth / 3; m_Height = TempHeight; CheckBoxSprite.SetSourceRect(m_Width*CurrentState,0,m_Width,m_Height); }
int GSGUI_INT_INPUT::PlaceInput(Vector2 v2Pos) { int r = 0; m_video->SetZBuffer(false); m_video->SetZWrite(false); Vector2 v2Size(m_width, m_size), v2TextAdd(m_size/4.0f, 0.0f); m_mouseOver = MouseOver(v2Pos, v2Size); Color top, bottom, text; if (m_active) { top = m_style.active_top; bottom = m_style.active_bottom; text = m_style.active_text; if (!m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT || m_input->GetRightClickState() == GSKS_HIT) m_active = false; } if (m_input->GetKeyState(GSK_ENTER) == GSKS_HIT) m_active = false; } else { if (m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT) m_active = true; top = m_style.focused_top; bottom = m_style.focused_bottom; text = m_style.active_text; } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; text = m_style.inactive_text; } if (m_strInput.GetString() == GS_L("")) m_strInput.SetString(GS_L("0")); } m_video->DrawRectangle(v2Pos, Vector2(m_width, m_size), top, top, bottom, bottom); str_type::stringstream ss; ss << m_strInput.GetString(); if (ss.str().length() > 0) //-V807 { GS2D_SSCANF(ss.str().c_str(), GS_L("%i"), &r); if (m_active && m_input->GetWheelState() != 0.0f) { r += (int)m_input->GetWheelState()*m_scrollAdd; ss.str(GS_L("")); ss << r; m_strInput.SetString(ss.str()); } GS2D_SSCANF(ss.str().c_str(), GS_L("%i"), &r); if (m_clamp) { if (r > m_max) { r = m_max; ss.str(GS_L("")); ss << r; } else if (r < m_min) { r = m_min; ss.str(GS_L("")); ss << r; } m_strInput.SetString(ss.str()); } } if (m_active) { m_strInput.PlaceInput(v2Pos+v2TextAdd, GS_L("Verdana14_shadow.fnt"), m_nMaxChars, m_size, text, m_video, m_input); } else { m_strInput.Place(v2Pos+v2TextAdd, GS_L("Verdana14_shadow.fnt"), m_size, text, m_video); } if (m_active || m_mouseOver) DrawOutline(v2Pos, v2Size); return r; }
GSGUI_BUTTON GSGUI_BUTTONLIST::PlaceMenu(Vector2 v2Pos) { GSGUI_BUTTON r; if (!m_video) return r; m_video->SetZBuffer(false); m_video->SetZWrite(false); Vector2 v2TextAdd(m_size/4.0f, 0.0f), v2ButtonSize = Vector2(m_width, m_size); if (!m_buttons.empty()) { bool newSingleSet = false; int focus=-1; int t=0; GSGUI_BUTTON_ITERATOR iter; for (iter = m_buttons.begin(); iter != m_buttons.end(); ++iter) { if (!iter->visible) continue; Vector2 v2ButtonPos = Vector2(v2Pos.x, v2Pos.y+((float)t*m_size)); GS_DWORD top, bottom, text; iter->onFocus = MouseOver(v2ButtonPos, v2ButtonSize); if (iter->onFocus) { top = m_style.focused_top; bottom = m_style.focused_bottom; text = m_style.active_text; focus = t; if (m_input->GetLeftClickState() == GSKS_HIT) { if (m_unselect) iter->active = !(iter->active); else iter->active = true; if (m_singleSelect) { newSingleSet = true; m_single.text = iter->text; } r.text = iter->text; r.active = iter->active; } } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; text = m_style.inactive_text; } if (iter->active) { top = m_style.active_top; bottom = m_style.active_bottom; text = m_style.active_text; } m_video->DrawRectangle(v2ButtonPos, v2ButtonSize, top, top, bottom, bottom); str_type::stringstream ss; ss << iter->text << iter->extText; m_video->DrawBitmapText( v2ButtonPos + v2TextAdd, ss.str().c_str(), GS_L("Verdana14_shadow.fnt"), text ); t++; } if (newSingleSet) { for (iter = m_buttons.begin(); iter != m_buttons.end(); ++iter) { if (m_single.text == iter->text) continue; iter->active = false; } newSingleSet = false; } if (m_autoUnclick) { for (iter = m_buttons.begin(); iter != m_buttons.end(); ++iter) { iter->active = false; } } } if (MouseOver(v2Pos, Vector2(m_width, m_size*(float)m_buttons.size()))) { m_mouseOver = true; DrawOutline(v2Pos, Vector2(m_width, m_size*(float)GetNumButtons())); } else { m_mouseOver = false; } return r; }
GSGUI_BUTTON GSGUI_DROPDOWN::PlaceMenu(Vector2 v2Pos) { GSGUI_BUTTON r; if (!m_video) return r; m_video->SetZBuffer(false); m_video->SetZWrite(false); Vector2 v2TextAdd(m_size/4.0f, 0.0f), v2ButtonSize = Vector2(m_width, m_size); bool overMainButton = false; bool overSomething = false; m_video->DrawRectangle(v2Pos, v2ButtonSize, m_style.active_top, m_style.active_top, m_style.active_bottom, m_style.active_bottom); m_video->DrawBitmapText( v2Pos + v2TextAdd, m_mainText.c_str(), GS_L("Verdana14_shadow.fnt"), m_style.active_text ); if (MouseOver(v2Pos, v2ButtonSize)) { m_mouseOver = overMainButton = overSomething = true; DrawOutline(v2Pos, v2ButtonSize); if ((!m_onClick && !m_active) || m_input->GetLeftClickState() == GSKS_HIT) m_active = !(m_active); } else { m_mouseOver = false; if (m_active) DrawOutline(v2Pos, v2ButtonSize); if (m_input->GetRightClickState() == GSKS_HIT) m_active = false; } if (!m_buttons.empty() && m_active) { int focus=-1; int t=1; GSGUI_BUTTON_ITERATOR iter; for (iter = m_buttons.begin(); iter != m_buttons.end(); ++iter) { Vector2 v2ButtonPos = Vector2(v2Pos.x, v2Pos.y+((float)t*m_size)); GS_DWORD top, bottom, text; iter->onFocus = MouseOver(v2ButtonPos, v2ButtonSize); if (iter->onFocus) overSomething = true; if (iter->onFocus) { top = m_style.focused_top; bottom = m_style.focused_bottom; text = m_style.active_text; focus = t; if (m_input->GetLeftClickState() == GSKS_HIT) { r.text = iter->text; top = m_style.active_top; bottom = m_style.active_bottom; m_active = false; } } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; text = m_style.inactive_text; } m_video->DrawRectangle(v2ButtonPos, v2ButtonSize, top, top, bottom, bottom); m_video->DrawBitmapText( v2ButtonPos + v2TextAdd, iter->text.c_str(), GS_L("Verdana14_shadow.fnt"), text ); t++; } if ((m_input->GetLeftClickState() == GSKS_HIT || m_input->GetRightClickState() == GSKS_HIT)) { if (m_active && focus == -1 && !overMainButton) m_active = false; } } return r; }
str_type::string GSGUI_STRING_LINE_INPUT::PlaceInput(Vector2 v2Pos) { m_video->SetZBuffer(false); m_video->SetZWrite(false); Vector2 v2Size(m_width, m_size), v2TextAdd(m_size/4.0f, 0.0f); m_mouseOver = MouseOver(v2Pos, v2Size); Color top, bottom, text; // const Vector2i scissor = m_video->GetTextRect(); // m_video->SetTextRect(Vector2i(int(GetWidth()-v2TextAdd.x), int(GetSize()-v2TextAdd.y))); if (m_active) { top = m_style.active_top; bottom = m_style.active_bottom; text = m_style.active_text; if (!m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT || m_input->GetRightClickState() == GSKS_HIT) m_active = false; } if (m_input->GetKeyState(GSK_ENTER) == GSKS_HIT) m_active = false; } else { if (m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT) m_active = true; top = m_style.focused_top; bottom = m_style.focused_bottom; text = m_style.active_text; } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; text = m_style.inactive_text; } if (m_strInput.GetString() == GS_L("")) m_strInput.SetString(GS_L("0")); } m_video->DrawRectangle(v2Pos, Vector2(m_width, m_size), top, top, bottom, bottom); str_type::stringstream ss; ss << m_strInput.GetString(); if (m_active) { m_strInput.PlaceInput(v2Pos+v2TextAdd, GS_L("Verdana14_shadow.fnt"), m_nMaxChars, m_size, text, m_video, m_input); } else { m_strInput.Place(v2Pos+v2TextAdd, GS_L("Verdana14_shadow.fnt"), m_size, text, m_video); } if (m_active || m_mouseOver) DrawOutline(v2Pos, v2Size); // m_video->SetTextRect(scissor); return m_strInput.GetString(); }
float GSGUI_FLOAT_INPUT::PlaceInput(Vector2 v2Pos) { m_lastValue = 0; m_video->SetZBuffer(false); m_video->SetZWrite(false); Vector2 v2Size(m_width, m_size), v2TextAdd(m_size/4.0f, 0.0f); m_mouseOver = MouseOver(v2Pos+Vector2(m_width, 0.0f), v2Size); Color top, bottom, text; m_video->DrawBitmapText( v2Pos + v2TextAdd, m_text.c_str(), GS_L("Verdana14_shadow.fnt"), gs2d::constant::WHITE ); if (m_active) { top = m_style.active_top; bottom = m_style.active_bottom; text = m_style.active_text; if (!m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT || m_input->GetRightClickState() == GSKS_HIT) m_active = false; } if (m_input->GetKeyState(GSK_ENTER) == GSKS_HIT) m_active = false; } else { if (m_mouseOver) { if (m_input->GetLeftClickState() == GSKS_HIT) m_active = true; top = m_style.focused_top; bottom = m_style.focused_bottom; text = m_style.active_text; } else { top = m_style.inactive_top; bottom = m_style.inactive_bottom; text = m_style.inactive_text; } if (m_strInput.GetString() == GS_L("")) m_strInput.SetString(GS_L("0.0")); } m_video->DrawRectangle(v2Pos+Vector2(m_width, 0.0f), Vector2(m_width, m_size), top, top, bottom, bottom); str_type::stringstream ss; ss.str(m_strInput.GetString()); // if there are no chars, go back to the min value //const unsigned int nLen = ss.str().length(); //-V807 if (m_strInput.GetString().length() > 0) { GS2D_SSCANF(ss.str().c_str(), GS_L("%f"), &m_lastValue); if (m_active && m_input->GetWheelState() != 0.0f) { m_lastValue += m_input->GetWheelState()*m_scrollAdd; ss.str(GS_L("")); ss << m_lastValue; m_strInput.SetString(ss.str()); } GS2D_SSCANF(ss.str().c_str(), GS_L("%f"), &m_lastValue); if (m_clamp) { if (m_lastValue > m_max) { m_lastValue = m_max; ss.str(GS_L("")); ss << m_lastValue; } else if (m_lastValue < m_min) { m_lastValue = m_min; ss.str(GS_L("")); ss << m_lastValue; } m_strInput.SetString(ss.str()); } } if (m_active) { m_strInput.PlaceInput(v2Pos+v2TextAdd+Vector2(m_width, 0.0f), GS_L("Verdana14_shadow.fnt"), m_nMaxChars, m_size, text, m_video, m_input); } else { m_strInput.Place(v2Pos+v2TextAdd+Vector2(m_width, 0.0f), GS_L("Verdana14_shadow.fnt"), m_size, text, m_video); } if (m_active || m_mouseOver) DrawOutline(v2Pos, v2Size+Vector2(m_width, 0.0f)); return m_lastValue; }
bool LineEdit::HandleEventSelf(const SDL_Event& ev) { switch (ev.type) { case SDL_MOUSEBUTTONDOWN: { if (MouseOver(ev.button.x, ev.button.y)) { hasFocus = true; } else { hasFocus = false; } break; } case SDL_KEYDOWN: { if (!hasFocus) break; switch(ev.key.keysym.sym) { case SDLK_BACKSPACE: { if (cursorPos > 0) { content.erase(--cursorPos, 1); } break; } case SDLK_DELETE: { if (cursorPos < content.size()) { content.erase(cursorPos, 1); } break; } case SDLK_ESCAPE: { hasFocus= false; break; } case SDLK_RIGHT: { if (cursorPos < content.size()) ++cursorPos; break; } case SDLK_LEFT: { if (cursorPos > 0) --cursorPos; break; } case SDLK_HOME: { cursorPos = 0; break; } case SDLK_END: { cursorPos = content.size(); break; } case SDLK_RETURN: { DefaultAction(); return true; } default: { uint16_t currentUnicode = ev.key.keysym.unicode; if (currentUnicode >= 32 && currentUnicode <= 126) // only ASCII supported ATM { char buf[2] = {(const char)currentUnicode, 0}; content.insert(cursorPos++, buf); } } } break; } } return false; }
void cMenu::MenuNavigation() { GetCursorPos( &Cur ); //Tabs. bool ActiveCheck = false; for (int i = 0; i < TabCount; i++) { if(MouseOver(Tabs[i].x, Tabs[i].y, Tabs[i].x + sizeoftab, Tabs[i].y + 20) == 2) SwitchTab(i); if(Tabs[i].Active) { ActiveName = Tabs[i].Name; ActiveCheck = true; } } if(!ActiveCheck) Tabs[0].Active = true; //Checks. for(int i = 0; i < CheckCount; i++) { if ( ActiveName != Checks[i].Parent ) continue; if((MouseOver(Checks[i].x, Checks[i].y, Checks[i].x + 10 , Checks[i].y + 10) == 3) ) Checks[i].Checked = 0; if((MouseOver(Checks[i].x, Checks[i].y, Checks[i].x + 10 , Checks[i].y + 10) == 2) ) Checks[i].Checked = 1; if(Checks[i].Checked) *Checks[i].Variable = 1; else *Checks[i].Variable = 0; } //Sliders. for(int i = 0; i < SliderCount; i++) { if ( ActiveName != Sliders[i].Parent ) continue; if(((MouseOver(Sliders[i].x, Sliders[i].y - 3, Sliders[i].x + 160 , Sliders[i].y + 6) == 2)) ) { //Calculate value based on click position. int Value1 = (Cur.x - Sliders[i].x); float Value2 = ((float)Value1 / (float)120) * Sliders[i].MaxValue; if((int)Value2 > Sliders[i].MaxValue) Value2 = (float)Sliders[i].MaxValue; if((int)Value2 < 0) Value2 = 0.0f; Sliders[i].Value = (int)Value2; *Sliders[i].Variable = Sliders[i].Value; } } //TextBoxes. for(int i = 0; i < TextBoxCount; i++) { if ( ActiveName != TextBoxes[i].Parent ) continue; if((MouseOver(TextBoxes[i].x, TextBoxes[i].y, TextBoxes[i].x + 100 , TextBoxes[i].y + 20) == 2) ) TextBoxes[i].Focused = 1; if((MouseOver(TextBoxes[i].x, TextBoxes[i].y, TextBoxes[i].x + 100 , TextBoxes[i].y + 20) == 3) ) TextBoxes[i].Focused = 0; if ( TextBoxes[i].Focused ) cMenu::ThinkTextBox( i ); } }