mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-17 04:58:28 +00:00
modularize bar_item drawing
This commit is contained in:
parent
4c3b5a50c8
commit
6fab04fadc
1 changed files with 43 additions and 39 deletions
82
src/bar.c
82
src/bar.c
|
@ -115,6 +115,48 @@ void bar_draw_alias(struct bar* bar, struct bar_item* bar_item, uint32_t x) {
|
|||
CGContextDrawImage(bar->context, bounds, bar_item->alias.image_ref);
|
||||
}
|
||||
|
||||
void bar_draw_bar_items(struct bar* bar) {
|
||||
SLSDisableUpdate(g_connection);
|
||||
SLSOrderWindow(g_connection, bar->id, -1, 0);
|
||||
SLSRemoveAllTrackingAreas(g_connection, bar->id);
|
||||
|
||||
//if (!bar->background_exists) {
|
||||
draw_rect(bar->context, bar->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);
|
||||
bar->background_exists = true;
|
||||
//}
|
||||
|
||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
||||
|
||||
if (!bar_item->queued_for_redraw) continue;
|
||||
bar_item_remove_associated_bar(bar_item, bar->adid);
|
||||
|
||||
if (!bar_item->drawing) continue;
|
||||
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << bar->adid))) continue;
|
||||
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << bar->sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) continue;
|
||||
|
||||
struct text_line* label = &bar_item->label.line;
|
||||
struct text_line* icon = &bar_item->icon.line;
|
||||
|
||||
if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED)
|
||||
SLSAddTrackingRect(g_connection, bar->id, CGRectInset(bar_item_construct_bounding_rect(bar_item), 1, 1));
|
||||
|
||||
bar_item_append_associated_bar(bar_item, bar->adid);
|
||||
bar_item_set_bounding_rect_for_display(bar_item, bar->adid, bar->origin);
|
||||
|
||||
bar_draw_group(bar, bar_item, bar->adid);
|
||||
bar_draw_item_background(bar, bar_item, bar->adid);
|
||||
bar_draw_line(bar, icon, icon->bounds.origin.x, icon->bounds.origin.y + bar_item->y_offset);
|
||||
bar_draw_line(bar, label, label->bounds.origin.x, label->bounds.origin.y + bar_item->y_offset);
|
||||
bar_draw_alias(bar, bar_item, bar_item->sandwich_position);
|
||||
bar_draw_graph(bar, bar_item, bar_item->sandwich_position, bar_item->graph.rtl);
|
||||
}
|
||||
|
||||
CGContextFlush(bar->context);
|
||||
SLSOrderWindow(g_connection, bar->id, 1, bar->id);
|
||||
SLSReenableUpdate(g_connection);
|
||||
}
|
||||
|
||||
void bar_redraw(struct bar* bar) {
|
||||
if (bar->hidden) return;
|
||||
uint32_t adid = bar->adid;
|
||||
|
@ -212,45 +254,7 @@ void bar_redraw(struct bar* bar) {
|
|||
bar_item->sandwich_position = sandwich_position;
|
||||
}
|
||||
|
||||
SLSDisableUpdate(g_connection);
|
||||
SLSOrderWindow(g_connection, bar->id, -1, 0);
|
||||
SLSRemoveAllTrackingAreas(g_connection, bar->id);
|
||||
|
||||
//if (!bar->background_exists) {
|
||||
draw_rect(bar->context, bar->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);
|
||||
bar->background_exists = true;
|
||||
//}
|
||||
|
||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
||||
|
||||
if (!bar_item->queued_for_redraw) continue;
|
||||
bar_item_remove_associated_bar(bar_item, bar->adid);
|
||||
|
||||
if (!bar_item->drawing) continue;
|
||||
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << adid))) continue;
|
||||
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) continue;
|
||||
|
||||
struct text_line* label = &bar_item->label.line;
|
||||
struct text_line* icon = &bar_item->icon.line;
|
||||
|
||||
if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED)
|
||||
SLSAddTrackingRect(g_connection, bar->id, CGRectInset(bar_item_construct_bounding_rect(bar_item), 1, 1));
|
||||
|
||||
bar_item_append_associated_bar(bar_item, adid);
|
||||
bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin);
|
||||
|
||||
bar_draw_group(bar, bar_item, adid);
|
||||
bar_draw_item_background(bar, bar_item, adid);
|
||||
bar_draw_line(bar, icon, icon->bounds.origin.x, icon->bounds.origin.y + bar_item->y_offset);
|
||||
bar_draw_line(bar, label, label->bounds.origin.x, label->bounds.origin.y + bar_item->y_offset);
|
||||
bar_draw_alias(bar, bar_item, bar_item->sandwich_position);
|
||||
bar_draw_graph(bar, bar_item, bar_item->sandwich_position, bar_item->graph.rtl);
|
||||
}
|
||||
|
||||
CGContextFlush(bar->context);
|
||||
SLSOrderWindow(g_connection, bar->id, 1, bar->id);
|
||||
SLSReenableUpdate(g_connection);
|
||||
bar_draw_bar_items(bar);
|
||||
}
|
||||
|
||||
void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
|
||||
|
|
Loading…
Add table
Reference in a new issue