void StatusButtonUp(HDC hDC, PSTATEL ip) { RECT rc; HPEN hpenOld; TEXTMETRIC tm; rc = ip->rc; TopLeft(hDC, &rc, hpenBlack, TRUE); BottomRight(hDC, &rc, hpenBlack, FALSE); rc.top++; rc.bottom--; rc.left++; rc.right--; TopLeft(hDC, &rc, hpenHilight, FALSE); BottomRight(hDC, &rc, hpenLowlight, TRUE); rc.top++; rc.bottom--; rc.left++; rc.right--; BottomRight(hDC, &rc, hpenLowlight, TRUE); rc.bottom--; rc.right--; hpenOld = (HPEN)SelectObject(hDC, hpenNeutral); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); SelectObject(hDC, hpenOld); GetTextMetrics(hDC, &tm); rc.top += tm.tmExternalLeading; DrawText(hDC, ip->text, lstrlen(ip->text), &rc, DT_CENTER | DT_VCENTER); }
SoccerPitch::SoccerPitch(int cx, int cy): m_cxClient(cx), m_cyClient(cy), m_bPaused(false) { //GoalWidth指的是得分區厚度 int GoalWidth = 200; m_pPlayingArea = new Region(20, 20, cx-20, cy-20); // m_pRedGoal = new Goal(V2D(m_pPlayingArea->Left(), (cy-GoalWidth)/2), V2D(m_pPlayingArea->Left(), cy - (cy-GoalWidth)/2), V2D(1,0)); m_pBlueGoal = new Goal(V2D( m_pPlayingArea->Right(), (cy-GoalWidth)/2), V2D(m_pPlayingArea->Right(), cy - (cy-GoalWidth)/2), V2D(-1,0)); //建立外牆 V2D TopLeft(m_pPlayingArea->Left(), m_pPlayingArea->Top()); V2D TopRight(m_pPlayingArea->Right(), m_pPlayingArea->Top()); V2D BottomRight(m_pPlayingArea->Right(), m_pPlayingArea->Bottom()); V2D BottomLeft(m_pPlayingArea->Left(), m_pPlayingArea->Bottom()); m_vecWalls.push_back(Wall(BottomLeft, m_pRedGoal->RightPost())); m_vecWalls.push_back(Wall(m_pRedGoal->LeftPost(), TopLeft)); m_vecWalls.push_back(Wall(TopLeft, TopRight)); m_vecWalls.push_back(Wall(TopRight, m_pBlueGoal->LeftPost())); m_vecWalls.push_back(Wall(m_pBlueGoal->RightPost(), BottomRight)); m_vecWalls.push_back(Wall(BottomRight, BottomLeft)); }
void InternalWindow::borderDragMouseDragged(MouseEventDetails* const e) { Vec2f Size; bool PositionChange; Pnt2f Position; Pnt2f BottomRight(getPosition() + getSize()); switch(_BorderDragged) { case WINDOW_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), getPreferredSize().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - getPosition().x(), getPreferredSize().y()); break; case WINDOW_TOP_BORDER: Size.setValues(getPreferredSize().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_BORDER: PositionChange = false; Size.setValues(getPreferredSize().x(), e->getLocation().y() - getPosition().y()); break; case WINDOW_TOP_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - getPosition().x(), e->getLocation().y() - getPosition().y()); break; case WINDOW_TOP_RIGHT_BORDER: Size.setValues(e->getLocation().x() - getPosition().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position.setValues(getPosition().x(), BottomRight.y() - Size.y()); break; case WINDOW_BOTTOM_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), e->getLocation().y() - getPosition().y()); PositionChange = true; Position.setValues( BottomRight.x() - Size.x(), getPosition().y()); break; } if(PositionChange) { setPreferredSize(Size); setPosition(Position); } else { setPreferredSize(Size); } }
void InternalWindow::BorderDraggedListener::mouseDragged(const MouseEventUnrecPtr e) { Vec2f Size; bool PositionChange; Pnt2f Position; Pnt2f BottomRight(_InternalWindow->getPosition() + _InternalWindow->getSize()); switch(_BorderDragged) { case WINDOW_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), _InternalWindow->getPreferredSize().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - _InternalWindow->getPosition().x(), _InternalWindow->getPreferredSize().y()); break; case WINDOW_TOP_BORDER: Size.setValues(_InternalWindow->getPreferredSize().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_BORDER: PositionChange = false; Size.setValues(_InternalWindow->getPreferredSize().x(), e->getLocation().y() - _InternalWindow->getPosition().y()); break; case WINDOW_TOP_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position = BottomRight - Size; break; case WINDOW_BOTTOM_RIGHT_BORDER: PositionChange = false; Size.setValues(e->getLocation().x() - _InternalWindow->getPosition().x(), e->getLocation().y() - _InternalWindow->getPosition().y()); break; case WINDOW_TOP_RIGHT_BORDER: Size.setValues(e->getLocation().x() - _InternalWindow->getPosition().x(), BottomRight.y() - e->getLocation().y()); PositionChange = true; Position.setValues(_InternalWindow->getPosition().x(), BottomRight.y() - Size.y()); break; case WINDOW_BOTTOM_LEFT_BORDER: Size.setValues(BottomRight.x() - e->getLocation().x(), e->getLocation().y() - _InternalWindow->getPosition().y()); PositionChange = true; Position.setValues( BottomRight.x() - Size.x(), _InternalWindow->getPosition().y()); break; } if(PositionChange) { _InternalWindow->setPreferredSize(Size); _InternalWindow->setPosition(Position); } else { _InternalWindow->setPreferredSize(Size); } }
//------------------------------- ctor ----------------------------------- //------------------------------------------------------------------------ SoccerPitch::SoccerPitch(int cx, int cy):m_cxClient(cx), m_cyClient(cy), m_bPaused(false), m_bGoalKeeperHasBall(false), m_Regions(NumRegionsHorizontal*NumRegionsVertical), m_bGameOn(true) { //define the playing area m_pPlayingArea = new Region(20, 20, cx-20, cy-20); //create the regions CreateRegions(PlayingArea()->Width() / (double)NumRegionsHorizontal, PlayingArea()->Height() / (double)NumRegionsVertical); //create the goals m_pRedGoal = new Goal(Vector2D( m_pPlayingArea->Left(), (cy-Prm.GoalWidth)/2), Vector2D(m_pPlayingArea->Left(), cy - (cy-Prm.GoalWidth)/2), Vector2D(1,0)); m_pBlueGoal = new Goal( Vector2D( m_pPlayingArea->Right(), (cy-Prm.GoalWidth)/2), Vector2D(m_pPlayingArea->Right(), cy - (cy-Prm.GoalWidth)/2), Vector2D(-1,0)); //create the soccer ball m_pBall = new SoccerBall(Vector2D((double)m_cxClient/2.0, (double)m_cyClient/2.0), Prm.BallSize, Prm.BallMass, m_vecWalls); //create the teams m_pRedTeam = new SoccerTeam(m_pRedGoal, m_pBlueGoal, this, SoccerTeam::red); m_pBlueTeam = new SoccerTeam(m_pBlueGoal, m_pRedGoal, this, SoccerTeam::blue); //make sure each team knows who their opponents are m_pRedTeam->SetOpponents(m_pBlueTeam); m_pBlueTeam->SetOpponents(m_pRedTeam); //create the walls Vector2D TopLeft(m_pPlayingArea->Left(), m_pPlayingArea->Top()); Vector2D TopRight(m_pPlayingArea->Right(), m_pPlayingArea->Top()); Vector2D BottomRight(m_pPlayingArea->Right(), m_pPlayingArea->Bottom()); Vector2D BottomLeft(m_pPlayingArea->Left(), m_pPlayingArea->Bottom()); m_vecWalls.push_back(Wall2D(BottomLeft, m_pRedGoal->RightPost())); m_vecWalls.push_back(Wall2D(m_pRedGoal->LeftPost(), TopLeft)); m_vecWalls.push_back(Wall2D(TopLeft, TopRight)); m_vecWalls.push_back(Wall2D(TopRight, m_pBlueGoal->LeftPost())); m_vecWalls.push_back(Wall2D(m_pBlueGoal->RightPost(), BottomRight)); m_vecWalls.push_back(Wall2D(BottomRight, BottomLeft)); ParamLoader* p = ParamLoader::Instance(); }
void FPaperExtractSpritesViewportClient::DrawRectangle(FCanvas* Canvas, const FLinearColor& Color, const FIntRect& Rect) { FVector2D TopLeft(-ZoomPos.X * ZoomAmount + Rect.Min.X * ZoomAmount, -ZoomPos.Y * ZoomAmount + Rect.Min.Y * ZoomAmount); FVector2D BottomRight(-ZoomPos.X * ZoomAmount + Rect.Max.X * ZoomAmount, -ZoomPos.Y * ZoomAmount + Rect.Max.Y * ZoomAmount); FVector2D RectVertices[4]; RectVertices[0] = FVector2D(TopLeft.X, TopLeft.Y); RectVertices[1] = FVector2D(BottomRight.X, TopLeft.Y); RectVertices[2] = FVector2D(BottomRight.X, BottomRight.Y); RectVertices[3] = FVector2D(TopLeft.X, BottomRight.Y); for (int32 RectVertexIndex = 0; RectVertexIndex < 4; ++RectVertexIndex) { const int32 NextVertexIndex = (RectVertexIndex + 1) % 4; FCanvasLineItem RectLine(RectVertices[RectVertexIndex], RectVertices[NextVertexIndex]); RectLine.SetColor(Color); Canvas->DrawItem(RectLine); } }
void CSwingBorderWnd::OnPaint() { CWnd::OnPaint(); CPaintDC dc(this); // device context for painting CDC *pDC = GetWindowDC(); CRect rectItem, pRect; GetWindowRect(pRect); GetClientRect(rectItem); rectItem.right = rectItem.left + pRect.Width(); rectItem.bottom = rectItem.top + pRect.Height(); CPoint TopLeft(rectItem.left, rectItem.top); CPoint BottomRight(rectItem.right - 1, rectItem.bottom - 1); CPoint TopRight(rectItem.right - 1, rectItem.top); CPoint BottomLeft(rectItem.left, rectItem.bottom - 1); pDC->SelectObject(&nDarkBorder); pDC->MoveTo(TopLeft); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft); pDC->LineTo(BottomLeft); pDC->MoveTo(BottomLeft.x, BottomLeft.y - 1); pDC->LineTo(BottomRight.x, BottomRight.y - 1); pDC->MoveTo(BottomRight.x - 1, BottomRight.y); pDC->LineTo(TopRight.x - 1, TopRight.y); pDC->SelectObject(&nWhiteBorder); pDC->MoveTo(BottomLeft); pDC->LineTo(BottomRight); pDC->MoveTo(BottomRight); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(TopRight.x - 1, TopRight.y + 1); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(BottomLeft.x + 1, BottomLeft.y - 1); ReleaseDC(pDC); // TODO: Add your message handler code here // Do not call CWnd::OnPaint() for painting messages }
CMessageBox::CMessageBox(const CRect& WindowRect, CWindow* pParent, CFontEngine* pFontEngine, const std::string& sTitle, const std::string& sMessage, int iButtons) : CFrame(WindowRect, pParent, pFontEngine, sTitle), m_iButtons(iButtons) { //m_pMessageLabel = new CLabel(CRect(75, 10, GetClientRect().Right() - 75, GetClientRect().Bottom() - 40), this, sMessage); m_pMessageLabel = new CLabel(CPoint(10, 10), this, sMessage); // judb Position buttons relative to lower right corner: CPoint BottomRight(GetClientRect().Right() - 20, GetClientRect().Bottom() - 30); if (iButtons & CMessageBox::BUTTON_CANCEL) { CButton *button = new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, "Cancel"); button->SetIsFocusable(true); m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_CANCEL, button)); BottomRight = BottomRight - CPoint(60, 0); } if (iButtons & CMessageBox::BUTTON_OK) { CButton *button = new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, "Ok"); button->SetIsFocusable(true); m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_OK, button)); BottomRight = BottomRight - CPoint(60, 0); } if (iButtons & CMessageBox::BUTTON_NO) { CButton *button = new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, "No"); button->SetIsFocusable(true); m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_NO, button)); BottomRight = BottomRight - CPoint(60, 0); } if (iButtons & CMessageBox::BUTTON_YES) { CButton *button = new CButton(CRect(BottomRight - CPoint(50, 18), BottomRight), this, "Yes"); button->SetIsFocusable(true); m_ButtonMap.insert(std::make_pair(CMessageBox::BUTTON_YES, button)); BottomRight = BottomRight - CPoint(60, 0); } }
void LowerRect(HDC hDC, LPRECT rcp) { TopLeft(hDC, rcp, hpenLowlight, FALSE); BottomRight(hDC, rcp, hpenHilight, FALSE); }
void CSwingCheckBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); CRect rectItem(lpDIS->rcItem); CRect rectCheck(rectItem); rectCheck.right = rectCheck.left + 12; rectCheck.bottom = rectCheck.top + 12; CPoint TopLeft(rectCheck.left, rectCheck.top); CPoint BottomRight(rectCheck.right, rectCheck.bottom); CPoint TopRight(rectCheck.right, rectCheck.top); CPoint BottomLeft(rectCheck.left, rectCheck.bottom); // TODO: Add your code to draw the specified item pDC->SelectObject(&nInactiveBrush); pDC->SelectStockObject(NULL_PEN); pDC->Rectangle(rectItem); pDC->SelectObject(&nDarkBorder); pDC->MoveTo(TopLeft); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft); pDC->LineTo(BottomLeft); pDC->MoveTo(BottomLeft.x, BottomLeft.y - 1); pDC->LineTo(BottomRight.x, BottomRight.y - 1); pDC->MoveTo(BottomRight.x - 1, BottomRight.y); pDC->LineTo(TopRight.x - 1, TopRight.y); pDC->SelectObject(&nWhiteBorder); pDC->MoveTo(BottomLeft); pDC->LineTo(BottomRight); pDC->MoveTo(BottomRight); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(TopRight.x - 1, TopRight.y + 1); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(BottomLeft.x + 1, BottomLeft.y - 1); pDC->SelectStockObject(DEFAULT_GUI_FONT); pDC->TextOut(16, 0, m_strCaption); if (m_Checked) { pDC->SelectObject(&nCheck); pDC->MoveTo(2, 3); pDC->LineTo(3, 8); pDC->MoveTo(3, 9); pDC->LineTo(9, 3); } if (lpDIS->itemState & ODS_FOCUS) { pDC->SelectObject(&nSelectedBorder); pDC->SelectStockObject(NULL_BRUSH); int xlen = pDC->GetTextExtent(m_strCaption).cx; pDC->Rectangle(15, 0, 13 + xlen + 3, 12); } }
const WPoint WRectangle::BottomRight() const { return BottomRight(); }