mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 05:44:16 +00:00
add new color subdomains
i.e. it is now possible to set (and animate) specific color channels: color.alpha=<float> color.red=<float> color.green=<float> color.blue=<float> The current way of setting colors with full argb-hex strings is of course still possible
This commit is contained in:
parent
bdc19bd994
commit
781ee63a8d
18 changed files with 237 additions and 159 deletions
|
@ -78,7 +78,7 @@ void alias_init(struct alias* alias) {
|
|||
alias->name = NULL;
|
||||
alias->owner = NULL;
|
||||
alias->color_override = false;
|
||||
alias->color = rgba_color_from_hex(0xffff0000);
|
||||
color_init(&alias->color, 0xffff0000);
|
||||
alias->update_frequency = 1;
|
||||
alias->counter = 0;
|
||||
|
||||
|
@ -251,7 +251,7 @@ bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token propert
|
|||
}
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR)) {
|
||||
alias->color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||
color_set_hex(&alias->color, token_to_uint32t(get_token(&message)));
|
||||
alias->color_override = true;
|
||||
return true;
|
||||
} else if (token_equals(property, PROPERTY_SCALE)) {
|
||||
|
|
|
@ -19,7 +19,7 @@ struct alias {
|
|||
struct window window;
|
||||
|
||||
bool color_override;
|
||||
struct rgba_color color;
|
||||
struct color color;
|
||||
struct image image;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ void background_init(struct background* background) {
|
|||
background->corner_radius = 0;
|
||||
background->y_offset = 0;
|
||||
|
||||
background->color = rgba_color_from_hex(0x00000000);
|
||||
background->border_color = rgba_color_from_hex(0x00000000);
|
||||
color_init(&background->color, 0x00000000);
|
||||
color_init(&background->border_color, 0x00000000);
|
||||
shadow_init(&background->shadow);
|
||||
image_init(&background->image);
|
||||
}
|
||||
|
@ -56,14 +56,8 @@ bool background_set_enabled(struct background* background, bool enabled) {
|
|||
}
|
||||
|
||||
bool background_set_color(struct background* background, uint32_t color) {
|
||||
struct rgba_color target_color = rgba_color_from_hex(color);
|
||||
if (background->color.r == target_color.r
|
||||
&& background->color.g == target_color.g
|
||||
&& background->color.b == target_color.b
|
||||
&& background->color.a == target_color.a) return false;
|
||||
background->color = target_color;
|
||||
background_set_enabled(background, true);
|
||||
return true;
|
||||
bool changed = background_set_enabled(background, true);
|
||||
return color_set_hex(&background->color, color) || changed;
|
||||
}
|
||||
|
||||
static bool background_set_clip(struct background* background, float clip) {
|
||||
|
@ -76,13 +70,7 @@ static bool background_set_clip(struct background* background, float clip) {
|
|||
}
|
||||
|
||||
static bool background_set_border_color(struct background* background, uint32_t color) {
|
||||
struct rgba_color target_color = rgba_color_from_hex(color);
|
||||
if (background->border_color.r == target_color.r
|
||||
&& background->border_color.g == target_color.g
|
||||
&& background->border_color.b == target_color.b
|
||||
&& background->border_color.a == target_color.a) return false;
|
||||
background->border_color = target_color;
|
||||
return true;
|
||||
return color_set_hex(&background->border_color, color);
|
||||
}
|
||||
|
||||
static bool background_set_border_width(struct background* background, uint32_t border_width) {
|
||||
|
@ -182,6 +170,21 @@ void background_calculate_bounds(struct background* background, uint32_t x, uint
|
|||
image_calculate_bounds(&background->image, x, y);
|
||||
}
|
||||
|
||||
static void draw_rect(CGContextRef context, CGRect region, struct color* fill_color, uint32_t corner_radius, uint32_t line_width, struct color* stroke_color) {
|
||||
CGContextSetLineWidth(context, line_width);
|
||||
if (stroke_color) CGContextSetRGBStrokeColor(context, stroke_color->r, stroke_color->g, stroke_color->b, stroke_color->a);
|
||||
CGContextSetRGBFillColor(context, fill_color->r, fill_color->g, fill_color->b, fill_color->a);
|
||||
|
||||
CGMutablePathRef path = CGPathCreateMutable();
|
||||
CGRect inset_region = CGRectInset(region, (float)(line_width) / 2.f, (float)(line_width) / 2.f);
|
||||
if (corner_radius > inset_region.size.height / 2.f || corner_radius > inset_region.size.width / 2.f)
|
||||
corner_radius = inset_region.size.height > inset_region.size.width ? inset_region.size.width / 2.f : inset_region.size.height / 2.f;
|
||||
CGPathAddRoundedRect(path, NULL, inset_region, corner_radius, corner_radius);
|
||||
CGContextAddPath(context, path);
|
||||
CGContextDrawPath(context, kCGPathFillStroke);
|
||||
CFRelease(path);
|
||||
}
|
||||
|
||||
void background_draw(struct background* background, CGContextRef context) {
|
||||
if (!background->enabled) return;
|
||||
CGRect background_bounds = background->bounds;
|
||||
|
@ -193,8 +196,7 @@ void background_draw(struct background* background, CGContextRef context) {
|
|||
&background->shadow.color,
|
||||
background->corner_radius,
|
||||
background->border_width,
|
||||
&background->shadow.color,
|
||||
false );
|
||||
&background->shadow.color);
|
||||
}
|
||||
|
||||
if (background->image.enabled)
|
||||
|
@ -205,8 +207,7 @@ void background_draw(struct background* background, CGContextRef context) {
|
|||
&background->color,
|
||||
background->corner_radius,
|
||||
background->border_width,
|
||||
&background->border_color,
|
||||
false );
|
||||
&background->border_color);
|
||||
}
|
||||
|
||||
void background_clear_pointers(struct background* background) {
|
||||
|
@ -237,8 +238,8 @@ void background_serialize(struct background* background, char* indent, FILE* rsp
|
|||
"%s\"y_offset\": %d,\n"
|
||||
"%s\"clip\": %f,\n",
|
||||
indent, format_bool(background->enabled),
|
||||
indent, hex_from_rgba_color(background->color),
|
||||
indent, hex_from_rgba_color(background->border_color),
|
||||
indent, background->color.hex,
|
||||
indent, background->border_color.hex,
|
||||
indent, background->border_width,
|
||||
indent, background->overrides_height ? (int)background->bounds.size.height : 0,
|
||||
indent, background->corner_radius,
|
||||
|
@ -298,15 +299,15 @@ bool background_parse_sub_domain(struct background* background, FILE* rsp, struc
|
|||
struct token token = get_token(&message);
|
||||
ANIMATE_BYTES(background_set_color,
|
||||
background,
|
||||
hex_from_rgba_color(background->color),
|
||||
token_to_int(token) );
|
||||
background->color.hex,
|
||||
token_to_int(token) );
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_BORDER_COLOR)) {
|
||||
struct token token = get_token(&message);
|
||||
ANIMATE_BYTES(background_set_border_color,
|
||||
background,
|
||||
hex_from_rgba_color(background->border_color),
|
||||
token_to_int(token) );
|
||||
background->border_color.hex,
|
||||
token_to_int(token) );
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_PADDING_LEFT)) {
|
||||
struct token token = get_token(&message);
|
||||
|
@ -345,8 +346,18 @@ bool background_parse_sub_domain(struct background* background, FILE* rsp, struc
|
|||
rsp,
|
||||
entry,
|
||||
message );
|
||||
else if (token_equals(subdom, SUB_DOMAIN_IMAGE))
|
||||
else if (token_equals(subdom, SUB_DOMAIN_IMAGE)) {
|
||||
return image_parse_sub_domain(&background->image, rsp, entry, message);
|
||||
}
|
||||
else if (token_equals(subdom, SUB_DOMAIN_COLOR)) {
|
||||
return color_parse_sub_domain(&background->color, rsp, entry, message);
|
||||
}
|
||||
else if (token_equals(subdom, SUB_DOMAIN_BORDER_COLOR)) {
|
||||
return color_parse_sub_domain(&background->border_color,
|
||||
rsp,
|
||||
entry,
|
||||
message );
|
||||
}
|
||||
else {
|
||||
respond(rsp, "[!] Background: Invalid subdomain '%s'\n", subdom.text);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ struct background {
|
|||
CGRect bounds;
|
||||
struct image image;
|
||||
struct shadow shadow;
|
||||
struct rgba_color color;
|
||||
struct rgba_color border_color;
|
||||
struct color color;
|
||||
struct color border_color;
|
||||
|
||||
struct background** clips;
|
||||
uint32_t num_clips;
|
||||
|
|
18
src/bar.c
18
src/bar.c
|
@ -145,17 +145,13 @@ void bar_draw(struct bar* bar, bool forced) {
|
|||
bar_check_for_clip_updates(bar);
|
||||
|
||||
if (g_bar_manager.bar_needs_update) {
|
||||
draw_rect(bar->window.context,
|
||||
bar->window.frame,
|
||||
&g_bar_manager.background.color,
|
||||
g_bar_manager.background.corner_radius,
|
||||
g_bar_manager.background.border_width,
|
||||
&g_bar_manager.background.border_color,
|
||||
true );
|
||||
|
||||
if (g_bar_manager.background.image.enabled) {
|
||||
image_draw(&g_bar_manager.background.image, bar->window.context);
|
||||
}
|
||||
struct background* background = &g_bar_manager.background;
|
||||
background->bounds = bar->window.frame;
|
||||
background->bounds.origin.y -= background->y_offset;
|
||||
background->shadow.enabled = false;
|
||||
background->enabled = true;
|
||||
CGContextClearRect(bar->window.context, bar->window.frame);
|
||||
background_draw(background, bar->window.context);
|
||||
}
|
||||
|
||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||
|
|
|
@ -44,8 +44,9 @@ void bar_manager_init(struct bar_manager* bar_manager) {
|
|||
bar_manager->background.overrides_height = true;
|
||||
bar_manager->background.padding_left = 20;
|
||||
bar_manager->background.padding_right = 20;
|
||||
bar_manager->background.border_color = rgba_color_from_hex(0xffff0000);
|
||||
bar_manager->background.color = rgba_color_from_hex(0x44000000);
|
||||
|
||||
color_set_hex(&bar_manager->background.border_color, 0xffff0000);
|
||||
color_set_hex(&bar_manager->background.color, 0x44000000);
|
||||
|
||||
bar_item_init(&bar_manager->default_item, NULL);
|
||||
bar_item_set_name(&bar_manager->default_item, string_copy("defaults"));
|
||||
|
|
82
src/color.c
Normal file
82
src/color.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "color.h"
|
||||
#include "bar_manager.h"
|
||||
#include "animation.h"
|
||||
|
||||
static bool color_update_hex(struct color* color) {
|
||||
uint32_t prev = color->hex;
|
||||
color->hex = (((uint32_t)(color->a * 255.f)) << 24)
|
||||
+ (((uint32_t)(color->r * 255.f)) << 16)
|
||||
+ (((uint32_t)(color->g * 255.f)) << 8)
|
||||
+ (((uint32_t)(color->b * 255.f)) << 0);
|
||||
|
||||
return prev != color->hex;
|
||||
}
|
||||
|
||||
void color_init(struct color* color, uint32_t hex) {
|
||||
color_set_hex(color, hex);
|
||||
}
|
||||
|
||||
bool color_set_hex(struct color* color, uint32_t hex) {
|
||||
color->a = clamp(((hex >> 24) & 0xff) / 255.f, 0.f, 1.f);
|
||||
color->r = clamp(((hex >> 16) & 0xff) / 255.f, 0.f, 1.f);
|
||||
color->g = clamp(((hex >> 8) & 0xff) / 255.f, 0.f, 1.f);
|
||||
color->b = clamp(((hex >> 0) & 0xff) / 255.f, 0.f, 1.f);
|
||||
return color_update_hex(color);
|
||||
}
|
||||
|
||||
bool color_set_alpha(struct color* color, float alpha) {
|
||||
color->a = clamp(alpha, 0.f, 1.f);
|
||||
return color_update_hex(color);
|
||||
}
|
||||
|
||||
bool color_set_r(struct color* color, float red) {
|
||||
color->r = clamp(red, 0.f, 1.f);
|
||||
return color_update_hex(color);
|
||||
}
|
||||
|
||||
bool color_set_g(struct color* color, float green) {
|
||||
color->g = clamp(green, 0.f, 1.f);
|
||||
return color_update_hex(color);
|
||||
}
|
||||
|
||||
bool color_set_b(struct color* color, float blue) {
|
||||
color->b = clamp(blue, 0.f, 1.f);
|
||||
return color_update_hex(color);
|
||||
}
|
||||
|
||||
bool color_parse_sub_domain(struct color* color, FILE* rsp, struct token property, char* message) {
|
||||
bool needs_refresh = false;
|
||||
|
||||
if (token_equals(property, PROPERTY_COLOR_HEX)) {
|
||||
ANIMATE_BYTES(color_set_hex,
|
||||
color,
|
||||
color->hex,
|
||||
token_to_int(get_token(&message)));
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR_ALPHA)) {
|
||||
ANIMATE_FLOAT(color_set_alpha,
|
||||
color,
|
||||
color->a,
|
||||
token_to_float(get_token(&message)));
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR_RED)) {
|
||||
ANIMATE_FLOAT(color_set_r,
|
||||
color,
|
||||
color->r,
|
||||
token_to_float(get_token(&message)));
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR_GREEN)) {
|
||||
ANIMATE_FLOAT(color_set_g,
|
||||
color,
|
||||
color->g,
|
||||
token_to_float(get_token(&message)));
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_COLOR_BLUE)) {
|
||||
ANIMATE_FLOAT(color_set_b,
|
||||
color,
|
||||
color->b,
|
||||
token_to_float(get_token(&message)));
|
||||
}
|
||||
|
||||
return needs_refresh;
|
||||
}
|
23
src/color.h
Normal file
23
src/color.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "misc/helpers.h"
|
||||
|
||||
struct color {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
uint32_t hex;
|
||||
};
|
||||
|
||||
static struct color g_transparent = { 0 };
|
||||
|
||||
void color_init(struct color* color, uint32_t hex);
|
||||
bool color_set_hex(struct color* color, uint32_t hex);
|
||||
bool color_set_alpha(struct color* color, float alpha);
|
||||
bool color_set_r(struct color* color, float red);
|
||||
bool color_set_g(struct color* color, float green);
|
||||
bool color_set_b(struct color* color, float blue);
|
||||
|
||||
bool color_parse_sub_domain(struct color* color, FILE* rsp, struct token property, char* message);
|
17
src/graph.c
17
src/graph.c
|
@ -4,12 +4,13 @@ void graph_init(struct graph* graph) {
|
|||
graph->width = 0;
|
||||
graph->cursor = 0;
|
||||
|
||||
graph->line_color = rgba_color_from_hex(0xcccccc);
|
||||
graph->fill_color = rgba_color_from_hex(0xcccccc);
|
||||
graph->line_width = 0.5;
|
||||
graph->fill = true;
|
||||
graph->overrides_fill_color = false;
|
||||
graph->enabled = true;
|
||||
|
||||
color_init(&graph->line_color, 0xcccccc);
|
||||
color_init(&graph->fill_color, 0xcccccc);
|
||||
}
|
||||
|
||||
void graph_setup(struct graph* graph, uint32_t width) {
|
||||
|
@ -112,8 +113,8 @@ void graph_serialize(struct graph* graph, char* indent, FILE* rsp) {
|
|||
"%s\"fill_color\": \"0x%x\",\n"
|
||||
"%s\"line_width\": \"%f\",\n"
|
||||
"%s\"data\": [\n",
|
||||
indent, hex_from_rgba_color(graph->line_color),
|
||||
indent, hex_from_rgba_color(graph->fill_color),
|
||||
indent, graph->line_color.hex,
|
||||
indent, graph->fill_color.hex,
|
||||
indent, graph->line_width, indent);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < graph->width; i++) {
|
||||
|
@ -131,12 +132,12 @@ void graph_destroy(struct graph* graph) {
|
|||
|
||||
bool graph_parse_sub_domain(struct graph* graph, FILE* rsp, struct token property, char* message) {
|
||||
if (token_equals(property, PROPERTY_COLOR)) {
|
||||
graph->line_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||
return true;
|
||||
return color_set_hex(&graph->line_color,
|
||||
token_to_uint32t(get_token(&message)));
|
||||
} else if (token_equals(property, PROPERTY_FILL_COLOR)) {
|
||||
graph->fill_color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
|
||||
graph->overrides_fill_color = true;
|
||||
return true;
|
||||
return color_set_hex(&graph->fill_color,
|
||||
token_to_uint32t(get_token(&message)));
|
||||
} else if (token_equals(property, PROPERTY_LINE_WIDTH)) {
|
||||
graph->line_width = token_to_float(get_token(&message));
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "misc/helpers.h"
|
||||
#include "color.h"
|
||||
|
||||
struct graph {
|
||||
bool rtl;
|
||||
|
@ -13,8 +14,8 @@ struct graph {
|
|||
float line_width;
|
||||
|
||||
CGRect bounds;
|
||||
struct rgba_color line_color;
|
||||
struct rgba_color fill_color;
|
||||
struct color line_color;
|
||||
struct color fill_color;
|
||||
};
|
||||
|
||||
void graph_init(struct graph* graph);
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#define SUB_DOMAIN_KNOB "knob"
|
||||
#define SUB_DOMAIN_SLIDER "slider"
|
||||
#define SUB_DOMAIN_FONT "font"
|
||||
#define SUB_DOMAIN_COLOR "color"
|
||||
#define SUB_DOMAIN_BORDER_COLOR "border_color"
|
||||
#define SUB_DOMAIN_HIGHLIGHT_COLOR "highlight_color"
|
||||
|
||||
#define PROPERTY_FONT "font"
|
||||
#define PROPERTY_COLOR "color"
|
||||
|
@ -62,6 +65,12 @@
|
|||
#define PROPERTY_SCALE "scale"
|
||||
#define PROPERTY_STRING "string"
|
||||
|
||||
#define PROPERTY_COLOR_HEX "hex"
|
||||
#define PROPERTY_COLOR_ALPHA "alpha"
|
||||
#define PROPERTY_COLOR_RED "red"
|
||||
#define PROPERTY_COLOR_GREEN "green"
|
||||
#define PROPERTY_COLOR_BLUE "blue"
|
||||
|
||||
#define PROPERTY_FONT_FAMILY "family"
|
||||
#define PROPERTY_FONT_STYLE "style"
|
||||
#define PROPERTY_FONT_SIZE "size"
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#define array_count(a) (sizeof((a)) / sizeof(*(a)))
|
||||
#define max(a, b) (a > b ? a : b)
|
||||
#define min(a, b) (a < b ? a : b)
|
||||
#define clamp(x, l, u) (min(max(x, l), u))
|
||||
|
||||
#define MAXLEN 512
|
||||
#define FORK_TIMEOUT 60
|
||||
|
||||
|
@ -26,14 +28,6 @@ struct signal_args {
|
|||
void *param1;
|
||||
};
|
||||
|
||||
struct rgba_color {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
|
||||
static struct rgba_color g_transparent = { 0 };
|
||||
static CGPoint g_nirvana = {-9999, -9999};
|
||||
|
||||
static double deg_to_rad = 2.* M_PI / 360.;
|
||||
|
@ -135,24 +129,6 @@ static inline void respond(FILE* rsp, char* response, ...) {
|
|||
va_end(args_stdout);
|
||||
}
|
||||
|
||||
static inline uint32_t hex_from_rgba_color(struct rgba_color rgba_color) {
|
||||
uint32_t result = 0;
|
||||
result += ((uint32_t)(rgba_color.a * 255.0)) << 24;
|
||||
result += ((uint32_t)(rgba_color.r * 255.0)) << 16;
|
||||
result += ((uint32_t)(rgba_color.g * 255.0)) << 8;
|
||||
result += ((uint32_t)(rgba_color.b * 255.0)) << 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline struct rgba_color rgba_color_from_hex(uint32_t color) {
|
||||
struct rgba_color result;
|
||||
result.r = ((color >> 16) & 0xff) / 255.0;
|
||||
result.g = ((color >> 8) & 0xff) / 255.0;
|
||||
result.b = ((color >> 0) & 0xff) / 255.0;
|
||||
result.a = ((color >> 24) & 0xff) / 255.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline struct key_value_pair get_key_value_pair(char *token, char split) {
|
||||
struct key_value_pair key_value_pair;
|
||||
key_value_pair.key = token;
|
||||
|
@ -320,22 +296,6 @@ static inline uint32_t get_set_bit_position(uint32_t mask) {
|
|||
return pos;
|
||||
}
|
||||
|
||||
static inline void draw_rect(CGContextRef context, CGRect region, struct rgba_color* fill_color, uint32_t corner_radius, uint32_t line_width, struct rgba_color* stroke_color, bool clear) {
|
||||
CGContextSetLineWidth(context, line_width);
|
||||
if (stroke_color) CGContextSetRGBStrokeColor(context, stroke_color->r, stroke_color->g, stroke_color->b, stroke_color->a);
|
||||
CGContextSetRGBFillColor(context, fill_color->r, fill_color->g, fill_color->b, fill_color->a);
|
||||
|
||||
if (clear) CGContextClearRect(context, region);
|
||||
CGMutablePathRef path = CGPathCreateMutable();
|
||||
CGRect inset_region = CGRectInset(region, (float)(line_width) / 2.f, (float)(line_width) / 2.f);
|
||||
if (corner_radius > inset_region.size.height / 2.f || corner_radius > inset_region.size.width / 2.f)
|
||||
corner_radius = inset_region.size.height > inset_region.size.width ? inset_region.size.width / 2.f : inset_region.size.height / 2.f;
|
||||
CGPathAddRoundedRect(path, NULL, inset_region, corner_radius, corner_radius);
|
||||
CGContextAddPath(context, path);
|
||||
CGContextDrawPath(context, kCGPathFillStroke);
|
||||
CFRelease(path);
|
||||
}
|
||||
|
||||
static inline void clip_rect(CGContextRef context, CGRect region, float clip, uint32_t corner_radius) {
|
||||
CGMutablePathRef path = CGPathCreateMutable();
|
||||
if (corner_radius > region.size.height / 2.f || corner_radius > region.size.width / 2.f)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <Carbon/Carbon.h>
|
||||
#include "event_loop.h"
|
||||
#include "event.h"
|
||||
|
||||
static const EventTypeSpec mouse_events [] = {
|
||||
{ kEventClassMouse, kEventMouseDown },
|
||||
{ kEventClassMouse, kEventMouseUp },
|
||||
|
|
|
@ -23,8 +23,8 @@ void popup_init(struct popup* popup, struct bar_item* host) {
|
|||
popup->host = host;
|
||||
background_init(&popup->background);
|
||||
window_init(&popup->window);
|
||||
popup->background.border_color = rgba_color_from_hex(0xffff0000);
|
||||
popup->background.color = rgba_color_from_hex(0x44000000);
|
||||
color_set_hex(&popup->background.border_color, 0xffff0000);
|
||||
color_set_hex(&popup->background.color, 0x44000000);
|
||||
}
|
||||
|
||||
static CGRect popup_get_frame(struct popup* popup) {
|
||||
|
|
32
src/shadow.c
32
src/shadow.c
|
@ -9,7 +9,8 @@ void shadow_init(struct shadow* shadow) {
|
|||
*cos(((double)shadow->angle)*deg_to_rad);
|
||||
shadow->offset.y = -((float)shadow->distance)
|
||||
*sin(((double)shadow->angle)*deg_to_rad);
|
||||
shadow->color = rgba_color_from_hex(0xff000000);
|
||||
|
||||
color_init(&shadow->color, 0xff000000);
|
||||
}
|
||||
|
||||
static bool shadow_set_enabled(struct shadow* shadow, bool enabled) {
|
||||
|
@ -37,14 +38,8 @@ static bool shadow_set_distance(struct shadow* shadow, uint32_t distance) {
|
|||
}
|
||||
|
||||
static bool shadow_set_color(struct shadow* shadow, uint32_t color) {
|
||||
struct rgba_color target_color = rgba_color_from_hex(color);
|
||||
if (shadow->color.r == target_color.r
|
||||
&& shadow->color.g == target_color.g
|
||||
&& shadow->color.b == target_color.b
|
||||
&& shadow->color.a == target_color.a) return false;
|
||||
shadow->color = target_color;
|
||||
shadow_set_enabled(shadow, true);
|
||||
return true;
|
||||
bool changed = shadow_set_enabled(shadow, true);
|
||||
return color_set_hex(&shadow->color, color) || changed;
|
||||
}
|
||||
|
||||
CGRect shadow_get_bounds(struct shadow* shadow, CGRect reference_bounds) {
|
||||
|
@ -59,7 +54,7 @@ void shadow_serialize(struct shadow* shadow, char* indent, FILE* rsp) {
|
|||
"%s\"angle\": %u,\n"
|
||||
"%s\"distance\": %u",
|
||||
indent, format_bool(shadow->enabled),
|
||||
indent, hex_from_rgba_color(shadow->color),
|
||||
indent, shadow->color.hex,
|
||||
indent, shadow->angle,
|
||||
indent, shadow->distance );
|
||||
}
|
||||
|
@ -89,11 +84,24 @@ bool shadow_parse_sub_domain(struct shadow* shadow, FILE* rsp, struct token prop
|
|||
struct token token = get_token(&message);
|
||||
ANIMATE_BYTES(shadow_set_color,
|
||||
shadow,
|
||||
hex_from_rgba_color(shadow->color),
|
||||
shadow->color.hex,
|
||||
token_to_int(token) );
|
||||
}
|
||||
else {
|
||||
respond(rsp, "[!] Shadow: Invalid property '%s'\n", property.text);
|
||||
struct key_value_pair key_value_pair = get_key_value_pair(property.text,
|
||||
'.' );
|
||||
if (key_value_pair.key && key_value_pair.value) {
|
||||
struct token subdom = {key_value_pair.key,strlen(key_value_pair.key)};
|
||||
struct token entry = {key_value_pair.value,strlen(key_value_pair.value)};
|
||||
if (token_equals(subdom, SUB_DOMAIN_COLOR)) {
|
||||
return color_parse_sub_domain(&shadow->color, rsp, entry, message);
|
||||
}
|
||||
else {
|
||||
respond(rsp, "[!] Shadow: Invalid subdomain '%s'\n", subdom.text);
|
||||
}
|
||||
} else {
|
||||
respond(rsp, "[!] Shadow: Invalid property '%s'\n", property.text);
|
||||
}
|
||||
}
|
||||
|
||||
return needs_refresh;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "misc/helpers.h"
|
||||
#include "color.h"
|
||||
|
||||
struct shadow {
|
||||
bool enabled;
|
||||
|
@ -8,7 +9,7 @@ struct shadow {
|
|||
uint32_t distance;
|
||||
CGPoint offset;
|
||||
|
||||
struct rgba_color color;
|
||||
struct color color;
|
||||
};
|
||||
|
||||
void shadow_init(struct shadow* shadow);
|
||||
|
|
71
src/text.c
71
src/text.c
|
@ -43,7 +43,6 @@ static void text_prepare_line(struct text* text) {
|
|||
text->bounds.size.height = (uint32_t) (text->bounds.size.height + 1.5);
|
||||
text->bounds.origin.x = (int32_t) (text->bounds.origin.x + 0.5);
|
||||
text->bounds.origin.y = (int32_t) (text->bounds.origin.y + 0.5);
|
||||
text->line.color = text->highlight ? text->highlight_color : text->color;
|
||||
|
||||
CFRelease(string);
|
||||
CFRelease(attributes);
|
||||
|
@ -90,40 +89,22 @@ void text_init(struct text* text) {
|
|||
text->y_offset = 0;
|
||||
text->align = POSITION_LEFT;
|
||||
|
||||
text->color = rgba_color_from_hex(0xffffffff);
|
||||
text->highlight_color = rgba_color_from_hex(0xff000000);
|
||||
|
||||
text->string = string_copy("");
|
||||
text_set_string(text, text->string, false);
|
||||
shadow_init(&text->shadow);
|
||||
background_init(&text->background);
|
||||
font_init(&text->font);
|
||||
}
|
||||
|
||||
static bool text_update_color(struct text* text) {
|
||||
struct rgba_color target_color = text->highlight
|
||||
? text->highlight_color
|
||||
: text->color;
|
||||
|
||||
if (text->line.color.r == target_color.r
|
||||
&& text->line.color.g == target_color.g
|
||||
&& text->line.color.b == target_color.b
|
||||
&& text->line.color.a == target_color.a) {
|
||||
return false;
|
||||
}
|
||||
|
||||
text->line.color = target_color;
|
||||
return true;
|
||||
color_init(&text->color, 0xffffffff);
|
||||
color_init(&text->highlight_color, 0xff000000);
|
||||
}
|
||||
|
||||
static bool text_set_color(struct text* text, uint32_t color) {
|
||||
text->color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
return color_set_hex(&text->color, color);
|
||||
}
|
||||
|
||||
static bool text_set_highlight_color(struct text* text, uint32_t color) {
|
||||
text->highlight_color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
return color_set_hex(&text->highlight_color, color);
|
||||
}
|
||||
|
||||
static bool text_set_padding_left(struct text* text, int padding) {
|
||||
|
@ -242,11 +223,8 @@ void text_draw(struct text* text, CGContextRef context) {
|
|||
CTLineDraw(text->line.line, context);
|
||||
}
|
||||
|
||||
CGContextSetRGBFillColor(context,
|
||||
text->line.color.r,
|
||||
text->line.color.g,
|
||||
text->line.color.b,
|
||||
text->line.color.a );
|
||||
struct color color = text->highlight ? text->highlight_color : text->color;
|
||||
CGContextSetRGBFillColor(context, color.r, color.g, color.b, color.a);
|
||||
|
||||
CGContextSetTextPosition(context,
|
||||
text->bounds.origin.x + text->padding_left,
|
||||
|
@ -292,8 +270,8 @@ void text_serialize(struct text* text, char* indent, FILE* rsp) {
|
|||
indent, text->string,
|
||||
indent, format_bool(text->drawing),
|
||||
indent, format_bool(text->highlight),
|
||||
indent, hex_from_rgba_color(text->color),
|
||||
indent, hex_from_rgba_color(text->highlight_color),
|
||||
indent, text->color.hex,
|
||||
indent, text->highlight_color.hex,
|
||||
indent, text->padding_left,
|
||||
indent, text->padding_right,
|
||||
indent, text->y_offset,
|
||||
|
@ -316,43 +294,43 @@ bool text_parse_sub_domain(struct text* text, FILE* rsp, struct token property,
|
|||
struct token token = get_token(&message);
|
||||
ANIMATE_BYTES(text_set_color,
|
||||
text,
|
||||
hex_from_rgba_color(text->color),
|
||||
token_to_int(token) );
|
||||
text->color.hex,
|
||||
token_to_int(token));
|
||||
}
|
||||
else if (token_equals(property, PROPERTY_HIGHLIGHT)) {
|
||||
bool highlight = evaluate_boolean_state(get_token(&message),
|
||||
text->highlight );
|
||||
if (g_bar_manager.animator.duration > 0) {
|
||||
if (text->highlight && !highlight) {
|
||||
uint32_t target = hex_from_rgba_color(text->color);
|
||||
text_set_color(text, hex_from_rgba_color(text->highlight_color));
|
||||
uint32_t target = text->color.hex;
|
||||
text_set_color(text, text->highlight_color.hex);
|
||||
|
||||
ANIMATE_BYTES(text_set_color,
|
||||
text,
|
||||
hex_from_rgba_color(text->color),
|
||||
target );
|
||||
text->color.hex,
|
||||
target );
|
||||
}
|
||||
else if (!text->highlight && highlight) {
|
||||
uint32_t target = hex_from_rgba_color(text->highlight_color);
|
||||
text_set_highlight_color(text, hex_from_rgba_color(text->color));
|
||||
uint32_t target = text->highlight_color.hex;
|
||||
text_set_highlight_color(text, text->color.hex);
|
||||
|
||||
ANIMATE_BYTES(text_set_highlight_color,
|
||||
text,
|
||||
hex_from_rgba_color(text->highlight_color),
|
||||
target );
|
||||
text->highlight_color.hex,
|
||||
target );
|
||||
}
|
||||
}
|
||||
|
||||
needs_refresh = text->highlight != highlight;
|
||||
text->highlight = highlight;
|
||||
needs_refresh = text_update_color(text);
|
||||
} else if (token_equals(property, PROPERTY_FONT))
|
||||
needs_refresh = text_set_font(text, string_copy(message), false);
|
||||
else if (token_equals(property, PROPERTY_HIGHLIGHT_COLOR)) {
|
||||
struct token token = get_token(&message);
|
||||
ANIMATE_BYTES(text_set_highlight_color,
|
||||
text,
|
||||
hex_from_rgba_color(text->highlight_color),
|
||||
token_to_int(token) );
|
||||
text->highlight_color.hex,
|
||||
token_to_int(token) );
|
||||
|
||||
} else if (token_equals(property, PROPERTY_PADDING_LEFT)) {
|
||||
struct token token = get_token(&message);
|
||||
|
@ -450,6 +428,13 @@ bool text_parse_sub_domain(struct text* text, FILE* rsp, struct token property,
|
|||
return shadow_parse_sub_domain(&text->shadow, rsp, entry, message);
|
||||
else if (token_equals(subdom, SUB_DOMAIN_FONT))
|
||||
return font_parse_sub_domain(&text->font, rsp, entry, message);
|
||||
else if (token_equals(subdom, SUB_DOMAIN_COLOR))
|
||||
return color_parse_sub_domain(&text->color, rsp, entry, message);
|
||||
else if (token_equals(subdom, SUB_DOMAIN_HIGHLIGHT_COLOR))
|
||||
return color_parse_sub_domain(&text->highlight_color,
|
||||
rsp,
|
||||
entry,
|
||||
message);
|
||||
else
|
||||
respond(rsp, "[!] Text: Invalid subdomain '%s' \n", subdom.text);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ struct text_line {
|
|||
CTLineRef line;
|
||||
CGFloat ascent;
|
||||
CGFloat descent;
|
||||
struct rgba_color color;
|
||||
};
|
||||
|
||||
struct text {
|
||||
|
@ -27,8 +26,8 @@ struct text {
|
|||
|
||||
struct font font;
|
||||
struct text_line line;
|
||||
struct rgba_color color;
|
||||
struct rgba_color highlight_color;
|
||||
struct color color;
|
||||
struct color highlight_color;
|
||||
struct shadow shadow;
|
||||
|
||||
struct background background;
|
||||
|
|
Loading…
Reference in a new issue