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
|
|
|
|
|
2016-09-22 00:01:12 +00:00
|
|
|
#define DEFAULT_DISPLAY_WIDTH 672
|
2016-10-25 00:26:52 +00:00
|
|
|
#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 550
|
2016-09-22 00:01:12 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal App_Coroutine_State
|
2016-06-29 17:16:08 +00:00
|
|
|
get_state(Application_Links *app){
|
2018-11-20 08:18:54 +00:00
|
|
|
App_Coroutine_State state = {};
|
2016-06-29 17:16:08 +00:00
|
|
|
state.co = app->current_coroutine;
|
|
|
|
state.type = app->type_coroutine;
|
|
|
|
return(state);
|
|
|
|
}
|
2018-12-15 09:10:42 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal void
|
2016-06-29 17:16:08 +00:00
|
|
|
restore_state(Application_Links *app, App_Coroutine_State state){
|
|
|
|
app->current_coroutine = state.co;
|
|
|
|
app->type_coroutine = state.type;
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal Coroutine_Head*
|
2017-07-19 20:07:50 +00:00
|
|
|
app_launch_coroutine(System_Functions *system, Application_Links *app, Coroutine_Type type, Coroutine_Head *co, void *in, void *out){
|
|
|
|
Coroutine_Head *result = 0;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
App_Coroutine_State prev_state = get_state(app);
|
|
|
|
|
|
|
|
app->current_coroutine = co;
|
|
|
|
app->type_coroutine = type;
|
|
|
|
result = system->launch_coroutine(co, in, out);
|
|
|
|
restore_state(app, prev_state);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal Coroutine_Head*
|
2017-07-19 20:07:50 +00:00
|
|
|
app_resume_coroutine(System_Functions *system, Application_Links *app, Coroutine_Type type, Coroutine_Head *co, void *in, void *out){
|
|
|
|
Coroutine_Head *result = 0;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
App_Coroutine_State prev_state = get_state(app);
|
|
|
|
|
|
|
|
app->current_coroutine = co;
|
|
|
|
app->type_coroutine = type;
|
|
|
|
result = system->resume_coroutine(co, in, out);
|
|
|
|
restore_state(app, prev_state);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal void
|
2018-03-24 21:43:57 +00:00
|
|
|
output_file_append(System_Functions *system, Models *models, Editing_File *file, String value){
|
2017-11-22 20:05:58 +00:00
|
|
|
if (!file->is_dummy){
|
|
|
|
i32 end = buffer_size(&file->state.buffer);
|
2019-02-08 10:03:48 +00:00
|
|
|
Edit edit = {};
|
|
|
|
edit.str = value.str;
|
|
|
|
edit.length = value.size;
|
|
|
|
edit.range.first = end;
|
|
|
|
edit.range.one_past_last = end;
|
|
|
|
|
|
|
|
Edit_Behaviors behaviors = {};
|
|
|
|
edit_single(system, models, file, edit, behaviors);
|
2018-06-02 00:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
file_cursor_to_end(System_Functions *system, Models *models, Editing_File *file){
|
|
|
|
Assert(file != 0);
|
|
|
|
i32 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-02-12 10:21:02 +00:00
|
|
|
Full_Cursor cursor = file_compute_cursor(system, file, seek_pos(pos));
|
2019-02-27 05:49:35 +00:00
|
|
|
view_set_cursor(system, models, view, cursor, true);
|
2019-02-12 10:21:02 +00:00
|
|
|
view->mark = cursor.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
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
SCROLL_RULE_SIG(fallback_scroll_rule){
|
|
|
|
b32 result = false;
|
|
|
|
if (target_x != *scroll_x){
|
|
|
|
*scroll_x = target_x;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
if (target_y != *scroll_y){
|
|
|
|
*scroll_y = target_y;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
#define DEFAULT_MAP_SIZE 10
|
|
|
|
#define DEFAULT_UI_MAP_SIZE 32
|
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
internal void
|
|
|
|
setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){
|
2017-11-08 21:28:44 +00:00
|
|
|
map_init(commands, part, DEFAULT_UI_MAP_SIZE, parent);
|
2019-01-26 01:12:25 +00:00
|
|
|
// TODO(allen): do(fix the weird built-in-ness of the ui map)
|
2017-11-08 18:24:30 +00:00
|
|
|
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];
|
2019-02-08 04:45:13 +00:00
|
|
|
map_add(commands, key_left , mdfr, (Custom_Command_Function*)0);
|
|
|
|
map_add(commands, key_right, mdfr, (Custom_Command_Function*)0);
|
|
|
|
map_add(commands, key_up , mdfr, (Custom_Command_Function*)0);
|
|
|
|
map_add(commands, key_down , mdfr, (Custom_Command_Function*)0);
|
|
|
|
map_add(commands, key_back , mdfr, (Custom_Command_Function*)0);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
setup_file_commands(Command_Map *commands, Partition *part, i32 parent){
|
2017-11-08 21:28:44 +00:00
|
|
|
map_init(commands, part, DEFAULT_MAP_SIZE, parent);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
setup_top_commands(Command_Map *commands, Partition *part, i32 parent){
|
2017-11-08 21:28:44 +00:00
|
|
|
map_init(commands, part, DEFAULT_MAP_SIZE, parent);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
interpret_binding_buffer(Models *models, void *buffer, i32 size){
|
|
|
|
b32 result = true;
|
|
|
|
|
2018-08-18 08:16:52 +00:00
|
|
|
Heap *gen = &models->mem.heap;
|
2017-11-08 18:24:30 +00:00
|
|
|
Partition *part = &models->mem.part;
|
2017-11-08 21:28:44 +00:00
|
|
|
Temp_Memory temp = begin_temp_memory(part);
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Partition local_part = {};
|
2017-11-08 18:24:30 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Mapping new_mapping = {};
|
2017-11-08 18:24:30 +00:00
|
|
|
|
|
|
|
models->scroll_rule = fallback_scroll_rule;
|
|
|
|
models->hook_open_file = 0;
|
|
|
|
models->hook_new_file = 0;
|
|
|
|
models->hook_save_file = 0;
|
|
|
|
models->hook_end_file = 0;
|
2019-01-31 12:38:24 +00:00
|
|
|
models->hook_file_edit_finished = 0;
|
2017-11-08 18:24:30 +00:00
|
|
|
models->command_caller = 0;
|
2018-09-22 23:45:24 +00:00
|
|
|
models->render_caller = 0;
|
2017-11-08 18:24:30 +00:00
|
|
|
models->input_filter = 0;
|
|
|
|
|
|
|
|
b32 did_top = false;
|
|
|
|
b32 did_file = false;
|
|
|
|
|
|
|
|
Command_Map *map_ptr = 0;
|
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
Binding_Unit *unit = (Binding_Unit*)buffer;
|
2017-11-08 18:24:30 +00:00
|
|
|
if (unit->type == unit_header && unit->header.error == 0){
|
|
|
|
Binding_Unit *end = unit + unit->header.total_size;
|
|
|
|
|
|
|
|
i32 user_map_count = unit->header.user_map_count;
|
2017-11-08 21:28:44 +00:00
|
|
|
new_mapping.user_map_count = user_map_count;
|
2017-11-08 18:24:30 +00:00
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
// Initialize Table and User Maps in Temp Buffer
|
2017-11-08 18:24:30 +00:00
|
|
|
new_mapping.map_id_table = push_array(part, i32, user_map_count);
|
|
|
|
memset(new_mapping.map_id_table, -1, user_map_count*sizeof(i32));
|
|
|
|
|
|
|
|
new_mapping.user_maps = push_array(part, Command_Map, user_map_count);
|
2017-11-09 00:12:14 +00:00
|
|
|
memset(new_mapping.user_maps, 0, user_map_count*sizeof(Command_Map));
|
2017-11-08 18:24:30 +00:00
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
// Find the Size of Each Map
|
2017-11-08 18:24:30 +00:00
|
|
|
for (++unit; unit < end; ++unit){
|
|
|
|
switch (unit->type){
|
|
|
|
case unit_map_begin:
|
|
|
|
{
|
|
|
|
i32 mapid = unit->map_begin.mapid;
|
2017-11-08 21:28:44 +00:00
|
|
|
|
|
|
|
if (mapid == mapid_ui || mapid == mapid_nomap){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (mapid == mapid_global){
|
|
|
|
did_top = true;
|
|
|
|
}
|
|
|
|
else if (mapid == mapid_file){
|
|
|
|
did_file = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command_Map *map = get_or_add_map(&new_mapping, mapid);
|
|
|
|
i32 count = map->count;
|
|
|
|
i32 new_count = 0;
|
2017-11-08 18:24:30 +00:00
|
|
|
if (unit->map_begin.replace){
|
2017-11-08 21:28:44 +00:00
|
|
|
map->real_beginning = unit;
|
|
|
|
new_count = unit->map_begin.bind_count;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-08 21:28:44 +00:00
|
|
|
if (map->real_beginning == 0){
|
|
|
|
map->real_beginning = unit;
|
|
|
|
}
|
|
|
|
new_count = unit->map_begin.bind_count + count;
|
|
|
|
}
|
|
|
|
|
|
|
|
map->count = new_count;
|
|
|
|
if (map->max < new_count){
|
|
|
|
map->max = new_count;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
// Add up the Map Counts
|
|
|
|
i32 count_global = DEFAULT_MAP_SIZE;
|
|
|
|
if (did_top){
|
|
|
|
count_global = clamp_bottom(6, new_mapping.map_top.count*3/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 count_file = DEFAULT_MAP_SIZE;
|
|
|
|
if (did_file){
|
|
|
|
count_file = clamp_bottom(6, new_mapping.map_file.count*3/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 count_ui = DEFAULT_UI_MAP_SIZE;
|
|
|
|
|
|
|
|
i32 count_user = 0;
|
|
|
|
for (i32 i = 0; i < user_map_count; ++i){
|
|
|
|
Command_Map *map = &new_mapping.user_maps[i];
|
|
|
|
count_user += clamp_bottom(6, map->max*3/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 binding_memsize = (count_global + count_file + count_ui + count_user)*sizeof(Command_Binding);
|
|
|
|
|
|
|
|
// Allocate Needed Memory
|
|
|
|
i32 map_id_table_memsize = user_map_count*sizeof(i32);
|
|
|
|
i32 user_maps_memsize = user_map_count*sizeof(Command_Map);
|
|
|
|
|
|
|
|
i32 map_id_table_rounded_memsize = l_round_up_i32(map_id_table_memsize, 8);
|
|
|
|
i32 user_maps_rounded_memsize = l_round_up_i32(user_maps_memsize, 8);
|
|
|
|
|
|
|
|
i32 binding_rounded_memsize = l_round_up_i32(binding_memsize, 8);
|
|
|
|
|
|
|
|
i32 needed_memsize = map_id_table_rounded_memsize + user_maps_rounded_memsize + binding_rounded_memsize;
|
2018-08-18 08:16:52 +00:00
|
|
|
new_mapping.memory = heap_allocate(gen, needed_memsize);
|
2017-11-08 21:28:44 +00:00
|
|
|
local_part = make_part(new_mapping.memory, needed_memsize);
|
|
|
|
|
|
|
|
// Move ID Table Memory and Pointer
|
|
|
|
i32 *old_table = new_mapping.map_id_table;
|
|
|
|
new_mapping.map_id_table = push_array(&local_part, i32, user_map_count);
|
|
|
|
memmove(new_mapping.map_id_table, old_table, map_id_table_memsize);
|
|
|
|
|
|
|
|
// Move User Maps Memory and Pointer
|
|
|
|
Command_Map *old_maps = new_mapping.user_maps;
|
|
|
|
new_mapping.user_maps = push_array(&local_part, Command_Map, user_map_count);
|
|
|
|
memmove(new_mapping.user_maps, old_maps, user_maps_memsize);
|
|
|
|
|
|
|
|
// Fill in Command Maps
|
|
|
|
unit = (Binding_Unit*)buffer;
|
2017-11-08 18:24:30 +00:00
|
|
|
for (++unit; unit < end; ++unit){
|
|
|
|
switch (unit->type){
|
|
|
|
case unit_map_begin:
|
|
|
|
{
|
|
|
|
i32 mapid = unit->map_begin.mapid;
|
2017-11-08 21:28:44 +00:00
|
|
|
|
|
|
|
if (mapid == mapid_ui || mapid == mapid_nomap){
|
2017-11-08 18:24:30 +00:00
|
|
|
map_ptr = 0;
|
2017-11-08 21:28:44 +00:00
|
|
|
break;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 21:28:44 +00:00
|
|
|
Command_Map *map = get_or_add_map(&new_mapping, mapid);
|
|
|
|
if (unit >= map->real_beginning){
|
|
|
|
if (mapid == mapid_global){
|
|
|
|
map_ptr = &new_mapping.map_top;
|
|
|
|
}
|
|
|
|
else if (mapid == mapid_file){
|
|
|
|
map_ptr = &new_mapping.map_file;
|
|
|
|
}
|
|
|
|
else if (mapid < mapid_global){
|
|
|
|
i32 index = get_or_add_map_index(&new_mapping, mapid);
|
|
|
|
Assert(index < user_map_count);
|
|
|
|
map_ptr = &new_mapping.user_maps[index];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
map_ptr = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Assert(map_ptr != 0);
|
|
|
|
|
|
|
|
// NOTE(allen): Map can begin multiple times, only alloc and clear when we first see it.
|
|
|
|
if (map_ptr->commands == 0){
|
|
|
|
i32 count = map->max;
|
|
|
|
i32 table_max = clamp_bottom(6, count*3/2);
|
|
|
|
map_init(map_ptr, &local_part, table_max, mapid_global);
|
|
|
|
}
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case unit_inherit:
|
2017-11-08 21:28:44 +00:00
|
|
|
{
|
|
|
|
if (map_ptr != 0){
|
|
|
|
map_ptr->parent = unit->map_inherit.mapid;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case unit_callback:
|
2017-11-08 21:28:44 +00:00
|
|
|
{
|
|
|
|
if (map_ptr != 0){
|
|
|
|
Custom_Command_Function *custom = unit->callback.func;
|
2019-02-08 04:45:13 +00:00
|
|
|
if (unit->callback.code == 0){
|
|
|
|
u32 index = 0;
|
|
|
|
if (map_get_modifiers_hash(unit->callback.modifiers, &index)){
|
|
|
|
map_ptr->vanilla_keyboard_default[index].custom = custom;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-08 04:45:13 +00:00
|
|
|
else{
|
|
|
|
map_add(map_ptr, unit->callback.code, unit->callback.modifiers, custom);
|
|
|
|
}
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case unit_hook:
|
|
|
|
{
|
|
|
|
i32 hook_id = unit->hook.hook_id;
|
|
|
|
if (hook_id >= 0){
|
|
|
|
if (hook_id < hook_type_count){
|
|
|
|
models->hooks[hook_id] = (Hook_Function*)unit->hook.func;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
switch (hook_id){
|
|
|
|
case special_hook_open_file:
|
|
|
|
{
|
|
|
|
models->hook_open_file = (Open_File_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case special_hook_new_file:
|
|
|
|
{
|
|
|
|
models->hook_new_file = (Open_File_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case special_hook_save_file:
|
|
|
|
{
|
|
|
|
models->hook_save_file = (Open_File_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case special_hook_end_file:
|
|
|
|
{
|
|
|
|
models->hook_end_file = (Open_File_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2019-01-31 12:38:24 +00:00
|
|
|
case special_hook_file_edit_finished:
|
|
|
|
{
|
|
|
|
models->hook_file_edit_finished = (File_Edit_Finished_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
case special_hook_command_caller:
|
|
|
|
{
|
|
|
|
models->command_caller = (Command_Caller_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2018-09-22 23:45:24 +00:00
|
|
|
case special_hook_render_caller:
|
|
|
|
{
|
|
|
|
models->render_caller = (Render_Caller_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
case special_hook_scroll_rule:
|
|
|
|
{
|
|
|
|
models->scroll_rule = (Scroll_Rule_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2017-11-30 23:25:49 +00:00
|
|
|
case special_hook_buffer_name_resolver:
|
|
|
|
{
|
|
|
|
models->buffer_name_resolver = (Buffer_Name_Resolver_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
case special_hook_modify_color_table:
|
|
|
|
{
|
|
|
|
models->modify_color_table = (Modify_Color_Table_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2019-03-15 08:38:28 +00:00
|
|
|
case special_hook_clipboard_change:
|
|
|
|
{
|
|
|
|
models->clipboard_change = (Clipboard_Change_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
case special_hook_get_view_buffer_region:
|
|
|
|
{
|
|
|
|
models->get_view_buffer_region = (Get_View_Buffer_Region_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
2017-11-08 18:24:30 +00:00
|
|
|
case special_hook_input_filter:
|
|
|
|
{
|
|
|
|
models->input_filter = (Input_Filter_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case special_hook_start:
|
|
|
|
{
|
|
|
|
models->hook_start = (Start_Hook_Function*)unit->hook.func;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-08 21:28:44 +00:00
|
|
|
|
|
|
|
if (!did_top){
|
|
|
|
setup_top_commands(&new_mapping.map_top, &local_part, mapid_global);
|
|
|
|
}
|
|
|
|
if (!did_file){
|
|
|
|
setup_file_commands(&new_mapping.map_file, &local_part, mapid_global);
|
|
|
|
}
|
|
|
|
setup_ui_commands(&new_mapping.map_ui, &local_part, mapid_global);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
2017-11-08 21:28:44 +00:00
|
|
|
else{
|
2019-01-26 01:12:25 +00:00
|
|
|
// TODO(allen): do(Error report: bad binding units map.)
|
|
|
|
// TODO(allen): do(no bindings set recovery plan.)
|
2017-11-08 21:28:44 +00:00
|
|
|
InvalidCodePath;
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
2017-11-08 21:28:44 +00:00
|
|
|
|
|
|
|
Mapping old_mapping = models->mapping;
|
|
|
|
if (old_mapping.memory != 0){
|
2018-08-18 08:16:52 +00:00
|
|
|
heap_free(gen, old_mapping.memory);
|
2017-11-08 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
models->mapping = new_mapping;
|
2017-11-08 21:28:44 +00:00
|
|
|
end_temp_memory(temp);
|
2017-11-08 18:24:30 +00:00
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
#include "4ed_api_implementation.cpp"
|
|
|
|
|
|
|
|
internal void
|
2017-07-19 20:07:50 +00:00
|
|
|
command_caller(Coroutine_Head *coroutine){
|
2016-06-29 17:16:08 +00:00
|
|
|
Command_In *cmd_in = (Command_In*)coroutine->in;
|
2018-11-20 02:04:16 +00:00
|
|
|
Models *models = cmd_in->models;
|
2019-02-08 04:45:13 +00:00
|
|
|
if (models->command_caller != 0){
|
|
|
|
Generic_Command generic = {};
|
|
|
|
generic.command = cmd_in->bind.custom;
|
2017-03-29 20:50:29 +00:00
|
|
|
models->command_caller(&models->app_links, generic);
|
2016-06-29 18:23:14 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-08 04:45:13 +00:00
|
|
|
cmd_in->bind.custom(&models->app_links);
|
2016-06-29 18:23:14 +00:00
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2016-08-29 01:03:26 +00:00
|
|
|
app_links_init(System_Functions *system, Application_Links *app_links, void *data, i32 size){
|
2016-06-29 17:16:08 +00:00
|
|
|
app_links->memory = data;
|
|
|
|
app_links->memory_size = size;
|
|
|
|
FillAppLinksAPI(app_links);
|
|
|
|
app_links->current_coroutine = 0;
|
|
|
|
app_links->system_links = system;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
Partition *part = &models->mem.part;
|
|
|
|
Color_Table color_table = {};
|
|
|
|
color_table.vals = push_array(part, u32, Stag_COUNT);
|
|
|
|
color_table.count = Stag_COUNT;
|
|
|
|
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;
|
|
|
|
if (match_cc(long_arg_name, "custom")){
|
|
|
|
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;
|
|
|
|
|
2017-07-03 15:43:51 +00:00
|
|
|
case 'l': action = CLAct_LogStdout; --i; break;
|
|
|
|
case 'L': action = CLAct_LogFile; --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){
|
|
|
|
settings->initial_line = str_to_int_c(argv[i]);
|
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
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
i32 w = str_to_int_c(argv[i]);
|
|
|
|
i32 h = str_to_int_c(argv[i+1]);
|
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
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
i32 x = str_to_int_c(argv[i]);
|
|
|
|
i32 y = str_to_int_c(argv[i+1]);
|
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){
|
|
|
|
plat_settings->font_size = str_to_int_c(argv[i]);
|
2017-11-20 23:31:57 +00:00
|
|
|
settings->font_size = plat_settings->font_size;
|
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;
|
2017-06-12 17:40:54 +00:00
|
|
|
|
2017-07-03 15:43:51 +00:00
|
|
|
case CLAct_LogStdout:
|
2017-06-12 17:40:54 +00:00
|
|
|
{
|
2017-07-03 15:43:51 +00:00
|
|
|
plat_settings->use_log = LogTo_Stdout;
|
|
|
|
action = CLAct_Nothing;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CLAct_LogFile:
|
|
|
|
{
|
|
|
|
plat_settings->use_log = LogTo_LogFile;
|
2017-06-12 17:40:54 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal App_Vars*
|
2016-10-22 15:30:25 +00:00
|
|
|
app_setup_memory(System_Functions *system, Application_Memory *memory){
|
2016-06-29 17:16:08 +00:00
|
|
|
Partition _partition = make_part(memory->vars_memory, memory->vars_memory_size);
|
2018-11-20 08:18:54 +00:00
|
|
|
App_Vars *vars = push_array(&_partition, App_Vars, 1);
|
2017-02-17 22:03:19 +00:00
|
|
|
Assert(vars != 0);
|
2018-03-10 02:06:55 +00:00
|
|
|
memset(vars, 0, sizeof(*vars));
|
2016-06-29 17:16:08 +00:00
|
|
|
vars->models.mem.part = _partition;
|
2018-08-18 08:16:52 +00:00
|
|
|
heap_init(&vars->models.mem.heap);
|
|
|
|
heap_extend(&vars->models.mem.heap, memory->target_memory, memory->target_memory_size);
|
2016-06-29 17:16:08 +00:00
|
|
|
return(vars);
|
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
internal u32
|
|
|
|
get_event_flags(Key_Code keycode){
|
|
|
|
u32 event_flags = 0;
|
|
|
|
if (keycode == key_esc){
|
|
|
|
event_flags |= EventOnEsc;
|
|
|
|
event_flags |= EventOnAnyKey;
|
|
|
|
}
|
2018-11-20 08:18:54 +00:00
|
|
|
else if (keycode == key_mouse_left || keycode == key_mouse_left_release){
|
|
|
|
event_flags |= EventOnMouseLeftButton;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2018-11-20 08:18:54 +00:00
|
|
|
else if (keycode == key_mouse_right || keycode == key_mouse_right_release){
|
|
|
|
event_flags |= EventOnMouseRightButton;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else if (keycode == key_mouse_wheel){
|
2018-11-20 08:18:54 +00:00
|
|
|
event_flags |= EventOnMouseWheel;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else if (keycode == key_mouse_move){
|
2018-11-20 08:18:54 +00:00
|
|
|
event_flags |= EventOnMouseMove;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else if (keycode == key_animate){
|
2018-11-20 08:18:54 +00:00
|
|
|
event_flags |= EventOnAnimate;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
2018-11-20 08:18:54 +00:00
|
|
|
else if (keycode == key_click_activate_view || keycode == key_click_deactivate_view){
|
|
|
|
event_flags |= EventOnViewActivation;
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
event_flags |= EventOnAnyKey;
|
|
|
|
}
|
|
|
|
return(event_flags);
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
internal void
|
|
|
|
force_abort_coroutine(System_Functions *system, Models *models, View *view){
|
|
|
|
User_Input user_in = {};
|
|
|
|
user_in.abort = true;
|
|
|
|
for (u32 j = 0; j < 10 && models->command_coroutine != 0; ++j){
|
|
|
|
models->command_coroutine = app_resume_coroutine(system, &models->app_links, Co_Command, models->command_coroutine, &user_in, models->command_coroutine_flags);
|
|
|
|
}
|
|
|
|
if (models->command_coroutine != 0){
|
|
|
|
// TODO(allen): post grave warning
|
|
|
|
models->command_coroutine = 0;
|
|
|
|
}
|
2019-02-10 09:18:34 +00:00
|
|
|
init_query_set(&view->query_set);
|
2018-11-20 08:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
launch_command_via_event(System_Functions *system, Application_Step_Result *app_result, Models *models, View *view, Key_Event_Data event){
|
|
|
|
models->key = event;
|
|
|
|
|
|
|
|
i32 map = view_get_map(view);
|
|
|
|
Command_Binding cmd_bind = map_extract_recursive(&models->mapping, map, event);
|
|
|
|
|
2019-02-08 04:45:13 +00:00
|
|
|
if (cmd_bind.custom != 0){
|
2018-11-20 08:18:54 +00:00
|
|
|
Assert(models->command_coroutine == 0);
|
|
|
|
Coroutine_Head *command_coroutine = system->create_coroutine(command_caller);
|
|
|
|
models->command_coroutine = command_coroutine;
|
|
|
|
|
2019-02-08 04:45:13 +00:00
|
|
|
Command_In cmd_in = {};
|
2018-11-20 08:18:54 +00:00
|
|
|
cmd_in.models = models;
|
|
|
|
cmd_in.bind = cmd_bind;
|
|
|
|
|
|
|
|
models->command_coroutine = app_launch_coroutine(system, &models->app_links, Co_Command, models->command_coroutine, &cmd_in, models->command_coroutine_flags);
|
|
|
|
|
|
|
|
models->prev_command = cmd_bind;
|
2019-02-25 23:42:13 +00:00
|
|
|
if (event.keycode != key_animate){
|
|
|
|
app_result->animating = true;
|
|
|
|
}
|
2018-11-20 08:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
launch_command_via_keycode(System_Functions *system, Application_Step_Result *app_result, Models *models, View *view, Key_Code keycode){
|
|
|
|
Key_Event_Data event = {};
|
|
|
|
event.keycode = keycode;
|
|
|
|
launch_command_via_event(system, app_result, models, view, event);
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
App_Read_Command_Line_Sig(app_read_command_line){
|
|
|
|
i32 out_size = 0;
|
2016-10-22 15:30:25 +00:00
|
|
|
App_Vars *vars = app_setup_memory(system, memory);
|
2016-07-03 22:29:07 +00:00
|
|
|
App_Settings *settings = &vars->models.settings;
|
2018-08-05 07:09:18 +00:00
|
|
|
memset(settings, 0, sizeof(*settings));
|
2017-03-29 16:32:06 +00:00
|
|
|
plat_settings->font_size = 16;
|
2017-07-19 20:07:50 +00:00
|
|
|
if (argc > 1){
|
|
|
|
init_command_line_settings(&vars->models.settings, plat_settings, argc, argv);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2016-07-03 22:29:07 +00:00
|
|
|
*files = vars->models.settings.init_files;
|
|
|
|
*file_count = &vars->models.settings.init_files_count;
|
2016-06-29 17:16:08 +00:00
|
|
|
return(out_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
App_Init_Sig(app_init){
|
2016-09-20 19:48:02 +00:00
|
|
|
App_Vars *vars = (App_Vars*)memory->vars_memory;
|
|
|
|
Models *models = &vars->models;
|
2017-03-29 20:50:29 +00:00
|
|
|
models->keep_playing = true;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
app_links_init(system, &models->app_links, memory->user_memory, memory->user_memory_size);
|
|
|
|
|
|
|
|
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-02-05 09:13:38 +00:00
|
|
|
Partition *part = &models->mem.part;
|
2017-03-29 20:50:29 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): live set
|
2016-06-29 17:16:08 +00:00
|
|
|
{
|
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;
|
|
|
|
models->live_set.views = push_array(part, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 23:55:50 +00:00
|
|
|
{
|
|
|
|
umem memsize = KB(8);
|
2019-02-05 09:13:38 +00:00
|
|
|
void *mem = push_array(part, u8, (i32)memsize);
|
2017-05-19 23:55:50 +00:00
|
|
|
parse_context_init_memory(&models->parse_context_memory, mem, memsize);
|
2018-08-18 08:16:52 +00:00
|
|
|
parse_context_add_default(&models->parse_context_memory, &models->mem.heap);
|
2017-05-19 23:55:50 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
{
|
|
|
|
Assert(models->config_api.get_bindings != 0);
|
2017-01-23 06:19:43 +00:00
|
|
|
i32 wanted_size = models->config_api.get_bindings(models->app_links.memory, models->app_links.memory_size);
|
2017-11-08 18:24:30 +00:00
|
|
|
Assert(wanted_size <= models->app_links.memory_size);
|
|
|
|
interpret_binding_buffer(models, models->app_links.memory, wanted_size);
|
2016-06-29 17:16:08 +00:00
|
|
|
memset(models->app_links.memory, 0, wanted_size);
|
|
|
|
}
|
|
|
|
|
2018-08-11 05:42:00 +00:00
|
|
|
dynamic_variables_init(&models->variable_layout);
|
2019-02-05 09:13:38 +00:00
|
|
|
dynamic_workspace_init(&models->mem.heap, &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-02-05 09:13:38 +00:00
|
|
|
working_set_init(system, &models->working_set, part, &vars->models.mem.heap);
|
2016-09-22 00:01:12 +00:00
|
|
|
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
|
2016-10-24 23:02:10 +00:00
|
|
|
models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-08 10:03:48 +00:00
|
|
|
// NOTE(allen): history setup
|
|
|
|
global_history_init(&models->global_history);
|
|
|
|
|
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){
|
2018-08-18 08:16:52 +00:00
|
|
|
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
|
2018-05-10 08:12:47 +00:00
|
|
|
copy(dest, make_string((char*)clipboard.str, clipboard.size));
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): style setup
|
2017-03-11 18:53:48 +00:00
|
|
|
models->global_font_id = 1;
|
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-02-05 09:13:38 +00:00
|
|
|
models->title_space = push_array(part, char, models->title_capacity);
|
2017-11-30 19:02:37 +00:00
|
|
|
{
|
|
|
|
String builder = make_string_cap(models->title_space, 0, models->title_capacity);
|
|
|
|
append(&builder, WINDOW_NAME);
|
|
|
|
terminate_with_null(&builder);
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:04:16 +00:00
|
|
|
// NOTE(allen): init system context
|
|
|
|
models->system = system;
|
|
|
|
models->vars = vars;
|
2016-09-21 22:34:19 +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[] = {
|
2017-03-10 20:44:42 +00:00
|
|
|
{ make_lit_string("*messages*"), &models->message_buffer, true , },
|
2018-03-25 06:43:56 +00:00
|
|
|
{ make_lit_string("*scratch*"), &models->scratch_buffer, false, },
|
2016-09-21 22:34:19 +00:00
|
|
|
};
|
|
|
|
|
2018-08-18 08:16:52 +00:00
|
|
|
Heap *heap = &models->mem.heap;
|
2016-09-21 22:34:19 +00:00
|
|
|
for (i32 i = 0; i < ArrayCount(init_files); ++i){
|
2018-08-18 08:16:52 +00:00
|
|
|
Editing_File *file = working_set_alloc_always(&models->working_set, heap, &models->lifetime_allocator);
|
2019-02-05 09:13:38 +00:00
|
|
|
buffer_bind_name(models, heap, part, &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;
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:32:06 +00:00
|
|
|
if (init_files[i].read_only){
|
|
|
|
init_read_only_file(system, models, file);
|
|
|
|
}
|
|
|
|
else{
|
2019-02-13 23:15:22 +00:00
|
|
|
File_Attributes attributes = {};
|
|
|
|
init_normal_file(system, models, 0, 0, attributes, file);
|
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);
|
2017-02-12 06:01:01 +00:00
|
|
|
file->settings.unwrapped_lines = true;
|
2016-09-21 22:34:19 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): setup first panel
|
|
|
|
{
|
|
|
|
Panel *panel = layout_initialize(part, &models->layout);
|
2019-02-27 05:49:35 +00:00
|
|
|
View *new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, panel);
|
2019-02-05 09:13:38 +00:00
|
|
|
view_set_file(system, models, new_view, models->scratch_buffer);
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
// NOTE(allen): hot directory
|
2017-02-12 06:01:01 +00:00
|
|
|
hot_directory_init(&models->hot_directory, current_directory);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-03-21 03:18:08 +00:00
|
|
|
// NOTE(allen): child process container
|
|
|
|
child_process_container_init(&models->child_processes, models);
|
2016-10-27 23:45:41 +00:00
|
|
|
|
|
|
|
// NOTE(allen): init GUI keys
|
|
|
|
models->user_up_key = key_up;
|
|
|
|
models->user_down_key = key_down;
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App_Step_Sig(app_step){
|
|
|
|
App_Vars *vars = (App_Vars*)memory->vars_memory;
|
|
|
|
Models *models = &vars->models;
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Application_Step_Result app_result = {};
|
2018-03-03 07:46:44 +00:00
|
|
|
app_result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
|
|
|
app_result.lctrl_lalt_is_altgr = models->settings.lctrl_lalt_is_altgr;
|
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-02-27 21:14:25 +00:00
|
|
|
begin_frame(target);
|
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
|
|
|
|
String clipboard = input->clipboard;
|
2018-11-20 04:18:57 +00:00
|
|
|
if (clipboard.str != 0){
|
2018-08-18 08:16:52 +00:00
|
|
|
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
|
2017-03-23 19:15:33 +00:00
|
|
|
dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size);
|
2019-03-15 08:38:28 +00:00
|
|
|
if(input->clipboard_changed && models->clipboard_change) {
|
|
|
|
models->clipboard_change(&models->app_links, *dest, clipboard_from_os);
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 21:30:08 +00:00
|
|
|
// NOTE(allen): check files are up to date
|
|
|
|
{
|
|
|
|
b32 mem_too_small = 0;
|
2017-03-23 19:14:39 +00:00
|
|
|
i32 size = 0;
|
|
|
|
i32 buffer_size = KB(32);
|
2016-08-26 21:30:08 +00:00
|
|
|
|
|
|
|
Partition *part = &models->mem.part;
|
|
|
|
Temp_Memory temp = begin_temp_memory(part);
|
|
|
|
char *buffer = push_array(part, char, buffer_size);
|
2017-02-12 06:01:01 +00:00
|
|
|
u32 unmark_top = 0;
|
|
|
|
u32 unmark_max = (8 << 10);
|
2016-08-27 00:42:16 +00:00
|
|
|
Editing_File **unmark = (Editing_File**)push_array(part, Editing_File*, unmark_max);
|
2016-08-26 21:30:08 +00:00
|
|
|
|
|
|
|
Working_Set *working_set = &models->working_set;
|
|
|
|
|
|
|
|
for (;system->get_file_change(buffer, buffer_size, &mem_too_small, &size);){
|
|
|
|
Assert(!mem_too_small);
|
2018-11-20 08:18:54 +00:00
|
|
|
Editing_File_Name canon = {};
|
2018-11-20 22:54:00 +00:00
|
|
|
if (get_canon_name(system, make_string(buffer, size), &canon)){
|
2017-11-30 23:25:49 +00:00
|
|
|
Editing_File *file = working_set_contains_canon(working_set, canon.name);
|
2017-11-21 21:30:40 +00:00
|
|
|
if (file != 0){
|
2016-08-26 21:30:08 +00:00
|
|
|
if (file->state.ignore_behind_os == 0){
|
2019-02-25 23:42:13 +00:00
|
|
|
file_add_dirty_flag(file, DirtyState_UnloadedChanges);
|
2016-08-26 21:30:08 +00:00
|
|
|
}
|
2016-08-27 00:42:16 +00:00
|
|
|
else if (file->state.ignore_behind_os == 1){
|
2017-02-12 06:01:01 +00:00
|
|
|
file->state.ignore_behind_os = 2;
|
|
|
|
unmark[unmark_top++] = file;
|
2016-08-27 00:42:16 +00:00
|
|
|
if (unmark_top == unmark_max){
|
|
|
|
break;
|
|
|
|
}
|
2016-08-26 21:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
for (u32 i = 0; i < unmark_top; ++i){
|
2016-08-27 00:42:16 +00:00
|
|
|
unmark[i]->state.ignore_behind_os = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-26 21:30:08 +00:00
|
|
|
end_temp_memory(temp);
|
|
|
|
}
|
|
|
|
|
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){
|
2018-11-18 18:21:17 +00:00
|
|
|
Partition *scratch = &models->mem.part;
|
2019-03-21 03:18:08 +00:00
|
|
|
Child_Process_Container *child_processes = &models->child_processes;
|
2018-11-18 18:21:17 +00:00
|
|
|
|
2019-03-21 03:18:08 +00:00
|
|
|
Temp_Memory temp = begin_temp_memory(scratch);
|
|
|
|
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;
|
|
|
|
system->cli_begin_update(cli);
|
|
|
|
if (system->cli_update_step(cli, dest, max, &amount)){
|
|
|
|
if (file != 0 && amount > 0){
|
|
|
|
amount = eol_in_place_convert_in(dest, amount);
|
|
|
|
output_file_append(system, models, file, make_string(dest, amount));
|
|
|
|
edited_file = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (system->cli_end_update(cli)){
|
|
|
|
if (file != 0){
|
|
|
|
char str_space[256];
|
|
|
|
String str = make_fixed_width_string(str_space);
|
|
|
|
append(&str, make_lit_string("exited with code "));
|
|
|
|
append_int_to_str(&str, cli->exit);
|
|
|
|
output_file_append(system, models, file, str);
|
|
|
|
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){
|
2018-11-18 18:21:17 +00:00
|
|
|
file_cursor_to_end(system, models, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
end_temp_memory(temp);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Key_Event_Data mouse_event = {};
|
2018-12-17 04:31:04 +00:00
|
|
|
block_copy(mouse_event.modifiers, input->keys.modifiers, sizeof(mouse_event.modifiers));
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
if (input->mouse.press_l){
|
|
|
|
mouse_event.keycode = key_mouse_left;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
else if (input->mouse.release_l){
|
|
|
|
mouse_event.keycode = key_mouse_left_release;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->mouse.press_r){
|
|
|
|
mouse_event.keycode = key_mouse_right;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
else if (input->mouse.release_r){
|
|
|
|
mouse_event.keycode = key_mouse_right_release;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->mouse.wheel != 0){
|
|
|
|
mouse_event.keycode = key_mouse_wheel;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
if (input->mouse.p != models->prev_p){
|
|
|
|
b32 was_in_window = hit_check(i32R(0, 0, prev_dim.x, prev_dim.y), models->prev_p);
|
|
|
|
b32 is_in_window = hit_check(i32R(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){
|
|
|
|
mouse_event.keycode = key_mouse_move;
|
2018-08-04 02:41:38 +00:00
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
if (models->animated_last_frame){
|
|
|
|
mouse_event.keycode = key_animate;
|
|
|
|
input->keys.keys[input->keys.count++] = mouse_event;
|
|
|
|
}
|
|
|
|
|
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)){
|
|
|
|
if (hit_check(mouse.x, mouse.y, panel->rect_full)){
|
|
|
|
mouse_panel = panel;
|
|
|
|
if (!hit_check(mouse.x, mouse.y, panel->rect_inner)){
|
|
|
|
mouse_in_margin = true;
|
|
|
|
for (divider_panel = mouse_panel->parent;
|
|
|
|
divider_panel != 0;
|
|
|
|
divider_panel = divider_panel->parent){
|
|
|
|
if (hit_check(mouse.x, mouse.y, divider_panel->rect_inner)){
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2019-02-25 23:42:13 +00:00
|
|
|
// Open command line files.
|
|
|
|
char space[512];
|
|
|
|
String cl_file_name = make_fixed_width_string(space);
|
|
|
|
copy_ss(&cl_file_name, models->hot_directory.string);
|
|
|
|
i32 cl_file_name_len = cl_file_name.size;
|
|
|
|
for (i32 i = 0; i < models->settings.init_files_count; ++i){
|
|
|
|
cl_file_name.size = cl_file_name_len;
|
|
|
|
|
|
|
|
String file_name = {};
|
|
|
|
Editing_File_Name canon_name = {};
|
2019-02-27 05:49:35 +00:00
|
|
|
if (get_canon_name(system, make_string_slowly(models->settings.init_files[i]), &canon_name)){
|
2019-02-25 23:42:13 +00:00
|
|
|
file_name = canon_name.name;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc(&cl_file_name, models->settings.init_files[i]);
|
|
|
|
file_name = cl_file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer_ID id = 0;
|
|
|
|
create_buffer(&models->app_links, file_name, 0, &id);
|
|
|
|
}
|
2019-02-27 05:49:35 +00:00
|
|
|
#endif
|
2019-02-25 23:42:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
// NOTE(allen): consume event stream
|
|
|
|
Key_Event_Data *key_ptr = input->keys.keys;
|
|
|
|
Key_Event_Data *key_end = key_ptr + input->keys.count;
|
|
|
|
for (;key_ptr < key_end; key_ptr += 1){
|
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
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
switch (vars->state){
|
|
|
|
case APP_STATE_EDIT:
|
|
|
|
{
|
|
|
|
Key_Code keycode = key_ptr->keycode;
|
|
|
|
|
|
|
|
enum{
|
|
|
|
EventConsume_None,
|
|
|
|
EventConsume_BeginResize,
|
|
|
|
EventConsume_ClickChangeView,
|
|
|
|
EventConsume_Command,
|
|
|
|
};
|
|
|
|
i32 event_consume_mode = EventConsume_Command;
|
2019-02-05 09:13:38 +00:00
|
|
|
if (keycode == key_mouse_left && input->mouse.press_l && (divider_panel != 0)){
|
2018-11-20 04:18:57 +00:00
|
|
|
event_consume_mode = EventConsume_BeginResize;
|
|
|
|
}
|
|
|
|
else if (keycode == key_mouse_left && input->mouse.press_l && mouse_panel != 0 && mouse_panel != active_panel){
|
|
|
|
event_consume_mode = EventConsume_ClickChangeView;
|
2018-08-05 07:09:18 +00:00
|
|
|
}
|
2017-07-18 00:00:07 +00:00
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
switch (event_consume_mode){
|
|
|
|
case EventConsume_BeginResize:
|
|
|
|
{
|
|
|
|
vars->state = APP_STATE_RESIZING;
|
2019-02-05 09:13:38 +00:00
|
|
|
models->resizing_intermediate_panel = divider_panel;
|
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): kill coroutine if we have one
|
2018-11-20 04:18:57 +00:00
|
|
|
if (models->command_coroutine != 0){
|
2018-11-20 08:18:54 +00:00
|
|
|
force_abort_coroutine(system, models, view);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): run deactivate command
|
|
|
|
launch_command_via_keycode(system, &app_result, models, view, key_click_deactivate_view);
|
|
|
|
|
|
|
|
// NOTE(allen): kill coroutine if we have one (again because we just launched a command)
|
|
|
|
if (models->command_coroutine != 0){
|
|
|
|
force_abort_coroutine(system, models, view);
|
2017-07-18 00:00:07 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
layout->active_panel = mouse_panel;
|
2018-11-20 04:18:57 +00:00
|
|
|
app_result.animating = 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
|
|
|
|
launch_command_via_keycode(system, &app_result, models, view, key_click_activate_view);
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
case EventConsume_Command:
|
|
|
|
{
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
// NOTE(allen): update command coroutine
|
2018-11-20 04:18:57 +00:00
|
|
|
if (models->command_coroutine != 0){
|
2018-11-20 08:18:54 +00:00
|
|
|
models->key = *key_ptr;
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
Coroutine_Head *command_coroutine = models->command_coroutine;
|
|
|
|
u32 abort_flags = models->command_coroutine_flags[1];
|
|
|
|
u32 get_flags = models->command_coroutine_flags[0] | abort_flags;
|
|
|
|
|
|
|
|
u32 event_flags = get_event_flags(key_ptr->keycode);
|
|
|
|
if ((get_flags & event_flags) != 0){
|
|
|
|
i32 map = view_get_map(view);
|
|
|
|
Command_Binding cmd_bind = map_extract_recursive(&models->mapping, map, *key_ptr);
|
|
|
|
|
|
|
|
User_Input user_in = {};
|
|
|
|
user_in.key = *key_ptr;
|
|
|
|
user_in.command.command = cmd_bind.custom;
|
|
|
|
user_in.abort = ((abort_flags & event_flags) != 0);
|
|
|
|
models->command_coroutine = app_resume_coroutine(system, &models->app_links, Co_Command, command_coroutine, &user_in, models->command_coroutine_flags);
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
if (user_in.key.keycode != key_animate){
|
|
|
|
app_result.animating = true;
|
|
|
|
}
|
|
|
|
|
2018-11-20 04:18:57 +00:00
|
|
|
if (models->command_coroutine == 0){
|
2019-02-10 09:18:34 +00:00
|
|
|
init_query_set(&view->query_set);
|
2018-11-20 04:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
// NOTE(allen): launch command
|
2016-06-29 17:16:08 +00:00
|
|
|
else{
|
2018-11-20 08:18:54 +00:00
|
|
|
launch_command_via_event(system, &app_result, models, view, *key_ptr);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2018-11-20 04:18:57 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case APP_STATE_RESIZING:
|
|
|
|
{
|
|
|
|
Key_Code keycode = key_ptr->keycode;
|
|
|
|
u32 event_flags = get_event_flags(keycode);
|
|
|
|
if (event_flags & EventOnAnyKey || keycode == key_mouse_left_release){
|
|
|
|
vars->state = APP_STATE_EDIT;
|
|
|
|
}
|
|
|
|
else if (keycode == key_mouse_move){
|
|
|
|
if (input->mouse.l){
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *split = models->resizing_intermediate_panel;
|
|
|
|
Range limits = layout_get_limiting_range_on_split(layout, split);
|
|
|
|
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{
|
2018-11-20 04:18:57 +00:00
|
|
|
vars->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
|
|
|
}
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 22:54:00 +00:00
|
|
|
// NOTE(allen): send panel size update
|
2019-02-24 07:22:16 +00:00
|
|
|
if (models->layout.panel_state_dirty && models->hooks[hook_buffer_viewer_update] != 0){
|
2018-11-20 22:54:00 +00:00
|
|
|
models->layout.panel_state_dirty = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
models->hooks[hook_buffer_viewer_update](&models->app_links);
|
2018-11-20 22:54:00 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:33:01 +00:00
|
|
|
// NOTE(allen): step panels
|
|
|
|
{
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *active_panel = layout_get_active_panel(layout);
|
2018-11-18 18:33:01 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
GUI_Scroll_Vars *scroll_vars = 0;
|
|
|
|
b32 file_scroll = false;
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-02-10 09:18:34 +00:00
|
|
|
if (!view->ui_mode){
|
2019-02-09 22:48:53 +00:00
|
|
|
scroll_vars = &edit_pos.scroll;
|
2018-11-18 18:33:01 +00:00
|
|
|
file_scroll = true;
|
|
|
|
}
|
|
|
|
else{
|
2019-02-10 09:18:34 +00:00
|
|
|
scroll_vars = &view->ui_scroll;
|
2018-11-18 18:33:01 +00:00
|
|
|
file_scroll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b32 active = (panel == active_panel);
|
2019-02-26 19:59:57 +00:00
|
|
|
GUI_Scroll_Vars new_scroll = do_step_file_view(system, models, view, panel->rect_inner, active, dt, *scroll_vars);
|
2018-11-18 18:33:01 +00:00
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
if (memcmp(scroll_vars, &new_scroll, sizeof(*scroll_vars)) != 0){
|
2018-11-18 18:33:01 +00:00
|
|
|
if (file_scroll){
|
2019-02-27 05:49:35 +00:00
|
|
|
view_set_scroll(system, models, view, new_scroll);
|
2018-11-18 18:33:01 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-26 19:59:57 +00:00
|
|
|
*scroll_vars = new_scroll;
|
2018-11-18 18:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-06 22:28:39 +00:00
|
|
|
// 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)){
|
2016-07-06 22:28:39 +00:00
|
|
|
View *view = panel->view;
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
edit_pos.scroll.scroll_x = (f32)edit_pos.scroll.target_x;
|
|
|
|
edit_pos.scroll.scroll_y = (f32)edit_pos.scroll.target_y;
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
2016-07-06 22:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): hook for files marked "edit finished"
|
2019-01-31 12:38:24 +00:00
|
|
|
{
|
|
|
|
File_Edit_Finished_Function *hook_file_edit_finished = models->hook_file_edit_finished;
|
|
|
|
if (hook_file_edit_finished != 0){
|
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-02-04 01:33:44 +00:00
|
|
|
if (working_set->edit_finished_list.next != &working_set->edit_finished_list){
|
2019-02-25 23:42:13 +00:00
|
|
|
b32 trigger_hook = false;
|
|
|
|
|
|
|
|
u32 elapse_time = models->edit_finished_hook_repeat_speed;
|
|
|
|
if (elapse_time != 0){
|
|
|
|
trigger_hook = true;
|
|
|
|
}
|
|
|
|
else if (working_set->time_of_next_edit_finished_signal == 0){
|
|
|
|
u32 trigger_window_length = 0;
|
|
|
|
if (elapse_time > 5){
|
|
|
|
trigger_window_length = elapse_time - 5;
|
|
|
|
}
|
|
|
|
u64 trigger_time = system->now_time() + (u64)trigger_window_length*1000LLU;
|
|
|
|
working_set->time_of_next_edit_finished_signal = trigger_time;
|
2019-02-04 01:33:44 +00:00
|
|
|
system->wake_up_timer_set(working_set->edit_finished_timer, elapse_time);
|
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
else if (system->now_time() >= working_set->time_of_next_edit_finished_signal){
|
|
|
|
trigger_hook = true;
|
|
|
|
}
|
|
|
|
if (trigger_hook){
|
|
|
|
Partition *scratch = &models->mem.part;
|
|
|
|
|
|
|
|
Temp_Memory temp = begin_temp_memory(scratch);
|
|
|
|
Node *first = working_set->edit_finished_list.next;
|
|
|
|
Node *stop = &working_set->edit_finished_list;
|
|
|
|
|
|
|
|
Editing_File **file_ptrs = push_array(scratch, Editing_File*, 0);
|
|
|
|
for (Node *node = first;
|
|
|
|
node != stop;
|
|
|
|
node = node->next){
|
|
|
|
Editing_File **file_ptr = push_array(scratch, Editing_File*, 1);
|
|
|
|
*file_ptr = CastFromMember(Editing_File, edit_finished_mark_node, node);
|
|
|
|
}
|
|
|
|
i32 id_count = (i32)(push_array(scratch, Editing_File*, 0) - file_ptrs);
|
|
|
|
|
|
|
|
Buffer_ID *ids = push_array(scratch, Buffer_ID, id_count);
|
|
|
|
for (i32 i = 0; i < id_count; i += 1){
|
|
|
|
ids[i] = file_ptrs[i]->id.id;
|
2019-02-04 01:33:44 +00:00
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
|
|
|
|
working_set->do_not_mark_edits = true;
|
|
|
|
hook_file_edit_finished(&models->app_links, ids, id_count);
|
|
|
|
working_set->do_not_mark_edits = false;
|
|
|
|
|
|
|
|
for (i32 i = 0; i < id_count; i += 1){
|
|
|
|
block_zero_struct(&file_ptrs[i]->edit_finished_mark_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
dll_init_sentinel(&working_set->edit_finished_list);
|
|
|
|
working_set->time_of_next_edit_finished_signal = 0;
|
|
|
|
|
|
|
|
end_temp_memory(temp);
|
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){
|
|
|
|
Hook_Function *exit_func = models->hooks[hook_exit];
|
|
|
|
if (exit_func != 0){
|
|
|
|
if (exit_func(&models->app_links) == 0){
|
|
|
|
app_result.animating = true;
|
|
|
|
models->keep_playing = true;
|
|
|
|
}
|
2016-09-09 13:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): rendering
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
f32 literal_dt = 0.f;
|
|
|
|
u64 now_usecond_stamp = system->now_time();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
{
|
|
|
|
Color_Table color_table = models->fallback_color_table;
|
|
|
|
if (models->modify_color_table != 0){
|
|
|
|
Frame_Info frame = {};
|
|
|
|
frame.index = models->frame_counter;
|
|
|
|
frame.literal_dt = literal_dt;
|
|
|
|
frame.animation_dt = animation_dt;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
begin_render_section(target, system, models->frame_counter, literal_dt, animation_dt);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *active_panel = layout_get_active_panel(layout);
|
2018-11-18 19:47:28 +00:00
|
|
|
View *active_view = active_panel->view;
|
2018-09-22 23:45:24 +00:00
|
|
|
|
2016-06-29 17:16:08 +00:00
|
|
|
// NOTE(allen): render the panels
|
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)){
|
|
|
|
i32_Rect full = panel->rect_full;
|
|
|
|
i32_Rect inner = panel->rect_inner;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
|
|
|
View *view = panel->view;
|
2019-02-25 23:42:13 +00:00
|
|
|
//Style *style = &models->styles.styles[0];
|
|
|
|
Color_Table color_table = models->color_table;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
draw_rectangle(target, full, color_table.vals[Stag_Back]);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
GUI_Scroll_Vars *scroll_vars = &edit_pos.scroll;
|
2016-07-02 17:54:56 +00:00
|
|
|
|
2018-11-27 15:21:10 +00:00
|
|
|
b32 active = (panel == active_panel);
|
2019-02-05 09:13:38 +00:00
|
|
|
do_render_file_view(system, view, models, scroll_vars, active_view, inner, active, target);
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-02-09 22:48:53 +00:00
|
|
|
view_set_edit_pos(view, edit_pos);
|
|
|
|
|
2018-11-27 15:21:10 +00:00
|
|
|
u32 margin_color = 0;
|
2016-06-29 17:16:08 +00:00
|
|
|
if (active){
|
2019-02-25 23:42:13 +00:00
|
|
|
margin_color = color_table.vals[Stag_Margin_Active];
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
else if (panel == mouse_panel){
|
2019-02-25 23:42:13 +00:00
|
|
|
margin_color = color_table.vals[Stag_Margin_Hover];
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-25 23:42:13 +00:00
|
|
|
margin_color = color_table.vals[Stag_Margin];
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
2018-11-27 15:21:10 +00:00
|
|
|
draw_rectangle(target, i32R( full.x0, full.y0, full.x1, inner.y0), margin_color);
|
|
|
|
draw_rectangle(target, i32R( full.x0, inner.y1, full.x1, full.y1), margin_color);
|
|
|
|
draw_rectangle(target, i32R( full.x0, inner.y0, inner.x0, inner.y1), margin_color);
|
|
|
|
draw_rectangle(target, i32R(inner.x1, inner.y0, full.x1, inner.y1), margin_color);
|
2016-06-29 17:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end_render_section(target, system);
|
|
|
|
}
|
|
|
|
|
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-02-25 23:42:13 +00:00
|
|
|
// TODO(allen): whenever something wants to animate it should set animate_next_frame now.
|
|
|
|
app_result.animating = app_result.animating || models->animate_next_frame;
|
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 = {};
|
|
|
|
|
|
|
|
result.read_command_line = app_read_command_line;
|
|
|
|
result.init = app_init;
|
|
|
|
result.step = app_step;
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|