theme API part 1, bug fixes

master
Allen Webster 2016-03-04 23:10:55 -05:00
parent 9bf2a73640
commit 6e1abb4237
9 changed files with 407 additions and 311 deletions

View File

@ -811,7 +811,7 @@ CUSTOM_COMMAND_SIG(build_search){
if (app->file_exists(app, dir.str, dir.size)){
dir.size = old_size;
push_parameter(app, par_flags, 0);
push_parameter(app, par_flags, CLI_OverlapWithConflict);
push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, dir.str, dir.size);
@ -840,6 +840,34 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
exec_command(app, cmdid_auto_tab_line_at_cursor);
}
CUSTOM_COMMAND_SIG(improve_theme){
Theme_Color colors[] = {
{Stag_Bar, 0xFF0088},
{Stag_Margin, 0x880088},
{Stag_Margin_Hover, 0xAA0088},
{Stag_Margin_Active, 0xDD0088},
{Stag_Cursor, 0xFF0000},
};
int count = ArrayCount(colors);
app->set_theme_colors(app, colors, count);
}
CUSTOM_COMMAND_SIG(ruin_theme){
Theme_Color colors[] = {
{Stag_Bar, 0x888888},
{Stag_Margin, 0x181818},
{Stag_Margin_Hover, 0x252525},
{Stag_Margin_Active, 0x323232},
{Stag_Cursor, 0x00EE00},
};
int count = ArrayCount(colors);
app->set_theme_colors(app, colors, count);
}
// NOTE(allen|a4.0.0): scroll rule information
//
// The parameters:
@ -961,6 +989,8 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, 'M', MDFR_ALT | MDFR_CTRL, open_my_files);
bind(context, 'M', MDFR_ALT, build_at_launch_location);
bind(context, '`', MDFR_ALT, improve_theme);
bind(context, '~', MDFR_ALT, ruin_theme);
end_map(context);

View File

