2016-10-08 12:57:59 -04:00
|
|
|
#include <glib.h>
|
2017-02-06 15:17:56 -05:00
|
|
|
#include <math.h>
|
2016-10-08 12:57:59 -04:00
|
|
|
#include "widgets/widget.h"
|
2016-10-09 04:13:15 -04:00
|
|
|
#include "widgets/widget-internal.h"
|
2016-12-27 16:19:15 -05:00
|
|
|
#include "theme.h"
|
|
|
|
|
2017-01-09 16:40:11 -05:00
|
|
|
/** Default padding. */
|
2017-01-09 17:01:09 -05:00
|
|
|
#define WIDGET_DEFAULT_PADDING 0
|
2017-01-09 16:29:31 -05:00
|
|
|
|
2017-01-08 15:36:06 -05:00
|
|
|
void widget_init ( widget *widget, const char *name )
|
2016-12-27 16:19:15 -05:00
|
|
|
{
|
2017-02-06 15:17:56 -05:00
|
|
|
widget->name = g_strdup ( name );
|
|
|
|
widget->def_padding = (Padding){ { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID }, { WIDGET_DEFAULT_PADDING, PW_PX, SOLID } };
|
|
|
|
widget->def_border = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
|
|
|
|
widget->def_border_radius = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
|
|
|
|
widget->def_margin = (Padding){ { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID }, { 0, PW_PX, SOLID } };
|
|
|
|
|
|
|
|
widget->padding = rofi_theme_get_padding ( widget, "padding", widget->def_padding );
|
|
|
|
widget->border = rofi_theme_get_padding ( widget, "border", widget->def_border );
|
|
|
|
widget->border_radius = rofi_theme_get_padding ( widget, "border-radius", widget->def_border_radius );
|
|
|
|
widget->margin = rofi_theme_get_padding ( widget, "margin", widget->def_margin );
|
2016-12-27 16:19:15 -05:00
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-12-28 06:21:42 -05:00
|
|
|
void widget_set_state ( widget *widget, const char *state )
|
|
|
|
{
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( g_strcmp0 ( widget->state, state ) ) {
|
2017-01-06 07:26:26 -05:00
|
|
|
widget->state = state;
|
|
|
|
// Update border.
|
2017-02-06 15:17:56 -05:00
|
|
|
widget->border = rofi_theme_get_padding ( widget, "border", widget->def_border );
|
|
|
|
widget->border_radius = rofi_theme_get_padding ( widget, "border-radius", widget->def_border_radius );
|
2017-01-06 07:24:35 -05:00
|
|
|
|
2017-01-06 07:26:26 -05:00
|
|
|
widget_queue_redraw ( widget );
|
|
|
|
}
|
2016-12-28 06:21:42 -05:00
|
|
|
}
|
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
int widget_intersect ( const widget *widget, int x, int y )
|
|
|
|
{
|
|
|
|
if ( widget == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) ) {
|
|
|
|
if ( y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_resize ( widget *widget, short w, short h )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
if ( widget->resize != NULL ) {
|
2016-12-30 12:31:30 -05:00
|
|
|
if ( widget->w != w || widget->h != h ) {
|
|
|
|
widget->resize ( widget, w, h );
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
widget->w = w;
|
|
|
|
widget->h = h;
|
|
|
|
}
|
2016-12-31 20:27:51 -05:00
|
|
|
// On a resize we always want to udpate.
|
|
|
|
widget_queue_redraw ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_move ( widget *widget, short x, short y )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
widget->x = x;
|
|
|
|
widget->y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean widget_enabled ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
return widget->enabled;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_enable ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget && !widget->enabled ) {
|
|
|
|
widget->enabled = TRUE;
|
|
|
|
widget_update ( widget );
|
2016-12-30 13:59:45 -05:00
|
|
|
widget_update ( widget->parent );
|
2017-01-31 02:09:55 -05:00
|
|
|
widget_queue_redraw ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_disable ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget && widget->enabled ) {
|
|
|
|
widget->enabled = FALSE;
|
|
|
|
widget_update ( widget );
|
2016-12-30 13:59:45 -05:00
|
|
|
widget_update ( widget->parent );
|
2017-01-31 02:09:55 -05:00
|
|
|
widget_queue_redraw ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_draw ( widget *widget, cairo_t *d )
|
|
|
|
{
|
|
|
|
// Check if enabled and if draw is implemented.
|
|
|
|
if ( widget && widget->enabled && widget->draw ) {
|
2017-01-04 04:47:37 -05:00
|
|
|
// Don't draw if there is no space.
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( widget->h < 1 || widget->w < 1 ) {
|
2017-01-04 04:47:37 -05:00
|
|
|
widget->need_redraw = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2016-12-28 06:21:42 -05:00
|
|
|
// Store current state.
|
|
|
|
cairo_save ( d );
|
2017-02-08 13:48:15 -05:00
|
|
|
const int margin_left = distance_get_pixel ( widget->margin.left, ORIENTATION_HORIZONTAL );
|
|
|
|
const int margin_top = distance_get_pixel ( widget->margin.top, ORIENTATION_VERTICAL );
|
|
|
|
const int margin_right = distance_get_pixel ( widget->margin.right, ORIENTATION_HORIZONTAL );
|
|
|
|
const int margin_bottom = distance_get_pixel ( widget->margin.bottom, ORIENTATION_VERTICAL );
|
|
|
|
const int left = distance_get_pixel ( widget->border.left, ORIENTATION_HORIZONTAL );
|
|
|
|
const int right = distance_get_pixel ( widget->border.right, ORIENTATION_HORIZONTAL );
|
|
|
|
const int top = distance_get_pixel ( widget->border.top, ORIENTATION_VERTICAL );
|
|
|
|
const int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL );
|
2017-02-09 02:27:26 -05:00
|
|
|
int radius_bl = distance_get_pixel ( widget->border_radius.left, ORIENTATION_HORIZONTAL );
|
|
|
|
int radius_tr = distance_get_pixel ( widget->border_radius.right, ORIENTATION_HORIZONTAL );
|
|
|
|
int radius_tl = distance_get_pixel ( widget->border_radius.top, ORIENTATION_VERTICAL );
|
|
|
|
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ORIENTATION_VERTICAL );
|
2017-02-06 17:45:46 -05:00
|
|
|
|
2017-02-09 02:27:26 -05:00
|
|
|
double vspace = widget->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0;
|
|
|
|
double hspace = widget->w - margin_left - margin_right - left / 2.0 - right / 2.0;
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( ( radius_bl + radius_tl ) > ( vspace ) ) {
|
2017-02-09 02:27:26 -05:00
|
|
|
int j = floor ( ( vspace ) / 2.0 );
|
2017-02-06 15:31:13 -05:00
|
|
|
radius_bl = MIN ( radius_bl, j );
|
|
|
|
radius_tl = MIN ( radius_tl, j );
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( ( radius_br + radius_tr ) > ( vspace ) ) {
|
|
|
|
int j = floor ( ( vspace ) / 2.0 );
|
2017-02-06 17:45:46 -05:00
|
|
|
radius_br = MIN ( radius_br, j );
|
|
|
|
radius_tr = MIN ( radius_tr, j );
|
2017-02-06 15:31:13 -05:00
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( ( radius_tl + radius_tr ) > ( hspace ) ) {
|
|
|
|
int j = floor ( ( hspace ) / 2.0 );
|
2017-02-06 15:31:13 -05:00
|
|
|
radius_tr = MIN ( radius_tr, j );
|
|
|
|
radius_tl = MIN ( radius_tl, j );
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( ( radius_bl + radius_br ) > ( hspace ) ) {
|
|
|
|
int j = floor ( ( hspace ) / 2.0 );
|
2017-02-06 15:31:13 -05:00
|
|
|
radius_br = MIN ( radius_br, j );
|
|
|
|
radius_bl = MIN ( radius_bl, j );
|
|
|
|
}
|
|
|
|
|
2017-02-06 15:17:56 -05:00
|
|
|
// Background painting.
|
2016-12-28 06:21:42 -05:00
|
|
|
// Set new x/y possition.
|
2017-01-08 15:36:06 -05:00
|
|
|
cairo_translate ( d, widget->x, widget->y );
|
2017-02-06 17:30:39 -05:00
|
|
|
cairo_set_line_width ( d, 0 );
|
2017-02-06 17:45:46 -05:00
|
|
|
// Set outlines.
|
|
|
|
cairo_move_to ( d, margin_left + radius_tl + left / 2.0, margin_top + radius_tl + top / 2.0 );
|
2017-02-06 17:30:39 -05:00
|
|
|
if ( radius_tl ) {
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_arc ( d, margin_left + radius_tl + left / 2.0, margin_top + radius_tl + top / 2.0, radius_tl, -1.0 * M_PI, -0.5 * M_PI );
|
2017-02-06 17:30:39 -05:00
|
|
|
}
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_tr - right / 2.0, margin_top + top / 2.0 );
|
2017-02-06 17:30:39 -05:00
|
|
|
if ( radius_tr ) {
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_arc ( d, widget->w - margin_right - radius_tr - right / 2.0, margin_top + radius_tr + top / 2.0, radius_tr, -0.5 * M_PI, 0 * M_PI );
|
2017-02-06 17:30:39 -05:00
|
|
|
}
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom - radius_br - bottom / 2.0 );
|
2017-02-06 17:30:39 -05:00
|
|
|
if ( radius_br ) {
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_arc ( d, widget->w - margin_right - radius_br - right / 2.0, widget->h - margin_bottom - radius_br - bottom / 2.0, radius_br, 0.0 * M_PI, 0.5 * M_PI );
|
2017-02-06 17:30:39 -05:00
|
|
|
}
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_line_to ( d, margin_left + radius_bl + left / 2.0, widget->h - margin_bottom - bottom / 2.0 );
|
2017-02-06 17:30:39 -05:00
|
|
|
if ( radius_bl ) {
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_arc ( d, margin_left + radius_bl + left / 2.0, widget->h - margin_bottom - radius_bl - bottom / 2.0, radius_bl, 0.5 * M_PI, 1.0 * M_PI );
|
2017-02-06 17:30:39 -05:00
|
|
|
}
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_line_to ( d, margin_left + left / 2.0, margin_top + radius_tl + top / 2.0 );
|
2017-02-06 17:30:39 -05:00
|
|
|
cairo_close_path ( d );
|
|
|
|
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 );
|
|
|
|
rofi_theme_get_color ( widget, "background", d );
|
|
|
|
cairo_fill_preserve ( d );
|
2017-02-06 17:30:39 -05:00
|
|
|
cairo_clip ( d );
|
|
|
|
|
|
|
|
widget->draw ( widget, d );
|
|
|
|
widget->need_redraw = FALSE;
|
|
|
|
|
|
|
|
cairo_restore ( d );
|
|
|
|
|
2017-01-04 08:01:28 -05:00
|
|
|
if ( left || top || right || bottom ) {
|
2017-01-04 16:46:46 -05:00
|
|
|
cairo_save ( d );
|
2017-02-06 17:30:39 -05:00
|
|
|
cairo_translate ( d, widget->x, widget->y );
|
2017-02-06 15:17:56 -05:00
|
|
|
cairo_new_path ( d );
|
2017-01-04 16:27:27 -05:00
|
|
|
rofi_theme_get_color ( widget, "foreground", d );
|
2017-01-04 08:01:28 -05:00
|
|
|
if ( left > 0 ) {
|
2017-02-09 02:27:26 -05:00
|
|
|
double offset = ( radius_tl > 0 ) ? top / 2.0 : 0;
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_set_line_width ( d, left );
|
2017-01-08 15:36:06 -05:00
|
|
|
distance_get_linestyle ( widget->border.left, d );
|
2017-02-09 02:27:26 -05:00
|
|
|
cairo_move_to ( d, margin_left + left / 2.0, margin_top + radius_tl + offset );
|
|
|
|
offset = ( radius_bl > 0 ) ? bottom / 2.0 : 0;
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_line_to ( d, margin_left + left / 2.0, widget->h - margin_bottom - radius_bl - offset );
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
2017-02-06 15:17:56 -05:00
|
|
|
if ( radius_tl > 0 ) {
|
|
|
|
distance_get_linestyle ( widget->border.left, d );
|
|
|
|
if ( left == top ) {
|
|
|
|
cairo_set_line_width ( d, left );
|
|
|
|
cairo_arc ( d,
|
|
|
|
margin_left + left / 2.0 + radius_tl, margin_top + radius_tl + top / 2.0, radius_tl, -M_PI, -0.5 * M_PI );
|
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_set_line_width ( d, 0 );
|
2017-02-09 02:27:26 -05:00
|
|
|
double minof = ceil ( MIN ( left / 2.0, top / 2.0 ) );
|
|
|
|
double radius_outer = radius_tl + minof;
|
|
|
|
double radius_inner = radius_tl - minof;
|
|
|
|
cairo_arc ( d, margin_left + radius_outer, margin_top + radius_outer, radius_outer, -M_PI, -0.5 * M_PI );
|
|
|
|
cairo_line_to ( d, margin_left + radius_tl + ceil ( left / 2.0 ), margin_top );
|
|
|
|
cairo_line_to ( d, margin_left + radius_tl + ceil ( left / 2.0 ), margin_top + top );
|
|
|
|
cairo_arc_negative ( d, margin_left + left + radius_inner, margin_top + top + radius_inner, radius_inner, -0.5 * M_PI, M_PI );
|
|
|
|
cairo_line_to ( d, margin_left + left, margin_top + radius_tl + ceil ( top / 2.0 ) );
|
|
|
|
cairo_line_to ( d, margin_left, margin_top + radius_tl + ceil ( top / 2.0 ) );
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_close_path ( d );
|
2017-02-09 02:27:26 -05:00
|
|
|
cairo_fill ( d );
|
2017-02-06 15:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( top > 0 ) {
|
2017-02-09 02:27:26 -05:00
|
|
|
double offset = ( radius_tl > 0 ) ? ( left / 2.0 ) : 0;
|
2017-02-08 13:48:15 -05:00
|
|
|
cairo_set_line_width ( d, top );
|
|
|
|
distance_get_linestyle ( widget->border.top, d );
|
2017-02-09 02:27:26 -05:00
|
|
|
cairo_move_to ( d, margin_left + radius_tl + offset, margin_top + top / 2.0 );
|
|
|
|
offset = ( radius_tr > 0 ) ? right / 2.0 : 0;
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_tr - offset, margin_top + top / 2.0 );
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
2017-02-06 15:17:56 -05:00
|
|
|
if ( radius_tr > 0 ) {
|
|
|
|
distance_get_linestyle ( widget->border.right, d );
|
|
|
|
if ( top == right ) {
|
|
|
|
cairo_set_line_width ( d, right );
|
|
|
|
cairo_arc ( d, widget->w - margin_right - right / 2.0 - radius_tr, margin_top + radius_tr + right / 2.0, radius_tr, -0.5 * M_PI, 0 * M_PI );
|
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_set_line_width ( d, 0 );
|
2017-02-09 02:27:26 -05:00
|
|
|
double minof = ceil ( MIN ( right / 2.0, top / 2.0 ) );
|
|
|
|
double radius_outer = radius_tr + minof;
|
|
|
|
double radius_inner = radius_tr - minof;
|
|
|
|
cairo_arc ( d, widget->w - margin_right - radius_outer, margin_top + radius_outer, radius_outer, -0.5 * M_PI, 0 );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right, margin_top + radius_tr + ceil ( top / 2.0 ) );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - right, margin_top + radius_tr + ceil ( top / 2.0 ) );
|
|
|
|
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner, margin_top + top + radius_inner, radius_inner, 0, -0.5 * M_PI );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_tr - ceil ( right / 2.0 ), margin_top + top );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_tr - ceil ( right / 2.0 ), margin_top );
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_close_path ( d );
|
2017-02-09 02:27:26 -05:00
|
|
|
cairo_fill ( d );
|
2017-02-06 15:17:56 -05:00
|
|
|
}
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( right > 0 ) {
|
2017-02-09 02:27:26 -05:00
|
|
|
double offset = ( radius_tr > 0 ) ? top / 2.0 : 0;
|
2017-02-08 13:48:15 -05:00
|
|
|
cairo_set_line_width ( d, right );
|
|
|
|
distance_get_linestyle ( widget->border.right, d );
|
2017-02-09 02:27:26 -05:00
|
|
|
cairo_move_to ( d, widget->w - margin_right - right / 2.0, margin_top + radius_tr + offset );
|
|
|
|
offset = ( radius_br > 0 ) ? bottom / 2.0 : 0;
|
2017-02-08 13:48:15 -05:00
|
|
|
cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom - radius_br - offset );
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( radius_br > 0 ) {
|
|
|
|
distance_get_linestyle ( widget->border.right, d );
|
|
|
|
if ( bottom == right ) {
|
|
|
|
cairo_set_line_width ( d, right );
|
|
|
|
cairo_arc ( d, widget->w - margin_right - right / 2.0 - radius_br, widget->h - margin_bottom - radius_br - right / 2.0, radius_br, 0.0 * M_PI, 0.5 * M_PI );
|
2017-02-06 15:17:56 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_set_line_width ( d, 0 );
|
2017-02-09 02:27:26 -05:00
|
|
|
double minof = ceil ( MIN ( right / 2.0, bottom / 2.0 ) );
|
|
|
|
double radius_outer = radius_br + minof;
|
|
|
|
double radius_inner = radius_br - minof;
|
|
|
|
cairo_arc ( d, widget->w - margin_right - radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, 0.0, 0.5 * M_PI );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_br - ceil ( right / 2.0 ), widget->h - margin_bottom );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_br - ceil ( right / 2.0 ), widget->h - margin_bottom - bottom );
|
|
|
|
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner, widget->h - margin_bottom - bottom - radius_inner, radius_inner, 0.5 * M_PI, 0.0 );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - right, widget->h - margin_bottom - radius_br - ceil ( bottom / 2.0 ) );
|
|
|
|
cairo_line_to ( d, widget->w - margin_right, widget->h - margin_bottom - radius_br - ceil ( bottom / 2.0 ) );
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_close_path ( d );
|
2017-02-06 15:17:56 -05:00
|
|
|
cairo_fill ( d );
|
|
|
|
}
|
|
|
|
}
|
2017-01-04 08:01:28 -05:00
|
|
|
if ( bottom > 0 ) {
|
2017-02-09 02:27:26 -05:00
|
|
|
double offset = ( radius_bl > 0 ) ? ( left / 2.0 ) : 0;
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_set_line_width ( d, bottom );
|
2017-01-08 15:36:06 -05:00
|
|
|
distance_get_linestyle ( widget->border.bottom, d );
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_move_to ( d, margin_left + radius_bl + offset, widget->h - bottom / 2.0 - margin_bottom );
|
2017-02-09 02:27:26 -05:00
|
|
|
offset = ( radius_br > 0 ) ? ( right / 2.0 ) : 0;
|
|
|
|
cairo_line_to ( d, widget->w - margin_right - radius_br - offset, widget->h - bottom / 2.0 - margin_bottom );
|
2017-01-04 08:01:28 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
2017-02-08 13:48:15 -05:00
|
|
|
if ( radius_bl > 0 ) {
|
|
|
|
distance_get_linestyle ( widget->border.left, d );
|
|
|
|
if ( bottom == left ) {
|
|
|
|
cairo_set_line_width ( d, left );
|
|
|
|
cairo_arc ( d, margin_left + left / 2.0 + radius_bl, widget->h - margin_bottom - radius_bl - left / 2.0, radius_bl, 0.5 * M_PI, 1.0 * M_PI );
|
2017-02-06 15:17:56 -05:00
|
|
|
cairo_stroke ( d );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_set_line_width ( d, 0 );
|
2017-02-09 02:27:26 -05:00
|
|
|
double minof = ceil ( MIN ( left / 2.0, bottom / 2.0 ) );
|
|
|
|
double radius_outer = radius_bl + minof;
|
|
|
|
double radius_inner = radius_bl - minof;
|
|
|
|
cairo_arc ( d, margin_left + radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, 0.5 * M_PI, M_PI );
|
|
|
|
cairo_line_to ( d, margin_left, widget->h - margin_bottom - radius_bl - ceil ( bottom / 2.0 ) );
|
|
|
|
cairo_line_to ( d, margin_left + left, widget->h - margin_bottom - radius_bl - ceil ( bottom / 2.0 ) );
|
|
|
|
cairo_arc_negative ( d, margin_left + left + radius_inner, widget->h - margin_bottom - bottom - radius_inner, radius_inner, M_PI, 0.5 * M_PI );
|
|
|
|
cairo_line_to ( d, margin_left + radius_bl + ceil ( left / 2.0 ), widget->h - margin_bottom - bottom );
|
|
|
|
cairo_line_to ( d, margin_left + radius_bl + ceil ( left / 2.0 ), widget->h - margin_bottom );
|
2017-02-08 04:15:38 -05:00
|
|
|
cairo_close_path ( d );
|
2017-02-06 15:17:56 -05:00
|
|
|
cairo_fill ( d );
|
|
|
|
}
|
|
|
|
}
|
2017-01-08 15:36:06 -05:00
|
|
|
cairo_restore ( d );
|
2017-01-03 09:39:19 -05:00
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-18 07:49:24 -04:00
|
|
|
void widget_free ( widget *wid )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2016-12-11 06:19:46 -05:00
|
|
|
if ( wid ) {
|
|
|
|
if ( wid->name ) {
|
|
|
|
g_free ( wid->name );
|
|
|
|
}
|
|
|
|
if ( wid->free ) {
|
|
|
|
wid->free ( wid );
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int widget_get_height ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->get_height ) {
|
|
|
|
return widget->get_height ( widget );
|
|
|
|
}
|
|
|
|
return widget->h;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int widget_get_width ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->get_width ) {
|
|
|
|
return widget->get_width ( widget );
|
|
|
|
}
|
|
|
|
return widget->w;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-17 12:21:03 -04:00
|
|
|
int widget_get_x_pos ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
return widget->x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int widget_get_y_pos ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
return widget->y;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
void widget_update ( widget *widget )
|
|
|
|
{
|
|
|
|
// When (desired )size of widget changes.
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->update ) {
|
|
|
|
widget->update ( widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_queue_redraw ( widget *wid )
|
|
|
|
{
|
|
|
|
if ( wid ) {
|
|
|
|
widget *iter = wid;
|
|
|
|
// Find toplevel widget.
|
|
|
|
while ( iter->parent != NULL ) {
|
2016-10-13 03:22:08 -04:00
|
|
|
iter->need_redraw = TRUE;
|
2016-10-14 10:46:54 -04:00
|
|
|
iter = iter->parent;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
iter->need_redraw = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean widget_need_redraw ( widget *wid )
|
|
|
|
{
|
2016-11-10 06:17:27 -05:00
|
|
|
if ( wid && wid->enabled ) {
|
2016-10-08 12:57:59 -04:00
|
|
|
return wid->need_redraw;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe )
|
|
|
|
{
|
|
|
|
if ( wid && wid->clicked ) {
|
|
|
|
return wid->clicked ( wid, xbe, wid->clicked_cb_data );
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata )
|
|
|
|
{
|
|
|
|
if ( wid ) {
|
|
|
|
wid->clicked = cb;
|
|
|
|
wid->clicked_cb_data = udata;
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 15:19:39 -04:00
|
|
|
|
|
|
|
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
|
|
|
|
{
|
|
|
|
if ( wid && wid->motion_notify ) {
|
|
|
|
wid->motion_notify ( wid, xme );
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-12-11 06:19:46 -05:00
|
|
|
|
2016-12-28 13:42:14 -05:00
|
|
|
int widget_padding_get_left ( const widget *wid )
|
|
|
|
{
|
2017-01-03 13:23:09 -05:00
|
|
|
int distance = distance_get_pixel ( wid->padding.left, ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.left, ORIENTATION_HORIZONTAL );
|
2017-01-03 17:51:15 -05:00
|
|
|
distance += distance_get_pixel ( wid->margin.left, ORIENTATION_HORIZONTAL );
|
2017-01-03 09:39:19 -05:00
|
|
|
return distance;
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
int widget_padding_get_right ( const widget *wid )
|
|
|
|
{
|
2017-01-03 13:23:09 -05:00
|
|
|
int distance = distance_get_pixel ( wid->padding.right, ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.right, ORIENTATION_HORIZONTAL );
|
2017-01-03 17:51:15 -05:00
|
|
|
distance += distance_get_pixel ( wid->margin.right, ORIENTATION_HORIZONTAL );
|
2017-01-03 09:39:19 -05:00
|
|
|
return distance;
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
int widget_padding_get_top ( const widget *wid )
|
|
|
|
{
|
2017-01-03 13:23:09 -05:00
|
|
|
int distance = distance_get_pixel ( wid->padding.top, ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.top, ORIENTATION_VERTICAL );
|
2017-01-03 17:51:15 -05:00
|
|
|
distance += distance_get_pixel ( wid->margin.top, ORIENTATION_VERTICAL );
|
2017-01-03 09:39:19 -05:00
|
|
|
return distance;
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
int widget_padding_get_bottom ( const widget *wid )
|
|
|
|
{
|
2017-01-03 13:23:09 -05:00
|
|
|
int distance = distance_get_pixel ( wid->padding.bottom, ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.bottom, ORIENTATION_VERTICAL );
|
2017-01-03 17:51:15 -05:00
|
|
|
distance += distance_get_pixel ( wid->margin.bottom, ORIENTATION_VERTICAL );
|
2017-01-03 09:39:19 -05:00
|
|
|
return distance;
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int widget_padding_get_remaining_width ( const widget *wid )
|
|
|
|
{
|
|
|
|
int width = wid->w;
|
|
|
|
width -= widget_padding_get_left ( wid );
|
|
|
|
width -= widget_padding_get_right ( wid );
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
int widget_padding_get_remaining_height ( const widget *wid )
|
|
|
|
{
|
|
|
|
int height = wid->h;
|
|
|
|
height -= widget_padding_get_top ( wid );
|
|
|
|
height -= widget_padding_get_bottom ( wid );
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
int widget_padding_get_padding_height ( const widget *wid )
|
|
|
|
{
|
2016-12-30 12:31:30 -05:00
|
|
|
int height = 0;
|
2016-12-28 13:42:14 -05:00
|
|
|
height += widget_padding_get_top ( wid );
|
|
|
|
height += widget_padding_get_bottom ( wid );
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
int widget_padding_get_padding_width ( const widget *wid )
|
|
|
|
{
|
2016-12-30 12:31:30 -05:00
|
|
|
int width = 0;
|
2016-12-28 13:42:14 -05:00
|
|
|
width += widget_padding_get_left ( wid );
|
|
|
|
width += widget_padding_get_right ( wid );
|
|
|
|
return width;
|
|
|
|
}
|
2016-12-30 12:31:30 -05:00
|
|
|
|
|
|
|
int widget_get_desired_height ( widget *wid )
|
|
|
|
{
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( wid && wid->get_desired_height ) {
|
2016-12-30 12:31:30 -05:00
|
|
|
return wid->get_desired_height ( wid );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|