void Gui_Element::Center(bool x, bool y) { if (x || y) { int _x = GetLocalPos().x; int _y = GetLocalPos().y; if (parent != NULL) { if (x) { _x = parent->GetLocalRect().w / 2 - rect.w / 2; } if (y) { _y = parent->GetLocalRect().h / 2 - rect.h / 2; } } else { if (x) _x = App->render->camera.w / 2 - rect.w / 2; if (y) _y = App->render->camera.h / 2 - rect.h / 2; } SetLocalPos(_x, _y); } }
CHitSquare::CHitSquare() { SetLocalPos(0,0,0); SetLocalScale(1,1,1); SetScale(0,0,0); SetRot(0,0,0); m_Direction = 1; #ifdef DEBUG m_pDebugFont = new CDebugFont; m_pDebugFont->SetUp(); #endif }
ActionMenu::ActionMenu(const ActionName::Type choice1, const ActionName::Type choice2, const Position& origin) : GameObject(LayerSpace::Window), m_activeChoice(0), m_lastChoice(0), m_numChoices(2), m_bChoiceLocked(false), m_bExpired(false), m_bAllCaps(false), m_miniWin(38, 22) { SetLocalPos(origin); m_choices.push_back(ActionIcon(choice1)); m_choices.push_back(ActionIcon(choice2)); Init(); }
Gui_Element::Gui_Element(p2Point<int> pos, Gui_Type t, Gui_Element* par) { SetLocalPos(pos.x, pos.y); type = t; active = true; mouseInside = false; clicked = false; draggable = false; focusable = false; focusIn = false; parent = par; listener_list.add((j1Module*)App->scene); parent = par; if (par != NULL) par->siblings.add(this); }
void CHitSquare::ConvertPosWorldtoLocal(D3DXVECTOR3 * point) { SetLocalPos((GetPos()->x - point->x)/(m_Scale.x),(GetPos()->y - point->y)/(m_Scale.y),0); }
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(); }
bool Gui_Element::CheckEvent(Gui_Element* hover, Gui_Element* focus) { bool inside = (hover == this); bool focused = (focus == this); int mouse_x = 0; int mouse_y = 0; App->input->GetMousePosition(mouse_x, mouse_y); p2List_item<j1Module*>* listener = listener_list.start; while (listener != NULL) { if (inside != mouseInside) { //Check if, when outside, mouse enters if (inside) { listener->data->ReceiveEvent(this, MOUSE_ENTER); } //Check if, when inside, mouse leaves else { listener->data->ReceiveEvent(this, MOUSE_LEAVE); clicked = false; } mouseInside = inside; } if (inside) { if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN) { listener->data->ReceiveEvent(this, MOUSE_CLICK_DOWN); clicked = true; } else if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_UP) { listener->data->ReceiveEvent(this, MOUSE_CLICK_UP); clicked = false; } if (draggable && clicked && App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_REPEAT) { p2Point<int> p = GetLocalPos(); int mouse_motionX = 0; int mouse_motionY = 0; App->input->GetMouseMotion(mouse_motionX, mouse_motionY); SetLocalPos(p.x + mouse_motionX, p.y + mouse_motionY); } } if (focusIn != focused) { if (listener) { if (focused) listener->data->ReceiveEvent(this, FOCUS_ON); else listener->data->ReceiveEvent(this, FOCUS_OFF); } focusIn = focused; } if (focused) { if (listener) { if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN) listener->data->ReceiveEvent(this, MOUSE_CLICK_DOWN); if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_UP) listener->data->ReceiveEvent(this, MOUSE_CLICK_UP); } } listener = listener->next; } return true; }
void ActionMenu::DoUpdate(const float ticks) { SetLocalPos(m_slider.GetLocalPos()); m_choices[m_activeChoice].DoUpdate(ticks); }