simplifying the file view widget

This commit is contained in:
Allen Webster 2016-03-01 02:06:12 -05:00
parent bbc737f7c5
commit dc5d0eceac
8 changed files with 361 additions and 1189 deletions

47
4ed.cpp
View File

@ -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,9 +3236,6 @@ 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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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,14 +2765,63 @@ 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;
f32 cursor_y = view_get_cursor_y(view);
@ -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){
@ -2889,36 +2912,9 @@ step_file_view(System_Functions *system, View *view_, i32_Rect rect,
}
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;
}
}
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);
}

View File

@ -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

View File

@ -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);

View File

@ -9,115 +9,6 @@
// 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;
@ -143,10 +34,6 @@ struct Style_Main_Data{
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;
};
@ -238,109 +125,6 @@ style_set_name(Style *style, String name){
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;
@ -381,171 +165,10 @@ style_index_by_tag(Style *s, u32 tag){
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;
@ -596,44 +219,5 @@ style_format_for_file(Font_Set *set, Style *style, Style_File_Format *out){
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