2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
2021-06-09 08:50:39 -04:00
|
|
|
* Copyright © 2013-2021 Qball Cow <qball@gmpclient.org>
|
2017-04-15 06:32:05 -04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
2021-05-05 15:53:29 -04:00
|
|
|
/** macro for initializing the padding struction. */
|
2020-08-28 10:41:59 -04:00
|
|
|
#define WIDGET_PADDING_INIT { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }
|
2017-01-09 16:29:31 -05:00
|
|
|
|
2020-06-17 08:10:48 -04:00
|
|
|
/* Corner radius - tl, tr, br, bl */
|
|
|
|
static void draw_rounded_rect ( cairo_t * d,
|
|
|
|
double x1, double y1, double x2, double y2,
|
|
|
|
double r0, double r1, double r2, double r3 )
|
|
|
|
{
|
|
|
|
if ( r0 > 0 ) {
|
2020-08-28 10:41:59 -04:00
|
|
|
cairo_move_to ( d, x1, y1 + r0 );
|
|
|
|
cairo_arc ( d, x1 + r0, y1 + r0, r0, -G_PI, -G_PI_2 );
|
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
cairo_move_to ( d, x1, y1 );
|
|
|
|
}
|
|
|
|
if ( r1 > 0 ) {
|
2020-08-28 10:41:59 -04:00
|
|
|
cairo_line_to ( d, x2 - r1, y1 );
|
|
|
|
cairo_arc ( d, x2 - r1, y1 + r1, r1, -G_PI_2, 0.0 );
|
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
cairo_line_to ( d, x2, y1 );
|
|
|
|
}
|
|
|
|
if ( r2 > 0 ) {
|
2020-08-28 10:41:59 -04:00
|
|
|
cairo_line_to ( d, x2, y2 - r2 );
|
|
|
|
cairo_arc ( d, x2 - r2, y2 - r2, r2, 0.0, G_PI_2 );
|
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
cairo_line_to ( d, x2, y2 );
|
|
|
|
}
|
|
|
|
if ( r3 > 0 ) {
|
2020-08-28 10:41:59 -04:00
|
|
|
cairo_line_to ( d, x1 + r3, y2 );
|
|
|
|
cairo_arc ( d, x1 + r3, y2 - r3, r3, G_PI_2, G_PI );
|
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
cairo_line_to ( d, x1, y2 );
|
|
|
|
}
|
|
|
|
cairo_close_path ( d );
|
|
|
|
}
|
|
|
|
|
2017-09-07 07:46:09 -04:00
|
|
|
void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name )
|
2016-12-27 16:19:15 -05:00
|
|
|
{
|
2020-08-28 10:41:59 -04:00
|
|
|
wid->type = type;
|
|
|
|
wid->parent = parent;
|
|
|
|
wid->name = g_strdup ( name );
|
2020-07-11 08:48:58 -04:00
|
|
|
wid->def_padding = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
|
|
|
|
wid->def_border = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
|
|
|
|
wid->def_border_radius = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
|
|
|
|
wid->def_margin = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
|
2017-02-06 15:17:56 -05:00
|
|
|
|
2017-09-07 07:46:09 -04:00
|
|
|
wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding );
|
|
|
|
wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border );
|
|
|
|
wid->border_radius = rofi_theme_get_padding ( wid, "border-radius", wid->def_border_radius );
|
|
|
|
wid->margin = rofi_theme_get_padding ( wid, "margin", wid->def_margin );
|
2017-09-07 02:52:30 -04:00
|
|
|
|
2021-06-01 04:44:23 -04:00
|
|
|
wid->cursor_type = rofi_theme_get_cursor_type ( wid, "cursor", ROFI_CURSOR_DEFAULT );
|
2021-05-22 18:17:27 -04:00
|
|
|
|
|
|
|
// enabled by default
|
2017-09-07 07:46:09 -04:00
|
|
|
wid->enabled = rofi_theme_get_boolean ( wid, "enabled", TRUE );
|
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 )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
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 );
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget->set_state != NULL ) {
|
2020-05-13 10:25:12 -04:00
|
|
|
widget->set_state ( widget, state );
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) &&
|
|
|
|
y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
|
|
|
|
return TRUE;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_resize ( widget *widget, short w, short h )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( widget->resize != NULL ) {
|
|
|
|
if ( widget->w != w || widget->h != h ) {
|
|
|
|
widget->resize ( widget, w, h );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
else {
|
|
|
|
widget->w = w;
|
|
|
|
widget->h = h;
|
|
|
|
}
|
|
|
|
// 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 )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
widget->x = x;
|
|
|
|
widget->y = y;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2019-08-08 14:02:20 -04:00
|
|
|
void widget_set_type ( widget *widget, WidgetType type )
|
|
|
|
{
|
|
|
|
if ( widget == NULL ) {
|
2020-02-02 07:56:37 -05:00
|
|
|
return;
|
2019-08-08 14:02:20 -04:00
|
|
|
}
|
|
|
|
widget->type = type;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2017-05-27 20:18:09 -04:00
|
|
|
WidgetType widget_type ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return WIDGET_TYPE_UNKNOWN;
|
2017-05-27 20:18:09 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->type;
|
2017-05-27 20:18:09 -04:00
|
|
|
}
|
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
gboolean widget_enabled ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return FALSE;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->enabled;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
|
2020-07-11 08:48:58 -04:00
|
|
|
void widget_set_enabled ( widget *widget, gboolean enabled )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget->enabled != enabled ) {
|
|
|
|
widget->enabled = enabled;
|
2016-10-08 12:57:59 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
void widget_draw ( widget *widget, cairo_t *d )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
// Check if enabled and if draw is implemented.
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( 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-06-02 10:34:52 -04:00
|
|
|
const int margin_left = distance_get_pixel ( widget->margin.left, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
const int margin_top = distance_get_pixel ( widget->margin.top, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
const int margin_right = distance_get_pixel ( widget->margin.right, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
const int margin_bottom = distance_get_pixel ( widget->margin.bottom, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
const int left = distance_get_pixel ( widget->border.left, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
const int right = distance_get_pixel ( widget->border.right, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
const int top = distance_get_pixel ( widget->border.top, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
const int bottom = distance_get_pixel ( widget->border.bottom, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
int radius_bl = distance_get_pixel ( widget->border_radius.left, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
int radius_tr = distance_get_pixel ( widget->border_radius.right, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
int radius_tl = distance_get_pixel ( widget->border_radius.top, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ROFI_ORIENTATION_VERTICAL );
|
2017-02-06 17:45:46 -05:00
|
|
|
|
2020-08-28 10:41:59 -04:00
|
|
|
double minof_tl, minof_tr, minof_br, minof_bl;
|
2020-06-17 08:10:48 -04:00
|
|
|
{
|
2020-08-28 10:41:59 -04:00
|
|
|
double left_2 = (double) left / 2;
|
|
|
|
double top_2 = (double) top / 2;
|
|
|
|
double right_2 = (double) right / 2;
|
2020-06-17 08:10:48 -04:00
|
|
|
double bottom_2 = (double) bottom / 2;
|
|
|
|
|
|
|
|
// Calculate the different offsets for the corners.
|
2020-08-28 10:41:59 -04:00
|
|
|
minof_tl = MIN ( left_2, top_2 );
|
2020-06-17 08:10:48 -04:00
|
|
|
minof_tr = MIN ( right_2, top_2 );
|
|
|
|
minof_br = MIN ( right_2, bottom_2 );
|
2020-08-28 10:41:59 -04:00
|
|
|
minof_bl = MIN ( left_2, bottom_2 );
|
2020-06-17 08:10:48 -04:00
|
|
|
|
|
|
|
// Contain border radius in widget space
|
|
|
|
double vspace, vspace_2, hspace, hspace_2;
|
2020-08-28 10:41:59 -04:00
|
|
|
vspace = widget->h - ( margin_top + margin_bottom ) - ( top_2 + bottom_2 );
|
|
|
|
hspace = widget->w - ( margin_left + margin_right ) - ( left_2 + right_2 );
|
2020-06-17 08:10:48 -04:00
|
|
|
vspace_2 = vspace / 2;
|
|
|
|
hspace_2 = hspace / 2;
|
|
|
|
|
|
|
|
if ( radius_bl + radius_tl > vspace ) {
|
|
|
|
radius_bl = MIN ( radius_bl, vspace_2 );
|
|
|
|
radius_tl = MIN ( radius_tl, vspace_2 );
|
|
|
|
}
|
|
|
|
if ( radius_br + radius_tr > vspace ) {
|
|
|
|
radius_br = MIN ( radius_br, vspace_2 );
|
|
|
|
radius_tr = MIN ( radius_tr, vspace_2 );
|
|
|
|
}
|
|
|
|
if ( radius_tl + radius_tr > hspace ) {
|
|
|
|
radius_tr = MIN ( radius_tr, hspace_2 );
|
|
|
|
radius_tl = MIN ( radius_tl, hspace_2 );
|
|
|
|
}
|
|
|
|
if ( radius_bl + radius_br > hspace ) {
|
|
|
|
radius_br = MIN ( radius_br, hspace_2 );
|
|
|
|
radius_bl = MIN ( radius_bl, hspace_2 );
|
|
|
|
}
|
2017-02-06 15:31:13 -05:00
|
|
|
}
|
|
|
|
|
2017-02-06 15:17:56 -05:00
|
|
|
// Background painting.
|
2017-11-23 12:41:52 -05:00
|
|
|
// Set new x/y position.
|
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 );
|
2020-06-17 08:10:48 -04:00
|
|
|
|
|
|
|
draw_rounded_rect ( d,
|
2020-08-28 10:41:59 -04:00
|
|
|
margin_left + ( left > 2 ? left - 1 : left == 1 ? 0.5 : 0 ),
|
|
|
|
margin_top + ( top > 2 ? top - 1 : top == 1 ? 0.5 : 0 ),
|
|
|
|
widget->w - margin_right - ( right > 2 ? right - 1 : right == 1 ? 0.5 : 0 ),
|
2020-06-17 08:10:48 -04:00
|
|
|
widget->h - margin_bottom - ( bottom > 2 ? bottom - 1 : bottom == 1 ? 0.5 : 0 ),
|
|
|
|
radius_tl - ( minof_tl > 1 ? minof_tl - 1 : 0 ),
|
|
|
|
radius_tr - ( minof_tr > 1 ? minof_tr - 1 : 0 ),
|
|
|
|
radius_br - ( minof_br > 1 ? minof_br - 1 : 0 ),
|
|
|
|
radius_bl - ( minof_bl > 1 ? minof_bl - 1 : 0 ) );
|
2017-02-06 17:30:39 -05:00
|
|
|
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 );
|
2017-09-06 13:02:09 -04:00
|
|
|
rofi_theme_get_color ( widget, "background-color", d );
|
2017-02-06 17:45:46 -05:00
|
|
|
cairo_fill_preserve ( d );
|
2021-06-13 15:41:31 -04:00
|
|
|
if ( rofi_theme_get_image ( widget, "background-image", 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 );
|
|
|
|
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( left != 0 || top != 0 || right != 0 || bottom != 0 ) {
|
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-09-06 13:02:09 -04:00
|
|
|
rofi_theme_get_color ( widget, "border-color", d );
|
2018-04-08 04:19:43 -04:00
|
|
|
|
2020-06-17 08:10:48 -04:00
|
|
|
double radius_int_tl, radius_int_tr, radius_int_br, radius_int_bl;
|
|
|
|
double radius_out_tl, radius_out_tr, radius_out_br, radius_out_bl;
|
2018-04-08 04:19:43 -04:00
|
|
|
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( radius_tl > 0 ) {
|
|
|
|
radius_out_tl = radius_tl + minof_tl,
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_int_tl = radius_tl - minof_tl;
|
2020-08-28 10:41:59 -04:00
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_out_tl = radius_int_tl = 0;
|
2017-01-04 08:01:28 -05:00
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( radius_tr > 0 ) {
|
|
|
|
radius_out_tr = radius_tr + minof_tr,
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_int_tr = radius_tr - minof_tr;
|
2020-08-28 10:41:59 -04:00
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_out_tr = radius_int_tr = 0;
|
2018-04-08 04:19:43 -04:00
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( radius_br > 0 ) {
|
|
|
|
radius_out_br = radius_br + minof_br,
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_int_br = radius_br - minof_br;
|
2020-08-28 10:41:59 -04:00
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_out_br = radius_int_br = 0;
|
2017-02-06 15:17:56 -05:00
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( radius_bl > 0 ) {
|
|
|
|
radius_out_bl = radius_bl + minof_bl,
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_int_bl = radius_bl - minof_bl;
|
2020-08-28 10:41:59 -04:00
|
|
|
}
|
|
|
|
else {
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_out_bl = radius_int_bl = 0;
|
2017-02-06 15:17:56 -05:00
|
|
|
}
|
2020-06-17 08:10:48 -04:00
|
|
|
|
|
|
|
draw_rounded_rect ( d,
|
|
|
|
margin_left,
|
|
|
|
margin_top,
|
|
|
|
widget->w - margin_right,
|
2020-09-05 05:12:38 -04:00
|
|
|
widget->h - margin_bottom,
|
2020-06-17 08:10:48 -04:00
|
|
|
radius_out_tl,
|
|
|
|
radius_out_tr,
|
|
|
|
radius_out_br,
|
|
|
|
radius_out_bl );
|
|
|
|
cairo_new_sub_path ( d );
|
|
|
|
draw_rounded_rect ( d,
|
|
|
|
margin_left + left,
|
2020-08-28 10:41:59 -04:00
|
|
|
margin_top + top,
|
2020-06-17 08:10:48 -04:00
|
|
|
widget->w - margin_right - right,
|
|
|
|
widget->h - margin_bottom - bottom,
|
|
|
|
radius_int_tl,
|
|
|
|
radius_int_tr,
|
|
|
|
radius_int_br,
|
|
|
|
radius_int_bl );
|
|
|
|
cairo_set_fill_rule ( d, CAIRO_FILL_RULE_EVEN_ODD );
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2018-06-09 13:13:57 -04:00
|
|
|
|
2016-10-18 07:49:24 -04:00
|
|
|
void widget_free ( widget *wid )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( wid->name != NULL ) {
|
|
|
|
g_free ( wid->name );
|
|
|
|
}
|
|
|
|
if ( wid->free != NULL ) {
|
|
|
|
wid->free ( wid );
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int widget_get_height ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( widget->get_height == NULL ) {
|
2016-10-08 12:57:59 -04:00
|
|
|
return widget->h;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->get_height ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
int widget_get_width ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( widget->get_width == NULL ) {
|
2016-10-08 12:57:59 -04:00
|
|
|
return widget->w;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->get_width ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2016-10-17 12:21:03 -04:00
|
|
|
int widget_get_x_pos ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return 0;
|
2016-10-17 12:21:03 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->x;
|
2016-10-17 12:21:03 -04:00
|
|
|
}
|
|
|
|
int widget_get_y_pos ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return 0;
|
2016-10-17 12:21:03 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return widget->y;
|
2016-10-17 12:21:03 -04:00
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2017-05-30 06:37:11 -04:00
|
|
|
void widget_xy_to_relative ( widget *widget, gint *x, gint *y )
|
|
|
|
{
|
|
|
|
*x -= widget->x;
|
|
|
|
*y -= widget->y;
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget->parent == NULL ) {
|
|
|
|
return;
|
2017-05-30 06:37:11 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
widget_xy_to_relative ( widget->parent, x, y );
|
2017-05-30 06:37:11 -04:00
|
|
|
}
|
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
void widget_update ( widget *widget )
|
|
|
|
{
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
// When (desired )size of widget changes.
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( widget->update != NULL ) {
|
|
|
|
widget->update ( widget );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_queue_redraw ( widget *wid )
|
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
2020-07-11 08:48:58 -04:00
|
|
|
return;
|
2020-07-09 11:47:32 -04:00
|
|
|
}
|
|
|
|
widget *iter = wid;
|
|
|
|
// Find toplevel widget.
|
|
|
|
while ( iter->parent != NULL ) {
|
2020-07-11 08:48:58 -04:00
|
|
|
iter->need_redraw = TRUE;
|
|
|
|
iter = iter->parent;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-09 11:47:32 -04:00
|
|
|
iter->need_redraw = TRUE;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean widget_need_redraw ( widget *wid )
|
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-08-28 10:41:59 -04:00
|
|
|
if ( !wid->enabled ) {
|
2020-07-11 08:48:58 -04:00
|
|
|
return FALSE;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return wid->need_redraw;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2017-05-27 20:18:09 -04:00
|
|
|
|
2017-05-30 06:37:11 -04:00
|
|
|
widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
2017-05-27 20:18:09 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->find_mouse_target != NULL ) {
|
2017-05-27 20:18:09 -04:00
|
|
|
widget *target = wid->find_mouse_target ( wid, type, x, y );
|
|
|
|
if ( target != NULL ) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 18:17:27 -04:00
|
|
|
|
|
|
|
if ( wid->type == type || type == WIDGET_TYPE_UNKNOWN ) {
|
2017-05-27 20:18:09 -04:00
|
|
|
return wid;
|
|
|
|
}
|
2021-05-22 18:17:27 -04:00
|
|
|
|
2017-05-27 20:18:09 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-30 06:45:48 -04:00
|
|
|
WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->trigger_action == NULL ) {
|
|
|
|
return FALSE;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return wid->trigger_action ( wid, action, x, y, wid->trigger_action_cb_data );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2017-05-27 20:18:09 -04:00
|
|
|
|
|
|
|
void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb cb, void * cb_data )
|
2016-10-08 12:57:59 -04:00
|
|
|
{
|
2017-05-30 07:40:03 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2017-05-27 20:18:09 -04:00
|
|
|
wid->trigger_action = cb;
|
|
|
|
wid->trigger_action_cb_data = cb_data;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
2016-10-25 15:19:39 -04:00
|
|
|
|
2017-05-30 06:13:25 -04:00
|
|
|
gboolean widget_motion_notify ( widget *wid, gint x, gint y )
|
2016-10-25 15:19:39 -04:00
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->motion_notify == NULL ) {
|
|
|
|
return FALSE;
|
2016-10-25 15:19:39 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return wid->motion_notify ( wid, x, y );
|
2016-10-25 15:19:39 -04:00
|
|
|
}
|
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-05-28 11:34:53 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-02 10:34:52 -04:00
|
|
|
int distance = distance_get_pixel ( wid->padding.left, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.left, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->margin.left, ROFI_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-05-28 11:34:53 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-02 10:34:52 -04:00
|
|
|
int distance = distance_get_pixel ( wid->padding.right, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.right, ROFI_ORIENTATION_HORIZONTAL );
|
|
|
|
distance += distance_get_pixel ( wid->margin.right, ROFI_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-05-28 11:34:53 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-02 10:34:52 -04:00
|
|
|
int distance = distance_get_pixel ( wid->padding.top, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.top, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->margin.top, ROFI_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-05-28 11:34:53 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-02 10:34:52 -04:00
|
|
|
int distance = distance_get_pixel ( wid->padding.bottom, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->border.bottom, ROFI_ORIENTATION_VERTICAL );
|
|
|
|
distance += distance_get_pixel ( wid->margin.bottom, ROFI_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-06-09 03:18:17 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->get_desired_height == NULL ) {
|
|
|
|
return wid->h;
|
2016-12-30 12:31:30 -05:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return wid->get_desired_height ( wid );
|
2016-12-30 12:31:30 -05:00
|
|
|
}
|
2017-05-28 10:10:11 -04:00
|
|
|
int widget_get_desired_width ( widget *wid )
|
|
|
|
{
|
2017-06-09 03:18:17 -04:00
|
|
|
if ( wid == NULL ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->get_desired_width == NULL ) {
|
|
|
|
return wid->w;
|
2017-05-28 10:10:11 -04:00
|
|
|
}
|
2020-07-11 08:48:58 -04:00
|
|
|
return wid->get_desired_width ( wid );
|
2017-05-28 10:10:11 -04:00
|
|
|
}
|
2017-06-12 02:17:28 -04:00
|
|
|
|
|
|
|
int widget_get_absolute_xpos ( widget *wid )
|
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
2020-07-11 08:48:58 -04:00
|
|
|
return 0;
|
2020-07-09 11:47:32 -04:00
|
|
|
}
|
|
|
|
int retv = wid->x;
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->parent != NULL ) {
|
|
|
|
retv += widget_get_absolute_xpos ( wid->parent );
|
2017-06-12 02:17:28 -04:00
|
|
|
}
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
int widget_get_absolute_ypos ( widget *wid )
|
|
|
|
{
|
2020-07-09 11:47:32 -04:00
|
|
|
if ( wid == NULL ) {
|
2020-07-11 08:48:58 -04:00
|
|
|
return 0;
|
2020-07-09 11:47:32 -04:00
|
|
|
}
|
|
|
|
int retv = wid->y;
|
2020-07-11 08:48:58 -04:00
|
|
|
if ( wid->parent != NULL ) {
|
|
|
|
retv += widget_get_absolute_ypos ( wid->parent );
|
2017-06-12 02:17:28 -04:00
|
|
|
}
|
|
|
|
return retv;
|
|
|
|
}
|