2016-06-29 17:16:08 +00:00
/*
2016-09-03 01:15:53 +00:00
* Mr . 4 th Dimention - Allen Webster
*
* 12.12 .2014
*
* Application layer for project codename " 4ed "
*
*/
2016-06-29 17:16:08 +00:00
// TOP
// App Structs
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
2016-09-01 03:06:46 +00:00
typedef enum App_State {
2016-06-29 17:16:08 +00:00
APP_STATE_EDIT ,
APP_STATE_RESIZING ,
// never below this
APP_STATE_COUNT
2016-09-01 03:06:46 +00:00
} App_State ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct App_State_Resizing {
2016-06-29 17:16:08 +00:00
Panel_Divider * divider ;
2016-09-01 03:06:46 +00:00
} App_State_Resizing ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct CLI_Process {
2016-06-29 17:16:08 +00:00
CLI_Handles cli ;
Editing_File * out_file ;
b32 cursor_at_end ;
2016-09-01 03:06:46 +00:00
} CLI_Process ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct CLI_List {
2016-06-29 17:16:08 +00:00
CLI_Process * procs ;
i32 count , max ;
2016-09-01 03:06:46 +00:00
} CLI_List ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct Command_Data {
2016-06-29 17:16:08 +00:00
Models * models ;
struct App_Vars * vars ;
System_Functions * system ;
Live_Views * live_set ;
i32 screen_width , screen_height ;
Key_Event_Data key ;
2016-09-01 03:06:46 +00:00
} Command_Data ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef enum Input_Types {
2016-06-29 17:16:08 +00:00
Input_AnyKey ,
Input_Esc ,
Input_MouseMove ,
Input_MouseLeftButton ,
Input_MouseRightButton ,
Input_MouseWheel ,
Input_Count
2016-09-01 03:06:46 +00:00
} Input_Types ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct Consumption_Record {
2016-06-29 17:16:08 +00:00
b32 consumed ;
char consumer [ 32 ] ;
2016-09-01 03:06:46 +00:00
} Consumption_Record ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef struct Available_Input {
2017-01-29 00:03:23 +00:00
Key_Input_Data * keys ;
2016-06-29 17:16:08 +00:00
Mouse_State * mouse ;
Consumption_Record records [ Input_Count ] ;
2016-09-01 03:06:46 +00:00
} Available_Input ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
internal Available_Input
2017-01-29 00:03:23 +00:00
init_available_input ( Key_Input_Data * keys , Mouse_State * mouse ) {
2016-06-29 17:16:08 +00:00
Available_Input result = { 0 } ;
result . keys = keys ;
result . mouse = mouse ;
return ( result ) ;
}
2017-01-29 00:03:23 +00:00
internal Key_Input_Data
2016-06-29 17:16:08 +00:00
direct_get_key_data ( Available_Input * available ) {
2017-01-29 00:03:23 +00:00
Key_Input_Data result = * available - > keys ;
2016-06-29 17:16:08 +00:00
return ( result ) ;
}
2016-09-01 03:06:46 +00:00
internal Mouse_State
2016-06-29 17:16:08 +00:00
direct_get_mouse_state ( Available_Input * available ) {
Mouse_State result = * available - > mouse ;
return ( result ) ;
}
2017-01-29 00:03:23 +00:00
internal Key_Input_Data
2016-06-29 17:16:08 +00:00
get_key_data ( Available_Input * available ) {
2017-01-29 00:03:23 +00:00
Key_Input_Data result = { 0 } ;
2016-06-29 17:16:08 +00:00
if ( ! available - > records [ Input_AnyKey ] . consumed ) {
result = * available - > keys ;
}
else if ( ! available - > records [ Input_Esc ] . consumed ) {
i32 i = 0 ;
i32 count = available - > keys - > count ;
Key_Event_Data key = { 0 } ;
for ( i = 0 ; i < count ; + + i ) {
key = get_single_key ( available - > keys , i ) ;
if ( key . keycode = = key_esc ) {
result . count = 1 ;
result . keys [ 0 ] = key ;
break ;
}
}
}
return ( result ) ;
}
2016-09-01 03:06:46 +00:00
internal Mouse_State
2016-06-29 17:16:08 +00:00
get_mouse_state ( Available_Input * available ) {
Mouse_State mouse = * available - > mouse ;
if ( available - > records [ Input_MouseLeftButton ] . consumed ) {
mouse . l = 0 ;
mouse . press_l = 0 ;
mouse . release_l = 0 ;
}
if ( available - > records [ Input_MouseRightButton ] . consumed ) {
mouse . r = 0 ;
mouse . press_r = 0 ;
mouse . release_r = 0 ;
}
if ( available - > records [ Input_MouseWheel ] . consumed ) {
mouse . wheel = 0 ;
}
return ( mouse ) ;
}
2016-09-01 03:06:46 +00:00
internal void
2016-06-29 17:16:08 +00:00
consume_input ( Available_Input * available , i32 input_type , char * consumer ) {
Consumption_Record * record = & available - > records [ input_type ] ;
record - > consumed = 1 ;
if ( consumer ) {
String str = make_fixed_width_string ( record - > consumer ) ;
2016-08-28 04:31:06 +00:00
copy_sc ( & str , consumer ) ;
2016-06-29 17:16:08 +00:00
terminate_with_null ( & str ) ;
}
else {
record - > consumer [ 0 ] = 0 ;
}
}
2016-12-18 20:42:11 +00:00
struct App_Vars {
2016-06-29 17:16:08 +00:00
Models models ;
// TODO(allen): This wants to live in
// models with everyone else but the order
// of declaration is a little bit off...
Live_Views live_set ;
CLI_List cli_processes ;
App_State state ;
App_State_Resizing resizing ;
Command_Data command_data ;
Available_Input available_input ;
2016-12-18 20:42:11 +00:00
} ;
2017-02-17 22:03:19 +00:00
global_const App_Vars null_app_vars = { 0 } ;
2016-06-29 17:16:08 +00:00
2016-09-01 03:06:46 +00:00
typedef enum Coroutine_Type {
2016-06-29 17:16:08 +00:00
Co_View ,
Co_Command
2016-09-01 03:06:46 +00:00
} Coroutine_Type ;
typedef struct App_Coroutine_State {
2016-06-29 17:16:08 +00:00
void * co ;
2016-08-29 01:03:26 +00:00
i32 type ;
2016-09-01 03:06:46 +00:00
} App_Coroutine_State ;
2016-06-29 17:16:08 +00:00
inline App_Coroutine_State
get_state ( Application_Links * app ) {
App_Coroutine_State state = { 0 } ;
state . co = app - > current_coroutine ;
state . type = app - > type_coroutine ;
return ( state ) ;
}
inline void
restore_state ( Application_Links * app , App_Coroutine_State state ) {
app - > current_coroutine = state . co ;
app - > type_coroutine = state . type ;
}
inline Coroutine *
2016-11-22 18:26:58 +00:00
app_launch_coroutine ( System_Functions * system , Application_Links * app , Coroutine_Type type , Coroutine * co , void * in , void * out ) {
2016-06-29 17:16:08 +00:00
Coroutine * result = 0 ;
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 ) ;
}
inline Coroutine *
2016-11-22 18:26:58 +00:00
app_resume_coroutine ( System_Functions * system , Application_Links * app , Coroutine_Type type , Coroutine * co , void * in , void * out ) {
2016-06-29 17:16:08 +00:00
Coroutine * result = 0 ;
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 ) ;
}
inline void
output_file_append ( System_Functions * system , Models * models , Editing_File * file , String value , b32 cursor_at_end ) {
i32 end = buffer_size ( & file - > state . buffer ) ;
2016-07-06 22:04:31 +00:00
file_replace_range ( system , models , file , end , end , value . str , value . size ) ;
2016-06-29 17:16:08 +00:00
}
inline void
2016-07-14 21:44:34 +00:00
do_feedback_message ( System_Functions * system , Models * models , String value , b32 set_to_start = 0 ) {
2016-06-29 17:16:08 +00:00
Editing_File * file = models - > message_buffer ;
if ( file ) {
output_file_append ( system , models , file , value , true ) ;
2016-07-14 21:44:34 +00:00
i32 pos = 0 ;
if ( ! set_to_start ) {
pos = buffer_size ( & file - > state . buffer ) ;
}
2016-06-29 17:16:08 +00:00
for ( View_Iter iter = file_view_iter_init ( & models - > layout , file , 0 ) ;
file_view_iter_good ( iter ) ;
iter = file_view_iter_next ( iter ) ) {
2017-03-12 01:20:24 +00:00
view_cursor_move ( system , iter . view , pos ) ;
2016-06-29 17:16:08 +00:00
}
}
}
// Commands
# define USE_MODELS(n) Models *n = command->models
# define USE_VARS(n) App_Vars *n = command->vars
# define USE_FILE(n,v) Editing_File *n = (v)->file_data.file
2016-09-21 22:34:19 +00:00
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
# define REQ_OPEN_VIEW(n) USE_VIEW(n); if (view_lock_level(n) > LockLevel_Open) return
# define REQ_READABLE_VIEW(n) USE_VIEW(n); if (view_lock_level(n) > LockLevel_Protected) return
2016-06-29 17:16:08 +00:00
# define REQ_FILE(n,v) Editing_File *n = (v)->file_data.file; if (!n) return
# define REQ_FILE_HISTORY(n,v) Editing_File *n = (v)->file_data.file; if (!n || !n->state.undo.undo.edits) return
# define COMMAND_DECL(n) internal void command_##n(System_Functions *system, Command_Data *command, Command_Binding binding)
internal View *
panel_make_empty ( System_Functions * system , App_Vars * vars , Panel * panel ) {
Models * models = & vars - > models ;
View_And_ID new_view ;
Assert ( panel - > view = = 0 ) ;
2017-01-14 03:01:35 +00:00
new_view = live_set_alloc_view ( & vars - > live_set , panel , models ) ;
2017-03-12 01:20:24 +00:00
view_set_file ( system , new_view . view , models - > scratch_buffer , models ) ;
2017-03-29 16:32:06 +00:00
new_view . view - > map = get_map ( models , models - > scratch_buffer - > settings . base_map_id ) ;
2016-06-29 17:16:08 +00:00
return ( new_view . view ) ;
}
COMMAND_DECL ( null ) {
AllowLocal ( command ) ;
}
COMMAND_DECL ( undo ) {
USE_MODELS ( models ) ;
REQ_OPEN_VIEW ( view ) ;
REQ_FILE_HISTORY ( file , view ) ;
2017-02-26 20:13:06 +00:00
view_undo_redo ( system , models , view , & file - > state . undo . undo , ED_UNDO ) ;
2016-06-29 17:16:08 +00:00
Assert ( file - > state . undo . undo . size > = 0 ) ;
}
COMMAND_DECL ( redo ) {
USE_MODELS ( models ) ;
REQ_OPEN_VIEW ( view ) ;
REQ_FILE_HISTORY ( file , view ) ;
2017-02-26 20:13:06 +00:00
view_undo_redo ( system , models , view , & file - > state . undo . redo , ED_REDO ) ;
2016-06-29 17:16:08 +00:00
Assert ( file - > state . undo . undo . size > = 0 ) ;
}
COMMAND_DECL ( interactive_new ) {
USE_VIEW ( view ) ;
2017-02-26 20:13:06 +00:00
view_show_interactive ( system , view , IAct_New , IInt_Sys_File_List , make_lit_string ( " New: " ) ) ;
2016-06-29 17:16:08 +00:00
}
COMMAND_DECL ( interactive_open ) {
USE_VIEW ( view ) ;
2017-02-26 20:13:06 +00:00
view_show_interactive ( system , view , IAct_Open , IInt_Sys_File_List , make_lit_string ( " Open: " ) ) ;
2016-06-29 17:16:08 +00:00
}
2017-03-27 22:36:42 +00:00
COMMAND_DECL ( interactive_open_or_new ) {
USE_VIEW ( view ) ;
view_show_interactive ( system , view , IAct_OpenOrNew , IInt_Sys_File_List , make_lit_string ( " Open: " ) ) ;
}
2016-06-29 17:16:08 +00:00
// TODO(allen): Improvements to reopen
2017-02-12 06:01:01 +00:00
// - Perform a diff
// - If the diff is not tremendously big, apply the edits.
2016-06-29 17:16:08 +00:00
COMMAND_DECL ( reopen ) {
USE_MODELS ( models ) ;
USE_VIEW ( view ) ;
REQ_FILE ( file , view ) ;
2017-02-12 06:01:01 +00:00
if ( file - > canon . name . str = = 0 ) return ;
2016-06-29 17:16:08 +00:00
2016-08-26 17:52:35 +00:00
if ( file - > canon . name . size ! = 0 ) {
Plat_Handle handle ;
if ( system - > load_handle ( file - > canon . name . str , & handle ) ) {
i32 size = system - > load_size ( handle ) ;
Partition * part = & models - > mem . part ;
Temp_Memory temp = begin_temp_memory ( part ) ;
char * buffer = push_array ( part , char , size ) ;
if ( buffer ) {
if ( system - > load_file ( handle , buffer , size ) ) {
2016-11-05 02:59:35 +00:00
system - > load_close ( handle ) ;
2016-08-26 17:52:35 +00:00
General_Memory * general = & models - > mem . general ;
File_Edit_Positions edit_poss [ 16 ] ;
2017-03-23 19:15:33 +00:00
int32_t line_number [ 16 ] ;
int32_t column_number [ 16 ] ;
2016-08-26 17:52:35 +00:00
View * vptrs [ 16 ] ;
i32 vptr_count = 0 ;
for ( View_Iter iter = file_view_iter_init ( & models - > layout , file , 0 ) ;
file_view_iter_good ( iter ) ;
iter = file_view_iter_next ( iter ) ) {
vptrs [ vptr_count ] = iter . view ;
2016-09-13 19:56:14 +00:00
edit_poss [ vptr_count ] = iter . view - > edit_pos [ 0 ] ;
line_number [ vptr_count ] = iter . view - > edit_pos [ 0 ] . cursor . line ;
column_number [ vptr_count ] = iter . view - > edit_pos [ 0 ] . cursor . character ;
2016-08-26 17:52:35 +00:00
iter . view - > edit_pos = 0 ;
+ + vptr_count ;
}
file_close ( system , general , file ) ;
init_normal_file ( system , models , file , buffer , size ) ;
2016-09-13 19:56:14 +00:00
for ( i32 i = 0 ; i < vptr_count ; + + i ) {
2017-03-12 01:20:24 +00:00
view_set_file ( system , vptrs [ i ] , file , models ) ;
2016-09-13 19:56:14 +00:00
2017-03-23 19:15:33 +00:00
int32_t line = line_number [ i ] ;
int32_t character = column_number [ i ] ;
2016-09-13 19:56:14 +00:00
2016-08-26 17:52:35 +00:00
* vptrs [ i ] - > edit_pos = edit_poss [ i ] ;
2017-03-12 01:20:24 +00:00
Full_Cursor cursor = view_compute_cursor ( system , vptrs [ i ] , seek_line_char ( line , character ) , 0 ) ;
2016-09-13 19:56:14 +00:00
2017-03-12 01:20:24 +00:00
view_set_cursor ( vptrs [ i ] , cursor , true , file - > settings . unwrapped_lines ) ;
2016-08-26 17:52:35 +00:00
}
2016-08-24 23:01:33 +00:00
}
2016-11-05 02:59:35 +00:00
else {
system - > load_close ( handle ) ;
}
}
else {
system - > load_close ( handle ) ;
2016-07-06 22:04:31 +00:00
}
2016-08-26 17:52:35 +00:00
end_temp_memory ( temp ) ;
2016-06-29 17:16:08 +00:00
}
}
}
COMMAND_DECL ( save ) {
USE_MODELS ( models ) ;
USE_VIEW ( view ) ;
REQ_FILE ( file , view ) ;
2016-08-26 21:30:08 +00:00
if ( ! file - > is_dummy & & file_is_ready ( file ) & & buffer_can_save ( file ) ) {
2016-12-26 22:49:01 +00:00
save_file ( system , models , file ) ;
2016-06-29 17:16:08 +00:00
}
}
COMMAND_DECL ( save_as ) {
USE_VIEW ( view ) ;
REQ_FILE ( file , view ) ;
2016-12-26 22:49:01 +00:00
view_show_interactive ( system , view , IAct_Save_As , IInt_Sys_File_List , make_lit_string ( " Save As: " ) ) ;
2016-06-29 17:16:08 +00:00
}
COMMAND_DECL ( change_active_panel ) {
USE_MODELS ( models ) ;
USE_PANEL ( panel ) ;
panel = panel - > next ;
if ( panel = = & models - > layout . used_sentinel ) {
panel = panel - > next ;
}
models - > layout . active_panel = ( i32 ) ( panel - models - > layout . panels ) ;
}
COMMAND_DECL ( interactive_switch_buffer ) {
USE_VIEW ( view ) ;
2017-04-18 15:41:49 +00:00
view_show_interactive ( system , view , IAct_Switch , IInt_Live_File_List , make_lit_string ( " Switch Buffer: " ) ) ;
2016-06-29 17:16:08 +00:00
}
COMMAND_DECL ( interactive_kill_buffer ) {
USE_VIEW ( view ) ;
2017-04-18 15:41:49 +00:00
view_show_interactive ( system , view , IAct_Kill , IInt_Live_File_List , make_lit_string ( " Kill Buffer: " ) ) ;
2016-06-29 17:16:08 +00:00
}
COMMAND_DECL ( kill_buffer ) {
USE_MODELS ( models ) ;
USE_VIEW ( view ) ;
REQ_FILE ( file , view ) ;
2016-08-24 23:01:33 +00:00
interactive_try_kill_file ( system , models , view , file ) ;
2016-06-29 17:16:08 +00:00
}
internal void
2017-05-19 23:55:50 +00:00
case_change_range ( System_Functions * system , Models * models , View * view , Editing_File * file , u8 a , u8 z , u8 char_delta ) {
2017-01-23 06:19:43 +00:00
Range range = { 0 } ;
range . min = Min ( view - > edit_pos - > cursor . pos , view - > edit_pos - > mark ) ;
range . max = Max ( view - > edit_pos - > cursor . pos , view - > edit_pos - > mark ) ;
2016-06-29 17:16:08 +00:00
if ( range . start < range . end ) {
Edit_Step step = { } ;
step . type = ED_NORMAL ;
step . edit . start = range . start ;
step . edit . end = range . end ;
step . edit . len = range . end - range . start ;
2016-10-22 15:30:25 +00:00
if ( file - > state . still_lexing ) {
2016-06-29 17:16:08 +00:00
system - > cancel_job ( BACKGROUND_THREADS , file - > state . lex_job ) ;
2016-10-22 15:30:25 +00:00
}
2016-06-29 17:16:08 +00:00
2017-05-19 23:55:50 +00:00
file_update_history_before_edit ( & models - > mem , file , step , 0 , hist_normal ) ;
2016-06-29 17:16:08 +00:00
u8 * data = ( u8 * ) file - > state . buffer . data ;
2017-03-23 19:15:33 +00:00
for ( i32 i = range . start ; i < range . end ; + + i ) {
2016-06-29 17:16:08 +00:00
if ( data [ i ] > = a & & data [ i ] < = z ) {
data [ i ] + = char_delta ;
}
}
2017-01-14 03:01:35 +00:00
if ( file - > state . token_array . tokens ) {
2017-05-19 23:55:50 +00:00
file_relex_parallel ( system , models , file , range . start , range . end , 0 ) ;
2017-01-14 03:01:35 +00:00
}
2016-06-29 17:16:08 +00:00
}
}
COMMAND_DECL ( open_color_tweaker ) {
USE_VIEW ( view ) ;
view_show_theme ( view ) ;
}
COMMAND_DECL ( open_debug ) {
USE_VIEW ( view ) ;
view_show_GUI ( view , VUI_Debug ) ;
2017-03-12 01:20:24 +00:00
view - > debug_vars = null_debug_vars ;
2016-06-29 17:16:08 +00:00
}
COMMAND_DECL ( user_callback ) {
USE_MODELS ( models ) ;
if ( binding . custom ) binding . custom ( & models - > app_links ) ;
}
2017-01-23 06:19:43 +00:00
global Command_Function command_table [ cmdid_count ] ;
2016-06-29 17:16:08 +00:00
# include "4ed_api_implementation.cpp"
struct Command_In {
Command_Data * cmd ;
Command_Binding bind ;
} ;
internal void
command_caller ( Coroutine * coroutine ) {
Command_In * cmd_in = ( Command_In * ) coroutine - > in ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd_in - > cmd ;
Models * models = command - > models ;
USE_VIEW ( view ) ;
2016-06-29 17:16:08 +00:00
2016-06-29 18:23:14 +00:00
if ( models - > command_caller ) {
Generic_Command generic ;
if ( cmd_in - > bind . function = = command_user_callback ) {
generic . command = cmd_in - > bind . custom ;
}
else {
generic . cmdid = ( Command_ID ) cmd_in - > bind . custom_id ;
}
2017-03-29 20:50:29 +00:00
models - > command_caller ( & models - > app_links , generic ) ;
2016-06-29 18:23:14 +00:00
}
else {
2016-09-21 22:34:19 +00:00
cmd_in - > bind . function ( command - > system , command , cmd_in - > bind ) ;
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 ;
}
internal void
setup_ui_commands ( Command_Map * commands , Partition * part , Command_Map * parent ) {
map_init ( commands , part , 32 , parent ) ;
2017-02-18 01:04:41 +00:00
map_clear ( commands ) ;
2016-06-29 17:16:08 +00:00
// TODO(allen): This is hacky, when the new UI stuff happens, let's fix it,
// and by that I mean actually fix it, don't just say you fixed it with
// something stupid again.
u8 mdfr_array [ ] = { MDFR_NONE , MDFR_SHIFT , MDFR_CTRL , MDFR_SHIFT | MDFR_CTRL } ;
for ( i32 i = 0 ; i < 4 ; + + i ) {
2017-02-12 06:01:01 +00:00
u8 mdfr = mdfr_array [ i ] ;
2016-06-29 17:16:08 +00:00
map_add ( commands , key_left , mdfr , command_null ) ;
map_add ( commands , key_right , mdfr , command_null ) ;
map_add ( commands , key_up , mdfr , command_null ) ;
map_add ( commands , key_down , mdfr , command_null ) ;
map_add ( commands , key_back , mdfr , command_null ) ;
}
}
internal void
setup_file_commands ( Command_Map * commands , Partition * part , Command_Map * parent ) {
map_init ( commands , part , 10 , parent ) ;
}
internal void
setup_top_commands ( Command_Map * commands , Partition * part , Command_Map * parent ) {
map_init ( commands , part , 10 , parent ) ;
}
internal void
setup_command_table ( ) {
# define SET(n) command_table[cmdid_##n] = command_##n
SET ( null ) ;
SET ( undo ) ;
SET ( redo ) ;
SET ( interactive_new ) ;
SET ( interactive_open ) ;
2017-03-27 22:36:42 +00:00
SET ( interactive_open_or_new ) ;
2016-06-29 17:16:08 +00:00
SET ( interactive_switch_buffer ) ;
SET ( interactive_kill_buffer ) ;
2016-07-05 13:11:26 +00:00
SET ( save_as ) ;
SET ( reopen ) ;
SET ( save ) ;
2016-06-29 17:16:08 +00:00
SET ( kill_buffer ) ;
SET ( open_color_tweaker ) ;
SET ( open_debug ) ;
# undef SET
}
// App Functions
internal void
app_hardcode_styles ( Models * models ) {
2016-07-01 05:42:19 +00:00
Interactive_Style file_info_style = { 0 } ;
Style * styles = models - > styles . styles ;
Style * style = styles + 1 ;
2016-06-29 17:16:08 +00:00
/////////////////
style_set_name ( style , make_lit_string ( " 4coder " ) ) ;
style - > main . back_color = 0xFF0C0C0C ;
style - > main . margin_color = 0xFF181818 ;
style - > main . margin_hover_color = 0xFF252525 ;
style - > main . margin_active_color = 0xFF323232 ;
2017-04-23 02:11:03 +00:00
style - > main . list_item_color = style - > main . margin_color ;
style - > main . list_item_hover_color = style - > main . margin_hover_color ;
style - > main . list_item_active_color = style - > main . margin_active_color ;
2016-06-29 17:16:08 +00:00
style - > main . cursor_color = 0xFF00EE00 ;
style - > main . highlight_color = 0xFFDDEE00 ;
style - > main . mark_color = 0xFF494949 ;
style - > main . default_color = 0xFF90B080 ;
style - > main . at_cursor_color = style - > main . back_color ;
style - > main . at_highlight_color = 0xFFFF44DD ;
style - > main . comment_color = 0xFF2090F0 ;
style - > main . keyword_color = 0xFFD08F20 ;
style - > main . str_constant_color = 0xFF50FF30 ;
style - > main . char_constant_color = style - > main . str_constant_color ;
style - > main . int_constant_color = style - > main . str_constant_color ;
style - > main . float_constant_color = style - > main . str_constant_color ;
style - > main . bool_constant_color = style - > main . str_constant_color ;
style - > main . include_color = style - > main . str_constant_color ;
style - > main . preproc_color = style - > main . default_color ;
style - > main . special_character_color = 0xFFFF0000 ;
2016-10-14 21:21:17 +00:00
style - > main . ghost_character_color = color_blend ( style - > main . default_color , 0.5f , style - > main . back_color ) ;
2016-06-29 17:16:08 +00:00
style - > main . paste_color = 0xFFDDEE00 ;
style - > main . undo_color = 0xFF00DDEE ;
style - > main . highlight_junk_color = 0xff3a0000 ;
style - > main . highlight_white_color = 0xff003a3a ;
file_info_style . bar_color = 0xFF888888 ;
file_info_style . bar_active_color = 0xFF666666 ;
file_info_style . base_color = 0xFF000000 ;
2016-07-02 22:59:16 +00:00
file_info_style . pop1_color = 0xFF3C57DC ;
2016-06-29 17:16:08 +00:00
file_info_style . pop2_color = 0xFFFF0000 ;
style - > main . file_info_style = file_info_style ;
+ + style ;
2016-09-13 01:58:32 +00:00
/////////////////
2016-06-29 17:16:08 +00:00
models - > styles . count = ( i32 ) ( style - styles ) ;
models - > styles . max = ArrayCount ( models - > styles . styles ) ;
style_copy ( main_style ( models ) , models - > styles . styles + 1 ) ;
}
enum Command_Line_Action {
CLAct_Nothing ,
CLAct_Ignore ,
CLAct_UserFile ,
CLAct_CustomDLL ,
CLAct_InitialFilePosition ,
CLAct_WindowSize ,
CLAct_WindowMaximize ,
CLAct_WindowPosition ,
2016-09-01 03:06:46 +00:00
CLAct_WindowFullscreen ,
2016-09-02 15:58:04 +00:00
CLAct_WindowStreamMode ,
2016-06-29 17:16:08 +00:00
CLAct_FontSize ,
2017-03-29 16:32:06 +00:00
CLAct_FontUseHinting ,
2017-06-12 17:40:54 +00:00
CLAct_Log ,
2016-06-29 17:16:08 +00:00
CLAct_Count
} ;
2016-09-19 02:49:25 +00:00
enum Command_Line_Mode {
CLMode_App ,
CLMode_Custom
} ;
2016-06-29 17:16:08 +00:00
void
2017-01-30 18:41:08 +00:00
init_command_line_settings ( App_Settings * settings , Plat_Settings * plat_settings , Command_Line_Parameters clparams ) {
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-06-12 17:40:54 +00:00
for ( i32 i = 1 ; i < = clparams . argc ; + + i ) {
2016-09-19 02:49:25 +00:00
if ( i = = clparams . argc ) {
arg = " " ;
}
else {
arg = clparams . argv [ i ] ;
}
if ( arg [ 0 ] = = ' - ' & & arg [ 1 ] = = ' - ' ) {
char * long_arg_name = arg + 2 ;
if ( match_cc ( long_arg_name , " custom " ) ) {
mode = CLMode_Custom ;
settings - > custom_arg_start = i + 1 ;
settings - > custom_arg_end = i + 1 ;
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 ' S ' : action = CLAct_WindowStreamMode ; break ;
case ' f ' : action = CLAct_FontSize ; break ;
2017-06-12 17:40:54 +00:00
case ' h ' : action = CLAct_FontUseHinting ; - - i ; break ;
case ' L ' : action = CLAct_Log ; - - 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 ;
2016-09-19 02:49:25 +00:00
if ( i < clparams . argc ) {
plat_settings - > custom_dll = clparams . argv [ i ] ;
}
action = CLAct_Nothing ;
} break ;
case CLAct_InitialFilePosition :
{
if ( i < clparams . argc ) {
settings - > initial_line = str_to_int_c ( clparams . argv [ i ] ) ;
}
action = CLAct_Nothing ;
} break ;
case CLAct_WindowSize :
{
if ( i + 1 < clparams . argc ) {
2017-03-29 16:32:06 +00:00
plat_settings - > set_window_size = true ;
2016-09-19 02:49:25 +00:00
plat_settings - > window_w = str_to_int_c ( clparams . argv [ i ] ) ;
plat_settings - > window_h = str_to_int_c ( clparams . argv [ i + 1 ] ) ;
+ + 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 :
{
if ( i + 1 < clparams . argc ) {
2017-03-29 16:32:06 +00:00
plat_settings - > set_window_pos = true ;
2016-09-19 02:49:25 +00:00
plat_settings - > window_x = str_to_int_c ( clparams . argv [ i ] ) ;
plat_settings - > window_y = str_to_int_c ( clparams . argv [ i + 1 ] ) ;
+ + i ;
}
action = CLAct_Nothing ;
} break ;
case CLAct_WindowFullscreen :
{
- - i ;
2017-03-29 16:32:06 +00:00
plat_settings - > fullscreen_window = true ;
plat_settings - > stream_mode = true ;
2016-09-19 02:49:25 +00:00
action = CLAct_Nothing ;
} break ;
case CLAct_WindowStreamMode :
{
- - i ;
2017-03-29 16:32:06 +00:00
plat_settings - > stream_mode = true ;
2016-09-19 02:49:25 +00:00
action = CLAct_Nothing ;
} break ;
case CLAct_FontSize :
{
if ( i < clparams . argc ) {
2017-03-29 16:32:06 +00:00
plat_settings - > font_size = str_to_int_c ( clparams . argv [ i ] ) ;
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 ;
2016-09-19 02:49:25 +00:00
action = CLAct_Nothing ;
} break ;
2017-06-12 17:40:54 +00:00
case CLAct_Log :
{
plat_settings - > use_log = true ;
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
{
2016-09-19 02:49:25 +00:00
settings - > custom_arg_end = i + 1 ;
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 ) ;
App_Vars * vars = push_struct ( & _partition , App_Vars ) ;
2017-02-17 22:03:19 +00:00
Assert ( vars ! = 0 ) ;
* vars = null_app_vars ;
2016-06-29 17:16:08 +00:00
vars - > models . mem . part = _partition ;
2017-01-14 03:01:35 +00:00
# if defined(USE_DEBUG_MEMORY)
2016-10-22 15:30:25 +00:00
general_memory_open ( system , & vars - > models . mem . general , memory - > target_memory , memory - > target_memory_size ) ;
2017-01-14 03:01:35 +00:00
# else
general_memory_open ( & vars - > models . mem . general , memory - > target_memory , memory - > target_memory_size ) ;
# endif
2016-06-29 17:16:08 +00:00
return ( vars ) ;
}
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 ;
2016-06-29 17:16:08 +00:00
2017-01-30 18:41:08 +00:00
* settings = null_app_settings ;
2017-03-29 16:32:06 +00:00
plat_settings - > font_size = 16 ;
2016-07-03 22:29:07 +00:00
if ( clparams . argc > 1 ) {
init_command_line_settings ( & vars - > models . settings , plat_settings , clparams ) ;
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 ) ;
}
2017-05-19 23:55:50 +00:00
SCROLL_RULE_SIG ( fallback_scroll_rule ) {
b32 result = false ;
2016-06-29 17:16:08 +00:00
if ( target_x ! = * scroll_x ) {
* scroll_x = target_x ;
2017-05-19 23:55:50 +00:00
result = true ;
2016-06-29 17:16:08 +00:00
}
if ( target_y ! = * scroll_y ) {
* scroll_y = target_y ;
2017-05-19 23:55:50 +00:00
result = true ;
2016-06-29 17:16:08 +00:00
}
return ( result ) ;
}
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 ;
models - > app_links . cmd_context = & vars - > command_data ;
2017-03-29 20:50:29 +00:00
Partition * partition = & models - > mem . part ;
2016-06-29 17:16:08 +00:00
2017-03-29 20:50:29 +00:00
PRFL_INIT ( memory - > debug_memory , memory - > debug_memory_size ) ;
i32 panel_max_count = models - > layout . panel_max_count = MAX_VIEWS ;
i32 divider_max_count = panel_max_count - 1 ;
models - > layout . panel_count = 0 ;
Panel * panels = push_array ( partition , Panel , panel_max_count ) ;
models - > layout . panels = panels ;
dll_init_sentinel ( & models - > layout . free_sentinel ) ;
dll_init_sentinel ( & models - > layout . used_sentinel ) ;
Panel * panel = panels ;
for ( i32 i = 0 ; i < panel_max_count ; + + i , + + panel ) {
dll_insert ( & models - > layout . free_sentinel , panel ) ;
}
Panel_Divider * dividers = push_array ( partition , Panel_Divider , divider_max_count ) ;
models - > layout . dividers = dividers ;
Panel_Divider * div = dividers ;
for ( i32 i = 0 ; i < divider_max_count - 1 ; + + i , + + div ) {
div - > next = ( div + 1 ) ;
2016-06-29 17:16:08 +00:00
}
2017-03-29 20:50:29 +00:00
div - > next = 0 ;
models - > layout . free_divider = dividers ;
2016-06-29 17:16:08 +00:00
{
models - > live_set = & vars - > live_set ;
vars - > live_set . count = 0 ;
vars - > live_set . max = panel_max_count ;
vars - > live_set . views = push_array ( partition , View , vars - > live_set . max ) ;
dll_init_sentinel ( & vars - > live_set . free_sentinel ) ;
2017-03-29 20:50:29 +00:00
i32 max = vars - > live_set . max ;
View * view = vars - > live_set . views ;
for ( i32 i = 0 ; i < max ; + + i , + + view ) {
2016-06-29 17:16:08 +00:00
dll_insert ( & vars - > live_set . free_sentinel , view ) ;
2017-03-29 20:50:29 +00:00
View_Persistent * persistent = & view - > persistent ;
2016-06-29 17:16:08 +00:00
persistent - > id = i ;
persistent - > models = models ;
}
}
2017-05-19 23:55:50 +00:00
{
umem memsize = KB ( 8 ) ;
void * mem = push_block ( partition , ( i32 ) memsize ) ;
parse_context_init_memory ( & models - > parse_context_memory , mem , memsize ) ;
parse_context_add_default ( & models - > parse_context_memory , & models - > mem . general ) ;
}
2016-06-29 17:16:08 +00:00
{
models - > scroll_rule = fallback_scroll_rule ;
models - > hook_open_file = 0 ;
models - > hook_new_file = 0 ;
2016-12-26 22:49:01 +00:00
models - > hook_save_file = 0 ;
2017-04-18 15:41:49 +00:00
models - > hook_end_file = 0 ;
2017-02-26 20:13:06 +00:00
models - > command_caller = 0 ;
models - > input_filter = 0 ;
2016-06-29 17:16:08 +00:00
setup_command_table ( ) ;
2017-01-23 06:19:43 +00:00
Command_Map * global_map = & models - > map_top ;
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 ) ;
2016-06-29 17:16:08 +00:00
2017-01-23 06:19:43 +00:00
b32 did_top = false ;
b32 did_file = false ;
2016-06-29 17:16:08 +00:00
if ( wanted_size < = models - > app_links . memory_size ) {
Command_Map * map_ptr = 0 ;
2017-02-17 22:03:19 +00:00
Binding_Unit * unit = ( Binding_Unit * ) models - > app_links . memory ;
2016-06-29 17:16:08 +00:00
if ( unit - > type = = unit_header & & unit - > header . error = = 0 ) {
2017-02-17 22:03:19 +00:00
Binding_Unit * end = unit + unit - > header . total_size ;
2016-06-29 17:16:08 +00:00
2017-02-17 22:03:19 +00:00
i32 user_map_count = unit - > header . user_map_count ;
2016-06-29 17:16:08 +00:00
2017-02-17 22:03:19 +00:00
models - > map_id_table = push_array ( & models - > mem . part , i32 , user_map_count ) ;
2016-06-29 17:16:08 +00:00
memset ( models - > map_id_table , - 1 , user_map_count * sizeof ( i32 ) ) ;
2017-02-17 22:03:19 +00:00
models - > user_maps = push_array ( & models - > mem . part , Command_Map , user_map_count ) ;
2016-06-29 17:16:08 +00:00
models - > user_map_count = user_map_count ;
for ( + + unit ; unit < end ; + + unit ) {
switch ( unit - > type ) {
case unit_map_begin :
{
2016-08-29 01:03:26 +00:00
i32 mapid = unit - > map_begin . mapid ;
i32 count = map_get_count ( models , mapid ) ;
2016-06-29 17:16:08 +00:00
if ( unit - > map_begin . replace ) {
map_set_count ( models , mapid , unit - > map_begin . bind_count ) ;
}
else {
map_set_count ( models , mapid , unit - > map_begin . bind_count + count ) ;
}
} ;
}
}
unit = ( Binding_Unit * ) models - > app_links . memory ;
for ( + + unit ; unit < end ; + + unit ) {
switch ( unit - > type ) {
case unit_map_begin :
{
2016-08-29 01:03:26 +00:00
i32 mapid = unit - > map_begin . mapid ;
i32 count = map_get_max_count ( models , mapid ) ;
i32 table_max = count * 3 / 2 ;
2017-02-18 01:04:41 +00:00
b32 auto_clear = false ;
2016-06-29 17:16:08 +00:00
if ( mapid = = mapid_global ) {
map_ptr = & models - > map_top ;
2017-02-18 01:04:41 +00:00
auto_clear = map_init ( map_ptr , & models - > mem . part , table_max , global_map ) ;
2017-01-23 06:19:43 +00:00
did_top = true ;
2016-06-29 17:16:08 +00:00
}
else if ( mapid = = mapid_file ) {
map_ptr = & models - > map_file ;
2017-02-18 01:04:41 +00:00
auto_clear = map_init ( map_ptr , & models - > mem . part , table_max , global_map ) ;
2017-01-23 06:19:43 +00:00
did_file = true ;
2016-06-29 17:16:08 +00:00
}
else if ( mapid < mapid_global ) {
i32 index = get_or_add_map_index ( models , mapid ) ;
Assert ( index < user_map_count ) ;
map_ptr = models - > user_maps + index ;
2017-02-18 01:04:41 +00:00
auto_clear = map_init ( map_ptr , & models - > mem . part , table_max , global_map ) ;
2017-01-23 06:19:43 +00:00
}
else {
map_ptr = 0 ;
2016-06-29 17:16:08 +00:00
}
2017-02-18 01:04:41 +00:00
if ( map_ptr & & ( unit - > map_begin . replace | | auto_clear ) ) {
2016-06-29 17:16:08 +00:00
map_clear ( map_ptr ) ;
}
} break ;
case unit_inherit :
if ( map_ptr ) {
Command_Map * parent = 0 ;
2016-08-29 01:03:26 +00:00
i32 mapid = unit - > map_inherit . mapid ;
2016-06-29 17:16:08 +00:00
if ( mapid = = mapid_global ) parent = & models - > map_top ;
else if ( mapid = = mapid_file ) parent = & models - > map_file ;
else if ( mapid < mapid_global ) {
i32 index = get_or_add_map_index ( models , mapid ) ;
if ( index < user_map_count ) parent = models - > user_maps + index ;
else parent = 0 ;
}
map_ptr - > parent = parent ;
} break ;
case unit_binding :
if ( map_ptr ) {
Command_Function func = 0 ;
if ( unit - > binding . command_id > = 0 & & unit - > binding . command_id < cmdid_count )
func = command_table [ unit - > binding . command_id ] ;
if ( func ) {
2017-02-18 01:04:41 +00:00
if ( unit - > binding . code = = 0 ) {
u32 index = 0 ;
if ( map_get_modifiers_hash ( unit - > binding . modifiers , & index ) ) {
map_ptr - > vanilla_keyboard_default [ index ] . function = func ;
map_ptr - > vanilla_keyboard_default [ index ] . custom_id = unit - > binding . command_id ;
}
2016-06-29 17:16:08 +00:00
}
else {
map_add ( map_ptr , unit - > binding . code , unit - > binding . modifiers , func , unit - > binding . command_id ) ;
}
}
2017-02-12 23:04:50 +00:00
} break ;
2016-06-29 17:16:08 +00:00
case unit_callback :
if ( map_ptr ) {
Command_Function func = command_user_callback ;
Custom_Command_Function * custom = unit - > callback . func ;
if ( func ) {
2017-02-18 01:04:41 +00:00
if ( unit - > callback . code = = 0 ) {
u32 index = 0 ;
if ( map_get_modifiers_hash ( unit - > binding . modifiers , & index ) ) {
map_ptr - > vanilla_keyboard_default [ index ] . function = func ;
map_ptr - > vanilla_keyboard_default [ index ] . custom = custom ;
}
2016-06-29 17:16:08 +00:00
}
else {
map_add ( map_ptr , unit - > callback . code , unit - > callback . modifiers , func , custom ) ;
}
}
2017-02-12 23:04:50 +00:00
} break ;
2016-06-29 17:16:08 +00:00
case unit_hook :
{
2016-08-29 01:03:26 +00:00
i32 hook_id = unit - > hook . hook_id ;
2016-06-29 17:16:08 +00:00
if ( hook_id > = 0 ) {
if ( hook_id < hook_type_count ) {
models - > hooks [ hook_id ] = ( Hook_Function * ) unit - > hook . func ;
}
else {
switch ( hook_id ) {
2017-01-23 06:19:43 +00:00
case special_hook_open_file :
2017-02-26 20:13:06 +00:00
{
models - > hook_open_file = ( Open_File_Hook_Function * ) unit - > hook . func ;
} break ;
2016-06-29 17:16:08 +00:00
2017-01-23 06:19:43 +00:00
case special_hook_new_file :
2017-02-26 20:13:06 +00:00
{
models - > hook_new_file = ( Open_File_Hook_Function * ) unit - > hook . func ;
} break ;
2016-06-29 17:16:08 +00:00
2017-01-23 06:19:43 +00:00
case special_hook_save_file :
2017-02-26 20:13:06 +00:00
{
models - > hook_save_file = ( Open_File_Hook_Function * ) unit - > hook . func ;
} break ;
2016-12-26 22:49:01 +00:00
2017-04-18 15:41:49 +00:00
case special_hook_end_file :
{
models - > hook_end_file = ( Open_File_Hook_Function * ) unit - > hook . func ;
} break ;
2017-01-23 06:19:43 +00:00
case special_hook_command_caller :
2017-02-26 20:13:06 +00:00
{
models - > command_caller = ( Command_Caller_Hook_Function * ) unit - > hook . func ;
} break ;
2016-06-29 18:23:14 +00:00
2017-01-23 06:19:43 +00:00
case special_hook_scroll_rule :
2017-02-26 20:13:06 +00:00
{
models - > scroll_rule = ( Scroll_Rule_Function * ) unit - > hook . func ;
} break ;
2016-06-29 19:11:37 +00:00
2017-01-23 06:19:43 +00:00
case special_hook_input_filter :
2017-02-26 20:13:06 +00:00
{
models - > input_filter = ( Input_Filter_Function * ) unit - > hook . func ;
} break ;
2016-06-29 17:16:08 +00:00
}
}
}
} break ;
}
}
}
}
memset ( models - > app_links . memory , 0 , wanted_size ) ;
2017-01-23 06:19:43 +00:00
if ( ! did_top ) setup_top_commands ( & models - > map_top , & models - > mem . part , global_map ) ;
if ( ! did_file ) setup_file_commands ( & models - > map_file , & models - > mem . part , global_map ) ;
2016-06-29 17:16:08 +00:00
2017-01-23 06:19:43 +00:00
setup_ui_commands ( & models - > map_ui , & models - > mem . part , global_map ) ;
2016-06-29 17:16:08 +00:00
}
// NOTE(allen): file setup
2017-01-14 03:01:35 +00:00
working_set_init ( & models - > working_set , partition , & vars - > models . mem . general ) ;
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
// 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 ;
// TODO(allen): more robust allocation solution for the clipboard
if ( clipboard . str ) {
2017-01-14 03:01:35 +00:00
String * dest = working_set_next_clipboard_string ( & models - > mem . general , & models - > working_set , clipboard . size ) ;
2016-08-28 04:31:06 +00:00
copy_ss ( 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 ;
2016-06-29 17:16:08 +00:00
app_hardcode_styles ( models ) ;
// NOTE(allen): init first panel
2016-09-21 22:34:19 +00:00
Command_Data * cmd = & vars - > command_data ;
cmd - > models = models ;
cmd - > vars = vars ;
cmd - > system = system ;
cmd - > live_set = & vars - > live_set ;
cmd - > screen_width = target - > width ;
cmd - > screen_height = target - > height ;
cmd - > key = null_key_event_data ;
General_Memory * general = & models - > mem . general ;
2016-09-22 21:25:52 +00:00
struct File_Init {
String name ;
Editing_File * * ptr ;
2017-03-29 16:32:06 +00:00
b32 read_only ;
2016-09-21 22:34:19 +00:00
} ;
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 , } ,
{ make_lit_string ( " *scratch* " ) , & models - > scratch_buffer , false , }
2016-09-21 22:34:19 +00:00
} ;
for ( i32 i = 0 ; i < ArrayCount ( init_files ) ; + + i ) {
2017-01-14 03:01:35 +00:00
Editing_File * file = working_set_alloc_always ( & models - > working_set , general ) ;
buffer_bind_name ( general , & models - > working_set , file , init_files [ i ] . name ) ;
2016-09-22 21:25:52 +00:00
2017-03-29 16:32:06 +00:00
if ( init_files [ i ] . read_only ) {
init_read_only_file ( system , models , file ) ;
}
else {
init_normal_file ( system , models , file , 0 , 0 ) ;
2016-09-22 21:25:52 +00:00
}
2017-02-12 06:01:01 +00:00
file - > settings . never_kill = true ;
file - > settings . unimportant = true ;
file - > settings . unwrapped_lines = true ;
2016-09-21 22:34:19 +00:00
2016-09-22 21:25:52 +00:00
if ( init_files [ i ] . ptr ) {
* init_files [ i ] . ptr = file ;
}
2016-09-21 22:34:19 +00:00
}
2016-06-29 17:16:08 +00:00
Panel_And_ID p = layout_alloc_panel ( & models - > layout ) ;
panel_make_empty ( system , vars , p . panel ) ;
models - > layout . active_panel = p . id ;
2017-02-12 06:01:01 +00:00
hot_directory_init ( & models - > hot_directory , current_directory ) ;
2016-06-29 17:16:08 +00:00
// NOTE(allen): child proc list setup
i32 max_children = 16 ;
partition_align ( partition , 8 ) ;
vars - > cli_processes . procs = push_array ( partition , CLI_Process , max_children ) ;
vars - > cli_processes . max = max_children ;
vars - > cli_processes . count = 0 ;
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
}
2016-08-28 19:25:24 +00:00
internal i32
2017-03-29 20:50:29 +00:00
update_cli_handle_without_file ( System_Functions * system , Models * models , CLI_Handles * cli , char * dest , i32 max ) {
2016-08-28 19:25:24 +00:00
i32 result = 0 ;
u32 amount = 0 ;
system - > cli_begin_update ( cli ) ;
if ( system - > cli_update_step ( cli , dest , max , & amount ) ) {
result = 1 ;
}
if ( system - > cli_end_update ( cli ) ) {
result = - 1 ;
}
return ( result ) ;
}
2016-06-29 17:16:08 +00:00
internal i32
2017-03-12 01:20:24 +00:00
update_cli_handle_with_file ( System_Functions * system , Models * models , CLI_Handles * cli , Editing_File * file , char * dest , i32 max , b32 cursor_at_end ) {
2016-06-29 17:16:08 +00:00
i32 result = 0 ;
u32 amount = 0 ;
system - > cli_begin_update ( cli ) ;
if ( system - > cli_update_step ( cli , dest , max , & amount ) ) {
2017-03-23 19:15:33 +00:00
amount = eol_in_place_convert_in ( dest , amount ) ;
2016-06-29 17:16:08 +00:00
output_file_append ( system , models , file , make_string ( dest , amount ) , cursor_at_end ) ;
result = 1 ;
}
if ( system - > cli_end_update ( cli ) ) {
char str_space [ 256 ] ;
String str = make_fixed_width_string ( str_space ) ;
2016-08-28 04:31:06 +00:00
append_ss ( & str , make_lit_string ( " exited with code " ) ) ;
2016-06-29 17:16:08 +00:00
append_int_to_str ( & str , cli - > exit ) ;
output_file_append ( system , models , file , str , cursor_at_end ) ;
result = - 1 ;
}
if ( cursor_at_end ) {
2016-07-18 22:05:28 +00:00
i32 new_cursor = buffer_size ( & file - > state . buffer ) ;
for ( View_Iter iter = file_view_iter_init ( & models - > layout , file , 0 ) ;
file_view_iter_good ( iter ) ;
iter = file_view_iter_next ( iter ) ) {
2017-03-12 01:20:24 +00:00
view_cursor_move ( system , iter . view , new_cursor ) ;
2016-07-18 22:05:28 +00:00
}
2016-06-29 17:16:08 +00:00
}
return ( result ) ;
}
2016-07-20 16:16:02 +00:00
2016-06-29 17:16:08 +00:00
App_Step_Sig ( app_step ) {
2017-03-29 20:50:29 +00:00
PRFL_BEGIN_FRAME ( ) ;
2017-03-17 17:45:41 +00:00
Application_Step_Result app_result = * app_result_ ;
2016-06-29 17:16:08 +00:00
app_result . animating = 0 ;
App_Vars * vars = ( App_Vars * ) memory - > vars_memory ;
Models * models = & vars - > models ;
// NOTE(allen): OS clipboard event handling
String clipboard = input - > clipboard ;
if ( clipboard . str ) {
2017-01-14 03:01:35 +00:00
String * dest = working_set_next_clipboard_string ( & models - > mem . general , & models - > working_set , clipboard . size ) ;
2017-03-23 19:15:33 +00:00
dest - > size = eol_convert_in ( dest - > str , clipboard . str , clipboard . size ) ;
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 ) ;
Editing_File_Canon_Name canon ;
2017-03-23 19:14:39 +00:00
if ( get_canon_name ( system , & canon , make_string ( buffer , size ) ) ) {
2016-08-26 21:30:08 +00:00
Editing_File * file = working_set_canon_contains ( working_set , canon . name ) ;
if ( file ) {
if ( file - > state . ignore_behind_os = = 0 ) {
file_mark_behind_os ( file ) ;
}
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
{
i32 prev_width = models - > layout . full_width ;
i32 prev_height = models - > layout . full_height ;
i32 current_width = target - > width ;
i32 current_height = target - > height ;
models - > layout . full_width = current_width ;
models - > layout . full_height = current_height ;
if ( prev_width ! = current_width | | prev_height ! = current_height ) {
layout_refit ( & models - > layout , prev_width , prev_height ) ;
}
}
// NOTE(allen): prepare input information
{
2016-06-29 19:11:37 +00:00
if ( models - > input_filter ) {
models - > input_filter ( & input - > mouse ) ;
}
2016-06-29 17:16:08 +00:00
Key_Event_Data mouse_event = { 0 } ;
if ( input - > mouse . press_l ) {
mouse_event . keycode = key_mouse_left ;
2017-01-29 00:03:23 +00:00
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 ;
2016-06-29 17:16:08 +00:00
}
if ( input - > mouse . press_r ) {
mouse_event . keycode = key_mouse_right ;
2017-01-29 00:03:23 +00:00
input - > keys . keys [ input - > keys . count + + ] = mouse_event ;
2016-09-09 17:14:38 +00:00
}
2017-01-29 00:03:23 +00:00
else if ( input - > mouse . release_r ) {
2016-09-09 17:14:38 +00:00
mouse_event . keycode = key_mouse_right_release ;
2017-01-29 00:03:23 +00:00
input - > keys . keys [ input - > keys . count + + ] = mouse_event ;
2016-09-09 17:14:38 +00:00
}
2016-06-29 17:16:08 +00:00
input - > mouse . wheel = - input - > mouse . wheel ;
}
// NOTE(allen): detect mouse hover status
i32 mx = input - > mouse . x ;
i32 my = input - > mouse . y ;
2017-03-17 17:45:41 +00:00
b32 mouse_in_edit_area = false ;
b32 mouse_in_margin_area = false ;
2016-06-29 17:16:08 +00:00
2017-03-17 17:45:41 +00:00
Panel * mouse_panel = 0 ;
{
Panel * used_panels = & models - > layout . used_sentinel , * panel = 0 ;
for ( dll_items ( panel , used_panels ) ) {
if ( hit_check ( mx , my , panel - > inner ) ) {
mouse_panel = panel ;
mouse_in_edit_area = true ;
break ;
}
else if ( hit_check ( mx , my , panel - > full ) ) {
mouse_panel = panel ;
mouse_in_margin_area = true ;
break ;
}
}
2016-06-29 17:16:08 +00:00
}
2017-04-15 21:47:23 +00:00
b32 mouse_on_divider = false ;
b32 mouse_divider_vertical = false ;
2016-06-29 17:16:08 +00:00
i32 mouse_divider_id = 0 ;
i32 mouse_divider_side = 0 ;
if ( mouse_in_margin_area ) {
Panel * panel = mouse_panel ;
if ( mx > = panel - > inner . x0 & & mx < panel - > inner . x1 ) {
2017-04-15 21:47:23 +00:00
mouse_divider_vertical = false ;
2016-06-29 17:16:08 +00:00
if ( my > panel - > inner . y0 ) {
mouse_divider_side = - 1 ;
}
else {
mouse_divider_side = 1 ;
}
}
else {
2017-04-15 21:47:23 +00:00
mouse_divider_vertical = true ;
2016-06-29 17:16:08 +00:00
if ( mx > panel - > inner . x0 ) {
mouse_divider_side = - 1 ;
}
else {
mouse_divider_side = 1 ;
}
}
if ( models - > layout . panel_count > 1 ) {
mouse_divider_id = panel - > parent ;
2017-04-15 21:47:23 +00:00
i32 which_child = panel - > which_child ;
2016-06-29 17:16:08 +00:00
for ( ; ; ) {
Divider_And_ID div = layout_get_divider ( & models - > layout , mouse_divider_id ) ;
if ( which_child = = mouse_divider_side & &
div . divider - > v_divider = = mouse_divider_vertical ) {
2017-04-15 21:47:23 +00:00
mouse_on_divider = true ;
2016-06-29 17:16:08 +00:00
break ;
}
if ( mouse_divider_id = = models - > layout . root ) {
break ;
}
else {
mouse_divider_id = div . divider - > parent ;
which_child = div . divider - > which_child ;
}
}
}
else {
mouse_on_divider = 0 ;
mouse_divider_id = 0 ;
}
}
// NOTE(allen): update child processes
if ( input - > dt > 0 ) {
Temp_Memory temp = begin_temp_memory ( & models - > mem . part ) ;
2017-01-23 06:19:43 +00:00
u32 max = KB ( 128 ) ;
2016-06-29 17:16:08 +00:00
char * dest = push_array ( & models - > mem . part , char , max ) ;
i32 count = vars - > cli_processes . count ;
for ( i32 i = 0 ; i < count ; + + i ) {
CLI_Process * proc = vars - > cli_processes . procs + i ;
Editing_File * file = proc - > out_file ;
if ( file ! = 0 ) {
i32 r = update_cli_handle_with_file (
system , models , & proc - > cli , file , dest , max , proc - > cursor_at_end ) ;
if ( r < 0 ) {
* proc = vars - > cli_processes . procs [ - - count ] ;
- - i ;
}
}
2016-08-28 19:25:24 +00:00
else {
update_cli_handle_without_file (
system , models , & proc - > cli , dest , max ) ;
}
2016-06-29 17:16:08 +00:00
}
vars - > cli_processes . count = count ;
end_temp_memory ( temp ) ;
}
// NOTE(allen): prepare to start executing commands
Command_Data * cmd = & vars - > command_data ;
cmd - > models = models ;
cmd - > vars = vars ;
cmd - > system = system ;
cmd - > live_set = & vars - > live_set ;
cmd - > screen_width = target - > width ;
cmd - > screen_height = target - > height ;
2016-09-01 19:40:25 +00:00
cmd - > key = null_key_event_data ;
2016-06-29 17:16:08 +00:00
if ( input - > first_step ) {
#if 0
{
View * view = 0 ;
View_Persistent * persistent = 0 ;
i32 i = 0 ;
i32 max = 0 ;
max = vars - > live_set . max ;
view = vars - > live_set . views ;
for ( i = 1 ; i < = max ; + + i , + + view ) {
persistent = & view - > persistent ;
persistent - > coroutine =
system - > create_coroutine ( view_caller ) ;
persistent - > coroutine =
app_launch_coroutine ( system , & models - > app_links , Co_View ,
persistent - > coroutine , view , 0 ) ;
if ( ! persistent - > coroutine ) {
// TODO(allen): Error message and recover
NotImplemented ;
}
}
}
# endif
if ( models - > hooks [ hook_start ] ) {
models - > hooks [ hook_start ] ( & models - > app_links ) ;
}
2016-09-09 22:56:43 +00:00
char space [ 512 ] ;
String cl_filename = make_fixed_width_string ( space ) ;
copy_ss ( & cl_filename , models - > hot_directory . string ) ;
i32 cl_filename_len = cl_filename . size ;
2016-08-24 23:01:33 +00:00
i32 i = 0 ;
2016-06-29 17:16:08 +00:00
Panel * panel = models - > layout . used_sentinel . next ;
2016-09-09 17:29:40 +00:00
for ( ; i < models - > settings . init_files_count ; + + i , panel = panel - > next ) {
2016-09-09 22:56:43 +00:00
cl_filename . size = cl_filename_len ;
2016-09-17 01:11:22 +00:00
String filename = { 0 } ;
Editing_File_Canon_Name canon_name ;
if ( get_canon_name ( system , & canon_name , make_string_slowly ( models - > settings . init_files [ i ] ) ) ) {
filename = canon_name . name ;
}
else {
append_sc ( & cl_filename , models - > settings . init_files [ i ] ) ;
filename = cl_filename ;
}
2016-06-29 17:16:08 +00:00
if ( i < models - > layout . panel_count ) {
2016-09-17 01:11:22 +00:00
view_open_file ( system , models , panel - > view , filename ) ;
2016-06-29 17:16:08 +00:00
view_show_file ( panel - > view ) ;
2016-09-09 17:29:40 +00:00
Assert ( " Earlier " & & panel - > view - > file_data . file ! = 0 ) ;
2016-06-29 17:16:08 +00:00
#if 0
if ( i = = 0 ) {
if ( panel - > view - > file_data . file ) {
// TODO(allen): How to set the cursor of a file on the first frame?
view_compute_cursor_from_line_pos ( panel - > view , models - > settings . initial_line , 1 ) ;
view_move_view_to_cursor ( panel - > view , & panel - > view - > recent . scroll ) ;
}
}
# endif
}
else {
2016-09-17 01:11:22 +00:00
view_open_file ( system , models , 0 , filename ) ;
2016-06-29 17:16:08 +00:00
}
2016-09-09 22:56:43 +00:00
2016-06-29 17:16:08 +00:00
}
if ( i < models - > layout . panel_count ) {
2017-03-12 01:20:24 +00:00
view_set_file ( system , panel - > view , models - > message_buffer , models ) ;
2016-06-29 17:16:08 +00:00
view_show_file ( panel - > view ) ;
2016-06-29 17:45:26 +00:00
+ + i ;
panel = panel - > next ;
}
2016-09-09 17:29:40 +00:00
panel = models - > layout . used_sentinel . next ;
for ( i = 0 ; i < models - > settings . init_files_count ; + + i , panel = panel - > next ) {
Assert ( panel - > view - > file_data . file ! = 0 ) ;
}
2016-06-29 17:16:08 +00:00
}
// NOTE(allen): respond if the user is trying to kill the application
if ( app_result . trying_to_kill ) {
b32 there_is_unsaved = 0 ;
app_result . animating = 1 ;
File_Node * node , * sent ;
sent = & models - > working_set . used_sentinel ;
for ( dll_items ( node , sent ) ) {
Editing_File * file = ( Editing_File * ) node ;
if ( buffer_needs_save ( file ) ) {
there_is_unsaved = 1 ;
break ;
}
}
if ( there_is_unsaved ) {
Coroutine * command_coroutine = models - > command_coroutine ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_VIEW ( view ) ;
2016-06-29 17:16:08 +00:00
for ( i32 i = 0 ; i < 128 & & command_coroutine ; + + i ) {
User_Input user_in = { 0 } ;
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
2017-04-15 21:47:23 +00:00
command_coroutine = app_resume_coroutine ( system , & models - > app_links , Co_Command , command_coroutine , & user_in , models - > command_coroutine_flags ) ;
2016-06-29 17:16:08 +00:00
}
if ( command_coroutine ! = 0 ) {
// TODO(allen): post grave warning
command_coroutine = 0 ;
}
if ( view ! = 0 ) {
init_query_set ( & view - > query_set ) ;
}
if ( view = = 0 ) {
Panel * panel = models - > layout . used_sentinel . next ;
view = panel - > view ;
}
view_show_interactive ( system , view ,
IAct_Sure_To_Close , IInt_Sure_To_Close ,
make_lit_string ( " Are you sure? " ) ) ;
models - > command_coroutine = command_coroutine ;
}
else {
models - > keep_playing = 0 ;
}
}
// NOTE(allen): pass events to debug
2017-01-29 00:03:23 +00:00
vars - > available_input = init_available_input ( & input - > keys , & input - > mouse ) ;
2016-06-29 17:16:08 +00:00
{
Debug_Data * debug = & models - > debug ;
2017-01-29 00:03:23 +00:00
Key_Input_Data key_data = get_key_data ( & vars - > available_input ) ;
2016-06-29 17:16:08 +00:00
Debug_Input_Event * events = debug - > input_events ;
i32 count = key_data . count ;
i32 preserved_inputs = ArrayCount ( debug - > input_events ) - count ;
debug - > this_frame_count = count ;
memmove ( events + count , events ,
sizeof ( Debug_Input_Event ) * preserved_inputs ) ;
for ( i32 i = 0 ; i < key_data . count ; + + i ) {
Key_Event_Data key = get_single_key ( & key_data , i ) ;
events [ i ] . key = key . keycode ;
events [ i ] . consumer [ 0 ] = 0 ;
events [ i ] . is_hold = key . modifiers [ MDFR_HOLD_INDEX ] ;
events [ i ] . is_ctrl = key . modifiers [ MDFR_CONTROL_INDEX ] ;
events [ i ] . is_alt = key . modifiers [ MDFR_ALT_INDEX ] ;
events [ i ] . is_shift = key . modifiers [ MDFR_SHIFT_INDEX ] ;
}
}
// NOTE(allen): Keyboard input to command coroutine.
if ( models - > command_coroutine ! = 0 ) {
Coroutine * command_coroutine = models - > command_coroutine ;
u32 get_flags = models - > command_coroutine_flags [ 0 ] ;
u32 abort_flags = models - > command_coroutine_flags [ 1 ] ;
get_flags | = abort_flags ;
if ( ( get_flags & EventOnAnyKey ) | | ( get_flags & EventOnEsc ) ) {
2017-01-29 00:03:23 +00:00
Key_Input_Data key_data = get_key_data ( & vars - > available_input ) ;
2016-06-29 17:16:08 +00:00
for ( i32 key_i = 0 ; key_i < key_data . count ; + + key_i ) {
Key_Event_Data key = get_single_key ( & key_data , key_i ) ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_VIEW ( view ) ;
2016-06-29 17:16:08 +00:00
b32 pass_in = 0 ;
cmd - > key = key ;
Command_Map * map = 0 ;
if ( view ) map = view - > map ;
if ( map = = 0 ) map = & models - > map_top ;
Command_Binding cmd_bind = map_extract_recursive ( map , key ) ;
2017-04-15 21:47:23 +00:00
User_Input user_in = { 0 } ;
2016-06-29 17:16:08 +00:00
user_in . type = UserInputKey ;
user_in . key = key ;
2016-07-02 14:15:15 +00:00
user_in . command . command = cmd_bind . custom ;
2016-06-29 17:16:08 +00:00
if ( ( EventOnEsc & abort_flags ) & & key . keycode = = key_esc ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
else if ( EventOnAnyKey & abort_flags ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
if ( EventOnAnyKey & get_flags ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_AnyKey , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
if ( key . keycode = = key_esc ) {
if ( EventOnEsc & get_flags ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-06-29 17:16:08 +00:00
}
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_Esc , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
if ( pass_in ) {
2017-04-15 21:47:23 +00:00
models - > command_coroutine = app_resume_coroutine ( system , & models - > app_links , Co_Command , command_coroutine , & user_in , models - > command_coroutine_flags ) ;
2016-06-29 17:16:08 +00:00
2017-04-15 21:47:23 +00:00
app_result . animating = true ;
2016-06-29 17:16:08 +00:00
// TOOD(allen): Deduplicate
// TODO(allen): Should I somehow allow a view to clean up however it wants after a
// command finishes, or after transfering to another view mid command?
if ( view ! = 0 & & models - > command_coroutine = = 0 ) {
init_query_set ( & view - > query_set ) ;
}
if ( models - > command_coroutine = = 0 ) break ;
}
}
}
// NOTE(allen): Mouse input to command coroutine
if ( models - > command_coroutine ! = 0 & & ( get_flags & EventOnMouse ) ) {
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_VIEW ( view ) ;
2016-06-29 17:16:08 +00:00
b32 pass_in = 0 ;
2017-04-15 21:47:23 +00:00
User_Input user_in = { 0 } ;
2016-06-29 17:16:08 +00:00
user_in . type = UserInputMouse ;
user_in . mouse = input - > mouse ;
if ( abort_flags & EventOnMouseMove ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
if ( get_flags & EventOnMouseMove ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseMove , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
if ( input - > mouse . press_l | | input - > mouse . release_l | | input - > mouse . l ) {
if ( abort_flags & EventOnLeftButton ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
if ( get_flags & EventOnLeftButton ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseLeftButton , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
}
if ( input - > mouse . press_r | | input - > mouse . release_r | | input - > mouse . r ) {
if ( abort_flags & EventOnRightButton ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
if ( get_flags & EventOnRightButton ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseRightButton , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
}
if ( input - > mouse . wheel ! = 0 ) {
if ( abort_flags & EventOnWheel ) {
2017-04-15 21:47:23 +00:00
user_in . abort = true ;
2016-06-29 17:16:08 +00:00
}
if ( get_flags & EventOnWheel ) {
2017-04-15 21:47:23 +00:00
pass_in = true ;
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseWheel , " command coroutine " ) ;
2016-06-29 17:16:08 +00:00
}
}
if ( pass_in ) {
2017-04-15 21:47:23 +00:00
models - > command_coroutine = app_resume_coroutine ( system , & models - > app_links , Co_Command , command_coroutine , & user_in , models - > command_coroutine_flags ) ;
2016-06-29 17:16:08 +00:00
2017-04-15 21:47:23 +00:00
app_result . animating = true ;
2016-06-29 17:16:08 +00:00
// TOOD(allen): Deduplicate
// TODO(allen): Should I somehow allow a view to clean up however it wants after a
// command finishes, or after transfering to another view mid command?
if ( view ! = 0 & & models - > command_coroutine = = 0 ) {
init_query_set ( & view - > query_set ) ;
}
}
}
}
// NOTE(allen): pass raw input to the panels
Input_Summary dead_input = { } ;
dead_input . mouse . x = input - > mouse . x ;
dead_input . mouse . y = input - > mouse . y ;
dead_input . dt = input - > dt ;
Input_Summary active_input = { } ;
active_input . mouse . x = input - > mouse . x ;
active_input . mouse . y = input - > mouse . y ;
active_input . dt = input - > dt ;
active_input . keys = get_key_data ( & vars - > available_input ) ;
Mouse_State mouse_state = get_mouse_state ( & vars - > available_input ) ;
{
Panel * panel = 0 , * used_panels = 0 ;
2016-09-21 22:34:19 +00:00
View * view = 0 ;
2016-06-29 17:16:08 +00:00
b32 active = 0 ;
Input_Summary summary = { 0 } ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_VIEW ( active_view ) ;
USE_PANEL ( active_panel ) ;
2016-06-29 17:16:08 +00:00
used_panels = & models - > layout . used_sentinel ;
for ( dll_items ( panel , used_panels ) ) {
view = panel - > view ;
2016-09-21 22:34:19 +00:00
active = ( panel = = active_panel ) ;
2016-06-29 17:16:08 +00:00
summary = ( active ) ? ( active_input ) : ( dead_input ) ;
view - > changed_context_in_step = 0 ;
View_Step_Result result = step_file_view ( system , view , active_view , summary ) ;
2016-07-20 16:16:02 +00:00
2016-06-29 17:16:08 +00:00
if ( result . animating ) {
app_result . animating = 1 ;
}
if ( result . consume_keys ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_AnyKey , " file view step " ) ;
2016-06-29 17:16:08 +00:00
}
if ( result . consume_keys | | result . consume_esc ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_Esc , " file view step " ) ;
2016-06-29 17:16:08 +00:00
}
if ( view - > changed_context_in_step = = 0 ) {
2016-09-21 22:34:19 +00:00
active = ( panel = = active_panel ) ;
2016-06-29 17:16:08 +00:00
summary = ( active ) ? ( active_input ) : ( dead_input ) ;
if ( panel = = mouse_panel & & ! input - > mouse . out_of_window ) {
summary . mouse = mouse_state ;
}
2016-07-02 22:59:16 +00:00
b32 file_scroll = false ;
GUI_Scroll_Vars scroll_zero = { 0 } ;
GUI_Scroll_Vars * scroll_vars = & view - > gui_scroll ;
if ( view - > showing_ui = = VUI_None ) {
if ( view - > file_data . file ) {
scroll_vars = & view - > edit_pos - > scroll ;
file_scroll = true ;
}
else {
scroll_vars = & scroll_zero ;
}
2016-07-02 17:54:56 +00:00
}
2016-07-06 22:04:31 +00:00
i32 max_y = 0 ;
if ( view - > showing_ui = = VUI_None ) {
max_y = view_compute_max_target_y ( view ) ;
}
else {
max_y = view - > gui_max_y ;
}
2016-12-18 20:42:11 +00:00
Input_Process_Result ip_result = do_step_file_view ( system , view , panel - > inner , active , & summary , * scroll_vars , view - > scroll_region , max_y ) ;
2016-07-06 22:04:31 +00:00
2016-06-29 17:16:08 +00:00
if ( ip_result . is_animating ) {
app_result . animating = 1 ;
}
if ( ip_result . consumed_l ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseLeftButton , " file view step " ) ;
2016-06-29 17:16:08 +00:00
}
if ( ip_result . consumed_r ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_MouseRightButton , " file view step " ) ;
2016-06-29 17:16:08 +00:00
}
2016-07-02 17:54:56 +00:00
2016-07-06 22:04:31 +00:00
if ( ip_result . has_max_y_suggestion ) {
view - > gui_max_y = ip_result . max_y ;
}
2016-07-02 17:54:56 +00:00
if ( ! gui_scroll_eq ( scroll_vars , & ip_result . vars ) ) {
2016-07-02 22:59:16 +00:00
if ( file_scroll ) {
2017-03-12 01:20:24 +00:00
view_set_scroll ( system , view , ip_result . vars ) ;
2016-07-02 17:54:56 +00:00
}
else {
* scroll_vars = ip_result . vars ;
}
}
2016-06-29 17:16:08 +00:00
view - > scroll_region = ip_result . region ;
}
}
}
// NOTE(allen): command execution
{
2017-01-29 00:03:23 +00:00
Key_Input_Data key_data = get_key_data ( & vars - > available_input ) ;
2016-06-29 17:16:08 +00:00
b32 hit_something = 0 ;
b32 hit_esc = 0 ;
for ( i32 key_i = 0 ; key_i < key_data . count ; + + key_i ) {
if ( models - > command_coroutine ! = 0 ) break ;
switch ( vars - > state ) {
case APP_STATE_EDIT :
{
Key_Event_Data key = get_single_key ( & key_data , key_i ) ;
cmd - > key = key ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_VIEW ( view ) ;
Assert ( view ) ;
Command_Map * map = view - > map ;
if ( map = = 0 ) {
map = & models - > map_top ;
}
2016-06-29 17:16:08 +00:00
Command_Binding cmd_bind = map_extract_recursive ( map , key ) ;
if ( cmd_bind . function ) {
if ( key . keycode = = key_esc ) {
hit_esc = 1 ;
}
else {
hit_something = 1 ;
}
Assert ( models - > command_coroutine = = 0 ) ;
Coroutine * command_coroutine = system - > create_coroutine ( command_caller ) ;
models - > command_coroutine = command_coroutine ;
Command_In cmd_in ;
cmd_in . cmd = cmd ;
cmd_in . bind = cmd_bind ;
2016-12-18 20:42:11 +00:00
models - > command_coroutine = app_launch_coroutine ( system , & models - > app_links , Co_Command , models - > command_coroutine , & cmd_in , models - > command_coroutine_flags ) ;
2016-06-29 17:16:08 +00:00
models - > prev_command = cmd_bind ;
app_result . animating = 1 ;
}
} break ;
case APP_STATE_RESIZING :
{
if ( key_data . count > 0 ) {
vars - > state = APP_STATE_EDIT ;
}
} break ;
}
}
if ( hit_something ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_AnyKey , " command dispatcher " ) ;
2016-06-29 17:16:08 +00:00
}
if ( hit_esc ) {
2016-12-18 20:42:11 +00:00
consume_input ( & vars - > available_input , Input_Esc , " command dispatcher " ) ;
2016-06-29 17:16:08 +00:00
}
}
// NOTE(allen): pass consumption data to debug
{
Debug_Data * debug = & models - > debug ;
i32 count = debug - > this_frame_count ;
Consumption_Record * record = 0 ;
record = & vars - > available_input . records [ Input_MouseLeftButton ] ;
if ( record - > consumed & & record - > consumer [ 0 ] ! = 0 ) {
Debug_Input_Event * event = debug - > input_events ;
for ( i32 i = 0 ; i < count ; + + i , + + event ) {
2016-09-09 17:14:38 +00:00
if ( event - > key = = key_mouse_left & & event - > consumer [ 0 ] = = 0 ) {
2016-06-29 17:16:08 +00:00
memcpy ( event - > consumer , record - > consumer , sizeof ( record - > consumer ) ) ;
}
}
}
record = & vars - > available_input . records [ Input_MouseRightButton ] ;
if ( record - > consumed & & record - > consumer [ 0 ] ! = 0 ) {
Debug_Input_Event * event = debug - > input_events ;
for ( i32 i = 0 ; i < count ; + + i , + + event ) {
2016-09-09 17:14:38 +00:00
if ( event - > key = = key_mouse_right & & event - > consumer [ 0 ] = = 0 ) {
2016-06-29 17:16:08 +00:00
memcpy ( event - > consumer , record - > consumer , sizeof ( record - > consumer ) ) ;
}
}
}
record = & vars - > available_input . records [ Input_Esc ] ;
if ( record - > consumed & & record - > consumer [ 0 ] ! = 0 ) {
Debug_Input_Event * event = debug - > input_events ;
for ( i32 i = 0 ; i < count ; + + i , + + event ) {
2016-09-09 17:14:38 +00:00
if ( event - > key = = key_esc & & event - > consumer [ 0 ] = = 0 ) {
2016-06-29 17:16:08 +00:00
memcpy ( event - > consumer , record - > consumer , sizeof ( record - > consumer ) ) ;
}
}
}
record = & vars - > available_input . records [ Input_AnyKey ] ;
if ( record - > consumed ) {
Debug_Input_Event * event = debug - > input_events ;
for ( i32 i = 0 ; i < count ; + + i , + + event ) {
if ( event - > consumer [ 0 ] = = 0 ) {
memcpy ( event - > consumer , record - > consumer , sizeof ( record - > consumer ) ) ;
}
}
}
}
// NOTE(allen): initialize message
if ( input - > first_step ) {
String welcome =
2017-04-23 02:40:28 +00:00
make_lit_string ( " ---------------------------------------------------------------- \n "
" Welcome to " VERSION " \n "
2016-12-24 21:09:53 +00:00
" If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html \n "
2016-06-29 17:16:08 +00:00
" \n "
2016-12-24 21:09:53 +00:00
" Newest features: \n "
2017-05-29 16:08:20 +00:00
" -Option for LAlt + LCtrl = AltGr on Windows is now in config.4coder \n "
" -The 4cpp lexer now has a customizable keyword table, *experimental* expansion of language support to: \n "
" Rust, C#, Java \n "
" Arbitrary keyword customization available in custom code (super users) \n "
" \n "
" New in alpha 4.0.18: \n "
2017-04-23 02:40:28 +00:00
" -Lexer now handles string literal prefixes and is more optimized \n "
" -Fixes for lingering unicode bugs \n "
" -Power users have an experimental new jump to error that positions through edits (coming to all tiers soon) \n "
" \n "
" New in alpha 4.0.18: \n "
2017-03-30 20:48:33 +00:00
" -Support for rendering unicode characters \n "
" -<ctrl t> isearch alpha-numeric word under cursor \n "
" -<ctrl Q> query replace alpha-numeric word under cursor \n "
" -<alt b> toggle file bar \n "
" \n "
" New in alpha 4.0.17: \n "
2017-02-20 21:05:42 +00:00
" -New support for extended ascii input. \n "
" -Extended ascii encoded in buffers as utf8. \n "
2017-02-26 20:13:06 +00:00
" -The custom layer now has a 'markers' API for tracking buffer positions across changes. \n "
2017-02-20 21:05:42 +00:00
" \n "
" New in alpha 4.0.16: \n "
2017-02-06 13:49:00 +00:00
" -<alt 2> If the current file is a C++ code file, this opens the matching header. \n " " If the current file is a C++ header, this opens the matching code file. \n "
" -Option to automatically save changes on build in the config file. \n "
" This works for builds triggered by <alt m>. \n "
" -Option in project files to have certain fkey commands save changes. \n "
" \n "
" New in alpha 4.0.15: \n "
2017-01-29 00:03:23 +00:00
" -<ctrl I> find all functions in the current buffer and list them in a jump buffer \n "
" -option to set user name in config.4coder \n "
" The user name is used in <alt t> and <alt y> comment writing commands \n "
" \n "
" New in alpha 4.0.14: \n "
2016-12-24 21:09:53 +00:00
" -Option to have wrap widths automatically adjust based on average view width \n "
" -The 'config.4coder' file can now be placed with the 4ed executable file \n "
" -New options in 'config.4coder' to specify the font and color theme \n "
" -New built in project configuration system \n "
2016-12-26 22:49:01 +00:00
" -New on-save hooks allows custom behavior in the custom layer whenever a file is saved \n "
" -When using code wrapping, any saved file is automatically indented in the text format, this option can be turned off in config.4coder \n "
2016-12-24 21:09:53 +00:00
" \n "
" New in alpha 4.0.12 and 4.0.13: \n "
2016-10-28 14:11:56 +00:00
" -Text files wrap lines at whitespace when possible \n "
" -New code wrapping feature is on by default \n "
2017-01-29 00:03:23 +00:00
" -Introduced a 'config.4coder' for setting several wrapping options: \n "
2016-10-28 14:11:56 +00:00
" enable_code_wrapping: set to false if you want the text like behavior \n "
" default_wrap_width: the wrap width to set in new files \n "
" -<ctrl 2> decrease the current buffer's wrap width \n "
" -<ctrl 3> increase the current buffer's wrap width \n "
" -In the customization layer new settings for the buffer are exposed dealing with wrapping \n "
" -In the customization layer there is a call for setting what keys the GUI should use \n "
" \n "
" New in alpha 4.0.11: \n "
2016-09-01 03:06:46 +00:00
" -The commands for going to next error, previous error, etc now work \n "
" on any buffer with jump locations including *search* \n "
" -4coder now supports proper, borderless, fullscreen with the flag -F \n "
2016-09-01 19:40:25 +00:00
" and fullscreen can be toggled with <control pageup>. \n "
" (This sometimes causes artifacts on the Windows task bar) \n "
2016-09-10 15:22:25 +00:00
" -<alt E> to exit \n "
2016-09-09 17:14:38 +00:00
" -hook on exit for the customization system \n "
" -tokens now exposed in customization system \n "
" -mouse release events in customization system \n "
2016-09-01 03:06:46 +00:00
" \n "
" New in alpha 4.0.10: \n "
2016-09-18 13:09:43 +00:00
" -<ctrl F> list all locations of a string across all open buffers \n "
2016-07-13 23:19:42 +00:00
" -Build now finds build.sh and Makefile on Linux \n "
" -<alt n> goes to the next error if the *compilation* buffer is open \n "
" -<alt N> goes to the previous error \n "
" -<alt M> goes to the first error \n "
" -<alt .> switch to the compilation buffer \n "
" -<alt ,> close the panel viewing the compilation buffer \n "
" -New documentation for the 4coder string library included in 4coder_API.html \n "
" -Low level allocation calls available in custom API \n "
2016-07-15 14:57:02 +00:00
" -Each panel can change font independently. \n "
" Per-buffer fonts are exposed in the custom API. \n "
2016-07-13 23:19:42 +00:00
" \n "
" New in alpha 4.0.9: \n "
2016-06-29 19:11:37 +00:00
" -A scratch buffer is now opened with 4coder automatically \n "
2016-07-02 17:54:56 +00:00
" -A new mouse suppression mode toggled by <F2> \n "
2016-07-03 23:07:31 +00:00
" -Hinting is disabled by default, a -h flag on the command line enables it \n "
2016-07-05 15:15:38 +00:00
" -New 4coder_API.html documentation file provided for the custom layer API \n "
2016-07-02 17:54:56 +00:00
" -Experimental new work-flow for building and jumping to errors \n "
2016-07-05 15:15:38 +00:00
" This system is only for MSVC in the 'power' version as of 4.0.9 \n "
2016-06-29 19:11:37 +00:00
" \n "
" New in alpha 4.0.8: \n "
2016-06-29 17:16:08 +00:00
" -Eliminated the parameter stack \n "
" \n "
" New in alpha 4.0.7: \n "
" -Right click sets the mark \n "
" -Clicks now have key codes so they can have events bound in customizations \n "
" -<alt d> opens a debug view, see more in README.txt \n "
" \n "
" New in alpha 4.0.6: \n "
" -Tied the view scrolling and the list arrow navigation together \n "
2016-07-02 17:54:56 +00:00
" -Scroll bars are now toggleable with <alt s> for show and <alt w> for hide \n "
2016-06-29 17:16:08 +00:00
" \n "
" New in alpha 4.0.5: \n "
" -New indent rule \n "
" -app->buffer_compute_cursor in the customization API \n "
2016-07-02 17:54:56 +00:00
" -f keys are available in the customization system now \n "
2016-06-29 17:16:08 +00:00
" \n "
" New in alpha 4.0.3 and 4.0.4: \n "
" -Scroll bar on files and file lists \n "
" -Arrow navigation in lists \n "
" -A new minimal theme editor \n "
" \n "
" New in alpha 4.0.2: \n "
" -The file count limit is over 8 million now \n "
" -File equality is handled better so renamings (such as 'subst') are safe now \n "
" -This buffer will report events including errors that happen in 4coder \n "
" -Super users can post their own messages here with app->print_message \n "
" -<ctrl e> centers view on cursor; cmdid_center_view in customization API \n "
" -Set font size on command line with -f N, N = 16 by default \n \n "
) ;
2016-07-14 21:44:34 +00:00
do_feedback_message ( system , models , welcome , true ) ;
2016-06-29 17:16:08 +00:00
}
// NOTE(allen): panel resizing
switch ( vars - > state ) {
case APP_STATE_EDIT :
{
if ( input - > mouse . press_l & & mouse_on_divider ) {
vars - > state = APP_STATE_RESIZING ;
Divider_And_ID div = layout_get_divider ( & models - > layout , mouse_divider_id ) ;
vars - > resizing . divider = div . divider ;
f32 min = 0 ;
f32 max = 0 ;
{
f32 mid = layout_get_position ( & models - > layout , mouse_divider_id ) ;
if ( mouse_divider_vertical ) {
max = ( f32 ) models - > layout . full_width ;
}
else {
max = ( f32 ) models - > layout . full_height ;
}
i32 divider_id = div . id ;
do {
Divider_And_ID other_div = layout_get_divider ( & models - > layout , divider_id ) ;
b32 divider_match = ( other_div . divider - > v_divider = = mouse_divider_vertical ) ;
f32 pos = layout_get_position ( & models - > layout , divider_id ) ;
if ( divider_match & & pos > mid & & pos < max ) {
max = pos ;
}
else if ( divider_match & & pos < mid & & pos > min ) {
min = pos ;
}
divider_id = other_div . divider - > parent ;
} while ( divider_id ! = - 1 ) ;
Temp_Memory temp = begin_temp_memory ( & models - > mem . part ) ;
i32 * divider_stack = push_array ( & models - > mem . part , i32 , models - > layout . panel_count ) ;
i32 top = 0 ;
divider_stack [ top + + ] = div . id ;
while ( top > 0 ) {
- - top ;
Divider_And_ID other_div = layout_get_divider ( & models - > layout , divider_stack [ top ] ) ;
b32 divider_match = ( other_div . divider - > v_divider = = mouse_divider_vertical ) ;
f32 pos = layout_get_position ( & models - > layout , divider_stack [ top ] ) ;
if ( divider_match & & pos > mid & & pos < max ) {
max = pos ;
}
else if ( divider_match & & pos < mid & & pos > min ) {
min = pos ;
}
if ( other_div . divider - > child1 ! = - 1 ) {
divider_stack [ top + + ] = other_div . divider - > child1 ;
}
if ( other_div . divider - > child2 ! = - 1 ) {
divider_stack [ top + + ] = other_div . divider - > child2 ;
}
}
end_temp_memory ( temp ) ;
}
}
} break ;
case APP_STATE_RESIZING :
{
if ( input - > mouse . l ) {
Panel_Divider * divider = vars - > resizing . divider ;
2016-09-09 15:04:38 +00:00
i32 mouse_position = 0 ;
2016-06-29 17:16:08 +00:00
2016-09-09 17:02:57 +00:00
b32 do_absolute_positions = 1 ;
2016-09-09 15:04:38 +00:00
if ( do_absolute_positions ) {
i32 absolute_positions [ MAX_VIEWS ] ;
i32 min = 0 , max = 0 ;
i32 div_id = ( i32 ) ( divider - models - > layout . dividers ) ;
layout_compute_absolute_positions ( & models - > layout , absolute_positions ) ;
mouse_position = ( divider - > v_divider ) ? ( mx ) : ( my ) ;
layout_get_min_max ( & models - > layout , divider , absolute_positions , & min , & max ) ;
2017-03-23 19:15:33 +00:00
absolute_positions [ div_id ] = clamp ( min , mouse_position , max ) ;
2016-09-09 15:04:38 +00:00
layout_update_all_positions ( & models - > layout , absolute_positions ) ;
2016-06-29 17:16:08 +00:00
}
2016-09-09 15:04:38 +00:00
else {
if ( divider - > v_divider ) {
2017-03-23 19:15:33 +00:00
mouse_position = clamp ( 0 , mx , models - > layout . full_width ) ;
2016-09-09 15:04:38 +00:00
}
else {
2017-03-23 19:15:33 +00:00
mouse_position = clamp ( 0 , my , models - > layout . full_height ) ;
2016-09-09 15:04:38 +00:00
}
2016-09-09 16:47:07 +00:00
divider - > pos = layout_compute_position ( & models - > layout , divider , mouse_position ) ;
2016-06-29 17:16:08 +00:00
}
layout_fix_all_panels ( & models - > layout ) ;
}
else {
vars - > state = APP_STATE_EDIT ;
}
} break ;
}
2016-12-18 20:42:11 +00:00
if ( models - > layout . panel_state_dirty & & models - > hooks [ hook_view_size_change ] ! = 0 ) {
models - > layout . panel_state_dirty = 0 ;
models - > hooks [ hook_view_size_change ] ( & models - > app_links ) ;
}
2016-06-29 17:16:08 +00:00
if ( mouse_in_edit_area & & mouse_panel ! = 0 & & input - > mouse . press_l ) {
2017-04-15 21:47:23 +00:00
i32 new_panel_id = ( i32 ) ( mouse_panel - models - > layout . panels ) ;
if ( models - > layout . active_panel ! = new_panel_id ) {
if ( models - > command_coroutine ! = 0 ) {
User_Input user_in = { 0 } ;
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 ;
}
Panel * active_panel = & models - > layout . panels [ models - > layout . active_panel ] ;
View * view = active_panel - > view ;
init_query_set ( & view - > query_set ) ;
}
models - > layout . active_panel = new_panel_id ;
app_result . animating = true ;
}
2016-06-29 17:16:08 +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 ) {
Panel * panel = 0 , * used_panels = & models - > layout . used_sentinel ;
for ( dll_items ( panel , used_panels ) ) {
View * view = panel - > view ;
GUI_Scroll_Vars * scroll_vars = & view - > gui_scroll ;
if ( view - > edit_pos ) {
scroll_vars = & view - > edit_pos - > scroll ;
}
scroll_vars - > scroll_x = ( f32 ) scroll_vars - > target_x ;
scroll_vars - > scroll_y = ( f32 ) scroll_vars - > target_y ;
}
}
2016-09-09 13:04:51 +00:00
// NOTE(allen): if this is the last frame, run the exit hook
if ( ! models - > keep_playing & & models - > hooks [ hook_exit ] ) {
if ( ! models - > hooks [ hook_exit ] ( & models - > app_links ) ) {
models - > keep_playing = 1 ;
}
}
2016-06-29 17:16:08 +00:00
// NOTE(allen): rendering
{
begin_render_section ( target , system ) ;
target - > clip_top = - 1 ;
draw_push_clip ( target , rect_from_target ( target ) ) ;
2016-09-21 22:34:19 +00:00
Command_Data * command = cmd ;
USE_PANEL ( active_panel ) ;
USE_VIEW ( active_view ) ;
2016-06-29 17:16:08 +00:00
// NOTE(allen): render the panels
Panel * panel , * used_panels ;
used_panels = & models - > layout . used_sentinel ;
for ( dll_items ( panel , used_panels ) ) {
i32_Rect full = panel - > full ;
i32_Rect inner = panel - > inner ;
View * view = panel - > view ;
Style * style = main_style ( models ) ;
2016-09-21 22:34:19 +00:00
b32 active = ( panel = = active_panel ) ;
2016-06-29 17:16:08 +00:00
u32 back_color = style - > main . back_color ;
draw_rectangle ( target , full , back_color ) ;
draw_push_clip ( target , panel - > inner ) ;
2016-07-02 17:54:56 +00:00
2016-07-02 22:59:16 +00:00
b32 file_scroll = false ;
GUI_Scroll_Vars scroll_zero = { 0 } ;
GUI_Scroll_Vars * scroll_vars = & view - > gui_scroll ;
if ( view - > showing_ui = = VUI_None ) {
if ( view - > file_data . file ) {
scroll_vars = & view - > edit_pos - > scroll ;
file_scroll = true ;
}
else {
scroll_vars = & scroll_zero ;
}
2016-07-02 17:54:56 +00:00
}
2017-01-29 00:03:23 +00:00
do_render_file_view ( system , view , scroll_vars , active_view , panel - > inner , active , target , & dead_input ) ;
2016-07-02 17:54:56 +00:00
2016-06-29 17:16:08 +00:00
draw_pop_clip ( target ) ;
u32 margin_color ;
if ( active ) {
margin_color = style - > main . margin_active_color ;
}
else if ( panel = = mouse_panel ) {
margin_color = style - > main . margin_hover_color ;
}
else {
margin_color = style - > main . margin_color ;
}
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 ) ;
}
end_render_section ( target , system ) ;
}
// NOTE(allen): get cursor type
if ( mouse_in_edit_area ) {
app_result . mouse_cursor_type = APP_MOUSE_CURSOR_ARROW ;
}
else if ( mouse_in_margin_area ) {
if ( mouse_on_divider ) {
if ( mouse_divider_vertical ) {
app_result . mouse_cursor_type = APP_MOUSE_CURSOR_LEFTRIGHT ;
}
else {
app_result . mouse_cursor_type = APP_MOUSE_CURSOR_UPDOWN ;
}
}
else {
app_result . mouse_cursor_type = APP_MOUSE_CURSOR_ARROW ;
}
}
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 ;
2017-03-17 17:45:41 +00:00
* app_result_ = app_result ;
2016-06-29 17:16:08 +00:00
// end-of-app_step
2017-03-29 20:50:29 +00:00
PRFL_END_FRAME ( " profile.data " ) ;
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