Commit b4c2b3e6 authored by o9000's avatar o9000

Gradients: mostly done

parent 822b1494
......@@ -194,7 +194,7 @@ endif( ENABLE_TINT2CONF )
if( ENABLE_ASAN )
SET(ASAN_C_FLAGS " -O0 -g3 -gdwarf-2 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic -Wshadow")
SET(ASAN_L_FLAGS " -O0 -g3 -gdwarf-2 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic ")
SET(ASAN_L_FLAGS " -O0 -g3 -gdwarf-2 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic -fuse-ld=gold ")
else()
SET(ASAN_C_FLAGS "")
SET(ASAN_L_FLAGS "")
......
......@@ -164,6 +164,7 @@ void init_battery_panel(void *p)
battery->area.has_mouse_press_effect = battery->area.has_mouse_over_effect;
if (battery_tooltip_enabled)
battery->area._get_tooltip_text = battery_get_tooltip;
init_area_gradients(&battery->area);
}
void battery_init_fonts()
......
......@@ -196,6 +196,7 @@ void init_clock_panel(void *p)
clock->area.resize_needed = 1;
clock->area.on_screen = TRUE;
init_area_gradients(&clock->area);
if (time_tooltip_format) {
clock->area._get_tooltip_text = clock_get_tooltip;
......
......@@ -71,8 +71,6 @@ char *snapshot_path;
// detect if it's an old config file (==1)
static gboolean new_config_file;
static gboolean read_bg_color2;
static gboolean read_bg_gradient;
static gboolean read_bg_color_hover;
static gboolean read_border_color_hover;
static gboolean read_bg_color_press;
......@@ -244,12 +242,10 @@ void add_entry(char *key, char *value)
init_background(&bg);
bg.border.radius = atoi(value);
g_array_append_val(backgrounds, bg);
read_bg_color2 = 0;
read_bg_gradient = 0;
read_bg_color_hover = 0;
read_border_color_hover = 0;
read_bg_color_press = 0;
read_border_color_press = 0;
read_bg_color_hover = FALSE;
read_border_color_hover = FALSE;
read_bg_color_press = FALSE;
read_border_color_press = FALSE;
} else if (strcmp(key, "border_width") == 0) {
g_array_index(backgrounds, Background, backgrounds->len - 1).border.width = atoi(value);
} else if (strcmp(key, "border_sides") == 0) {
......@@ -345,27 +341,13 @@ void add_entry(char *key, char *value)
GradientClass *g = &g_array_index(gradients, GradientClass, gradients->len - 1);
extract_values(value, &value1, &value2, &value3);
ColorStop *color_stop = (ColorStop *) calloc(1, sizeof(ColorStop));
color_stop->offset = atof(value1);
color_stop->offset = atof(value1) / 100.0;
get_color(value2, color_stop->color.rgb);
if (value3)
color_stop->color.alpha = (atoi(value2) / 100.0);
color_stop->color.alpha = (atoi(value3) / 100.0);
else
color_stop->color.alpha = 0.5;
g->extra_color_stops = g_list_append(g->extra_color_stops, color_stop);
} else if (strcmp(key, "from_origin") == 0) {
GradientClass *g = &g_array_index(gradients, GradientClass, gradients->len - 1);
if (g->type == GRADIENT_HORIZONTAL || g->type == GRADIENT_VERTICAL || g->type == GRADIENT_CENTERED) {
fprintf(stderr, RED "Control points can only be specified for linear and radial gradients: line %s = %s" RESET "\n", key, value);
} else {
g->from.origin = origin_from_string(value);
}
} else if (strcmp(key, "to_origin") == 0) {
GradientClass *g = &g_array_index(gradients, GradientClass, gradients->len - 1);
if (g->type == GRADIENT_HORIZONTAL || g->type == GRADIENT_VERTICAL || g->type == GRADIENT_CENTERED) {
fprintf(stderr, RED "Control points can only be specified for linear and radial gradients: line %s = %s" RESET "\n", key, value);
} else {
g->to.origin = origin_from_string(value);
}
} else if (strcmp(key, "from_offset_x") == 0) {
GradientClass *g = &g_array_index(gradients, GradientClass, gradients->len - 1);
if (g->type == GRADIENT_HORIZONTAL || g->type == GRADIENT_VERTICAL || g->type == GRADIENT_CENTERED) {
......@@ -554,7 +536,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
panel_config.area.gradients = g_list_append(panel_config.area.gradients, &g_array_index(backgrounds, Background, id));
panel_config.area.gradients = g_list_append(panel_config.area.gradients, &g_array_index(gradients, GradientClass, id));
} else if (strcmp(key, "wm_menu") == 0)
wm_menu = atoi(value);
else if (strcmp(key, "panel_dock") == 0)
......@@ -663,7 +645,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
panel_config.battery.area.gradients = g_list_append(panel_config.battery.area.gradients, &g_array_index(backgrounds, Background, id));
panel_config.battery.area.gradients = g_list_append(panel_config.battery.area.gradients, &g_array_index(gradients, GradientClass, id));
#endif
} else if (strcmp(key, "battery_hide") == 0) {
#ifdef ENABLE_BATTERY
......@@ -690,7 +672,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
separator->area.gradients = g_list_append(separator->area.gradients, &g_array_index(backgrounds, Background, id));
separator->area.gradients = g_list_append(separator->area.gradients, &g_array_index(gradients, GradientClass, id));
} else if (strcmp(key, "separator_color") == 0) {
Separator *separator = get_or_create_last_separator();
extract_values(value, &value1, &value2, &value3);
......@@ -788,7 +770,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
execp->area.gradients = g_list_append(execp->area.gradients, &g_array_index(backgrounds, Background, id));
execp->area.gradients = g_list_append(execp->area.gradients, &g_array_index(gradients, GradientClass, id));
} else if (strcmp(key, "execp_centered") == 0) {
Execp *execp = get_or_create_last_execp();
execp->backend->centered = atoi(value);
......@@ -889,7 +871,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
panel_config.clock.area.gradients = g_list_append(panel_config.clock.area.gradients, &g_array_index(backgrounds, Background, id));
panel_config.clock.area.gradients = g_list_append(panel_config.clock.area.gradients, &g_array_index(gradients, GradientClass, id));
} else if (strcmp(key, "clock_tooltip") == 0) {
if (strlen(value) > 0)
time_tooltip_format = strdup(value);
......@@ -1175,7 +1157,7 @@ void add_entry(char *key, char *value)
int id = atoi(value);
id = (id < gradients->len && id >= 0) ? id : -1;
if (id >= 0)
launcher_icon_gradient = &g_array_index(gradients, GradientClass, id);
launcher_icon_gradients = g_list_append(launcher_icon_gradients, &g_array_index(gradients, GradientClass, id));
} else if (strcmp(key, "launcher_icon_size") == 0) {
launcher_max_icon_size = atoi(value);
} else if (strcmp(key, "launcher_item_app") == 0) {
......
......@@ -182,6 +182,7 @@ void init_execp_panel(void *p)
execp->area.resize_needed = TRUE;
execp->area.on_screen = TRUE;
init_area_gradients(&execp->area);
if (!execp->backend->timer)
execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer);
......
......@@ -53,7 +53,7 @@ char *icon_theme_name_xsettings;
int launcher_icon_theme_override;
int startup_notifications;
Background *launcher_icon_bg;
GradientClass *launcher_icon_gradient;
GList *launcher_icon_gradients;
Imlib_Image scale_icon(Imlib_Image original, int icon_size);
void free_icon(Imlib_Image icon);
......@@ -76,6 +76,7 @@ void default_launcher()
launcher_icon_theme_override = 0;
startup_notifications = 0;
launcher_icon_bg = NULL;
launcher_icon_gradients = NULL;
}
void init_launcher()
......@@ -107,6 +108,7 @@ void init_launcher_panel(void *p)
launcher->area.on_screen = TRUE;
panel_refresh = TRUE;
init_area_gradients(&launcher->area);
launcher_load_themes(launcher);
launcher_load_icons(launcher);
......@@ -422,16 +424,20 @@ void launcher_load_icons(Launcher *launcher)
{
// Load apps (.desktop style launcher items)
GSList *app = launcher->list_apps;
int index = 0;
while (app != NULL) {
LauncherIcon *launcherIcon = calloc(1, sizeof(LauncherIcon));
index++;
LauncherIcon *launcherIcon = (LauncherIcon *)calloc(1, sizeof(LauncherIcon));
launcherIcon->area.panel = launcher->area.panel;
launcherIcon->area._draw_foreground = draw_launcher_icon;
launcherIcon->area.size_mode = LAYOUT_FIXED;
launcherIcon->area._resize = NULL;
sprintf(launcherIcon->area.name, "LauncherIcon %d", index);
launcherIcon->area.resize_needed = 0;
launcherIcon->area.has_mouse_over_effect = panel_config.mouse_effects;
launcherIcon->area.has_mouse_press_effect = launcherIcon->area.has_mouse_over_effect;
launcherIcon->area.bg = launcher_icon_bg;
launcherIcon->area.gradients = launcher_icon_gradients;
launcherIcon->area.on_screen = TRUE;
launcherIcon->area._on_change_layout = launcher_icon_on_change_layout;
launcherIcon->area._dump_geometry = launcher_icon_dump_geometry;
......@@ -444,6 +450,7 @@ void launcher_load_icons(Launcher *launcher)
add_area(&launcherIcon->area, (Area *)launcher);
launcher->list_icons = g_slist_append(launcher->list_icons, launcherIcon);
launcher_reload_icon(launcher, launcherIcon);
init_area_gradients(&launcherIcon->area);
app = g_slist_next(app);
}
}
......
......@@ -46,7 +46,7 @@ extern char *icon_theme_name_config;
extern int launcher_icon_theme_override;
extern int startup_notifications;
extern Background *launcher_icon_bg;
extern GradientClass *launcher_icon_gradient;
extern GList *launcher_icon_gradients;
// default global data
void default_launcher();
......
......@@ -56,6 +56,7 @@ gboolean panel_refresh;
gboolean task_dragged;
char *panel_window_name = NULL;
gboolean debug_geometry;
gboolean debug_gradients;
gboolean panel_autohide;
int panel_autohide_show_timeout;
......@@ -115,6 +116,9 @@ void default_panel()
Background transparent_bg;
init_background(&transparent_bg);
g_array_append_val(backgrounds, transparent_bg);
GradientClass transparent_gradient;
init_gradient(&transparent_gradient, GRADIENT_VERTICAL);
g_array_append_val(gradients, transparent_gradient);
}
void cleanup_panel()
......@@ -215,6 +219,7 @@ void init_panel()
p->area._clear = panel_clear_background;
p->separator_list = NULL;
init_panel_size_and_position(p);
init_area_gradients(&p->area);
// add children according to panel_items
for (int k = 0; k < strlen(panel_items_order); k++) {
if (panel_items_order[k] == 'L')
......
......@@ -84,6 +84,7 @@ void init_separator_panel(void *p)
separator->area.on_screen = TRUE;
separator->area._resize = resize_separator;
separator->area._draw_foreground = draw_separator;
init_area_gradients(&separator->area);
}
}
......
......@@ -123,6 +123,7 @@ void init_systray_panel(void *p)
show(&systray.area);
schedule_redraw(&systray.area);
refresh_systray = TRUE;
init_area_gradients(&systray.area);
}
gboolean resize_systray(void *obj)
......@@ -1500,9 +1501,9 @@ void refresh_systray_icons()
}
}
gboolean systray_on_monitor(int i_monitor, int num_panels)
gboolean systray_on_monitor(int i_monitor, int n_panels)
{
return (i_monitor == systray_monitor) || (i_monitor == 0 && (systray_monitor >= num_panels || systray_monitor < 0));
return (i_monitor == systray_monitor) || (i_monitor == 0 && (systray_monitor >= n_panels || systray_monitor < 0));
}
TrayWindow *systray_find_icon(Window win)
......
......@@ -595,6 +595,9 @@ void set_task_state(Task *task, TaskState state)
Task *task1 = g_ptr_array_index(task_buttons, i);
task1->current_state = state;
task1->area.bg = panels[0].g_task.background[state];
free_area_gradients(&task1->area);
task1->area.gradients = panels[0].g_task.gradient[state];
init_area_gradients(&task1->area);
schedule_redraw(&task1->area);
if (state == TASK_ACTIVE && g_slist_find(urgent_list, task1))
del_urgent(task1);
......
......@@ -304,10 +304,18 @@ void init_taskbar_panel(void *p)
taskbar = &panel->taskbar[j];
memcpy(&taskbar->area, &panel->g_taskbar.area, sizeof(Area));
taskbar->desktop = j;
if (j == server.desktop)
if (j == server.desktop) {
taskbar->area.bg = panel->g_taskbar.background[TASKBAR_ACTIVE];
else
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panel->g_taskbar.gradient[TASKBAR_ACTIVE];
init_area_gradients(&taskbar->area);
} else {
taskbar->area.bg = panel->g_taskbar.background[TASKBAR_NORMAL];
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panel->g_taskbar.gradient[TASKBAR_NORMAL];
init_area_gradients(&taskbar->area);
}
}
init_taskbarname_panel(panel);
}
......@@ -478,8 +486,15 @@ void update_all_taskbars_visibility()
void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
{
taskbar->area.bg = panels[0].g_taskbar.background[state];
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panels[0].g_taskbar.gradient[state];
init_area_gradients(&taskbar->area);
if (taskbarname_enabled) {
taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state];
free_area_gradients(&taskbar->bar_name.area);
taskbar->bar_name.area.gradients = panels[0].g_taskbar.gradient_name[state];
init_area_gradients(&taskbar->bar_name.area);
}
update_taskbar_visibility(taskbar);
......
......@@ -60,10 +60,13 @@ void init_taskbarname_panel(void *p)
taskbar->bar_name.area.parent = taskbar;
taskbar->bar_name.area.has_mouse_over_effect = panel_config.mouse_effects;
taskbar->bar_name.area.has_mouse_press_effect = panel_config.mouse_effects;
if (j == server.desktop)
if (j == server.desktop) {
taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_ACTIVE];
else
taskbar->bar_name.area.gradients = panel->g_taskbar.gradient_name[TASKBAR_ACTIVE];
} else {
taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_NORMAL];
taskbar->bar_name.area.gradients = panel->g_taskbar.gradient_name[TASKBAR_NORMAL];
}
// use desktop number if name is missing
if (l) {
......@@ -75,6 +78,7 @@ void init_taskbarname_panel(void *p)
// append the name at the beginning of taskbar
taskbar->area.children = g_list_append(taskbar->area.children, &taskbar->bar_name);
init_area_gradients(&taskbar->bar_name.area);
}
for (l = list; l; l = l->next)
......
......@@ -375,6 +375,7 @@ void init(int argc, char *argv[])
#endif
debug_geometry = getenv("DEBUG_GEOMETRY") != NULL;
debug_gradients = getenv("DEBUG_GRADIENTS") != NULL;
}
static int sigchild_pipe_valid = FALSE;
......
......@@ -21,6 +21,7 @@
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -481,21 +482,19 @@ void draw_background(Area *a, cairo_t *c)
a->bg->border.radius - a->bg->border.width / 1.571);
cairo_fill(c);
/*
cairo_pattern_t *cairo_gradient_pattern;
if (area_has_gradient_fill(a)) {
cairo_gradient_pattern = cairo_pattern_create_linear(0.0, 0.0, 0.0, a->height - top_bottom_border_width(a));
cairo_pattern_add_color_stop_rgba(cairo_gradient_pattern, 0.1, a->bg->fill_color.rgb[0],
a->bg->fill_color.rgb[1], a->bg->fill_color.rgb[2], a->bg->fill_color.alpha);
cairo_pattern_add_color_stop_rgba(cairo_gradient_pattern, 0.9, a->bg->fill_color2.rgb[0],
a->bg->fill_color2.rgb[1], a->bg->fill_color2.rgb[2], a->bg->fill_color2.alpha);
cairo_set_source(c, cairo_gradient_pattern);
} else
if (area_has_gradient_fill(a))
cairo_pattern_destroy(cairo_gradient_pattern);
*/
}
for (GList *l = a->gradient_instances; l; l = l->next) {
GradientInstance *gi = (GradientInstance *)l->data;
if (!gi->pattern)
update_gradient(gi);
cairo_set_source(c, gi->pattern);
draw_rect(c,
left_border_width(a),
top_border_width(a),
a->width - left_right_border_width(a),
a->height - top_bottom_border_width(a),
a->bg->border.radius - a->bg->border.width / 1.571);
cairo_fill(c);
}
if (a->bg->border.width > 0) {
......@@ -537,6 +536,8 @@ void remove_area(Area *a)
Area *area = (Area *)a;
Area *parent = (Area *)area->parent;
free_area_gradients(a);
if (parent) {
parent->children = g_list_remove(parent->children, area);
parent->resize_needed = TRUE;
......@@ -560,7 +561,6 @@ void add_area(Area *a, Area *parent)
schedule_redraw(parent);
panel_refresh = TRUE;
}
init_area_gradients(a);
}
void free_area(Area *a)
......@@ -846,86 +846,80 @@ void area_dump_geometry(Area *area, int indent)
}
}
void instantiate_gradient_offsets(Area *area, GradientInstance *gi, GList *offsets, GList **offset_instances)
Area *compute_element_area(Area *area, Element element)
{
if (element == ELEMENT_SELF)
return area;
if (element == ELEMENT_PARENT)
return (Area *)area->parent;
if (element == ELEMENT_PANEL)
return (Area *)area->panel;
g_assert_not_reached();
return area;
}
void instantiate_gradient_offsets(GradientInstance *gi, GList *offsets)
{
for (GList *l = offsets; l; l = l->next) {
Offset *offset = (Offset *)l->data;
OffsetInstance *offset_instance = (OffsetInstance *)calloc(1, sizeof(OffsetInstance));
offset_instance->constant = offset->constant;
if (offset_instance->constant) {
offset_instance->constant_value = offset->constant_value;
} else {
offset_instance->variable = offset->variable;
offset_instance->multiplier = offset->multiplier;
if (offset->variable_element == ORIGIN_ELEMENT)
offset_instance->variable_element = area;
else if (offset->variable_element == ORIGIN_PARENT)
offset_instance->variable_element = area->parent ? (Area *)area->parent : area;
else if (offset->variable_element == ORIGIN_PANEL)
offset_instance->variable_element = (Area *)area->panel;
else if (offset->variable_element == ORIGIN_SCREEN)
// TODO
offset_instance->variable_element = (Area *)area->panel;
else if (offset->variable_element == ORIGIN_DESKTOP)
// TODO
offset_instance->variable_element = (Area *)area->panel;
else
g_assert_not_reached();
*offset_instances = g_list_append(*offset_instances, offset_instance);
offset_instance->variable_element->dependent_gradients =
g_list_append(offset_instance->variable_element->dependent_gradients, gi);
gi->gradient_dependencies = g_list_append(gi->gradient_dependencies, offset_instance->variable_element);
if (!offset->constant) {
Area *element_area = compute_element_area(gi->area, offset->element);
element_area->dependent_gradients = g_list_append(element_area->dependent_gradients, gi);
}
}
}
void free_gradient_offsets(GradientInstance *gi, GList **offset_instances)
void free_gradient_offsets(GradientInstance *gi, GList **offsets)
{
for (GList *l = *offset_instances; l; l = l->next) {
OffsetInstance *offset_instance = (OffsetInstance *)l->data;
if (!offset_instance->constant) {
offset_instance->variable_element->dependent_gradients =
g_list_remove_all(offset_instance->variable_element->dependent_gradients, gi);
gi->gradient_dependencies = g_list_remove_all(gi->gradient_dependencies, offset_instance->variable_element);
for (GList *l = *offsets; l; l = l->next) {
Offset *offset = (Offset *)l->data;
if (!offset->constant) {
Area *element_area = compute_element_area(gi->area, offset->element);
element_area->dependent_gradients = g_list_remove_all(element_area->dependent_gradients, gi);
}
}
g_list_free_full(*offset_instances, free);
}
void instantiate_gradient_point(Area *area,
GradientInstance *gi,
ControlPoint *control,
ControlPointInstance *control_instance)
void instantiate_gradient_point(GradientInstance *gi, ControlPoint *control)
{
instantiate_gradient_offsets(area, gi, control->offsets_x, &control_instance->offsets_x);
instantiate_gradient_offsets(area, gi, control->offsets_y, &control_instance->offsets_y);
instantiate_gradient_offsets(area, gi, control->offsets_r, &control_instance->offsets_r);
instantiate_gradient_offsets(gi, control->offsets_x);
instantiate_gradient_offsets(gi, control->offsets_y);
instantiate_gradient_offsets(gi, control->offsets_r);
}
void free_gradient_point(GradientInstance *gi, ControlPointInstance *control_instance)
void free_gradient_point(GradientInstance *gi, ControlPoint *control)
{
free_gradient_offsets(gi, &control_instance->offsets_x);
free_gradient_offsets(gi, &control_instance->offsets_y);
free_gradient_offsets(gi, &control_instance->offsets_r);
free_gradient_offsets(gi, &control->offsets_x);
free_gradient_offsets(gi, &control->offsets_y);
free_gradient_offsets(gi, &control->offsets_r);
}
void instantiate_gradient(Area *area, GradientClass *g, GradientInstance *gi)
{
gi->gradient_class = g;
g_assert_nonnull(area);
g_assert_nonnull(g);
gi->area = area;
gi->from.origin = area;
instantiate_gradient_point(area, gi, &g->from, &gi->from);
instantiate_gradient_point(area, gi, &g->to, &gi->to);
gi->gradient_class = g;
instantiate_gradient_point(gi, &g->from);
instantiate_gradient_point(gi, &g->to);
}
void free_gradient(GradientInstance *gi)
{
free_gradient_point(gi, &gi->from);
free_gradient_point(gi, &gi->to);
if (gi->pattern) {
cairo_pattern_destroy(gi->pattern);
gi->pattern = NULL;
}
free_gradient_point(gi, &gi->gradient_class->from);
free_gradient_point(gi, &gi->gradient_class->to);
gi->gradient_class = NULL;
}
void init_area_gradients(Area *area)
{
g_assert_null(area->gradient_instances);
if (debug_gradients)
fprintf(stderr, "Initializing gradients for area %s\n", area->name);
for (GList *l = area->gradients; l; l = l->next) {
GradientClass *g = (GradientClass *)l->data;
GradientInstance *gi = (GradientInstance *)calloc(1, sizeof(GradientInstance));
......@@ -936,14 +930,170 @@ void init_area_gradients(Area *area)
void free_area_gradients(Area *area)
{
if (debug_gradients)
fprintf(stderr, "Freeing gradients for area %s\n", area->name);
for (GList *l = area->gradient_instances; l; l = l->next) {
GradientInstance *gi = (GradientInstance *)l->data;
free_gradient(gi);
}
g_list_free_full(area->gradient_instances, free);
area->gradient_instances = NULL;
g_assert_null(area->dependent_gradients);
}
double compute_control_point_offset(Area *area, Offset *offset)
{
if (offset->constant)
return offset->constant_value;
Area *element_area = compute_element_area(area, offset->element);
Area *parent_area = ((Area *)area->parent);
g_assert_nonnull(element_area);
g_assert_nonnull(parent_area);
double width = element_area->width;
double height = element_area->height;
double radius = sqrt(element_area->width * element_area->width + element_area->height * element_area->height) / 2.0;
double left, top;
if (offset->element == ELEMENT_SELF) {
left = 0;
top = 0;
} else if (offset->element == ELEMENT_PARENT) {
left = parent_area->posx - area->posx;
top = parent_area->posy - area->posy;
} else if (offset->element == ELEMENT_PANEL) {
left = 0 - area->posx;
top = 0 - area->posy;
}
double right = left + width;
double bottom = top + height;
double center_x = left + 0.5 * width;
double center_y = top + 0.5 * height;
if (offset->variable == SIZE_WIDTH)
return width * offset->multiplier;
if (offset->variable == SIZE_HEIGHT)
return height * offset->multiplier;
if (offset->variable == SIZE_RADIUS)
return radius * offset->multiplier;
if (offset->variable == SIZE_LEFT)
return left * offset->multiplier;
if (offset->variable == SIZE_RIGHT)
return right * offset->multiplier;
if (offset->variable == SIZE_TOP)
return top * offset->multiplier;
if (offset->variable == SIZE_BOTTOM)
return bottom * offset->multiplier;
if (offset->variable == SIZE_CENTERX)
return center_x * offset->multiplier;
if (offset->variable == SIZE_CENTERY)
return center_y * offset->multiplier;
g_assert_not_reached();
return 0;
}
double compute_control_point_offsets(GradientInstance *gi, GList *offsets)
{
double result = 0;
for (GList *l = offsets; l; l = l->next) {
Offset *offset = (Offset *)l->data;
result += compute_control_point_offset(gi->area, offset);
}
return result;
}
void compute_control_point(GradientInstance *gi, ControlPoint *control, double *x, double *y, double *r)
{
*x = compute_control_point_offsets(gi, control->offsets_x);
*y = compute_control_point_offsets(gi, control->offsets_y);
*r = compute_control_point_offsets(gi, control->offsets_r);
}
void update_gradient(GradientInstance *gi)
{
// TODO
if (gi->pattern) {
return;
cairo_pattern_destroy(gi->pattern);
gi->pattern = NULL;
}
schedule_redraw(gi->area);
double from_x, from_y, from_r;
compute_control_point(gi, &gi->gradient_class->from, &from_x, &from_y, &from_r);
double to_x, to_y, to_r;
compute_control_point(gi, &gi->gradient_class->to, &to_x, &to_y, &to_r);
if (gi->gradient_class->type == GRADIENT_VERTICAL || gi->gradient_class->type == GRADIENT_HORIZONTAL ||
gi->gradient_class->type == GRADIENT_LINEAR) {
gi->pattern = cairo_pattern_create_linear(from_x, from_y, to_x, to_y);
if (debug_gradients)
fprintf(stderr,
"Creating linear gradient for area %s: %f %f, %f %f\n",
gi->area->name,
from_x,
from_y,
to_x,
to_y);
} else if (gi->gradient_class->type == GRADIENT_CENTERED || gi->gradient_class->type == GRADIENT_RADIAL) {
gi->pattern = cairo_pattern_create_radial(from_x, from_y, from_r, to_x, to_y, to_r);
if (debug_gradients)
fprintf(stderr,
"Creating radial gradient for area %s: %f %f %f, %f %f %f\n",
gi->area->name,
from_x,
from_y,
from_r,
to_x,
to_y,
to_r);
} else {
g_assert_not_reached();
}
if (debug_gradients)
fprintf(stderr,
"Adding color stop at offset %f: %f %f %f %f\n",
0.0,
gi->gradient_class->start_color.rgb[0],
gi->gradient_class->start_color.rgb[1],
gi->gradient_class->start_color.rgb[2],
gi->gradient_class->start_color.alpha);
cairo_pattern_add_color_stop_rgba(gi->pattern,
0,
gi->gradient_class->start_color.rgb[0],
gi->gradient_class->start_color.rgb[1],
gi->gradient_class->start_color.rgb[2],
gi->gradient_class->start_color.alpha);
for (GList *l = gi->gradient_class->extra_color_stops; l; l = l->next) {
ColorStop *color_stop = (ColorStop *)l->data;
if (debug_gradients)
fprintf(stderr,
"Adding color stop at offset %f: %f %f %f %f\n",
color_stop->offset,
color_stop->color.rgb[0],
color_stop->color.rgb[1],
color_stop->color.rgb[2],
color_stop->color.alpha);
cairo_pattern_add_color_stop_rgba(gi->pattern,
color_stop->offset,
color_stop->color.rgb[0],
color_stop->color.rgb[1],
color_stop->color.rgb[2],
color_stop->color.alpha);
}
if (debug_gradients)
fprintf(stderr,
"Adding color stop at offset %f: %f %f %f %f\n",
1.0,
gi->gradient_class->end_color.rgb[0],
gi->gradient_class->end_color.rgb[1],
gi->gradient_class->end_color.rgb[2],
gi->gradient_class->end_color.alpha);
cairo_pattern_add_color_stop_rgba(gi->pattern,
1.0,
gi->gradient_class->end_color.rgb[0],
gi->gradient_class->end_color.rgb[1],
gi->gradient_class->end_color.rgb[2],
gi->gradient_class->end_color.alpha);
schedule_redraw(gi->area);
}