/*============================================================================= -- Updates the position and size of each asset. =============================================================================*/ void ButtonCaption::_UpdateAssets() { mImgUp.SetPos(GetScreenPos()); mImgUp.SetSize( GetWidth(), GetHeight() ); mImgUp.ResetPos(); mImgUp.ResetSize(); mImgDown.SetPos(GetScreenPos()); mImgDown.SetSize( GetWidth(), GetHeight() ); mImgDown.ResetPos(); mImgDown.ResetSize(); }
/*============================================================================= -- Updates the scalar metrics of any assets. =============================================================================*/ void EditBox::_UpdateAssets() { mImgBorder.SetPos(GetScreenPos()); mImgBorder.ResetPos(); //position the caret if (!mText.expired()) { unsigned width = GetRoot()->GetDefaultFont()->GetTextLengthPx(mText.lock()->GetText()); mImgCaret.SetPos( GetScreenPos().x+width+GUI_EDIT_TEXT_PAD, GetScreenPos().y+GUI_EDIT_TEXT_PAD ); } }
bool Gui_Element::MouseCollision(p2Point<int> mouse_pos) { bool ret = false; if (mouse_pos.x > GetScreenPos().x && mouse_pos.x < rect.w + GetScreenPos().x && mouse_pos.y > GetScreenPos().y && mouse_pos.y < rect.h + GetScreenPos().y) { ret = true; } return ret; }
SDL_Rect UIEntity::GetScreenRect()const { SDL_Rect ret = rect; GetScreenPos(ret.x, ret.y); return ret; }
bool RectComponent::IsOver(int screen_x, int screen_y) { if (behave_solid_ == true) { return Component::IsOver(screen_x, screen_y); } if (Component::IsOver(screen_x, screen_y) == false) { return false; } if (image_id_ == Painter::kInvalidImageid) { if (hollow_ == true) { Component* child = Component::GetChild(screen_x, screen_y); if (child != 0) { return child->IsOver(screen_x, screen_y); } return false; } else { return true; } } else { PixelCoord pos(GetScreenPos()); PixelCoord size(GetSize()); PixelRect rect(pos, pos + size); GUIImageManager* i_man = GetImageManager(); return i_man->IsOverImage(image_id_, screen_x, screen_y, rect); } }
// Called before render is available bool UIButton::Update(float dt) { bool ret = true; GetState(); int x, y; GetScreenPos(x, y); if (state == IDLE) App->render->Blit(idle, x , y); if (state == PRESSED) App->render->Blit(pressed, x , y); if (state == HOVER) App->render->Blit(hover, x , y); /*SDL_Rect button_rec = GetScreenRect(); SDL_Rect t = text.GetLocalRect(); x = button_rec.x + (button_rec.w / 2 - t.w / 2); y = button_rec.y + (button_rec.h / 2 - t.h / 2); App->render->Blit(text.texture, x, y);*/ text.Update(dt); return ret; }
void Gui_Image::Draw() { if (active) { p2Point<int> pos = GetScreenPos(); App->render->Blit(texture, pos.x, pos.y, §ion, 0.0f); } }
SDL_Rect Gui_Element::GetScreenRect() { if (parent != NULL) { p2Point<int> p = GetScreenPos(); return{ p.x, p.y, rect.w, rect.h }; } return rect; }
void MAPOBJECT::PaintSelected() { if(!m_selected || m_pDevice == NULL)return; BBOX bbox = GetBoundingBox(); //Bounding box in world space // Create 8 points according to the corners of the bounding box D3DXVECTOR3 corners[] = {D3DXVECTOR3(bbox.max.x, bbox.max.y, bbox.max.z), D3DXVECTOR3(bbox.max.x, bbox.max.y, bbox.min.z), D3DXVECTOR3(bbox.max.x, bbox.min.y, bbox.max.z), D3DXVECTOR3(bbox.max.x, bbox.min.y, bbox.min.z), D3DXVECTOR3(bbox.min.x, bbox.max.y, bbox.max.z), D3DXVECTOR3(bbox.min.x, bbox.max.y, bbox.min.z), D3DXVECTOR3(bbox.min.x, bbox.min.y, bbox.max.z), D3DXVECTOR3(bbox.min.x, bbox.min.y, bbox.min.z)}; // Find the max and min points of these // 8 offests points in screen space INTPOINT pmax(-10000, -10000), pmin(10000,10000); for(int i=0;i<8;i++) { INTPOINT screenPos = GetScreenPos(corners[i], m_pDevice); if(screenPos.x > pmax.x)pmax.x = screenPos.x; if(screenPos.y > pmax.y)pmax.y = screenPos.y; if(screenPos.x < pmin.x)pmin.x = screenPos.x; if(screenPos.y < pmin.y)pmin.y = screenPos.y; } RECT scr = {-20, -20, 820, 620}; // Check that the max and min point is within our viewport boundaries if(pmax.inRect(scr) || pmin.inRect(scr)) { float s = (pmax.x - pmin.x) / 3.0f; if((pmax.y - pmin.y) < (pmax.x - pmin.x))s = (pmax.y - pmin.y) / 3.0f; D3DXVECTOR2 corner1[] = {D3DXVECTOR2((float)pmin.x, (float)pmin.y + s), D3DXVECTOR2((float)pmin.x, (float)pmin.y), D3DXVECTOR2((float)pmin.x + s, (float)pmin.y)}; D3DXVECTOR2 corner2[] = {D3DXVECTOR2((float)pmax.x - s, (float)pmin.y), D3DXVECTOR2((float)pmax.x, (float)pmin.y), D3DXVECTOR2((float)pmax.x, (float)pmin.y + s)}; D3DXVECTOR2 corner3[] = {D3DXVECTOR2((float)pmax.x, (float)pmax.y - s), D3DXVECTOR2((float)pmax.x, (float)pmax.y), D3DXVECTOR2((float)pmax.x - s, (float)pmax.y)}; D3DXVECTOR2 corner4[] = {D3DXVECTOR2((float)pmin.x + s, (float)pmax.y), D3DXVECTOR2((float)pmin.x, (float)pmax.y), D3DXVECTOR2((float)pmin.x, (float)pmax.y - s)}; //Draw the 4 corners if(line != NULL) { line->SetWidth(2.0f); line->Begin(); line->Draw(corner1, 3, 0xffffffff); line->Draw(corner2, 3, 0xffffffff); line->Draw(corner3, 3, 0xffffffff); line->Draw(corner4, 3, 0xffffffff); line->End(); } } }
void RectComponent::RepaintBackground(Painter* painter) { painter->PushAttrib(Painter::kAttrAll); GUIImageManager* i_man = GetImageManager(); PixelCoord pos(GetScreenPos()); PixelCoord size(GetSize()); PixelRect rect(pos, pos + size); PixelRect clipping_rect(rect); clipping_rect.right_++; clipping_rect.bottom_++; //painter->ReduceClippingRect(clipping_rect); if (hollow_ == false) { if (corner_radius_ == 0) { if (image_id_ == Painter::kInvalidImageid) { painter->SetColor(color_[0], 0); painter->SetAlphaValue(color_[0].alpha_); if (shaded_ == true) { painter->SetColor(color_[1], 1); painter->SetColor(color_[2], 2); painter->SetColor(color_[3], 3); painter->FillShadedRect(rect); } else { if (color_[0].alpha_ != 0) { painter->FillRect(rect); } } } else { i_man->DrawImage(image_id_, rect); } } else { // Draw with rounded corners. painter->SetColor(color_[0], 0); painter->SetAlphaValue(color_[0].alpha_); PixelRect _rect(GetScreenPos(), GetScreenPos() + GetSize()); painter->DrawRoundedRect(_rect, corner_radius_, corner_radius_mask_, true); } } painter->PopAttrib(); }
void Gui_InputBox::Draw() { image.Draw(); text.Draw(); if (inputOn) { iPoint pos = GetScreenPos(); App->render->DrawQuad({ pos.x + cursor.x - App->render->camera.x, pos.y - App->render->camera.y, CURSOR_WIDTH, cursor.y }, 255, 255, 255); } }
void Gui_Label::Draw() { if (active) { if (texture) { p2Point<int> pos = GetScreenPos(); App->render->Blit(texture, pos.x, pos.y, NULL, 0.0f); } } }
void AvatarButton::OnMouseClick(int x, int y, unsigned int button) { if(button == BUTTON_RIGHT) { if(menu) menu->Show(GetScreenPos() + ui::Point(x, y)); } else { isButtonDown = true; } }
void View::DrawLine (FP x1, FP y1, FP x2, FP y2, DWORD color) { HDC hdc; POINT SPos1 = GetScreenPos (x1,y1); POINT SPos2 = GetScreenPos (x2,y2); hdc = GetDC (hWnd); HPEN hPen = CreatePen (PS_SOLID, 1, color); SelectObject (hdc, hPen); MoveToEx (hdc, SPos1.x, SPos1.y, NULL); LineTo (hdc, SPos2.x, SPos2.y); ReleaseDC (hWnd, hdc); DeleteObject (hPen); }
//********************************************************************************** // //********************************************************************************** void CTextInput::Render() { CWindow::Render(); V2 pos( GetScreenPos() ); CFont * const p_font( CFont::GetDefaultFont() ); const V2 text_size( p_font->GetStringSize( m_szText ) ); pos.x += 0.5f * ( TEXT_INPUT_WIDTH - text_size.x ); pos.y += 0.5f * ( TEXT_INPUT_HEIGHT - text_size.y ); p_font->Print( m_szText, pos, GetTextColor() ); }
/*============================================================================= -- Updates the position and size of each asset. =============================================================================*/ void ListBox::_UpdateAssets() { mImgBackground.SetPos(GetScreenPos()); mImgBackground.SetSize(GetWidth(), GetHeight()); //tell every cell the new sizes std::vector< WeakPtr<Cell> >::iterator iter = mVisibleCells.begin(); while (iter != mVisibleCells.end()) { (*iter).lock()->SetSize(GetCellWidth(), GetCellHeight()); iter++; } }
// Called before render is available bool UILabel::Update(float dt) { bool ret = true; if (texture != NULL) { iPoint cam_pos(App->render->camera.x, App->render->camera.y); int x, y; GetScreenPos(x, y); App->render->Blit(texture, x - cam_pos.x, y - cam_pos.y); } return ret; }
/*============================================================================= -- Returns the cell at the absolute screen position @point. If the point is not within the bounds of where cells are, then no cell will be returned. =============================================================================*/ WeakPtr<Cell> ListBox::GetCellAtPoint(Vector2D<int> point) { _CalculateVisibleCells(); Vector2D<int> screenPos = GetScreenPos(); if (point.x > screenPos.x+LISTBOX_CELL_PADDING && point.x < screenPos.x+GetCellWidth()+LISTBOX_CELL_PADDING) { int selectedVisibleCellIndex = (point.y-screenPos.y-LISTBOX_CELL_PADDING) / GetCellHeight(); if (selectedVisibleCellIndex < (int)mVisibleCells.size() && selectedVisibleCellIndex >= 0) return mVisibleCells.at(selectedVisibleCellIndex); } return WeakPtr<Cell>(); }
void SaveButton::OnMouseClick(int x, int y, unsigned int button) { if(button == SDL_BUTTON_RIGHT) { if(menu) menu->Show(GetScreenPos() + ui::Point(x, y)); } else { isButtonDown = true; if(button !=1 && selectable) { selected = !selected; DoSelection(); } } }
void View::DrawPoint (FP x, FP y, DWORD color) { HDC hdc; POINT SPos = GetScreenPos (x, y); hdc = GetDC (hWnd); RECT rect; rect.left = SPos.x - 1; rect.top = SPos.y - 1; rect.right = SPos.x + 2; rect.bottom = SPos.y + 2; HBRUSH hBrush = CreateSolidBrush (color); FillRect (hdc, &rect, hBrush); ReleaseDC (hWnd, hdc); DeleteObject (hBrush); }
static void Display(GraphicsDevice *g, int yc, HandleInputResult result) { char s[128]; int y = 5; int i; int w = g->cachedConfig.Res.x; int h = g->cachedConfig.Res.y; Mission *mission = CampaignGetCurrentMission(&gCampaign); if (mission) { // Re-make the background if the resolution has changed if (gEventHandlers.HasResolutionChanged) { MakeBackground(g, 0); } if (result.RemakeBg || brush.IsGuideImageNew) { // Clear background first for (i = 0; i < GraphicsGetScreenSize(&g->cachedConfig); i++) { g->buf[i] = PixelFromColor(g, colorBlack); } brush.IsGuideImageNew = false; GrafxDrawExtra extra; extra.guideImage = brush.GuideImageSurface; extra.guideImageAlpha = brush.GuideImageAlpha; GrafxDrawBackground(g, &sDrawBuffer, tintNone, camera, &extra); } GraphicsBlitBkg(g); // Draw brush highlight tiles if (brush.IsActive && IsBrushPosValid(brush.Pos, mission)) { EditorBrushSetHighlightedTiles(&brush); } for (i = 0; i < (int)brush.HighlightedTiles.size; i++) { Vec2i *pos = CArrayGet(&brush.HighlightedTiles, i); Vec2i screenPos = GetScreenPos(*pos); if (screenPos.x >= 0 && screenPos.x < w && screenPos.y >= 0 && screenPos.y < h) { DrawRectangle( g, screenPos, Vec2iNew(TILE_WIDTH, TILE_HEIGHT), colorWhite, DRAW_FLAG_LINE); } } sprintf( s, "Mission %d/%d", gCampaign.MissionIndex + 1, (int)gCampaign.Setting.Missions.size); TextStringMasked(&gTextManager, s, g, Vec2iNew(270, y), yc == YC_MISSIONINDEX ? colorRed : colorWhite); if (brush.LastPos.x) { sprintf(s, "(%d, %d)", brush.Pos.x, brush.Pos.y); TextString(&gTextManager, s, g, Vec2iNew(w - 40, h - 16)); } } else { ClearScreen(g); if (gCampaign.Setting.Missions.size) { sprintf(s, "End/%d", (int)gCampaign.Setting.Missions.size); TextStringMasked(&gTextManager, s, g, Vec2iNew(270, y), yc == YC_MISSIONINDEX ? colorRed : colorWhite); } } if (fileChanged) { DrawTPic(10, y, PicManagerGetOldPic(&gPicManager, 221)); } TextString(&gTextManager, "Press F1 for help", g, Vec2iNew(20, h - 20 - CDogsTextHeight())); y = 150; UIObjectDraw( sObjs, g, Vec2iZero(), gEventHandlers.mouse.currentPos, &sDrawObjs); if (result.WillDisplayAutomap && mission) { AutomapDraw(AUTOMAP_FLAGS_SHOWALL, true); } else { if (sTooltipObj && sTooltipObj->Tooltip) { UITooltipDraw( g, gEventHandlers.mouse.currentPos, sTooltipObj->Tooltip); } MouseDraw(&gEventHandlers.mouse); } BlitFlip(g, &gConfig.Graphics); }
//************************************************************************************* // //************************************************************************************* void CWindowText::Render() { CFont::GetDefaultFont()->Print( m_szText, GetScreenPos(), m_Color ); }
void Gui_Element::DrawDebug() { if (active) { App->render->DrawLine(GetScreenPos().x, GetScreenPos().y, GetScreenPos().x + rect.w, GetScreenPos().y, 255, 0, 0); App->render->DrawLine(GetScreenPos().x, GetScreenPos().y, GetScreenPos().x, GetScreenPos().y + rect.h, 255, 0, 0); App->render->DrawLine(GetScreenPos().x + rect.w, GetScreenPos().y, GetScreenPos().x + rect.w, GetScreenPos().y + rect.h, 255, 0, 0); App->render->DrawLine(GetScreenPos().x, GetScreenPos().y + rect.h, GetScreenPos().x + rect.w, GetScreenPos().y + rect.h, 255, 0, 0); } }