From dc5d0eceaceec383de997cafbe6f87f4402ac2f5 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 1 Mar 2016 02:06:12 -0500 Subject: [PATCH] simplifying the file view widget --- 4ed.cpp | 49 +-- 4ed_app_target.cpp | 1 - 4ed_color_view.cpp | 22 +- 4ed_debug_view.cpp | 359 ------------------- 4ed_file_view.cpp | 240 ++++++------- 4ed_layout.cpp | 1 - 4ed_rendering.h | 16 +- 4ed_style.cpp | 862 ++++++++++++--------------------------------- 8 files changed, 361 insertions(+), 1189 deletions(-) delete mode 100644 4ed_debug_view.cpp diff --git a/4ed.cpp b/4ed.cpp index 034f2071..0d6f9e2a 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1713,39 +1713,6 @@ COMMAND_DECL(open_menu){ AllowLocal(menu_view); } -#if FRED_INTERNAL -COMMAND_DECL(open_debug_view){ - ProfileMomentFunction(); - USE_VARS(vars); - USE_STYLE(style); - USE_LIVE_SET(live_set); - USE_PANEL(panel); - USE_MEM(mem); - USE_EXCHANGE(exchange); - - View *new_view = live_set_alloc_view(live_set, mem); - view_replace_major(system, exchange, new_view, panel, live_set); - - new_view->map = &vars->map_debug; - Debug_View *debug_view = debug_view_init(new_view); - debug_view->font_id = style->font_id; - debug_view->mode = DBG_MEMORY; -} - -COMMAND_DECL(debug_memory){ - ProfileMomentFunction(); - REQ_DBG_VIEW(view); - view->mode = DBG_MEMORY; -} - -COMMAND_DECL(debug_os_events){ - ProfileMomentFunction(); - REQ_DBG_VIEW(view); - view->mode = DBG_OS_EVENTS; -} - -#endif - COMMAND_DECL(close_minor_view){ ProfileMomentFunction(); REQ_VIEW(view); @@ -2574,16 +2541,6 @@ app_links_init(System_Functions *system, void *data, int size){ app_links.end_query_bar = external_end_query_bar; } -#if FRED_INTERNAL -internal void -setup_debug_commands(Command_Map *commands, Partition *part, Command_Map *parent){ - map_init(commands, part, 6, parent); - - map_add(commands, 'm', MDFR_NONE, command_debug_memory); - map_add(commands, 'o', MDFR_NONE, command_debug_os_events); -} -#endif - internal void setup_ui_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 32, parent); @@ -3131,7 +3088,6 @@ App_Init_Sig(app_init){ sizeof(Interactive_View), sizeof(Menu_View), sizeof(Config_View), - sizeof(Debug_View), }; { @@ -3280,10 +3236,7 @@ App_Init_Sig(app_init){ #endif setup_ui_commands(&vars->map_ui, &vars->mem.part, global); -#if FRED_INTERNAL - setup_debug_commands(&vars->map_debug, &vars->mem.part, global); -#endif - + vars->font_set = &target->font_set; font_set_init(vars->font_set, partition, 16, 5); diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 41d07e30..03bdf872 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -59,7 +59,6 @@ #include "4ed_menu_view.cpp" #include "4ed_app_settings.h" #include "4ed_config_view.cpp" -#include "4ed_debug_view.cpp" #include "4ed.cpp" // BOTTOM diff --git a/4ed_color_view.cpp b/4ed_color_view.cpp index fd604225..c60442e1 100644 --- a/4ed_color_view.cpp +++ b/4ed_color_view.cpp @@ -1702,18 +1702,24 @@ step_draw_library(System_Functions *system, Exchange *exchange, Mem_Options *mem case CV_MODE_IMPORT_WAIT: { Style *styles = color_view->inspecting_styles.styles; - Data file; - i32 file_max; + Data file = {}; + i32 file_max = 0; - i32 count, max; - max = ArrayCount(color_view->inspecting_styles.styles); + i32 count = 0; + i32 max = ArrayCount(color_view->inspecting_styles.styles); + + AllowLocal(styles); + AllowLocal(max); if (exchange_file_ready(exchange, color_view->import_file_id, &file.data, &file.size, &file_max)){ if (file.data){ - if (style_library_import(file, ui.fonts, styles, max, &count)) - color_view->mode = CV_MODE_IMPORT; - else color_view->mode = CV_MODE_LIBRARY; + if (0 /* && style_library_import(file, ui.fonts, styles, max, &count) */){ + color_view->mode = CV_MODE_IMPORT; + } + else{ + color_view->mode = CV_MODE_LIBRARY; + } color_view->inspecting_styles.count = count; } else{ @@ -1768,7 +1774,7 @@ step_draw_library(System_Functions *system, Exchange *exchange, Mem_Options *mem String str = make_string(data, 0, ui.hot_directory->string.size + 5); copy(&str, ui.hot_directory->string); append(&str, make_lit_string(".p4c")); - style_library_export(system, exchange, mem, &target->font_set, str.str, styles, export_count); + /*style_library_export(system, exchange, mem, &target->font_set, str.str, styles, export_count);*/ end_temp_memory(temp); color_view->mode = CV_MODE_LIBRARY; diff --git a/4ed_debug_view.cpp b/4ed_debug_view.cpp deleted file mode 100644 index b77930c1..00000000 --- a/4ed_debug_view.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 13.09.2015 - * - * Internal debug view for 4coder - * - */ - -// TOP -#if FRED_INTERNAL - -enum Debug_Mode{ - DBG_MEMORY, - DBG_OS_EVENTS -}; - -struct Dbg_Past_Key{ - Key_Event_Data key; - i32 frame_index; - bool8 modifiers[3]; -}; - -struct Debug_View{ - View view_base; - i16 font_id; - Debug_Mode mode; - Dbg_Past_Key past_keys[32]; - i32 past_key_count, past_key_pos; - i16 prev_mouse_wheel; -}; - -inline Debug_View* -view_to_debug_view(View *view){ - Assert(!view || view->type == VIEW_TYPE_DEBUG); - return (Debug_View*)view; -} - -internal i32 -draw_general_memory(Debug_View *view, i32_Rect rect, Render_Target *target, i32 y){ - i16 font_id = view->font_id; - i32 y_advance = get_font_info(&target->font_set, font_id)->height; - Bubble *sentinel = &view->view_base.mem->general.sentinel; - - for (Bubble *bubble = sentinel->next; - bubble != sentinel; - bubble = bubble->next){ - bool32 used = (bubble->flags & MEM_BUBBLE_USED) != 0; - u32 color; - if (used) color = 0xFFFFFFFF; - else color = 0xFF00FFFF; - - char str[256]; - String s = make_fixed_width_string(str); - if (used){ - switch (bubble->type){ - case BUBBLE_BUFFER: append(&s, "buffer "); break; - case BUBBLE_STARTS: append(&s, "starts "); break; - case BUBBLE_WIDTHS: append(&s, "widths "); break; - case BUBBLE_WRAPS: append(&s, "wraps "); break; - case BUBBLE_TOKENS: append(&s, "tokens "); break; - case BUBBLE_UNDO_STRING: append(&s, "undo string "); break; - case BUBBLE_UNDO: append(&s, "undo "); break; - default: append(&s, "unknown "); break; - } - } - else{ - append(&s, "unused "); - } - append_int_to_str(bubble->size, &s); - terminate_with_null(&s); - - draw_string(target, font_id, str, rect.x0, y, color); - y += y_advance; - - Bubble *next = bubble->next; - if (next != sentinel){ - u8 *end_ptr = (u8*)(bubble + 1) + bubble->size; - u8 *next_ptr = (u8*)(next); - if (end_ptr != next_ptr){ - color = 0xFFFF0000; - s = make_fixed_width_string(str); - append(&s, "discontinuity"); - terminate_with_null(&s); - - draw_string(target, font_id, str, rect.x0, y, color); - y += y_advance; - } - } - } - - return y; -} - -internal i32 -draw_system_memory(System_Functions *system, Debug_View *view, i32_Rect rect, - Render_Target *target, i32 y){ - i16 font_id = view->font_id; - i32 y_advance = get_font_info(&target->font_set, font_id)->height; - Bubble *sentinel = system->internal_sentinel(); - - for (Bubble *bubble = sentinel->next; - bubble != sentinel; - bubble = bubble->next){ - Sys_Bubble *sysb = (Sys_Bubble*)bubble; - u32 color = 0xFFFFFFFF; - - char str[256]; - String s = make_fixed_width_string(str); - - append(&s, sysb->file_name); - append(&s, " "); - append_int_to_str(sysb->line_number, &s); - append(&s, " "); - append_int_to_str(bubble->size, &s); - terminate_with_null(&s); - - draw_string(target, font_id, str, rect.x0, y, color); - - y += y_advance; - } - - return y; -} - -internal void -draw_background_threads(System_Functions *system, - Debug_View *view, i32_Rect rect, Render_Target *target){ - i32 pending; - bool8 running[4]; - system->internal_get_thread_states(BACKGROUND_THREADS, running, &pending); - - i32 box_size = 30; - - i32_Rect trect; - trect.x0 = rect.x1 - box_size; - trect.y0 = rect.y0; - trect.x1 = rect.x1; - trect.y1 = rect.y0 + box_size; - - u32 light = 0xFF606060; - for (i32 i = 0; i < 4; ++i){ - u32 color; - if (running[i]) color = 0xFF9090FF; - else color = 0xFF101010; - draw_rectangle(target, trect, color); - draw_rectangle_outline(target, trect, light); - trect.x0 -= box_size; - trect.x1 -= box_size; - } - - char str[256]; - String s = make_fixed_width_string(str); - append_int_to_str(pending, &s); - terminate_with_null(&s); - draw_string(target, view->font_id, str, trect.x1, trect.y1, light); -} - -struct Dbg_Modifier{ - char *name; - u8 modifier; -}; -internal void -draw_modifiers(Debug_View *view, Render_Target *target, - bool8 *modifiers, u32 on_color, u32 off_color, i32 *x, i32 y){ - persist Dbg_Modifier dm[] = { - {"CTRL", MDFR_CONTROL_INDEX}, - {"ALT", MDFR_ALT_INDEX}, - {"SHIFT", MDFR_SHIFT_INDEX} - }; - for (i32 i = 0; i < MDFR_INDEX_COUNT; ++i){ - Dbg_Modifier m = dm[i]; - u32 color; - - if (modifiers[m.modifier]) color = on_color; - else color = off_color; - - *x = draw_string(target, view->font_id, m.name, *x, y, color); - *x += 5; - } -} - -internal i32 -draw_key_event(Debug_View *view, Render_Target *target, - Dbg_Past_Key *key, i32 x, i32 y, u32 on_color, u32 off_color){ - draw_modifiers(view, target, key->modifiers, - on_color, off_color, &x, y); - - i16 font_id = view->font_id; - Render_Font *font = get_font_info(&target->font_set, font_id)->font; - - if (font && font->glyphs[key->key.character].exists){ - char c[2]; - c[0] = (char)key->key.character; - c[1] = 0; - x = draw_string(target, font_id, c, x, y, on_color); - } - else{ - char c[10] = {}; - String str = make_fixed_width_string(c); - append(&str, "\\"); - append_int_to_str(key->key.keycode, &str); - terminate_with_null(&str); - x = draw_string(target, font_id, c, x, y, on_color); - } - - return x; -} - -internal void -draw_os_events(Debug_View *view, i32_Rect rect, Render_Target *target, - Input_Summary *active_input){ - persist i32 max_past = ArrayCount(view->past_keys); - - i32 x, y, max_x, max_y; - x = rect.x0; - y = rect.y0; - - i16 font_id = view->font_id; - i32 line_height = get_font_info(&target->font_set, font_id)->height; - -#if 0 - draw_modifiers(view, target, active_input->keys.modifiers, - 0xFFFFFFFF, 0xFF444444, &x, y); -#endif - - max_x = x; - x = rect.x0; - y += line_height; - - for (i32 j = 0; j < view->past_key_count; ++j){ - Dbg_Past_Key *key = view->past_keys + j; - u32 on_color, off_color; - - switch ((view->past_key_pos - j - 1 + max_past*2) % max_past){ - case 0: on_color = 0xFFAAAAFF; off_color = 0xFF505088; break; - case 1: on_color = 0xFF9999CC; off_color = 0xFF404077; break; - case 2: on_color = 0xFF8888AA; off_color = 0xFF303066; break; - default: on_color = 0xFF888888; off_color = 0xFF303030; break; - } - - x = draw_key_event(view, target, key, x, y, on_color, off_color); - - if (max_x < x) max_x = x; - x = rect.x0; - y += line_height; - } - - i32_Rect mrect = rect; - mrect.x0 = max_x + 1; - - max_y = y; - x = mrect.x0; - y = mrect.y0; - - { - u32 color; - if (active_input->mouse.out_of_window){ - color = 0xFFFF0000; - draw_string(target, font_id, "OUT", x, y, color); - } - else{ - color = 0xFF008800; - draw_string(target, font_id, "IN", x, y, color); - } - y += line_height; - - char c[16]; - String s = make_fixed_width_string(c); - append_int_to_str(active_input->mouse.x, &s); - append(&s, ", "); - append_int_to_str(active_input->mouse.y, &s); - terminate_with_null(&s); - draw_string(target, font_id, c, x, y, color); - y += line_height; - - u32 btn_color; - if (active_input->mouse.l) btn_color = color; - else btn_color = 0xFF444444; - x = draw_string(target, font_id, "L ", x, y, btn_color); - - if (active_input->mouse.r) btn_color = color; - else btn_color = 0xFF444444; - x = draw_string(target, font_id, "R", x, y, btn_color); - - x = mrect.x0; - y += line_height; - - s = make_fixed_width_string(c); - append_int_to_str(view->prev_mouse_wheel, &s); - terminate_with_null(&s); - - if (active_input->mouse.wheel != 0) btn_color = color; - else btn_color = 0xFF444444; - draw_string(target, font_id, c, x, y, btn_color); - - y += line_height; - } -} - -internal i32 -draw_debug_view(System_Functions *system, - Debug_View *view, i32_Rect rect, Render_Target *target, - Input_Summary *active_input){ - i32 result = 0; - - draw_rectangle(target, rect, 0xFF000000); - - switch (view->mode){ - case DBG_MEMORY: - { - i32 y = rect.y0; - y = draw_general_memory(view, rect, target, y); - draw_rectangle(target, i32R(rect.x0, y, rect.x1, y+2), 0xFF222222); - y += 2; - y = draw_system_memory(system, view, rect, target, y); - }break; - case DBG_OS_EVENTS: - { - draw_os_events(view, rect, target, active_input); - }break; - } - return result; -} - -internal void -step_debug_view(Debug_View *view, i32_Rect rect, Render_Target *target, - Input_Summary *active_input){ - persist i32 max_past = ArrayCount(view->past_keys); - AllowLocal(max_past); -} - -internal -Do_View_Sig(do_debug_view){ - view->mouse_cursor_type = APP_MOUSE_CURSOR_ARROW; - Debug_View *debug_view = (Debug_View*)view; - i32 result = 0; - - switch (message){ - case VMSG_RESIZE: break; - case VMSG_STYLE_CHANGE: break; - case VMSG_STEP: step_debug_view(debug_view, rect, target, active_input); result = 1; break; - case VMSG_DRAW: draw_debug_view(system, debug_view, rect, target, active_input); break; - case VMSG_FREE: break; - } - - return result; -} - -internal Debug_View* -debug_view_init(View *view){ - Debug_View *result = (Debug_View*)view; - view->type = VIEW_TYPE_DEBUG; - view->do_view = do_debug_view; - return result; -} - -#endif -// BOTTOM diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 4bb66ec7..cd436c68 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -10,7 +10,7 @@ // TOP struct File_View_Mode{ - b8 rewrite; + i8 rewrite; }; struct Incremental_Search{ @@ -29,22 +29,13 @@ enum File_View_Widget_Type{ struct File_View_Widget{ UI_State state; File_View_Widget_Type type; - i32 height; + i32 height_; struct{ b32 undo_line; b32 history_line; } timeline; }; -enum Link_Type{ - link_result, - link_related, - link_error, - link_warning, - // never below this - link_type_count -}; - struct File_View{ View view_base; @@ -1451,6 +1442,8 @@ view_set_widget(File_View *view, File_View_Widget_Type type){ view->widget.type = type; } + +#if 0 inline i32 view_widget_height(File_View *view, i32 font_height){ i32 result = 0; @@ -1467,6 +1460,7 @@ view_widget_height(File_View *view, i32 font_height){ } return result; } +#endif inline i32_Rect view_widget_rect(File_View *view, i32 font_height){ @@ -1476,9 +1470,15 @@ view_widget_rect(File_View *view, i32 font_height){ if (view->file){ result.y0 = result.y0 + font_height + 2; } - result.y1 = result.y0 + view_widget_height(view, font_height); - return result; +#if 0 + if (view->file){ + result.y0 = result.y0 + font_height + 2; + } + result.y1 = result.y0 + view_widget_height(view, font_height); +#endif + + return(result); } #if FRED_SLOW @@ -2597,32 +2597,6 @@ struct Get_Link_Result{ i32 index; }; -internal u32* -style_get_link_color(Style *style, Link_Type type){ - u32 *result; - switch (type){ - case link_result: - result = &style->main.result_link_color; - break; - - case link_related: - result = &style->main.related_link_color; - break; - - case link_error: - result = &style->main.error_link_color; - break; - - case link_warning: - result = &style->main.warning_link_color; - break; - - default: - result = &style->main.default_color; - } - return result; -} - internal u32* style_get_color(Style *style, Cpp_Token token){ u32 *result; @@ -2791,13 +2765,62 @@ undo_shit(System_Functions *system, File_View *view, UI_State *state, UI_Layout } } +internal void +draw_file_view_queries(File_View *view, UI_State *state, UI_Layout *layout){ + Widget_ID wid; + Query_Slot *slot; + Query_Bar *bar; + i32 i = 1; + + for (slot = view->query_set.used_slot; slot != 0; slot = slot->next){ + wid = make_id(state, i++); + bar = slot->query_bar; + do_text_field(wid, state, layout, bar->prompt, bar->string); + } +} + internal i32 step_file_view(System_Functions *system, View *view_, i32_Rect rect, - b32 is_active, Input_Summary *user_input){ + b32 is_active, Input_Summary *user_input){ view_->mouse_cursor_type = APP_MOUSE_CURSOR_IBEAM; + i32 result = 0; File_View *view = (File_View*)view_; Editing_File *file = view->file; + + i32 widget_height = 0; + { + i32_Rect widg_rect = view_widget_rect(view, view->font_height); + + UI_State state = + ui_state_init(&view->widget.state, 0, user_input, + view->style, view->font_set, 0, 1); + + UI_Layout layout; + begin_layout(&layout, widg_rect); + + switch (view->widget.type){ + case FWIDG_NONE: + { + draw_file_view_queries(view, &state, &layout); + }break; + + case FWIDG_TIMELINES: + { + i32 scrub_max = view->scrub_max; + i32 undo_count = file->state.undo.undo.edit_count; + i32 redo_count = file->state.undo.redo.edit_count; + i32 total_count = undo_count + redo_count; + + undo_shit(system, view, &state, &layout, total_count, undo_count, scrub_max); + }break; + } + + widget_height = layout.y - widg_rect.y0; + if (ui_finish_frame(&view->widget.state, &state, &layout, widg_rect, 0, 0)){ + result = 1; + } + } if (file && !file->state.is_loading){ f32 line_height = (f32)view->font_height; @@ -2807,7 +2830,7 @@ step_file_view(System_Functions *system, View *view_, i32_Rect rect, i32 lowest_line = view_compute_lowest_line(view); f32 max_target_y = view_compute_max_target_y(lowest_line, (i32)line_height, max_y); f32 delta_y = 3.f*line_height; - f32 extra_top = (f32)view_widget_height(view, (i32)line_height); + f32 extra_top = (f32)widget_height; f32 taken_top_space = line_height + extra_top; if (user_input->mouse.y < rect.y0 + taken_top_space){ @@ -2887,38 +2910,11 @@ step_file_view(System_Functions *system, View *view_, i32_Rect rect, } result = 1; } - - if (!is_active) view_set_widget(view, FWIDG_NONE); - - // NOTE(allen): framely undo stuff - i32 scrub_max = view->scrub_max; - i32 undo_count = file->state.undo.undo.edit_count; - i32 redo_count = file->state.undo.redo.edit_count; - i32 total_count = undo_count + redo_count; - switch (view->widget.type){ - case FWIDG_TIMELINES: - { - i32_Rect widg_rect = view_widget_rect(view, view->font_height); - - UI_State state = - ui_state_init(&view->widget.state, 0, user_input, - view->style, view->font_set, 0, 1); - - UI_Layout layout; - begin_layout(&layout, widg_rect); - undo_shit(system, view, &state, &layout, total_count, undo_count, scrub_max); - - view->widget.height = layout.y - widg_rect.y0; - - if (ui_finish_frame(&view->widget.state, &state, &layout, widg_rect, 0, 0)){ - result = 1; - } - }break; - } + if (!is_active) view_set_widget(view, FWIDG_NONE); } - - return result; + + return(result); } internal void @@ -2975,20 +2971,6 @@ draw_file_bar(File_View *view, Interactive_Bar *bar, Render_Target *target){ } } -internal void -draw_file_view_queries(File_View *view, UI_State *state, UI_Layout *layout){ - Widget_ID wid; - Query_Slot *slot; - Query_Bar *bar; - i32 i = 1; - - for (slot = view->query_set.used_slot; slot != 0; slot = slot->next){ - wid = make_id(state, i++); - bar = slot->query_bar; - do_text_field(wid, state, layout, bar->prompt, bar->string); - } -} - internal i32 draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *target){ Editing_File *file = view->file; @@ -3157,58 +3139,66 @@ draw_file_loaded(File_View *view, i32_Rect rect, b32 is_active, Render_Target *t } internal i32 -draw_file_view(View *view_, i32_Rect rect, bool32 is_active, Render_Target *target){ +draw_file_view(View *view_, i32_Rect rect, b32 is_active, Render_Target *target){ File_View *view = (File_View*)view_; i32 result = 0; - + + i32 widget_height = 0; + { + //UI_Style ui_style = get_ui_style_upper(view->style); + + i32_Rect widg_rect = view_widget_rect(view, view->font_height); + + //draw_rectangle(target, widg_rect, ui_style.dark); + //draw_rectangle_outline(target, widg_rect, ui_style.dim); + + UI_State state = + ui_state_init(&view->widget.state, target, 0, + view->style, view->font_set, 0, 0); + + UI_Layout layout; + begin_layout(&layout, widg_rect); + + switch (view->widget.type){ + case FWIDG_NONE: + { + draw_file_view_queries(view, &state, &layout); + }break; + + case FWIDG_TIMELINES: + { + if (view->file){ + Editing_File *file = view->file; + i32 undo_count = file->state.undo.undo.edit_count; + i32 redo_count = file->state.undo.redo.edit_count; + i32 total_count = undo_count + redo_count; + undo_shit(0, view, &state, &layout, total_count, undo_count, 0); + } + else{ + view->widget.type = FWIDG_NONE; + } + }break; + } + + widget_height = layout.y - widg_rect.y0; + ui_finish_frame(&view->widget.state, &state, &layout, widg_rect, 0, 0); + } + if (view->file){ Interactive_Bar bar; draw_file_setup_bar(view->style, view->font_height, &bar, &rect); - + if (file_is_ready(view->file)){ + rect.y0 += widget_height; + target->push_clip(target, rect); + rect.y0 -= widget_height; result = draw_file_loaded(view, rect, is_active, target); + target->pop_clip(target); } draw_file_bar(view, &bar, target); } - UI_Style ui_style = get_ui_style_upper(view->style); - - i32_Rect widg_rect = view_widget_rect(view, view->font_height); - - draw_rectangle(target, widg_rect, ui_style.dark); - draw_rectangle_outline(target, widg_rect, ui_style.dim); - - UI_State state = - ui_state_init(&view->widget.state, target, 0, - view->style, view->font_set, 0, 0); - - UI_Layout layout; - begin_layout(&layout, widg_rect); - - switch (view->widget.type){ - case FWIDG_NONE: - { - draw_file_view_queries(view, &state, &layout); - }break; - - case FWIDG_TIMELINES: - { - if (view->file){ - Editing_File *file = view->file; - i32 undo_count = file->state.undo.undo.edit_count; - i32 redo_count = file->state.undo.redo.edit_count; - i32 total_count = undo_count + redo_count; - undo_shit(0, view, &state, &layout, total_count, undo_count, 0); - } - else{ - view->widget.type = FWIDG_NONE; - } - }break; - } - - ui_finish_frame(&view->widget.state, &state, &layout, widg_rect, 0, 0); - return (result); } diff --git a/4ed_layout.cpp b/4ed_layout.cpp index ad79d2ce..e9d60591 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -47,7 +47,6 @@ enum View_Type{ VIEW_TYPE_NONE, VIEW_TYPE_FILE, VIEW_TYPE_COLOR, - VIEW_TYPE_DEBUG, VIEW_TYPE_INTERACTIVE, VIEW_TYPE_MENU, VIEW_TYPE_CONFIG diff --git a/4ed_rendering.h b/4ed_rendering.h index f3e6f3e3..b0fbcccd 100644 --- a/4ed_rendering.h +++ b/4ed_rendering.h @@ -47,14 +47,6 @@ struct Render_Font{ i32 tex_width, tex_height; }; -struct Render_Target; - -#define Draw_Push_Clip_Sig(name) void name(Render_Target *target, i32_Rect clip_box) -typedef Draw_Push_Clip_Sig(Draw_Push_Clip); - -#define Draw_Pop_Clip_Sig(name) void name(Render_Target *target) -typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip); - enum Render_Piece_Type{ piece_type_rectangle, piece_type_outline, @@ -108,6 +100,14 @@ struct Render_Piece_Combined{ }; }; +struct Render_Target; + +#define Draw_Push_Clip_Sig(name) void name(Render_Target *target, i32_Rect clip_box) +typedef Draw_Push_Clip_Sig(Draw_Push_Clip); + +#define Draw_Pop_Clip_Sig(name) void name(Render_Target *target) +typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip); + #define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece) typedef Draw_Push_Piece_Sig(Draw_Push_Piece); diff --git a/4ed_style.cpp b/4ed_style.cpp index 2d5cda45..ab0fc20e 100644 --- a/4ed_style.cpp +++ b/4ed_style.cpp @@ -1,639 +1,223 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 28.08.2015 - * - * Styles for 4coder - * - */ - -// TOP - -struct P4C_Page_Header{ - i32 size; - u32 id; -}; - -#define P4C_STYLE_ID COMPOSE_ID('s', 't', 'y', 'l') - -struct Style_Page_Header{ - i32 version; - i32 count; -}; - -struct Style_Main_Data_v1{ - u32 back_color; - u32 margin_color; - u32 margin_active_color; - u32 cursor_color; - u32 at_cursor_color; - u32 highlight_color; - u32 at_highlight_color; - u32 mark_color; - u32 default_color; - u32 comment_color; - u32 keyword_color; - u32 constant_color; - u32 special_character_color; - u32 highlight_junk_color; - u32 highlight_white_color; - u32 paste_color; - Interactive_Style file_info_style; -}; - -struct Style_File_Format_v1{ - i32 name_size; - char name[24]; - i32 font_name_size; - char font_name[24]; - Style_Main_Data_v1 main; -}; - -struct Style_Main_Data_v2{ - u32 back_color; - u32 margin_color; - u32 margin_active_color; - u32 cursor_color; - u32 at_cursor_color; - u32 highlight_color; - u32 at_highlight_color; - u32 mark_color; - u32 default_color; - u32 comment_color; - u32 keyword_color; - u32 str_constant_color; - u32 char_constant_color; - u32 int_constant_color; - u32 float_constant_color; - u32 bool_constant_color; - u32 preproc_color; - u32 include_color; - u32 special_character_color; - u32 highlight_junk_color; - u32 highlight_white_color; - u32 paste_color; - Interactive_Style file_info_style; -}; - -struct Style_File_Format_v2{ - i32 name_size; - char name[24]; - i32 font_name_size; - char font_name[24]; - Style_Main_Data_v2 main; -}; - -struct Style_Main_Data_v3{ - u32 back_color; - u32 margin_color; - u32 margin_hover_color; - u32 margin_active_color; - u32 cursor_color; - u32 at_cursor_color; - u32 highlight_color; - u32 at_highlight_color; - u32 mark_color; - u32 default_color; - u32 comment_color; - u32 keyword_color; - u32 str_constant_color; - u32 char_constant_color; - u32 int_constant_color; - u32 float_constant_color; - u32 bool_constant_color; - u32 preproc_color; - u32 include_color; - u32 special_character_color; - u32 highlight_junk_color; - u32 highlight_white_color; - u32 paste_color; - Interactive_Style file_info_style; -}; - -struct Style_File_Format_v3{ - i32 name_size; - char name[24]; - i32 font_name_size; - char font_name[24]; - Style_Main_Data_v3 main; -}; - -struct Style_Main_Data{ - u32 back_color; - u32 margin_color; - u32 margin_hover_color; - u32 margin_active_color; - u32 cursor_color; - u32 at_cursor_color; - u32 highlight_color; - u32 at_highlight_color; - u32 mark_color; - u32 default_color; - u32 comment_color; - u32 keyword_color; - u32 str_constant_color; - u32 char_constant_color; - u32 int_constant_color; - u32 float_constant_color; - u32 bool_constant_color; - u32 preproc_color; - u32 include_color; - u32 special_character_color; - u32 highlight_junk_color; - u32 highlight_white_color; - u32 paste_color; - u32 undo_color; - u32 result_link_color; - u32 related_link_color; - u32 error_link_color; - u32 warning_link_color; - Interactive_Style file_info_style; -}; - -struct Style_File_Format_v4{ - i32 name_size; - char name[24]; - i32 font_name_size; - char font_name[24]; - Style_Main_Data main; -}; - -enum Style_Color_Tag{ - STAG_BAR_COLOR, - STAG_BAR_ACTIVE_COLOR, - STAG_BAR_BASE_COLOR, - STAG_BAR_POP1_COLOR, - STAG_BAR_POP2_COLOR, - STAG_BACK_COLOR, - STAG_MARGIN_COLOR, - STAG_MARGIN_HOVER_COLOR, - STAG_MARGIN_ACTIVE_COLOR, - STAG_CURSOR_COLOR, - STAG_AT_CURSOR_COLOR, - STAG_HIGHLIGHT_COLOR, - STAG_AT_HIGHLIGHT_COLOR, - STAG_MARK_COLOR, - STAG_DEFAULT_COLOR, - STAG_COMMENT_COLOR, - STAG_KEYWORD_COLOR, - STAG_STR_CONSTANT_COLOR, - STAG_CHAR_CONSTANT_COLOR, - STAG_INT_CONSTANT_COLOR, - STAG_FLOAT_CONSTANT_COLOR, - STAG_BOOL_CONSTANT_COLOR, - STAG_PREPROC_COLOR, - STAG_INCLUDE_COLOR, - STAG_SPECIAL_CHARACTER_COLOR, - STAG_HIGHLIGHT_JUNK_COLOR, - STAG_HIGHLIGHT_WHITE_COLOR, - STAG_PASTE_COLOR, - STAG_UNDO_COLOR, - STAG_NEXT_UNDO_COLOR, - STAG_RESULT_LINK_COLOR, - STAG_RELATED_LINK_COLOR, - STAG_ERROR_LINK_COLOR, - STAG_WARNING_LINK_COLOR, - // never below this - STAG_COUNT -}; - -struct Style_Color_Specifier{ - u32 tag; - u32 color; -}; - -struct Style_File_Format{ - i32 name_size; - char name[24]; - i32 font_name_size; - char font_name[24]; - - i32 color_specifier_count; -}; - -struct Style{ - char name_[24]; - String name; - Style_Main_Data main; - b32 font_changed; - i16 font_id; -}; - -struct Style_Library{ - Style styles[64]; - i32 count, max; -}; - -internal void -style_copy(Style *dst, Style *src){ - *dst = *src; - dst->name.str = dst->name_; -} - -internal void -style_set_name(Style *style, String name){ - i32 count = ArrayCount(style->name_); - style->name_[count - 1] = 0; - style->name = make_string(style->name_, 0, count - 1); - copy(&style->name, name); -} - -internal void -style_form_convert(Style_File_Format_v2 *o, Style_File_Format_v1 *i){ - o->name_size = i->name_size; - memcpy(o->name, i->name, i->name_size); - o->font_name_size = i->font_name_size; - memcpy(o->font_name, i->font_name, i->font_name_size); - - o->main.back_color = i->main.back_color; - o->main.margin_color = i->main.margin_color; - o->main.margin_active_color = i->main.margin_active_color; - o->main.cursor_color = i->main.cursor_color; - o->main.at_cursor_color = i->main.at_cursor_color; - o->main.highlight_color = i->main.highlight_color; - o->main.at_highlight_color = i->main.at_highlight_color; - o->main.mark_color = i->main.mark_color; - o->main.default_color = i->main.default_color; - o->main.comment_color = i->main.comment_color; - o->main.keyword_color = i->main.keyword_color; - o->main.str_constant_color = i->main.constant_color; - o->main.char_constant_color = i->main.constant_color; - o->main.int_constant_color = i->main.constant_color; - o->main.float_constant_color = i->main.constant_color; - o->main.bool_constant_color = i->main.constant_color; - o->main.include_color = i->main.constant_color; - o->main.preproc_color = i->main.default_color; - o->main.special_character_color = i->main.special_character_color; - o->main.highlight_junk_color = i->main.highlight_junk_color; - o->main.highlight_white_color = i->main.highlight_white_color; - o->main.paste_color = i->main.paste_color; - o->main.file_info_style = i->main.file_info_style; -} - -internal void -style_form_convert(Style_File_Format_v3 *o, Style_File_Format_v2 *i){ - o->name_size = i->name_size; - memcpy(o->name, i->name, i->name_size); - o->font_name_size = i->font_name_size; - memcpy(o->font_name, i->font_name, i->font_name_size); - - o->main.back_color = i->main.back_color; - o->main.margin_color = i->main.margin_color; - o->main.margin_active_color = i->main.margin_active_color; - - o->main.margin_hover_color = color_blend(i->main.margin_color, .5f, i->main.margin_active_color); - - o->main.cursor_color = i->main.cursor_color; - o->main.at_cursor_color = i->main.at_cursor_color; - o->main.highlight_color = i->main.highlight_color; - o->main.at_highlight_color = i->main.at_highlight_color; - o->main.mark_color = i->main.mark_color; - o->main.default_color = i->main.default_color; - o->main.comment_color = i->main.comment_color; - o->main.keyword_color = i->main.keyword_color; - o->main.str_constant_color = i->main.str_constant_color; - o->main.char_constant_color = i->main.char_constant_color; - o->main.int_constant_color = i->main.int_constant_color; - o->main.float_constant_color = i->main.float_constant_color; - o->main.bool_constant_color = i->main.bool_constant_color; - o->main.include_color = i->main.include_color; - o->main.preproc_color = i->main.preproc_color; - o->main.special_character_color = i->main.special_character_color; - o->main.highlight_junk_color = i->main.highlight_junk_color; - o->main.highlight_white_color = i->main.highlight_white_color; - o->main.paste_color = i->main.paste_color; - o->main.file_info_style = i->main.file_info_style; -} - -internal void -style_form_convert(Style_File_Format_v4 *o, Style_File_Format_v3 *i){ - o->name_size = i->name_size; - memcpy(o->name, i->name, i->name_size); - o->font_name_size = i->font_name_size; - memcpy(o->font_name, i->font_name, i->font_name_size); - - o->main.back_color = i->main.back_color; - o->main.margin_color = i->main.margin_color; - o->main.margin_hover_color = i->main.margin_hover_color; - o->main.margin_active_color = i->main.margin_active_color; - - o->main.cursor_color = i->main.cursor_color; - o->main.at_cursor_color = i->main.at_cursor_color; - o->main.highlight_color = i->main.highlight_color; - o->main.at_highlight_color = i->main.at_highlight_color; - o->main.mark_color = i->main.mark_color; - o->main.default_color = i->main.default_color; - o->main.comment_color = i->main.comment_color; - o->main.keyword_color = i->main.keyword_color; - o->main.str_constant_color = i->main.str_constant_color; - o->main.char_constant_color = i->main.char_constant_color; - o->main.int_constant_color = i->main.int_constant_color; - o->main.float_constant_color = i->main.float_constant_color; - o->main.bool_constant_color = i->main.bool_constant_color; - o->main.include_color = i->main.include_color; - o->main.preproc_color = i->main.preproc_color; - o->main.special_character_color = i->main.special_character_color; - o->main.highlight_junk_color = i->main.highlight_junk_color; - o->main.highlight_white_color = i->main.highlight_white_color; - o->main.paste_color = i->main.paste_color; - o->main.undo_color = i->main.paste_color ^ 0x00FFFFFF; - o->main.file_info_style = i->main.file_info_style; - o->main.file_info_style.bar_active_color = i->main.file_info_style.bar_color; -} - -inline u32* -style_index_by_tag(Style *s, u32 tag){ - u32 *result = 0; - switch (tag){ - case STAG_BAR_COLOR: result = &s->main.file_info_style.bar_color; break; - case STAG_BAR_ACTIVE_COLOR: result = &s->main.file_info_style.bar_active_color; break; - case STAG_BAR_BASE_COLOR: result = &s->main.file_info_style.base_color; break; - case STAG_BAR_POP1_COLOR: result = &s->main.file_info_style.pop1_color; break; - case STAG_BAR_POP2_COLOR: result = &s->main.file_info_style.pop2_color; break; - - case STAG_BACK_COLOR: result = &s->main.back_color; break; - case STAG_MARGIN_COLOR: result = &s->main.margin_color; break; - case STAG_MARGIN_HOVER_COLOR: result = &s->main.margin_hover_color; break; - case STAG_MARGIN_ACTIVE_COLOR: result = &s->main.margin_active_color; break; - - case STAG_CURSOR_COLOR: result = &s->main.cursor_color; break; - case STAG_AT_CURSOR_COLOR: result = &s->main.at_cursor_color; break; - case STAG_HIGHLIGHT_COLOR: result = &s->main.highlight_color; break; - case STAG_AT_HIGHLIGHT_COLOR: result = &s->main.at_highlight_color; break; - case STAG_MARK_COLOR: result = &s->main.mark_color; break; - - case STAG_DEFAULT_COLOR: result = &s->main.default_color; break; - case STAG_COMMENT_COLOR: result = &s->main.comment_color; break; - case STAG_KEYWORD_COLOR: result = &s->main.keyword_color; break; - case STAG_STR_CONSTANT_COLOR: result = &s->main.str_constant_color; break; - case STAG_CHAR_CONSTANT_COLOR: result = &s->main.char_constant_color; break; - case STAG_INT_CONSTANT_COLOR: result = &s->main.int_constant_color; break; - case STAG_FLOAT_CONSTANT_COLOR: result = &s->main.float_constant_color; break; - case STAG_BOOL_CONSTANT_COLOR: result = &s->main.bool_constant_color; break; - - case STAG_PREPROC_COLOR: result = &s->main.preproc_color; break; - case STAG_INCLUDE_COLOR: result = &s->main.include_color; break; - - case STAG_SPECIAL_CHARACTER_COLOR: result = &s->main.special_character_color; break; - - case STAG_HIGHLIGHT_JUNK_COLOR: result = &s->main.highlight_junk_color; break; - case STAG_HIGHLIGHT_WHITE_COLOR: result = &s->main.highlight_white_color; break; - - case STAG_PASTE_COLOR: result = &s->main.paste_color; break; - case STAG_UNDO_COLOR: result = &s->main.undo_color; break; - - case STAG_RESULT_LINK_COLOR: result = &s->main.result_link_color; break; - case STAG_RELATED_LINK_COLOR: result = &s->main.related_link_color; break; - case STAG_ERROR_LINK_COLOR: result = &s->main.error_link_color; break; - case STAG_WARNING_LINK_COLOR: result = &s->main.warning_link_color; break; - } - return result; -} - -internal Style_File_Format* -style_format_for_use(Font_Set *fonts, Style *out, Style_File_Format *style){ - out->name = make_string(out->name_, 0, ArrayCount(out->name_) - 1); - out->name_[ArrayCount(out->name_) - 1] = 0; - copy(&out->name, style->name); - if (!font_set_extract(fonts, - make_string(style->font_name, style->font_name_size), - &out->font_id)){ - out->font_id = 0; - } - - i32 spec_count = style->color_specifier_count; - Style_Color_Specifier *spec = (Style_Color_Specifier*)(style + 1); - - for (i32 i = 0; i < spec_count; ++i, ++spec){ - u32 *color = style_index_by_tag(out, spec->tag); - if (color) *color = spec->color; - } - -#if 0 // TODO(allen): when new colors are introduced, derive them here. - for (u32 i = 0; i < STAG_COUNT; ++i){ - u32 *color = style_index_by_tag(out, i); - if (color && (*color >> 24) == 0){ - switch (i){ - } - } - } -#endif - - return (Style_File_Format*)(spec); -} - -inline void -style_format_for_use(Font_Set *fonts, Style *out, Style_File_Format_v4 *style){ - out->name = make_string(out->name_, 0, ArrayCount(out->name_) - 1); - out->name_[ArrayCount(out->name_) - 1] = 0; - copy(&out->name, style->name); - if (!font_set_extract(fonts, - make_string(style->font_name, style->font_name_size), - &out->font_id)){ - out->font_id = 0; - } - out->main = style->main; -} - -inline void -style_format_for_use(Font_Set *fonts, Style *out, Style_File_Format_v1 *style){ - Style_File_Format_v2 form2; - Style_File_Format_v3 form3; - Style_File_Format_v4 form; - style_form_convert(&form2, style); - style_form_convert(&form3, &form2); - style_form_convert(&form, &form3); - style_format_for_use(fonts, out, &form); -} - -inline void -style_format_for_use(Font_Set *fonts, Style *out, Style_File_Format_v2 *style){ - Style_File_Format_v3 form3; - Style_File_Format_v4 form; - style_form_convert(&form3, style); - style_form_convert(&form, &form3); - style_format_for_use(fonts, out, &form); -} - -inline void -style_format_for_use(Font_Set *fonts, Style *out, Style_File_Format_v3 *style){ - Style_File_Format_v4 form; - style_form_convert(&form, style); - style_format_for_use(fonts, out, &form); -} - -internal b32 -style_library_import(Data file, Font_Set *fonts, Style *out, i32 max, - i32 *count_opt, i32 *total_opt = 0){ - b32 result = 1; - Style_Page_Header *h = 0; - - if (!file.data){ - result = 0; - } - else{ - void *cursor = file.data; - i32 to_read = 0; - - { - P4C_Page_Header *h = (P4C_Page_Header*)cursor; - if (h->id != P4C_STYLE_ID){ - result = 0; - goto early_exit; - } - cursor = h+1; - } - - h = (Style_Page_Header*)cursor; - to_read = h->count; - cursor = h+1; - - if (total_opt) *total_opt = to_read; - if (to_read > max) to_read = max; - if (count_opt) *count_opt = to_read; - - switch (h->version){ - case 1: - { - Style_File_Format_v1 *in = (Style_File_Format_v1*)cursor; - for (i32 i = 0; i < to_read; ++i){ - style_format_for_use(fonts, out++, in++); - } - }break; - case 2: - { - Style_File_Format_v2 *in = (Style_File_Format_v2*)cursor; - for (i32 i = 0; i < to_read; ++i){ - style_format_for_use(fonts, out++, in++); - } - }break; - - case 3: - { - Style_File_Format_v3 *in = (Style_File_Format_v3*)cursor; - for (i32 i = 0; i < to_read; ++i){ - style_format_for_use(fonts, out++, in++); - } - }break; - case 4: - { - Style_File_Format *in = (Style_File_Format*)cursor; - for (i32 i = 0; i < to_read; ++i){ - in = style_format_for_use(fonts, out++, in); - } - }break; - - default: result = 0; break; - } - -early_exit:; - } - - return result; -} - -#if 0 -internal b32 -style_library_import(System_Functions *system, - char *filename, Font_Set *fonts, Style *out, i32 max, - i32 *count_opt, i32 *total_opt = 0){ - b32 result; - Data file = system->load_file(filename); - result = style_library_import(file, fonts, out, max, count_opt, total_opt); - system->free_file(file); - - return result; -} -#endif - -internal b32 -style_library_add(Style_Library *library, Style *style){ - b32 result = 0; - i32 count = library->count; - String my_name = style->name; - Style *ostyle = library->styles; - Style *out = 0; - // TODO(allen): hashtable for name lookup? - for (i32 i = 0; i < count; ++i, ++ostyle){ - if (match(my_name, ostyle->name)){ - out = ostyle; - break; - } - } - if (!out && count < library->max){ - out = library->styles + library->count++; - } - if (out){ - style_copy(out, style); - result = 1; - } - return result; -} - -internal Style_File_Format* -style_format_for_file(Font_Set *set, Style *style, Style_File_Format *out){ - out->name_size = style->name.size; - memcpy(out->name, style->name.str, ArrayCount(out->name)); - - String font_name = get_font_info(set, style->font_id)->name; - out->font_name_size = font_name.size; - memcpy(out->font_name, font_name.str, font_name.size); - - Style_Color_Specifier *spec = (Style_Color_Specifier*)(out + 1); - i32 count = 0; - - for (u32 i = 0; i < STAG_COUNT; ++i){ - u32 *color = style_index_by_tag(style, i); - if (color){ - spec->tag = i; - spec->color = *color; - ++count; - ++spec; - } - } - out->color_specifier_count = count; - - return (Style_File_Format*)spec; -} - -internal void -style_library_export(System_Functions *system, Exchange *exchange, Mem_Options *mem, - Font_Set *set, char *filename, Style **styles, i32 count){ - i32 size = count*(sizeof(Style_File_Format) + STAG_COUNT*sizeof(Style_Color_Specifier)) + - sizeof(P4C_Page_Header) + sizeof(Style_Page_Header); - Temp_Memory temp = begin_temp_memory(&mem->part); - void *data = push_block(&mem->part, size); - void *cursor = data; - - { - P4C_Page_Header *h = (P4C_Page_Header*)cursor; - h->size = size - sizeof(P4C_Page_Header); - h->id = P4C_STYLE_ID; - cursor = h+1; - } - - { - Style_Page_Header *h = (Style_Page_Header*)cursor; - h->version = 4; - h->count = count; - cursor = h+1; - } - - Style_File_Format *out = (Style_File_Format*)cursor; - Style **in = styles; - for (i32 i = 0; i < count; ++i){ - out = style_format_for_file(set, *in++, out); - } - - int filename_len = str_size(filename); - exchange_save_file(exchange, filename, filename_len, - (byte*)data, size, size); -#if 0 - system->save_file(filename, data, size); -#endif - - end_temp_memory(temp); -} - -// BOTTOM - +/* + * Mr. 4th Dimention - Allen Webster + * + * 28.08.2015 + * + * Styles for 4coder + * + */ + +// TOP + +struct Style_Main_Data{ + u32 back_color; + u32 margin_color; + u32 margin_hover_color; + u32 margin_active_color; + u32 cursor_color; + u32 at_cursor_color; + u32 highlight_color; + u32 at_highlight_color; + u32 mark_color; + u32 default_color; + u32 comment_color; + u32 keyword_color; + u32 str_constant_color; + u32 char_constant_color; + u32 int_constant_color; + u32 float_constant_color; + u32 bool_constant_color; + u32 preproc_color; + u32 include_color; + u32 special_character_color; + u32 highlight_junk_color; + u32 highlight_white_color; + u32 paste_color; + u32 undo_color; + Interactive_Style file_info_style; +}; + +struct Style_File_Format_v4{ + i32 name_size; + char name[24]; + i32 font_name_size; + char font_name[24]; + Style_Main_Data main; +}; + +enum Style_Color_Tag{ + STAG_BAR_COLOR, + STAG_BAR_ACTIVE_COLOR, + STAG_BAR_BASE_COLOR, + STAG_BAR_POP1_COLOR, + STAG_BAR_POP2_COLOR, + STAG_BACK_COLOR, + STAG_MARGIN_COLOR, + STAG_MARGIN_HOVER_COLOR, + STAG_MARGIN_ACTIVE_COLOR, + STAG_CURSOR_COLOR, + STAG_AT_CURSOR_COLOR, + STAG_HIGHLIGHT_COLOR, + STAG_AT_HIGHLIGHT_COLOR, + STAG_MARK_COLOR, + STAG_DEFAULT_COLOR, + STAG_COMMENT_COLOR, + STAG_KEYWORD_COLOR, + STAG_STR_CONSTANT_COLOR, + STAG_CHAR_CONSTANT_COLOR, + STAG_INT_CONSTANT_COLOR, + STAG_FLOAT_CONSTANT_COLOR, + STAG_BOOL_CONSTANT_COLOR, + STAG_PREPROC_COLOR, + STAG_INCLUDE_COLOR, + STAG_SPECIAL_CHARACTER_COLOR, + STAG_HIGHLIGHT_JUNK_COLOR, + STAG_HIGHLIGHT_WHITE_COLOR, + STAG_PASTE_COLOR, + STAG_UNDO_COLOR, + STAG_NEXT_UNDO_COLOR, + STAG_RESULT_LINK_COLOR, + STAG_RELATED_LINK_COLOR, + STAG_ERROR_LINK_COLOR, + STAG_WARNING_LINK_COLOR, + // never below this + STAG_COUNT +}; + +struct Style_Color_Specifier{ + u32 tag; + u32 color; +}; + +struct Style_File_Format{ + i32 name_size; + char name[24]; + i32 font_name_size; + char font_name[24]; + + i32 color_specifier_count; +}; + +struct Style{ + char name_[24]; + String name; + Style_Main_Data main; + b32 font_changed; + i16 font_id; +}; + +struct Style_Library{ + Style styles[64]; + i32 count, max; +}; + +internal void +style_copy(Style *dst, Style *src){ + *dst = *src; + dst->name.str = dst->name_; +} + +internal void +style_set_name(Style *style, String name){ + i32 count = ArrayCount(style->name_); + style->name_[count - 1] = 0; + style->name = make_string(style->name_, 0, count - 1); + copy(&style->name, name); +} + +inline u32* +style_index_by_tag(Style *s, u32 tag){ + u32 *result = 0; + switch (tag){ + case STAG_BAR_COLOR: result = &s->main.file_info_style.bar_color; break; + case STAG_BAR_ACTIVE_COLOR: result = &s->main.file_info_style.bar_active_color; break; + case STAG_BAR_BASE_COLOR: result = &s->main.file_info_style.base_color; break; + case STAG_BAR_POP1_COLOR: result = &s->main.file_info_style.pop1_color; break; + case STAG_BAR_POP2_COLOR: result = &s->main.file_info_style.pop2_color; break; + + case STAG_BACK_COLOR: result = &s->main.back_color; break; + case STAG_MARGIN_COLOR: result = &s->main.margin_color; break; + case STAG_MARGIN_HOVER_COLOR: result = &s->main.margin_hover_color; break; + case STAG_MARGIN_ACTIVE_COLOR: result = &s->main.margin_active_color; break; + + case STAG_CURSOR_COLOR: result = &s->main.cursor_color; break; + case STAG_AT_CURSOR_COLOR: result = &s->main.at_cursor_color; break; + case STAG_HIGHLIGHT_COLOR: result = &s->main.highlight_color; break; + case STAG_AT_HIGHLIGHT_COLOR: result = &s->main.at_highlight_color; break; + case STAG_MARK_COLOR: result = &s->main.mark_color; break; + + case STAG_DEFAULT_COLOR: result = &s->main.default_color; break; + case STAG_COMMENT_COLOR: result = &s->main.comment_color; break; + case STAG_KEYWORD_COLOR: result = &s->main.keyword_color; break; + case STAG_STR_CONSTANT_COLOR: result = &s->main.str_constant_color; break; + case STAG_CHAR_CONSTANT_COLOR: result = &s->main.char_constant_color; break; + case STAG_INT_CONSTANT_COLOR: result = &s->main.int_constant_color; break; + case STAG_FLOAT_CONSTANT_COLOR: result = &s->main.float_constant_color; break; + case STAG_BOOL_CONSTANT_COLOR: result = &s->main.bool_constant_color; break; + + case STAG_PREPROC_COLOR: result = &s->main.preproc_color; break; + case STAG_INCLUDE_COLOR: result = &s->main.include_color; break; + + case STAG_SPECIAL_CHARACTER_COLOR: result = &s->main.special_character_color; break; + + case STAG_HIGHLIGHT_JUNK_COLOR: result = &s->main.highlight_junk_color; break; + case STAG_HIGHLIGHT_WHITE_COLOR: result = &s->main.highlight_white_color; break; + + case STAG_PASTE_COLOR: result = &s->main.paste_color; break; + case STAG_UNDO_COLOR: result = &s->main.undo_color; break; + } + return result; +} + +internal b32 +style_library_add(Style_Library *library, Style *style){ + b32 result = 0; + i32 count = library->count; + String my_name = style->name; + Style *ostyle = library->styles; + Style *out = 0; + // TODO(allen): hashtable for name lookup? + for (i32 i = 0; i < count; ++i, ++ostyle){ + if (match(my_name, ostyle->name)){ + out = ostyle; + break; + } + } + if (!out && count < library->max){ + out = library->styles + library->count++; + } + if (out){ + style_copy(out, style); + result = 1; + } + return result; +} + +internal Style_File_Format* +style_format_for_file(Font_Set *set, Style *style, Style_File_Format *out){ + out->name_size = style->name.size; + memcpy(out->name, style->name.str, ArrayCount(out->name)); + + String font_name = get_font_info(set, style->font_id)->name; + out->font_name_size = font_name.size; + memcpy(out->font_name, font_name.str, font_name.size); + + Style_Color_Specifier *spec = (Style_Color_Specifier*)(out + 1); + i32 count = 0; + + for (u32 i = 0; i < STAG_COUNT; ++i){ + u32 *color = style_index_by_tag(style, i); + if (color){ + spec->tag = i; + spec->color = *color; + ++count; + ++spec; + } + } + out->color_specifier_count = count; + + return (Style_File_Format*)spec; +} + +// BOTTOM +