2006-10-09 17:38:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wxPieCtrl.cpp
|
|
|
|
// Purpose: wxPieCtrl (v0.1.2)
|
|
|
|
// Author: Volodymir (T-Rex) Tryapichko
|
2007-01-24 16:58:11 +00:00
|
|
|
// Modified by: Frank Weiler, 24.02.2007
|
2006-10-09 17:38:59 +00:00
|
|
|
// Created: June-07-2005
|
|
|
|
// RCS-ID: $Id:
|
|
|
|
// Copyright: (c) Volodymir (T-Rex) Tryapichko
|
|
|
|
// Licence: wxWidgets license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "wxPieCtrl.h"
|
|
|
|
#include <wx/arrimpl.cpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2007-01-19 14:30:18 +00:00
|
|
|
#if ! wxCHECK_VERSION(2,8,0)
|
2006-10-09 17:38:59 +00:00
|
|
|
WX_DEFINE_OBJARRAY(wxArrayDouble);
|
2007-01-19 14:30:18 +00:00
|
|
|
#endif
|
2006-10-09 17:38:59 +00:00
|
|
|
WX_DEFINE_OBJARRAY(wxPieSeries);
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
|
|
|
|
/* #### wxPieCtlrLegend */
|
2006-10-09 17:38:59 +00:00
|
|
|
BEGIN_EVENT_TABLE(wxPieCtrlLegend, wxWindow)
|
2007-01-24 16:58:11 +00:00
|
|
|
EVT_PAINT(wxPieCtrlLegend::OnPaint)
|
|
|
|
EVT_ERASE_BACKGROUND(wxPieCtrlLegend::OnEraseBackground)
|
2006-10-09 17:38:59 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
/* constructor */
|
2007-01-02 21:28:27 +00:00
|
|
|
wxPieCtrlLegend::wxPieCtrlLegend(wxPieCtrl * parent, wxString title,
|
2006-10-09 17:38:59 +00:00
|
|
|
wxPoint pos, wxSize sz,
|
|
|
|
long style)
|
|
|
|
: wxWindow(parent, -1, pos, sz, style), m_IsTransparent(false),
|
|
|
|
m_HorBorder(5), m_VerBorder(5)
|
|
|
|
{
|
2007-01-25 21:26:16 +00:00
|
|
|
m_TitleColour = wxColour(0,0,0);
|
2006-10-09 17:38:59 +00:00
|
|
|
m_LabelColour = *wxBLACK;
|
2007-01-02 21:28:27 +00:00
|
|
|
m_BackColour = wxColour(255,255,0);
|
2007-01-10 01:01:24 +00:00
|
|
|
m_TitleFont = *wxSWISS_FONT;
|
|
|
|
m_TitleFont.SetWeight(wxBOLD);
|
2007-01-24 16:58:11 +00:00
|
|
|
//remember the title, because GetLabel() doesn't seem to work under X
|
2007-01-10 01:01:24 +00:00
|
|
|
m_szTitle = title;
|
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
|
2007-01-10 01:01:24 +00:00
|
|
|
void wxPieCtrlLegend::SetLabel(const wxString& label) {
|
|
|
|
wxWindow::SetLabel(label);
|
|
|
|
m_szTitle = label;
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetTransparent(bool value)
|
|
|
|
{
|
|
|
|
m_IsTransparent = value;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::RecreateBackground(wxMemoryDC & parentdc)
|
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
GetSize(&w,&h);
|
2007-01-02 21:28:27 +00:00
|
|
|
m_Background.Create(w,h);
|
2006-10-09 17:38:59 +00:00
|
|
|
m_BackgroundDC.SelectObject(m_Background);
|
|
|
|
if(IsTransparent())
|
2007-01-02 21:28:27 +00:00
|
|
|
{
|
2006-10-09 17:38:59 +00:00
|
|
|
m_BackgroundDC.Blit(0,0,w, h, &parentdc, GetPosition().x, GetPosition().y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_BackgroundDC.SetBackground(wxBrush(m_BackColour));
|
2007-01-02 21:28:27 +00:00
|
|
|
m_BackgroundDC.Clear();
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetHorBorder(unsigned int value)
|
|
|
|
{
|
|
|
|
m_HorBorder = value;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetVerBorder(unsigned int value)
|
|
|
|
{
|
|
|
|
m_VerBorder = value;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetLabelColour(wxColour colour)
|
|
|
|
{
|
|
|
|
m_LabelColour = colour;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetBackColour(wxColour colour)
|
|
|
|
{
|
|
|
|
m_BackColour = colour;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2007-05-10 09:10:51 +00:00
|
|
|
void wxPieCtrlLegend::MeasureText()
|
2006-10-09 17:38:59 +00:00
|
|
|
{
|
2007-05-09 10:47:22 +00:00
|
|
|
unsigned int i;
|
2007-05-10 09:10:51 +00:00
|
|
|
int w,h;
|
|
|
|
int dy(m_VerBorder),maxwidth,tw,th,titlew,titleh;
|
2007-05-09 10:47:22 +00:00
|
|
|
wxPieCtrl * parent = (wxPieCtrl *)GetParent();
|
|
|
|
|
|
|
|
if (parent->m_Series.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxBitmap testbmp(10, 10);
|
|
|
|
wxMemoryDC testmdc(testbmp);
|
|
|
|
testmdc.SetFont(m_TitleFont);
|
|
|
|
testmdc.GetTextExtent(m_szTitle,&titlew,&titleh);
|
|
|
|
dy += (titleh+5);
|
|
|
|
testmdc.SetFont(m_LabelFont);
|
2007-05-10 09:10:51 +00:00
|
|
|
maxwidth = titlew + 2*m_HorBorder + 15;
|
2007-05-09 10:47:22 +00:00
|
|
|
for(i = 0; i < parent->m_Series.Count(); i++)
|
|
|
|
{
|
|
|
|
testmdc.GetTextExtent(parent->m_Series[i].GetLabel(), &tw, &th);
|
|
|
|
dy += (th+3);
|
|
|
|
maxwidth = max(maxwidth, (int)(2*m_HorBorder+tw+15));
|
|
|
|
}
|
|
|
|
dy += m_VerBorder;
|
|
|
|
|
2007-05-10 09:10:51 +00:00
|
|
|
GetSize(&w, &h);
|
|
|
|
if(w != maxwidth || h != dy)
|
|
|
|
SetSize(maxwidth, dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::OnPaint(wxPaintEvent & /*event*/)
|
|
|
|
{
|
|
|
|
int w,h,dy;
|
|
|
|
unsigned int i;
|
|
|
|
int tw,th,titlew,titleh;
|
|
|
|
|
|
|
|
wxPieCtrl * parent = (wxPieCtrl *)GetParent();
|
|
|
|
|
|
|
|
if (parent->m_Series.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetSize(&w, &h);
|
2007-05-09 10:47:22 +00:00
|
|
|
wxBitmap bmp(w, h);
|
|
|
|
wxMemoryDC mdc(bmp);
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
if(IsTransparent())
|
|
|
|
{
|
2007-05-10 09:10:51 +00:00
|
|
|
// wxClientDC parentdc(GetParent());
|
2006-10-09 17:38:59 +00:00
|
|
|
mdc.Blit(0,0,w,h,&m_BackgroundDC, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mdc.SetBackground(wxBrush(m_BackColour));
|
2007-01-02 21:28:27 +00:00
|
|
|
mdc.Clear();
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
2007-05-09 10:47:22 +00:00
|
|
|
|
|
|
|
// Draw legend title
|
2006-10-09 17:38:59 +00:00
|
|
|
mdc.SetFont(m_TitleFont);
|
|
|
|
mdc.SetTextForeground(m_TitleColour);
|
2007-05-10 09:10:51 +00:00
|
|
|
mdc.GetTextExtent(m_szTitle,&titlew,&titleh);
|
2007-01-10 01:01:24 +00:00
|
|
|
mdc.DrawText(m_szTitle,m_HorBorder+2,m_VerBorder+2);
|
2007-05-09 10:47:22 +00:00
|
|
|
|
|
|
|
// Draw legend items
|
|
|
|
dy = m_VerBorder+titleh+5;
|
2006-10-09 17:38:59 +00:00
|
|
|
mdc.SetFont(m_LabelFont);
|
|
|
|
mdc.SetTextForeground(m_LabelColour);
|
2007-05-09 10:47:22 +00:00
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
for(i = 0; i < parent->m_Series.Count(); i++)
|
|
|
|
{
|
|
|
|
mdc.GetTextExtent(parent->m_Series[i].GetLabel(), &tw, &th);
|
|
|
|
mdc.SetBrush(wxBrush(parent->m_Series[i].GetColour()));
|
|
|
|
mdc.DrawCircle(m_HorBorder+5, dy+th/2, 5);
|
|
|
|
mdc.DrawText(parent->m_Series[i].GetLabel(), m_HorBorder+15, dy);
|
|
|
|
dy += (th+3);
|
|
|
|
}
|
2006-10-13 05:18:31 +00:00
|
|
|
|
2007-05-09 10:47:22 +00:00
|
|
|
// SetWindowStyle borders distort the pie circle on Mac so we draw our own
|
|
|
|
int x, y;
|
|
|
|
wxPen savedPen = mdc.GetPen();
|
2006-10-13 05:18:31 +00:00
|
|
|
GetSize(&x,&y);
|
2007-05-09 10:47:22 +00:00
|
|
|
x--;
|
|
|
|
y--;
|
|
|
|
mdc.SetPen(*wxGREY_PEN);
|
|
|
|
mdc.DrawLine(0,0,x,0); // top
|
|
|
|
mdc.DrawLine(0,y,0,0); // left
|
|
|
|
mdc.SetPen(*wxWHITE_PEN);
|
|
|
|
mdc.DrawLine(0,y,x,y); // bottom
|
|
|
|
mdc.DrawLine(x,0,x,y); // right
|
|
|
|
mdc.SetPen(savedPen);
|
2007-01-10 01:01:24 +00:00
|
|
|
|
2007-05-09 10:47:22 +00:00
|
|
|
wxPaintDC pdc(this);
|
2006-10-09 17:38:59 +00:00
|
|
|
pdc.Blit(0,0,w,h,&mdc,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrlLegend::SetLabelFont(wxFont font)
|
|
|
|
{
|
|
|
|
m_LabelFont = font;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2006-10-23 06:48:48 +00:00
|
|
|
void wxPieCtrlLegend::OnEraseBackground(wxEraseEvent & /*event*/)
|
2006-10-09 17:38:59 +00:00
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
//prevent flickering
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
/* ####### wxPiePart */
|
2006-10-09 17:38:59 +00:00
|
|
|
wxPiePart::wxPiePart()
|
|
|
|
: m_Value(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPiePart::wxPiePart(double value, wxColour colour, wxString label)
|
|
|
|
: m_Value(value), m_Colour(colour), m_Label(label)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPiePart::wxPiePart(const wxPiePart & part)
|
|
|
|
: m_Value(part.m_Value), m_Colour(part.m_Colour), m_Label(part.m_Label)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
|
|
|
|
/* ############ wxPieCtrl */
|
2006-10-09 17:38:59 +00:00
|
|
|
BEGIN_EVENT_TABLE(wxPieCtrl, wxWindow)
|
2007-01-19 00:59:31 +00:00
|
|
|
EVT_PAINT(wxPieCtrl::OnPaint)
|
|
|
|
EVT_ERASE_BACKGROUND(wxPieCtrl::OnEraseBackground)
|
|
|
|
EVT_SIZE(wxPieCtrl::OnSize)
|
|
|
|
EVT_MOTION(wxPieCtrl::OnMouseMove)
|
2006-10-09 17:38:59 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-01-19 00:59:31 +00:00
|
|
|
/* constructor */
|
2006-10-09 17:38:59 +00:00
|
|
|
wxPieCtrl::wxPieCtrl(wxWindow * parent, wxWindowID id, wxPoint pos,
|
|
|
|
wxSize sz, long style, wxString name)
|
2007-01-24 16:58:11 +00:00
|
|
|
:wxWindow(parent, id, pos, sz, style, name)
|
2007-01-02 21:28:27 +00:00
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
m_ShowEdges=true;
|
|
|
|
m_CanRepaint=true;
|
|
|
|
m_BackColour=*wxWHITE;
|
|
|
|
m_padding=10;
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
SetSizer(NULL);
|
|
|
|
SetSize(sz);
|
|
|
|
m_CanvasBitmap.Create(1,1);
|
2007-01-02 21:28:27 +00:00
|
|
|
m_Legend = new wxPieCtrlLegend(this, _("Pie Ctrl"), wxPoint(10,10), wxSize(100,75));
|
2007-05-09 10:47:22 +00:00
|
|
|
RecreateCanvas();
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
/* getter and setter */
|
|
|
|
|
|
|
|
void wxPieCtrl::SetPadding(int pad) {
|
|
|
|
m_padding = pad;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
int wxPieCtrl::GetPadding() {
|
|
|
|
return m_padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrl::SetShowEdges(bool value)
|
|
|
|
{
|
|
|
|
m_ShowEdges = value;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxPieCtrl::GetShowEdges() {
|
|
|
|
return m_ShowEdges;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrl::SetBackColour(wxColour colour)
|
|
|
|
{
|
|
|
|
m_BackColour = colour;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxColour wxPieCtrl::GetBackColour() {
|
|
|
|
return m_BackColour;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* event handlers */
|
|
|
|
/* handles mouse motion events to show tooltips
|
|
|
|
for some (unkown) reason under X no tooltips are displayed
|
|
|
|
*/
|
2007-01-19 00:59:31 +00:00
|
|
|
void wxPieCtrl::OnMouseMove(wxMouseEvent& ev) {
|
|
|
|
//get the pie part, over which the mouse pointer is
|
|
|
|
int piepart = GetCoveredPiePart(ev.GetX(),ev.GetY());
|
|
|
|
//part identified
|
2007-01-22 02:22:36 +00:00
|
|
|
if(piepart >=0) {
|
2007-01-19 00:59:31 +00:00
|
|
|
//prevent tooltip flicker
|
|
|
|
if(piepart != m_lastCoveredPart) {
|
|
|
|
wxString tooltip = this->m_Series[piepart].GetLabel();
|
|
|
|
this->SetToolTip(tooltip);
|
|
|
|
m_lastCoveredPart=piepart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this->SetToolTip(wxEmptyString);
|
|
|
|
m_lastCoveredPart=-1;
|
|
|
|
}
|
2007-01-22 02:22:36 +00:00
|
|
|
ev.Skip();
|
2007-01-19 00:59:31 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
void wxPieCtrl::OnSize(wxSizeEvent & /*event*/)
|
|
|
|
{
|
|
|
|
RecreateCanvas();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrl::OnEraseBackground(wxEraseEvent & /*event*/)
|
|
|
|
{
|
|
|
|
//prevent flicker
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrl::OnPaint(wxPaintEvent & /*event*/)
|
|
|
|
{
|
|
|
|
wxPaintDC pdc(this);
|
|
|
|
Draw(pdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal methods */
|
2007-01-19 00:59:31 +00:00
|
|
|
/* gets the pie part on coords using pixel colour */
|
|
|
|
int wxPieCtrl::GetCoveredPiePart(int x,int y) {
|
|
|
|
wxColour col;
|
|
|
|
wxClientDC dc(this);
|
|
|
|
if(dc.GetPixel(x,y,&col)) {
|
|
|
|
for(unsigned int i=0; i <m_Series.Count();i++) {
|
|
|
|
if(m_Series[i].GetColour() == col) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
void wxPieCtrl::RecreateCanvas()
|
|
|
|
{
|
2007-05-09 10:47:22 +00:00
|
|
|
int x = GetSize().GetWidth();
|
|
|
|
int y = GetSize().GetHeight();
|
2007-01-10 01:01:24 +00:00
|
|
|
//#ifdef __WXMAC__
|
2007-05-09 10:47:22 +00:00
|
|
|
if ((x < 1) || (y < 1))
|
|
|
|
return;
|
2007-01-10 01:01:24 +00:00
|
|
|
//#endif
|
2006-10-12 12:52:19 +00:00
|
|
|
m_CanvasBitmap.Create(x, y);
|
|
|
|
m_CanvasDC.SelectObject(m_CanvasBitmap);
|
2007-05-10 09:10:51 +00:00
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxPieCtrl::GetPartAngles(wxArrayDouble & angles)
|
|
|
|
{
|
|
|
|
angles.Clear();
|
|
|
|
double total(0);
|
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < m_Series.Count(); i++)
|
|
|
|
{
|
|
|
|
total += m_Series[i].GetValue();
|
|
|
|
}
|
|
|
|
double current(0);
|
2007-01-02 21:28:27 +00:00
|
|
|
angles.Add(current);
|
2006-10-09 17:38:59 +00:00
|
|
|
for(i = 0; i < m_Series.Count(); i++)
|
|
|
|
{
|
|
|
|
current += m_Series[i].GetValue();
|
2007-01-02 21:28:27 +00:00
|
|
|
angles.Add(360 * (double)current / (double)total);
|
2007-01-24 16:58:11 +00:00
|
|
|
}
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
void wxPieCtrl::DrawParts(wxRect& pieRect)
|
2006-10-09 17:38:59 +00:00
|
|
|
{
|
2007-01-02 21:28:27 +00:00
|
|
|
wxArrayDouble angles;
|
2007-01-24 16:58:11 +00:00
|
|
|
wxPen oldpen = m_CanvasDC.GetPen();
|
|
|
|
if(m_ShowEdges) {
|
|
|
|
m_CanvasDC.SetPen(*wxBLACK_PEN);
|
|
|
|
}
|
|
|
|
if(m_Series.Count() == 1)
|
2006-10-09 17:38:59 +00:00
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
m_CanvasDC.SetBrush(wxBrush(m_Series[0].GetColour()));
|
|
|
|
m_CanvasDC.DrawEllipticArc(pieRect.GetLeft(),
|
|
|
|
pieRect.GetTop(),
|
|
|
|
pieRect.GetRight()-pieRect.GetLeft(),
|
|
|
|
pieRect.GetBottom()-pieRect.GetTop(),
|
|
|
|
0,360);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GetPartAngles(angles);
|
|
|
|
for(unsigned int i = 0; i < angles.Count(); i++)
|
2007-01-02 21:28:27 +00:00
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
if(i > 0)
|
|
|
|
{
|
|
|
|
if(!m_ShowEdges)
|
|
|
|
{
|
|
|
|
m_CanvasDC.SetPen(wxPen(m_Series[i-1].GetColour()));
|
|
|
|
}
|
|
|
|
m_CanvasDC.SetBrush(wxBrush(m_Series[i-1].GetColour()));
|
|
|
|
double t1,t2;
|
|
|
|
#ifndef __WXMSW__
|
|
|
|
// Convert angles to ints and back to doubles to avoid roundoff error which causes gaps between parts
|
|
|
|
t1 = (double)(int)angles[i-1];
|
|
|
|
t2 = (double)(int)angles[i];
|
|
|
|
// !!! very little parts (angel diff < 1) are not shown
|
|
|
|
// because t1=t2 after type conversion
|
2006-10-12 12:52:19 +00:00
|
|
|
#else
|
2007-01-24 16:58:11 +00:00
|
|
|
t1 = angles[i-1];
|
|
|
|
t2 = angles[i];
|
|
|
|
#endif
|
|
|
|
if(t1 != t2) {
|
|
|
|
m_CanvasDC.DrawEllipticArc(pieRect.GetLeft(),
|
|
|
|
pieRect.GetTop(),
|
|
|
|
pieRect.GetRight()-pieRect.GetLeft(),
|
|
|
|
pieRect.GetBottom()-pieRect.GetTop(),
|
|
|
|
t1,t2);
|
|
|
|
}
|
|
|
|
}
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-24 16:58:11 +00:00
|
|
|
m_CanvasDC.SetPen(oldpen);
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 16:58:11 +00:00
|
|
|
/* paint the pie */
|
2006-10-09 17:38:59 +00:00
|
|
|
void wxPieCtrl::Draw(wxPaintDC & pdc)
|
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
int bgW,bgH;
|
|
|
|
wxRect pieRect;
|
|
|
|
//size for background ops
|
|
|
|
GetSize(&bgW,&bgH);
|
|
|
|
//pie rect respects padding and is centered
|
|
|
|
int maxL = min(bgW,bgH) - 2* m_padding;
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
if(m_CanRepaint)
|
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
//calc the pie rect coords
|
|
|
|
pieRect.SetLeft(bgW/2 - maxL/2);
|
|
|
|
pieRect.SetTop(bgH/2 - maxL/2);
|
|
|
|
pieRect.SetBottom(pieRect.GetTop() + maxL);
|
|
|
|
pieRect.SetRight(pieRect.GetLeft() + maxL);
|
|
|
|
|
|
|
|
#if ! wxCHECK_VERSION(2,8,0)
|
2007-01-02 21:28:27 +00:00
|
|
|
m_CanvasDC.BeginDrawing();
|
2007-01-19 14:30:18 +00:00
|
|
|
#endif
|
2007-01-24 16:58:11 +00:00
|
|
|
m_CanvasDC.SetBackground(wxBrush(m_BackColour));
|
|
|
|
m_CanvasDC.Clear();
|
|
|
|
if(m_Series.Count())
|
2006-10-09 17:38:59 +00:00
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
DrawParts(pieRect);
|
2007-01-02 21:28:27 +00:00
|
|
|
}
|
2007-01-24 16:58:11 +00:00
|
|
|
else {
|
|
|
|
//no data, draw an black circle
|
|
|
|
m_CanvasDC.SetBrush(*wxBLACK_BRUSH);
|
|
|
|
m_CanvasDC.DrawEllipticArc(pieRect.GetLeft(),
|
|
|
|
pieRect.GetTop(),
|
|
|
|
pieRect.GetRight()-pieRect.GetLeft(),
|
|
|
|
pieRect.GetBottom()-pieRect.GetTop(),
|
|
|
|
0,360);
|
2007-01-02 21:28:27 +00:00
|
|
|
}
|
2007-01-24 16:58:11 +00:00
|
|
|
#if ! wxCHECK_VERSION(2,8,0)
|
|
|
|
m_CanvasDC.EndDrawing();
|
2006-10-09 17:38:59 +00:00
|
|
|
#endif
|
|
|
|
m_CanRepaint = false;
|
|
|
|
}
|
2007-01-24 16:58:11 +00:00
|
|
|
pdc.Blit(0,0,bgW,bgH,&m_CanvasDC,0,0);
|
2007-01-02 21:28:27 +00:00
|
|
|
m_Legend->RecreateBackground(m_CanvasDC);
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wxPieCtrl::Refresh(bool eraseBackground, const wxRect* rect)
|
|
|
|
{
|
|
|
|
m_CanRepaint = true;
|
2007-01-02 21:28:27 +00:00
|
|
|
wxWindow::Refresh(eraseBackground, rect);
|
2007-05-10 09:10:51 +00:00
|
|
|
m_Legend->MeasureText();
|
2006-10-09 17:38:59 +00:00
|
|
|
}
|
|
|
|
|