I decided to attempt to draw my own graph with widgets, but I am having some trouble drawing to my frame.
below I have re-created my project with just the key features included to show more clearly, the draw function is taken from the widgets example archieve but when this class is called the frame/window is shown with no rectangle?
Code: Select all
#include "BatteryHistory.h"
BEGIN_EVENT_TABLE(BatteryHistory, wxFrame)
EVT_BUTTON(ID_EXIT, BatteryHistory::exitEvt)
END_EVENT_TABLE()
BatteryHistory::BatteryHistory(const wxString& title, const wxPoint &position, const wxSize& size, long style)
: wxFrame(NULL, ID_BATTERY, title, wxDefaultPosition, wxSize(380,320))
{
//Frame setup
mainFrameSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(mainFrameSizer);
this->SetAutoLayout(TRUE);
this->SetBackgroundColour(wxColour(255, 255, 255));
this->SetIcon(wxICON(sample));
//Draw Graph
wxPaintDC dc(this);
drawGraph(dc);
Center();
}
/////////////////////////////////////////////////////////////
//destructor
/////////////////////////////////////////////////////////////
BatteryHistory::~BatteryHistory()
{}
/////////////////////////////////////////////////////////////
//Draw Graph
/////////////////////////////////////////////////////////////
void BatteryHistory::drawGraph(wxDC& dc)
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxRED_BRUSH);
// Get window dimensions
wxSize sz = GetClientSize();
// Our rectangle dimensions
wxCoord w = 100, h = 50;
// Center the rectangle on the window, but never
// draw at a negative position.
int x = wxMax(0, (sz.x - w)/2);
int y = wxMax(0, (sz.y - h)/2);
wxRect rectToDraw(x, y, w, h);
dc.DrawRectangle(rectToDraw);
}
Thank you for any help in advance!