void CProgress::Draw(void) const { CWindow::Draw(); if (m_pSDLSurface) { CRect SubRect(m_WindowRect.SizeRect()); SubRect.Grow(-1); CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE); Painter.DrawRect(m_WindowRect.SizeRect(), false, COLOR_BLACK); Painter.DrawRect(SubRect, false, COLOR_LIGHTGRAY); Painter.DrawHLine(SubRect.Left(), SubRect.Right(), SubRect.Top(), COLOR_DARKGRAY); Painter.DrawVLine(SubRect.Top(), SubRect.Bottom(), SubRect.Left(), COLOR_DARKGRAY); SubRect.Grow(-2); if (m_Value > m_MinLimit) { if (m_Value < m_MaxLimit) { SubRect.SetRight(stdex::safe_static_cast<int>(SubRect.Left() + SubRect.Width() * (stdex::safe_static_cast<double>(m_Value - m_MinLimit) / (m_MaxLimit - m_MinLimit)))); } Painter.DrawRect(SubRect, true, m_BarColor, m_BarColor); } } }
void CButton::Draw(void) const { CWindow::Draw(); if (m_pSDLSurface) { CPoint FontCenterPoint = m_WindowRect.SizeRect().Center(); CRect SubRect(m_WindowRect.SizeRect()); CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE); CRGBColor FontColor = DEFAULT_TEXT_COLOR; switch (m_eButtonState) { case UP: Painter.Draw3DRaisedRect(SubRect, DEFAULT_BUTTON_COLOR); break; case DOWN: Painter.Draw3DLoweredRect(SubRect, DEFAULT_BUTTON_COLOR); FontCenterPoint = FontCenterPoint + CPoint(1, 1); break; case DISABLED: FontColor = DEFAULT_DISABLED_LINE_COLOR; break; default: break; } SubRect.Grow(-2); if (m_pRenderedString.get()) { m_pRenderedString->Draw(m_pSDLSurface, SubRect, FontCenterPoint, FontColor); } } }
void CCheckBox::Draw() const { CWindow::Draw(); if (m_pSDLSurface) { CRect SubRect(m_WindowRect.SizeRect()); CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE); Painter.DrawRect(m_WindowRect.SizeRect(), false, COLOR_WHITE); if (m_eCheckBoxState != DISABLED) { Painter.DrawRect(SubRect, false, COLOR_LIGHTGRAY); Painter.DrawHLine(SubRect.Left(), SubRect.Right(), SubRect.Top(), COLOR_BLACK); Painter.DrawVLine(SubRect.Top(), SubRect.Bottom(), SubRect.Left(), COLOR_BLACK); SubRect.Grow(-1); if (m_bHasFocus) { Painter.DrawRect(SubRect, false, COLOR_GRAY); } SubRect.Grow(-1); if (m_eCheckBoxState == CHECKED) { // Painter.DrawLine(SubRect.TopLeft(), SubRect.BottomRight(), DEFAULT_LINE_COLOR); // Painter.DrawLine(SubRect.BottomLeft(), SubRect.TopRight(), DEFAULT_LINE_COLOR); SDL_Rect SourceRect = m_WindowRect.SizeRect().SDLRect(); SDL_Rect DestRect = SubRect.SDLRect(); SDL_BlitSurface(m_hBitmapCheck.Bitmap(), &SourceRect, m_pSDLSurface, &DestRect); } } } }
void CToolTip::Draw(void) const { CWindow::Draw(); if (m_pSDLSurface) { CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE); Painter.DrawRect(m_WindowRect.SizeRect(), false); CRect SubRect(m_WindowRect.SizeRect()); SubRect.Grow(-2); if (m_pRenderedString.get()) { m_pRenderedString->Draw(m_pSDLSurface, SubRect, SubRect.TopLeft(), m_FontColor); } } }
void CPictureButton::Draw(void) const { CWindow::Draw(); if (m_pSDLSurface) { CRect SubRect(m_WindowRect.SizeRect()); CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE); switch (m_eButtonState) { case UP: Painter.Draw3DRaisedRect(SubRect, DEFAULT_BUTTON_COLOR); break; case DOWN: Painter.Draw3DLoweredRect(SubRect, DEFAULT_BUTTON_COLOR); SubRect = SubRect + CPoint(1, 1); break; case DISABLED: break; default: break; } SubRect.Grow(-1); SDL_Rect SourceRect; SourceRect.x = stdex::safe_static_cast<short int>((m_phBitmap->Bitmap()->w - SubRect.Width()) / 2 < 0 ? 0 : (m_phBitmap->Bitmap()->w - SubRect.Width()) / 2); SourceRect.y = stdex::safe_static_cast<short int>((m_phBitmap->Bitmap()->h - SubRect.Height()) / 2 < 0 ? 0 : (m_phBitmap->Bitmap()->w - SubRect.Height()) / 2); SourceRect.w = stdex::safe_static_cast<short int>(std::min(SubRect.Width(), m_phBitmap->Bitmap()->w)); SourceRect.h = stdex::safe_static_cast<short int>(std::min(SubRect.Height(), m_phBitmap->Bitmap()->h)); SDL_Rect DestRect; DestRect.x = stdex::safe_static_cast<short int>((SubRect.Width() - m_phBitmap->Bitmap()->w) / 2 < 0 ? SubRect.Left() : SubRect.Left() + (SubRect.Width() - m_phBitmap->Bitmap()->w) / 2); DestRect.y = stdex::safe_static_cast<short int>((SubRect.Height() - m_phBitmap->Bitmap()->h) / 2 < 0 ? SubRect.Top() : SubRect.Top() + (SubRect.Height() - m_phBitmap->Bitmap()->h) / 2); DestRect.w = stdex::safe_static_cast<short int>(std::min(SubRect.Width(), m_phBitmap->Bitmap()->w)); DestRect.h = stdex::safe_static_cast<short int>(std::min(SubRect.Height(), m_phBitmap->Bitmap()->h)); SDL_BlitSurface(m_phBitmap->Bitmap(), &SourceRect, m_pSDLSurface, &DestRect); } }
bool CDropDown::HandleMessage(CMessage* pMessage) { bool bHandled = false; CRect SubRect(m_WindowRect); SubRect.Grow(-3); if (pMessage) { switch(pMessage->MessageType()) { case CMessage::KEYBOARD_KEYDOWN: { CKeyboardMessage* pKeyboardMessage = dynamic_cast<CKeyboardMessage*>(pMessage); if (pKeyboardMessage && pMessage->Destination() == this) { switch (pKeyboardMessage->Key) { case SDLK_UP: SelectItem(GetSelectedIndex() - 1); ShowListBox(); break; case SDLK_DOWN: SelectItem(GetSelectedIndex() + 1); ShowListBox(); break; case SDLK_RETURN: case SDLK_SPACE: HideListBox(); break; case SDLK_TAB: HideListBox(); // intentional fall through: the parent frame will change focused widget default: // Forward all key downs to parent CMessageServer::Instance().QueueMessage(new CKeyboardMessage(CMessage::KEYBOARD_KEYDOWN, m_pParentWindow, this, pKeyboardMessage->ScanCode, pKeyboardMessage->Modifiers, pKeyboardMessage->Key, pKeyboardMessage->Unicode)); break; } } break; } case CMessage::MOUSE_BUTTONDOWN: { CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage); if (pMouseMessage->Button == CMouseMessage::LEFT) { if (m_pListBox->IsVisible() && m_pDropButton->GetWindowRect().SizeRect().HitTest(m_pDropButton->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE && m_pListBox->GetWindowRect().SizeRect().HitTest(m_pListBox->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE) { HideListBox(); } } break; } case CMessage::CTRL_SINGLELCLICK: { if (pMessage->Destination() == this) { if (pMessage->Source() == m_pDropButton) { if (m_pListBox->IsVisible()) { HideListBox(); } else { ShowListBox(); } bHandled = true; } } break; } case CMessage::CTRL_VALUECHANGE: { TIntMessage* pCtrlMessage = dynamic_cast<TIntMessage*>(pMessage); if (pCtrlMessage && pMessage->Destination() == this) { if (pCtrlMessage->Source() == m_pListBox) { const SListItem& ListItem = m_pListBox->GetItem(pCtrlMessage->Value()); SetWindowText(ListItem.sItemText); HideListBox(); CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0)); bHandled = true; } else if (pCtrlMessage->Source() == m_pEditBox) { m_pListBox->SetAllSelections(false); HideListBox(); CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0)); bHandled = true; } } break; } default : bHandled = CWindow::HandleMessage(pMessage); break; } } return bHandled; }
bool CDropDown::HandleMessage(CMessage* pMessage) { bool bHandled = false; CRect SubRect(m_WindowRect); SubRect.Grow(-3); if (pMessage) { switch(pMessage->MessageType()) { case CMessage::MOUSE_BUTTONDOWN: { CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage); if (pMouseMessage->Button == CMouseMessage::LEFT) { if (m_pListBox->IsVisible() && m_pDropButton->GetWindowRect().SizeRect().HitTest(m_pDropButton->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE && m_pListBox->GetWindowRect().SizeRect().HitTest(m_pListBox->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE) { HideListBox(); } } break; } case CMessage::CTRL_SINGLELCLICK: { if (pMessage->Destination() == this) { if (pMessage->Source() == m_pDropButton) { if (m_pListBox->IsVisible()) { HideListBox(); } else { ShowListBox(); } bHandled = true; } } break; } case CMessage::CTRL_VALUECHANGE: { TIntMessage* pCtrlMessage = dynamic_cast<TIntMessage*>(pMessage); if (pCtrlMessage && pMessage->Destination() == this) { if (pCtrlMessage->Source() == m_pListBox) { const SListItem& ListItem = m_pListBox->GetItem(pCtrlMessage->Value()); SetWindowText(ListItem.sItemText); HideListBox(); CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0)); bHandled = true; } else if (pCtrlMessage->Source() == m_pEditBox) { m_pListBox->SetAllSelections(false); HideListBox(); CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0)); bHandled = true; } } break; } default : bHandled = CWindow::HandleMessage(pMessage); break; } } return bHandled; }