Working throught the zetcode WxWidget tutorial:widgets I: wxSlider

This one looks sort of interesting.
Its a vertical slider that looks like it fills up a container..
Although… It sounds as if the quite time is up…..
Let’s see how far we can get through this. (Someone is watching Garfield the movie we’re good..)
Ok…
This example has basically two things going on .. The Slider and what seems to be the equivalent of a progress bar in VB…
I think for fun, I’m going to modify this code and put a horizontal slider as well has a horizontal progress bar on the same form below the vertical¬† and run through the options for practice.

Constructor options for the slider look like:
wxSlider(wxWindow* parent, wxWindowID id, int value , int minValue, int maxValue, const wxPoint& point = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSL_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, const wxString& name = “slider”)

I’m looking through this code and there are certain aspects that make total sense and other things that confuse me..
Ok…
This makes sense…
We’ve defined the object in the header…
class MyPanel : public wxPanel
{
public:
MyPanel(wxFrame *parent);

void OnPaint(wxPaintEvent& event);
void OnScroll(wxScrollEvent& event);

wxSlider *slider;
int fill;

/############### I ADDED THIS FOR PRACTICE

wxSlider *hslider;
int hfill;
void OnHPaint(wxPaintEvent& event);
void OnHScroll(wxScrollEvent& event);

};

Now the event needs to be connect (Also makes perfect sense)

Connect(ID_SLIDER, wxEVT_COMMAND_SLIDER_UPDATED,
wxScrollEventHandler(MyPanel::OnScroll));

So it gets connect to this:

void MyPanel::OnScroll(wxScrollEvent& event)
{
fill = slider->GetValue();
Refresh();
}

Ok… I just solved my own confusion Refresh() generates a repaint.
I’m not sure my modification blends well with this simplified example…
For now, to get this to work I’m going to update both boxes in the same refresh event, but that just doesn’t feel right…
But first I need to under stand whats going on with the progessbar like stuff.

The repaint code looks like this:

void MyPanel::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);

wxPen pen(wxColour(212, 212, 212));
dc.SetPen(pen);

dc.DrawRectangle(wxRect(140, 30, 80, 140));

wxBrush brush1(wxColour(197, 108, 0));
dc.SetBrush(brush1);

dc.DrawRectangle(wxRect(140, 30, 80, fill));
}

Ok… I think this author likes to mess with his readership a little… The title of this tutorial was wxSlder… But the most interesting stuff tends to have nothing to do with this…
Videos are over I’ll need to come back to this later….

I made a second rectangle and flipped it on its side… within the same refresh event as the first..
Anyway… one to the next one

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *