diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-09-27 08:51:17 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-09-27 22:15:39 +0200 |
commit | 89acc7b6edc80c54d1746348ed02329a08c50b41 (patch) | |
tree | c565883fc2e974f493162e7a0330323116b70be7 /source/scrollbar.c | |
parent | 769dab5f66e1a344d22c9a3587f5a56ec4b77c2e (diff) |
Make one widget_draw function, abstract rest (textbox, scrollbar) behind it.
Diffstat (limited to 'source/scrollbar.c')
-rw-r--r-- | source/scrollbar.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/source/scrollbar.c b/source/scrollbar.c index 1da6f689..e58ebb5c 100644 --- a/source/scrollbar.c +++ b/source/scrollbar.c @@ -29,14 +29,17 @@ #include "x11-helper.h" #include "settings.h" +static void scrollbar_draw ( Widget *widget, cairo_t *draw ); + scrollbar *scrollbar_create ( short x, short y, short w, short h ) { scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); - sb->widget.x = x; - sb->widget.y = y; - sb->widget.w = MAX ( 1, w ); - sb->widget.h = MAX ( 1, h ); + sb->widget.x = x; + sb->widget.y = y; + sb->widget.w = MAX ( 1, w ); + sb->widget.h = MAX ( 1, h ); + sb->widget.draw = scrollbar_draw; sb->length = 10; sb->pos = 0; @@ -75,26 +78,25 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length ) } } -void scrollbar_draw ( scrollbar *sb, cairo_t *draw ) +static void scrollbar_draw ( Widget *widget, cairo_t *draw ) { - if ( sb != NULL && sb->widget.enabled ) { - // Calculate position and size. - const short bh = sb->widget.h - 0; - float sec = ( ( bh ) / (float) sb->length ); - short height = sb->pos_length * sec; - short y = sb->pos * sec; - // Set max pos. - y = MIN ( y, bh - 2 ); - // Never go out of bar. - height = MAX ( 2, height ); - // Cap length; - height = MIN ( bh - y + 1, ( height ) ); - // Redraw base window - color_separator ( draw ); + scrollbar *sb = (scrollbar *) widget; + // Calculate position and size. + const short bh = sb->widget.h - 0; + float sec = ( ( bh ) / (float) sb->length ); + short height = sb->pos_length * sec; + short y = sb->pos * sec; + // Set max pos. + y = MIN ( y, bh - 2 ); + // Never go out of bar. + height = MAX ( 2, height ); + // Cap length; + height = MIN ( bh - y + 1, ( height ) ); + // Redraw base window + color_separator ( draw ); - cairo_rectangle ( draw, sb->widget.x + config.line_margin, sb->widget.y + y, sb->widget.w - config.line_margin, height ); - cairo_fill ( draw ); - } + cairo_rectangle ( draw, sb->widget.x + config.line_margin, sb->widget.y + y, sb->widget.w - config.line_margin, height ); + cairo_fill ( draw ); } void scrollbar_resize ( scrollbar *sb, int w, int h ) { |