It almost works right. The problem I'm having is that when I create the control, the specified size is ignored and instead I get a control that has a client size of 80x100 pixels, even though I specified a wxSize of 30x120. What have I missed?
Here's the control so far:
Code: Select all
class wxBitmapSlider : public wxControl ...
Code: Select all
BEGIN_EVENT_TABLE(wxBitmapSlider, wxSlider)
EVT_PAINT(wxBitmapSlider::OnPaint)
EVT_KEY_DOWN(wxBitmapSlider::OnKeyDown)
EVT_KEY_UP(wxBitmapSlider::OnKeyUp)
EVT_LEFT_UP(wxBitmapSlider::OnMouseRelease)
EVT_MOTION(wxBitmapSlider::OnMouseMove)
EVT_LEFT_DOWN(wxBitmapSlider::OnMouse)
END_EVENT_TABLE()
wxBitmapSlider::wxBitmapSlider( wxWindow* parent, wxWindowID id, float value, float minValue, float maxValue, const wxPoint &pos , const wxSize &size, long style)
{
Create( parent, id, value, minValue, maxValue, pos, size, style );
}
void wxBitmapSlider::Create(wxWindow* parent, wxWindowID id, float value, float minValue, float maxValue, const wxPoint &pos, const wxSize &size, long style)
{
_dragging = false;
_style = style;
_minValue = minValue;
_maxValue = maxValue;
_value = value;
wxControl::Create( parent, id, pos, size, style|wxBORDER_NONE );
}
void wxBitmapSlider::OnPaint( wxPaintEvent& event )
{
wxBufferedPaintDC dc(this);
wxSize size = GetSize();
// Bitmap drawing code omitted for brevity...
if( _style & wxSL_VERTICAL )
{
dc.Clear();
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(*wxGREEN_PEN);
dc.DrawLine(size.x/2, 0, size.x/2, size.y);
dc.DrawRectangle(size.x/2 - 3, (_value / _maxValue * (float)size.y), 7, 5);
}
else
{
dc.Clear();
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(*wxGREEN_PEN);
dc.DrawLine(0, size.y/2, size.x, size.y/2);
dc.DrawRectangle((_value / _maxValue * (float)size.x), size.y/2 - 3, 5, 7 );
}
event.Skip();
}
// Range and value setters, getters, and mouse event handlers omitted for brevity.
Code: Select all
new wxBitmapSlider( itemDialog1, ID_WHATEVER, 8192, 0, 16383, wxDefaultPosition, wxSize( 30, 120 ), wxSL_VERTICAL|wxSL_INVERSE );