Rewrite of 4ed_api_implementation to use Models instead of Command_Data
This commit is contained in:
parent
3b5addace1
commit
79e88ac55e
|
@ -46,7 +46,7 @@ struct Application_Links;
|
|||
#define VIEW_SET_BUFFER_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags)
|
||||
#define VIEW_POST_FADE_SIG(n) bool32 n(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color)
|
||||
#define VIEW_BEGIN_UI_MODE_SIG(n) bool32 n(Application_Links *app, View_Summary *view)
|
||||
#define VIEW_END_UI_MODE_SIG(n) int32_t n(Application_Links *app, View_Summary *view)
|
||||
#define VIEW_END_UI_MODE_SIG(n) bool32 n(Application_Links *app, View_Summary *view)
|
||||
#define VIEW_SET_UI_SIG(n) bool32 n(Application_Links *app, View_Summary *view, UI_Control *control, UI_Quit_Function_Type *quit_function)
|
||||
#define VIEW_GET_UI_COPY_SIG(n) UI_Control n(Application_Links *app, View_Summary *view, struct Partition *part)
|
||||
#define CREATE_USER_MANAGED_SCOPE_SIG(n) Managed_Scope n(Application_Links *app)
|
||||
|
@ -649,7 +649,7 @@ static inline bool32 view_set_highlight(Application_Links *app, View_Summary *vi
|
|||
static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer(app, view, buffer_id, flags));}
|
||||
static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade(app, view, seconds, start, end, color));}
|
||||
static inline bool32 view_begin_ui_mode(Application_Links *app, View_Summary *view){return(app->view_begin_ui_mode(app, view));}
|
||||
static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode(app, view));}
|
||||
static inline bool32 view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode(app, view));}
|
||||
static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control, UI_Quit_Function_Type *quit_function){return(app->view_set_ui(app, view, control, quit_function));}
|
||||
static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy(app, view, part));}
|
||||
static inline Managed_Scope create_user_managed_scope(Application_Links *app){return(app->create_user_managed_scope(app));}
|
||||
|
@ -768,7 +768,7 @@ static inline bool32 view_set_highlight(Application_Links *app, View_Summary *vi
|
|||
static inline bool32 view_set_buffer(Application_Links *app, View_Summary *view, Buffer_ID buffer_id, Set_Buffer_Flag flags){return(app->view_set_buffer_(app, view, buffer_id, flags));}
|
||||
static inline bool32 view_post_fade(Application_Links *app, View_Summary *view, float seconds, int32_t start, int32_t end, int_color color){return(app->view_post_fade_(app, view, seconds, start, end, color));}
|
||||
static inline bool32 view_begin_ui_mode(Application_Links *app, View_Summary *view){return(app->view_begin_ui_mode_(app, view));}
|
||||
static inline int32_t view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode_(app, view));}
|
||||
static inline bool32 view_end_ui_mode(Application_Links *app, View_Summary *view){return(app->view_end_ui_mode_(app, view));}
|
||||
static inline bool32 view_set_ui(Application_Links *app, View_Summary *view, UI_Control *control, UI_Quit_Function_Type *quit_function){return(app->view_set_ui_(app, view, control, quit_function));}
|
||||
static inline UI_Control view_get_ui_copy(Application_Links *app, View_Summary *view, struct Partition *part){return(app->view_get_ui_copy_(app, view, part));}
|
||||
static inline Managed_Scope create_user_managed_scope(Application_Links *app){return(app->create_user_managed_scope_(app));}
|
||||
|
|
95
4ed.cpp
95
4ed.cpp
|
@ -168,7 +168,6 @@ do_feedback_message(System_Functions *system, Models *models, String value){
|
|||
|
||||
// Commands
|
||||
|
||||
#define USE_MODELS(n) Models *n = command->models
|
||||
#define USE_VARS(n) App_Vars *n = command->vars
|
||||
#define USE_FILE(n,v) Editing_File *n = (v)->file_data.file
|
||||
|
||||
|
@ -188,7 +187,7 @@ do_feedback_message(System_Functions *system, Models *models, String value){
|
|||
#define REQ_FILE(n,v) Editing_File *n = (v)->transient.file_data.file; if (n == 0) return
|
||||
#define REQ_FILE_HISTORY(n,v) Editing_File *n = (v)->transient.file_data.file; if (n == 0 || n->state.undo.undo.edits == 0) return
|
||||
|
||||
#define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Command_Data *command, Command_Binding binding)
|
||||
#define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Models *models, Command_Binding binding)
|
||||
|
||||
internal View*
|
||||
panel_make_empty(System_Functions *system, Models *models, Panel *panel){
|
||||
|
@ -198,9 +197,7 @@ panel_make_empty(System_Functions *system, Models *models, Panel *panel){
|
|||
return(new_view.view);
|
||||
}
|
||||
|
||||
COMMAND_DECL(null){
|
||||
AllowLocal(command);
|
||||
}
|
||||
COMMAND_DECL(null){}
|
||||
|
||||
internal void
|
||||
view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack *stack, Edit_Type expected_type){
|
||||
|
@ -216,17 +213,29 @@ view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack
|
|||
}
|
||||
|
||||
COMMAND_DECL(undo){
|
||||
USE_MODELS(models);
|
||||
REQ_OPEN_VIEW(view);
|
||||
REQ_FILE_HISTORY(file, view);
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
View *view = active_panel->view;
|
||||
if (view_lock_flags(view) != 0){
|
||||
return;
|
||||
}
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (file->state.undo.undo.edits == 0){
|
||||
return;
|
||||
}
|
||||
view_undo_redo(system, models, view, &file->state.undo.undo, ED_UNDO);
|
||||
Assert(file->state.undo.undo.size >= 0);
|
||||
}
|
||||
|
||||
COMMAND_DECL(redo){
|
||||
USE_MODELS(models);
|
||||
REQ_OPEN_VIEW(view);
|
||||
REQ_FILE_HISTORY(file, view);
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
View *view = active_panel->view;
|
||||
if (view_lock_flags(view) != 0){
|
||||
return;
|
||||
}
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (file->state.undo.undo.edits == 0){
|
||||
return;
|
||||
}
|
||||
view_undo_redo(system, models, view, &file->state.undo.redo, ED_REDO);
|
||||
Assert(file->state.undo.undo.size >= 0);
|
||||
}
|
||||
|
@ -235,12 +244,12 @@ COMMAND_DECL(redo){
|
|||
// - Perform a diff
|
||||
// - If the diff is not tremendously big, apply the edits.
|
||||
COMMAND_DECL(reopen){
|
||||
USE_MODELS(models);
|
||||
USE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
if (file->canon.name.str == 0) return;
|
||||
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
View *view = active_panel->view;
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (file->canon.name.str == 0){
|
||||
return;
|
||||
}
|
||||
if (file->canon.name.size != 0){
|
||||
Plat_Handle handle;
|
||||
if (system->load_handle(file->canon.name.str, &handle)){
|
||||
|
@ -307,17 +316,15 @@ COMMAND_DECL(reopen){
|
|||
}
|
||||
|
||||
COMMAND_DECL(save){
|
||||
USE_MODELS(models);
|
||||
USE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
View *view = active_panel->view;
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
if (!file->is_dummy && file_is_ready(file) && buffer_can_save(file)){
|
||||
save_file(system, models, file);
|
||||
}
|
||||
}
|
||||
|
||||
COMMAND_DECL(user_callback){
|
||||
USE_MODELS(models);
|
||||
if (binding.custom != 0){
|
||||
binding.custom(&models->app_links);
|
||||
}
|
||||
|
@ -351,11 +358,11 @@ setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){
|
|||
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
|
||||
for (i32 i = 0; i < 4; ++i){
|
||||
u8 mdfr = mdfr_array[i];
|
||||
map_add(commands, key_left, mdfr, command_null);
|
||||
map_add(commands, key_right, mdfr, command_null);
|
||||
map_add(commands, key_up, mdfr, command_null);
|
||||
map_add(commands, key_down, mdfr, command_null);
|
||||
map_add(commands, key_back, mdfr, command_null);
|
||||
map_add(commands, key_left , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_right, mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_up , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_down , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
map_add(commands, key_back , mdfr, command_null, (Custom_Command_Function*)0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1089,15 +1096,12 @@ App_Init_Sig(app_init){
|
|||
|
||||
// NOTE(allen): init first panel
|
||||
Command_Data *cmd = &models->command_data;
|
||||
|
||||
cmd->models = models;
|
||||
cmd->vars = vars;
|
||||
cmd->system = system;
|
||||
cmd->live_set = &models->live_set;
|
||||
|
||||
cmd->screen_width = target->width;
|
||||
cmd->screen_height = target->height;
|
||||
|
||||
cmd->key = null_key_event_data;
|
||||
|
||||
File_Init init_files[] = {
|
||||
|
@ -1302,6 +1306,19 @@ App_Step_Sig(app_step){
|
|||
}
|
||||
}
|
||||
|
||||
Panel *mouse_panel = 0;
|
||||
b32 mouse_in_edit_area = false;
|
||||
b32 mouse_in_margin_area = false;
|
||||
b32 mouse_on_divider = false;
|
||||
b32 mouse_divider_vertical = false;
|
||||
|
||||
#if 0
|
||||
////
|
||||
////
|
||||
//// BEGIN INPUT PROCESSING
|
||||
////
|
||||
////
|
||||
|
||||
// NOTE(allen): prepare input information
|
||||
b32 has_keyboard_event = (input->keys.count > 0);
|
||||
{
|
||||
|
@ -1786,11 +1803,16 @@ App_Step_Sig(app_step){
|
|||
}
|
||||
}
|
||||
|
||||
////
|
||||
////
|
||||
//// END INPUT PROCESSING
|
||||
////
|
||||
////
|
||||
#endif
|
||||
|
||||
// NOTE(allen): step panels
|
||||
{
|
||||
Command_Data *command = cmd;
|
||||
USE_VIEW(active_view);
|
||||
USE_PANEL(active_panel);
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
|
||||
for (Panel *panel = models->layout.used_sentinel.next;
|
||||
panel != &models->layout.used_sentinel;
|
||||
|
@ -1862,11 +1884,8 @@ App_Step_Sig(app_step){
|
|||
{
|
||||
begin_render_section(target, system);
|
||||
|
||||
Command_Data *command = cmd;
|
||||
USE_PANEL(active_panel);
|
||||
USE_VIEW(active_view);
|
||||
|
||||
cmd->target = target;
|
||||
Panel *active_panel = &models->layout.panels[models->layout.active_panel];
|
||||
View *active_view = active_panel->view;
|
||||
|
||||
// NOTE(allen): render the panels
|
||||
for (Panel *panel = models->layout.used_sentinel.next;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,7 +27,7 @@ struct App_Settings{
|
|||
b32 use_hinting;
|
||||
};
|
||||
|
||||
struct Command_Data{
|
||||
struct Command_Data___{
|
||||
struct Models *models;
|
||||
struct App_Vars *vars;
|
||||
System_Functions *system;
|
||||
|
@ -81,8 +81,6 @@ struct Models{
|
|||
Scroll_Rule_Function *scroll_rule;
|
||||
Buffer_Name_Resolver_Function *buffer_name_resolver;
|
||||
|
||||
Command_Data command_data;
|
||||
|
||||
Style_Library styles;
|
||||
u32 *palette;
|
||||
|
||||
|
@ -117,6 +115,22 @@ struct Models{
|
|||
|
||||
i32 previous_mouse_x;
|
||||
i32 previous_mouse_y;
|
||||
|
||||
// System Context
|
||||
System_Functions *system;
|
||||
struct App_Vars *vars;
|
||||
|
||||
// Event Context
|
||||
Key_Event_Data key;
|
||||
|
||||
// Render Context
|
||||
View *render_view;
|
||||
Render_Target *target;
|
||||
i32_Rect render_rect;
|
||||
Full_Cursor render_cursor;
|
||||
Range render_range;
|
||||
Buffer_Render_Item *render_items;
|
||||
i32 render_item_count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
@ -183,7 +197,7 @@ struct App_Coroutine_State{
|
|||
};
|
||||
|
||||
struct Command_In{
|
||||
Command_Data *cmd;
|
||||
Models *models;
|
||||
Command_Binding bind;
|
||||
};
|
||||
|
||||
|
|
|
@ -81,8 +81,6 @@ get_map(Mapping *mapping, i32 mapid){
|
|||
#define COMMAND_HASH_EMPTY 0
|
||||
#define COMMAND_HASH_ERASED max_u64
|
||||
|
||||
internal void command_null(Command_Data *command);
|
||||
|
||||
internal u64
|
||||
map_hash(Key_Code event_code, u8 modifiers){
|
||||
u64 result = (event_code << 8) | modifiers;
|
||||
|
@ -90,7 +88,7 @@ map_hash(Key_Code event_code, u8 modifiers){
|
|||
}
|
||||
|
||||
internal b32
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, Custom_Command_Function *custom = 0, b32 override_original = true){
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, Custom_Command_Function *custom){
|
||||
b32 result = false;
|
||||
Assert(map->count * 8 < map->max * 7);
|
||||
u64 hash = map_hash(event_code, modifiers);
|
||||
|
@ -107,23 +105,21 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
|
|||
entry = map->commands[index];
|
||||
}
|
||||
|
||||
if (override_original || !result){
|
||||
Command_Binding bind = {0};
|
||||
bind.function = function;
|
||||
bind.custom = custom;
|
||||
bind.hash = hash;
|
||||
map->commands[index] = bind;
|
||||
if (!result){
|
||||
++map->count;
|
||||
}
|
||||
Command_Binding bind = {0};
|
||||
bind.function = function;
|
||||
bind.custom = custom;
|
||||
bind.hash = hash;
|
||||
map->commands[index] = bind;
|
||||
if (!result){
|
||||
++map->count;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline b32
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, u64 custom_id, b32 override_original = true){
|
||||
return (map_add(map, event_code, modifiers, function, (Custom_Command_Function*)custom_id, override_original));
|
||||
map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *function, u64 custom_id){
|
||||
return(map_add(map, event_code, modifiers, function, (Custom_Command_Function*)custom_id));
|
||||
}
|
||||
|
||||
internal b32
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define FRED_COMMAND_H
|
||||
|
||||
#define Command_Function_Sig(name) \
|
||||
void (name)(System_Functions *system, struct Command_Data *command, struct Command_Binding binding)
|
||||
void (name)(System_Functions *system, struct Models *models, struct Command_Binding binding)
|
||||
|
||||
typedef Command_Function_Sig(Command_Function);
|
||||
|
||||
|
|
30
4ed_view.cpp
30
4ed_view.cpp
|
@ -1145,16 +1145,14 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v
|
|||
|
||||
internal void
|
||||
do_core_render(Application_Links *app){
|
||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||
Models *models = cmd->models;
|
||||
Render_Target *target = cmd->target;
|
||||
View *view = cmd->render_view;
|
||||
i32_Rect rect = cmd->render_rect;
|
||||
Full_Cursor render_cursor = cmd->render_cursor;
|
||||
Range on_screen_range = cmd->render_range;
|
||||
Buffer_Render_Item *items = cmd->render_items;
|
||||
i32 item_count = cmd->render_item_count;
|
||||
|
||||
Models *models = (Models*)app->cmd_context;
|
||||
Render_Target *target = models->target;
|
||||
View *view = models->render_view;
|
||||
i32_Rect rect = models->render_rect;
|
||||
Full_Cursor render_cursor = models->render_cursor;
|
||||
Range on_screen_range = models->render_range;
|
||||
Buffer_Render_Item *items = models->render_items;
|
||||
i32 item_count = models->render_item_count;
|
||||
render_loaded_file_in_view__inner(models, target, view,
|
||||
rect, render_cursor, on_screen_range,
|
||||
items, item_count);
|
||||
|
@ -1283,12 +1281,12 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
|
|||
////
|
||||
|
||||
if (models->render_caller != 0){
|
||||
models->command_data.render_view = view;
|
||||
models->command_data.render_rect = rect;
|
||||
models->command_data.render_cursor = render_cursor;
|
||||
models->command_data.render_range = on_screen_range;
|
||||
models->command_data.render_items = items;
|
||||
models->command_data.render_item_count = item_count;
|
||||
models->render_view = view;
|
||||
models->render_rect = rect;
|
||||
models->render_cursor = render_cursor;
|
||||
models->render_range = on_screen_range;
|
||||
models->render_items = items;
|
||||
models->render_item_count = item_count;
|
||||
models->render_caller(&models->app_links, view->persistent.id + 1, on_screen_range, do_core_render);
|
||||
}
|
||||
else{
|
||||
|
|
Loading…
Reference in New Issue