void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, wxHtmlRenderingInfo& info) { #if 0 // useful for debugging dc.SetPen(*wxRED_PEN); dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); #endif int xlocal = x + m_PosX; int ylocal = y + m_PosY; if (m_UseBkColour) { wxBrush myb = wxBrush(m_BkColour, wxBRUSHSTYLE_SOLID); int real_y1 = mMax(ylocal, view_y1); int real_y2 = mMin(ylocal + m_Height - 1, view_y2); dc.SetBrush(myb); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1); } if (m_Border == 1) { // draw thin border using lines wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID); wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID); dc.SetPen(mypen1); dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1); dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal); dc.SetPen(mypen2); dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1); dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1); } else if (m_Border> 0) { wxBrush mybrush1(m_BorderColour1, wxBRUSHSTYLE_SOLID); wxBrush mybrush2(m_BorderColour2, wxBRUSHSTYLE_SOLID); // draw upper left corner // 0---------------5 // | / // | 3-----------4 // | | // | 2 // |/ // 1 wxPoint poly[6]; poly[0].x =m_PosX; poly[0].y = m_PosY ; poly[1].x =m_PosX; poly[1].y = m_PosY + m_Height; poly[2].x =m_PosX + m_Border; poly[2].y = poly[1].y - m_Border; poly[3].x =poly[2].x ; poly[3].y = m_PosY + m_Border; poly[4].x =m_PosX + m_Width - m_Border; poly[4].y = poly[3].y; poly[5].x =m_PosX + m_Width; poly[5].y = m_PosY; dc.SetBrush(mybrush1); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawPolygon(6, poly, x, y); // draw lower right corner reusing point 1,2,4 and 5 // 5 // /| // 4 | // | | // 2-----------3 | // / | // 1---------------0 dc.SetBrush(mybrush2); poly[0].x = poly[5].x; poly[0].y = poly[1].y; poly[3].x = poly[4].x; poly[3].y = poly[2].y; dc.DrawPolygon(6, poly, x, y); // smooth color transition like firefox wxColour borderMediumColour( (m_BorderColour1.Red() + m_BorderColour2.Red()) /2 , (m_BorderColour1.Green() + m_BorderColour2.Green()) /2 , (m_BorderColour1.Blue() + m_BorderColour2.Blue()) /2 ); wxPen mypen3(borderMediumColour, 1, wxPENSTYLE_SOLID); dc.SetPen(mypen3); dc.DrawLines(2, &poly[1], x, y - 1); // between 1 and 2 dc.DrawLines(2, &poly[4], x, y - 1); // between 4 and 5 } if (m_Cells) { // draw container's contents: for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) { // optimize drawing: don't render off-screen content: if ((ylocal + cell->GetPosY() <= view_y2) && (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1)) { // the cell is visible, draw it: UpdateRenderingStatePre(info, cell); cell->Draw(dc, xlocal, ylocal, view_y1, view_y2, info); UpdateRenderingStatePost(info, cell); } else { // the cell is off-screen, proceed with font+color+etc. // changes only: cell->DrawInvisible(dc, xlocal, ylocal, info); } } } }
void SurfaceImpl::Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back) { PenColour(fore); BrushColour(back); hdc->DrawPolygon(npts, (wxPoint*)pts); }
void FlatAuiTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxCoord normal_textx, normal_texty; wxCoord selected_textx, selected_texty; wxCoord texty; wxFont m_selected_font = m_normal_font; // if the caption is empty, measure some temporary text wxString caption = page.caption; if (caption.empty()) caption = wxT("Xj"); dc.SetFont(m_selected_font); dc.GetTextExtent(caption, &selected_textx, &selected_texty); dc.SetFont(m_normal_font); dc.GetTextExtent(caption, &normal_textx, &normal_texty); // figure out the size of the tab wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxCoord tab_height = m_tab_ctrl_height - 3; wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height; caption = page.caption; // select pen, brush and font for the tab to be drawn if (page.active) { dc.SetFont(m_selected_font); texty = selected_texty; } else { dc.SetFont(m_normal_font); texty = normal_texty; } // create points that will make the tab outline int clip_width = tab_width; if (tab_x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - tab_x; /* wxPoint clip_points[6]; clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3); clip_points[1] = wxPoint(tab_x, tab_y+2); clip_points[2] = wxPoint(tab_x+2, tab_y); clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y); clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2); clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3); // FIXME: these ports don't provide wxRegion ctor from array of points #if !defined(__WXDFB__) && !defined(__WXCOCOA__) // set the clipping region for the tab -- wxRegion clipping_region(WXSIZEOF(clip_points), clip_points); dc.SetClippingRegion(clipping_region); #endif // !wxDFB && !wxCocoa */ // since the above code above doesn't play well with WXDFB or WXCOCOA, // we'll just use a rectangle for the clipping region for now -- dc.SetClippingRegion(tab_x, tab_y, clip_width+1, tab_height-3); wxPoint border_points[4]; if (m_flags &wxAUI_NB_BOTTOM) { border_points[0] = wxPoint(tab_x, tab_y); border_points[1] = wxPoint(tab_x, tab_y+tab_height-4); border_points[2] = wxPoint(tab_x+tab_width, tab_y+tab_height-4); border_points[3] = wxPoint(tab_x+tab_width, tab_y); } else //if (m_flags & wxAUI_NB_TOP) {} { border_points[0] = wxPoint(tab_x, tab_y+tab_height); border_points[1] = wxPoint(tab_x, tab_y); border_points[2] = wxPoint(tab_x+tab_width, tab_y); border_points[3] = wxPoint(tab_x+tab_width, tab_y+tab_height); } // else if (m_flags &wxAUI_NB_LEFT) {} // else if (m_flags &wxAUI_NB_RIGHT) {} int drawn_tab_yoff = border_points[1].y; int drawn_tab_height = border_points[0].y - border_points[1].y; if (page.active) { // draw active tab // draw base background color wxRect r(tab_x, tab_y, tab_width, tab_height); dc.SetPen(wxPen(m_active_colour)); dc.SetBrush(wxBrush(m_active_colour)); dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4); // this white helps fill out the gradient at the top of the tab dc.SetPen(*wxWHITE_PEN); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4); // these two points help the rounded corners appear more antialiased dc.SetPen(wxPen(m_active_colour)); dc.DrawPoint(r.x+2, r.y+1); dc.DrawPoint(r.x+r.width-2, r.y+1); // set rectangle down a bit for gradient drawing //r.SetHeight(r.GetHeight()/2); r.x += 2; r.width -= 2; /*r.y += r.height; r.y -= 2;*/ r.y += 1; r.height -= 2; // draw gradient background wxColor top_color = m_active_colour; wxColor bottom_color = m_active_colour; dc.GradientFillLinear(r, bottom_color, top_color, wxSOUTH); // Adapt text color int average = (m_active_colour.Red()+m_active_colour.Green()+m_active_colour.Blue())/3; if (average < 127) dc.SetTextForeground(*wxWHITE); else dc.SetTextForeground(*wxBLACK); } else { // draw inactive tab wxRect r(tab_x, tab_y+1, tab_width, tab_height-3); // start the gradent up a bit and leave the inside border inset // by a pixel for a 3D look. Only the top half of the inactive // tab will have a slight gradient r.x += 3; r.y++; r.width -= 4; r.height /= 2; r.height--; // -- draw top gradient fill for glossy look wxColor top_color = m_base_colour; wxColor bottom_color = gdAuiStepColour(top_color, 160); dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); r.y += r.height; r.y--; // -- draw bottom fill for glossy look top_color = m_base_colour; bottom_color = m_base_colour; dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); // Adapt text color int average = (m_base_colour.Red()+m_base_colour.Green()+m_base_colour.Blue())/3; if (average < 127) dc.SetTextForeground(*wxWHITE); else dc.SetTextForeground(*wxBLACK); } // draw tab outline dc.SetPen(m_border_pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawPolygon(WXSIZEOF(border_points), border_points); // there are two horizontal grey lines at the bottom of the tab control, // this gets rid of the top one of those lines in the tab control if (page.active) { if (m_flags &wxAUI_NB_BOTTOM) dc.SetPen(wxPen(wxColour(gdAuiStepColour(m_base_colour, 170)))); // else if (m_flags &wxAUI_NB_LEFT) {} // else if (m_flags &wxAUI_NB_RIGHT) {} else //for wxAUI_NB_TOP dc.SetPen(m_base_colour_pen); //Game Develop use white pen so as to conform to white background dc.SetPen(*wxWHITE_PEN); dc.DrawLine(border_points[0].x+1, border_points[0].y, border_points[5].x, border_points[5].y); } int text_offset = tab_x + 8; int close_button_width = 0; if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { close_button_width = m_active_close_bmp.GetWidth(); } int bitmap_offset = 0; if (page.bitmap.IsOk()) { bitmap_offset = tab_x + 8; // draw bitmap dc.DrawBitmap(page.bitmap, bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), true); text_offset = bitmap_offset + page.bitmap.GetWidth(); text_offset += 3; // bitmap padding } else { text_offset = tab_x + 8; } wxString draw_text = gdAuiChopText(dc, caption, tab_width - (text_offset-tab_x) - close_button_width); // draw tab text dc.DrawText(draw_text, text_offset, drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1); // draw focus rectangle if (page.active && (wnd->FindFocus() == wnd)) { wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1), selected_textx, selected_texty); wxRect focusRect; wxRect focusRectBitmap; if (page.bitmap.IsOk()) focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), page.bitmap.GetWidth(), page.bitmap.GetHeight()); if (page.bitmap.IsOk() && draw_text.IsEmpty()) focusRect = focusRectBitmap; else if (!page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText; else if (page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText.Union(focusRectBitmap); focusRect.Inflate(2, 2); wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); } // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { wxBitmap bmp = m_disabled_close_bmp; if (close_button_state == wxAUI_BUTTON_STATE_HOVER || close_button_state == wxAUI_BUTTON_STATE_PRESSED) { bmp = m_active_close_bmp; } wxRect rect(tab_x + tab_width - close_button_width - 1, tab_y + (tab_height/2) - (bmp.GetHeight()/2), close_button_width, tab_height); IndentPressedBitmap(&rect, close_button_state); dc.DrawBitmap(bmp, rect.x, rect.y, true); *out_button_rect = rect; } *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); }
static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g) { switch (g->control_group->type) { case GROUP_TYPE_TILT : case GROUP_TYPE_STICK : case GROUP_TYPE_CURSOR : { // this is starting to be a mess combining all these in one case ControlState x = 0, y = 0, z = 0; switch (g->control_group->type) { case GROUP_TYPE_STICK : ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y); break; case GROUP_TYPE_TILT : ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y); break; case GROUP_TYPE_CURSOR : ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); break; } // ir cursor forward movement if (GROUP_TYPE_CURSOR == g->control_group->type) { if (z) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); } else { dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); } dc.DrawRectangle(0, 31 - z*31, 64, 2); } // octagon for visual aid for diagonal adjustment dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxWHITE_BRUSH); if (GROUP_TYPE_STICK == g->control_group->type) { // outline and fill colors wxBrush LightGrayBrush("#dddddd"); wxPen LightGrayPen("#bfbfbf"); dc.SetBrush(LightGrayBrush); dc.SetPen(LightGrayPen); // polygon offset ControlState max , diagonal , box = 64 , d_of = box / 256.0 , x_of = box / 2.0; if (g->control_group->name == "Main Stick") { max = (87.0 / 127.0) * 100; diagonal = (55.0 / 127.0) * 100; } else if (g->control_group->name == "C-Stick") { max = (74.0 / 127.0) * 100; diagonal = (46.0 / 127.0) * 100; } else { max = (82.0 / 127.0) * 100; diagonal = (58.0 / 127.0) * 100; } // polygon corners wxPoint Points[8]; Points[0].x = (int)(0.0 * d_of + x_of); Points[0].y = (int)(max * d_of + x_of); Points[1].x = (int)(diagonal * d_of + x_of); Points[1].y = (int)(diagonal * d_of + x_of); Points[2].x = (int)(max * d_of + x_of); Points[2].y = (int)(0.0 * d_of + x_of); Points[3].x = (int)(diagonal * d_of + x_of); Points[3].y = (int)(-diagonal * d_of + x_of); Points[4].x = (int)(0.0 * d_of + x_of); Points[4].y = (int)(-max * d_of + x_of); Points[5].x = (int)(-diagonal * d_of + x_of); Points[5].y = (int)(-diagonal * d_of + x_of); Points[6].x = (int)(-max * d_of + x_of); Points[6].y = (int)(0.0 * d_of + x_of); Points[7].x = (int)(-diagonal * d_of + x_of); Points[7].y = (int)(diagonal * d_of + x_of); // draw polygon dc.DrawPolygon(8, Points); } else { dc.DrawRectangle(16, 16, 32, 32); } if (GROUP_TYPE_CURSOR != g->control_group->type) { // deadzone circle dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawCircle(32, 32, g->control_group->settings[SETTING_DEADZONE]->value * 32); } // raw dot { ControlState xx, yy; xx = g->control_group->controls[3]->control_ref->State(); xx -= g->control_group->controls[2]->control_ref->State(); yy = g->control_group->controls[1]->control_ref->State(); yy -= g->control_group->controls[0]->control_ref->State(); dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); DrawCoordinate(dc, xx, yy); } // adjusted dot if (x != 0 && y != 0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); // XXX: The adjusted values flip the Y axis to be in the format // the Wii expects. Should this be in WiimoteEmu.cpp instead? DrawCoordinate(dc, x, -y); } } break; case GROUP_TYPE_FORCE : { ControlState raw_dot[3]; ControlState adj_dot[3]; const ControlState deadzone = g->control_group->settings[0]->value; // adjusted ((ControllerEmu::Force*)g->control_group)->GetState(adj_dot); // raw for (unsigned int i=0; i<3; ++i) { raw_dot[i] = (g->control_group->controls[i*2 + 1]->control_ref->State() - g->control_group->controls[i*2]->control_ref->State()); } // deadzone rect for forward/backward visual dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.SetPen(*wxLIGHT_GREY_PEN); int deadzone_height = deadzone * VIS_BITMAP_SIZE; DrawCenteredRectangle(dc, 0, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE, deadzone_height); #define LINE_HEIGHT 2 int line_y; // raw forward/background line dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); line_y = VIS_COORD(raw_dot[2]); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT); // adjusted forward/background line if (adj_dot[2] != 0.0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); line_y = VIS_COORD(adj_dot[2]); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, line_y, VIS_BITMAP_SIZE, LINE_HEIGHT); } #define DEADZONE_RECT_SIZE 32 // empty deadzone square dc.SetBrush(*wxWHITE_BRUSH); dc.SetPen(*wxLIGHT_GREY_PEN); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, DEADZONE_RECT_SIZE, DEADZONE_RECT_SIZE); // deadzone square dc.SetBrush(*wxLIGHT_GREY_BRUSH); int dz_size = (deadzone * DEADZONE_RECT_SIZE); DrawCenteredRectangle(dc, VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, dz_size, dz_size); // raw dot dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); DrawCoordinate(dc, raw_dot[1], raw_dot[0]); // adjusted dot if (adj_dot[1] != 0 && adj_dot[0] != 0) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); DrawCoordinate(dc, adj_dot[1], adj_dot[0]); } } break; case GROUP_TYPE_BUTTONS : { const unsigned int button_count = ((unsigned int)g->control_group->controls.size()); // draw the shit dc.SetPen(*wxGREY_PEN); unsigned int * const bitmasks = new unsigned int[ button_count ]; for (unsigned int n = 0; n<button_count; ++n) bitmasks[n] = (1 << n); unsigned int buttons = 0; ((ControllerEmu::Buttons*)g->control_group)->GetState(&buttons, bitmasks); for (unsigned int n = 0; n<button_count; ++n) { if (buttons & bitmasks[n]) { dc.SetBrush(*wxRED_BRUSH); } else { unsigned char amt = 255 - g->control_group->controls[n]->control_ref->State() * 128; dc.SetBrush(wxBrush(wxColour(amt, amt, amt))); } dc.DrawRectangle(n * 12, 0, 14, 12); // text const std::string name = g->control_group->controls[n]->name; // bit of hax so ZL, ZR show up as L, R dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n*12 + 2, 1); } delete[] bitmasks; } break; case GROUP_TYPE_TRIGGERS : { const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size())); // draw the shit dc.SetPen(*wxGREY_PEN); ControlState deadzone = g->control_group->settings[0]->value; ControlState* const trigs = new ControlState[trigger_count]; ((ControllerEmu::Triggers*)g->control_group)->GetState(trigs); for (unsigned int n = 0; n < trigger_count; ++n) { ControlState trig_r = g->control_group->controls[n]->control_ref->State(); // outline dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(0, n*12, 64, 14); // raw dc.SetBrush(*wxGREY_BRUSH); dc.DrawRectangle(0, n*12, trig_r*64, 14); // deadzone affected dc.SetBrush(*wxRED_BRUSH); dc.DrawRectangle(0, n*12, trigs[n]*64, 14); // text dc.DrawText(StrToWxStr(g->control_group->controls[n]->name), 3, n*12 + 1); } delete[] trigs; // deadzone box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14); } break; case GROUP_TYPE_MIXED_TRIGGERS : { const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2)); // draw the shit dc.SetPen(*wxGREY_PEN); ControlState thresh = g->control_group->settings[0]->value; for (unsigned int n = 0; n < trigger_count; ++n) { dc.SetBrush(*wxRED_BRUSH); ControlState trig_d = g->control_group->controls[n]->control_ref->State(); ControlState trig_a = trig_d > thresh ? 1 : g->control_group->controls[n+trigger_count]->control_ref->State(); dc.DrawRectangle(0, n*12, 64+20, 14); if (trig_d <= thresh) dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(trig_a*64, n*12, 64+20, 14); dc.DrawRectangle(64, n*12, 32, 14); // text dc.DrawText(StrToWxStr(g->control_group->controls[n+trigger_count]->name), 3, n*12 + 1); dc.DrawText(StrToWxStr(std::string(1, g->control_group->controls[n]->name[0])), 64 + 3, n*12 + 1); } // threshold box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14); } break; case GROUP_TYPE_SLIDER: { const ControlState deadzone = g->control_group->settings[0]->value; ControlState state = g->control_group->controls[1]->control_ref->State() - g->control_group->controls[0]->control_ref->State(); dc.SetPen(*wxGREY_PEN); dc.SetBrush(*wxGREY_BRUSH); dc.DrawRectangle(31 + state * 30, 0, 2, 14); ControlState adj_state; ((ControllerEmu::Slider*)g->control_group)->GetState(&adj_state); if (state) { dc.SetPen(*wxRED_PEN); dc.SetBrush(*wxRED_BRUSH); dc.DrawRectangle(31 + adj_state * 30, 0, 2, 14); } // deadzone box dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(32 - deadzone * 32, 0, deadzone * 64, 14); } break; default: break; } }
void LabelTrack::Draw(wxDC & dc, wxRect & r, double h, double pps, double sel0, double sel1) { double right = h + r.width / pps; double dsel0 = sel0; if (dsel0 < h) dsel0 = h; if (dsel0 > right) dsel0 = right; double dsel1 = sel1; if (dsel1 < h) dsel1 = h; if (dsel1 > right) dsel1 = right; wxRect before = r; before.width = int ((dsel0 - h) * pps); dc.SetBrush(mUnselectedBrush); dc.SetPen(mUnselectedPen); dc.DrawRectangle(before); wxRect selr = r; selr.x += before.width; selr.width = int ((dsel1 - dsel0) * pps); dc.SetBrush(mSelectedBrush); dc.SetPen(mSelectedPen); dc.DrawRectangle(selr); wxRect after = r; after.x += (before.width + selr.width); after.width -= (before.width + selr.width); if (after.x < r.x) { after.width -= (r.x - after.x); after.x = r.x; } dc.SetBrush(mUnselectedBrush); dc.SetPen(mUnselectedPen); dc.DrawRectangle(after); dc.SetBrush(mFlagBrush); dc.SetPen(mFlagPen); int nextx = 0; for (int i = 0; i < (int)mLabels.Count(); i++) { int x = r.x + (int) ((mLabels[i]->t - h) * pps); int y = r.y; int height = r.height; if (x >= r.x && x < r.x + r.width) { if (x < nextx && i != mSelIndex) { // Draw flag obscured by the previous label dc.DrawLine(x, y, x, y + 2); dc.DrawLine(x, y + height - 2, x, y + height); mLabels[i]->width = 0; } else { // Draw the flag and label wxPoint tri[3]; tri[0].x = x; tri[0].y = y; tri[1].x = x - 8; tri[1].y = y + 4; tri[2].x = x; tri[2].y = y + 8; if (mSelIndex == i) dc.SetBrush(*wxWHITE_BRUSH); dc.DrawPolygon(3, tri); if (mSelIndex == i) dc.SetBrush(mFlagBrush); dc.DrawLine(x, y, x, y + height); dc.SetTextForeground(wxColour(204, 0, 0)); #ifdef __WXMAC__ long textWidth, textHeight; #else int textWidth, textHeight; #endif dc.GetTextExtent(mLabels[i]->title, &textWidth, &textHeight); dc.DrawText(mLabels[i]->title, x + 4, y + 4); if (i == mSelIndex) { wxRect outline; outline.x = x + 2; outline.y = y + 2; outline.width = textWidth + 4; outline.height = height - 4; dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(outline); dc.SetBrush(mFlagBrush); } mLabels[i]->width = textWidth + 8; nextx = x + textWidth + 8; } } } }
void wxCstmTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxCoord normal_textx, normal_texty; wxCoord selected_textx, selected_texty; wxCoord textx, texty; // if the caption is empty, measure some temporary text wxString caption = page.caption; if (caption.empty()) caption = wxT("Xj"); dc.SetFont(m_selectedFont); dc.GetTextExtent(caption, &selected_textx, &selected_texty); dc.SetFont(m_normalFont); dc.GetTextExtent(caption, &normal_textx, &normal_texty); // figure out the size of the tab wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxCoord tab_height = tab_size.y; wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height; caption = page.caption; // select pen, brush and font for the tab to be drawn if (page.active) { dc.SetPen(m_selectedBkPen); dc.SetBrush(m_selectedBkBrush); dc.SetFont(m_selectedFont); textx = selected_textx; texty = selected_texty; } else { dc.SetPen(m_normalBkPen); dc.SetBrush(m_normalBkBrush); dc.SetFont(m_normalFont); textx = normal_textx; texty = normal_texty; } /* wxPoint points[7]; points[0].x = tab_x; points[0].y = tab_y + tab_height - 1; points[1].x = tab_x + tab_height - 3; points[1].y = tab_y + 2; points[2].x = tab_x + tab_height + 3; points[2].y = tab_y; points[3].x = tab_x + tab_width - 2; points[3].y = tab_y; points[4].x = tab_x + tab_width; points[4].y = tab_y + 2; points[5].x = tab_x + tab_width; points[5].y = tab_y + tab_height - 1; points[6] = points[0]; */ // -- draw line -- wxPoint points[7]; points[0].x = tab_x; points[0].y = tab_y + tab_height - 1; points[1].x = tab_x + tab_height - 3; points[1].y = tab_y + 2; points[2].x = tab_x + tab_height + 3; points[2].y = tab_y; points[3].x = tab_x + tab_width - 3; points[3].y = tab_y; points[4].x = tab_x + tab_width + 3; points[4].y = tab_y + 2; points[5].x = tab_x + tab_width + tab_height; points[5].y = tab_y + tab_height - 1; points[6] = points[0]; dc.SetClippingRegion(in_rect); dc.DrawPolygon(WXSIZEOF(points) - 1, points); //dc.SetPen(*wxGREY_PEN); if (page.active) { dc.SetPen(*wxBLACK_PEN); } else { dc.SetPen(*wxBLACK_PEN); } //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points); dc.DrawLines(WXSIZEOF(points), points); int text_offset; int close_button_width = 0; if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { close_button_width = m_activeCloseBmp.GetWidth(); text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); } else { text_offset = tab_x + (tab_height/3) + (tab_width/2) - (textx/2); } // set minimum text offset if (text_offset < tab_x + tab_height) text_offset = tab_x + tab_height; // chop text if necessary wxString draw_text = wxAuiChopText(dc, caption, tab_width - (text_offset-tab_x) - close_button_width); // draw tab text dc.SetTextForeground(page.active ? m_selectedTextColour : m_normalTextColour); dc.DrawText(draw_text, text_offset, (tab_y + tab_height)/2 - (texty/2) + 1); // draw focus rectangle if (page.active && (wnd->FindFocus() == wnd)) { wxRect focusRect(text_offset, ((tab_y + tab_height)/2 - (texty/2) + 1), selected_textx, selected_texty); focusRect.Inflate(2, 2); wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); } // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { wxBitmap bmp; if (page.active) bmp = m_activeCloseBmp; else bmp = m_disabledCloseBmp; wxRect rect(tab_x + tab_width - close_button_width - 1, tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, close_button_width, tab_height - 1); DrawButtons(dc, rect, bmp, *wxWHITE, close_button_state); *out_button_rect = rect; } *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); }
void clTabRendererCurved::Draw(wxDC& dc, const clTabInfo& tabInfo, const clTabColours& colours, size_t style) { const int TOP_SMALL_HEIGHT = 0; wxColour bgColour(tabInfo.IsActive() ? colours.activeTabBgColour : colours.inactiveTabBgColour); wxColour penColour(tabInfo.IsActive() ? colours.activeTabPenColour : colours.inactiveTabPenColour); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); dc.SetTextForeground(tabInfo.IsActive() ? colours.activeTabTextColour : colours.inactiveTabTextColour); dc.SetFont(font); if(style & kNotebook_BottomTabs) { // Bottom tabs { wxPoint points[6]; points[0] = tabInfo.m_rect.GetTopLeft(); points[1].x = points[0].x + majorCurveWidth; points[1].y = tabInfo.m_rect.GetBottomLeft().y - TOP_SMALL_HEIGHT; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y + TOP_SMALL_HEIGHT; points[3].x = points[0].x + (tabInfo.m_rect.GetWidth() - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[1].y; points[5] = tabInfo.m_rect.GetTopRight(); dc.SetPen(penColour); dc.SetBrush(bgColour); dc.DrawPolygon(6, points); } { wxPoint points[6]; points[0] = tabInfo.m_rect.GetTopLeft(); points[0].x += 1; points[1].x = points[0].x + majorCurveWidth; points[1].y = tabInfo.m_rect.GetBottomLeft().y - TOP_SMALL_HEIGHT - 1; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y + TOP_SMALL_HEIGHT; points[3].x = points[0].x + (tabInfo.m_rect.GetWidth() - 2 - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[1].y; points[5] = tabInfo.m_rect.GetTopRight(); points[5].x -= 2; dc.SetPen(tabInfo.IsActive() ? colours.activeTabInnerPenColour : colours.inactiveTabInnerPenColour); dc.SetBrush(bgColour); dc.DrawPolygon(6, points); } } else if(IS_VERTICAL_TABS(style)) { // Left side tabs wxRect rotatedRect(0, 0, tabInfo.m_rect.GetHeight(), tabInfo.m_rect.GetWidth()); wxBitmap b(rotatedRect.GetSize()); wxMemoryDC tmpDC(b); tmpDC.SetPen(colours.tabAreaColour); tmpDC.SetBrush(colours.tabAreaColour); tmpDC.DrawRectangle(rotatedRect); tmpDC.SetFont(font); tmpDC.SetTextForeground(tabInfo.IsActive() ? colours.activeTabTextColour : colours.inactiveTabTextColour); tmpDC.SetPen(penColour); tmpDC.SetBrush(bgColour); if(tabInfo.IsActive()) { { wxPoint points[6]; points[0] = rotatedRect.GetBottomLeft(); points[1].x = points[0].x + majorCurveWidth; points[1].y = rotatedRect.GetLeftTop().y + TOP_SMALL_HEIGHT; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y - TOP_SMALL_HEIGHT; points[3].x = points[0].x + (rotatedRect.GetWidth() - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[3].y + TOP_SMALL_HEIGHT; points[5] = rotatedRect.GetBottomRight(); tmpDC.SetPen(penColour); tmpDC.SetBrush(bgColour); tmpDC.DrawPolygon(6, points); } { wxPoint points[6]; points[0] = rotatedRect.GetBottomLeft(); points[0].x += 1; points[1].x = points[0].x + majorCurveWidth; points[1].y = rotatedRect.GetLeftTop().y + TOP_SMALL_HEIGHT + 1; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y - TOP_SMALL_HEIGHT; points[3].x = points[0].x + (rotatedRect.GetWidth() - 2 - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[3].y + TOP_SMALL_HEIGHT; points[5] = rotatedRect.GetBottomRight(); points[5].x -= 2; tmpDC.SetPen(tabInfo.IsActive() ? colours.activeTabInnerPenColour : colours.inactiveTabInnerPenColour); tmpDC.SetBrush(bgColour); tmpDC.DrawPolygon(6, points); } } else { // Inactive tabs wxDirection direction = wxNORTH; wxPoint basePoint = ((style & kNotebook_LeftTabs) ? rotatedRect.GetLeftTop() : rotatedRect.GetRightTop()); { wxPoint pt = basePoint; pt.x -= 1; wxRect gr(pt, wxSize(1, rotatedRect.GetHeight())); tmpDC.SetPen(*wxTRANSPARENT_PEN); tmpDC.GradientFillLinear(gr, colours.inactiveTabPenColour, bgColour, direction); } { wxPoint pt = basePoint; wxRect gr(pt, wxSize(1, rotatedRect.GetHeight())); tmpDC.SetPen(*wxTRANSPARENT_PEN); tmpDC.GradientFillLinear(gr, colours.inactiveTabInnerPenColour, bgColour, direction); } { wxPoint pt = basePoint; pt.x += 1; wxRect gr(pt, wxSize(1, rotatedRect.GetHeight())); tmpDC.SetPen(*wxTRANSPARENT_PEN); tmpDC.GradientFillLinear(gr, colours.inactiveTabPenColour, bgColour, direction); } } // Vertical tabs // Draw bitmap if(tabInfo.GetBitmap().IsOk()) { tmpDC.DrawBitmap(tabInfo.GetBitmap(), tabInfo.m_bmpY, tabInfo.m_bmpX); } tmpDC.DrawText(tabInfo.m_label, tabInfo.m_textY, tabInfo.m_textX); if(tabInfo.IsActive() && (style & kNotebook_CloseButtonOnActiveTab)) { tmpDC.DrawBitmap(colours.closeButton, tabInfo.m_bmpCloseY, tabInfo.m_bmpCloseX); } tmpDC.SelectObject(wxNullBitmap); wxImage img = b.ConvertToImage(); img = img.Rotate90((style & kNotebook_RightTabs)); b = wxBitmap(img); dc.DrawBitmap(b, tabInfo.m_rect.GetTopLeft()); } else { // Default tabs (placed at the top) { wxPoint points[6]; points[0] = tabInfo.m_rect.GetBottomLeft(); points[1].x = points[0].x + majorCurveWidth; points[1].y = tabInfo.m_rect.GetLeftTop().y + TOP_SMALL_HEIGHT; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y - TOP_SMALL_HEIGHT; points[3].x = points[0].x + (tabInfo.m_rect.GetWidth() - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[3].y + TOP_SMALL_HEIGHT; points[5] = tabInfo.m_rect.GetBottomRight(); dc.SetPen(penColour); dc.SetBrush(bgColour); dc.DrawPolygon(6, points); } { wxPoint points[6]; points[0] = tabInfo.m_rect.GetBottomLeft(); points[0].x += 1; points[1].x = points[0].x + majorCurveWidth; points[1].y = tabInfo.m_rect.GetLeftTop().y + TOP_SMALL_HEIGHT + 1; points[2].x = points[1].x + smallCurveWidth; points[2].y = points[1].y - TOP_SMALL_HEIGHT; points[3].x = points[0].x + (tabInfo.m_rect.GetWidth() - 2 - (majorCurveWidth + smallCurveWidth)); points[3].y = points[2].y; points[4].x = points[3].x + smallCurveWidth; points[4].y = points[3].y + TOP_SMALL_HEIGHT; points[5] = tabInfo.m_rect.GetBottomRight(); points[5].x -= 2; dc.SetPen(tabInfo.IsActive() ? colours.activeTabInnerPenColour : colours.inactiveTabInnerPenColour); dc.SetBrush(bgColour); dc.DrawPolygon(6, points); } } if(!IS_VERTICAL_TABS(style)) { // Draw bitmap if(tabInfo.GetBitmap().IsOk()) { dc.DrawBitmap(tabInfo.GetBitmap(), tabInfo.m_bmpX + tabInfo.m_rect.GetX(), tabInfo.m_bmpY); } dc.DrawText(tabInfo.m_label, tabInfo.m_textX + tabInfo.m_rect.GetX(), tabInfo.m_textY); if(tabInfo.IsActive() && (style & kNotebook_CloseButtonOnActiveTab)) { dc.DrawBitmap(colours.closeButton, tabInfo.m_bmpCloseX + tabInfo.m_rect.GetX(), tabInfo.m_bmpCloseY); } } }
void wxGridCellChoiceRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rectCell, int row, int col, bool isSelected) { wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected); // first calculate button size // don't draw outside the cell int nButtonWidth = 17; if (rectCell.height < 2) return; wxRect rectButton; rectButton.x = rectCell.x + rectCell.width - nButtonWidth; rectButton.y = rectCell.y + 1; int cell_rows, cell_cols; attr.GetSize(&cell_rows, &cell_cols); rectButton.width = nButtonWidth; if (cell_rows == 1) rectButton.height = rectCell.height-2; else rectButton.height = nButtonWidth; SetTextColoursAndFont(grid, attr, dc, isSelected); int hAlign, vAlign; attr.GetAlignment(&hAlign, &vAlign); // leave room for button wxRect rect = rectCell; rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2); rect.Inflate(-1); grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign); // don't bother drawing if the cell is too small if (rectButton.height < 4 || rectButton.width < 4) return; // draw 3-d button wxColour colourBackGround = wxColour(COLORBASE); dc.SetBrush(wxBrush(colourBackGround, wxSOLID)); dc.SetPen(wxPen(colourBackGround, 1, wxSOLID)); dc.DrawRectangle(rectButton); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID)); dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(), rectButton.GetRight(), rectButton.GetBottom()); dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(), rectButton.GetRight(), rectButton.GetTop()-1); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW), 1, wxSOLID)); dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1, rectButton.GetRight()-1, rectButton.GetBottom()-1); dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1, rectButton.GetRight()-1, rectButton.GetTop()); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT), 1, wxSOLID)); dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1, rectButton.GetLeft()+1, rectButton.GetTop()+1); dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1, rectButton.GetLeft()+1, rectButton.GetBottom()-1); // Draw little triangle int nTriWidth = 7; int nTriHeight = 4; wxPoint point[3]; point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nTriWidth)/2, rectButton.GetTop()+(rectButton.GetHeight()-nTriHeight)/2); point[1] = wxPoint(point[0].x+nTriWidth-1, point[0].y); point[2] = wxPoint(point[0].x+3, point[0].y+nTriHeight-1); dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID)); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID)); dc.DrawPolygon(3, point); if (m_border == wxLAYOUT_TOP) { dc.SetPen(wxPen(*wxBLACK, 1, wxDOT)); dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(), rectCell.GetLeft(), rectCell.GetTop()); } }
//void simple_vector_layer::Draw(wxDC &dc, wxCoord x, wxCoord y, bool transparent, double zoomFactor, double translationX, double translationY, double resolution) const void simple_vector_layer::draw(wxDC &dc, wxCoord x, wxCoord y, bool transparent) const { wxPen pen; wxBrush brush; // 2D pen.SetWidth(m_polygon_border_width); pen.SetColour(m_polygon_border_color); pen.SetStyle(m_polygon_border_style); brush.SetColour(m_polygon_inner_color); brush.SetStyle(m_polygon_inner_style); dc.SetPen(pen); dc.SetBrush(brush); for (unsigned int i = 0; i < m_circles.size(); i++) { wxPoint p = transform().from_local_int(m_circles[i]); wxCoord r = static_cast<wxCoord>(m_circles[i].radius / transform().zoom_factor()); dc.DrawCircle(p, r); } // Ellipses alignees for (unsigned int i=0;i<m_ellipses.size();++i) { wxPoint p = transform().from_local_int(m_ellipses[i]); wxSize s( static_cast<wxCoord>(2*m_ellipses[i].a/transform().zoom_factor()), static_cast<wxCoord>(2*m_ellipses[i].b/transform().zoom_factor()) ); dc.DrawEllipse(p,s); //dc.DrawEllipticArc(p,s,0.,90.); //dc.DrawEllipticArcRot(p,s,0.,90.); } // Ellipses non alignees for (unsigned int i=0;i<m_rotatedellipses.size();++i) { std::vector<wxPoint> points; points.reserve( m_rotatedellipses[i].controlPoints.size() ); for (unsigned int j=0;j<m_rotatedellipses[i].controlPoints.size();++j) points.push_back(transform().from_local_int(m_rotatedellipses[i].controlPoints[j])); dc.DrawSpline(static_cast<int>(points.size()),&points.front()); } for (unsigned int i=0;i<m_polygons.size();++i) { std::vector<wxPoint> points; points.reserve( m_polygons[i].size() ); for (unsigned int j=0;j<m_polygons[i].size();++j) points.push_back(transform().from_local_int(m_polygons[i][j])); dc.DrawPolygon( static_cast<int>(points.size()) , &(points.front()) ); } // 1D pen.SetColour(m_line_color); pen.SetWidth(m_line_width); pen.SetStyle(m_line_style); dc.SetPen(pen); for (unsigned int i = 0; i < m_arcs.size(); i++) { const arc_type &local_tab = m_arcs[i]; for (unsigned int j = 0; j < local_tab.arc_points.size() - 1; ++j) { wxPoint p = transform().from_local_int(local_tab.arc_points[j ]); wxPoint q = transform().from_local_int(local_tab.arc_points[j+1]); dc.DrawLine(p,q); } } // Splines for (unsigned int i=0;i<m_splines.size();++i) { const spline_type& spline = m_splines[i]; std::vector<wxPoint> points; unsigned int n = static_cast<int>(spline.size()); for (unsigned int j=0;j<n;++j) { wxPoint p = transform().from_local_int(spline[j]); points.push_back(p); } dc.DrawSpline(n,&points.front()); } // 0D pen.SetColour(m_point_color); pen.SetWidth(m_point_width); dc.SetPen(pen); for (unsigned int i = 0; i < m_points.size(); i++) { wxPoint p = transform().from_local_int(m_points[i]); //dc.DrawLine(p); dc.DrawPoint(p); } // Text if(text_visibility()) { pen.SetColour(m_text_color); dc.SetPen(pen); for (unsigned int i = 0; i < m_texts.size(); i++) { wxPoint p = transform().from_local_int(m_texts[i].first); //dc.DrawLine(p); dc.DrawText(wxString(m_texts[i].second.c_str(),*wxConvCurrent),p); } } }
void SAuiTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxCoord normal_textx, normal_texty; wxCoord selected_textx, selected_texty; wxCoord texty; // if the caption is empty, measure some temporary text wxString caption = page.caption; if (caption.empty()) caption = wxT("Xj"); dc.SetFont(m_selectedFont); dc.GetTextExtent(caption, &selected_textx, &selected_texty); dc.SetFont(m_normalFont); dc.GetTextExtent(caption, &normal_textx, &normal_texty); bool bluetab = false; if (page.window->GetName() == "startpage") bluetab = true; // figure out the size of the tab wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxCoord tab_height = m_tabCtrlHeight + 2;// -1;// -3; wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height + 3; if (!page.active) { tab_height -= 2; tab_y += 2; } caption = page.caption; // select pen, brush and font for the tab to be drawn if (page.active) { dc.SetFont(m_selectedFont); texty = selected_texty; } else { dc.SetFont(m_normalFont); texty = normal_texty; } // create points that will make the tab outline int clip_width = tab_width; if (tab_x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - tab_x; dc.SetClippingRegion(tab_x, tab_y, clip_width + 1, tab_height - 3); wxPoint border_points[6]; if (m_flags &wxAUI_NB_BOTTOM) { border_points[0] = wxPoint(tab_x, tab_y); border_points[1] = wxPoint(tab_x, tab_y + tab_height - 4); border_points[2] = wxPoint(tab_x, tab_y + tab_height - 4); border_points[3] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4); border_points[4] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4); border_points[5] = wxPoint(tab_x + tab_width, tab_y); } else { border_points[0] = wxPoint(tab_x, tab_y + tab_height - 4); border_points[1] = wxPoint(tab_x, tab_y); border_points[2] = wxPoint(tab_x + 2, tab_y); border_points[3] = wxPoint(tab_x + tab_width - 2, tab_y); border_points[4] = wxPoint(tab_x + tab_width, tab_y); border_points[5] = wxPoint(tab_x + tab_width, tab_y + tab_height - 4); } int drawn_tab_yoff = border_points[1].y + 1; int drawn_tab_height = border_points[0].y - border_points[1].y; wxColour bgcol; if (page.active) { // draw active tab bgcol = m_activeColour; // draw base background color wxRect r(tab_x, tab_y, tab_width, tab_height); dc.SetPen(wxPen(bluetab ? wxColor(224, 238, 255) : m_activeColour)); dc.SetBrush(wxBrush(bluetab ? wxColor(224, 238, 255) : m_activeColour)); dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, r.height - 5); // highlight top of tab wxColour col_hilight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); dc.SetPen(*wxTRANSPARENT_PEN);// *wxWHITE_PEN); dc.SetBrush(wxBrush(col_hilight));// *wxWHITE_BRUSH); dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, 1); } else { bgcol = m_inactiveTabColour; wxRect r(tab_x, tab_y, tab_width, tab_height); wxPoint mouse = wnd->ScreenToClient(wxGetMousePosition()); /*if (r.Contains(mouse)) { dc.SetPen(wxPen(m_activeColour)); dc.SetBrush(wxBrush(m_activeColour)); } else {*/ dc.SetPen(wxPen(m_inactiveTabColour)); dc.SetBrush(wxBrush(m_inactiveTabColour)); //} dc.DrawRectangle(r.x + 1, r.y + 1, r.width - 1, r.height - 4); } // draw tab outline dc.SetPen(m_borderPen); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawPolygon(WXSIZEOF(border_points), border_points); // there are two horizontal grey lines at the bottom of the tab control, // this gets rid of the top one of those lines in the tab control if (page.active) { if (m_flags &wxAUI_NB_BOTTOM) dc.SetPen(wxPen(m_baseColour.ChangeLightness(170))); else dc.SetPen(wxPen(bluetab ? wxColor(224, 238, 255) : m_activeColour)); dc.DrawLine(border_points[0].x + 1, border_points[0].y, border_points[5].x, border_points[5].y); } int text_offset = tab_x + 8; int close_button_width = 0; if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { close_button_width = m_activeCloseBmp.GetWidth(); } int bitmap_offset = 0; if (page.bitmap.IsOk()) { bitmap_offset = tab_x + 8; // draw bitmap dc.DrawBitmap(page.bitmap, bitmap_offset, drawn_tab_yoff + (drawn_tab_height / 2) - (page.bitmap.GetHeight() / 2), true); text_offset = bitmap_offset + page.bitmap.GetWidth(); text_offset += 4; // bitmap padding } else { text_offset = tab_x + 8; } dc.SetTextForeground((page.active && bluetab) ? wxColor(0,0,0) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); wxString draw_text = wxAuiChopText(dc, caption, tab_width - (text_offset - tab_x) - close_button_width); // draw tab text dc.DrawText(draw_text, text_offset, drawn_tab_yoff + (drawn_tab_height) / 2 - (texty / 2) - 0); // draw focus rectangle if (page.active && (wnd->FindFocus() == wnd)) { wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height) / 2 - (texty / 2) - 1), selected_textx, selected_texty); wxRect focusRect; wxRect focusRectBitmap; if (page.bitmap.IsOk()) focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height / 2) - (page.bitmap.GetHeight() / 2), page.bitmap.GetWidth(), page.bitmap.GetHeight()); if (page.bitmap.IsOk() && draw_text.IsEmpty()) focusRect = focusRectBitmap; else if (!page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText; else if (page.bitmap.IsOk() && !draw_text.IsEmpty()) focusRect = focusRectText.Union(focusRectBitmap); focusRect.Inflate(2, 2); wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); } // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { wxBitmap bmp = m_disabledCloseBmp; int offsetY = tab_y; if (m_flags & wxAUI_NB_BOTTOM) offsetY = 1; wxRect rect(tab_x + tab_width - close_button_width - 3, offsetY + (tab_height / 2) - (bmp.GetHeight() / 2), close_button_width, tab_height); IndentPressedBitmap(&rect, close_button_state); if (close_button_state == wxAUI_BUTTON_STATE_HOVER || close_button_state == wxAUI_BUTTON_STATE_PRESSED) { /*wxColour bcol = m_borderPen.GetColour(); float r = ((float)bcol.Red() * 0.2f) + ((float)m_activeColour.Red() * 0.8f); float g = ((float)bcol.Green() * 0.2f) + ((float)m_activeColour.Green() * 0.8f); float b = ((float)bcol.Blue() * 0.2f) + ((float)m_activeColour.Blue() * 0.8f);*/ //captionAccentColour = wxColor(r, g, b); //dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(wxPen(Drawing::darkColour(bgcol, 2.0f))); dc.SetBrush(wxBrush(Drawing::lightColour(bgcol, 1.0f))); dc.DrawRectangle(rect.x, rect.y + 1, rect.width - 1, rect.width - 2); bmp = m_activeCloseBmp; //dc.DrawBitmap(bmp, rect.x + 1, rect.y, true); //dc.DrawBitmap(bmp, rect.x - 1, rect.y, true); dc.DrawBitmap(bmp, rect.x, rect.y, true); } else { bmp = m_disabledCloseBmp; dc.DrawBitmap(bmp, rect.x, rect.y, true); } *out_button_rect = rect; } *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); }
void MyFrame::Draw(wxDC& dc) { // This routine just draws a bunch of random stuff on the screen so that we // can check that different types of object are being drawn consistently // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SetFont(wxGetApp().m_testFont); dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); // dc.SetBackground(*wxWHITE_BRUSH); dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK,0,wxDOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE //char *test = "Hebrew שלום -- Japanese (日本語)"; //wxString tmp = wxConvUTF8.cMB2WC( test ); //dc.DrawText( tmp, 10, 200 ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; points[1].x = 20; points[1].y = 0; points[2].x = 20; points[2].y = 20; points[3].x = 10; points[3].y = 20; points[4].x = 10; points[4].y = -20; dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); points[0].x = 150; points[0].y = 250; points[1].x = 180; points[1].y = 250; points[2].x = 180; points[2].y = 220; points[3].x = 200; points[3].y = 220; dc.DrawSpline( 4, points ); dc.DrawArc( 20,10, 10,10, 25,40 ); wxString str; int i = 0; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); i = m_angle; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); wxIcon my_icon = wxICON(mondrian) ; dc.DrawIcon( my_icon, 100, 100); if (m_bitmap.Ok()) { dc.DrawBitmap(m_bitmap, 10, 25); } if (m_imgUp.Ok()) { dc.DrawBitmap(m_imgUp, 300, 200); dc.DrawBitmap(m_imgUp, 300, 250, true); } }
void kwxAngularMeter::DrawNeedle(wxDC &dc) { //Triangular double dxi,dyi, val; wxPoint ppoint[6]; int w, h ; GetClientSize(&w,&h); dc.SetPen(*wxThePenList->FindOrCreatePen(m_cNeedleColour, 1,wxSOLID)); val = (m_nScaledVal + m_nAngleStart) * m_dPI / 180; //radians angle parameter dyi = sin(val - 90) * 2; //coordinates of the left base dxi = cos(val - 90) * 2; ppoint[0].x = (w / 2) - dxi; //left base ppoint[0].y = (h / 2) - dyi; dxi = cos(val) * ((h / 2) - 4); //coordinates of the tip marker dyi = sin(val) * ((h / 2) - 4); ppoint[2].x = (w / 2) - dxi; //points ppoint[2].y = (h / 2) - dyi; dxi = cos(val + 90) * 2; //coordinates basic right dyi = sin(val + 90) * 2; ppoint[4].x = (w / 2) - dxi; //right based ppoint[4].y = (h / 2) - dyi; ppoint[5].x = ppoint[0].x; //return the left base ppoint[5].y = ppoint[0].y; ////////////////////////// val = (m_nScaledVal + m_nAngleStart + 1) * m_dPI / 180; dxi = cos(val) * ((h / 2) - 10); //coordinates of the right middle dyi = sin(val) * ((h / 2) - 10); ppoint[3].x = (w / 2) - dxi; //average basis right ppoint[3].y = (h / 2) - dyi; val = (m_nScaledVal + m_nAngleStart - 1) * m_dPI / 180; dxi = cos(val) * ((h / 2) - 10); //coordinates of the left middle dyi = sin(val) * ((h / 2) - 10); ppoint[1].x = (w / 2) - dxi; //average basis the left ppoint[1].y = (h / 2) - dyi; ///////////////////////// dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(m_cNeedleColour,wxSOLID)); dc.DrawPolygon(6, ppoint, 0, 0, wxODDEVEN_RULE); //Circle indicator dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(*wxWHITE,wxSOLID)); dc.DrawCircle(w / 2, h / 2, 4); }
// Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { // vars to use ... #if wxUSE_STATUSBAR wxString s ; #endif // wxUSE_STATUSBAR wxPen wP ; wxBrush wB ; wxPoint points[6]; wxColour wC; wxFont wF ; dc.SetFont(*wxSWISS_FONT); dc.SetPen(*wxGREEN_PEN); switch (m_index) { default: case 0: // draw lines to make a cross dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); // draw point colored line and spline wP = *wxCYAN_PEN ; wP.SetWidth(3); dc.SetPen(wP); dc.DrawPoint (25,15) ; dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); #if wxUSE_STATUSBAR s = wxT("Green Cross, Cyan Line and spline"); #endif // wxUSE_STATUSBAR break ; case 1: // draw standard shapes dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRectangle(10, 10, 100, 70); wB = wxBrush (_T("DARK ORCHID"), wxTRANSPARENT); dc.SetBrush (wB); dc.DrawRoundedRectangle(50, 50, 100, 70, 20); dc.SetBrush (wxBrush(_T("GOLDENROD"), wxSOLID) ); dc.DrawEllipse(100, 100, 100, 50); points[0].x = 100; points[0].y = 200; points[1].x = 70; points[1].y = 260; points[2].x = 160; points[2].y = 230; points[3].x = 40; points[3].y = 230; points[4].x = 130; points[4].y = 260; points[5].x = 100; points[5].y = 200; dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); #if wxUSE_STATUSBAR s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); #endif // wxUSE_STATUSBAR break ; case 2: // draw text in Arial or similar font dc.DrawLine(50,25,50,35); dc.DrawLine(45,30,55,30); dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); wC = dc.GetTextForeground() ; dc.SetTextForeground (_T("FIREBRICK")); // no effect in msw ?? dc.SetTextBackground (_T("WHEAT")); dc.DrawText(wxT("This is a Red string"), 50, 200); dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45); dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90); wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.SetTextForeground (wC) ; dc.DrawText(wxT("This is a Times-style string"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Swiss, Times text; red text, rotated and colored orange"); #endif // wxUSE_STATUSBAR break ; case 3 : // four arcs start and end points, center dc.SetBrush(*wxGREEN_BRUSH); dc.DrawArc ( 200,300, 370,230, 300,300 ); dc.SetBrush(*wxBLUE_BRUSH); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(-10,-10); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(0,0); wP.SetColour (_T("CADET BLUE")); dc.SetPen(wP); dc.DrawArc ( 75,125, 110, 40, 75, 75 ); wP.SetColour (_T("SALMON")); dc.SetPen(wP); dc.SetBrush(*wxRED_BRUSH); //top left corner, width and height, start and end angle // 315 same center and x-radius as last pie-arc, half Y radius dc.DrawEllipticArc(25,50,100,50,180.0,45.0) ; wP = *wxCYAN_PEN ; wP.SetWidth(3); dc.SetPen(wP); //wxTRANSPARENT)); dc.SetBrush (wxBrush (_T("SALMON"),wxSOLID)) ; dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0) ; //same end point dc.DrawEllipticArc(300, 50,200,100,90.0,145.0) ; dc.DrawEllipticArc(300,100,200,100,90.0,345.0) ; #if wxUSE_STATUSBAR s = wxT("This is an arc test page"); #endif // wxUSE_STATUSBAR break ; case 4: dc.DrawCheckMark ( 30,30,25,25); dc.SetBrush (wxBrush (_T("SALMON"),wxTRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); #if wxUSE_STATUSBAR s = wxT("Two check marks"); #endif // wxUSE_STATUSBAR break ; case 5: wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string"), 50, 60); // rescale and draw in blue wP = *wxCYAN_PEN ; dc.SetPen(wP); dc.SetUserScale (2.0,0.5); dc.SetDeviceOrigin(200,0); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); dc.SetUserScale (2.0,2.0); dc.SetDeviceOrigin(200,200); dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); wP = *wxRED_PEN ; dc.SetPen(wP); dc.SetUserScale (1.0,1.0); dc.SetDeviceOrigin(0,10); dc.SetMapMode (wxMM_METRIC) ; //svg ignores this dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Scaling test page"); #endif // wxUSE_STATUSBAR break ; case 6: dc.DrawIcon( wxIcon(mondrian_xpm), 10, 10 ); dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); #if wxUSE_STATUSBAR s = wxT("Icon and Bitmap "); #endif // wxUSE_STATUSBAR break ; } #if wxUSE_STATUSBAR m_child->SetStatusText(s); #endif // wxUSE_STATUSBAR }
void LineShape::drawHead(wxDC& dc) { int arrowHeadSize = 10; // First we draw a triangle at (0.0) // Second we rotate the triangle with the angle the line makes with the // Y-axis around it's centre // Than we move the centre of the triangle to the end of the line, but // outside the node top = Point(0, -arrowHeadSize); right = Point(arrowHeadSize * std::sin(PI / 3), arrowHeadSize * std::cos(PI / 3)); left = Point(-arrowHeadSize * std::sin(PI / 3), arrowHeadSize * std::cos(PI / 3)); // double angle = getAngle(); double angle = Shape2DUtils::getAngle(node1->getCentre(), node2->getCentre()) + 0.5 * PI; top = Shape2DUtils::rotate(top, angle); right = Shape2DUtils::rotate(right, angle); left = Shape2DUtils::rotate(left, angle); double shortenLine = 0.0; double dxRect = node2->getSize().x / 2; double dyRect = node2->getSize().y / 2; double boundaryAngle = std::atan(dxRect / dyRect); if (0.0 < angle && angle <= PI / 2) { if (angle < boundaryAngle) { shortenLine = dyRect / std::cos(angle); } else { shortenLine = dxRect / std::cos(PI / 2 - angle); } } else if (PI / 2 < angle && angle <= 2 * PI / 2) { if (angle < PI - boundaryAngle) { shortenLine = dxRect / std::cos(angle - PI / 2); } else { shortenLine = dyRect / std::cos(PI - angle); } } else if (2 * PI / 2 < angle && angle <= 3 * PI / 2) { if (angle < boundaryAngle + PI) { shortenLine = dyRect / std::cos(angle - PI); } else { shortenLine = dxRect / std::cos(3 * PI / 2 - angle); } } else if (3 * PI / 2 < angle && angle <= 4 * PI / 2) { if (angle < 2 * PI - boundaryAngle) { shortenLine = dxRect / std::cos(angle - PI / 2); } else { shortenLine = dyRect / std::cos(PI / 2 - angle); } } else { if (angle < 2 * PI - boundaryAngle) { shortenLine = dxRect / std::cos(angle - 3 * PI / 2); } else { shortenLine = dyRect / std::cos(2 * PI - angle); } } shortenLine += arrowHeadSize; double dX = (getLength() - shortenLine) * sin(angle); double dY = (getLength() - shortenLine) * cos(angle); Point triangleCentre(getBegin().x + dX, getBegin().y - dY); top += triangleCentre; right += triangleCentre; left += triangleCentre; Point triangle[] = {top, right, left}; if (isSelected()) { dc.SetPen(wxPen(WXSTRING("RED"), lineWidth, wxSOLID)); dc.SetBrush(wxBrush(wxColour(WXSTRING("RED")))); } else { dc.SetPen(wxPen(WXSTRING("BLACK"), lineWidth, wxSOLID)); dc.SetBrush(wxBrush(wxColour(WXSTRING("BLACK")))); } dc.DrawPolygon(3, triangle); // For debugging purposes dc.SetPen(wxPen(WXSTRING("ORANGE"), 2, wxSOLID)); dc.SetBrush(wxBrush(wxColour(WXSTRING("ORANGE")))); dc.DrawCircle(top, 2); dc.SetPen(wxPen(WXSTRING("GREEN"), 2, wxSOLID)); // stuuRRRRRRboord RRRRRRechts gRRRRRRoen dc.SetBrush(wxBrush(wxColour(WXSTRING("GREEN")))); dc.DrawCircle(right, 2); dc.SetPen(wxPen(WXSTRING("RED"), 2, wxSOLID)); dc.SetBrush(wxBrush(wxColour(WXSTRING("RED")))); dc.DrawCircle(left, 2); }
void AngularMeter::DrawNeedle(wxDC &dc) { //indicatore triangolare double dxi,dyi, val; wxPoint ppoint[6]; int w, h ; GetClientSize(&w,&h); int hOffset = 0; int wOffset = 0; if (w > h) wOffset = (w - h) / 2; if (h > w) hOffset = (h - w) / 2; //square out the size if (w > h) w=h; if (h > w) h=w; dc.SetPen(*wxThePenList->FindOrCreatePen(_needleColor, 1,wxSOLID)); val = (_scaledValue + _angleStart) * _PI / 180; //radianti parametro angolo dyi = sin(val - 90) * 2; //coordinate base sinistra dxi = cos(val - 90) * 2; ppoint[0].x = (int)((w / 2) - dxi); //base sinistra ppoint[0].y = (int)((h / 2) - dyi); dxi = cos(val) * ((h / 2) - 4); //coordinate punta indicatore dyi = sin(val) * ((h / 2) - 4); ppoint[2].x = (int)((w / 2) - dxi); //punta ppoint[2].y = (int)((h / 2) - dyi); dxi = cos(val + 90) * 2; //coordinate base destra dyi = sin(val + 90) * 2; ppoint[4].x = (int)((w / 2) - dxi); //base destra ppoint[4].y = (int)((h / 2) - dyi); ppoint[5].x = ppoint[0].x; //ritorno base sinistra ppoint[5].y = ppoint[0].y; ////////////////////////// val = (_scaledValue + _angleStart + 1) * _PI / 180; dxi = cos(val) * ((h / 2) - 10); //coordinate medio destra dyi = sin(val) * ((h / 2) - 10); ppoint[3].x = (int)((w / 2) - dxi); //base media destra ppoint[3].y = (int)((h / 2) - dyi); val = (_scaledValue + _angleStart - 1) * _PI / 180; dxi = cos(val) * ((h / 2) - 10); //coordinate medio sinistra dyi = sin(val) * ((h / 2) - 10); ppoint[1].x = (int)((w / 2) - dxi); //base media sinistra ppoint[1].y = (int)((h / 2) - dyi); ///////////////////////// dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(_needleColor,wxSOLID)); dc.DrawPolygon(6, ppoint, wOffset, hOffset, wxODDEVEN_RULE); //cerchio indicatore dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(_needleColor,wxSOLID)); dc.DrawCircle((w / 2) + wOffset, (h / 2) + hOffset, 10); }
void wxRibbonAUIArtProvider::DrawScrollButton( wxDC& dc, wxWindow* WXUNUSED(wnd), const wxRect& rect, long style) { wxRect true_rect(rect); wxPoint arrow_points[3]; if((style & wxRIBBON_SCROLL_BTN_FOR_MASK) == wxRIBBON_SCROLL_BTN_FOR_TABS) { true_rect.y += 2; true_rect.height -= 2; dc.SetPen(m_tab_border_pen); } else { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(m_background_brush); dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); dc.SetPen(m_page_border_pen); } switch(style & wxRIBBON_SCROLL_BTN_DIRECTION_MASK) { case wxRIBBON_SCROLL_BTN_LEFT: dc.DrawLine(true_rect.GetRight(), true_rect.y, true_rect.GetRight(), true_rect.y + true_rect.height); arrow_points[0] = wxPoint(rect.width / 2 - 2, rect.height / 2); arrow_points[1] = arrow_points[0] + wxPoint(5, -5); arrow_points[2] = arrow_points[0] + wxPoint(5, 5); break; case wxRIBBON_SCROLL_BTN_RIGHT: dc.DrawLine(true_rect.x, true_rect.y, true_rect.x, true_rect.y + true_rect.height); arrow_points[0] = wxPoint(rect.width / 2 + 3, rect.height / 2); arrow_points[1] = arrow_points[0] - wxPoint(5, -5); arrow_points[2] = arrow_points[0] - wxPoint(5, 5); break; case wxRIBBON_SCROLL_BTN_DOWN: dc.DrawLine(true_rect.x, true_rect.y, true_rect.x + true_rect.width, true_rect.y); arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 + 3); arrow_points[1] = arrow_points[0] - wxPoint( 5, 5); arrow_points[2] = arrow_points[0] - wxPoint(-5, 5); break; case wxRIBBON_SCROLL_BTN_UP: dc.DrawLine(true_rect.x, true_rect.GetBottom(), true_rect.x + true_rect.width, true_rect.GetBottom()); arrow_points[0] = wxPoint(rect.width / 2, rect.height / 2 - 2); arrow_points[1] = arrow_points[0] + wxPoint( 5, 5); arrow_points[2] = arrow_points[0] + wxPoint(-5, 5); break; default: return; } int x = rect.x; int y = rect.y; if(style & wxRIBBON_SCROLL_BTN_ACTIVE) { ++x; ++y; } dc.SetPen(*wxTRANSPARENT_PEN); wxBrush B(m_tab_label_colour); dc.SetBrush(B); dc.DrawPolygon(sizeof(arrow_points)/sizeof(wxPoint), arrow_points, x, y); }
// Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { // vars to use ... #if wxUSE_STATUSBAR wxString s; #endif // wxUSE_STATUSBAR wxPen wP; wxBrush wB; wxPoint points[6]; wxColour wC; wxFont wF; dc.SetFont(*wxSWISS_FONT); dc.SetPen(*wxGREEN_PEN); switch (m_index) { default: case 0: // draw lines to make a cross dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); // draw point colored line and spline wP = *wxCYAN_PEN; wP.SetWidth(3); dc.SetPen(wP); dc.DrawPoint (25,15); dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); #if wxUSE_STATUSBAR s = wxT("Green Cross, Cyan Line and spline"); #endif // wxUSE_STATUSBAR break; case 1: // draw standard shapes dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRectangle(10, 10, 100, 70); wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT); dc.SetBrush (wB); dc.DrawRoundedRectangle(50, 50, 100, 70, 20); dc.SetBrush (wxBrush(wxT("GOLDENROD")) ); dc.DrawEllipse(100, 100, 100, 50); points[0].x = 100; points[0].y = 200; points[1].x = 70; points[1].y = 260; points[2].x = 160; points[2].y = 230; points[3].x = 40; points[3].y = 230; points[4].x = 130; points[4].y = 260; points[5].x = 100; points[5].y = 200; dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); #if wxUSE_STATUSBAR s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); #endif // wxUSE_STATUSBAR break; case 2: // draw text in Arial or similar font dc.DrawLine(50,25,50,35); dc.DrawLine(45,30,55,30); dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); wC = dc.GetTextForeground(); dc.SetTextForeground (wxT("FIREBRICK")); // no effect in msw ?? dc.SetTextBackground (wxT("WHEAT")); dc.DrawText(wxT("This is a Red string"), 50, 200); dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45); dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90); wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.SetTextForeground (wC); dc.DrawText(wxT("This is a Times-style string"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Swiss, Times text; red text, rotated and colored orange"); #endif // wxUSE_STATUSBAR break; case 3 : // four arcs start and end points, center dc.SetBrush(*wxGREEN_BRUSH); dc.DrawArc ( 200,300, 370,230, 300,300 ); dc.SetBrush(*wxBLUE_BRUSH); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(-10,-10); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(0,0); wP.SetColour (wxT("CADET BLUE")); dc.SetPen(wP); dc.DrawArc ( 75,125, 110, 40, 75, 75 ); wP.SetColour (wxT("SALMON")); dc.SetPen(wP); dc.SetBrush(*wxRED_BRUSH); //top left corner, width and height, start and end angle // 315 same center and x-radius as last pie-arc, half Y radius dc.DrawEllipticArc(25,50,100,50,180.0,45.0); wP = *wxCYAN_PEN; wP.SetWidth(3); dc.SetPen(wP); //wxTRANSPARENT)); dc.SetBrush (wxBrush (wxT("SALMON"))); dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0); //same end point dc.DrawEllipticArc(300, 50,200,100,90.0,145.0); dc.DrawEllipticArc(300,100,200,100,90.0,345.0); #if wxUSE_STATUSBAR s = wxT("This is an arc test page"); #endif // wxUSE_STATUSBAR break; case 4: dc.DrawCheckMark ( 30,30,25,25); dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); #if wxUSE_STATUSBAR s = wxT("Two check marks"); #endif // wxUSE_STATUSBAR break; case 5: wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string"), 50, 60); // rescale and draw in blue wP = *wxCYAN_PEN; dc.SetPen(wP); dc.SetUserScale (2.0,0.5); dc.SetDeviceOrigin(200,0); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); dc.SetUserScale (2.0,2.0); dc.SetDeviceOrigin(200,200); dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); wP = *wxRED_PEN; dc.SetPen(wP); dc.SetUserScale (1.0,1.0); dc.SetDeviceOrigin(0,10); dc.SetMapMode (wxMM_METRIC); //svg ignores this dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Scaling test page"); #endif // wxUSE_STATUSBAR break; case 6: dc.DrawIcon( wxICON(sample), 10, 10 ); dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); #if wxUSE_STATUSBAR s = wxT("Icon and Bitmap "); #endif // wxUSE_STATUSBAR break; case 7: dc.SetTextForeground(wxT("RED")); dc.DrawText(wxT("Red = Clipping Off"), 30, 5); dc.SetTextForeground(wxT("GREEN")); dc.DrawText(wxT("Green = Clipping On"), 30, 25); dc.SetTextForeground(wxT("BLACK")); dc.SetPen(*wxRED_PEN); dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); dc.SetPen(*wxGREEN_PEN); // Clipped checkmarks dc.DrawRectangle(180,50,75,75); dc.SetClippingRegion(180,50,75,75); // x,y,width,height version dc.DrawCheckMark ( 180,50,75,75); dc.DestroyClippingRegion(); dc.DrawRectangle(wxRect(80,150,75,75)); dc.SetClippingRegion(wxPoint(80,150),wxSize(75,75)); // pt,size version dc.DrawCheckMark ( 80,150,75,75); dc.DestroyClippingRegion(); dc.DrawRectangle(wxRect(180,150,75,75)); dc.SetClippingRegion(wxRect(180,150,75,75)); // rect version dc.DrawCheckMark ( 180,150,75,75); dc.DestroyClippingRegion(); dc.DrawRectangle(wxRect( 80,250,50,65)); dc.DrawRectangle(wxRect(105,260,50,65)); dc.SetClippingRegion(wxRect( 80,250,50,65)); // second call to SetClippingRegion dc.SetClippingRegion(wxRect(105,260,50,65)); // forms intersection with previous dc.DrawCheckMark(80,250,75,75); dc.DestroyClippingRegion(); // only one call to destroy (there's no stack) /* ** Clipping by wxRegion not implemented for SVG. Should be ** possible, but need to access points that define the wxRegion ** from inside DoSetDeviceClippingRegion() and wxRegion does not ** implement anything like getPoints(). points[0].x = 180; points[0].y = 250; points[1].x = 255; points[1].y = 250; points[2].x = 180; points[2].y = 325; points[3].x = 255; points[3].y = 325; points[4].x = 180; points[4].y = 250; dc.DrawLines (5, points); wxRegion reg = wxRegion(5,points); dc.SetClippingRegion(reg); dc.DrawCheckMark ( 180,250,75,75); dc.DestroyClippingRegion(); */ #if wxUSE_STATUSBAR s = wxT("Clipping region"); #endif // wxUSE_STATUSBAR break; case 8: wxString txtStr; wxCoord txtX, txtY, txtW, txtH, txtDescent, txtEL; wxCoord txtPad = 0; wP = *wxRED_PEN; dc.SetPen(wP); //dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); //dc.SetTextBackground(*wxBLUE); // Horizontal text txtStr = wxT("Horizontal string"); dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); txtX = 50; txtY = 300; dc.DrawRectangle(txtX, txtY, txtW + 2*txtPad, txtH + 2*txtPad); dc.DrawText(txtStr, txtX + txtPad, txtY + txtPad); // Vertical text txtStr = wxT("Vertical string"); dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); txtX = 50; txtY = 250; dc.DrawRectangle(txtX, txtY - (txtW + 2*txtPad), txtH + 2*txtPad, txtW + 2*txtPad); dc.DrawRotatedText(txtStr, txtX + txtPad, txtY - txtPad, 90); // 45 degree text txtStr = wxT("45 deg string"); dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); double lenW = (double)(txtW + 2*txtPad) / sqrt(2.0); double lenH = (double)(txtH + 2*txtPad) / sqrt(2.0); double padding = (double)txtPad / sqrt(2.0); txtX = 150; txtY = 200; dc.DrawLine(txtX - padding, txtY, txtX + lenW, txtY - lenW); // top dc.DrawLine(txtX + lenW, txtY - lenW, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); dc.DrawLine(txtX - padding, txtY, txtX - padding + lenH, txtY + lenH); dc.DrawLine(txtX - padding + lenH, txtY + lenH, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); // bottom dc.DrawRotatedText(txtStr, txtX, txtY, 45); #if wxUSE_STATUSBAR s = wxT("Text position test page"); #endif // wxUSE_STATUSBAR break; } #if wxUSE_STATUSBAR m_child->SetStatusText(s); #endif // wxUSE_STATUSBAR }
void MyApp::Draw(wxDC&dc) { // This routine just draws a bunch of random stuff on the screen so that we // can check that different types of object are being drawn consistently // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); // dc.Clear(); dc.SetFont(m_testFont); // dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK, 0, wxPENSTYLE_DOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE const char *test = "Hebrew שלום -- Japanese (日本語)"; wxString tmp = wxConvUTF8.cMB2WC( test ); dc.DrawText( tmp, 10, 200 ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; points[1].x = 20; points[1].y = 0; points[2].x = 20; points[2].y = 20; points[3].x = 10; points[3].y = 20; points[4].x = 10; points[4].y = -20; dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); dc.DrawArc( 20, 330, 40, 300, 20, 300 ); { wxDCBrushChanger changeBrush(dc, *wxTRANSPARENT_BRUSH); dc.DrawArc( 60, 330, 80, 300, 60, 300 ); } dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); points[0].x = 150; points[0].y = 250; points[1].x = 180; points[1].y = 250; points[2].x = 180; points[2].y = 220; points[3].x = 200; points[3].y = 220; dc.DrawSpline( 4, points ); wxString str; int i = 0; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); i = m_angle; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); wxIcon my_icon = wxICON(sample); dc.DrawIcon( my_icon, 100, 100); if (m_bitmap.IsOk()) dc.DrawBitmap( m_bitmap, 10, 10 ); #if wxUSE_GRAPHICS_CONTEXT wxGraphicsContext *gc = NULL; wxPrinterDC *printer_dc = wxDynamicCast( &dc, wxPrinterDC ); if (printer_dc) gc = wxGraphicsContext::Create( *printer_dc ); wxWindowDC *window_dc = wxDynamicCast( &dc, wxWindowDC ); if (window_dc) gc = wxGraphicsContext::Create( *window_dc ); #ifdef __WXMSW__ wxEnhMetaFileDC *emf_dc = wxDynamicCast( &dc, wxEnhMetaFileDC ); if (emf_dc) gc = wxGraphicsContext::Create( *emf_dc ); #endif if (gc) { // make a path that contains a circle and some lines, centered at 100,100 gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); path.AddCircle( 50.0, 50.0, 50.0 ); path.MoveToPoint(0.0, 50.0); path.AddLineToPoint(100.0, 50.0); path.MoveToPoint(50.0, 0.0); path.AddLineToPoint(50.0, 100.0 ); path.CloseSubpath(); path.AddRectangle(25.0, 25.0, 50.0, 50.0); gc->StrokePath(path); // draw some text wxString text("Text by wxGraphicsContext"); gc->SetFont( m_testFont, *wxBLACK ); gc->DrawText(text, 25.0, 60.0); // draw rectangle around the text double w, h, d, el; gc->GetTextExtent(text, &w, &h, &d, &el); gc->SetPen( *wxBLACK_PEN ); gc->DrawRectangle(25.0, 60.0, w, h); delete gc; } #endif }
void wxGISTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxCoord tab_height = m_tabCtrlHeight - 2; wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height; int clip_width = tab_width; if (tab_x + clip_width > in_rect.x + in_rect.width - 4) clip_width = (in_rect.x + in_rect.width) - tab_x - 4; dc.SetClippingRegion(tab_x, tab_y, clip_width + 1, tab_height - 3); wxPoint tabPoints[7]; int adjust = 0; if (!page.active) { adjust = 1; } tabPoints[0].x = tab_x + 3; tabPoints[0].y = (m_flags & wxAUI_NB_BOTTOM) ? 3 : tab_height - 2; tabPoints[1].x = tabPoints[0].x; tabPoints[1].y = (m_flags & wxAUI_NB_BOTTOM) ? tab_height - (VERT_PADDING + 2) - adjust : (VERT_PADDING + 2) + adjust; tabPoints[2].x = tabPoints[1].x+2; tabPoints[2].y = (m_flags & wxAUI_NB_BOTTOM) ? tab_height - VERT_PADDING - adjust: VERT_PADDING + adjust; tabPoints[3].x = tab_x +tab_width - 2; tabPoints[3].y = tabPoints[2].y; tabPoints[4].x = tabPoints[3].x + 2; tabPoints[4].y = tabPoints[1].y; tabPoints[5].x = tabPoints[4].x; tabPoints[5].y = tabPoints[0].y; tabPoints[6].x = tabPoints[0].x; tabPoints[6].y = tabPoints[0].y; dc.SetBrush((page.active) ? wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)) : wxBrush(*wxTRANSPARENT_BRUSH)); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW))); dc.DrawPolygon(7, tabPoints); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); if (page.active) { dc.DrawLine(tabPoints[0].x + 1, tabPoints[0].y, tabPoints[5].x , tabPoints[0].y); } int drawn_tab_yoff = tabPoints[1].y; int drawn_tab_height = tabPoints[0].y - tabPoints[2].y; int text_offset = tab_x + 8; int bitmap_offset = 0; if (page.bitmap.IsOk()) { bitmap_offset = tab_x + 8; // draw bitmap dc.DrawBitmap(page.bitmap, bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), true); text_offset = bitmap_offset + page.bitmap.GetWidth(); text_offset += 3; // bitmap padding } else { text_offset = tab_x + 8; } // if the caption is empty, measure some temporary text wxString caption = page.caption; if (caption.empty()) caption = wxT("Xj"); wxCoord textx; wxCoord texty; if (page.active) dc.SetFont(m_selectedFont); else dc.SetFont(m_normalFont); dc.GetTextExtent(caption, &textx, &texty); // draw tab text dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); dc.DrawText(page.caption, text_offset, drawn_tab_yoff + drawn_tab_height / 2 - texty / 2 - 1); // draw 'x' on tab (if enabled) if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { int close_button_width = m_activeCloseBmp.GetWidth(); wxBitmap bmp = m_disabledCloseBmp; if ((close_button_state == wxAUI_BUTTON_STATE_HOVER) || (close_button_state == wxAUI_BUTTON_STATE_PRESSED)) bmp = m_activeCloseBmp; wxRect rect(tab_x + tab_width - close_button_width - 3, drawn_tab_yoff + (drawn_tab_height / 2) - (bmp.GetHeight() / 2), close_button_width, tab_height); // Indent the button if it is pressed down: if (close_button_state == wxAUI_BUTTON_STATE_PRESSED) { rect.x++; rect.y++; } dc.DrawBitmap(bmp, rect.x, rect.y, true); *out_button_rect = rect; } *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); }