Commit ab964fee authored by Davis King's avatar Davis King

Removed all the arrow button styles and replaced them with a single

button style.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402599
parent 9db0ca77
......@@ -285,202 +285,119 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace arrow_button_style_helper
void button_style_arrow::
draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const
{
enum arrow_direction
{
UP,
DOWN,
LEFT,
RIGHT
};
void draw_arrow_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const bool is_depressed,
const arrow_direction dir
)
{
rectangle area = rect.intersect(c);
if (area.is_empty())
return;
fill_rect(c,rect,rgb_pixel(212,208,200));
const long height = rect.height();
const long width = rect.width();
const long smallest = (width < height) ? width : height;
const long rows = (smallest+3)/4;
const long start = rows + rows/2-1;
long dep;
long tip_x = 0;
long tip_y = 0;
long wy = 0;
long hy = 0;
long wx = 0;
long hx = 0;
if (is_depressed)
{
dep = 0;
rectangle area = rect.intersect(c);
if (area.is_empty())
return;
// draw the button's border
draw_button_down(c,rect);
}
else
{
dep = -1;
fill_rect(c,rect,rgb_pixel(212,208,200));
// draw the button's border
draw_button_up(c,rect);
}
const long height = rect.height();
const long width = rect.width();
const long smallest = (width < height) ? width : height;
switch (dir)
{
case UP:
tip_x = width/2 + rect.left() + dep;
tip_y = (height - start)/2 + rect.top() + dep + 1;
wy = 0;
hy = 1;
wx = 1;
hx = 0;
break;
case DOWN:
tip_x = width/2 + rect.left() + dep;
tip_y = rect.bottom() - (height - start)/2 + dep;
wy = 0;
hy = -1;
wx = 1;
hx = 0;
break;
case LEFT:
tip_x = rect.left() + (width - start)/2 + dep + 1;
tip_y = height/2 + rect.top() + dep;
wy = 1;
hy = 0;
wx = 0;
hx = 1;
break;
case RIGHT:
tip_x = rect.right() - (width - start)/2 + dep;
tip_y = height/2 + rect.top() + dep;
wy = 1;
hy = 0;
wx = 0;
hx = -1;
break;
}
const long rows = (smallest+3)/4;
const long start = rows + rows/2-1;
long dep;
long tip_x = 0;
long tip_y = 0;
long wy = 0;
long hy = 0;
long wx = 0;
long hx = 0;
rgb_pixel color;
if (enabled)
{
color.red = 0;
color.green = 0;
color.blue = 0;
}
else
{
color.red = 128;
color.green = 128;
color.blue = 128;
}
if (is_depressed)
{
dep = 0;
// draw the button's border
draw_button_down(c,rect);
}
else
{
dep = -1;
// draw the button's border
draw_button_up(c,rect);
}
for (long i = 0; i < rows; ++i)
{
draw_line(c,point(tip_x + wx*i + hx*i, tip_y + wy*i + hy*i),
point(tip_x + wx*i*-1 + hx*i, tip_y + wy*i*-1 + hy*i),
color);
}
switch (dir)
{
case UP:
tip_x = width/2 + rect.left() + dep;
tip_y = (height - start)/2 + rect.top() + dep + 1;
wy = 0;
hy = 1;
wx = 1;
hx = 0;
break;
case DOWN:
tip_x = width/2 + rect.left() + dep;
tip_y = rect.bottom() - (height - start)/2 + dep;
wy = 0;
hy = -1;
wx = 1;
hx = 0;
break;
case LEFT:
tip_x = rect.left() + (width - start)/2 + dep + 1;
tip_y = height/2 + rect.top() + dep;
wy = 1;
hy = 0;
wx = 0;
hx = 1;
break;
case RIGHT:
tip_x = rect.right() - (width - start)/2 + dep;
tip_y = height/2 + rect.top() + dep;
wy = 1;
hy = 0;
wx = 0;
hx = -1;
break;
}
}
void button_style_left_arrow::
draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const
{
using namespace arrow_button_style_helper;
draw_arrow_button(c, rect, enabled, is_depressed, LEFT);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
rgb_pixel color;
if (enabled)
{
color.red = 0;
color.green = 0;
color.blue = 0;
}
else
{
color.red = 128;
color.green = 128;
color.blue = 128;
}
void button_style_right_arrow::
draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const
{
using namespace arrow_button_style_helper;
draw_arrow_button(c, rect, enabled, is_depressed, RIGHT);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void button_style_up_arrow::
draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const
{
using namespace arrow_button_style_helper;
draw_arrow_button(c, rect, enabled, is_depressed, UP);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
for (long i = 0; i < rows; ++i)
{
draw_line(c,point(tip_x + wx*i + hx*i, tip_y + wy*i + hy*i),
point(tip_x + wx*i*-1 + hx*i, tip_y + wy*i*-1 + hy*i),
color);
}
void button_style_down_arrow::
draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const
{
using namespace arrow_button_style_helper;
draw_arrow_button(c, rect, enabled, is_depressed, DOWN);
}
// ----------------------------------------------------------------------------------------
......
......@@ -229,53 +229,23 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class button_style_left_arrow : public button_style
class button_style_arrow : public button_style
{
public:
virtual void draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const;
virtual rectangle get_min_size (
const ustring& name,
const font& mfont
) const { return rectangle(); }
};
// ----------------------------------------------------------------------------------------
class button_style_right_arrow : public button_style
{
public:
virtual void draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const;
virtual rectangle get_min_size (
const ustring& name,
const font& mfont
) const { return rectangle(); }
};
enum arrow_direction
{
UP,
DOWN,
LEFT,
RIGHT
};
// ----------------------------------------------------------------------------------------
button_style_arrow (
arrow_direction dir_
) : dir(dir_) {}
class button_style_up_arrow : public button_style
{
public:
virtual void draw_button (
const canvas& c,
const rectangle& rect,
......@@ -291,28 +261,9 @@ namespace dlib
const ustring& name,
const font& mfont
) const { return rectangle(); }
};
// ----------------------------------------------------------------------------------------
class button_style_down_arrow : public button_style
{
public:
virtual void draw_button (
const canvas& c,
const rectangle& rect,
const bool enabled,
const font& mfont,
const long lastx,
const long lasty,
const ustring& name,
const bool is_depressed
) const;
virtual rectangle get_min_size (
const ustring& name,
const font& mfont
) const { return rectangle(); }
private:
arrow_direction dir;
};
// ----------------------------------------------------------------------------------------
......@@ -488,17 +439,17 @@ namespace dlib
class scroll_bar_style_default : public scroll_bar_style
{
public:
button_style_up_arrow get_up_button_style (
) const { return button_style_up_arrow(); }
button_style_arrow get_up_button_style (
) const { return button_style_arrow(button_style_arrow::UP); }
button_style_down_arrow get_down_button_style (
) const { return button_style_down_arrow(); }
button_style_arrow get_down_button_style (
) const { return button_style_arrow(button_style_arrow::DOWN); }
button_style_left_arrow get_left_button_style (
) const { return button_style_left_arrow(); }
button_style_arrow get_left_button_style (
) const { return button_style_arrow(button_style_arrow::LEFT); }
button_style_right_arrow get_right_button_style (
) const { return button_style_right_arrow(); }
button_style_arrow get_right_button_style (
) const { return button_style_arrow(button_style_arrow::RIGHT); }
virtual long get_width (
) const { return 16; }
......
......@@ -136,37 +136,27 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class button_style_left_arrow : public button_style
{
/*!
This draws a simple button with a left pointing arrow in it
!*/
};
// ----------------------------------------------------------------------------------------
class button_style_right_arrow : public button_style
{
/*!
This draws a simple button with a right pointing arrow in it
!*/
};
// ----------------------------------------------------------------------------------------
class button_style_up_arrow : public button_style
class button_style_arrow : public button_style
{
public:
/*!
This draws a simple button with an up pointing arrow in it
This draws a simple button with an arrow in it
!*/
};
// ----------------------------------------------------------------------------------------
enum arrow_direction
{
UP,
DOWN,
LEFT,
RIGHT
};
class button_style_down_arrow : public button_style
{
button_style_arrow (
arrow_direction dir
);
/*!
This draws a simple button with a down pointing arrow in it
ensures
- the arrow in the button will point in the given direction
!*/
};
......
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