Commit 07b0dae0 authored by Davis King's avatar Davis King

Made the scrollable_region and zoomable_region widgets have user settable styles.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402592
parent 972ffa75
This diff is collapsed.
......@@ -2096,6 +2096,22 @@ namespace dlib
long y
);
template <
typename style_type
>
void set_style (
const style_type& style_
)
{
auto_mutex M(m);
style.reset(new style_type(style_));
hsb.set_style(style_.get_horizontal_scroll_bar_style());
vsb.set_style(style_.get_vertical_scroll_bar_style());
// do this just so that everything gets redrawn right
set_size(rect.width(), rect.height());
}
void set_zoom_increment (
double zi
);
......@@ -2240,6 +2256,8 @@ namespace dlib
scroll_bar vsb;
scroll_bar hsb;
scoped_ptr<scrollable_region_style> style;
// restricted functions
zoomable_region(zoomable_region&); // copy constructor
zoomable_region& operator=(zoomable_region&); // assignment operator
......@@ -2252,7 +2270,6 @@ namespace dlib
{
/*!
INITIAL VALUE
- border_size == 2
- hscroll_bar_inc == 1
- vscroll_bar_inc == 1
- h_wheel_scroll_bar_inc == 1
......@@ -2262,7 +2279,6 @@ namespace dlib
CONVENTION
- mouse_drag_enabled() == mouse_drag_enabled_
- border_size == 2
- horizontal_scroll_increment() == hscroll_bar_inc
- vertical_scroll_increment() == vscroll_bar_inc
- horizontal_mouse_wheel_scroll_increment() == h_wheel_scroll_bar_inc
......@@ -2290,6 +2306,22 @@ namespace dlib
virtual ~scrollable_region (
) = 0;
template <
typename style_type
>
void set_style (
const style_type& style_
)
{
auto_mutex M(m);
style.reset(new style_type(style_));
hsb.set_style(style_.get_horizontal_scroll_bar_style());
vsb.set_style(style_.get_vertical_scroll_bar_style());
// do this just so that everything gets redrawn right
set_size(rect.width(), rect.height());
}
void show (
);
......@@ -2435,7 +2467,6 @@ namespace dlib
rectangle display_rect_;
scroll_bar hsb;
scroll_bar vsb;
const unsigned long border_size;
unsigned long hscroll_bar_inc;
unsigned long vscroll_bar_inc;
unsigned long h_wheel_scroll_bar_inc;
......@@ -2443,6 +2474,7 @@ namespace dlib
bool mouse_drag_enabled_;
bool user_is_dragging_mouse;
point drag_origin;
scoped_ptr<scrollable_region_style> style;
};
......
......@@ -1614,6 +1614,20 @@ namespace dlib
- all resources associated with *this have been released
!*/
template <
typename style_type
>
void set_style (
const style_type& style_
);
/*!
requires
- style_type == a type that inherits from scrollable_region_style
ensures
- this zoomable_region object will draw itself using the given
style
!*/
void set_zoom_increment (
double zi
);
......@@ -1841,6 +1855,20 @@ namespace dlib
- all resources associated with *this have been released
!*/
template <
typename style_type
>
void set_style (
const style_type& style_
);
/*!
requires
- style_type == a type that inherits from scrollable_region_style
ensures
- this scrollable_region object will draw itself using the given
style
!*/
void set_size (
unsigned long width,
unsigned long height
......
......@@ -533,6 +533,50 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// scrollable_region styles
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class scrollable_region_style
{
public:
virtual ~scrollable_region_style() {}
virtual long get_border_size (
) const = 0;
virtual void draw_scrollable_region_border (
const canvas& c,
const rectangle& rect,
const bool enabled
) const = 0;
};
// ----------------------------------------------------------------------------------------
class scrollable_region_style_default : public scrollable_region_style
{
public:
scroll_bar_style_default get_horizontal_scroll_bar_style (
) const { return scroll_bar_style_default(); }
scroll_bar_style_default get_vertical_scroll_bar_style (
) const { return scroll_bar_style_default(); }
virtual long get_border_size (
) const { return 2; }
virtual void draw_scrollable_region_border (
const canvas& c,
const rectangle& rect,
const bool enabled
) const { draw_sunken_rectangle(c,rect); }
};
// ----------------------------------------------------------------------------------------
}
......
......@@ -418,6 +418,78 @@ namespace dlib
!*/
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// scrollable_region (and zoomable_region) styles
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class scrollable_region_style
{
/*!
WHAT THIS OBJECT REPRESENTS
This is an abstract class that defines the interface a
scrollable_region and zoomable_region style object must implement.
Note that derived classes must be copyable via
their copy constructors.
!*/
public:
virtual ~scrollable_region_style() {}
virtual long get_border_size (
) const = 0;
/*!
requires
- the mutex drawable::m is locked
ensures
- returns the size of the border region in pixels
!*/
virtual void draw_scrollable_region_border (
const canvas& c,
const rectangle& rect,
const bool enabled
) const = 0;
/*!
requires
- the mutex drawable::m is locked
- c == the canvas to draw on
- rect and enabled are the variables defined in the protected section
of the drawable class.
ensures
- draws the border part of a scrollable_region on the canvas c at the
location given by rect.
!*/
scroll_bar_style_type get_horizontal_scroll_bar_style (
) const;
/*!
ensures
- returns the style of scroll_bar to use for the
horizontal scroll_bar in this widget.
!*/
scroll_bar_style_type get_vertical_scroll_bar_style (
) const;
/*!
ensures
- returns the style of scroll_bar to use for the
vertical scroll_bar in this widget.
!*/
};
// ----------------------------------------------------------------------------------------
class scrollable_region_style_default : public scrollable_region_style
{
public:
/*!
This is the default style for scrollable_region and zoomable_region objects.
!*/
};
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment