file bar is GUI/scroll rule/etc

master
Allen Webster 2016-03-02 19:50:04 -05:00
parent d2c21a934a
commit 2ca78a6bf8
10 changed files with 5749 additions and 5659 deletions

View File

@ -407,6 +407,66 @@ CUSTOM_COMMAND_SIG(reverse_search){
isearch(app, 1);
}
CUSTOM_COMMAND_SIG(rewrite_as_single_caps){
File_View_Summary view;
Buffer_Summary buffer;
Range range;
String string;
int is_first, i;
exec_command(app, cmdid_seek_token_left);
view = app->get_active_file_view(app);
range.min = view.cursor.pos;
exec_command(app, cmdid_seek_token_right);
app->refresh_file_view(app, &view);
range.max = view.cursor.pos;
string.str = (char*)app->memory;
string.size = range.max - range.min;
assert(string.size < app->memory_size);
buffer = app->get_buffer(app, view.buffer_id);
app->buffer_read_range(app, &buffer, range.min, range.max, string.str);
is_first = 1;
for (i = 0; i < string.size; ++i){
if (char_is_alpha_true(string.str[i])){
if (is_first) is_first = 0;
else string.str[i] = char_to_lower(string.str[i]);
}
else{
is_first = 1;
}
}
app->buffer_replace_range(app, &buffer, range.min, range.max, string.str, string.size);
}
// TODO(allen):
// get range by specific "word" type (for example "get token range")
// read range by specific "word" type
// Dream API: for rewrite_as_single_caps
#if 0
{
rewrite = get_rewrite(app, ByToken);
string = get_rewrite_string(app, &rewrite, app->memory, app->memory_size);
is_first = 1;
for (i = 0; i < string.size; ++i){
if (char_is_alpha_true(string.str[i])){
if (is_first) is_first = 0;
else string.str[i] = char_to_lower(string.str[i]);
}
else{
is_first = 1;
}
}
do_rewrite(app, &rewrite, string);
}
#endif
CUSTOM_COMMAND_SIG(replace_in_range){
Query_Bar replace;
char replace_space[1024];
@ -701,6 +761,61 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
exec_command(app, cmdid_auto_tab_line_at_cursor);
}
struct Scroll_Velocity{
float x, y;
};
Scroll_Velocity scroll_velocity[16] = {0};
static int
smooth_camera_step(float target, float *current, float *vel, float S, float T){
int result = 0;
float curr = *current;
float v = *vel;
if (curr != target){
if (curr > target - .1f && curr < target + .1f){
curr = target;
v = 1.f;
}
else{
float L = curr + T*(target - curr);
int sign = (target > curr) - (target < curr);
float V = curr + sign*v;
if (sign > 0) curr = (L<V)?(L):(V);
else curr = (L>V)?(L):(V);
if (curr == V){
v *= S;
}
}
*current = curr;
*vel = v;
result = 1;
}
return result;
}
extern "C" SCROLL_RULE_SIG(scroll_rule){
Scroll_Velocity *velocity = scroll_velocity + view_id;
int result = 0;
if (velocity->x == 0.f){
velocity->x = 1.f;
velocity->y = 1.f;
}
if (smooth_camera_step(target_y, scroll_y, &velocity->y, 40.f, 1.f/4.f)){
result = 1;
}
if (smooth_camera_step(target_x, scroll_x, &velocity->x, 40.f, 1.f/4.f)){
result = 1;
}
return(result);
}
extern "C" GET_BINDING_DATA(get_bindings){
Bind_Helper context_actual = begin_bind_helper(data, size);
Bind_Helper *context = &context_actual;
@ -830,14 +945,13 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, 'g', MDFR_CTRL, goto_line);
bind(context, 'q', MDFR_CTRL, query_replace);
bind(context, 'a', MDFR_CTRL, replace_in_range);
bind(context, 's', MDFR_ALT, rewrite_as_single_caps);
bind(context, 'K', MDFR_CTRL, cmdid_kill_buffer);
bind(context, 'O', MDFR_CTRL, cmdid_reopen);
bind(context, 'w', MDFR_CTRL, cmdid_interactive_save_as);
bind(context, 's', MDFR_CTRL, cmdid_save);
bind(context, ',', MDFR_ALT, switch_to_compilation);
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);

View File