@ -319,6 +319,13 @@ struct Query_Bar{
String string;
};
struct Theme_Color{
Style_Tag tag;
unsigned int color;
};
#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)
@ -383,6 +390,8 @@ struct Application_Links;
#define START_QUERY_BAR_SIG(name) int name(Application_Links *context, Query_Bar *bar, unsigned int flags)
#define END_QUERY_BAR_SIG(name) void name(Application_Links *context, Query_Bar *bar, unsigned int flags)
// Setting colors
#define SET_THEME_COLORS_SIG(name) void name(Application_Links *context, Theme_Color *colors, int count)
// Boundry type flags
@ -457,6 +466,9 @@ extern "C"{
// Queries
typedef START_QUERY_BAR_SIG(Start_Query_Bar_Function);
typedef END_QUERY_BAR_SIG(End_Query_Bar_Function);
// Set theme colors
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
}
struct Application_Links{
@ -514,6 +526,9 @@ struct Application_Links{
Start_Query_Bar_Function *start_query_bar;
End_Query_Bar_Function *end_query_bar;
// Theme
Set_Theme_Colors_Function *set_theme_colors;
// Internal
void *cmd_context;
};

View File

@ -214,17 +214,6 @@ push_parameter(Application_Links *app, const char *param, int param_len, const c
app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_string(value_copy, value_len));
}
#if UseInterfacesThatArePhasingOut
inline String
push_directory(Application_Links *app){
String result;
result.memory_size = 512;
result.str = app->push_memory(app, result.memory_size);
result.size = app->directory_get_hot(app, result.str, result.memory_size);
return(result);
}
#endif
inline Range
get_range(View_Summary *view){
Range range;

40
4ed.cpp
View File

@ -1637,7 +1637,7 @@ COMMAND_DECL(close_minor_view){
if (view->file){
map = app_get_map(models, view->file->settings.base_map_id);
}
view_show_file(view, map, view->file);
view_show_file(view, map);
}
COMMAND_DECL(cursor_mark_swap){
@ -1801,22 +1801,27 @@ COMMAND_DECL(command_line){
if (buffer_id){
file = working_set_get_file(working_set, buffer_id, 1);
}
else{
else if (buffer_name){
file.file = working_set_contains(working_set, make_string(buffer_name, buffer_name_len));
file.index = (i32)(file.file - working_set->files);
if (file.file == 0)
if (file.file == 0){
file = working_set_get_available_file(working_set);
else{
if (file.file == 0){
// TODO(allen): feedback message - no available file
return;
}
}
}
if (file.file){
i32 proc_count = vars->cli_processes.count;
View_Iter iter;
i32 i;
file_create_read_only(system, models, file.file, buffer_name);
file.file->settings.unimportant = 1;
table_add(&working_set->table, file.file->name.source_path, file.index);
for (i = 0; i < proc_count; ++i){
if (procs[i].out_file == file.file){
if (flags & CLI_OverlapWithConflict)
@ -1834,10 +1839,6 @@ COMMAND_DECL(command_line){
bind_to_new_view = 0;
}
}
file_create_read_only(system, models, file.file, buffer_name);
file.file->settings.unimportant = 1;
table_add(&working_set->table, file.file->name.source_path, file.index);
}
else{
// TODO(allen): feedback message - file conflict
@ -2487,6 +2488,20 @@ extern "C"{
vptr = cmd->view;
free_query_slot(&vptr->query_set, bar);
}
SET_THEME_COLORS_SIG(external_set_theme_colors){
Command_Data *cmd = (Command_Data*)context->cmd_context;
Style *style = &cmd->models->style;
Theme_Color *theme_color;
i32 i;
u32 *color;
theme_color = colors;
for (i = 0; i < count; ++i, ++theme_color){
color = style_index_by_tag(&style->main, theme_color->tag);
if (color) *color = theme_color->color | 0xFF000000;
}
}
}
struct Command_In{
@ -2553,6 +2568,8 @@ app_links_init(System_Functions *system, void *data, int size){
app_links.start_query_bar = external_start_query_bar;
app_links.end_query_bar = external_end_query_bar;
app_links.set_theme_colors = external_set_theme_colors;
}
internal void
@ -3260,7 +3277,7 @@ App_Init_Sig(app_init){
if (!did_top) setup_top_commands(&models->map_top, &models->mem.part, global);
if (!did_file) setup_file_commands(&models->map_file, &models->mem.part, global);
#if defined(FRED_SUPER)
#if !defined(FRED_SUPER)
models->hooks[hook_start] = 0;
#endif
@ -3392,10 +3409,9 @@ App_Init_Sig(app_init){
vars->sys_app_bindings = (Sys_App_Binding*)push_array(partition, Sys_App_Binding, vars->sys_app_max);
// NOTE(allen): parameter setup
i32 max = models->working_set.file_max;
models->buffer_param_indices = push_array(partition, i32, max);
models->buffer_param_max = max;
models->buffer_param_max = 32;
models->buffer_param_count = 0;
models->buffer_param_indices = push_array(partition, i32, models->buffer_param_max);
}
App_Step_Sig(app_step){

View File

@ -443,7 +443,7 @@ working_set_contains(Working_Set *working, String filename){
Editing_File *result = 0;
i32 id;
if (table_find(&working->table, filename, &id)){
if (id >= 0 && id < working->file_max){
if (id >= 0 && id <= working->file_max){
result = working->files + id;
}
}

View File

@ -1296,6 +1296,10 @@ view_set_file(
file->settings.is_initialized = 1;
}
}
// TODO(allen): Fix this:
view->ui_state = {};
view->showing_ui = VUI_None;
}
struct Relative_Scrolling{
@ -2595,7 +2599,7 @@ view_show_theme(View *fview, Command_Map *gui_map){
}
inline void
view_show_file(View *view, Command_Map *file_map, Editing_File *file){
view_show_file(View *view, Command_Map *file_map){
view->ui_state = {};
if (file_map){
view->map = file_map;
@ -2603,7 +2607,6 @@ view_show_file(View *view, Command_Map *file_map, Editing_File *file){
else{
view->map = view->map_for_file;
}
view->file = file;
view->showing_ui = VUI_None;
}
@ -2652,7 +2655,8 @@ interactive_view_complete(View *view){
}
break;
}
view_show_file(view, 0, 0);
view_show_file(view, 0);
view->file = 0;
}
internal void

View File

@ -19,10 +19,38 @@ struct Struct_Field{
void to_lower(char *src, char *dst){
char *c, ch;
for (c = src; *c != 0; ++c){
ch = char_to_lower(*c);
*dst++ = ch;
}
*dst = 0;
}
void to_upper(char *src, char *dst){
char *c, ch;
for (c = src; *c != 0; ++c){
ch = char_to_upper(*c);
*dst++ = ch;
}
*dst = 0;
}
void to_camel(char *src, char *dst){
char *c, ch;
int is_first = 1;
for (c = src; *c != 0; ++c){
ch = *c;
if (ch >= 'A' && ch <= 'Z'){
ch += ('a' - 'A');
if (char_is_alpha_numeric_true(ch)){
if (is_first){
is_first = 0;
ch = char_to_upper(ch);
}
else{
ch = char_to_lower(ch);
}
}
else{
is_first = 1;
}
*dst++ = ch;
}
@ -361,42 +389,39 @@ char* main_style_fields[] = {
"next_undo",
};
static void
do_style_tag(FILE *file, char *tag){
int j, is_first;
char *str_, c;
String str;
static char*
make_style_tag(char *tag){
char *str;
int len;
str.memory_size = (int)strlen(tag);
str_ = (char*)malloc(str.memory_size + 1);
str = make_string(str_, 0, str.memory_size + 1);
copy(&str, make_string(tag, str.memory_size));
terminate_with_null(&str);
len = (int)strlen(tag);
str = (char*)malloc(len + 1);
to_camel(tag, str);
str[len] = 0;
is_first = 1;
for (j = 0; j < str.size; ++j){
c = str.str[j];
if (char_is_alpha_numeric_true(c)){
if (is_first){
is_first = 0;
str.str[j] = char_to_upper(c);
}
}
else{
is_first = 1;
}
return(str);
}
fprintf(file, "Stag_%s,\n", str.str);
char style_index_function_start[] =
"inline u32*\n"
"style_index_by_tag(Style_Main_Data *s, u32 tag){\n"
" u32 *result = 0;\n"
" switch (tag){\n";
free(str.str);
}
char style_index_function_end[] =
" }\n"
" return(result);\n"
"}\n\n";
char style_case[] = " case Stag_%s: result = &s->%s_color; break;\n";
char style_info_case[] = " case Stag_%s: result = &s->file_info_style.%s_color; break;\n";
char* generate_style(){
char *filename = "4coder_style.h & 4ed_style.h";
char filename_4coder[] = "4coder_style.h";
char filename_4ed[] = "4ed_style.h";
FILE *file;
char *tag;
int count, i;
file = fopen(filename_4coder, "wb");
@ -404,12 +429,16 @@ char* generate_style(){
{
count = ArrayCount(bar_style_fields);
for (i = 0; i < count; ++i){
do_style_tag(file, bar_style_fields[i]);
tag = make_style_tag(bar_style_fields[i]);
fprintf(file, "Stag_%s,\n", tag);
free(tag);
}
count = ArrayCount(main_style_fields);
for (i = 0; i < count; ++i){
do_style_tag(file, main_style_fields[i]);
tag = make_style_tag(main_style_fields[i]);
fprintf(file, "Stag_%s,\n", tag);
free(tag);
}
}
struct_end(file);
@ -434,6 +463,25 @@ char* generate_style(){
fprintf(file, "Interactive_Style file_info_style;\n");
}
struct_end(file);
{
fprintf(file, "%s", style_index_function_start);
count = ArrayCount(bar_style_fields);
for (i = 0; i < count; ++i){
tag = make_style_tag(bar_style_fields[i]);
fprintf(file, style_info_case, tag, bar_style_fields[i]);
free(tag);
}
count = ArrayCount(main_style_fields);
for (i = 0; i < count; ++i){
tag = make_style_tag(main_style_fields[i]);
fprintf(file, style_case, tag, main_style_fields[i]);
free(tag);
}
fprintf(file, "%s", style_index_function_end);
}
fclose(file);
return(filename);

View File

@ -38,50 +38,6 @@ style_set_name(Style *style, String name){
terminate_with_null(&style->name);
}
inline u32*
style_index_by_tag(Style *s, u32 tag){
u32 *result = 0;
switch (tag){
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_Base: result = &s->main.file_info_style.base_color; break;
case Stag_Pop1: result = &s->main.file_info_style.pop1_color; break;
case Stag_Pop2: result = &s->main.file_info_style.pop2_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: 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: 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: result = &s->main.preproc_color; break;
case Stag_Include: result = &s->main.include_color; break;
case Stag_Special_Character: result = &s->main.special_character_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: result = &s->main.paste_color; break;
case Stag_Undo: result = &s->main.undo_color; break;
}
return result;
}
struct Style_Library{
Style styles[64];
i32 count, max;

View File

@ -35,3 +35,41 @@ u32 next_undo_color;
Interactive_Style file_info_style;
};
inline u32*
style_index_by_tag(Style_Main_Data *s, u32 tag){
u32 *result = 0;
switch (tag){
case Stag_Bar: result = &s->file_info_style.bar_color; break;
case Stag_Bar_Active: result = &s->file_info_style.bar_active_color; break;
case Stag_Base: result = &s->file_info_style.base_color; break;
case Stag_Pop1: result = &s->file_info_style.pop1_color; break;
case Stag_Pop2: result = &s->file_info_style.pop2_color; break;
case Stag_Back: result = &s->back_color; break;
case Stag_Margin: result = &s->margin_color; break;
case Stag_Margin_Hover: result = &s->margin_hover_color; break;
case Stag_Margin_Active: result = &s->margin_active_color; break;
case Stag_Cursor: result = &s->cursor_color; break;
case Stag_At_Cursor: result = &s->at_cursor_color; break;
case Stag_Highlight: result = &s->highlight_color; break;
case Stag_At_Highlight: result = &s->at_highlight_color; break;
case Stag_Mark: result = &s->mark_color; break;
case Stag_Default: result = &s->default_color; break;
case Stag_Comment: result = &s->comment_color; break;
case Stag_Keyword: result = &s->keyword_color; break;
case Stag_Str_Constant: result = &s->str_constant_color; break;
case Stag_Char_Constant: result = &s->char_constant_color; break;
case Stag_Int_Constant: result = &s->int_constant_color; break;
case Stag_Float_Constant: result = &s->float_constant_color; break;
case Stag_Bool_Constant: result = &s->bool_constant_color; break;
case Stag_Preproc: result = &s->preproc_color; break;
case Stag_Include: result = &s->include_color; break;
case Stag_Special_Character: result = &s->special_character_color; break;
case Stag_Highlight_Junk: result = &s->highlight_junk_color; break;
case Stag_Highlight_White: result = &s->highlight_white_color; break;
case Stag_Paste: result = &s->paste_color; break;
case Stag_Undo: result = &s->undo_color; break;
case Stag_Next_Undo: result = &s->next_undo_color; break;
}
return(result);
}