2016-06-29 17:16:08 +00:00
|
|
|
/*
|
2016-09-03 01:15:53 +00:00
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 12.12.2014
|
|
|
|
*
|
|
|
|
* Application layer for project codename "4ed"
|
|
|
|
*
|
|
|
|
*/
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal void
|
2019-06-01 23:33:31 +00:00
|
|
|
output_file_append(Models *models, Editing_File *file, String_Const_u8 value){
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 end = buffer_size(&file->state.buffer);
|
2019-08-12 09:16:04 +00:00
|
|
|
Edit_Behaviors behaviors = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
edit_single(models, file, Ii64(end), value, behaviors);
|
2018-06-02 00:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-10-03 17:57:44 +00:00
|
|
|
file_cursor_to_end(Models *models, Editing_File *file){
|
2018-06-02 00:29:36 +00:00
|
|
|
Assert(file != 0);
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 pos = buffer_size(&file->state.buffer);
|
2019-02-05 09:13:38 +00:00
|
|
|
Layout *layout = &models->layout;
|
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
2018-06-02 00:29:36 +00:00
|
|
|
View *view = panel->view;
|
2019-02-27 05:49:35 +00:00
|
|
|
if (view->file != file){
|
2018-06-02 00:29:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
view_set_cursor(models, view, pos);
|
|
|
|
view->mark = pos;
|
2017-11-22 20:05:58 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Commands
|
|
|
|
|
|
|
|
#define USE_VARS(n) App_Vars *n = command->vars
|
|
|
|
#define USE_FILE(n,v) Editing_File *n = (v)->file_data.file
|
|
|
|
|
2017-03-17 17:45:41 +00:00
|
|
|
#define USE_PANEL(n) Panel *n = 0; do{ \
|
2016-09-21 22:34:19 +00:00
|
|
|
i32 panel_index = command->models->layout.active_panel; \
|
|
|
|
n = command->models->layout.panels + panel_index; \
|
2017-03-17 17:45:41 +00:00
|
|
|
}while(false)
|
2016-09-21 22:34:19 +00:00
|
|
|
|
2017-03-17 17:45:41 +00:00
|
|
|
#define USE_VIEW(n) View *n = 0; do{ \
|
|
|
|
i32 panel_index = command->models->layout.active_panel; \
|
|
|
|
Panel *__panel__ = command->models->layout.panels + panel_index; \
|
|
|
|
n = __panel__->view; \
|
|
|
|
}while(false)
|
2016-09-21 22:34:19 +00:00
|
|
|
|
2018-03-24 10:06:45 +00:00
|
|
|
#define REQ_OPEN_VIEW(n) USE_VIEW(n); if (view_lock_flags(n) != 0) return
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-10 09:18:34 +00:00
|
|
|
#define REQ_FILE(n,v) Editing_File *n = (v)->file_data.file; if (n == 0) return
|
|
|
|
#define REQ_FILE_HISTORY(n,v) Editing_File *n = (v)->file_data.file; if (n == 0 || n->state.undo.undo.edits == 0) return
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
|
|
|
|
DELTA_RULE_SIG(fallback_scroll_rule){
|
|
|
|
return(pending_delta);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
#include "4ed_api_implementation.cpp"
|
|
|
|
|
|
|
|
// App Functions
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
internal void
|
|
|
|
fill_hardcode_default_style(Color_Table color_table){
|
|
|
|
color_table.vals[Stag_Back] = 0xFF0C0C0C;
|
|
|
|
color_table.vals[Stag_Margin] = 0xFF181818;
|
|
|
|
color_table.vals[Stag_Margin_Hover] = 0xFF252525;
|
|
|
|
color_table.vals[Stag_Margin_Active] = 0xFF323232;
|
|
|
|
color_table.vals[Stag_List_Item] = color_table.vals[Stag_Margin];
|
|
|
|
color_table.vals[Stag_List_Item_Hover] = color_table.vals[Stag_Margin_Hover];
|
|
|
|
color_table.vals[Stag_List_Item_Active] = color_table.vals[Stag_Margin_Active];
|
|
|
|
color_table.vals[Stag_Cursor] = 0xFF00EE00;
|
|
|
|
color_table.vals[Stag_Highlight] = 0xFFDDEE00;
|
|
|
|
color_table.vals[Stag_Mark] = 0xFF494949;
|
|
|
|
color_table.vals[Stag_Default] = 0xFF90B080;
|
|
|
|
color_table.vals[Stag_At_Cursor] = color_table.vals[Stag_Back];
|
|
|
|
color_table.vals[Stag_Highlight_Cursor_Line] = 0xFF1E1E1E;
|
|
|
|
color_table.vals[Stag_At_Highlight] = 0xFFFF44DD;
|
|
|
|
color_table.vals[Stag_Comment] = 0xFF2090F0;
|
|
|
|
color_table.vals[Stag_Keyword] = 0xFFD08F20;
|
|
|
|
color_table.vals[Stag_Str_Constant] = 0xFF50FF30;
|
|
|
|
color_table.vals[Stag_Char_Constant] = color_table.vals[Stag_Str_Constant];
|
|
|
|
color_table.vals[Stag_Int_Constant] = color_table.vals[Stag_Str_Constant];
|
|
|
|
color_table.vals[Stag_Float_Constant] = color_table.vals[Stag_Str_Constant];
|
|
|
|
color_table.vals[Stag_Bool_Constant] = color_table.vals[Stag_Str_Constant];
|
|
|
|
color_table.vals[Stag_Include] = color_table.vals[Stag_Str_Constant];
|
|
|
|
color_table.vals[Stag_Preproc] = color_table.vals[Stag_Default];
|
|
|
|
color_table.vals[Stag_Special_Character] = 0xFFFF0000;
|
|
|
|
color_table.vals[Stag_Ghost_Character] = color_blend(color_table.vals[Stag_Default],
|
|
|
|
0.5f,
|
|
|
|
color_table.vals[Stag_Back]);
|
|
|
|
|
|
|
|
color_table.vals[Stag_Paste] = 0xFFDDEE00;
|
|
|
|
color_table.vals[Stag_Undo] = 0xFF00DDEE;
|
|
|
|
|
|
|
|
color_table.vals[Stag_Highlight_Junk] = 0xff3a0000;
|
|
|
|
color_table.vals[Stag_Highlight_White] = 0xff003a3a;
|
|
|
|
|
|
|
|
color_table.vals[Stag_Bar] = 0xFF888888;
|
|
|
|
color_table.vals[Stag_Base] = 0xFF000000;
|
|
|
|
color_table.vals[Stag_Pop1] = 0xFF3C57DC;
|
|
|
|
color_table.vals[Stag_Pop2] = 0xFFFF0000;
|
|
|
|
|
|
|
|
color_table.vals[Stag_Back_Cycle_1] = 0x10A00000;
|
|
|
|
color_table.vals[Stag_Back_Cycle_2] = 0x0C00A000;
|
|
|
|
color_table.vals[Stag_Back_Cycle_3] = 0x0C0000A0;
|
|
|
|
color_table.vals[Stag_Back_Cycle_4] = 0x0CA0A000;
|
|
|
|
color_table.vals[Stag_Text_Cycle_1] = 0xFFA00000;
|
|
|
|
color_table.vals[Stag_Text_Cycle_2] = 0xFF00A000;
|
|
|
|
color_table.vals[Stag_Text_Cycle_3] = 0xFF0030B0;
|
|
|
|
color_table.vals[Stag_Text_Cycle_4] = 0xFFA0A000;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
internal void
|
2017-06-16 23:10:50 +00:00
|
|
|
app_hardcode_default_style(Models *models){
|
2019-02-25 23:42:13 +00:00
|
|
|
Color_Table color_table = {};
|
|
|
|
color_table.count = Stag_COUNT;
|
2019-10-01 02:06:21 +00:00
|
|
|
color_table.vals = push_array(models->arena, u32, color_table.count);
|
2019-02-25 23:42:13 +00:00
|
|
|
fill_hardcode_default_style(color_table);
|
|
|
|
models->fallback_color_table = color_table;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-23 23:07:18 +00:00
|
|
|
internal void
|
2017-07-19 20:07:50 +00:00
|
|
|
init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, i32 argc, char **argv){
|
2016-09-19 02:49:25 +00:00
|
|
|
char *arg = 0;
|
|
|
|
Command_Line_Mode mode = CLMode_App;
|
2016-06-29 17:16:08 +00:00
|
|
|
Command_Line_Action action = CLAct_Nothing;
|
2017-06-12 17:40:54 +00:00
|
|
|
b32 strict = false;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
settings->init_files_max = ArrayCount(settings->init_files);
|
2017-07-19 20:07:50 +00:00
|
|
|
for (i32 i = 1; i <= argc; ++i){
|
|
|
|
if (i == argc){
|
2016-09-19 02:49:25 +00:00
|
|
|
arg = "";
|
|
|
|
}
|
|
|
|
else{
|
2017-07-19 20:07:50 +00:00
|
|
|
arg = argv[i];
|
2016-09-19 02:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (arg[0] == '-' && arg[1] == '-'){
|
|
|
|
char *long_arg_name = arg+2;
|
2019-06-01 23:33:31 +00:00
|
|
|
if (string_match(SCu8(long_arg_name),
|
|
|
|
string_u8_litexpr("custom"))){
|
2016-09-19 02:49:25 +00:00
|
|
|
mode = CLMode_Custom;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode){
|
|
|
|
case CLMode_App:
|
2016-06-29 17:16:08 +00:00
|
|
|
{
|
2016-09-19 02:49:25 +00:00
|
|
|
switch (action){
|
|
|
|
case CLAct_Nothing:
|
|
|
|
{
|
|
|
|
if (arg[0] == '-'){
|
|
|
|
action = CLAct_Ignore;
|
|
|
|
switch (arg[1]){
|
2017-06-12 17:40:54 +00:00
|
|
|
case 'd': action = CLAct_CustomDLL; strict = false; break;
|
|
|
|
case 'D': action = CLAct_CustomDLL; strict = true; break;
|
2016-09-19 02:49:25 +00:00
|
|
|
|
|
|
|
case 'i': action = CLAct_InitialFilePosition; break;
|
|
|
|
|
|
|
|
case 'w': action = CLAct_WindowSize; break;
|
|
|
|
case 'W': action = CLAct_WindowMaximize; break;
|
|
|
|
case 'p': action = CLAct_WindowPosition; break;
|
|
|
|
case 'F': action = CLAct_WindowFullscreen; break;
|
|
|
|
|
|
|
|
case 'f': action = CLAct_FontSize; break;
|
2017-06-12 17:40:54 +00:00
|
|
|
case 'h': action = CLAct_FontUseHinting; --i; break;
|
2016-09-19 02:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (arg[0] != 0){
|
|
|
|
if (settings->init_files_count < settings->init_files_max){
|
2017-06-12 17:40:54 +00:00
|
|
|
i32 index = settings->init_files_count++;
|
2016-09-19 02:49:25 +00:00
|
|
|
settings->init_files[index] = arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2016-09-19 02:49:25 +00:00
|
|
|
case CLAct_CustomDLL:
|
|
|
|
{
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->custom_dll_is_strict = (b8)strict;
|
2017-07-19 20:07:50 +00:00
|
|
|
if (i < argc){
|
|
|
|
plat_settings->custom_dll = argv[i];
|
2016-09-19 02:49:25 +00:00
|
|
|
}
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_InitialFilePosition:
|
|
|
|
{
|
2017-07-19 20:07:50 +00:00
|
|
|
if (i < argc){
|
2019-06-01 23:33:31 +00:00
|
|
|
settings->initial_line = (i32)string_to_integer(SCu8(argv[i]), 10);
|
2016-09-19 02:49:25 +00:00
|
|
|
}
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_WindowSize:
|
|
|
|
{
|
2017-07-19 20:07:50 +00:00
|
|
|
if (i + 1 < argc){
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->set_window_size = true;
|
2017-06-17 23:41:27 +00:00
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
i32 w = (i32)string_to_integer(SCu8(argv[i]), 10);
|
|
|
|
i32 h = (i32)string_to_integer(SCu8(argv[i + 1]), 10);
|
2017-06-17 23:41:27 +00:00
|
|
|
if (w > 0){
|
|
|
|
plat_settings->window_w = w;
|
|
|
|
}
|
|
|
|
if (h > 0){
|
|
|
|
plat_settings->window_h = h;
|
|
|
|
}
|
2016-09-19 02:49:25 +00:00
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_WindowMaximize:
|
|
|
|
{
|
|
|
|
--i;
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->maximize_window = true;
|
2016-09-19 02:49:25 +00:00
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_WindowPosition:
|
|
|
|
{
|
2017-07-19 20:07:50 +00:00
|
|
|
if (i + 1 < argc){
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->set_window_pos = true;
|
2017-06-17 23:41:27 +00:00
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
i32 x = (i32)string_to_integer(SCu8(argv[i]), 10);
|
|
|
|
i32 y = (i32)string_to_integer(SCu8(argv[i + 1]), 10);
|
2017-06-17 23:41:27 +00:00
|
|
|
if (x > 0){
|
|
|
|
plat_settings->window_x = x;
|
|
|
|
}
|
|
|
|
if (y > 0){
|
|
|
|
plat_settings->window_y = y;
|
|
|
|
}
|
2016-09-19 02:49:25 +00:00
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_WindowFullscreen:
|
|
|
|
{
|
|
|
|
--i;
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->fullscreen_window = true;
|
2016-09-19 02:49:25 +00:00
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_FontSize:
|
|
|
|
{
|
2017-07-19 20:07:50 +00:00
|
|
|
if (i < argc){
|
2019-09-28 00:49:59 +00:00
|
|
|
settings->font_size = (i32)string_to_integer(SCu8(argv[i]), 10);
|
2016-09-19 02:49:25 +00:00
|
|
|
}
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
case CLAct_FontUseHinting:
|
2016-09-19 02:49:25 +00:00
|
|
|
{
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->use_hinting = true;
|
2017-11-20 23:31:57 +00:00
|
|
|
settings->use_hinting = plat_settings->use_hinting;
|
2016-09-19 02:49:25 +00:00
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
}break;
|
2016-07-03 22:29:07 +00:00
|
|
|
|
2016-09-19 02:49:25 +00:00
|
|
|
case CLMode_Custom:
|
2016-07-03 22:29:07 +00:00
|
|
|
{
|
2017-07-19 20:07:50 +00:00
|
|
|
settings->custom_flags = argv + i;
|
|
|
|
settings->custom_flags_count = argc - i;
|
|
|
|
i = argc;
|
2017-06-23 23:07:18 +00:00
|
|
|
mode = CLMode_App;
|
2016-07-03 22:29:07 +00:00
|
|
|
}break;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-08-13 04:19:02 +00:00
|
|
|
internal Models*
|
2019-10-01 02:06:21 +00:00
|
|
|
models_init(Thread_Context *tctx){
|
|
|
|
Arena *arena = reserve_arena(tctx);
|
|
|
|
Models *models = push_array_zero(arena, Models, 1);
|
|
|
|
models->tctx = tctx;
|
|
|
|
models->arena = arena;
|
|
|
|
heap_init(&models->heap, tctx->allocator);
|
2019-08-13 04:19:02 +00:00
|
|
|
return(models);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
internal void
|
|
|
|
app_load_vtables(API_VTable_system *vtable_system,
|
|
|
|
API_VTable_font *vtable_font,
|
|
|
|
API_VTable_graphics *vtable_graphics){
|
|
|
|
system_api_read_vtable(vtable_system);
|
|
|
|
font_api_read_vtable(vtable_font);
|
|
|
|
graphics_api_read_vtable(vtable_graphics);
|
2018-11-20 08:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 02:54:06 +00:00
|
|
|
internal Log_Function*
|
2019-10-03 17:57:44 +00:00
|
|
|
app_get_logger(void){
|
|
|
|
log_init();
|
2019-08-16 02:54:06 +00:00
|
|
|
return(log_string);
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
App_Read_Command_Line_Sig(app_read_command_line){
|
2019-10-01 02:06:21 +00:00
|
|
|
Models *models = models_init(tctx);
|
2019-08-13 04:19:02 +00:00
|
|
|
App_Settings *settings = &models->settings;
|
2019-09-28 00:49:59 +00:00
|
|
|
block_zero_struct(settings);
|
2017-07-19 20:07:50 +00:00
|
|
|
if (argc > 1){
|
2019-08-13 04:19:02 +00:00
|
|
|
init_command_line_settings(&models->settings, plat_settings, argc, argv);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2019-08-13 04:19:02 +00:00
|
|
|
*files = models->settings.init_files;
|
|
|
|
*file_count = &models->settings.init_files_count;
|
2019-10-01 02:06:21 +00:00
|
|
|
return(models);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App_Init_Sig(app_init){
|
2019-10-01 02:06:21 +00:00
|
|
|
Models *models = (Models*)base_ptr;
|
2017-03-29 20:50:29 +00:00
|
|
|
models->keep_playing = true;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
models->config_api = api;
|
2018-11-20 02:04:16 +00:00
|
|
|
models->app_links.cmd_context = models;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-10-05 02:48:05 +00:00
|
|
|
API_VTable_custom custom_vtable = {};
|
|
|
|
custom_api_fill_vtable(&custom_vtable);
|
2019-10-08 01:42:23 +00:00
|
|
|
API_VTable_system system_vtable = {};
|
|
|
|
system_api_fill_vtable(&system_vtable);
|
2019-10-10 22:57:02 +00:00
|
|
|
Custom_Layer_Init_Type *custom_init = api.init_apis(&custom_vtable, &system_vtable);
|
|
|
|
Assert(custom_init != 0);
|
|
|
|
custom_init(&models->app_links);
|
2017-03-29 20:50:29 +00:00
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
// NOTE(allen): coroutines
|
2019-10-03 17:57:44 +00:00
|
|
|
coroutine_system_init(&models->coroutines);
|
2019-08-04 05:36:13 +00:00
|
|
|
|
2019-07-24 07:41:40 +00:00
|
|
|
// NOTE(allen): font set
|
2019-10-03 17:57:44 +00:00
|
|
|
font_set_init(&models->font_set);
|
2019-07-24 07:41:40 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): live set
|
2019-10-05 02:48:05 +00:00
|
|
|
Arena *arena = models->arena;
|
2016-06-29 17:16:08 +00:00
|
|
|
{
|
2019-10-14 06:58:49 +00:00
|
|
|
models->live_set.node_arena = reserve_arena(models->tctx);
|
2017-07-17 23:35:13 +00:00
|
|
|
models->live_set.count = 0;
|
2019-02-05 09:13:38 +00:00
|
|
|
models->live_set.max = MAX_VIEWS;
|
2019-06-01 23:33:31 +00:00
|
|
|
models->live_set.views = push_array(arena, View, models->live_set.max);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2018-03-24 10:06:45 +00:00
|
|
|
//dll_init_sentinel
|
2019-02-10 09:18:34 +00:00
|
|
|
models->live_set.free_sentinel.next = &models->live_set.free_sentinel;
|
|
|
|
models->live_set.free_sentinel.prev = &models->live_set.free_sentinel;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2017-07-17 23:35:13 +00:00
|
|
|
i32 max = models->live_set.max;
|
|
|
|
View *view = models->live_set.views;
|
2017-03-29 20:50:29 +00:00
|
|
|
for (i32 i = 0; i < max; ++i, ++view){
|
2018-03-24 10:06:45 +00:00
|
|
|
//dll_insert(&models->live_set.free_sentinel, view);
|
2019-02-10 09:18:34 +00:00
|
|
|
view->next = models->live_set.free_sentinel.next;
|
|
|
|
view->prev = &models->live_set.free_sentinel;
|
|
|
|
models->live_set.free_sentinel.next = view;
|
|
|
|
view->next->prev = view;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
managed_ids_init(models->tctx->allocator, &models->managed_id_set);
|
|
|
|
lifetime_allocator_init(models->tctx->allocator, &models->lifetime_allocator);
|
2019-09-04 05:31:35 +00:00
|
|
|
dynamic_workspace_init(&models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace);
|
2018-06-23 03:03:58 +00:00
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): file setup
|
2019-08-13 04:19:02 +00:00
|
|
|
working_set_init(models, &models->working_set);
|
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
Mutex_Lock file_order_lock(models->working_set.mutex);
|
2019-08-13 04:19:02 +00:00
|
|
|
|
2019-04-01 00:36:09 +00:00
|
|
|
// NOTE(allen):
|
2019-02-08 10:03:48 +00:00
|
|
|
global_history_init(&models->global_history);
|
2019-09-02 18:59:36 +00:00
|
|
|
text_layout_init(models, &models->text_layouts);
|
2019-02-08 10:03:48 +00:00
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): clipboard setup
|
|
|
|
models->working_set.clipboard_max_size = ArrayCount(models->working_set.clipboards);
|
|
|
|
models->working_set.clipboard_size = 0;
|
|
|
|
models->working_set.clipboard_current = 0;
|
|
|
|
models->working_set.clipboard_rolling = 0;
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
// TODO(allen): do(better clipboard allocation)
|
2018-05-10 08:12:47 +00:00
|
|
|
if (clipboard.str != 0){
|
2019-10-01 02:06:21 +00:00
|
|
|
String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, clipboard.size);
|
2019-06-01 23:33:31 +00:00
|
|
|
block_copy(dest->str, clipboard.str, clipboard.size);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): style setup
|
2019-07-24 07:41:40 +00:00
|
|
|
{
|
|
|
|
Face_Description description = {};
|
|
|
|
description.font.file_name = string_u8_litexpr("liberation-mono.ttf");
|
|
|
|
description.font.in_4coder_font_folder = true;
|
|
|
|
description.parameters.pt_size = 12;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *new_face = font_set_new_face(&models->font_set, &description);
|
|
|
|
models->global_face_id = new_face->id;
|
2019-07-24 07:41:40 +00:00
|
|
|
}
|
2017-06-16 23:10:50 +00:00
|
|
|
app_hardcode_default_style(models);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2017-11-30 19:02:37 +00:00
|
|
|
// NOTE(allen): title space
|
|
|
|
models->has_new_title = true;
|
|
|
|
models->title_capacity = KB(4);
|
2019-06-01 23:33:31 +00:00
|
|
|
models->title_space = push_array(arena, char, models->title_capacity);
|
|
|
|
block_copy(models->title_space, WINDOW_NAME, sizeof(WINDOW_NAME));
|
2017-11-30 19:02:37 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): init baked in buffers
|
2016-09-22 21:25:52 +00:00
|
|
|
File_Init init_files[] = {
|
2019-06-01 23:33:31 +00:00
|
|
|
{ string_u8_litinit("*messages*"), &models->message_buffer, true , },
|
2019-08-16 02:54:06 +00:00
|
|
|
{ string_u8_litinit("*scratch*") , &models->scratch_buffer, false, },
|
|
|
|
{ string_u8_litinit("*log*") , &models->log_buffer , true , },
|
2016-09-21 22:34:19 +00:00
|
|
|
};
|
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
Heap *heap = &models->heap;
|
2016-09-21 22:34:19 +00:00
|
|
|
for (i32 i = 0; i < ArrayCount(init_files); ++i){
|
2019-08-12 09:16:04 +00:00
|
|
|
Editing_File *file = working_set_allocate_file(&models->working_set, &models->lifetime_allocator);
|
2019-09-04 05:31:35 +00:00
|
|
|
buffer_bind_name(models, arena, &models->working_set, file, init_files[i].name);
|
2016-09-22 21:25:52 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
if (init_files[i].ptr != 0){
|
|
|
|
*init_files[i].ptr = file;
|
|
|
|
}
|
|
|
|
|
2019-04-05 23:30:24 +00:00
|
|
|
File_Attributes attributes = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
file_create_from_string(models, file, SCu8(), attributes);
|
2017-03-29 16:32:06 +00:00
|
|
|
if (init_files[i].read_only){
|
2019-04-05 23:30:24 +00:00
|
|
|
file->settings.read_only = true;
|
2019-10-01 02:06:21 +00:00
|
|
|
history_free(models, &file->state.history);
|
2016-09-22 21:25:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
file->settings.never_kill = true;
|
2018-05-07 02:47:22 +00:00
|
|
|
file_set_unimportant(file, true);
|
2016-09-21 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): setup first panel
|
|
|
|
{
|
2019-06-01 23:33:31 +00:00
|
|
|
Panel *panel = layout_initialize(arena, &models->layout);
|
2019-09-04 05:31:35 +00:00
|
|
|
View *new_view = live_set_alloc_view(&models->lifetime_allocator, &models->live_set, panel);
|
2019-10-13 20:17:22 +00:00
|
|
|
view_init(models, new_view, models->scratch_buffer, models->view_event_handler);
|
2019-02-05 09:13:38 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-03-30 21:51:56 +00:00
|
|
|
// NOTE(allen): miscellaneous init
|
2019-10-03 17:57:44 +00:00
|
|
|
hot_directory_init(arena, &models->hot_directory, current_directory);
|
2019-10-01 02:06:21 +00:00
|
|
|
child_process_container_init(models->tctx->allocator, &models->child_processes);
|
2019-10-10 00:07:38 +00:00
|
|
|
models->user_up_key = KeyCode_Up;
|
|
|
|
models->user_down_key = KeyCode_Down;
|
2019-10-03 17:57:44 +00:00
|
|
|
models->period_wakeup_timer = system_wake_up_timer_create();
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App_Step_Sig(app_step){
|
2019-10-01 02:06:21 +00:00
|
|
|
Models *models = (Models*)base_ptr;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
Mutex_Lock file_order_lock(models->working_set.mutex);
|
2019-10-10 18:21:47 +00:00
|
|
|
Scratch_Block scratch(models->tctx, Scratch_Share);
|
2019-08-13 04:19:02 +00:00
|
|
|
|
2019-03-30 21:51:56 +00:00
|
|
|
models->next_animate_delay = max_u32;
|
2019-02-25 23:42:13 +00:00
|
|
|
models->animate_next_frame = false;
|
2018-03-03 07:46:44 +00:00
|
|
|
|
2019-01-26 01:12:25 +00:00
|
|
|
// NOTE(allen): per-frame update of models state
|
2019-07-24 07:41:40 +00:00
|
|
|
begin_frame(target, &models->font_set);
|
2019-01-26 01:12:25 +00:00
|
|
|
models->target = target;
|
2019-02-27 21:14:25 +00:00
|
|
|
models->input = input;
|
2019-01-26 01:12:25 +00:00
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): OS clipboard event handling
|
2019-06-01 23:33:31 +00:00
|
|
|
String_Const_u8 clipboard = input->clipboard;
|
2018-11-20 04:18:57 +00:00
|
|
|
if (clipboard.str != 0){
|
2019-10-01 02:06:21 +00:00
|
|
|
String_Const_u8 *dest = working_set_next_clipboard_string(&models->heap, &models->working_set, clipboard.size);
|
2019-06-01 23:33:31 +00:00
|
|
|
dest->size = eol_convert_in((char*)dest->str, (char*)clipboard.str, (i32)clipboard.size);
|
2019-03-30 22:36:31 +00:00
|
|
|
if (input->clipboard_changed && models->clipboard_change != 0){
|
|
|
|
models->clipboard_change(&models->app_links, *dest, ClipboardFlag_FromOS);
|
2019-03-15 08:38:28 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): reorganizing panels on screen
|
2019-02-05 09:13:38 +00:00
|
|
|
Vec2_i32 prev_dim = layout_get_root_size(&models->layout);
|
2019-02-10 07:48:07 +00:00
|
|
|
Vec2_i32 current_dim = V2i32(target->width, target->height);
|
2019-02-05 09:13:38 +00:00
|
|
|
layout_set_root_size(&models->layout, current_dim);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2018-11-18 18:21:17 +00:00
|
|
|
// NOTE(allen): update child processes
|
2018-11-18 18:33:01 +00:00
|
|
|
f32 dt = input->dt;
|
|
|
|
if (dt > 0){
|
2019-10-10 18:21:47 +00:00
|
|
|
Temp_Memory_Block temp(scratch);
|
2018-11-18 18:21:17 +00:00
|
|
|
|
2019-10-10 18:21:47 +00:00
|
|
|
Child_Process_Container *child_processes = &models->child_processes;
|
2019-03-21 03:18:08 +00:00
|
|
|
Child_Process **processes_to_free = push_array(scratch, Child_Process*, child_processes->active_child_process_count);
|
|
|
|
i32 processes_to_free_count = 0;
|
2018-11-18 18:21:17 +00:00
|
|
|
|
|
|
|
u32 max = KB(128);
|
|
|
|
char *dest = push_array(scratch, char, max);
|
|
|
|
|
2019-03-21 03:18:08 +00:00
|
|
|
for (Node *node = child_processes->child_process_active_list.next;
|
|
|
|
node != &child_processes->child_process_active_list;
|
|
|
|
node = node->next){
|
|
|
|
Child_Process *child_process = CastFromMember(Child_Process, node, node);
|
|
|
|
|
|
|
|
Editing_File *file = child_process->out_file;
|
|
|
|
CLI_Handles *cli = &child_process->cli;
|
|
|
|
|
|
|
|
// TODO(allen): do(call a 'child process updated hook' let that hook populate the buffer if it so chooses)
|
2018-11-18 18:21:17 +00:00
|
|
|
|
|
|
|
b32 edited_file = false;
|
|
|
|
u32 amount = 0;
|
2019-10-03 17:57:44 +00:00
|
|
|
system_cli_begin_update(cli);
|
|
|
|
if (system_cli_update_step(cli, dest, max, &amount)){
|
2018-11-18 18:21:17 +00:00
|
|
|
if (file != 0 && amount > 0){
|
|
|
|
amount = eol_in_place_convert_in(dest, amount);
|
2019-06-01 23:33:31 +00:00
|
|
|
output_file_append(models, file, SCu8(dest, amount));
|
2018-11-18 18:21:17 +00:00
|
|
|
edited_file = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
if (system_cli_end_update(cli)){
|
2018-11-18 18:21:17 +00:00
|
|
|
if (file != 0){
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_u8 str = push_u8_stringf(scratch, "exited with code %d", cli->exit);
|
2019-06-01 23:33:31 +00:00
|
|
|
output_file_append(models, file, str);
|
2018-11-18 18:21:17 +00:00
|
|
|
edited_file = true;
|
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
processes_to_free[processes_to_free_count++] = child_process;
|
|
|
|
child_process_set_return_code(models, child_processes, child_process->id, cli->exit);
|
2018-11-18 18:21:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 03:18:08 +00:00
|
|
|
if (child_process->cursor_at_end && file != 0){
|
2019-10-03 17:57:44 +00:00
|
|
|
file_cursor_to_end(models, file);
|
2018-11-18 18:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 03:18:08 +00:00
|
|
|
for (i32 i = 0; i < processes_to_free_count; ++i){
|
|
|
|
child_process_free(child_processes, processes_to_free[i]->id);
|
2018-11-18 18:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
// NOTE(allen): input filter and simulated events
|
|
|
|
if (models->input_filter != 0){
|
|
|
|
models->input_filter(&input->mouse);
|
|
|
|
}
|
2018-11-18 19:47:28 +00:00
|
|
|
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_List input_list = input->events;
|
2019-10-11 01:40:10 +00:00
|
|
|
Input_Modifier_Set modifiers = system_get_keyboard_modifiers(scratch);
|
2018-11-20 04:18:57 +00:00
|
|
|
if (input->mouse.press_l){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_MouseButton;
|
|
|
|
event.mouse.code = MouseCode_Left;
|
|
|
|
event.mouse.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else if (input->mouse.release_l){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
2019-10-11 01:40:10 +00:00
|
|
|
event.kind = InputEventKind_MouseButtonRelease;
|
2019-10-10 18:21:47 +00:00
|
|
|
event.mouse.code = MouseCode_Left;
|
|
|
|
event.mouse.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
if (input->mouse.press_r){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_MouseButton;
|
|
|
|
event.mouse.code = MouseCode_Right;
|
|
|
|
event.mouse.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else if (input->mouse.release_r){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
2019-10-11 01:40:10 +00:00
|
|
|
event.kind = InputEventKind_MouseButtonRelease;
|
2019-10-10 18:21:47 +00:00
|
|
|
event.mouse.code = MouseCode_Right;
|
|
|
|
event.mouse.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
if (input->mouse.wheel != 0){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_MouseWheel;
|
|
|
|
event.mouse_wheel.value = (f32)(input->mouse.wheel);
|
|
|
|
event.mouse_wheel.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
if (input->mouse.p != models->prev_p){
|
2019-10-06 06:59:35 +00:00
|
|
|
b32 was_in_window = rect_contains_point(Ri32(0, 0, prev_dim.x, prev_dim.y), models->prev_p);
|
|
|
|
b32 is_in_window = rect_contains_point(Ri32(0, 0, current_dim.x, current_dim.y), input->mouse.p);
|
2018-11-20 04:18:57 +00:00
|
|
|
if (is_in_window || was_in_window){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_MouseMove;
|
|
|
|
event.mouse_move.p = input->mouse.p;
|
2019-10-11 01:40:10 +00:00
|
|
|
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
|
2019-10-10 18:21:47 +00:00
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-08-04 02:41:38 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
if (models->animated_last_frame){
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_Core;
|
|
|
|
event.core.code = CoreCode_Animate;
|
|
|
|
push_input_event(scratch, &input_list, &event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): expose layout
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
// NOTE(allen): mouse hover status
|
|
|
|
Panel *mouse_panel = 0;
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *divider_panel = 0;
|
|
|
|
b32 mouse_in_margin = false;
|
2019-02-25 23:42:13 +00:00
|
|
|
Vec2_i32 mouse = input->mouse.p;
|
2019-02-05 09:13:38 +00:00
|
|
|
{
|
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
2019-04-05 02:03:36 +00:00
|
|
|
if (rect_contains_point(panel->rect_full, mouse)){
|
2019-02-05 09:13:38 +00:00
|
|
|
mouse_panel = panel;
|
2019-04-05 02:03:36 +00:00
|
|
|
if (!rect_contains_point(panel->rect_inner, mouse)){
|
2019-02-05 09:13:38 +00:00
|
|
|
mouse_in_margin = true;
|
|
|
|
for (divider_panel = mouse_panel->parent;
|
|
|
|
divider_panel != 0;
|
|
|
|
divider_panel = divider_panel->parent){
|
2019-04-05 02:03:36 +00:00
|
|
|
if (rect_contains_point(divider_panel->rect_inner, mouse)){
|
2019-02-05 09:13:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2019-02-05 09:13:38 +00:00
|
|
|
if (mouse_panel != 0){
|
|
|
|
break;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
// NOTE(allen): First frame initialization
|
|
|
|
if (input->first_step){
|
2019-02-27 05:49:35 +00:00
|
|
|
if (models->hook_start != 0){
|
|
|
|
char **files = models->settings.init_files;
|
|
|
|
i32 files_count = models->settings.init_files_count;
|
|
|
|
char **flags = models->settings.custom_flags;
|
|
|
|
i32 flags_count = models->settings.custom_flags_count;
|
|
|
|
models->hook_start(&models->app_links, files, files_count, flags, flags_count);
|
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
// NOTE(allen): consume event stream
|
2019-10-10 18:21:47 +00:00
|
|
|
for (Input_Event_Node *node = input_list.first;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
2019-10-10 20:15:47 +00:00
|
|
|
b32 event_was_handled = false;
|
2019-10-10 18:21:47 +00:00
|
|
|
Input_Event *event = &node->event;
|
|
|
|
|
2019-10-10 20:15:47 +00:00
|
|
|
if (event->kind == InputEventKind_TextInsert &&
|
|
|
|
event->text.blocked){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *active_panel = layout_get_active_panel(layout);
|
2018-11-20 02:04:16 +00:00
|
|
|
View *view = active_panel->view;
|
2018-11-20 04:18:57 +00:00
|
|
|
Assert(view != 0);
|
2017-07-18 00:00:07 +00:00
|
|
|
|
2019-08-13 00:57:25 +00:00
|
|
|
switch (models->state){
|
2018-11-20 04:18:57 +00:00
|
|
|
case APP_STATE_EDIT:
|
|
|
|
{
|
2019-10-10 18:21:47 +00:00
|
|
|
typedef i32 Event_Consume_Rule;
|
2018-11-20 04:18:57 +00:00
|
|
|
enum{
|
|
|
|
EventConsume_None,
|
|
|
|
EventConsume_BeginResize,
|
|
|
|
EventConsume_ClickChangeView,
|
2019-10-10 18:21:47 +00:00
|
|
|
EventConsume_CustomCommand,
|
2018-11-20 04:18:57 +00:00
|
|
|
};
|
2019-10-10 18:21:47 +00:00
|
|
|
|
|
|
|
Event_Consume_Rule consume_rule = EventConsume_CustomCommand;
|
|
|
|
if (match_mouse_code(event, MouseCode_Left) && (divider_panel != 0)){
|
|
|
|
consume_rule = EventConsume_BeginResize;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2019-10-10 18:21:47 +00:00
|
|
|
else if (match_mouse_code(event, MouseCode_Left) &&
|
|
|
|
mouse_panel != 0 && mouse_panel != active_panel){
|
|
|
|
consume_rule = EventConsume_ClickChangeView;
|
2018-08-05 07:09:18 +00:00
|
|
|
}
|
2017-07-18 00:00:07 +00:00
|
|
|
|
2019-10-10 18:21:47 +00:00
|
|
|
switch (consume_rule){
|
2018-11-20 04:18:57 +00:00
|
|
|
case EventConsume_BeginResize:
|
|
|
|
{
|
2019-08-13 00:57:25 +00:00
|
|
|
models->state = APP_STATE_RESIZING;
|
2019-02-05 09:13:38 +00:00
|
|
|
models->resizing_intermediate_panel = divider_panel;
|
2019-10-10 20:15:47 +00:00
|
|
|
event_was_handled = true;
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
2017-07-18 00:00:07 +00:00
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
case EventConsume_ClickChangeView:
|
|
|
|
{
|
2018-11-20 08:18:54 +00:00
|
|
|
// NOTE(allen): run deactivate command
|
2019-10-13 20:17:22 +00:00
|
|
|
co_send_core_event(models, view, CoreCode_ClickDeactivateView);
|
2018-11-20 04:18:57 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
layout->active_panel = mouse_panel;
|
2019-03-30 21:51:56 +00:00
|
|
|
models->animate_next_frame = true;
|
2018-11-20 08:18:54 +00:00
|
|
|
active_panel = mouse_panel;
|
|
|
|
view = active_panel->view;
|
2018-11-20 04:18:57 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
// NOTE(allen): run activate command
|
2019-10-13 20:17:22 +00:00
|
|
|
co_send_core_event(models, view, CoreCode_ClickActivateView);
|
2019-10-10 20:15:47 +00:00
|
|
|
|
|
|
|
event_was_handled = true;
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-10-10 18:21:47 +00:00
|
|
|
case EventConsume_CustomCommand:
|
2018-11-20 04:18:57 +00:00
|
|
|
{
|
2019-10-13 20:17:22 +00:00
|
|
|
event_was_handled = co_send_event(models, view, event);
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case APP_STATE_RESIZING:
|
|
|
|
{
|
2019-10-10 18:21:47 +00:00
|
|
|
Event_Property event_flags = get_event_properties(event);
|
|
|
|
if (HasFlag(event_flags, EventProperty_AnyKey) ||
|
|
|
|
match_mouse_code_release(event, MouseCode_Left)){
|
2019-08-13 00:57:25 +00:00
|
|
|
models->state = APP_STATE_EDIT;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2019-10-10 18:21:47 +00:00
|
|
|
else if (event->kind == InputEventKind_MouseMove){
|
2018-11-20 04:18:57 +00:00
|
|
|
if (input->mouse.l){
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *split = models->resizing_intermediate_panel;
|
2019-10-10 18:21:47 +00:00
|
|
|
Range_i32 limits = layout_get_limiting_range_on_split(layout, split);
|
2019-02-05 09:13:38 +00:00
|
|
|
i32 mouse_position = (split->vertical_split)?(mouse.x):(mouse.y);
|
|
|
|
mouse_position = clamp(limits.min, mouse_position, limits.max);
|
|
|
|
layout_set_split_absolute_position(layout, split, mouse_position);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-08-13 00:57:25 +00:00
|
|
|
models->state = APP_STATE_EDIT;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2017-04-15 21:47:23 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
2017-04-15 21:47:23 +00:00
|
|
|
}
|
2019-10-10 20:15:47 +00:00
|
|
|
|
|
|
|
if (event_was_handled && event->kind == InputEventKind_KeyStroke){
|
|
|
|
for (Input_Event *dependent_text = event->key.first_dependent_text;
|
|
|
|
dependent_text != 0;
|
|
|
|
dependent_text = dependent_text->text.next_text){
|
|
|
|
Assert(dependent_text->kind == InputEventKind_TextInsert);
|
|
|
|
dependent_text->text.blocked = true;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 22:54:00 +00:00
|
|
|
// NOTE(allen): send panel size update
|
2019-10-10 22:57:02 +00:00
|
|
|
if (models->layout.panel_state_dirty){
|
2018-11-20 22:54:00 +00:00
|
|
|
models->layout.panel_state_dirty = false;
|
2019-10-10 22:57:02 +00:00
|
|
|
if (models->buffer_viewer_update != 0){
|
|
|
|
models->buffer_viewer_update(&models->app_links);
|
|
|
|
}
|
2018-11-20 22:54:00 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
// NOTE(allen): dt
|
|
|
|
f32 literal_dt = 0.f;
|
2019-10-03 17:57:44 +00:00
|
|
|
u64 now_usecond_stamp = system_now_time();
|
2019-09-02 18:59:36 +00:00
|
|
|
if (!input->first_step){
|
|
|
|
u64 elapsed_useconds = now_usecond_stamp - models->last_render_usecond_stamp;
|
|
|
|
literal_dt = (f32)((f64)(elapsed_useconds)/1000000.f);
|
|
|
|
}
|
|
|
|
models->last_render_usecond_stamp = now_usecond_stamp;
|
|
|
|
f32 animation_dt = 0.f;
|
|
|
|
if (models->animated_last_frame){
|
|
|
|
animation_dt = literal_dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): on the first frame there should be no scrolling
|
|
|
|
if (input->first_step){
|
2019-02-05 09:13:38 +00:00
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
2018-11-18 18:33:01 +00:00
|
|
|
View *view = panel->view;
|
2019-10-14 02:13:15 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
edit_pos.scroll.position = view_normalize_buffer_point(models, view, edit_pos.scroll.target);
|
|
|
|
block_zero_struct(&edit_pos.scroll.target);
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
2018-11-18 18:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
// NOTE(allen): apply pending smooth deltas
|
|
|
|
{
|
|
|
|
Delta_Rule_Function *scroll_rule = models->scroll_rule;
|
2019-02-05 09:13:38 +00:00
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
2016-07-06 22:28:39 +00:00
|
|
|
View *view = panel->view;
|
2019-09-02 18:59:36 +00:00
|
|
|
|
|
|
|
View_ID view_id = view_get_id(&models->live_set, view);
|
|
|
|
b32 new_target = (b32)view->new_scroll_target;
|
2019-10-14 02:13:15 +00:00
|
|
|
|
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
Vec2_f32 pending = view_buffer_point_difference(models, view,
|
|
|
|
edit_pos.scroll.target, edit_pos.scroll.position);
|
|
|
|
if (!near_zero(pending, 0.5f)){
|
|
|
|
Vec2_f32 partial = scroll_rule(pending, view_id, new_target, animation_dt);
|
|
|
|
edit_pos.scroll.position = view_move_buffer_point(models, view,
|
|
|
|
edit_pos.scroll.position, partial);
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
|
|
|
models->animate_next_frame = true;
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-10-14 02:13:15 +00:00
|
|
|
edit_pos.scroll.position = edit_pos.scroll.target;
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
2016-07-06 22:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 18:54:15 +00:00
|
|
|
// NOTE(allen): hook for files reloaded
|
|
|
|
{
|
|
|
|
File_Externally_Modified_Function *hook_file_externally_modified = models->hook_file_externally_modified;
|
|
|
|
if (hook_file_externally_modified != 0){
|
|
|
|
Working_Set *working_set = &models->working_set;
|
|
|
|
Assert(working_set->has_external_mod_sentinel.next != 0);
|
|
|
|
if (working_set->has_external_mod_sentinel.next != &working_set->has_external_mod_sentinel){
|
|
|
|
for (Node *node = working_set->has_external_mod_sentinel.next, *next = 0;
|
|
|
|
node != &working_set->has_external_mod_sentinel;
|
|
|
|
node = next){
|
|
|
|
next = node->next;
|
|
|
|
Editing_File *file = CastFromMember(Editing_File, external_mod_node, node);
|
|
|
|
dll_remove(node);
|
|
|
|
block_zero_struct(node);
|
|
|
|
hook_file_externally_modified(&models->app_links, file->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 12:38:24 +00:00
|
|
|
// NOTE(allen): if the exit signal has been sent, run the exit hook.
|
2018-08-05 07:09:18 +00:00
|
|
|
if (input->trying_to_kill){
|
|
|
|
models->keep_playing = false;
|
|
|
|
}
|
|
|
|
if (!models->keep_playing){
|
2019-10-10 22:57:02 +00:00
|
|
|
Hook_Function *exit_func = models->exit;
|
2018-08-05 07:09:18 +00:00
|
|
|
if (exit_func != 0){
|
|
|
|
if (exit_func(&models->app_links) == 0){
|
2019-03-30 21:51:56 +00:00
|
|
|
models->animate_next_frame = true;
|
2018-08-05 07:09:18 +00:00
|
|
|
models->keep_playing = true;
|
|
|
|
}
|
2016-09-09 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): rendering
|
|
|
|
{
|
2019-03-31 18:55:26 +00:00
|
|
|
Frame_Info frame = {};
|
|
|
|
frame.index = models->frame_counter;
|
|
|
|
frame.literal_dt = literal_dt;
|
|
|
|
frame.animation_dt = animation_dt;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
{
|
|
|
|
Color_Table color_table = models->fallback_color_table;
|
|
|
|
if (models->modify_color_table != 0){
|
|
|
|
color_table = models->modify_color_table(&models->app_links, frame);
|
|
|
|
if (color_table.count < models->fallback_color_table.count){
|
|
|
|
block_copy(models->fallback_color_table.vals, color_table.vals, color_table.count*sizeof(*color_table.vals));
|
|
|
|
color_table = models->fallback_color_table;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
models->color_table = color_table;
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
begin_render_section(target, models->frame_counter, literal_dt, animation_dt);
|
2019-03-31 18:55:26 +00:00
|
|
|
models->in_render_mode = true;
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
Live_Views *live_views = &models->live_set;
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
for (Node *node = layout->open_panels.next;
|
|
|
|
node != &layout->open_panels;
|
|
|
|
node = node->next){
|
|
|
|
Panel *panel = CastFromMember(Panel, node, node);
|
|
|
|
View *view = panel->view;
|
|
|
|
View_Context_Node *ctx = view->ctx;
|
|
|
|
if (ctx != 0){
|
|
|
|
Render_Caller_Function *render_caller = ctx->ctx.render_caller;
|
|
|
|
if (render_caller != 0){
|
|
|
|
render_caller(&models->app_links, frame, view_get_id(live_views, view));
|
|
|
|
}
|
|
|
|
}
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-03-31 18:55:26 +00:00
|
|
|
models->in_render_mode = false;
|
2019-10-03 17:57:44 +00:00
|
|
|
end_render_section(target);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 02:54:06 +00:00
|
|
|
// NOTE(allen): flush the log
|
|
|
|
log_flush(models);
|
|
|
|
|
2019-03-30 21:51:56 +00:00
|
|
|
// NOTE(allen): set the app_result
|
|
|
|
Application_Step_Result app_result = {};
|
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
|
|
|
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
|
|
|
|
|
2017-11-30 19:02:37 +00:00
|
|
|
// NOTE(allen): get new window title
|
|
|
|
if (models->has_new_title){
|
|
|
|
models->has_new_title = false;
|
|
|
|
app_result.has_new_title = true;
|
|
|
|
app_result.title_string = models->title_space;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): get cursor type
|
2019-02-05 09:13:38 +00:00
|
|
|
if (mouse_panel != 0 && !mouse_in_margin){
|
2016-06-29 17:16:08 +00:00
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_ARROW;
|
|
|
|
}
|
2019-02-05 09:13:38 +00:00
|
|
|
else if (divider_panel != 0){
|
|
|
|
if (divider_panel->vertical_split){
|
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_LEFTRIGHT;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-05 09:13:38 +00:00
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_UPDOWN;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 09:13:38 +00:00
|
|
|
else{
|
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_ARROW;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
models->prev_mouse_panel = mouse_panel;
|
|
|
|
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
|
|
|
|
app_result.perform_kill = !models->keep_playing;
|
2019-03-30 21:51:56 +00:00
|
|
|
app_result.animating = models->animate_next_frame;
|
|
|
|
if (models->animate_next_frame){
|
|
|
|
// NOTE(allen): Silence the timer, because we're going to do another frame right away anyways.
|
2019-10-03 17:57:44 +00:00
|
|
|
system_wake_up_timer_set(models->period_wakeup_timer, max_u32);
|
2019-03-30 21:51:56 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
// NOTE(allen): Set the timer's wakeup period, possibly to max_u32 thus effectively silencing it.
|
2019-10-03 17:57:44 +00:00
|
|
|
system_wake_up_timer_set(models->period_wakeup_timer, models->next_animate_delay);
|
2019-03-30 21:51:56 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2018-08-04 02:41:38 +00:00
|
|
|
// NOTE(allen): Update Frame to Frame States
|
2019-02-25 23:42:13 +00:00
|
|
|
models->prev_p = input->mouse.p;
|
2018-08-04 02:41:38 +00:00
|
|
|
models->animated_last_frame = app_result.animating;
|
2018-03-10 02:06:55 +00:00
|
|
|
models->frame_counter += 1;
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// end-of-app_step
|
2018-03-03 07:46:44 +00:00
|
|
|
return(app_result);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 20:05:35 +00:00
|
|
|
extern "C" App_Get_Functions_Sig(app_get_functions){
|
2016-06-29 17:16:08 +00:00
|
|
|
App_Functions result = {};
|
|
|
|
|
2019-10-03 17:57:44 +00:00
|
|
|
result.load_vtables = app_load_vtables;
|
2019-08-16 02:54:06 +00:00
|
|
|
result.get_logger = app_get_logger;
|
2016-06-29 17:16:08 +00:00
|
|
|
result.read_command_line = app_read_command_line;
|
|
|
|
result.init = app_init;
|
|
|
|
result.step = app_step;
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|