void ButtonWindow::OnPaint(Canvas &canvas) { const bool focused = HasCursorKeys() ? HasFocus() : down; if (focused) { Pen pen(Layout::Scale(1), COLOR_BLACK); canvas.Select(pen); canvas.SelectHollowBrush(); canvas.Rectangle(-1, -1, canvas.GetWidth(), canvas.GetHeight()); } PixelRect rc(2, 2, canvas.GetWidth() - 4, canvas.GetHeight() - 4); if (down) { rc.left += Layout::FastScale(1); rc.top += Layout::FastScale(1); } canvas.DrawButton(GetClientRect(), down); canvas.SetTextColor(IsEnabled() ? (IsDithered() && down ? COLOR_WHITE : COLOR_BLACK) : COLOR_GRAY); canvas.SetBackgroundTransparent(); unsigned style = GetTextStyle(); if (IsDithered()) style |= DT_UNDERLINE; canvas.DrawFormattedText(&rc, text.c_str(), style); }
void paint(Canvas &canvas) { canvas.SelectHollowBrush(); canvas.SelectBlackPen(); Brush red_brush(COLOR_RED); const PixelRect rc = GetClientRect(); const int width = rc.right - rc.left; const int height = rc.bottom - rc.top; const int hmiddle = (rc.left + rc.right) / 2; const int vmiddle = (rc.top + rc.bottom) / 2; RasterPoint p1[3] = { { -100, vmiddle }, { (width * 2) / 3, -100 }, { hmiddle, height * 2 }, }; RasterPoint p2[3] = { { -2000, vmiddle }, { width * 10, -3000 }, { width * 5, 3000 }, }; const TCHAR *label; switch (page) { case 0: canvas.DrawSegment(hmiddle, vmiddle, min(width, height) / 3, Angle::Zero(), Angle::Degrees(90), false); label = _T("segment 0-90 horizon=false"); break; case 1: canvas.DrawSegment(hmiddle, vmiddle, min(width, height) / 3, Angle::Degrees(45), Angle::Degrees(180), true); label = _T("segment 45-180 horizon=true"); break; case 2: canvas.DrawCircle(hmiddle, vmiddle, min(width, height) / 3); label = _T("circle"); break; case 3: case 4: PixelRect rc; rc.left = hmiddle - 50; rc.top = vmiddle - 20; rc.right = hmiddle + 50; rc.bottom = vmiddle + 20; canvas.DrawButton(rc, page == 4); label = page == 4 ? _T("button down=true") : _T("button down=false"); break; case 5: canvas.Select(red_brush); canvas.DrawPolygon(p1, 3); label = _T("big polygon"); break; case 6: canvas.Select(red_brush); canvas.DrawPolygon(p2, 3); label = _T("huge polygon"); break; } canvas.SetTextColor(Color(0, 0, 128)); canvas.SetBackgroundTransparent(); canvas.Select(normal_font); canvas.DrawText(5, 5, label); #ifndef ENABLE_OPENGL canvas.DrawText(5, 25, buffered ? _T("buffered") : _T("not buffered")); #endif }
void ScrollBar::Paint(Canvas &canvas) const { // Prepare Pen canvas.SelectBlackPen(); // ################### // #### ScrollBar #### // ################### // draw rectangle around entire scrollbar area canvas.DrawTwoLines(rc.left, rc.top, rc.left, rc.bottom, rc.right, rc.bottom); canvas.DrawTwoLines(rc.right, rc.bottom, rc.right, rc.top, rc.left, rc.top); // ################### // #### Buttons #### // ################### UPixelScalar arrow_padding = max(UPixelScalar(GetWidth() / 4), UPixelScalar(4)); canvas.SelectBlackBrush(); PixelRect up_arrow_rect = rc; ++up_arrow_rect.left; up_arrow_rect.bottom = up_arrow_rect.top + GetWidth(); canvas.DrawLine(up_arrow_rect.left, up_arrow_rect.bottom, up_arrow_rect.right, up_arrow_rect.bottom); canvas.DrawButton(up_arrow_rect, false); RasterPoint up_arrow[3] = { { PixelScalar((up_arrow_rect.left + rc.right) / 2), PixelScalar(up_arrow_rect.top + arrow_padding) }, { PixelScalar(up_arrow_rect.left + arrow_padding), PixelScalar(up_arrow_rect.bottom - arrow_padding) }, { PixelScalar(rc.right - arrow_padding), PixelScalar(up_arrow_rect.bottom - arrow_padding) }, }; canvas.DrawTriangleFan(up_arrow, ARRAY_SIZE(up_arrow)); PixelRect down_arrow_rect = rc; ++down_arrow_rect.left; down_arrow_rect.top = down_arrow_rect.bottom - GetWidth(); canvas.DrawLine(down_arrow_rect.left, down_arrow_rect.top - 1, down_arrow_rect.right, down_arrow_rect.top - 1); canvas.DrawButton(down_arrow_rect, false); RasterPoint down_arrow[3] = { { PixelScalar((down_arrow_rect.left + rc.right) / 2), PixelScalar(down_arrow_rect.bottom - arrow_padding) }, { PixelScalar(down_arrow_rect.left + arrow_padding), PixelScalar(down_arrow_rect.top + arrow_padding) }, { PixelScalar(rc.right - arrow_padding), PixelScalar(down_arrow_rect.top + arrow_padding) }, }; canvas.DrawTriangleFan(down_arrow, ARRAY_SIZE(down_arrow)); // ################### // #### Slider #### // ################### if (rc_slider.top + 4 < rc_slider.bottom) { canvas.DrawLine(rc_slider.left, rc_slider.top, rc_slider.right, rc_slider.top); canvas.DrawLine(rc_slider.left, rc_slider.bottom, rc_slider.right, rc_slider.bottom); PixelRect rc_slider2 = rc_slider; ++rc_slider2.left; ++rc_slider2.top; canvas.DrawButton(rc_slider2, false); } // fill the rest with darker gray if (up_arrow_rect.bottom + 1 < rc_slider.top) canvas.DrawFilledRectangle(rc.left + 1, up_arrow_rect.bottom + 1, rc.right, rc_slider.top, COLOR_GRAY); if (rc_slider.bottom < down_arrow_rect.top) canvas.DrawFilledRectangle(rc.left + 1, rc_slider.bottom, rc.right, down_arrow_rect.top, COLOR_GRAY); }
void ScrollBar::Paint(Canvas &canvas) const { // ################### // #### ScrollBar #### // ################### // draw rectangle around entire scrollbar area canvas.SelectBlackPen(); canvas.SelectHollowBrush(); canvas.Rectangle(rc.left, rc.top, rc.right, rc.bottom); // ################### // #### Buttons #### // ################### const int arrow_padding = std::max(GetWidth() / 4, 4); PixelRect up_arrow_rect = rc; ++up_arrow_rect.left; up_arrow_rect.bottom = up_arrow_rect.top + GetWidth(); PixelRect down_arrow_rect = rc; ++down_arrow_rect.left; down_arrow_rect.top = down_arrow_rect.bottom - GetWidth(); canvas.DrawExactLine(up_arrow_rect.left, up_arrow_rect.bottom, up_arrow_rect.right, up_arrow_rect.bottom); canvas.DrawExactLine(down_arrow_rect.left, down_arrow_rect.top - 1, down_arrow_rect.right, down_arrow_rect.top - 1); canvas.DrawButton(up_arrow_rect, false); canvas.DrawButton(down_arrow_rect, false); canvas.SelectNullPen(); canvas.SelectBlackBrush(); const RasterPoint up_arrow[3] = { { (up_arrow_rect.left + rc.right) / 2, up_arrow_rect.top + arrow_padding }, { up_arrow_rect.left + arrow_padding, up_arrow_rect.bottom - arrow_padding }, { rc.right - arrow_padding, up_arrow_rect.bottom - arrow_padding }, }; canvas.DrawTriangleFan(up_arrow, ARRAY_SIZE(up_arrow)); const RasterPoint down_arrow[3] = { { (down_arrow_rect.left + rc.right) / 2, down_arrow_rect.bottom - arrow_padding }, { down_arrow_rect.left + arrow_padding, down_arrow_rect.top + arrow_padding }, { rc.right - arrow_padding, down_arrow_rect.top + arrow_padding }, }; canvas.DrawTriangleFan(down_arrow, ARRAY_SIZE(down_arrow)); // ################### // #### Slider #### // ################### if (rc_slider.top + 4 < rc_slider.bottom) { canvas.SelectBlackPen(); canvas.DrawExactLine(rc_slider.left, rc_slider.top, rc_slider.right, rc_slider.top); canvas.DrawExactLine(rc_slider.left, rc_slider.bottom, rc_slider.right, rc_slider.bottom); PixelRect rc_slider2 = rc_slider; ++rc_slider2.left; ++rc_slider2.top; canvas.DrawButton(rc_slider2, false); } // fill the rest with darker gray if (up_arrow_rect.bottom + 1 < rc_slider.top) canvas.DrawFilledRectangle(rc.left + 1, up_arrow_rect.bottom + 1, rc.right, rc_slider.top, COLOR_GRAY); if (rc_slider.bottom + 1 < down_arrow_rect.top - 1) canvas.DrawFilledRectangle(rc.left + 1, rc_slider.bottom + 1, rc.right, down_arrow_rect.top - 1, COLOR_GRAY); }
void paint(Canvas &canvas) { canvas.SelectHollowBrush(); canvas.SelectBlackPen(); Brush red_brush(COLOR_RED); const PixelRect rc = get_client_rect(); const UPixelScalar width = rc.right - rc.left; const UPixelScalar height = rc.bottom - rc.top; const UPixelScalar hmiddle = (rc.left + rc.right) / 2; const UPixelScalar vmiddle = (rc.top + rc.bottom) / 2; RasterPoint p1[3] = { { -100, PixelScalar(vmiddle) }, { PixelScalar((width * 2) / 3), -100 }, { PixelScalar(hmiddle), PixelScalar(height * 2) }, }; RasterPoint p2[3] = { { -2000, PixelScalar(vmiddle) }, { PixelScalar(width * 10), -3000 }, { PixelScalar(width * 5), 3000 }, }; const TCHAR *label; switch (page) { case 0: canvas.DrawSegment(hmiddle, vmiddle, min(width, height) / 3, Angle::Degrees(fixed_zero), Angle::Degrees(fixed(90)), false); label = _T("segment 0-90 horizon=false"); break; case 1: canvas.DrawSegment(hmiddle, vmiddle, min(width, height) / 3, Angle::Degrees(fixed(45)), Angle::Degrees(fixed_180), true); label = _T("segment 45-180 horizon=true"); break; case 2: canvas.circle(hmiddle, vmiddle, min(width, height) / 3); label = _T("circle"); break; case 3: case 4: PixelRect rc; rc.left = hmiddle - 50; rc.top = vmiddle - 20; rc.right = hmiddle + 50; rc.bottom = vmiddle + 20; canvas.DrawButton(rc, page == 4); label = page == 4 ? _T("button down=true") : _T("button down=false"); break; case 5: canvas.Select(red_brush); canvas.polygon(p1, 3); label = _T("big polygon"); break; case 6: canvas.Select(red_brush); canvas.polygon(p2, 3); label = _T("huge polygon"); break; } canvas.SetTextColor(Color(0, 0, 128)); canvas.text(5, 5, label); #ifndef ENABLE_OPENGL canvas.text(5, 25, buffered ? _T("buffered") : _T("not buffered")); #endif }