@ -157,11 +157,13 @@ struct Query_Bar{
#define GET_BINDING_DATA(name) int name(void *data, int size)
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
#define HOOK_SIG(name) void name(struct Application_Links *app)
#define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target)
extern "C"{
typedef CUSTOM_COMMAND_SIG(Custom_Command_Function);
typedef GET_BINDING_DATA(Get_Binding_Data_Function);
typedef HOOK_SIG(Hook_Function);
typedef SCROLL_RULE_SIG(Scroll_Rule_Function);
}
struct Application_Links;
@ -190,6 +192,7 @@ struct Application_Links;
#define BUFFER_SEEK_STRING_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
#define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *str, int len)
#define BUFFER_SET_POS_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int pos)
// File view manipulation
#define GET_VIEW_MAX_INDEX_SIG(name) int name(Application_Links *context)
@ -245,6 +248,7 @@ extern "C"{
typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function);
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function);
// View manipulation
typedef GET_VIEW_MAX_INDEX_SIG(Get_View_Max_Index_Function);
@ -294,6 +298,7 @@ struct Application_Links{
Buffer_Seek_String_Function *buffer_seek_string;
Buffer_Read_Range_Function *buffer_read_range;
Buffer_Replace_Range_Function *buffer_replace_range;
Buffer_Set_Pos_Function *buffer_set_pos;
// View manipulation
Get_View_Max_Index_Function *get_view_max_index;
@ -319,6 +324,7 @@ struct Application_Links{
struct Custom_API{
Get_Binding_Data_Function *get_bindings;
Scroll_Rule_Function *scroll_rule;
};
// NOTE(allen): definitions for the buffer that communicates to 4ed.exe

125
4ed.cpp
View File

@ -62,6 +62,7 @@ struct Command_Data{
Editing_Layout *layout;
Live_Views *live_set;
Style *style;
Style_Font *global_font;
Delay *delay;
struct App_Vars *vars;
Exchange *exchange;
@ -100,6 +101,7 @@ struct App_Vars{
Font_Set *font_set;
Style_Font global_font;
Style style;
Style_Library styles;
u32 *palette;
@ -181,6 +183,7 @@ globalvar Application_Links app_links;
#define USE_LAYOUT(n) Editing_Layout *n = command->layout
#define USE_LIVE_SET(n) Live_Views *live_set = command->live_set
#define USE_STYLE(n) Style *n = command->style
#define USE_FONT(n) Style_Font *n = command->global_font
#define USE_DELAY(n) Delay *n = command->delay
#define USE_VARS(n) App_Vars *n = command->vars
#define USE_EXCHANGE(n) Exchange *n = command->exchange
@ -241,7 +244,7 @@ param_stack_end(Partition *part){
internal File_View*
panel_make_empty(System_Functions *system, Exchange *exchange,
App_Vars *vars, Style *style, Panel *panel){
App_Vars *vars, Style *style, Style_Font *global_font, Panel *panel){
Mem_Options *mem = &vars->mem;
Editing_Layout *layout = &vars->layout;
@ -252,13 +255,13 @@ panel_make_empty(System_Functions *system, Exchange *exchange,
View_And_ID new_view;
Assert(panel->view == 0);
new_view = live_set_alloc_view(&vars->live_set, mem);
new_view = live_set_alloc_view(&vars->live_set, vars->config_api.scroll_rule);
panel->view = new_view.view;
panel->view->panel = panel;
file_view = file_view_init(panel->view, layout, working_set, delay,
&vars->settings, &vars->hot_directory, mem, &vars->styles);
view_set_file(file_view, 0, vars->font_set, style, 0, 0, 0);
view_set_file(file_view, 0, vars->font_set, style, global_font, 0, 0, 0);
panel->view->map = app_get_map(vars, mapid_global);
return(file_view);
@ -284,7 +287,6 @@ COMMAND_DECL(write_character){
next_cursor_pos = view->cursor.pos + 1;
view_replace_range(system, mem, view, layout, pos, pos, &character, 1, next_cursor_pos);
view_cursor_move(view, next_cursor_pos);
file->state.cursor_pos = view->cursor.pos;
}
}
@ -948,6 +950,7 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
Editing_Layout *layout = cmd->layout;
App_Vars *vars = cmd->vars;
Style *style = cmd->style;
Style_Font *global_font = cmd->global_font;
Working_Set *working_set = &vars->working_set;
Delay *delay = &vars->delay1;
@ -966,7 +969,7 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
temp = begin_temp_memory(&mem->part);
cmd->part = partition_sub_part(&mem->part, Kbytes(16));
view_set_file(file_view, file, vars->font_set, style,
view_set_file(file_view, file, vars->font_set, style, global_font,
system, vars->hooks[hook_open_file], &app_links);
cmd->part = old_part;
@ -988,6 +991,7 @@ COMMAND_DECL(reopen){
USE_WORKING_SET(working_set);
USE_VARS(vars);
USE_STYLE(style);
USE_FONT(global_font);
i32 file_id = exchange_request_file(exchange, expand_str(file->name.source_path));
i32 index = 0;
@ -996,7 +1000,7 @@ COMMAND_DECL(reopen){
index = working_set_get_index(working_set, file);
app_push_file_binding(vars, file_id, index);
view_set_file(view, file, vars->font_set, style,
view_set_file(view, file, vars->font_set, style, global_font,
system, vars->hooks[hook_open_file], &app_links);
}
else{
@ -1310,6 +1314,7 @@ COMMAND_DECL(open_panel_vsplit){
USE_EXCHANGE(exchange);
USE_VARS(vars);
USE_STYLE(style);
USE_FONT(global_font);
if (layout->panel_count < layout->panel_max_count){
Split_Result split = layout_split_panel(layout, panel, 1);
@ -1328,7 +1333,7 @@ COMMAND_DECL(open_panel_vsplit){
panel2->prev_inner = panel2->inner;
layout->active_panel = (i32)(panel2 - layout->panels);
panel_make_empty(system, exchange, vars, style, panel2);
panel_make_empty(system, exchange, vars, style, global_font, panel2);
}
}
@ -1339,6 +1344,7 @@ COMMAND_DECL(open_panel_hsplit){
USE_EXCHANGE(exchange);
USE_VARS(vars);
USE_STYLE(style);
USE_FONT(global_font);
if (layout->panel_count < layout->panel_max_count){
Split_Result split = layout_split_panel(layout, panel, 0);
@ -1357,7 +1363,7 @@ COMMAND_DECL(open_panel_hsplit){
panel2->prev_inner = panel2->inner;
layout->active_panel = (i32)(panel2 - layout->panels);
panel_make_empty(system, exchange, vars, style, panel2);
panel_make_empty(system, exchange, vars, style, global_font, panel2);
}
}
@ -1513,8 +1519,9 @@ COMMAND_DECL(move_up){
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
USE_FONT_SET(font_set);
USE_FONT(global_font);
f32 font_height = (f32)get_font_info(font_set, view->style->font_id)->height;
f32 font_height = (f32)get_font_info(font_set, global_font->font_id)->height;
f32 cy = view_get_cursor_y(view)-font_height;
f32 px = view->preferred_x;
if (cy >= 0){
@ -1528,8 +1535,9 @@ COMMAND_DECL(move_down){
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
USE_FONT_SET(font_set);
USE_FONT(global_font);
f32 font_height = (f32)get_font_info(font_set, view->style->font_id)->height;
f32 font_height = (f32)get_font_info(font_set, global_font->font_id)->height;
f32 cy = view_get_cursor_y(view)+font_height;
f32 px = view->preferred_x;
view->cursor = view_compute_cursor_from_xy(view, px, cy);
@ -1710,7 +1718,7 @@ COMMAND_DECL(set_settings){
internal void
build(System_Functions *system, Mem_Options *mem,
App_Vars *vars, Working_Set *working_set,
Font_Set *font_set, Style *style,
Font_Set *font_set, Style *style, Style_Font *global_font,
Live_Views *live_set, Exchange *exchange,
Panel *panel, Command_Data *command,
String hot_directory,
@ -1759,7 +1767,7 @@ build(System_Functions *system, Mem_Options *mem,
}
if (file){
file_create_super_locked(system, mem, working_set, file, buffer_name, font_set, style->font_id);
file_create_super_locked(system, mem, working_set, file, buffer_name, font_set, global_font->font_id);
file->settings.unimportant = 1;
table_add(&working_set->table, file->name.source_path, index);
@ -1793,6 +1801,7 @@ COMMAND_DECL(command_line){
USE_PANEL(panel);
USE_EXCHANGE(exchange);
USE_FONT_SET(font_set);
USE_FONT(global_font);
char *buffer_name = 0;
char *path = 0;
@ -1857,7 +1866,7 @@ COMMAND_DECL(command_line){
}
build(system, mem, vars, working_set,
font_set, style, live_set, exchange,
font_set, style, global_font, live_set, exchange,
panel, command,
vars->hot_directory.string,
buffer_name, buffer_name_len,
@ -2160,8 +2169,8 @@ extern "C"{
pos = file->state.cursor_pos;
if (pos < start) next_cursor = pos;
else if (pos < end) next_cursor = start + len;
else next_cursor = pos + end - start + len;
else if (pos < end) next_cursor = start;
else next_cursor = pos + end - start - len;
file_replace_range(system, mem, file, layout,
start, end, str, len, next_cursor);
@ -2173,6 +2182,30 @@ extern "C"{
return(result);
}
BUFFER_SET_POS_SIG(external_buffer_set_pos){
Command_Data *cmd = (Command_Data*)context->cmd_context;
Editing_File *file;
Working_Set *working_set;
int result = 0;
int size;
if (buffer->exists){
working_set = cmd->working_set;
file = working_set->files + buffer->buffer_id;
if (!file->state.is_dummy && file_is_ready(file)){
result = 1;
size = buffer_size(&file->state.buffer);
if (pos < 0) pos = 0;
if (pos > size) pos = size;
file->state.cursor_pos = pos;
fill_buffer_summary(buffer, file, working_set);
}
}
return(result);
}
GET_VIEW_MAX_INDEX_SIG(external_get_view_max_index){
Command_Data *cmd = (Command_Data*)context->cmd_context;
Live_Views *live_set = cmd->live_set;
@ -2316,7 +2349,7 @@ extern "C"{
if (buffer_id >= 0 && buffer_id < max){
file = working_set->files + buffer_id;
if (!file->state.is_dummy){
view_set_file(file_view, file, cmd->vars->font_set, cmd->style,
view_set_file(file_view, file, cmd->vars->font_set, cmd->style, cmd->global_font,
cmd->system, cmd->vars->hooks[hook_open_file], &app_links);
}
}
@ -2549,10 +2582,11 @@ app_hardcode_styles(App_Vars *vars){
style = styles;
i16 fonts = 1;
vars->global_font.font_id = fonts + 0;
vars->global_font.font_changed = 0;
/////////////////
style_set_name(style, make_lit_string("4coder"));
style->font_id = fonts + 0;
style->main.back_color = 0xFF0C0C0C;
style->main.margin_color = 0xFF181818;
@ -2587,18 +2621,10 @@ app_hardcode_styles(App_Vars *vars){
file_info_style.pop1_color = 0xFF4444AA;
file_info_style.pop2_color = 0xFFFF0000;
style->main.file_info_style = file_info_style;
style->font_changed = 1;
++style;
/////////////////
*style = *(style-1);
style_set_name(style, make_lit_string("4coder-mono"));
style->font_id = fonts + 1;
++style;
/////////////////
style_set_name(style, make_lit_string("Handmade Hero"));
style->font_id = fonts + 1;
style->main.back_color = 0xFF161616;
style->main.margin_color = 0xFF262626;
@ -2634,12 +2660,10 @@ app_hardcode_styles(App_Vars *vars){
file_info_style.pop1_color = 0xFF03CF0C;
file_info_style.pop2_color = 0xFFFF0000;
style->main.file_info_style = file_info_style;
style->font_changed = 1;
++style;
/////////////////
style_set_name(style, make_lit_string("Twilight"));
style->font_id = fonts + 2;
style->main.back_color = 0xFF090D12;
style->main.margin_color = 0xFF1A2634;
@ -2674,12 +2698,10 @@ app_hardcode_styles(App_Vars *vars){
file_info_style.pop1_color = 0xFF1BFF0C;
file_info_style.pop2_color = 0xFFFF200D;
style->main.file_info_style = file_info_style;
style->font_changed = 1;
++style;
/////////////////
style_set_name(style, make_lit_string("Wolverine"));
style->font_id = fonts + 3;
style->main.back_color = 0xFF070711;
style->main.margin_color = 0xFF111168;
@ -2714,12 +2736,10 @@ app_hardcode_styles(App_Vars *vars){
file_info_style.pop1_color = 0xFFFAFA15;
file_info_style.pop2_color = 0xFFD20000;
style->main.file_info_style = file_info_style;
style->font_changed = 1;
++style;
/////////////////
style_set_name(style, make_lit_string("stb"));
style->font_id = fonts + 4;
style->main.back_color = 0xFFD6D6D6;
style->main.margin_color = 0xFF9E9E9E;
@ -2731,7 +2751,7 @@ app_hardcode_styles(App_Vars *vars){
style->main.highlight_color = 0xFF0044FF;
style->main.at_highlight_color = 0xFFD6D6D6;
style->main.default_color = 0xFF000000;
style->main.comment_color = 0xFF000000;
style->main.comment_color = 0xFF005800;
style->main.keyword_color = 0xFF000000;
style->main.str_constant_color = 0xFF000000;
style->main.char_constant_color = style->main.str_constant_color;
@ -2754,13 +2774,11 @@ app_hardcode_styles(App_Vars *vars){
file_info_style.pop1_color = 0xFF1111DC;
file_info_style.pop2_color = 0xFFE80505;
style->main.file_info_style = file_info_style;
style->font_changed = 1;
++style;
vars->styles.count = (i32)(style - styles);
vars->styles.max = ArrayCount(vars->styles.styles);
style_copy(&vars->style, vars->styles.styles);
vars->style.font_changed = 0;
}
char *_4coder_get_extension(const char *filename, int len, int *extension_len){
@ -2944,6 +2962,21 @@ App_Read_Command_Line_Sig(app_read_command_line){
return(out_size);
}
extern "C" SCROLL_RULE_SIG(fallback_scroll_rule){
int result = 0;
if (target_x != *scroll_x){
*scroll_x = target_x;
result = 1;
}
if (target_y != *scroll_y){
*scroll_y = target_y;
result = 1;
}
return(result);
}
App_Init_Sig(app_init){
app_links_init(system, memory->user_memory, memory->user_memory_size);
@ -3011,6 +3044,10 @@ App_Init_Sig(app_init){
}
}
if (vars->config_api.scroll_rule == 0){
vars->config_api.scroll_rule = fallback_scroll_rule;
}
setup_command_table();
Command_Map *global = &vars->map_top;
@ -3225,7 +3262,7 @@ App_Init_Sig(app_init){
// NOTE(allen): init first panel
Panel_And_ID p = layout_alloc_panel(&vars->layout);
panel_make_empty(system, exchange, vars, &vars->style, p.panel);
panel_make_empty(system, exchange, vars, &vars->style, &vars->global_font, p.panel);
vars->layout.active_panel = p.id;
String hdbase = make_fixed_width_string(vars->hot_dir_base_);
@ -3508,6 +3545,7 @@ App_Step_Sig(app_step){
cmd->layout = &vars->layout;
cmd->live_set = &vars->live_set;
cmd->style = &vars->style;
cmd->global_font = &vars->global_font;
cmd->delay = &vars->delay1;
cmd->vars = vars;
cmd->exchange = exchange;
@ -3941,7 +3979,7 @@ App_Step_Sig(app_step){
if (data){
String val = make_string((char*)data, size);
file_create_from_string(system, mem, working_set, ed_file, filename,
vars->font_set, vars->style.font_id, val);
vars->font_set, vars->global_font.font_id, val);
if (ed_file->settings.tokens_exist){
file_first_lex_parallel(system, general, ed_file);
@ -3956,7 +3994,7 @@ App_Step_Sig(app_step){
else{
if (binding->fail & SysAppCreateNewBuffer){
file_create_empty(system, mem, working_set, ed_file, filename,
vars->font_set, vars->style.font_id);
vars->font_set, vars->global_font.font_id);
if (binding->fail & SysAppCreateView){
view_file_in_panel(cmd, binding->panel, ed_file);
}
@ -4013,6 +4051,7 @@ App_Step_Sig(app_step){
ProfileStart(delayed_actions);
if (vars->delay1.count > 0){
Style *style = &vars->style;
Style_Font *global_font = &vars->global_font;
Working_Set *working_set = &vars->working_set;
Live_Views *live_set = &vars->live_set;
Mem_Options *mem = &vars->mem;
@ -4156,13 +4195,13 @@ App_Step_Sig(app_step){
{
Get_File_Result file = working_set_get_available_file(working_set);
file_create_empty(system, mem, working_set, file.file, string.str,
vars->font_set, style->font_id);
vars->font_set, global_font->font_id);
table_add(&working_set->table, file.file->name.source_path, file.index);
View *view = panel->view;
File_View *fview = view_to_file_view(view);
view_set_file(fview, file.file, vars->font_set, style,
view_set_file(fview, file.file, vars->font_set, style, global_font,
system, vars->hooks[hook_open_file], &app_links);
view->map = app_get_map(vars, file.file->settings.base_map_id);
#if BUFFER_EXPERIMENT_SCALPEL <= 0
@ -4178,7 +4217,7 @@ App_Step_Sig(app_step){
View *view = panel->view;
File_View *fview = view_to_file_view(view);
view_set_file(fview, file, vars->font_set, style,
view_set_file(fview, file, vars->font_set, style, global_font,
system, vars->hooks[hook_open_file], &app_links);
view->map = app_get_map(vars, file->settings.base_map_id);
}
@ -4259,13 +4298,13 @@ App_Step_Sig(app_step){
ProfileStart(style_change);
// NOTE(allen): send style change messages if the style has changed
if (vars->style.font_changed){
vars->style.font_changed = 0;
if (vars->global_font.font_changed){
vars->global_font.font_changed = 0;
Editing_File *file = vars->working_set.files;
for (i32 i = vars->working_set.file_index_count; i > 0; --i, ++file){
if (buffer_good(&file->state.buffer) && !file->state.is_dummy){
Render_Font *font = get_font_info(vars->font_set, vars->style.font_id)->font;
Render_Font *font = get_font_info(vars->font_set, vars->global_font.font_id)->font;
float *advance_data = 0;
if (font) advance_data = font->advance_data;

View File

@ -40,10 +40,10 @@
#include "4ed_font_set.cpp"
#include "4ed_rendering_helper.cpp"
#include "4ed_command.cpp"
#include "4ed_layout.cpp"
#include "4ed_style.cpp"
#include "4ed_file.cpp"
#include "4ed_gui.cpp"
#include "4ed_layout.cpp"
#include "4ed_delay.cpp"
#include "4ed_app_settings.h"
#include "4ed_file_view.cpp"

File diff suppressed because it is too large Load Diff

View File

@ -550,12 +550,13 @@ get_pop_color(UI_State *state, u32 *pop, Widget_ID wid, UI_Style style){
internal UI_State
ui_state_init(UI_State *state_in, Render_Target *target, Input_Summary *user_input,
Style *style, Font_Set *font_set, Working_Set *working_set, b32 input_stage){
Style *style, i16 font_id, Font_Set *font_set, Working_Set *working_set,
b32 input_stage){
UI_State state = {};
state.target = target;
state.style = style;
state.font_set = font_set;
state.font_id = style->font_id;
state.font_id = font_id;
state.working_set = working_set;
if (user_input){
state.mouse = &user_input->mouse;
@ -821,7 +822,7 @@ internal b32
do_button(i32 id, UI_State *state, UI_Layout *layout, char *text, i32 height_mult,
b32 is_toggle = 0, b32 on = 0){
b32 result = 0;
i16 font_id = state->style->font_id;
i16 font_id = state->font_id;
i32 character_h = get_font_info(state->font_set, font_id)->height;
i32_Rect btn_rect = layout_rect(layout, character_h * height_mult);
@ -869,7 +870,7 @@ do_button(i32 id, UI_State *state, UI_Layout *layout, char *text, i32 height_mul
internal b32
do_undo_slider(Widget_ID wid, UI_State *state, UI_Layout *layout, i32 max, i32 v, Undo_Data *undo, i32 *out){
b32 result = 0;
i16 font_id = state->style->font_id;
i16 font_id = state->font_id;
i32 character_h = get_font_info(state->font_set, font_id)->height;
i32_Rect containing_rect = layout_rect(layout, character_h);
@ -1013,7 +1014,7 @@ do_undo_slider(Widget_ID wid, UI_State *state, UI_Layout *layout, i32 max, i32 v
internal void
do_label(UI_State *state, UI_Layout *layout, char *text, int text_size, f32 height = 2.f){
Style *style = state->style;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 line_height = get_font_info(state->font_set, font_id)->height;
i32_Rect label = layout_rect(layout, FLOOR32(line_height * height));
@ -1178,13 +1179,13 @@ draw_gradient_slider(Render_Target *target, Vec4 base, i32 channel,
inline void
draw_hsl_slider(Render_Target *target, Vec4 base, i32 channel,
i32 steps, real32 top, f32_Rect slider){
i32 steps, f32 top, f32_Rect slider){
draw_gradient_slider(target, base, channel, steps, top, slider, 1);
}
inline void
draw_rgb_slider(Render_Target *target, Vec4 base, i32 channel,
i32 steps, f32 top, f32_Rect slider){
i32 steps, f32 top, f32_Rect slider){
draw_gradient_slider(target, base, channel, steps, top, slider, 0);
}
@ -1195,7 +1196,7 @@ do_main_file_box(System_Functions *system, UI_State *state, UI_Layout *layout,
Style *style = state->style;
String *string = &hot_directory->string;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 line_height = get_font_info(state->font_set, font_id)->height;
i32_Rect box = layout_rect(layout, line_height + 2);
@ -1224,7 +1225,7 @@ do_main_string_box(System_Functions *system, UI_State *state, UI_Layout *layout,
b32 result = 0;
Style *style = state->style;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 line_height = get_font_info(state->font_set, font_id)->height;
i32_Rect box = layout_rect(layout, line_height + 2);
@ -1251,7 +1252,7 @@ do_list_option(i32 id, UI_State *state, UI_Layout *layout, String text){
b32 result = 0;
Style *style = state->style;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 character_h = get_font_info(state->font_set, font_id)->height;
i32_Rect box = layout_rect(layout, character_h*2);
@ -1287,7 +1288,7 @@ do_checkbox_list_option(i32 id, UI_State *state, UI_Layout *layout, String text,
b32 result = 0;
Style *style = state->style;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 character_h = get_font_info(state->font_set, font_id)->height;
i32_Rect box = layout_rect(layout, character_h*2);
@ -1332,7 +1333,7 @@ internal b32
do_file_option(i32 id, UI_State *state, UI_Layout *layout, String filename, b32 is_folder, String extra, char slash){
b32 result = 0;
Style *style = state->style;
i16 font_id = style->font_id;
i16 font_id = state->font_id;
i32 character_h = get_font_info(state->font_set, font_id)->height;
char slash_buf[2] = { slash, 0 };
@ -1556,6 +1557,7 @@ struct Color_UI{
UI_Layout *layout;
Font_Set *fonts;
Style_Font *global_font;
f32 hex_advance;
u32 *palette;
@ -1964,7 +1966,7 @@ do_palette(Color_UI *ui, i32_Rect rect){
if (!ui->state->input_stage){
Render_Target *target = ui->state->target;
draw_string(target, style->font_id, "Global Palette: right click to save color",
draw_string(target, ui->state->font_id, "Global Palette: right click to save color",
layout.x, layout.rect.y0, style->main.default_color);
}
@ -2233,8 +2235,8 @@ do_font_switch(Color_UI *ui){
for (i16 i = 1; i < count; ++i){
if (i == font_id) continue;
if (do_font_option(ui, i)){
ui->state->style->font_id = i;
ui->state->style->font_changed = 1;
ui->global_font->font_id = i;
ui->global_font->font_changed = 1;
}
}
@ -2251,7 +2253,7 @@ do_style_preview(Library_UI *ui, Style *style, i32 toggle = -1){
if (style == ui->state->style) id = 2;
else id = raw_ptr_dif(style, ui->styles->styles) + 100;
i16 font_id = style->font_id;
i16 font_id = ui->state->font_id;
Font_Info *info = get_font_info(ui->state->font_set, font_id);
i32_Rect prect = layout_rect(ui->layout, info->height*3 + 6);

View File

@ -332,6 +332,8 @@ struct View{
Panel *panel;
Command_Map *map;
Do_View_Function *do_view;
Scroll_Rule_Function *scroll_rule;
i32 id;
};
struct Live_Views{
@ -353,7 +355,7 @@ live_set_get_view(Live_Views *live_set, i32 id){
}
internal View_And_ID
live_set_alloc_view(Live_Views *live_set, Mem_Options *mem){
live_set_alloc_view(Live_Views *live_set, Scroll_Rule_Function *scroll_rule){
View_And_ID result = {};
Assert(live_set->count < live_set->max);
@ -361,9 +363,11 @@ live_set_alloc_view(Live_Views *live_set, Mem_Options *mem){
result.view = live_set->free_sentinel.next;
result.id = (i32)((char*)result.view - (char*)live_set->views);
result.view->id = result.id;
dll_remove(result.view);
memset(result.view, 0, live_set->stride);
result.view->scroll_rule = scroll_rule;
return(result);
}
@ -397,45 +401,5 @@ view_base_compute_height(View *view){
#define view_compute_width(view) (view_base_compute_width(&(view)->view_base))
#define view_compute_height(view) (view_base_compute_height(&(view)->view_base))
struct Interactive_Style{
u32 bar_color;
u32 bar_active_color;
u32 base_color;
u32 pop1_color;
u32 pop2_color;
};
struct Interactive_Bar{
Interactive_Style style;
f32 pos_x, pos_y;
f32 text_shift_x, text_shift_y;
i32_Rect rect;
i16 font_id;
};
internal void
intbar_draw_string(Render_Target *target,
Interactive_Bar *bar, u8 *str, u32 char_color){
i16 font_id = bar->font_id;
draw_string(target, font_id, (char*)str,
(i32)(bar->pos_x + bar->text_shift_x),
(i32)(bar->pos_y + bar->text_shift_y),
char_color);
bar->pos_x += font_string_width(target, font_id, (char*)str);
}
internal void
intbar_draw_string(Render_Target *target, Interactive_Bar *bar,
String str, u32 char_color){
i16 font_id = bar->font_id;
draw_string(target, font_id, str,
(i32)(bar->pos_x + bar->text_shift_x),
(i32)(bar->pos_y + bar->text_shift_y),
char_color);
bar->pos_x += font_string_width(target, font_id, str);
}
// BOTTOM

View File

@ -9,6 +9,42 @@
// TOP
// TODO(allen):
// Font changing UI should be in the library menu now, it's not tied to the fonts any more
// Get the import export stuff up and running for styles again
struct Interactive_Style{
u32 bar_color;
u32 bar_active_color;
u32 base_color;
u32 pop1_color;
u32 pop2_color;
};
struct Interactive_Bar{
f32 pos_x, pos_y;
f32 text_shift_x, text_shift_y;
i32_Rect rect;
i16 font_id;
};
internal void
intbar_draw_string(Render_Target *target, Interactive_Bar *bar,
String str, u32 char_color){
i16 font_id = bar->font_id;
draw_string(target, font_id, str,
(i32)(bar->pos_x + bar->text_shift_x),
(i32)(bar->pos_y + bar->text_shift_y),
char_color);
bar->pos_x += font_string_width(target, font_id, str);
}
struct Style_Font{
i16 font_id;
i16 font_changed;
};
struct Style_Main_Data{
u32 back_color;
u32 margin_color;
@ -37,51 +73,39 @@ struct Style_Main_Data{
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,
enum Style_Tag{
Stag_Bar,
Stag_Bar_Active,
Stag_Bar_Base,
Stag_Bar_Pop1,
Stag_Bar_Pop2,
Stag_Back,
Stag_Margin,
Stag_Margin_Hover,
Stag_Margin_Active,
Stag_Cursor,
Stag_At_Cursor,
Stag_Highlight,
Stag_At_Highlight,
Stag_Mark,
Stag_Default,
Stag_Comment,
Stag_Keyword,
Stag_Str_Constant,
Stag_Char_Constant,
Stag_Int_Constant,
Stag_Float_Constant,
Stag_Bool_Constant,
Stag_Preproc,
Stag_Include,
Stag_Special_Character,
Stag_Highlight_Junk,
Stag_Highlight_White,
Stag_Paste,
Stag_Undo,
Stag_Next_Undo,
// never below this
STAG_COUNT
Stag_Count
};
struct Style_Color_Specifier{
@ -92,8 +116,6 @@ struct Style_Color_Specifier{
struct Style_File_Format{
i32 name_size;
char name[24];
i32 font_name_size;
char font_name[24];
i32 color_specifier_count;
};
@ -102,8 +124,6 @@ struct Style{
char name_[24];
String name;
Style_Main_Data main;
b32 font_changed;
i16 font_id;
};
struct Style_Library{
@ -120,51 +140,51 @@ style_copy(Style *dst, Style *src){
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);
terminate_with_null(&style->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_Bar: result = &s->main.file_info_style.bar_color; break;
case Stag_Bar_Active: result = &s->main.file_info_style.bar_active_color; break;
case Stag_Bar_Base: result = &s->main.file_info_style.base_color; break;
case Stag_Bar_Pop1: result = &s->main.file_info_style.pop1_color; break;
case Stag_Bar_Pop2: 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_Back: result = &s->main.back_color; break;
case Stag_Margin: result = &s->main.margin_color; break;
case Stag_Margin_Hover: result = &s->main.margin_hover_color; break;
case Stag_Margin_Active: 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_Cursor: result = &s->main.cursor_color; break;
case Stag_At_Cursor: result = &s->main.at_cursor_color; break;
case Stag_Highlight: result = &s->main.highlight_color; break;
case Stag_At_Highlight: result = &s->main.at_highlight_color; break;
case Stag_Mark: 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_Default: result = &s->main.default_color; break;
case Stag_Comment: result = &s->main.comment_color; break;
case Stag_Keyword: result = &s->main.keyword_color; break;
case Stag_Str_Constant: result = &s->main.str_constant_color; break;
case Stag_Char_Constant: result = &s->main.char_constant_color; break;
case Stag_Int_Constant: result = &s->main.int_constant_color; break;
case Stag_Float_Constant: result = &s->main.float_constant_color; break;
case Stag_Bool_Constant: 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_Preproc: result = &s->main.preproc_color; break;
case Stag_Include: result = &s->main.include_color; break;
case STAG_SPECIAL_CHARACTER_COLOR: result = &s->main.special_character_color; break;
case Stag_Special_Character: 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_Highlight_Junk: result = &s->main.highlight_junk_color; break;
case Stag_Highlight_White: 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_Paste: result = &s->main.paste_color; break;
case Stag_Undo: result = &s->main.undo_color; break;
}
return result;
}
@ -198,14 +218,10 @@ 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){
for (u32 i = 0; i < Stag_Count; ++i){
u32 *color = style_index_by_tag(style, i);
if (color){
spec->tag = i;

View File

@ -7,7 +7,7 @@ SET clset=64
SET WARNINGS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /WX
SET STUFF=/GR- /nologo
SET DEBUG=/Zi
SET EXPORTS=/EXPORT:get_bindings
SET EXPORTS=/EXPORT:get_bindings /EXPORT:scroll_rule
SET SRC=4coder_custom.cpp
cl %WARNINGS% %STUFF% %DEBUG% %SRC% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS%

View File

@ -1754,6 +1754,9 @@ main(int argc, char **argv){
if (win32vars.custom){
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
GetProcAddress(win32vars.custom, "get_bindings");
win32vars.custom_api.scroll_rule = (Scroll_Rule_Function*)
GetProcAddress(win32vars.custom, "scroll_rule");
}
#endif