meta generate styles

This commit is contained in:
Allen Webster 2016-03-04 18:10:00 -05:00
parent 78653ef118
commit f0e2ca99a5
10 changed files with 535 additions and 230 deletions

View File

@ -191,6 +191,28 @@ CUSTOM_COMMAND_SIG(backspace_word){
app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0); app->buffer_replace_range(app, &buffer, pos1, pos2, 0, 0);
} }
CUSTOM_COMMAND_SIG(snipe_token_or_word){
View_Summary view;
Buffer_Summary buffer;
int pos1, pos2;
view = app->get_active_view(app);
push_parameter(app, par_flags, BoundryToken | BoundryWhitespace);
exec_command(app, cmdid_seek_left);
app->refresh_view(app, &view);
pos1 = view.cursor.pos;
push_parameter(app, par_flags, BoundryToken | BoundryWhitespace);
exec_command(app, cmdid_seek_right);
app->refresh_view(app, &view);
pos2 = view.cursor.pos;
Range range = make_range(pos1, pos2);
buffer = app->get_buffer(app, view.buffer_id);
app->buffer_replace_range(app, &buffer, range.start, range.end, 0, 0);
}
CUSTOM_COMMAND_SIG(switch_to_compilation){ CUSTOM_COMMAND_SIG(switch_to_compilation){
View_Summary view; View_Summary view;
Buffer_Summary buffer; Buffer_Summary buffer;
@ -647,7 +669,7 @@ CUSTOM_COMMAND_SIG(execute_any_cli){
hot_directory = make_fixed_width_string(even_more_space); hot_directory = make_fixed_width_string(even_more_space);
hot_directory.size = app->directory_get_hot(app, hot_directory.str, hot_directory.memory_size); hot_directory.size = app->directory_get_hot(app, hot_directory.str, hot_directory.memory_size);
push_parameter(app, par_cli_flags, CLI_OverlapWithConflict); push_parameter(app, par_flags, CLI_OverlapWithConflict);
push_parameter(app, par_name, bar_out.string.str, bar_out.string.size); push_parameter(app, par_name, bar_out.string.str, bar_out.string.size);
push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size); push_parameter(app, par_cli_path, hot_directory.str, hot_directory.size);
push_parameter(app, par_cli_command, bar_cmd.string.str, bar_cmd.string.size); push_parameter(app, par_cli_command, bar_cmd.string.str, bar_cmd.string.size);
@ -734,7 +756,7 @@ CUSTOM_COMMAND_SIG(build_at_launch_location){
// An example of calling build by setting all // An example of calling build by setting all
// parameters directly. This only works if build.bat can be called // parameters directly. This only works if build.bat can be called
// from the directory the application is launched at. // from the directory the application is launched at.
push_parameter(app, par_cli_flags, CLI_OverlapWithConflict); push_parameter(app, par_flags, CLI_OverlapWithConflict);
push_parameter(app, par_name, literal("*compilation*")); push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, literal(".")); push_parameter(app, par_cli_path, literal("."));
push_parameter(app, par_cli_command, literal("build")); push_parameter(app, par_cli_command, literal("build"));
@ -751,7 +773,7 @@ CUSTOM_COMMAND_SIG(build_search){
// //
// Step 2: app->file_exists queries the file system to see if "<somedir>/build.bat" exists. // Step 2: app->file_exists queries the file system to see if "<somedir>/build.bat" exists.
// If it does exist several parameters are pushed and cmdid_command_line is executed: // If it does exist several parameters are pushed and cmdid_command_line is executed:
// - par_cli_flags: flags for specifiying behaviors // - par_flags: flags for specifiying behaviors
// CLI_OverlapWithConflict - (on by default) if another CLI is still using the output buffer // CLI_OverlapWithConflict - (on by default) if another CLI is still using the output buffer
// that process is detached from the buffer and this process executes outputing to the buffer // that process is detached from the buffer and this process executes outputing to the buffer
// CLI_AlwaysBindToView - if set, the current view always switches to the output buffer // CLI_AlwaysBindToView - if set, the current view always switches to the output buffer
@ -789,7 +811,7 @@ CUSTOM_COMMAND_SIG(build_search){
if (app->file_exists(app, dir.str, dir.size)){ if (app->file_exists(app, dir.str, dir.size)){
dir.size = old_size; dir.size = old_size;
push_parameter(app, par_cli_flags, 0); push_parameter(app, par_flags, 0);
push_parameter(app, par_name, literal("*compilation*")); push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, dir.str, dir.size); push_parameter(app, par_cli_path, dir.str, dir.size);
@ -1012,6 +1034,7 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, key_down, MDFR_ALT, move_down_10); bind(context, key_down, MDFR_ALT, move_down_10);
bind(context, key_back, MDFR_CTRL, backspace_word); bind(context, key_back, MDFR_CTRL, backspace_word);
bind(context, key_back, MDFR_ALT, snipe_token_or_word);
bind(context, ' ', MDFR_CTRL, cmdid_set_mark); bind(context, ' ', MDFR_CTRL, cmdid_set_mark);
bind(context, 'm', MDFR_CTRL, cmdid_cursor_mark_swap); bind(context, 'm', MDFR_CTRL, cmdid_cursor_mark_swap);

View File

@ -1,6 +1,7 @@
#include "4coder_version.h" #include "4coder_version.h"
#include "4coder_keycodes.h" #include "4coder_keycodes.h"
#include "4coder_style.h"
#include "4coder_buffer_types.h" #include "4coder_buffer_types.h"
#ifndef FRED_STRING_STRUCT #ifndef FRED_STRING_STRUCT
@ -161,6 +162,8 @@ typedef struct File_List{
enum Command_ID{ enum Command_ID{
cmdid_null, cmdid_null,
cmdid_write_character, cmdid_write_character,
cmdid_seek_left,
cmdid_seek_right,
cmdid_seek_whitespace_right, cmdid_seek_whitespace_right,
cmdid_seek_whitespace_left, cmdid_seek_whitespace_left,
cmdid_seek_whitespace_up, cmdid_seek_whitespace_up,
@ -233,12 +236,12 @@ enum Param_ID{
par_name, par_name,
par_buffer_id, par_buffer_id,
par_do_in_background, par_do_in_background,
par_flags,
par_lex_as_cpp_file, par_lex_as_cpp_file,
par_wrap_lines, par_wrap_lines,
par_key_mapid, par_key_mapid,
par_cli_path, par_cli_path,
par_cli_command, par_cli_command,
par_cli_flags,
par_clear_blank_lines, par_clear_blank_lines,
// never below this // never below this
par_type_count par_type_count
@ -286,6 +289,8 @@ struct View_Summary{
int exists; int exists;
int view_id; int view_id;
int buffer_id; int buffer_id;
int locked_buffer_id;
int hidden_buffer_id;
Full_Cursor cursor; Full_Cursor cursor;
Full_Cursor mark; Full_Cursor mark;
@ -350,9 +355,10 @@ struct Application_Links;
#define GET_PARAMETER_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int param_index) #define GET_PARAMETER_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int param_index)
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *app, char *filename, int len) #define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *app, char *filename, int len)
#define REFRESH_BUFFER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer)
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out) #define BUFFER_SEEK_DELIMITER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
#define BUFFER_SEEK_STRING_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) #define BUFFER_SEEK_STRING_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
#define REFRESH_BUFFER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer)
#define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) #define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) #define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len)
#define BUFFER_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos) #define BUFFER_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos)
@ -371,6 +377,23 @@ struct Application_Links;
#define VIEW_SET_BUFFER_SIG(name) int name(Application_Links *app, View_Summary *view, int buffer_id) #define VIEW_SET_BUFFER_SIG(name) int name(Application_Links *app, View_Summary *view, int buffer_id)
// Directly get user input // Directly get user input
#define GET_USER_INPUT_SIG(name) User_Input name(Application_Links *context, unsigned int get_type, unsigned int abort_type)
// Queries
#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)
// Boundry type flags
#define BoundryWhitespace 0x1
#define BoundryToken 0x2
#define BoundryAlphanumeric 0x4
#define BoundryCamelCase 0x8
// Input type flags
#define EventOnAnyKey 0x1 #define EventOnAnyKey 0x1
#define EventOnEsc 0x2 #define EventOnEsc 0x2
#define EventOnLeftButton 0x4 #define EventOnLeftButton 0x4
@ -382,11 +405,7 @@ struct Application_Links;
#define EventOnMouseMove 0x20 #define EventOnMouseMove 0x20
#define EventOnMouse (EventOnButton | EventOnMouseMove) #define EventOnMouse (EventOnButton | EventOnMouseMove)
#define GET_USER_INPUT_SIG(name) User_Input name(Application_Links *context, unsigned int get_type, unsigned int abort_type)
// Queries
#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)
extern "C"{ extern "C"{
// Command exectuion // Command exectuion
@ -411,9 +430,10 @@ extern "C"{
typedef GET_PARAMETER_BUFFER_SIG(Get_Parameter_Buffer_Function); typedef GET_PARAMETER_BUFFER_SIG(Get_Parameter_Buffer_Function);
typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function); typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function);
typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function); typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function);
typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function); typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function);
typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function); typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function); typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function); typedef BUFFER_SET_POS_SIG(Buffer_Set_Pos_Function);
@ -466,9 +486,10 @@ struct Application_Links{
Get_Parameter_Buffer_Function *get_parameter_buffer; Get_Parameter_Buffer_Function *get_parameter_buffer;
Get_Buffer_By_Name_Function *get_buffer_by_name; Get_Buffer_By_Name_Function *get_buffer_by_name;
Refresh_Buffer_Function *refresh_buffer;
Buffer_Seek_Delimiter_Function *buffer_seek_delimiter; Buffer_Seek_Delimiter_Function *buffer_seek_delimiter;
Buffer_Seek_String_Function *buffer_seek_string; Buffer_Seek_String_Function *buffer_seek_string;
Refresh_Buffer_Function *refresh_buffer;
Buffer_Read_Range_Function *buffer_read_range; Buffer_Read_Range_Function *buffer_read_range;
Buffer_Replace_Range_Function *buffer_replace_range; Buffer_Replace_Range_Function *buffer_replace_range;
Buffer_Set_Pos_Function *buffer_set_pos; Buffer_Set_Pos_Function *buffer_set_pos;

33
4coder_style.h Normal file
View File

@ -0,0 +1,33 @@
enum Style_Tag{
Stag_Bar,
Stag_Bar_Active,
Stag_Base,
Stag_Pop1,
Stag_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,
};

344
4ed.cpp
View File

@ -230,33 +230,6 @@ COMMAND_DECL(seek_whitespace_right){
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
COMMAND_DECL(seek_whitespace_left){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_left(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_whitespace_up){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_up(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_whitespace_down){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_down(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
internal i32 internal i32
seek_token_left(Cpp_Token_Stack *tokens, i32 pos){ seek_token_left(Cpp_Token_Stack *tokens, i32 pos){
Cpp_Get_Token_Result get = cpp_get_token(tokens, pos); Cpp_Get_Token_Result get = cpp_get_token(tokens, pos);
@ -286,6 +259,141 @@ seek_token_right(Cpp_Token_Stack *tokens, i32 pos){
return token->start + token->size; return token->start + token->size;
} }
COMMAND_DECL(seek_left){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
u32 flags = BoundryWhitespace;
Command_Parameter *end = param_stack_end(&command->part);
Command_Parameter *param = param_stack_first(&command->part, end);
for (; param < end; param = param_next(param, end)){
int p = dynamic_to_int(&param->param.param);
switch (p){
case par_flags:
flags = dynamic_to_int(&param->param.value);
break;
}
}
i32 pos[4] = {0};
if (flags & (1)){
pos[0] = buffer_seek_whitespace_left(&file->state.buffer, view->cursor.pos);
}
if (flags & (1 << 1)){
if (file->state.tokens_complete){
pos[1] = seek_token_left(&file->state.token_stack, view->cursor.pos);
}
else{
pos[1] = buffer_seek_whitespace_left(&file->state.buffer, view->cursor.pos);
}
}
if (flags & (1 << 2)){
pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, view->cursor.pos);
if (flags & (1 << 3)){
pos[3] = buffer_seek_range_camel_left(&file->state.buffer, view->cursor.pos, pos[2]);
}
}
else{
if (flags & (1 << 3)){
pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, view->cursor.pos);
}
}
i32 new_pos = 0;
for (i32 i = 0; i < ArrayCount(pos); ++i){
if (pos[i] > new_pos) new_pos = pos[i];
}
view_cursor_move(view, new_pos);
}
COMMAND_DECL(seek_right){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
u32 flags = BoundryWhitespace;
Command_Parameter *end = param_stack_end(&command->part);
Command_Parameter *param = param_stack_first(&command->part, end);
for (; param < end; param = param_next(param, end)){
int p = dynamic_to_int(&param->param.param);
switch (p){
case par_flags:
flags = dynamic_to_int(&param->param.value);
break;
}
}
i32 size = buffer_size(&file->state.buffer);
i32 pos[4];
for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size;
if (flags & (1)){
pos[0] = buffer_seek_whitespace_right(&file->state.buffer, view->cursor.pos);
}
if (flags & (1 << 1)){
if (file->state.tokens_complete){
pos[1] = seek_token_right(&file->state.token_stack, view->cursor.pos);
}
else{
pos[1] = buffer_seek_whitespace_right(&file->state.buffer, view->cursor.pos);
}
}
if (flags & (1 << 2)){
pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, view->cursor.pos);
if (flags & (1 << 3)){
pos[3] = buffer_seek_range_camel_right(&file->state.buffer, view->cursor.pos, pos[2]);
}
}
else{
if (flags & (1 << 3)){
pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, view->cursor.pos);
}
}
i32 new_pos = size;
for (i32 i = 0; i < ArrayCount(pos); ++i){
if (pos[i] < new_pos) new_pos = pos[i];
}
view_cursor_move(view, new_pos);
}
COMMAND_DECL(seek_whitespace_left){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_left(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_whitespace_up){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_up(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_whitespace_down){
ProfileMomentFunction();
REQ_READABLE_VIEW(view);
REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_down(&file->state.buffer, view->cursor.pos);
view_cursor_move(view, pos);
}
COMMAND_DECL(seek_token_left){ COMMAND_DECL(seek_token_left){
ProfileMomentFunction(); ProfileMomentFunction();
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
@ -1676,7 +1784,7 @@ COMMAND_DECL(command_line){
} }
}break; }break;
case par_cli_flags: case par_flags:
{ {
flags = (u32)dynamic_to_int(&param->param.value); flags = (u32)dynamic_to_int(&param->param.value);
}break; }break;
@ -1814,6 +1922,8 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor
internal void internal void
fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_Set *working_set){ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_Set *working_set){
i32 lock_level;
int buffer_id;
*view = {}; *view = {};
if (vptr->in_use){ if (vptr->in_use){
@ -1823,7 +1933,30 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_
view->unwrapped_lines = vptr->unwrapped_lines; view->unwrapped_lines = vptr->unwrapped_lines;
if (vptr->file){ if (vptr->file){
view->buffer_id = (int)(vptr->file - working_set->files); lock_level = view_lock_level(vptr);
buffer_id = (int)(vptr->file - working_set->files);
if (lock_level <= 0){
view->buffer_id = buffer_id;
}
else{
view->buffer_id = 0;
}
if (lock_level <= 1){
view->locked_buffer_id = buffer_id;
}
else{
view->locked_buffer_id = 0;
}
if (lock_level <= 2){
view->hidden_buffer_id = buffer_id;
}
else{
view->hidden_buffer_id = 0;
}
view->mark = view_compute_cursor_from_pos(vptr, vptr->mark); view->mark = view_compute_cursor_from_pos(vptr, vptr->mark);
view->cursor = vptr->cursor; view->cursor = vptr->cursor;
view->preferred_x = vptr->preferred_x; view->preferred_x = vptr->preferred_x;
@ -1938,12 +2071,14 @@ extern "C"{
GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){ GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Buffer_Summary buffer = {}; Buffer_Summary buffer = {};
View *view = cmd->view;
Editing_File *file; Editing_File *file;
file = cmd->view->file; if (view_lock_level(view) <= LockLevel_Open){
file = view->file;
if (file){ if (file){
fill_buffer_summary(&buffer, file, &cmd->models->working_set); fill_buffer_summary(&buffer, file, &cmd->models->working_set);
}
} }
return(buffer); return(buffer);
@ -1979,13 +2114,6 @@ extern "C"{
return(buffer); return(buffer);
} }
REFRESH_BUFFER_SIG(external_refresh_buffer){
int result;
*buffer = external_get_buffer(app, buffer->buffer_id);
result = buffer->exists;
return(result);
}
BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){ BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Editing_File *file; Editing_File *file;
@ -2019,7 +2147,6 @@ extern "C"{
} }
BUFFER_SEEK_STRING_SIG(external_buffer_seek_string){ BUFFER_SEEK_STRING_SIG(external_buffer_seek_string){
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
App_Models *models; App_Models *models;
Editing_File *file; Editing_File *file;
@ -2059,6 +2186,13 @@ extern "C"{
return(result); return(result);
} }
REFRESH_BUFFER_SIG(external_refresh_buffer){
int result;
*buffer = external_get_buffer(app, buffer->buffer_id);
result = buffer->exists;
return(result);
}
BUFFER_READ_RANGE_SIG(external_buffer_read_range){ BUFFER_READ_RANGE_SIG(external_buffer_read_range){
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Editing_File *file; Editing_File *file;
@ -2458,6 +2592,8 @@ setup_command_table(){
SET(null); SET(null);
SET(write_character); SET(write_character);
SET(seek_left);
SET(seek_right);
SET(seek_whitespace_right); SET(seek_whitespace_right);
SET(seek_whitespace_left); SET(seek_whitespace_left);
SET(seek_whitespace_up); SET(seek_whitespace_up);
@ -3657,69 +3793,6 @@ App_Step_Sig(app_step){
ProfileEnd(command_coroutine); ProfileEnd(command_coroutine);
// NOTE(allen): command execution
ProfileStart(command);
if (!consumed_input[0] || !consumed_input[1]){
b32 consumed_input2[2] = {0};
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
if (models->command_coroutine != 0) break;
switch (vars->state){
case APP_STATE_EDIT:
{
Key_Event_Data key = get_single_key(&key_data, key_i);
b32 hit_esc = (key.keycode == key_esc);
cmd->key = key;
if (hit_esc || !consumed_input[0]){
View *view = cmd->view;
Command_Map *map = 0;
if (view) map = view->map;
if (map == 0) map = &models->map_top;
Command_Binding cmd_bind = map_extract_recursive(map, key);
if (cmd_bind.function){
if (hit_esc){
consumed_input2[1] = 1;
}
else{
consumed_input2[0] = 1;
}
Assert(models->command_coroutine == 0);
Coroutine *command_coroutine = system->create_coroutine(command_caller);
models->command_coroutine = command_coroutine;
Command_In cmd_in;
cmd_in.cmd = cmd;
cmd_in.bind = cmd_bind;
models->command_coroutine = system->launch_coroutine(models->command_coroutine,
&cmd_in, models->command_coroutine_flags);
models->prev_command = cmd_bind;
app_result.redraw = 1;
}
}
}break;
case APP_STATE_RESIZING:
{
if (key_data.count > 0){
vars->state = APP_STATE_EDIT;
}
}break;
}
}
consumed_input[0] |= consumed_input2[0];
consumed_input[1] |= consumed_input2[1];
}
update_command_data(vars, cmd);
ProfileEnd(command);
// NOTE(allen): pass raw input to the panels // NOTE(allen): pass raw input to the panels
ProfileStart(step); ProfileStart(step);
@ -3784,6 +3857,69 @@ App_Step_Sig(app_step){
update_command_data(vars, cmd); update_command_data(vars, cmd);
ProfileEnd(step); ProfileEnd(step);
// NOTE(allen): command execution
ProfileStart(command);
if (!consumed_input[0] || !consumed_input[1]){
b32 consumed_input2[2] = {0};
for (i32 key_i = 0; key_i < key_data.count; ++key_i){
if (models->command_coroutine != 0) break;
switch (vars->state){
case APP_STATE_EDIT:
{
Key_Event_Data key = get_single_key(&key_data, key_i);
b32 hit_esc = (key.keycode == key_esc);
cmd->key = key;
if (hit_esc || !consumed_input[0]){
View *view = cmd->view;
Command_Map *map = 0;
if (view) map = view->map;
if (map == 0) map = &models->map_top;
Command_Binding cmd_bind = map_extract_recursive(map, key);
if (cmd_bind.function){
if (hit_esc){
consumed_input2[1] = 1;
}
else{
consumed_input2[0] = 1;
}
Assert(models->command_coroutine == 0);
Coroutine *command_coroutine = system->create_coroutine(command_caller);
models->command_coroutine = command_coroutine;
Command_In cmd_in;
cmd_in.cmd = cmd;
cmd_in.bind = cmd_bind;
models->command_coroutine = system->launch_coroutine(models->command_coroutine,
&cmd_in, models->command_coroutine_flags);
models->prev_command = cmd_bind;
app_result.redraw = 1;
}
}
}break;
case APP_STATE_RESIZING:
{
if (key_data.count > 0){
vars->state = APP_STATE_EDIT;
}
}break;
}
}
consumed_input[0] |= consumed_input2[0];
consumed_input[1] |= consumed_input2[1];
}
update_command_data(vars, cmd);
ProfileEnd(command);
ProfileStart(resizing); ProfileStart(resizing);
// NOTE(allen): panel resizing // NOTE(allen): panel resizing
switch (vars->state){ switch (vars->state){

View File

@ -38,10 +38,11 @@
#include "4ed_font_set.cpp" #include "4ed_font_set.cpp"
#include "4ed_rendering_helper.cpp" #include "4ed_rendering_helper.cpp"
#include "4ed_style.h"
#include "4ed_style.cpp"
#include "4ed_template.cpp" #include "4ed_template.cpp"
#include "4ed_exchange.cpp" #include "4ed_exchange.cpp"
#include "4ed_command.cpp" #include "4ed_command.cpp"
#include "4ed_style.cpp"
#include "4ed_file.cpp" #include "4ed_file.cpp"
#include "4ed_gui.cpp" #include "4ed_gui.cpp"
#include "4ed_layout.cpp" #include "4ed_layout.cpp"

View File

@ -9,6 +9,25 @@
// TOP // TOP
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);
}
#include "buffer/4coder_shared.cpp" #include "buffer/4coder_shared.cpp"
#if BUFFER_EXPERIMENT_SCALPEL == 0 #if BUFFER_EXPERIMENT_SCALPEL == 0

View File

@ -2778,7 +2778,7 @@ theme_library_shit(System_Functions *system, Exchange *exchange,
begin_row(ui.layout, 3); begin_row(ui.layout, 3);
if (ui.state->style->name.size >= 1){ if (ui.state->style->name.size >= 1){
if (do_button(-2, ui.state, ui.layout, "Save", 2)){ if (do_button(-2, ui.state, ui.layout, "Save", 2)){
style_library_add(ui.styles, ui.state->style); //style_library_add(ui.styles, ui.state->style);
} }
} }
else{ else{
@ -2943,7 +2943,7 @@ theme_library_shit(System_Functions *system, Exchange *exchange,
if (do_button(-2, ui.state, ui.layout, "Finish Import", 2)){ if (do_button(-2, ui.state, ui.layout, "Finish Import", 2)){
Style *style = styles; Style *style = styles;
for (i32 i = 0; i < style_count; ++i, ++style){ for (i32 i = 0; i < style_count; ++i, ++style){
if (import_check[i]) style_library_add(ui.styles, style); //if (import_check[i]) style_library_add(ui.styles, style);
} }
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
} }

View File

@ -9,7 +9,8 @@
// TOP // TOP
#define ArrayCount(a) (sizeof(a)/sizeof(*a)) #define FCPP_STRING_IMPLEMENTATION
#include "4coder_string.h"
struct Struct_Field{ struct Struct_Field{
char *type; char *type;
@ -48,6 +49,11 @@ void struct_end(FILE *file){
} }
void enum_begin(FILE *file, char *name){
fprintf(file, "enum %s{\n", name);
}
char *keys_that_need_codes[] = { char *keys_that_need_codes[] = {
"back", "back",
"up", "up",
@ -318,6 +324,120 @@ char* generate_version(){
return(filename); return(filename);
} }
//////////////////////////////////////////////////////////////////////////////////////////////////
char* bar_style_fields[] = {
"bar",
"bar_active",
"base",
"pop1",
"pop2",
};
char* main_style_fields[] = {
"back",
"margin",
"margin_hover",
"margin_active",
"cursor",
"at_cursor",
"highlight",
"at_highlight",
"mark",
"default",
"comment",
"keyword",
"str_constant",
"char_constant",
"int_constant",
"float_constant",
"bool_constant",
"preproc",
"include",
"special_character",
"highlight_junk",
"highlight_white",
"paste",
"undo",
"next_undo",
};
static void
do_style_tag(FILE *file, char *tag){
int j, is_first;
char *str_, c;
String str;
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);
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;
}
}
fprintf(file, "Stag_%s,\n", str.str);
free(str.str);
}
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;
int count, i;
file = fopen(filename_4coder, "wb");
enum_begin(file, "Style_Tag");
{
count = ArrayCount(bar_style_fields);
for (i = 0; i < count; ++i){
do_style_tag(file, bar_style_fields[i]);
}
count = ArrayCount(main_style_fields);
for (i = 0; i < count; ++i){
do_style_tag(file, main_style_fields[i]);
}
}
struct_end(file);
fclose(file);
file = fopen(filename_4ed, "wb");
struct_begin(file, "Interactive_Style");
{
count = ArrayCount(bar_style_fields);
for (i = 0; i < count; ++i){
fprintf(file, "u32 %s_color;\n", bar_style_fields[i]);
}
}
struct_end(file);
struct_begin(file, "Style_Main_Data");
{
count = ArrayCount(main_style_fields);
for (i = 0; i < count; ++i){
fprintf(file, "u32 %s_color;\n", main_style_fields[i]);
}
fprintf(file, "Interactive_Style file_info_style;\n");
}
struct_end(file);
fclose(file);
return(filename);
}
int main(){ int main(){
char *filename; char *filename;
@ -330,6 +450,9 @@ int main(){
filename = generate_version(); filename = generate_version();
printf("gen success: %s\n", filename); printf("gen success: %s\n", filename);
filename = generate_style();
printf("gen success: %s\n", filename);
} }
// BOTTOM // BOTTOM

View File

@ -13,124 +13,17 @@
// Font changing UI should be in the library menu now, it's not tied to the fonts any more // 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 // 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{ struct Style_Font{
i16 font_id; i16 font_id;
i16 font_changed; i16 font_changed;
}; };
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;
};
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
};
struct Style_Color_Specifier{
u32 tag;
u32 color;
};
struct Style_File_Format{
i32 name_size;
char name[24];
i32 color_specifier_count;
};
struct Style{ struct Style{
char name_[24]; char name_[24];
String name; String name;
Style_Main_Data main; Style_Main_Data main;
}; };
struct Style_Library{
Style styles[64];
i32 count, max;
};
internal void internal void
style_copy(Style *dst, Style *src){ style_copy(Style *dst, Style *src){
*dst = *src; *dst = *src;
@ -151,9 +44,9 @@ style_index_by_tag(Style *s, u32 tag){
switch (tag){ switch (tag){
case Stag_Bar: result = &s->main.file_info_style.bar_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_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_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_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_Pop2: result = &s->main.file_info_style.pop2_color; break;
case Stag_Back: result = &s->main.back_color; break; case Stag_Back: result = &s->main.back_color; break;
case Stag_Margin: result = &s->main.margin_color; break; case Stag_Margin: result = &s->main.margin_color; break;
@ -189,6 +82,24 @@ style_index_by_tag(Style *s, u32 tag){
return result; return result;
} }
struct Style_Library{
Style styles[64];
i32 count, max;
};
#if 0
struct Style_Color_Specifier{
u32 tag;
u32 color;
};
struct Style_File_Format{
i32 name_size;
char name[24];
i32 color_specifier_count;
};
internal b32 internal b32
style_library_add(Style_Library *library, Style *style){ style_library_add(Style_Library *library, Style *style){
b32 result = 0; b32 result = 0;
@ -234,6 +145,7 @@ style_format_for_file(Font_Set *set, Style *style, Style_File_Format *out){
return (Style_File_Format*)spec; return (Style_File_Format*)spec;
} }
#endif
// BOTTOM // BOTTOM

37
4ed_style.h Normal file
View File

@ -0,0 +1,37 @@
struct Interactive_Style{
u32 bar_color;
u32 bar_active_color;
u32 base_color;
u32 pop1_color;
u32 pop2_color;
};
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 next_undo_color;
Interactive_Style file_info_style;
};