mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 03:43:02 +00:00
cleanup
This commit is contained in:
parent
faf1d22ca1
commit
d2e6a36f6b
18 changed files with 156 additions and 206 deletions
|
@ -101,7 +101,7 @@ uint32_t alias_get_height(struct alias* alias) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void alias_find_window(struct alias* alias) {
|
||||
static void alias_find_window(struct alias* alias) {
|
||||
CFArrayRef window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionAll,
|
||||
kCGNullWindowID );
|
||||
int window_count = CFArrayGetCount(window_list);
|
||||
|
|
|
@ -24,7 +24,6 @@ struct alias {
|
|||
void alias_init(struct alias* alias);
|
||||
void alias_setup(struct alias* alias, char* owner, char* name);
|
||||
bool alias_update_image(struct alias* alias);
|
||||
void alias_find_window(struct alias* alias);
|
||||
uint32_t alias_get_length(struct alias* alias);
|
||||
uint32_t alias_get_height(struct alias* alias);
|
||||
|
||||
|
|
|
@ -1,43 +1,6 @@
|
|||
#include "animation.h"
|
||||
#include "event.h"
|
||||
|
||||
double function_linear(double x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
double function_square(double x) {
|
||||
return x*x;
|
||||
}
|
||||
|
||||
double function_tanh(double x) {
|
||||
double a = 0.52;
|
||||
return a * tanh(2. * atanh(1. / (2. * a)) * (x - 0.5)) + 0.5;
|
||||
}
|
||||
|
||||
double function_sin(double x) {
|
||||
return sin(M_PI / 2. * x);
|
||||
}
|
||||
|
||||
double function_exp(double x) {
|
||||
return x*exp(x - 1.);
|
||||
}
|
||||
|
||||
double function_bounce(double x) {
|
||||
double alpha = 2.;
|
||||
double beta = 0.8;
|
||||
if (x < 1. / alpha) {
|
||||
return alpha*alpha * x * x;
|
||||
}
|
||||
else {
|
||||
return beta * beta * (x - 1./2. + 1./alpha/2.)
|
||||
+ 1. - beta*beta* (1./2. + 1./alpha/2.);
|
||||
}
|
||||
}
|
||||
|
||||
double function_overshoot(double x) {
|
||||
return x * (1. + 0.5*(sin(3. * M_PI * x)));
|
||||
}
|
||||
|
||||
static ANIMATOR_CALLBACK(animator_handler) {
|
||||
struct event *event = event_create(&g_event_loop, ANIMATOR_REFRESH, NULL);
|
||||
event_loop_post(&g_event_loop, event);
|
||||
|
@ -50,7 +13,7 @@ struct animation* animation_create() {
|
|||
return animation;
|
||||
}
|
||||
|
||||
void animation_destroy(struct animation* animation) {
|
||||
static void animation_destroy(struct animation* animation) {
|
||||
if (animation) free(animation);
|
||||
}
|
||||
|
||||
|
@ -80,7 +43,7 @@ void animation_setup(struct animation* animation, void* target, animator_functio
|
|||
}
|
||||
}
|
||||
|
||||
bool animation_update(struct animation* animation) {
|
||||
static bool animation_update(struct animation* animation) {
|
||||
if (!animation->target
|
||||
|| !animation->update_function
|
||||
|| animation->counter > animation->duration) {
|
||||
|
@ -137,7 +100,7 @@ void animator_init(struct animator* animator) {
|
|||
animator->duration = 0;
|
||||
}
|
||||
|
||||
void animator_calculate_offset_for_animation(struct animator* animator, struct animation* animation) {
|
||||
static void animator_calculate_offset_for_animation(struct animator* animator, struct animation* animation) {
|
||||
if (animator->animation_count < 1) return;
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
@ -176,7 +139,7 @@ void animator_add(struct animator* animator, struct animation* animation) {
|
|||
}
|
||||
}
|
||||
|
||||
void animator_remove(struct animator* animator, struct animation* animation) {
|
||||
static void animator_remove(struct animator* animator, struct animation* animation) {
|
||||
if (animator->animation_count == 1) {
|
||||
free(animator->animations);
|
||||
animator->animations = NULL;
|
||||
|
|
|
@ -69,10 +69,7 @@ struct animation {
|
|||
};
|
||||
|
||||
struct animation* animation_create();
|
||||
void animation_destroy(struct animation* animation);
|
||||
|
||||
void animation_setup(struct animation* animation, void* target, animator_function* update_function, int initial_value, int final_value, uint32_t duration, char interp_function);
|
||||
bool animation_update(struct animation* animation);
|
||||
|
||||
extern struct event_loop g_event_loop;
|
||||
|
||||
|
@ -90,5 +87,4 @@ struct animator {
|
|||
|
||||
void animator_init(struct animator* animator);
|
||||
void animator_add(struct animator* animator, struct animation* animation);
|
||||
void animator_remove(struct animator* animator, struct animation* animation);
|
||||
bool animator_update(struct animator* animator);
|
||||
|
|
|
@ -23,7 +23,20 @@ void background_init(struct background* background) {
|
|||
image_init(&background->image);
|
||||
}
|
||||
|
||||
bool background_set_color(struct background* background, uint32_t color) {
|
||||
bool background_set_height(struct background* background, uint32_t height) {
|
||||
if (background->bounds.size.height == height) return false;
|
||||
background->bounds.size.height = height;
|
||||
background->overrides_height = height != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool background_set_enabled(struct background* background, bool enabled) {
|
||||
if (background->enabled == enabled) return false;
|
||||
background->enabled = enabled;
|
||||
return true;
|
||||
}
|
||||
|
||||
static 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
|
||||
|
@ -34,7 +47,7 @@ bool background_set_color(struct background* background, uint32_t color) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool background_set_border_color(struct background* background, uint32_t color) {
|
||||
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
|
||||
|
@ -44,44 +57,31 @@ bool background_set_border_color(struct background* background, uint32_t color)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool background_set_enabled(struct background* background, bool enabled) {
|
||||
if (background->enabled == enabled) return false;
|
||||
background->enabled = enabled;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_height(struct background* background, uint32_t height) {
|
||||
if (background->bounds.size.height == height) return false;
|
||||
background->bounds.size.height = height;
|
||||
background->overrides_height = height != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_border_width(struct background* background, uint32_t border_width) {
|
||||
static bool background_set_border_width(struct background* background, uint32_t border_width) {
|
||||
if (background->border_width == border_width) return false;
|
||||
background->border_width = border_width;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_corner_radius(struct background* background, uint32_t corner_radius) {
|
||||
static bool background_set_corner_radius(struct background* background, uint32_t corner_radius) {
|
||||
if (background->corner_radius == corner_radius) return false;
|
||||
background->corner_radius = corner_radius;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_padding_left(struct background* background, uint32_t pad) {
|
||||
static bool background_set_padding_left(struct background* background, uint32_t pad) {
|
||||
if (background->padding_left == pad) return false;
|
||||
background->padding_left = pad;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_padding_right(struct background* background, uint32_t pad) {
|
||||
static bool background_set_padding_right(struct background* background, uint32_t pad) {
|
||||
if (background->padding_right == pad) return false;
|
||||
background->padding_right = pad;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool background_set_yoffset(struct background* background, int offset) {
|
||||
static bool background_set_yoffset(struct background* background, int offset) {
|
||||
if (background->y_offset == offset) return false;
|
||||
background->y_offset = offset;
|
||||
return true;
|
||||
|
|
|
@ -19,16 +19,10 @@ struct background {
|
|||
};
|
||||
|
||||
void background_init(struct background* background);
|
||||
bool background_set_color(struct background* background, uint32_t color);
|
||||
bool background_set_border_color(struct background* background, uint32_t color);
|
||||
bool background_set_enabled(struct background* background, bool enabled);
|
||||
bool background_set_height(struct background* background, uint32_t height);
|
||||
bool background_set_border_width(struct background* background, uint32_t border_width);
|
||||
bool background_set_corner_radius(struct background* background, uint32_t corner_radius);
|
||||
bool background_set_padding_left(struct background* background, uint32_t pad);
|
||||
bool background_set_padding_right(struct background* background, uint32_t pad);
|
||||
|
||||
void background_calculate_bounds(struct background* background, uint32_t x, uint32_t y);
|
||||
|
||||
bool background_set_height(struct background* background, uint32_t height);
|
||||
|
||||
void background_draw(struct background* background, CGContextRef context);
|
||||
|
||||
void background_clear_pointers(struct background* background);
|
||||
|
|
10
src/bar.c
10
src/bar.c
|
@ -31,7 +31,7 @@ bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) {
|
||||
static void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) {
|
||||
if (bar->adid != g_bar_manager.active_adid) return;
|
||||
struct window* window = bar_item_get_window(bar_item, bar->adid);
|
||||
|
||||
|
@ -159,7 +159,7 @@ void bar_draw(struct bar* bar) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline void bar_calculate_bounds_top_bottom(struct bar* bar) {
|
||||
static void bar_calculate_bounds_top_bottom(struct bar* bar) {
|
||||
bool is_builtin = CGDisplayIsBuiltin(bar->did);
|
||||
uint32_t notch_width = is_builtin ? g_bar_manager.notch_width : 0;
|
||||
|
||||
|
@ -294,7 +294,7 @@ static inline void bar_calculate_bounds_top_bottom(struct bar* bar) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline void bar_calculate_bounds_left_right(struct bar* bar) {
|
||||
static void bar_calculate_bounds_left_right(struct bar* bar) {
|
||||
uint32_t notch_width = 0;
|
||||
|
||||
uint32_t center_length = bar_manager_length_for_bar_side(&g_bar_manager,
|
||||
|
@ -411,7 +411,7 @@ void bar_calculate_bounds(struct bar* bar) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline CGRect bar_get_frame(struct bar *bar) {
|
||||
static CGRect bar_get_frame(struct bar *bar) {
|
||||
bool is_builtin = CGDisplayIsBuiltin(bar->did);
|
||||
int notch_offset = is_builtin ? g_bar_manager.notch_offset : 0;
|
||||
|
||||
|
@ -479,7 +479,7 @@ void bar_set_hidden(struct bar* bar, bool hidden) {
|
|||
else bar_resize(bar);
|
||||
}
|
||||
|
||||
static inline void bar_create_window(struct bar* bar) {
|
||||
static void bar_create_window(struct bar* bar) {
|
||||
window_init(&bar->window);
|
||||
window_create(&bar->window, bar_get_frame(bar));
|
||||
window_assign_mouse_tracking_area(&bar->window, bar->window.frame);
|
||||
|
|
|
@ -9,7 +9,7 @@ struct bar_item* bar_item_create() {
|
|||
return bar_item;
|
||||
}
|
||||
|
||||
void bar_item_clear_pointers(struct bar_item* bar_item) {
|
||||
static void bar_item_clear_pointers(struct bar_item* bar_item) {
|
||||
bar_item->name = NULL;
|
||||
bar_item->script = NULL;
|
||||
bar_item->click_script = NULL;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "custom_events.h"
|
||||
|
||||
struct custom_event* custom_event_create(void) {
|
||||
static struct custom_event* custom_event_create(void) {
|
||||
return malloc(sizeof(struct custom_event));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
#include "event_loop.h"
|
||||
#include "event.h"
|
||||
|
||||
#ifdef STATS
|
||||
struct cycle_counter {
|
||||
uint64_t cycle_count;
|
||||
uint64_t hit_count;
|
||||
};
|
||||
|
||||
static struct cycle_counter queue_counters[2];
|
||||
static struct cycle_counter event_counters[EVENT_TYPE_COUNT];
|
||||
|
||||
static inline void cycle_counter_tick(const char *name, struct cycle_counter *counter, uint64_t elapsed_cycles) {
|
||||
uint64_t cycle_count = __sync_add_and_fetch(&counter->cycle_count, elapsed_cycles);
|
||||
uint64_t hit_count = __sync_add_and_fetch(&counter->hit_count, 1);
|
||||
fprintf(stdout, "%30s: hits %'25lld | cur %'25lld | avg %'25lld\n",
|
||||
name, hit_count, elapsed_cycles, cycle_count / hit_count)
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool queue_init(struct queue *queue) {
|
||||
if (!memory_pool_init(&queue->pool, QUEUE_POOL_SIZE)) return false;
|
||||
queue->head = memory_pool_push(&queue->pool, struct queue_item);
|
||||
|
@ -34,10 +17,6 @@ static void queue_push(struct queue *queue, struct event *event) {
|
|||
bool success;
|
||||
struct queue_item *tail, *new_tail;
|
||||
|
||||
#ifdef STATS
|
||||
uint64_t begin_cycles = __rdtsc();
|
||||
#endif
|
||||
|
||||
new_tail = memory_pool_push(&queue->pool, struct queue_item);
|
||||
new_tail->data = event;
|
||||
new_tail->next = NULL;
|
||||
|
@ -49,15 +28,6 @@ static void queue_push(struct queue *queue, struct event *event) {
|
|||
if (!success) __sync_bool_compare_and_swap(&queue->tail, tail, tail->next);
|
||||
} while (!success);
|
||||
__sync_bool_compare_and_swap(&queue->tail, tail, new_tail);
|
||||
|
||||
#ifdef DEBUG
|
||||
uint64_t count = __sync_add_and_fetch(&queue->count, 1);
|
||||
assert(count > 0 && count < QUEUE_MAX_COUNT);
|
||||
#endif
|
||||
|
||||
#ifdef STATS
|
||||
cycle_counter_tick(__FUNCTION__, &queue_counters[0], __rdtsc() - begin_cycles);
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct event *queue_pop(struct queue *queue) {
|
||||
|
|
|
@ -88,7 +88,7 @@ bool image_load(struct image* image, char* path, FILE* rsp) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool image_data_equals(struct image* image, CFDataRef new_data_ref) {
|
||||
static bool image_data_equals(struct image* image, CFDataRef new_data_ref) {
|
||||
bool equals = false;
|
||||
if (image->image_ref && image->data_ref) {
|
||||
uint32_t old_len = CFDataGetLength(image->data_ref);
|
||||
|
|
|
@ -21,7 +21,6 @@ struct image {
|
|||
|
||||
void image_init(struct image* image);
|
||||
bool image_set_enabled(struct image* image, bool enabled);
|
||||
bool image_data_equals(struct image* image, CFDataRef new_data_ref);
|
||||
void image_copy(struct image* image, CGImageRef source);
|
||||
bool image_set_image(struct image* image, CGImageRef new_image_ref, CGRect bounds, bool forced);
|
||||
bool image_load(struct image* image, char* path, FILE* rsp);
|
||||
|
|
|
@ -60,6 +60,43 @@ static inline void notification_destroy(struct notification* notification) {
|
|||
free(notification);
|
||||
}
|
||||
|
||||
static inline double function_linear(double x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline double function_square(double x) {
|
||||
return x*x;
|
||||
}
|
||||
|
||||
static inline double function_tanh(double x) {
|
||||
double a = 0.52;
|
||||
return a * tanh(2. * atanh(1. / (2. * a)) * (x - 0.5)) + 0.5;
|
||||
}
|
||||
|
||||
static inline double function_sin(double x) {
|
||||
return sin(M_PI / 2. * x);
|
||||
}
|
||||
|
||||
static inline double function_exp(double x) {
|
||||
return x*exp(x - 1.);
|
||||
}
|
||||
|
||||
static inline double function_bounce(double x) {
|
||||
double alpha = 2.;
|
||||
double beta = 0.8;
|
||||
if (x < 1. / alpha) {
|
||||
return alpha*alpha * x * x;
|
||||
}
|
||||
else {
|
||||
return beta * beta * (x - 1./2. + 1./alpha/2.)
|
||||
+ 1. - beta*beta* (1./2. + 1./alpha/2.);
|
||||
}
|
||||
}
|
||||
|
||||
static inline double function_overshoot(double x) {
|
||||
return x * (1. + 0.5*(sin(3. * M_PI * x)));
|
||||
}
|
||||
|
||||
static inline char* format_bool(bool b) {
|
||||
return b ? "on" : "off";
|
||||
}
|
||||
|
|
19
src/popup.c
19
src/popup.c
|
@ -26,20 +26,20 @@ void popup_init(struct popup* popup, struct bar_item* host) {
|
|||
popup->background.color = rgba_color_from_hex(0x44000000);
|
||||
}
|
||||
|
||||
CGRect popup_get_frame(struct popup* popup) {
|
||||
static CGRect popup_get_frame(struct popup* popup) {
|
||||
return (CGRect){{popup->anchor.x, popup->anchor.y},
|
||||
{popup->background.bounds.size.width,
|
||||
popup->background.bounds.size.height}};
|
||||
}
|
||||
|
||||
bool popup_set_blur_radius(struct popup* popup, uint32_t radius) {
|
||||
static bool popup_set_blur_radius(struct popup* popup, uint32_t radius) {
|
||||
if (popup->blur_radius == radius) return false;
|
||||
popup->blur_radius = radius;
|
||||
window_set_blur_radius(&popup->window, radius);
|
||||
return false;
|
||||
}
|
||||
|
||||
void popup_order_windows(struct popup* popup) {
|
||||
static void popup_order_windows(struct popup* popup) {
|
||||
window_set_level(&popup->window, kCGScreenSaverWindowLevel);
|
||||
window_order(&popup->window, NULL, W_ABOVE);
|
||||
|
||||
|
@ -62,7 +62,7 @@ void popup_order_windows(struct popup* popup) {
|
|||
}
|
||||
}
|
||||
|
||||
void popup_calculate_popup_anchor_for_bar_item(struct popup* popup, struct bar_item* bar_item, struct bar* bar) {
|
||||
static void popup_calculate_popup_anchor_for_bar_item(struct popup* popup, struct bar_item* bar_item, struct bar* bar) {
|
||||
if (popup->adid != g_bar_manager.active_adid) return;
|
||||
struct window* window = bar_item_get_window(bar_item, popup->adid);
|
||||
|
||||
|
@ -210,7 +210,7 @@ void popup_calculate_bounds(struct popup* popup, struct bar* bar) {
|
|||
window_set_frame(&popup->window, popup_get_frame(popup));
|
||||
}
|
||||
|
||||
void popup_create_window(struct popup* popup) {
|
||||
static void popup_create_window(struct popup* popup) {
|
||||
window_create(&popup->window,(CGRect){{popup->anchor.x, popup->anchor.y},
|
||||
{popup->background.bounds.size.width,
|
||||
popup->background.bounds.size.height}});
|
||||
|
@ -228,7 +228,7 @@ void popup_create_window(struct popup* popup) {
|
|||
popup->drawing = true;
|
||||
}
|
||||
|
||||
void popup_close_window(struct popup* popup) {
|
||||
static void popup_close_window(struct popup* popup) {
|
||||
window_close(&popup->window);
|
||||
popup->drawing = false;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
|
|||
bar_item->parent = popup->host;
|
||||
}
|
||||
|
||||
bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
static bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
for (int i = 0; i < popup->num_items; i++) {
|
||||
if (popup->items[i] == bar_item) return true;
|
||||
}
|
||||
|
@ -380,16 +380,15 @@ void popup_serialize(struct popup* popup, char* indent, FILE* rsp) {
|
|||
if (i < popup->num_items - 1) fprintf(rsp, ",\n");
|
||||
}
|
||||
fprintf(rsp, "\n%s]", indent);
|
||||
|
||||
}
|
||||
|
||||
bool popup_set_yoffset(struct popup* popup, int y_offset) {
|
||||
static bool popup_set_yoffset(struct popup* popup, int y_offset) {
|
||||
if (popup->y_offset == y_offset) return false;
|
||||
popup->y_offset = y_offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool popup_set_cell_size(struct popup* popup, int size) {
|
||||
static bool popup_set_cell_size(struct popup* popup, int size) {
|
||||
if (popup->cell_size == size && popup->overrides_cell_size) return false;
|
||||
popup->overrides_cell_size = true;
|
||||
popup->cell_size = size;
|
||||
|
|
|
@ -12,13 +12,13 @@ void shadow_init(struct shadow* shadow) {
|
|||
shadow->color = rgba_color_from_hex(0xff000000);
|
||||
}
|
||||
|
||||
bool shadow_set_enabled(struct shadow* shadow, bool enabled) {
|
||||
static bool shadow_set_enabled(struct shadow* shadow, bool enabled) {
|
||||
if (shadow->enabled == enabled) return false;
|
||||
shadow->enabled = enabled;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool shadow_set_angle(struct shadow* shadow, uint32_t angle) {
|
||||
static bool shadow_set_angle(struct shadow* shadow, uint32_t angle) {
|
||||
if (shadow->angle == angle) return false;
|
||||
shadow->angle = angle;
|
||||
shadow->offset.x = ((float)shadow->distance)*cos(((double)shadow->angle)*deg_to_rad);
|
||||
|
@ -26,7 +26,7 @@ bool shadow_set_angle(struct shadow* shadow, uint32_t angle) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool shadow_set_distance(struct shadow* shadow, uint32_t distance) {
|
||||
static bool shadow_set_distance(struct shadow* shadow, uint32_t distance) {
|
||||
if (shadow->distance == distance) return false;
|
||||
shadow->distance = distance;
|
||||
shadow->offset.x = ((float)shadow->distance)
|
||||
|
@ -36,7 +36,7 @@ bool shadow_set_distance(struct shadow* shadow, uint32_t distance) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool shadow_set_color(struct shadow* shadow, uint32_t color) {
|
||||
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
|
||||
|
|
|
@ -12,10 +12,6 @@ struct shadow {
|
|||
};
|
||||
|
||||
void shadow_init(struct shadow* shadow);
|
||||
bool shadow_set_enabled(struct shadow* shadow, bool enabled);
|
||||
bool shadow_set_angle(struct shadow* shadow, uint32_t angle);
|
||||
bool shadow_set_distance(struct shadow* shadow, uint32_t distance);
|
||||
bool shadow_set_color(struct shadow* shadow, uint32_t color);
|
||||
CGRect shadow_get_bounds(struct shadow* shadow, CGRect reference_bounds);
|
||||
|
||||
void shadow_serialize(struct shadow* shadow, char* indent, FILE* rsp);
|
||||
|
|
136
src/text.c
136
src/text.c
|
@ -44,29 +44,7 @@ static CTFontRef text_create_font(char *cstring) {
|
|||
return font;
|
||||
}
|
||||
|
||||
void text_init(struct text* text) {
|
||||
text->drawing = true;
|
||||
text->highlight = false;
|
||||
text->has_const_width = false;
|
||||
text->custom_width = 0;
|
||||
text->padding_left = 0;
|
||||
text->padding_right = 0;
|
||||
text->y_offset = 0;
|
||||
text->align = POSITION_LEFT;
|
||||
|
||||
text->color = rgba_color_from_hex(0xffffffff);
|
||||
text->highlight_color = rgba_color_from_hex(0xff000000);
|
||||
|
||||
text->font = NULL;
|
||||
text->string = string_copy("");
|
||||
text->font_name = string_copy("Hack Nerd Font:Bold:14.0");
|
||||
text_set_font(text, text->font_name, true);
|
||||
text_set_string(text, text->string, false);
|
||||
shadow_init(&text->shadow);
|
||||
background_init(&text->background);
|
||||
}
|
||||
|
||||
void text_prepare_line(struct text* text) {
|
||||
static void text_prepare_line(struct text* text) {
|
||||
const void *keys[] = { kCTFontAttributeName,
|
||||
kCTForegroundColorFromContextAttributeName };
|
||||
|
||||
|
@ -111,6 +89,11 @@ void text_prepare_line(struct text* text) {
|
|||
CFRelease(attr_string);
|
||||
}
|
||||
|
||||
static void text_destroy_line(struct text* text) {
|
||||
if (text->line.line) CFRelease(text->line.line);
|
||||
text->line.line = NULL;
|
||||
}
|
||||
|
||||
bool text_set_string(struct text* text, char* string, bool forced) {
|
||||
if (!string) return false;
|
||||
if (!forced && text->string && strcmp(text->string, string) == 0) {
|
||||
|
@ -124,16 +107,6 @@ bool text_set_string(struct text* text, char* string, bool forced) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool text_set_color(struct text* text, uint32_t color) {
|
||||
text->color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
}
|
||||
|
||||
bool text_set_hightlight_color(struct text* text, uint32_t color) {
|
||||
text->highlight_color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
}
|
||||
|
||||
bool text_set_font(struct text* text, char* font_string, bool forced) {
|
||||
if (!font_string) return false;
|
||||
if (!forced && text->font_name
|
||||
|
@ -151,38 +124,29 @@ bool text_set_font(struct text* text, char* font_string, bool forced) {
|
|||
return text_set_string(text, text->string, true);
|
||||
}
|
||||
|
||||
bool text_set_padding_left(struct text* text, int padding) {
|
||||
if (text->padding_left == padding) return false;
|
||||
text->padding_left = padding;
|
||||
return true;
|
||||
void text_init(struct text* text) {
|
||||
text->drawing = true;
|
||||
text->highlight = false;
|
||||
text->has_const_width = false;
|
||||
text->custom_width = 0;
|
||||
text->padding_left = 0;
|
||||
text->padding_right = 0;
|
||||
text->y_offset = 0;
|
||||
text->align = POSITION_LEFT;
|
||||
|
||||
text->color = rgba_color_from_hex(0xffffffff);
|
||||
text->highlight_color = rgba_color_from_hex(0xff000000);
|
||||
|
||||
text->font = NULL;
|
||||
text->string = string_copy("");
|
||||
text->font_name = string_copy("Hack Nerd Font:Bold:14.0");
|
||||
text_set_font(text, text->font_name, true);
|
||||
text_set_string(text, text->string, false);
|
||||
shadow_init(&text->shadow);
|
||||
background_init(&text->background);
|
||||
}
|
||||
|
||||
bool text_set_padding_right(struct text* text, int padding) {
|
||||
if (text->padding_right == padding) return false;
|
||||
text->padding_right = padding;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool text_set_yoffset(struct text* text, int offset) {
|
||||
if (text->y_offset == offset) return false;
|
||||
text->y_offset = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool text_set_width(struct text* text, int width) {
|
||||
if (width < 0) {
|
||||
bool prev = text->has_const_width;
|
||||
text->has_const_width = false;
|
||||
return prev != text->has_const_width;
|
||||
}
|
||||
|
||||
if (text->custom_width == width && text->has_const_width) return false;
|
||||
text->custom_width = width;
|
||||
text->has_const_width = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool text_update_color(struct text* text) {
|
||||
static bool text_update_color(struct text* text) {
|
||||
struct rgba_color target_color = text->highlight
|
||||
? text->highlight_color
|
||||
: text->color;
|
||||
|
@ -198,6 +162,47 @@ bool text_update_color(struct text* text) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool text_set_color(struct text* text, uint32_t color) {
|
||||
text->color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
}
|
||||
|
||||
static bool text_set_hightlight_color(struct text* text, uint32_t color) {
|
||||
text->highlight_color = rgba_color_from_hex(color);
|
||||
return text_update_color(text);
|
||||
}
|
||||
|
||||
static bool text_set_padding_left(struct text* text, int padding) {
|
||||
if (text->padding_left == padding) return false;
|
||||
text->padding_left = padding;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool text_set_padding_right(struct text* text, int padding) {
|
||||
if (text->padding_right == padding) return false;
|
||||
text->padding_right = padding;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool text_set_yoffset(struct text* text, int offset) {
|
||||
if (text->y_offset == offset) return false;
|
||||
text->y_offset = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool text_set_width(struct text* text, int width) {
|
||||
if (width < 0) {
|
||||
bool prev = text->has_const_width;
|
||||
text->has_const_width = false;
|
||||
return prev != text->has_const_width;
|
||||
}
|
||||
|
||||
if (text->custom_width == width && text->has_const_width) return false;
|
||||
text->custom_width = width;
|
||||
text->has_const_width = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void text_clear_pointers(struct text* text) {
|
||||
text->string = NULL;
|
||||
text->font_name = NULL;
|
||||
|
@ -225,11 +230,6 @@ uint32_t text_get_height(struct text* text) {
|
|||
return text->drawing ? text->bounds.size.height : 0;
|
||||
}
|
||||
|
||||
void text_destroy_line(struct text* text) {
|
||||
if (text->line.line) CFRelease(text->line.line);
|
||||
text->line.line = NULL;
|
||||
}
|
||||
|
||||
void text_destroy(struct text* text) {
|
||||
background_destroy(&text->background);
|
||||
if (text->string) free(text->string);
|
||||
|
|
|
@ -37,13 +37,10 @@ struct text {
|
|||
|
||||
void text_init(struct text* text);
|
||||
void text_clear_pointers(struct text* text);
|
||||
void text_destroy_line(struct text* text);
|
||||
bool text_set_string(struct text* text, char* string, bool forced);
|
||||
bool text_set_color(struct text* text, uint32_t color);
|
||||
bool text_set_font(struct text* text, char* font_string, bool forced);
|
||||
uint32_t text_get_length(struct text* text, bool override);
|
||||
uint32_t text_get_height(struct text* text);
|
||||
bool text_update_color(struct text* text);
|
||||
bool text_set_string(struct text* text, char* string, bool forced);
|
||||
bool text_set_font(struct text* text, char* font_string, bool forced);
|
||||
|
||||
void text_calculate_bounds(struct text* text, uint32_t x, uint32_t y);
|
||||
void text_draw(struct text* text, CGContextRef context);
|
||||
|
|
Loading…
Reference in a new issue