2016-06-13 18:54:26 +00:00
|
|
|
/*
|
2018-08-26 09:55:12 +00:00
|
|
|
* Mr. 4th Dimention - Allen Webster
|
2017-04-01 06:15:33 +00:00
|
|
|
*
|
|
|
|
* ??.??.????
|
|
|
|
*
|
|
|
|
* Implementation of the API functions.
|
|
|
|
*
|
2018-08-26 09:55:12 +00:00
|
|
|
*/
|
2016-06-13 18:54:26 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-12-16 06:56:13 +00:00
|
|
|
function void
|
2019-11-07 01:36:30 +00:00
|
|
|
output_file_append(Thread_Context *tctx, Models *models, Editing_File *file, String_Const_u8 value){
|
|
|
|
i64 end = buffer_size(&file->state.buffer);
|
|
|
|
Edit_Behaviors behaviors = {};
|
2020-05-03 15:00:28 +00:00
|
|
|
behaviors.pos_before_edit = end;
|
2019-11-07 01:36:30 +00:00
|
|
|
edit_single(tctx, models, file, Ii64(end), value, behaviors);
|
|
|
|
}
|
|
|
|
|
2019-12-16 06:56:13 +00:00
|
|
|
function void
|
2019-11-07 01:36:30 +00:00
|
|
|
file_cursor_to_end(Thread_Context *tctx, Models *models, Editing_File *file){
|
|
|
|
Assert(file != 0);
|
|
|
|
i64 pos = buffer_size(&file->state.buffer);
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
|
|
|
View *view = panel->view;
|
|
|
|
if (view->file != file){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
view_set_cursor(tctx, models, view, pos);
|
|
|
|
view->mark = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-10-18 02:54:02 +00:00
|
|
|
access_test(Access_Flag object_flags, Access_Flag access_flags){
|
|
|
|
return((object_flags & access_flags) == access_flags);
|
2016-06-20 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-04-05 23:30:24 +00:00
|
|
|
api_check_panel(Panel *panel){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel != 0 && panel->kind != PanelKind_Unused){
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-04-05 23:30:24 +00:00
|
|
|
api_check_buffer(Editing_File *file){
|
2019-08-12 09:16:04 +00:00
|
|
|
return(file != 0);
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-04-05 23:30:24 +00:00
|
|
|
api_check_buffer(Editing_File *file, Access_Flag access){
|
|
|
|
return(api_check_buffer(file) && access_test(file_get_access_flags(file), access));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-04-05 23:30:24 +00:00
|
|
|
api_check_view(View *view){
|
2019-03-30 23:18:13 +00:00
|
|
|
return(view != 0 && view->in_use);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-04-05 23:30:24 +00:00
|
|
|
api_check_view(View *view, Access_Flag access){
|
|
|
|
return(api_check_view(view) && access_test(view_get_access_flags(view), access));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function b32
|
2019-07-26 00:18:05 +00:00
|
|
|
is_running_coroutine(Application_Links *app){
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *info = (Thread_Context_Extra_Info*)tctx->user_data;
|
|
|
|
return(info->coroutine != 0);
|
2019-07-26 00:18:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-18 02:54:02 +00:00
|
|
|
global_set_setting(Application_Links *app, Global_Setting_ID setting, i64 value){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2017-05-14 23:42:16 +00:00
|
|
|
b32 result = true;
|
|
|
|
switch (setting){
|
|
|
|
case GlobalSetting_LAltLCtrlIsAltGr:
|
|
|
|
{
|
2019-10-10 18:21:47 +00:00
|
|
|
models->settings.lctrl_lalt_is_altgr = (b32)(value != 0);
|
2017-05-14 23:42:16 +00:00
|
|
|
}break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-10-05 02:48:05 +00:00
|
|
|
global_get_screen_rectangle(Application_Links *app){
|
2019-03-31 21:04:02 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-12-08 02:53:01 +00:00
|
|
|
return(Rf32(V2f32(0, 0), V2f32(layout_get_root_size(&models->layout))));
|
2019-03-31 21:04:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Thread_Context*
|
2019-10-05 02:48:05 +00:00
|
|
|
get_thread_context(Application_Links *app){
|
2019-10-22 04:10:29 +00:00
|
|
|
return(app->tctx);
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 02:53:01 +00:00
|
|
|
api(custom) function Child_Process_ID
|
|
|
|
create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command){
|
2019-03-21 03:18:08 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-12-08 02:53:01 +00:00
|
|
|
Child_Process_ID result = 0;
|
|
|
|
if (!child_process_call(app->tctx, models, path, command, &result)){
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
return(result);
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){
|
2019-03-21 03:18:08 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Child_Process *child_process = child_process_from_id(&models->child_processes, child_process_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-03-21 03:18:08 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file) && child_process != 0){
|
|
|
|
result = child_process_set_target_buffer(models, child_process, file, flags);
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Child_Process_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-21 03:18:08 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Child_Process_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = file->state.attached_child_process;
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
child_process_get_attached_buffer(Application_Links *app, Child_Process_ID child_process_id){
|
2019-03-21 03:18:08 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Child_Process *child_process = child_process_from_id(&models->child_processes, child_process_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = 0;
|
|
|
|
if (child_process != 0 && child_process->out_file != 0){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = child_process->out_file->id;
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Process_State
|
2019-10-05 02:48:05 +00:00
|
|
|
child_process_get_state(Application_Links *app, Child_Process_ID child_process_id){
|
2019-03-21 03:18:08 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-19 02:31:59 +00:00
|
|
|
return(child_process_get_state(&models->child_processes, child_process_id));
|
2019-03-21 03:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 22:09:52 +00:00
|
|
|
api(custom) function b32
|
|
|
|
enqueue_virtual_event(Application_Links *app, Input_Event *event){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
b32 result = false;
|
|
|
|
if (InputEventKind_None < event->kind && event->kind < InputEventKind_COUNT){
|
|
|
|
models_push_virtual_event(models, event);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i32
|
2019-10-05 02:48:05 +00:00
|
|
|
get_buffer_count(Application_Links *app)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-08-12 09:16:04 +00:00
|
|
|
return(working_set->active_file_count);
|
2016-07-10 05:49:11 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2019-06-16 23:38:22 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-11-18 19:47:28 +00:00
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-08-12 09:16:04 +00:00
|
|
|
Editing_File *file = working_set_get_file(working_set, buffer_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
file = file_get_next(working_set, file);
|
2019-02-13 22:14:27 +00:00
|
|
|
for (;file != 0 && !access_test(file_get_access_flags(file), access);){
|
2019-04-05 23:30:24 +00:00
|
|
|
file = file_get_next(working_set, file);
|
2016-06-20 20:34:48 +00:00
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = 0;
|
2019-02-13 22:14:27 +00:00
|
|
|
if (file != 0){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = file->id;
|
2019-04-06 19:40:36 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = working_set_contains_name(working_set, name);
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file, access)){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = file->id;
|
2017-06-28 15:15:54 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2017-06-28 15:15:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_buffer_by_file_name(Application_Links *app, String_Const_u8 file_name, Access_Flag access)
|
2017-06-30 18:20:34 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-11-20 08:18:54 +00:00
|
|
|
Editing_File_Name canon = {};
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = false;
|
2019-08-04 00:49:40 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-10-03 17:57:44 +00:00
|
|
|
if (get_canon_name(scratch, file_name, &canon)){
|
2019-06-19 02:31:59 +00:00
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-06-01 23:58:28 +00:00
|
|
|
Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon));
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file, access)){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = file->id;
|
2016-06-20 20:34:48 +00:00
|
|
|
}
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-17 04:22:06 +00:00
|
|
|
buffer_read_range(Application_Links *app, Buffer_ID buffer_id, Range_i64 range, u8 *out)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 size = buffer_size(&file->state.buffer);
|
|
|
|
if (0 <= range.min && range.min <= range.max && range.max <= size){
|
2019-09-02 18:59:36 +00:00
|
|
|
Scratch_Block scratch(app);
|
|
|
|
String_Const_u8 string = buffer_stringify(scratch, &file->state.buffer, range);
|
|
|
|
block_copy(out, string.str, string.size);
|
2016-06-14 20:40:57 +00:00
|
|
|
result = true;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:00:28 +00:00
|
|
|
function Edit_Behaviors
|
|
|
|
get_active_edit_behaviors(Models *models, Editing_File *file){
|
|
|
|
Panel *panel = layout_get_active_panel(&models->layout);
|
|
|
|
Assert(panel != 0);
|
|
|
|
View *view = panel->view;
|
|
|
|
Assert(view != 0);
|
|
|
|
Edit_Behaviors behaviors = {};
|
|
|
|
if (view->file == file){
|
|
|
|
behaviors.pos_before_edit = view->edit_pos_.cursor_pos;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
behaviors.pos_before_edit = -1;
|
|
|
|
}
|
|
|
|
return(behaviors);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range_i64 range, String_Const_u8 string)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 size = buffer_size(&file->state.buffer);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (0 <= range.first && range.first <= range.one_past_last && range.one_past_last <= size){
|
2020-05-03 15:00:28 +00:00
|
|
|
Edit_Behaviors behaviors = get_active_edit_behaviors(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
edit_single(app->tctx, models, file, range, string, behaviors);
|
2019-04-01 03:05:48 +00:00
|
|
|
result = true;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, Batch_Edit *batch)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2019-04-05 23:30:24 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_buffer(file)){
|
2020-05-03 15:00:28 +00:00
|
|
|
Edit_Behaviors behaviors = get_active_edit_behaviors(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
result = edit_batch(app->tctx, models, file, batch, behaviors);
|
2019-04-05 23:30:24 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Match
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_seek_string(Application_Links *app, Buffer_ID buffer, String_Const_u8 needle, Scan_Direction direction, i64 start_pos){
|
2019-06-11 23:16:27 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer);
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Match result = {};
|
2019-06-11 23:16:27 +00:00
|
|
|
if (api_check_buffer(file)){
|
|
|
|
if (needle.size == 0){
|
2019-06-19 02:31:59 +00:00
|
|
|
result.flags = StringMatch_CaseSensitive;
|
2019-10-06 06:59:35 +00:00
|
|
|
result.range = Ii64(start_pos);
|
2019-06-11 23:16:27 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-16 23:38:22 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-06-11 23:16:27 +00:00
|
|
|
Gap_Buffer *gap_buffer = &file->state.buffer;
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 size = buffer_size(gap_buffer);
|
|
|
|
List_String_Const_u8 chunks = buffer_get_chunks(scratch, gap_buffer);
|
2019-12-18 03:38:08 +00:00
|
|
|
Range_i64 range = {};
|
2019-06-16 23:38:22 +00:00
|
|
|
if (direction == Scan_Forward){
|
2019-06-20 03:43:02 +00:00
|
|
|
i64 adjusted_pos = start_pos + 1;
|
2019-06-17 20:05:14 +00:00
|
|
|
start_pos = clamp_top(adjusted_pos, size);
|
2019-10-06 06:59:35 +00:00
|
|
|
range = Ii64(adjusted_pos, size);
|
2019-06-11 23:16:27 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-10-01 22:45:51 +00:00
|
|
|
i64 adjusted_pos = start_pos - 1 + needle.size;
|
2019-06-17 20:05:14 +00:00
|
|
|
start_pos = clamp_bot(0, adjusted_pos);
|
2019-10-06 06:59:35 +00:00
|
|
|
range = Ii64(0, adjusted_pos);
|
2019-06-16 23:38:22 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
buffer_chunks_clamp(&chunks, range);
|
|
|
|
if (chunks.first != 0){
|
2019-06-17 20:05:14 +00:00
|
|
|
u64_Array jump_table = string_compute_needle_jump_table(scratch, needle, direction);
|
|
|
|
Character_Predicate dummy = {};
|
|
|
|
String_Match_List list = find_all_matches(scratch, 1,
|
|
|
|
chunks, needle, jump_table, &dummy, direction,
|
2019-06-20 03:43:02 +00:00
|
|
|
range.min, buffer, 0);
|
2019-06-17 20:05:14 +00:00
|
|
|
if (list.count == 1){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = *list.first;
|
2019-06-17 20:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 03:43:02 +00:00
|
|
|
result.range = Ii64(start_pos);
|
2019-06-11 23:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Match
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_seek_character_class(Application_Links *app, Buffer_ID buffer, Character_Predicate *predicate, Scan_Direction direction, i64 start_pos){
|
2019-06-09 00:09:14 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-20 03:43:02 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer);
|
|
|
|
String_Match result = {};
|
2019-06-09 00:09:14 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 18:59:36 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-06-09 00:09:14 +00:00
|
|
|
Gap_Buffer *gap_buffer = &file->state.buffer;
|
2019-09-02 18:59:36 +00:00
|
|
|
List_String_Const_u8 chunks_list = buffer_get_chunks(scratch, gap_buffer);
|
2019-06-09 00:09:14 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
if (chunks_list.node_count > 0){
|
|
|
|
// TODO(allen): If you are reading this comment, then I haven't revisited this to tighten it up yet.
|
|
|
|
// buffer_seek_character_class was originally implemented using the chunk indexer helper
|
|
|
|
// Buffer_Chunk_Position, and it was written when buffer chunks were in an array instead
|
|
|
|
// of the new method of listing strings in a linked list.
|
|
|
|
// This should probably be implemented as a direct iteration-in-an-iteration that avoids the
|
|
|
|
// extra function calls and branches to achieve the iteration. However, this is a very easy API to
|
|
|
|
// get wrong. There are _a lot_ of opportunities for off by one errors and necessary code duplication,
|
|
|
|
// really tedious stuff. Anyway, this is all just to say, cleaning this up would be really nice, but
|
|
|
|
// there are almost certainly lower hanging fruit with higher payoffs elsewhere... unless need to change
|
|
|
|
// this anyway or whatever.
|
|
|
|
String_Const_u8 chunk_mem[3] = {};
|
|
|
|
String_Const_u8_Array chunks = {chunk_mem};
|
|
|
|
for (Node_String_Const_u8 *node = chunks_list.first;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
chunks.vals[chunks.count] = node->string;
|
|
|
|
chunks.count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
i64 size = buffer_size(gap_buffer);
|
2019-06-11 23:16:27 +00:00
|
|
|
start_pos = clamp(-1, start_pos, size);
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Chunk_Position pos = buffer_get_chunk_position(chunks, size, start_pos);
|
2019-06-09 00:09:14 +00:00
|
|
|
for (;;){
|
2019-06-11 23:16:27 +00:00
|
|
|
i32 past_end = buffer_chunk_position_iterate(chunks, &pos, direction);
|
|
|
|
if (past_end == -1){
|
|
|
|
break;
|
2019-06-09 00:09:14 +00:00
|
|
|
}
|
2019-06-11 23:16:27 +00:00
|
|
|
else if (past_end == 1){
|
2019-10-06 06:59:35 +00:00
|
|
|
result.range = Ii64(size);
|
2019-06-11 23:16:27 +00:00
|
|
|
break;
|
2019-06-09 00:09:14 +00:00
|
|
|
}
|
2019-06-11 23:16:27 +00:00
|
|
|
u8 v = chunks.vals[pos.chunk_index].str[pos.chunk_pos];
|
2019-06-09 00:09:14 +00:00
|
|
|
if (character_predicate_check_character(*predicate, v)){
|
2019-06-20 03:43:02 +00:00
|
|
|
result.buffer = buffer;
|
2019-10-06 06:59:35 +00:00
|
|
|
result.range = Ii64(pos.real_pos, pos.real_pos + 1);
|
2019-06-09 00:09:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function f32
|
2019-10-29 04:27:20 +00:00
|
|
|
buffer_line_y_difference(Application_Links *app, Buffer_ID buffer_id,
|
|
|
|
f32 width, Face_ID face_id,
|
|
|
|
i64 line_a, i64 line_b){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
f32 result = 0.0f;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
result = file_line_y_difference(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
line_a, line_b);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Line_Shift_Vertical
|
2019-10-29 04:27:20 +00:00
|
|
|
buffer_line_shift_y(Application_Links *app, Buffer_ID buffer_id,
|
|
|
|
f32 width, Face_ID face_id,
|
|
|
|
i64 line, f32 y_shift){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
Line_Shift_Vertical result = {};
|
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
result = file_line_shift_y(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
line, y_shift);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-29 04:27:20 +00:00
|
|
|
buffer_pos_at_relative_xy(Application_Links *app, Buffer_ID buffer_id,
|
|
|
|
f32 width, Face_ID face_id,
|
|
|
|
i64 base_line, Vec2_f32 relative_xy){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
i64 result = -1;
|
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
result = file_pos_at_relative_xy(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
base_line, relative_xy);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-30 23:27:37 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-11-04 13:37:45 +00:00
|
|
|
buffer_relative_box_of_pos(Application_Links *app, Buffer_ID buffer_id, f32 width, Face_ID face_id, i64 base_line, i64 pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-10-30 23:27:37 +00:00
|
|
|
Rect_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-30 23:27:37 +00:00
|
|
|
result = file_relative_box_of_pos(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
base_line, pos);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-12-27 05:20:19 +00:00
|
|
|
api(custom) function Rect_f32
|
|
|
|
buffer_padded_box_of_pos(Application_Links *app, Buffer_ID buffer_id, f32 width, Face_ID face_id, i64 base_line, i64 pos){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
Rect_f32 result = {};
|
|
|
|
if (api_check_buffer(file)){
|
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
|
|
|
result = file_padded_box_of_pos(app->tctx, models, file,
|
2020-01-15 18:14:17 +00:00
|
|
|
layout_func, width, face,
|
|
|
|
base_line, pos);
|
2019-12-27 05:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-29 04:27:20 +00:00
|
|
|
buffer_relative_character_from_pos(Application_Links *app, Buffer_ID buffer_id,
|
|
|
|
f32 width, Face_ID face_id, i64 base_line, i64 pos)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
i64 result = 0;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
result = file_relative_character_from_pos(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
base_line, pos);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_pos_from_relative_character(Application_Links *app, Buffer_ID buffer_id, f32 width, Face_ID face_id, i64 base_line, i64 relative_character)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 result = -1;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
result = file_pos_from_relative_character(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
base_line, relative_character);
|
2019-09-02 21:32:52 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function f32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_line_y_difference(Application_Links *app, View_ID view_id, i64 line_a, i64 line_b){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
f32 result = 0.0f;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_line_y_difference(app->tctx, models, view, line_a, line_b);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Line_Shift_Vertical
|
2019-10-05 02:48:05 +00:00
|
|
|
view_line_shift_y(Application_Links *app, View_ID view_id, i64 line, f32 y_shift){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
Line_Shift_Vertical result = {};
|
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_line_shift_y(app->tctx, models, view, line, y_shift);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
view_pos_at_relative_xy(Application_Links *app, View_ID view_id, i64 base_line, Vec2_f32 relative_xy){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
i64 result = -1;
|
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_pos_at_relative_xy(app->tctx, models, view, base_line, relative_xy);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-30 23:27:37 +00:00
|
|
|
api(custom) function Rect_f32
|
|
|
|
view_relative_box_of_pos(Application_Links *app, View_ID view_id, i64 base_line, i64 pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-10-30 23:27:37 +00:00
|
|
|
Rect_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-30 23:27:37 +00:00
|
|
|
result = view_relative_box_of_pos(app->tctx, models, view, base_line, pos);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-12-27 05:20:19 +00:00
|
|
|
api(custom) function Rect_f32
|
|
|
|
view_padded_box_of_pos(Application_Links *app, View_ID view_id, i64 base_line, i64 pos){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
Rect_f32 result = {};
|
|
|
|
if (api_check_view(view)){
|
|
|
|
result = view_padded_box_of_pos(app->tctx, models, view, base_line, pos);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
view_relative_character_from_pos(Application_Links *app, View_ID view_id, i64 base_line, i64 pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
i64 result = 0;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_relative_character_from_pos(app->tctx, models, view, base_line, pos);
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
view_pos_from_relative_character(Application_Links *app, View_ID view_id, i64 base_line, i64 character){
|
2019-09-02 18:59:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
i64 result = 0;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_pos_from_relative_character(app->tctx, models, view, base_line, character);
|
2016-07-12 18:20:06 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_exists(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
return(api_check_buffer(file));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Access_Flag
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Access_Flag result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = file_get_access_flags(file);
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_size(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = buffer_size(&file->state.buffer);
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_line_count(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
u64 result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 18:59:36 +00:00
|
|
|
result = buffer_line_count(&file->state.buffer);
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Const_u8
|
2019-10-05 02:48:05 +00:00
|
|
|
push_buffer_base_name(Application_Links *app, Arena *arena, Buffer_ID buffer_id){
|
2019-03-30 20:17:10 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Const_u8 result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-07-13 00:43:17 +00:00
|
|
|
result = push_string_copy(arena, string_from_file_name(&file->base_name));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Const_u8
|
2019-10-05 02:48:05 +00:00
|
|
|
push_buffer_unique_name(Application_Links *app, Arena *out, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Const_u8 result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-07-13 00:43:17 +00:00
|
|
|
result = push_string_copy(out, string_from_file_name(&file->unique_name));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Const_u8
|
2019-10-05 02:48:05 +00:00
|
|
|
push_buffer_file_name(Application_Links *app, Arena *arena, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Const_u8 result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-07-13 00:43:17 +00:00
|
|
|
result = push_string_copy(arena, string_from_file_name(&file->canon));
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Dirty_State
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id){
|
2019-03-30 23:18:13 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
Dirty_State result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = file->state.dirty;
|
2019-03-30 23:18:13 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){
|
2019-04-01 03:50:37 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-10-31 17:05:38 +00:00
|
|
|
result = true;
|
2019-04-01 03:50:37 +00:00
|
|
|
file->state.dirty = dirty_state;
|
2019-10-31 17:05:38 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function b32
|
2019-10-31 21:42:11 +00:00
|
|
|
buffer_set_layout(Application_Links *app, Buffer_ID buffer_id, Layout_Function *layout_func){
|
2019-10-31 17:05:38 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_buffer(file)){
|
2019-04-01 03:50:37 +00:00
|
|
|
result = true;
|
2019-10-31 17:05:38 +00:00
|
|
|
file->settings.layout_func = layout_func;
|
2019-10-31 21:42:11 +00:00
|
|
|
file_clear_layout_cache(file);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function b32
|
2019-11-01 03:46:53 +00:00
|
|
|
buffer_clear_layout_cache(Application_Links *app, Buffer_ID buffer_id){
|
2019-10-31 21:42:11 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_buffer(file)){
|
|
|
|
result = true;
|
|
|
|
file_clear_layout_cache(file);
|
2019-10-31 17:05:38 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function Layout_Function*
|
|
|
|
buffer_get_layout(Application_Links *app, Buffer_ID buffer_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
Layout_Function *result = 0;
|
|
|
|
if (api_check_buffer(file)){
|
|
|
|
result = file->settings.layout_func;
|
2019-04-01 03:50:37 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-10 18:21:47 +00:00
|
|
|
buffer_get_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i64 *value_out)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2018-08-11 00:42:15 +00:00
|
|
|
result = true;
|
2016-09-22 00:01:12 +00:00
|
|
|
switch (setting){
|
2018-03-24 21:43:57 +00:00
|
|
|
case BufferSetting_Unimportant:
|
|
|
|
{
|
|
|
|
*value_out = file->settings.unimportant;
|
|
|
|
}break;
|
|
|
|
|
2020-01-27 02:27:38 +00:00
|
|
|
case BufferSetting_Unkillable:
|
|
|
|
{
|
|
|
|
*value_out = (file->settings.never_kill || file->settings.unkillable);
|
|
|
|
}break;
|
|
|
|
|
2018-03-24 21:43:57 +00:00
|
|
|
case BufferSetting_ReadOnly:
|
|
|
|
{
|
|
|
|
*value_out = file->settings.read_only;
|
|
|
|
}break;
|
|
|
|
|
2019-02-12 02:33:11 +00:00
|
|
|
case BufferSetting_RecordsHistory:
|
|
|
|
{
|
|
|
|
*value_out = history_is_activated(&file->state.history);
|
|
|
|
}break;
|
|
|
|
|
2018-03-24 21:43:57 +00:00
|
|
|
default:
|
|
|
|
{
|
2019-06-19 02:31:59 +00:00
|
|
|
result = false;
|
2018-03-24 21:43:57 +00:00
|
|
|
}break;
|
2016-09-22 00:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-10 18:21:47 +00:00
|
|
|
buffer_set_setting(Application_Links *app, Buffer_ID buffer_id, Buffer_Setting_ID setting, i64 value)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-03-21 03:18:08 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2017-04-15 21:47:23 +00:00
|
|
|
result = true;
|
2016-06-14 20:40:57 +00:00
|
|
|
switch (setting){
|
2016-07-12 18:20:06 +00:00
|
|
|
case BufferSetting_Unimportant:
|
|
|
|
{
|
2018-05-07 02:47:22 +00:00
|
|
|
if (value != 0){
|
|
|
|
file_set_unimportant(file, true);
|
2016-07-12 18:20:06 +00:00
|
|
|
}
|
|
|
|
else{
|
2018-05-07 02:47:22 +00:00
|
|
|
file_set_unimportant(file, false);
|
2016-07-12 18:20:06 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
2020-01-27 02:27:38 +00:00
|
|
|
case BufferSetting_Unkillable:
|
|
|
|
{
|
|
|
|
file->settings.unkillable = (value != 0);
|
|
|
|
}break;
|
|
|
|
|
2016-07-12 18:20:06 +00:00
|
|
|
case BufferSetting_ReadOnly:
|
|
|
|
{
|
2020-01-27 02:27:38 +00:00
|
|
|
file->settings.read_only = (value != 0);
|
2016-07-12 18:20:06 +00:00
|
|
|
}break;
|
2016-10-05 06:08:23 +00:00
|
|
|
|
2019-02-12 02:33:11 +00:00
|
|
|
case BufferSetting_RecordsHistory:
|
|
|
|
{
|
|
|
|
if (value){
|
|
|
|
if (!history_is_activated(&file->state.history)){
|
2019-10-22 04:10:29 +00:00
|
|
|
history_init(app->tctx, models, &file->state.history);
|
2019-02-12 02:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (history_is_activated(&file->state.history)){
|
2019-10-22 04:10:29 +00:00
|
|
|
history_free(app->tctx, &file->state.history);
|
2019-02-12 02:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = 0;
|
|
|
|
}break;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_managed_scope(Application_Links *app, Buffer_ID buffer_id)
|
2018-09-04 00:37:54 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Managed_Scope result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = file_get_managed_scope(file);
|
2016-06-24 02:53:33 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-27 05:49:35 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-10-22 04:10:29 +00:00
|
|
|
file_end_file(app->tctx, models, file);
|
2019-02-27 05:49:35 +00:00
|
|
|
result = true;
|
2016-09-15 15:01:52 +00:00
|
|
|
}
|
2019-02-27 05:49:35 +00:00
|
|
|
return(result);
|
2016-09-15 15:01:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
Editing_File *new_file = create_file(app->tctx, models, file_name, flags);
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = 0;
|
|
|
|
if (new_file != 0){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = new_file->id;
|
2017-01-14 03:01:35 +00:00
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
return(result);
|
2016-06-17 03:31:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, Buffer_Save_Flag flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2016-06-24 02:21:11 +00:00
|
|
|
|
2019-06-20 04:45:58 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2017-11-21 21:30:40 +00:00
|
|
|
b32 skip_save = false;
|
2019-06-20 04:45:58 +00:00
|
|
|
if (!HasFlag(flags, BufferSave_IgnoreDirtyFlag)){
|
2018-03-24 21:43:57 +00:00
|
|
|
if (file->state.dirty == DirtyState_UpToDate){
|
2019-06-16 23:38:22 +00:00
|
|
|
skip_save = true;
|
2017-11-21 21:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!skip_save){
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
2020-03-11 23:22:37 +00:00
|
|
|
Scratch_Block scratch(tctx);
|
2019-07-13 00:43:17 +00:00
|
|
|
String_Const_u8 name = push_string_copy(scratch, file_name);
|
2019-10-22 04:10:29 +00:00
|
|
|
save_file_to_name(tctx, models, file, name.str);
|
2019-02-13 22:14:27 +00:00
|
|
|
result = true;
|
2016-11-05 03:55:07 +00:00
|
|
|
}
|
2017-01-14 03:01:35 +00:00
|
|
|
}
|
2016-06-24 02:21:11 +00:00
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_Kill_Result
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2016-06-17 03:31:15 +00:00
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-04-05 02:03:36 +00:00
|
|
|
Buffer_Kill_Result result = BufferKillResult_DoesNotExist;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2020-01-27 02:27:38 +00:00
|
|
|
if (!file->settings.never_kill && !file->settings.unkillable){
|
2019-01-29 05:36:17 +00:00
|
|
|
b32 needs_to_save = file_needs_save(file);
|
2018-08-05 07:09:18 +00:00
|
|
|
if (!needs_to_save || (flags & BufferKill_AlwaysKill) != 0){
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
2019-10-14 22:57:47 +00:00
|
|
|
if (models->end_buffer != 0){
|
2019-10-22 04:10:29 +00:00
|
|
|
models->end_buffer(app, file->id);
|
2016-08-27 17:48:10 +00:00
|
|
|
}
|
2018-08-05 07:09:18 +00:00
|
|
|
|
|
|
|
buffer_unbind_name_low_level(working_set, file);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file->canon.name_size != 0){
|
2019-10-03 17:57:44 +00:00
|
|
|
buffer_unbind_file(working_set, file);
|
2016-08-27 17:48:10 +00:00
|
|
|
}
|
2019-10-22 04:10:29 +00:00
|
|
|
file_free(tctx, models, file);
|
2019-10-01 02:06:21 +00:00
|
|
|
working_set_free_file(&models->heap, working_set, file);
|
2018-08-05 07:09:18 +00:00
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
Layout *layout = &models->layout;
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
Node *order = &working_set->touch_order_sentinel;
|
|
|
|
Node *file_node = order->next;
|
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-08-05 07:09:18 +00:00
|
|
|
View *view = panel->view;
|
2019-02-27 05:49:35 +00:00
|
|
|
if (view->file == file){
|
2019-09-02 18:59:36 +00:00
|
|
|
Assert(file_node != order);
|
2019-02-27 05:49:35 +00:00
|
|
|
view->file = 0;
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *new_file = CastFromMember(Editing_File, touch_node, file_node);
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_file(tctx, models, view, new_file);
|
2019-09-02 18:59:36 +00:00
|
|
|
file_node = file_node->next;
|
|
|
|
if (file_node == order){
|
2019-02-05 09:13:38 +00:00
|
|
|
file_node = file_node->next;
|
2018-08-05 07:09:18 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
Assert(file_node != order);
|
2018-08-05 07:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 02:03:36 +00:00
|
|
|
result = BufferKillResult_Killed;
|
2016-06-24 02:21:11 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-04-05 02:03:36 +00:00
|
|
|
result = BufferKillResult_Dirty;
|
2016-06-24 02:21:11 +00:00
|
|
|
}
|
2016-06-17 03:31:15 +00:00
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
else{
|
2019-04-05 02:03:36 +00:00
|
|
|
result = BufferKillResult_Unkillable;
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
2016-06-17 03:31:15 +00:00
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
return(result);
|
2016-06-17 03:31:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_Reopen_Result
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags)
|
2018-11-21 07:48:42 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
2020-03-11 23:22:37 +00:00
|
|
|
Scratch_Block scratch(tctx);
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-04-01 03:05:48 +00:00
|
|
|
Buffer_Reopen_Result result = BufferReopenResult_Failed;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (file->canon.name_size > 0){
|
2019-02-13 22:14:27 +00:00
|
|
|
Plat_Handle handle = {};
|
2019-10-03 17:57:44 +00:00
|
|
|
if (system_load_handle(scratch, (char*)file->canon.name_space, &handle)){
|
|
|
|
File_Attributes attributes = system_load_attributes(handle);
|
2019-02-13 22:14:27 +00:00
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
char *file_memory = push_array(scratch, char, (i32)attributes.size);
|
2019-02-13 22:14:27 +00:00
|
|
|
|
|
|
|
if (file_memory != 0){
|
2019-10-03 17:57:44 +00:00
|
|
|
if (system_load_file(handle, file_memory, (i32)attributes.size)){
|
|
|
|
system_load_close(handle);
|
2019-02-13 22:14:27 +00:00
|
|
|
|
|
|
|
// TODO(allen): try(perform a diff maybe apply edits in reopen)
|
|
|
|
|
2019-02-26 23:17:53 +00:00
|
|
|
i32 line_numbers[16];
|
|
|
|
i32 column_numbers[16];
|
2019-02-13 22:14:27 +00:00
|
|
|
View *vptrs[16];
|
|
|
|
i32 vptr_count = 0;
|
|
|
|
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
|
|
|
View *view_it = panel->view;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (view_it->file == file){
|
|
|
|
vptrs[vptr_count] = view_it;
|
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view_it);
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = file_compute_cursor(view_it->file, seek_pos(edit_pos.cursor_pos));
|
2019-06-20 23:43:27 +00:00
|
|
|
line_numbers[vptr_count] = (i32)cursor.line;
|
2019-09-02 18:59:36 +00:00
|
|
|
column_numbers[vptr_count] = (i32)cursor.col;
|
2019-06-01 23:58:28 +00:00
|
|
|
view_it->file = models->scratch_buffer;
|
|
|
|
++vptr_count;
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
2018-11-21 07:48:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Working_Set *working_set = &models->working_set;
|
2019-10-22 04:10:29 +00:00
|
|
|
file_free(tctx, models, file);
|
2019-06-01 23:58:28 +00:00
|
|
|
working_set_file_default_settings(working_set, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
file_create_from_string(tctx, models, file, SCu8(file_memory, attributes.size), attributes);
|
2018-11-21 07:48:42 +00:00
|
|
|
|
2019-02-13 22:14:27 +00:00
|
|
|
for (i32 i = 0; i < vptr_count; ++i){
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_file(tctx, models, vptrs[i], file);
|
2019-02-13 22:14:27 +00:00
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
vptrs[i]->file = file;
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 line = line_numbers[i];
|
|
|
|
i64 col = column_numbers[i];
|
|
|
|
Buffer_Cursor cursor = file_compute_cursor(file, seek_line_col(line, col));
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_cursor(tctx, models, vptrs[i], cursor.pos);
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
2019-04-01 03:05:48 +00:00
|
|
|
result = BufferReopenResult_Reopened;
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-10-03 17:57:44 +00:00
|
|
|
system_load_close(handle);
|
2018-11-21 07:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-10-03 17:57:44 +00:00
|
|
|
system_load_close(handle);
|
2018-11-21 07:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
return(result);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function File_Attributes
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_get_file_attributes(Application_Links *app, Buffer_ID buffer_id)
|
2019-02-13 23:15:22 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
File_Attributes result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-06-19 02:31:59 +00:00
|
|
|
block_copy_struct(&result, &file->attributes);
|
2019-02-13 23:15:22 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-13 23:15:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function View*
|
2019-02-13 22:14:27 +00:00
|
|
|
get_view_next__inner(Layout *layout, View *view){
|
|
|
|
if (view != 0){
|
|
|
|
Panel *panel = view->panel;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel);
|
2019-02-05 09:13:38 +00:00
|
|
|
if (panel != 0){
|
2019-02-13 22:14:27 +00:00
|
|
|
view = panel->view;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-13 22:14:27 +00:00
|
|
|
view = 0;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-02-13 22:14:27 +00:00
|
|
|
Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
view = panel->view;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
return(view);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function View*
|
2019-03-22 05:06:30 +00:00
|
|
|
get_view_prev__inner(Layout *layout, View *view){
|
|
|
|
if (view != 0){
|
|
|
|
Panel *panel = view->panel;
|
|
|
|
panel = layout_get_prev_open_panel(layout, panel);
|
|
|
|
if (panel != 0){
|
|
|
|
view = panel->view;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
view = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2020-01-15 18:42:02 +00:00
|
|
|
Panel *panel = layout_get_last_open_panel(layout);
|
2019-03-22 05:06:30 +00:00
|
|
|
view = panel->view;
|
|
|
|
}
|
|
|
|
return(view);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function View_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_view_next(Application_Links *app, View_ID view_id, Access_Flag access)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Layout *layout = &models->layout;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
view = get_view_next__inner(layout, view);
|
|
|
|
for (;view != 0 && !access_test(view_get_access_flags(view), access);){
|
|
|
|
view = get_view_next__inner(layout, view);
|
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID result = 0;
|
2019-02-13 22:14:27 +00:00
|
|
|
if (view != 0){
|
2019-10-25 23:33:50 +00:00
|
|
|
result = view_get_id(&models->view_set, view);
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2016-06-20 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function View_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_view_prev(Application_Links *app, View_ID view_id, Access_Flag access)
|
2019-03-22 05:06:30 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
view = get_view_prev__inner(layout, view);
|
|
|
|
for (;view != 0 && !access_test(view_get_access_flags(view), access);){
|
|
|
|
view = get_view_prev__inner(layout, view);
|
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID result = 0;
|
2019-03-22 05:06:30 +00:00
|
|
|
if (view != 0){
|
2019-10-25 23:33:50 +00:00
|
|
|
result = view_get_id(&models->view_set, view);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function View_ID
|
|
|
|
get_this_ctx_view(Application_Links *app, Access_Flag access)
|
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
|
|
|
View_ID result = 0;
|
|
|
|
if (tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
|
|
|
View *view = (View*)coroutine->user_data;
|
|
|
|
if (view != 0){
|
|
|
|
result = view_get_id(&models->view_set, view);
|
|
|
|
}
|
2019-03-22 05:06:30 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function View_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_active_view(Application_Links *app, Access_Flag access)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *panel = layout_get_active_panel(&models->layout);
|
2019-02-13 22:14:27 +00:00
|
|
|
Assert(panel != 0);
|
|
|
|
View *view = panel->view;
|
|
|
|
Assert(view != 0);
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view, access)){
|
2019-10-25 23:33:50 +00:00
|
|
|
result = view_get_id(&models->view_set, view);
|
2016-06-20 20:34:48 +00:00
|
|
|
}
|
2019-02-24 07:22:16 +00:00
|
|
|
return(result);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_exists(Application_Links *app, View_ID view_id){
|
2019-04-05 21:56:58 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-04-05 21:56:58 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_buffer(Application_Links *app, View_ID view_id, Access_Flag access){
|
2019-03-31 18:55:26 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-03-31 18:55:26 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file, access)){
|
2019-08-12 09:16:04 +00:00
|
|
|
result = file->id;
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_cursor_pos(Application_Links *app, View_ID view_id){
|
2019-04-02 20:06:49 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-04-02 20:06:49 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-06-19 02:31:59 +00:00
|
|
|
result = edit_pos.cursor_pos;
|
2019-04-02 20:06:49 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function i64
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_mark_pos(Application_Links *app, View_ID view_id){
|
2019-04-05 21:56:58 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 result = 0;;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = view->mark;
|
2019-04-05 21:56:58 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function f32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_preferred_x(Application_Links *app, View_ID view_id){
|
2019-04-05 21:56:58 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
f32 result = 0.f;;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = view->preferred_x;
|
2019-04-05 21:56:58 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_set_preferred_x(Application_Links *app, View_ID view_id, f32 x){
|
2019-09-02 21:32:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_view(view)){
|
|
|
|
view->preferred_x = x;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_screen_rect(Application_Links *app, View_ID view_id){
|
2019-04-05 21:56:58 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-19 02:31:59 +00:00
|
|
|
Rect_f32 result = {};
|
2019-04-05 21:56:58 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-06 06:59:35 +00:00
|
|
|
result = Rf32(view->panel->rect_full);
|
2019-04-05 21:56:58 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Panel_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_panel(Application_Links *app, View_ID view_id){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Layout *layout = &models->layout;
|
2019-02-24 07:22:16 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Panel_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-13 22:14:27 +00:00
|
|
|
Panel *panel = view->panel;
|
2019-06-19 02:31:59 +00:00
|
|
|
result = panel_get_id(layout, panel);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function View_ID
|
2019-10-18 02:54:02 +00:00
|
|
|
panel_get_view(Application_Links *app, Panel_ID panel_id, Access_Flag access){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Final){
|
|
|
|
View *view = panel->view;
|
2019-10-18 02:54:02 +00:00
|
|
|
if (api_check_view(view, access)){
|
2019-10-25 23:33:50 +00:00
|
|
|
result = view_get_id(&models->view_set, view);
|
2019-10-18 02:54:02 +00:00
|
|
|
}
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
panel_is_split(Application_Links *app, Panel_ID panel_id){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Intermediate){
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
panel_is_leaf(Application_Links *app, Panel_ID panel_id){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Final){
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-18 02:54:02 +00:00
|
|
|
panel_split(Application_Links *app, Panel_ID panel_id, Dimension split_dim){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *new_panel = 0;
|
2019-11-08 04:58:13 +00:00
|
|
|
if (layout_split_panel(layout, panel, (split_dim == Dimension_X), &new_panel)){
|
2019-10-25 23:33:50 +00:00
|
|
|
Live_Views *view_set = &models->view_set;
|
2019-11-08 04:58:13 +00:00
|
|
|
View *new_view = live_set_alloc_view(&models->lifetime_allocator, view_set, new_panel);
|
2019-10-22 04:10:29 +00:00
|
|
|
view_init(app->tctx, models, new_view, models->scratch_buffer,
|
2019-10-18 02:54:02 +00:00
|
|
|
models->view_event_handler);
|
2019-02-24 07:22:16 +00:00
|
|
|
result = true;
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
2016-07-05 01:36:30 +00:00
|
|
|
}
|
2019-02-24 07:22:16 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-18 02:54:02 +00:00
|
|
|
panel_set_split(Application_Links *app, Panel_ID panel_id, Panel_Split_Kind kind,
|
|
|
|
f32 t){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Intermediate){
|
|
|
|
panel->split.kind = kind;
|
|
|
|
switch (kind){
|
|
|
|
case PanelSplitKind_Ratio_Max:
|
|
|
|
case PanelSplitKind_Ratio_Min:
|
|
|
|
{
|
|
|
|
panel->split.v_f32 = clamp(0.f, t, 1.f);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case PanelSplitKind_FixedPixels_Max:
|
|
|
|
case PanelSplitKind_FixedPixels_Min:
|
|
|
|
{
|
2019-10-09 14:40:50 +00:00
|
|
|
panel->split.v_i32 = i32_round32(t);
|
2019-02-24 07:22:16 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
print_message(app, string_u8_litexpr("Invalid split kind passed to panel_set_split, no change made to view layout"));
|
2019-02-24 07:22:16 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
layout_propogate_sizes_down_from_node(layout, panel);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-11-08 04:58:13 +00:00
|
|
|
panel_swap_children(Application_Links *app, Panel_ID panel_id){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-02-24 07:22:16 +00:00
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Intermediate){
|
|
|
|
Swap(Panel*, panel->tl_panel, panel->br_panel);
|
|
|
|
layout_propogate_sizes_down_from_node(layout, panel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-11-08 04:58:13 +00:00
|
|
|
api(custom) function Panel_ID
|
|
|
|
panel_get_root(Application_Links *app){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
Panel *panel = layout->root;
|
|
|
|
return(panel_get_id(layout, panel));
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Panel_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
panel_get_parent(Application_Links *app, Panel_ID panel_id){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Panel_ID result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = panel_get_id(layout, panel->parent);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Panel_ID
|
2019-10-18 02:54:02 +00:00
|
|
|
panel_get_child(Application_Links *app, Panel_ID panel_id, Side which_child){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
Panel *panel = imp_get_panel(models, panel_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Panel_ID result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_panel(panel)){
|
2019-02-24 07:22:16 +00:00
|
|
|
if (panel->kind == PanelKind_Intermediate){
|
|
|
|
Panel *child = 0;
|
|
|
|
switch (which_child){
|
2019-10-18 02:54:02 +00:00
|
|
|
case Side_Min:
|
2019-02-24 07:22:16 +00:00
|
|
|
{
|
|
|
|
child = panel->tl_panel;
|
|
|
|
}break;
|
2019-10-18 02:54:02 +00:00
|
|
|
case Side_Max:
|
2019-02-24 07:22:16 +00:00
|
|
|
{
|
|
|
|
child = panel->br_panel;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
if (child != 0){
|
2019-06-19 02:31:59 +00:00
|
|
|
result = panel_get_id(layout, child);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_close(Application_Links *app, View_ID view_id)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Layout *layout = &models->layout;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-13 20:17:22 +00:00
|
|
|
result = view_close(models, view);
|
2016-07-05 01:36:30 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_buffer_region(Application_Links *app, View_ID view_id){
|
2019-02-27 05:49:35 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-19 02:31:59 +00:00
|
|
|
Rect_f32 result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = view_get_buffer_rect(app->tctx, models, view);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_Scroll
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_buffer_scroll(Application_Links *app, View_ID view_id){
|
2019-03-31 20:56:00 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Scroll result = {};
|
2019-03-31 20:56:00 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-14 02:13:15 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
result = edit_pos.scroll;
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_set_active(Application_Links *app, View_ID view_id)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-13 22:14:27 +00:00
|
|
|
models->layout.active_panel = view->panel;
|
2016-06-28 19:48:12 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-11-07 01:36:30 +00:00
|
|
|
view_enqueue_command_function(Application_Links *app, View_ID view_id, Custom_Command_Function *custom_func)
|
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_view(view)){
|
|
|
|
models_push_view_command_function(models, view_id, custom_func);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function b32
|
2019-10-10 22:57:02 +00:00
|
|
|
view_get_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i64 *value_out)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2016-09-20 19:48:02 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-13 22:14:27 +00:00
|
|
|
result = true;
|
2016-09-20 19:48:02 +00:00
|
|
|
switch (setting){
|
2018-03-24 10:06:45 +00:00
|
|
|
case ViewSetting_ShowWhitespace:
|
|
|
|
{
|
2019-02-27 05:49:35 +00:00
|
|
|
*value_out = view->show_whitespace;
|
2018-03-24 10:06:45 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case ViewSetting_ShowScrollbar:
|
|
|
|
{
|
2019-02-13 22:14:27 +00:00
|
|
|
*value_out = !view->hide_scrollbar;
|
2018-03-24 10:06:45 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case ViewSetting_ShowFileBar:
|
|
|
|
{
|
2019-02-13 22:14:27 +00:00
|
|
|
*value_out = !view->hide_file_bar;
|
2018-03-24 10:06:45 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-02-13 22:14:27 +00:00
|
|
|
result = false;
|
2018-03-24 10:06:45 +00:00
|
|
|
}break;
|
2016-09-20 19:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-10 18:21:47 +00:00
|
|
|
view_set_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i64 value)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2016-06-29 18:38:58 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2016-07-04 20:40:57 +00:00
|
|
|
result = true;
|
2016-06-29 18:38:58 +00:00
|
|
|
switch (setting){
|
2016-07-04 20:40:57 +00:00
|
|
|
case ViewSetting_ShowWhitespace:
|
|
|
|
{
|
2019-09-02 18:59:36 +00:00
|
|
|
view->show_whitespace = (b8)value;
|
2016-07-04 20:40:57 +00:00
|
|
|
}break;
|
|
|
|
|
2016-06-29 18:38:58 +00:00
|
|
|
case ViewSetting_ShowScrollbar:
|
|
|
|
{
|
2019-09-02 18:59:36 +00:00
|
|
|
view->hide_scrollbar = (b8)!value;
|
2016-06-29 18:38:58 +00:00
|
|
|
}break;
|
2016-07-04 20:40:57 +00:00
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
case ViewSetting_ShowFileBar:
|
|
|
|
{
|
2019-09-02 18:59:36 +00:00
|
|
|
view->hide_file_bar = (b8)!value;
|
2017-03-27 22:36:42 +00:00
|
|
|
}break;
|
|
|
|
|
2016-07-04 20:40:57 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}break;
|
2016-06-29 18:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
view_get_managed_scope(Application_Links *app, View_ID view_id)
|
2018-08-11 00:42:15 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-06-20 04:45:58 +00:00
|
|
|
Managed_Scope result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-10 09:18:34 +00:00
|
|
|
Assert(view->lifetime_object != 0);
|
2019-06-20 04:45:58 +00:00
|
|
|
result = (Managed_Scope)(view->lifetime_object->workspace.scope_id);
|
2018-08-11 00:42:15 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2018-08-11 00:42:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_Cursor
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_compute_cursor(Application_Links *app, Buffer_ID buffer, Buffer_Seek seek)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer);
|
|
|
|
Buffer_Cursor result = {};
|
|
|
|
if (api_check_buffer(file)){
|
|
|
|
result = file_compute_cursor(file, seek);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Buffer_Cursor
|
2019-10-05 02:48:05 +00:00
|
|
|
view_compute_cursor(Application_Links *app, View_ID view_id, Buffer_Seek seek){
|
2019-09-02 21:32:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
Buffer_Cursor result = {};
|
|
|
|
if (api_check_view(view)){
|
|
|
|
result = view_compute_cursor(view, seek);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_set_cursor(Application_Links *app, View_ID view_id, Buffer_Seek seek)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-02-13 22:14:27 +00:00
|
|
|
Assert(file != 0);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = file_compute_cursor(file, seek);
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_cursor(app->tctx, models, view, cursor.pos);
|
2019-02-10 09:18:34 +00:00
|
|
|
result = true;
|
2016-07-12 18:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-15 03:26:00 +00:00
|
|
|
view_set_buffer_scroll(Application_Links *app, View_ID view_id, Buffer_Scroll scroll,
|
|
|
|
Set_Buffer_Scroll_Rule rule)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 18:59:36 +00:00
|
|
|
b32 result = false;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
scroll.position = view_normalize_buffer_point(tctx, models, view, scroll.position);
|
|
|
|
scroll.target = view_normalize_buffer_point(tctx, models, view, scroll.target);
|
2019-10-14 02:13:15 +00:00
|
|
|
scroll.target.pixel_shift.x = f32_round32(scroll.target.pixel_shift.x);
|
|
|
|
scroll.target.pixel_shift.y = f32_round32(scroll.target.pixel_shift.y);
|
|
|
|
scroll.target.pixel_shift.x = clamp_bot(0.f, scroll.target.pixel_shift.x);
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Item_List line = view_get_line_layout(tctx, models, view,
|
|
|
|
scroll.target.line_number);
|
|
|
|
scroll.target.pixel_shift.y =
|
|
|
|
clamp(0.f, scroll.target.pixel_shift.y, line.height);
|
2019-10-15 03:26:00 +00:00
|
|
|
if (rule == SetBufferScroll_SnapCursorIntoView){
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_scroll(tctx, models, view, scroll);
|
2019-10-15 03:26:00 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
|
|
|
edit_pos.scroll = scroll;
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
|
|
|
}
|
2019-10-14 02:13:15 +00:00
|
|
|
view->new_scroll_target = true;
|
|
|
|
result = true;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_set_mark(Application_Links *app, View_ID view_id, Buffer_Seek seek)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-03-21 03:18:08 +00:00
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *file = view->file;
|
2018-03-24 10:06:45 +00:00
|
|
|
Assert(file != 0);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2016-07-02 22:59:16 +00:00
|
|
|
if (seek.type != buffer_seek_pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = file_compute_cursor(file, seek);
|
2019-02-13 22:14:27 +00:00
|
|
|
view->mark = cursor.pos;
|
2016-07-02 22:59:16 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-13 22:14:27 +00:00
|
|
|
view->mark = seek.pos;
|
2016-07-02 22:59:16 +00:00
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
result = true;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-11-07 02:09:16 +00:00
|
|
|
api(custom) function b32
|
|
|
|
view_quit_ui(Application_Links *app, View_ID view_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (view != 0){
|
|
|
|
view_quit_ui(app->tctx, models, view);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
view_set_buffer(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Set_Buffer_Flag flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-08-12 09:16:04 +00:00
|
|
|
Editing_File *file = working_set_get_file(&models->working_set, buffer_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-02-27 05:49:35 +00:00
|
|
|
if (file != view->file){
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_file(app->tctx, models, view, file);
|
2016-06-24 04:02:09 +00:00
|
|
|
if (!(flags & SetBuffer_KeepOriginalGUI)){
|
2019-11-07 02:09:16 +00:00
|
|
|
view_quit_ui(app->tctx, models, view);
|
2016-06-24 04:02:09 +00:00
|
|
|
}
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
result = true;
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-14 02:13:15 +00:00
|
|
|
view_push_context(Application_Links *app, View_ID view_id, View_Context *ctx){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-15 03:26:00 +00:00
|
|
|
view_push_context(view, ctx);
|
2018-11-18 19:47:28 +00:00
|
|
|
result = true;
|
2018-07-14 01:13:05 +00:00
|
|
|
}
|
2018-11-18 19:47:28 +00:00
|
|
|
return(result);
|
2018-07-14 01:13:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-14 02:13:15 +00:00
|
|
|
view_pop_context(Application_Links *app, View_ID view_id){
|
2019-02-26 19:59:57 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-15 03:26:00 +00:00
|
|
|
view_pop_context(view);
|
2019-02-26 19:59:57 +00:00
|
|
|
result = true;
|
2018-07-14 01:13:05 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
return(result);
|
2018-07-14 01:13:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 01:46:57 +00:00
|
|
|
api(custom) function b32
|
|
|
|
view_alter_context(Application_Links *app, View_ID view_id, View_Context *ctx){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
b32 result = false;
|
|
|
|
if (api_check_view(view)){
|
|
|
|
view_alter_context(view, ctx);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-14 02:13:15 +00:00
|
|
|
api(custom) function View_Context
|
|
|
|
view_current_context(Application_Links *app, View_ID view_id){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-10-14 02:13:15 +00:00
|
|
|
View_Context result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_view(view)){
|
2019-10-18 02:54:02 +00:00
|
|
|
result = view_current_context(view);
|
2018-08-04 02:41:38 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
return(result);
|
2018-08-04 02:41:38 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
api(custom) function Data
|
|
|
|
view_current_context_hook_memory(Application_Links *app, View_ID view_id,
|
|
|
|
Hook_ID hook_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
Data result = {};
|
|
|
|
if (api_check_view(view)){
|
2019-10-18 02:54:02 +00:00
|
|
|
View_Context_Node *ctx = view_current_context_node(view);
|
2019-10-15 03:26:00 +00:00
|
|
|
if (ctx != 0){
|
|
|
|
switch (hook_id){
|
|
|
|
case HookID_DeltaRule:
|
|
|
|
{
|
|
|
|
result = make_data(ctx->delta_rule_memory,
|
|
|
|
ctx->ctx.delta_rule_memory_size);
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function Dynamic_Workspace*
|
2018-09-07 22:39:33 +00:00
|
|
|
get_dynamic_workspace(Models *models, Managed_Scope handle){
|
2019-09-04 05:31:35 +00:00
|
|
|
Dynamic_Workspace *result = 0;
|
|
|
|
Table_Lookup lookup = table_lookup(&models->lifetime_allocator.scope_id_to_scope_ptr_table, handle);
|
|
|
|
if (lookup.found_match){
|
|
|
|
u64 val = 0;
|
|
|
|
table_read(&models->lifetime_allocator.scope_id_to_scope_ptr_table, lookup, &val);
|
|
|
|
result = (Dynamic_Workspace*)IntAsPtr(val);
|
2018-08-26 09:55:12 +00:00
|
|
|
}
|
2019-09-04 05:31:35 +00:00
|
|
|
return(result);
|
2018-08-26 09:55:12 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
create_user_managed_scope(Application_Links *app)
|
2018-10-01 19:32:28 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-04 05:31:35 +00:00
|
|
|
Lifetime_Object *object = lifetime_alloc_object(&models->lifetime_allocator, DynamicWorkspace_Unassociated, 0);
|
2018-09-26 18:06:57 +00:00
|
|
|
object->workspace.user_back_ptr = object;
|
|
|
|
Managed_Scope scope = (Managed_Scope)object->workspace.scope_id;
|
|
|
|
return(scope);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
destroy_user_managed_scope(Application_Links *app, Managed_Scope scope)
|
2018-10-01 19:32:28 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-26 18:06:57 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
2019-03-21 03:18:08 +00:00
|
|
|
b32 result = false;
|
2018-09-27 05:01:01 +00:00
|
|
|
if (workspace != 0 && workspace->user_type == DynamicWorkspace_Unassociated){
|
2018-09-26 18:06:57 +00:00
|
|
|
Lifetime_Object *lifetime_object = (Lifetime_Object*)workspace->user_back_ptr;
|
2019-09-04 05:31:35 +00:00
|
|
|
lifetime_free_object(&models->lifetime_allocator, lifetime_object);
|
2019-03-21 03:18:08 +00:00
|
|
|
result = true;
|
2018-09-26 18:06:57 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2018-09-26 18:06:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
get_global_managed_scope(Application_Links *app)
|
2018-09-26 18:06:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-26 18:06:57 +00:00
|
|
|
return((Managed_Scope)models->dynamic_workspace.scope_id);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function Lifetime_Object*
|
2018-09-27 05:01:01 +00:00
|
|
|
get_lifetime_object_from_workspace(Dynamic_Workspace *workspace){
|
|
|
|
Lifetime_Object *result = 0;
|
|
|
|
switch (workspace->user_type){
|
|
|
|
case DynamicWorkspace_Unassociated:
|
|
|
|
{
|
|
|
|
result = (Lifetime_Object*)workspace->user_back_ptr;
|
|
|
|
}break;
|
|
|
|
case DynamicWorkspace_Buffer:
|
|
|
|
{
|
|
|
|
Editing_File *file = (Editing_File*)workspace->user_back_ptr;
|
|
|
|
result = file->lifetime_object;
|
|
|
|
}break;
|
|
|
|
case DynamicWorkspace_View:
|
|
|
|
{
|
|
|
|
View *vptr = (View*)workspace->user_back_ptr;
|
2019-02-10 09:18:34 +00:00
|
|
|
result = vptr->lifetime_object;
|
2018-09-27 05:01:01 +00:00
|
|
|
}break;
|
2019-01-31 12:38:24 +00:00
|
|
|
default:
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
InvalidPath;
|
2019-01-31 12:38:24 +00:00
|
|
|
}break;
|
2018-09-27 05:01:01 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
get_managed_scope_with_multiple_dependencies(Application_Links *app, Managed_Scope *scopes, i32 count)
|
2018-08-11 05:42:00 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-08-12 06:33:52 +00:00
|
|
|
Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator;
|
2019-06-01 23:58:28 +00:00
|
|
|
|
2020-03-11 23:22:37 +00:00
|
|
|
Scratch_Block scratch(app);
|
2018-08-12 03:45:09 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
// TODO(allen): revisit this
|
|
|
|
struct Node_Ptr{
|
|
|
|
Node_Ptr *next;
|
|
|
|
Lifetime_Object *object_ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
Node_Ptr *first = 0;
|
|
|
|
Node_Ptr *last = 0;
|
|
|
|
i32 member_count = 0;
|
2018-08-12 03:45:09 +00:00
|
|
|
|
|
|
|
b32 filled_array = true;
|
|
|
|
for (i32 i = 0; i < count; i += 1){
|
2018-10-01 19:32:28 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scopes[i]);
|
2018-08-26 09:55:12 +00:00
|
|
|
if (workspace == 0){
|
|
|
|
filled_array = false;
|
|
|
|
break;
|
|
|
|
}
|
2018-08-12 03:45:09 +00:00
|
|
|
|
2018-08-26 09:55:12 +00:00
|
|
|
switch (workspace->user_type){
|
|
|
|
case DynamicWorkspace_Global:
|
2018-08-12 03:45:09 +00:00
|
|
|
{
|
2018-09-07 22:39:33 +00:00
|
|
|
// NOTE(allen): (global_scope INTERSECT X) == X for all X, therefore we emit nothing when a global group is in the key list.
|
2018-08-12 03:45:09 +00:00
|
|
|
}break;
|
|
|
|
|
2018-09-26 18:06:57 +00:00
|
|
|
case DynamicWorkspace_Unassociated:
|
2018-08-26 09:55:12 +00:00
|
|
|
case DynamicWorkspace_Buffer:
|
|
|
|
case DynamicWorkspace_View:
|
2018-08-12 03:45:09 +00:00
|
|
|
{
|
2018-09-27 05:01:01 +00:00
|
|
|
Lifetime_Object *object = get_lifetime_object_from_workspace(workspace);
|
|
|
|
Assert(object != 0);
|
2019-06-01 23:58:28 +00:00
|
|
|
Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1);
|
|
|
|
sll_queue_push(first, last, new_node);
|
|
|
|
new_node->object_ptr = object;
|
|
|
|
member_count += 1;
|
2018-08-12 03:45:09 +00:00
|
|
|
}break;
|
|
|
|
|
2018-08-26 09:55:12 +00:00
|
|
|
case DynamicWorkspace_Intersected:
|
2018-08-12 03:45:09 +00:00
|
|
|
{
|
2018-08-26 09:55:12 +00:00
|
|
|
Lifetime_Key *key = (Lifetime_Key*)workspace->user_back_ptr;
|
|
|
|
if (lifetime_key_check(lifetime_allocator, key)){
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 key_member_count = key->count;
|
2018-08-26 09:55:12 +00:00
|
|
|
Lifetime_Object **key_member_ptr = key->members;
|
2019-06-01 23:58:28 +00:00
|
|
|
for (i32 j = 0; j < key_member_count; j += 1, key_member_ptr += 1){
|
|
|
|
Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1);
|
|
|
|
sll_queue_push(first, last, new_node);
|
|
|
|
new_node->object_ptr = *key_member_ptr;
|
|
|
|
member_count += 1;
|
2018-08-26 09:55:12 +00:00
|
|
|
}
|
2018-08-12 03:45:09 +00:00
|
|
|
}
|
|
|
|
}break;
|
2018-09-26 18:06:57 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
InvalidPath;
|
2018-09-26 18:06:57 +00:00
|
|
|
}break;
|
2018-08-12 03:45:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Scope result = 0;
|
2018-08-12 03:45:09 +00:00
|
|
|
if (filled_array){
|
2019-06-01 23:58:28 +00:00
|
|
|
Lifetime_Object **object_ptr_array = push_array(scratch, Lifetime_Object*, member_count);
|
|
|
|
i32 index = 0;
|
|
|
|
for (Node_Ptr *node = first;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
object_ptr_array[index] = node->object_ptr;
|
|
|
|
index += 1;
|
|
|
|
}
|
2018-08-12 03:45:09 +00:00
|
|
|
member_count = lifetime_sort_and_dedup_object_set(object_ptr_array, member_count);
|
2019-09-04 05:31:35 +00:00
|
|
|
Lifetime_Key *key = lifetime_get_or_create_intersection_key(lifetime_allocator, object_ptr_array, member_count);
|
2018-09-07 22:39:33 +00:00
|
|
|
result = (Managed_Scope)key->dynamic_workspace.scope_id;
|
2018-08-12 03:45:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-11 05:42:00 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_scope_clear_contents(Application_Links *app, Managed_Scope scope)
|
2018-10-01 19:32:28 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-27 05:01:01 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
2019-03-21 03:18:08 +00:00
|
|
|
b32 result = false;
|
2018-09-27 05:01:01 +00:00
|
|
|
if (workspace != 0){
|
2019-09-04 05:31:35 +00:00
|
|
|
dynamic_workspace_clear_contents(workspace);
|
2019-03-21 03:18:08 +00:00
|
|
|
result = true;
|
2018-09-27 05:01:01 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2018-09-27 05:01:01 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_scope_clear_self_all_dependent_scopes(Application_Links *app, Managed_Scope scope)
|
2018-10-01 19:32:28 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-27 05:01:01 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
2019-03-21 03:18:08 +00:00
|
|
|
b32 result = false;
|
2018-09-27 05:01:01 +00:00
|
|
|
if (workspace != 0 && workspace->user_type != DynamicWorkspace_Global && workspace->user_type != DynamicWorkspace_Intersected){
|
|
|
|
Lifetime_Object *object = get_lifetime_object_from_workspace(workspace);
|
|
|
|
Assert(object != 0);
|
2019-09-04 05:31:35 +00:00
|
|
|
lifetime_object_reset(&models->lifetime_allocator, object);
|
2019-03-21 03:18:08 +00:00
|
|
|
result = true;
|
2018-09-27 05:01:01 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2018-09-27 05:01:01 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Base_Allocator*
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_scope_allocator(Application_Links *app, Managed_Scope scope)
|
2018-08-12 03:45:09 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-04 05:31:35 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
|
|
|
Base_Allocator *result = 0;
|
|
|
|
if (workspace != 0){
|
|
|
|
result = &workspace->heap_wrapper;
|
|
|
|
}
|
|
|
|
return(result);
|
2018-08-12 03:45:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 06:09:31 +00:00
|
|
|
api(custom) function u64
|
|
|
|
managed_id_group_highest_id(Application_Links *app, String_Const_u8 group){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Managed_ID_Set *set = &models->managed_id_set;
|
|
|
|
return(managed_ids_group_highest_id(set, group));
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_ID
|
2019-11-24 23:13:51 +00:00
|
|
|
managed_id_declare(Application_Links *app, String_Const_u8 group, String_Const_u8 name)
|
2018-08-12 03:45:09 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-04 05:31:35 +00:00
|
|
|
Managed_ID_Set *set = &models->managed_id_set;
|
2019-11-24 23:13:51 +00:00
|
|
|
return(managed_ids_declare(set, group, name));
|
2018-08-12 03:45:09 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 19:35:41 +00:00
|
|
|
api(custom) function Managed_ID
|
|
|
|
managed_id_get(Application_Links *app, String_Const_u8 group, String_Const_u8 name){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Managed_ID_Set *set = &models->managed_id_set;
|
|
|
|
return(managed_ids_get(set, group, name));
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void*
|
2019-12-18 03:38:08 +00:00
|
|
|
managed_scope_get_attachment(Application_Links *app, Managed_Scope scope, Managed_ID id, u64 size){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-04 05:31:35 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
|
|
|
void *result = 0;
|
2018-08-18 08:16:52 +00:00
|
|
|
if (workspace != 0){
|
2019-09-04 05:31:35 +00:00
|
|
|
Dynamic_Variable_Block *var_block = &workspace->var_block;
|
|
|
|
Data data = dynamic_variable_get(var_block, id, size);
|
|
|
|
if (data.size >= size){
|
|
|
|
result = data.data;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
#define M \
|
2020-05-01 13:31:44 +00:00
|
|
|
"ERROR: scope attachment already exists with a size smaller than the requested size; no attachment pointer can be returned."
|
|
|
|
print_message(app, string_u8_litexpr(M));
|
2019-10-10 22:57:02 +00:00
|
|
|
#undef M
|
2018-08-11 00:42:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-12-08 02:53:01 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_scope_attachment_erase(Application_Links *app, Managed_Scope scope, Managed_ID id){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-04 05:31:35 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
2019-12-08 02:53:01 +00:00
|
|
|
b32 result = false;
|
2019-09-04 05:31:35 +00:00
|
|
|
if (workspace != 0){
|
|
|
|
Dynamic_Variable_Block *var_block = &workspace->var_block;
|
|
|
|
dynamic_variable_erase(var_block, id);
|
2019-12-08 02:53:01 +00:00
|
|
|
result = true;
|
2018-08-11 00:42:15 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2018-08-11 00:42:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Object
|
2019-10-05 02:48:05 +00:00
|
|
|
alloc_managed_memory_in_scope(Application_Links *app, Managed_Scope scope, i32 item_size, i32 count)
|
2018-08-18 08:16:52 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scope);
|
2018-08-18 08:16:52 +00:00
|
|
|
Managed_Object result = 0;
|
|
|
|
if (workspace != 0){
|
2019-09-04 05:31:35 +00:00
|
|
|
result = managed_object_alloc_managed_memory(workspace, item_size, count, 0);
|
2018-08-18 08:16:52 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Object
|
2019-10-05 02:48:05 +00:00
|
|
|
alloc_buffer_markers_on_buffer(Application_Links *app, Buffer_ID buffer_id, i32 count, Managed_Scope *optional_extra_scope)
|
2018-09-04 00:37:54 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
Managed_Scope markers_scope = file_get_managed_scope(file);
|
2018-09-07 22:39:33 +00:00
|
|
|
if (optional_extra_scope != 0){
|
|
|
|
Managed_Object scope_array[2];
|
|
|
|
scope_array[0] = markers_scope;
|
|
|
|
scope_array[1] = *optional_extra_scope;
|
2019-10-05 02:48:05 +00:00
|
|
|
markers_scope = get_managed_scope_with_multiple_dependencies(app, scope_array, 2);
|
2018-09-04 00:37:54 +00:00
|
|
|
}
|
2018-09-07 22:39:33 +00:00
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, markers_scope);
|
2018-09-04 00:37:54 +00:00
|
|
|
Managed_Object result = 0;
|
|
|
|
if (workspace != 0){
|
2019-09-04 05:31:35 +00:00
|
|
|
result = managed_object_alloc_buffer_markers(workspace, buffer_id, count, 0);
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function Managed_Object_Ptr_And_Workspace
|
2018-09-07 22:39:33 +00:00
|
|
|
get_dynamic_object_ptrs(Models *models, Managed_Object object){
|
2018-11-20 08:18:54 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace result = {};
|
2018-09-07 22:39:33 +00:00
|
|
|
u32 hi_id = (object >> 32)&max_u32;
|
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, hi_id);
|
|
|
|
if (workspace != 0){
|
|
|
|
u32 lo_id = object&max_u32;
|
|
|
|
Managed_Object_Standard_Header *header = (Managed_Object_Standard_Header*)dynamic_workspace_get_pointer(workspace, lo_id);
|
|
|
|
if (header != 0){
|
|
|
|
result.workspace = workspace;
|
|
|
|
result.header = header;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function u32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_get_item_size(Application_Links *app, Managed_Object object)
|
2018-09-07 22:39:33 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
2019-03-28 03:06:17 +00:00
|
|
|
u32 result = 0;
|
2018-09-07 22:39:33 +00:00
|
|
|
if (object_ptrs.header != 0){
|
2019-03-28 03:06:17 +00:00
|
|
|
result = object_ptrs.header->item_size;
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
2019-03-28 03:06:17 +00:00
|
|
|
return(result);
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function u32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_get_item_count(Application_Links *app, Managed_Object object)
|
2018-09-07 22:39:33 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
2019-03-28 03:06:17 +00:00
|
|
|
u32 result = 0;
|
2018-09-07 22:39:33 +00:00
|
|
|
if (object_ptrs.header != 0){
|
2019-03-28 03:06:17 +00:00
|
|
|
result = object_ptrs.header->count;
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
2019-03-28 03:06:17 +00:00
|
|
|
return(result);
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void*
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_get_pointer(Application_Links *app, Managed_Object object)
|
2019-09-04 05:31:35 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
|
|
|
return(get_dynamic_object_memory_ptr(object_ptrs.header));
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Object_Type
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_get_type(Application_Links *app, Managed_Object object)
|
2018-09-07 22:39:33 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
|
|
|
if (object_ptrs.header != 0){
|
|
|
|
Managed_Object_Type type = object_ptrs.header->type;
|
|
|
|
if (type < 0 || ManagedObjectType_COUNT <= type){
|
|
|
|
type = ManagedObjectType_Error;
|
|
|
|
}
|
|
|
|
return(type);
|
|
|
|
}
|
|
|
|
return(ManagedObjectType_Error);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Managed_Scope
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_get_containing_scope(Application_Links *app, Managed_Object object)
|
2018-09-07 22:39:33 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
u32 hi_id = (object >> 32)&max_u32;
|
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, hi_id);
|
|
|
|
if (workspace != 0){
|
|
|
|
return((Managed_Scope)hi_id);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_free(Application_Links *app, Managed_Object object)
|
2018-09-04 00:37:54 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-04 00:37:54 +00:00
|
|
|
u32 hi_id = (object >> 32)&max_u32;
|
|
|
|
Dynamic_Workspace *workspace = get_dynamic_workspace(models, hi_id);
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 result = false;
|
2018-09-04 00:37:54 +00:00
|
|
|
if (workspace != 0){
|
2019-03-28 03:06:17 +00:00
|
|
|
result = managed_object_free(workspace, object);
|
2018-09-04 00:37:54 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
return(result);
|
2018-09-04 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
// TODO(allen): ELIMINATE STORE & LOAD
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_store_data(Application_Links *app, Managed_Object object, u32 first_index, u32 count, void *mem)
|
2018-08-18 08:16:52 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
|
|
|
u8 *ptr = get_dynamic_object_memory_ptr(object_ptrs.header);
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 result = false;
|
2018-08-26 09:55:12 +00:00
|
|
|
if (ptr != 0){
|
2018-09-07 22:39:33 +00:00
|
|
|
u32 item_count = object_ptrs.header->count;
|
|
|
|
if (0 <= first_index && first_index + count <= item_count){
|
|
|
|
u32 item_size = object_ptrs.header->item_size;
|
2019-10-01 23:41:23 +00:00
|
|
|
block_copy(ptr + first_index*item_size, mem, count*item_size);
|
2019-09-04 05:31:35 +00:00
|
|
|
heap_assert_good(&object_ptrs.workspace->heap);
|
2019-02-26 19:59:57 +00:00
|
|
|
result = true;
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
2018-08-26 09:55:12 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
return(result);
|
2018-08-18 08:16:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
managed_object_load_data(Application_Links *app, Managed_Object object, u32 first_index, u32 count, void *mem_out)
|
2018-08-18 08:16:52 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-09-07 22:39:33 +00:00
|
|
|
Managed_Object_Ptr_And_Workspace object_ptrs = get_dynamic_object_ptrs(models, object);
|
|
|
|
u8 *ptr = get_dynamic_object_memory_ptr(object_ptrs.header);
|
2019-02-26 19:59:57 +00:00
|
|
|
b32 result = false;
|
2018-08-26 09:55:12 +00:00
|
|
|
if (ptr != 0){
|
2018-09-07 22:39:33 +00:00
|
|
|
u32 item_count = object_ptrs.header->count;
|
|
|
|
if (0 <= first_index && first_index + count <= item_count){
|
|
|
|
u32 item_size = object_ptrs.header->item_size;
|
2019-10-01 23:41:23 +00:00
|
|
|
block_copy(mem_out, ptr + first_index*item_size, count*item_size);
|
2019-09-04 05:31:35 +00:00
|
|
|
heap_assert_good(&object_ptrs.workspace->heap);
|
2019-02-26 19:59:57 +00:00
|
|
|
result = true;
|
2018-09-07 22:39:33 +00:00
|
|
|
}
|
2018-08-26 09:55:12 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
return(result);
|
2018-08-18 08:16:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function User_Input
|
2019-10-14 22:57:47 +00:00
|
|
|
get_next_input(Application_Links *app, Event_Property get_properties, Event_Property abort_properties)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
2018-11-20 08:18:54 +00:00
|
|
|
User_Input result = {};
|
2019-10-22 04:10:29 +00:00
|
|
|
if (tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
2019-10-25 23:33:50 +00:00
|
|
|
Co_Out *out = (Co_Out*)coroutine->out;
|
|
|
|
out->request = CoRequest_None;
|
|
|
|
out->get_flags = get_properties;
|
|
|
|
out->abort_flags = abort_properties;
|
|
|
|
coroutine_yield(coroutine);
|
|
|
|
Co_In *in = (Co_In*)coroutine->in;
|
|
|
|
result = in->user_input;
|
|
|
|
}
|
|
|
|
else{
|
2019-10-14 22:57:47 +00:00
|
|
|
#define M "ERROR: get_next_input called in a hook that may not make calls to blocking APIs"
|
2019-10-25 23:33:50 +00:00
|
|
|
print_message(app, string_u8_litexpr(M));
|
2019-10-14 22:57:47 +00:00
|
|
|
#undef M
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
api(custom) function i64
|
|
|
|
get_current_input_sequence_number(Application_Links *app)
|
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
return(models->current_input_sequence_number);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function User_Input
|
2019-10-14 22:57:47 +00:00
|
|
|
get_current_input(Application_Links *app)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-14 22:57:47 +00:00
|
|
|
return(models->current_input);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-14 22:57:47 +00:00
|
|
|
set_current_input(Application_Links *app, User_Input *input)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-14 22:57:47 +00:00
|
|
|
block_copy_struct(&models->current_input, input);
|
2018-10-06 15:26:20 +00:00
|
|
|
}
|
|
|
|
|
2019-10-10 20:15:47 +00:00
|
|
|
api(custom) function void
|
2019-10-14 22:57:47 +00:00
|
|
|
leave_current_input_unhandled(Application_Links *app){
|
2019-10-10 20:15:47 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-14 22:57:47 +00:00
|
|
|
models->current_input_unhandled = true;
|
2019-10-10 20:15:47 +00:00
|
|
|
}
|
|
|
|
|
2019-10-10 22:57:02 +00:00
|
|
|
api(custom) function void
|
|
|
|
set_custom_hook(Application_Links *app, Hook_ID hook_id, Void_Func *func_ptr){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
switch (hook_id){
|
|
|
|
case HookID_BufferViewerUpdate:
|
|
|
|
{
|
|
|
|
models->buffer_viewer_update = (Hook_Function*)func_ptr;
|
|
|
|
}break;
|
2019-10-15 03:26:00 +00:00
|
|
|
case HookID_DeltaRule:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-15 03:26:00 +00:00
|
|
|
models->delta_rule = (Delta_Rule_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-13 20:17:22 +00:00
|
|
|
case HookID_ViewEventHandler:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-13 20:17:22 +00:00
|
|
|
models->view_event_handler = (Custom_Command_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-11-05 06:25:19 +00:00
|
|
|
case HookID_Tick:
|
|
|
|
{
|
|
|
|
models->tick = (Tick_Function*)func_ptr;
|
|
|
|
}break;
|
2019-10-10 22:57:02 +00:00
|
|
|
case HookID_RenderCaller:
|
|
|
|
{
|
|
|
|
models->render_caller = (Render_Caller_Function*)func_ptr;
|
|
|
|
}break;
|
2020-03-04 01:37:55 +00:00
|
|
|
case HookID_WholeScreenRenderCaller:
|
|
|
|
{
|
|
|
|
models->whole_screen_render_caller = (Whole_Screen_Render_Caller_Function*)func_ptr;
|
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_BufferNameResolver:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->buffer_name_resolver = (Buffer_Name_Resolver_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_BeginBuffer:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->begin_buffer = (Buffer_Hook_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_EndBuffer:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->end_buffer = (Buffer_Hook_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_NewFile:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->new_file = (Buffer_Hook_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_SaveFile:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->save_file = (Buffer_Hook_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-14 22:57:47 +00:00
|
|
|
case HookID_BufferEditRange:
|
2019-10-10 22:57:02 +00:00
|
|
|
{
|
2019-10-14 22:57:47 +00:00
|
|
|
models->buffer_edit_range = (Buffer_Edit_Range_Function*)func_ptr;
|
2019-10-10 22:57:02 +00:00
|
|
|
}break;
|
2019-10-16 22:31:59 +00:00
|
|
|
case HookID_BufferRegion:
|
|
|
|
{
|
|
|
|
models->buffer_region = (Buffer_Region_Function*)func_ptr;
|
|
|
|
}break;
|
2019-10-29 04:27:20 +00:00
|
|
|
case HookID_Layout:
|
|
|
|
{
|
|
|
|
models->layout_func = (Layout_Function*)func_ptr;
|
|
|
|
}break;
|
2020-05-03 13:24:39 +00:00
|
|
|
case HookID_ViewChangeBuffer:
|
|
|
|
{
|
|
|
|
models->view_change_buffer = (View_Change_Buffer_Function*)func_ptr;
|
|
|
|
}break;
|
2019-10-10 22:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 21:04:57 +00:00
|
|
|
api(custom) function Void_Func*
|
|
|
|
get_custom_hook(Application_Links *app, Hook_ID hook_id){
|
|
|
|
Void_Func *result = 0;
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
switch (hook_id){
|
|
|
|
case HookID_BufferViewerUpdate:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->buffer_viewer_update;
|
|
|
|
}break;
|
|
|
|
case HookID_DeltaRule:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->delta_rule;
|
|
|
|
}break;
|
|
|
|
case HookID_ViewEventHandler:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->view_event_handler;
|
|
|
|
}break;
|
|
|
|
case HookID_Tick:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->tick;
|
|
|
|
}break;
|
|
|
|
case HookID_RenderCaller:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->render_caller;
|
|
|
|
}break;
|
|
|
|
case HookID_WholeScreenRenderCaller:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->whole_screen_render_caller;
|
|
|
|
}break;
|
|
|
|
case HookID_BufferNameResolver:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->buffer_name_resolver;
|
|
|
|
}break;
|
|
|
|
case HookID_BeginBuffer:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->begin_buffer;
|
|
|
|
}break;
|
|
|
|
case HookID_EndBuffer:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->end_buffer;
|
|
|
|
}break;
|
|
|
|
case HookID_NewFile:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->new_file;
|
|
|
|
}break;
|
|
|
|
case HookID_SaveFile:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->save_file;
|
|
|
|
}break;
|
|
|
|
case HookID_BufferEditRange:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->buffer_edit_range;
|
|
|
|
}break;
|
|
|
|
case HookID_BufferRegion:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->buffer_region;
|
|
|
|
}break;
|
|
|
|
case HookID_Layout:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->layout_func;
|
|
|
|
}break;
|
2020-05-03 13:24:39 +00:00
|
|
|
case HookID_ViewChangeBuffer:
|
|
|
|
{
|
|
|
|
result = (Void_Func*)models->view_change_buffer;
|
|
|
|
}break;
|
2020-05-01 21:04:57 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
api(custom) function b32
|
2019-12-18 03:38:08 +00:00
|
|
|
set_custom_hook_memory_size(Application_Links *app, Hook_ID hook_id, u64 size){
|
2019-10-15 03:26:00 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
b32 result = true;
|
|
|
|
switch (hook_id){
|
|
|
|
case HookID_DeltaRule:
|
|
|
|
{
|
|
|
|
models->delta_rule_memory_size = size;
|
|
|
|
}break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Mouse_State
|
2019-10-05 02:48:05 +00:00
|
|
|
get_mouse_state(Application_Links *app)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-11-20 04:18:57 +00:00
|
|
|
return(models->input->mouse);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
get_active_query_bars(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2019-01-25 21:03:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
2019-02-27 05:49:35 +00:00
|
|
|
b32 result = false;
|
2019-10-13 20:17:22 +00:00
|
|
|
if (api_check_view(view)){
|
2019-02-27 05:49:35 +00:00
|
|
|
i32 count = 0;
|
|
|
|
Query_Bar **ptrs = array_out->ptrs;
|
2019-02-10 09:18:34 +00:00
|
|
|
for (Query_Slot *slot = view->query_set.used_slot;
|
2019-02-27 05:49:35 +00:00
|
|
|
slot != 0 && (count < max_result_count);
|
2019-01-25 21:03:52 +00:00
|
|
|
slot = slot->next){
|
|
|
|
if (slot->query_bar != 0){
|
2019-02-27 05:49:35 +00:00
|
|
|
ptrs[count++] = slot->query_bar;
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-27 05:49:35 +00:00
|
|
|
array_out->count = count;
|
|
|
|
result = true;
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
start_query_bar(Application_Links *app, Query_Bar *bar, u32 flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *active_panel = layout_get_active_panel(&models->layout);
|
2018-11-18 19:47:28 +00:00
|
|
|
View *active_view = active_panel->view;
|
2019-02-10 09:18:34 +00:00
|
|
|
Query_Slot *slot = alloc_query_slot(&active_view->query_set);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = (slot != 0);
|
2018-03-24 10:06:45 +00:00
|
|
|
if (result){
|
|
|
|
slot->query_bar = bar;
|
|
|
|
}
|
2016-07-02 14:15:15 +00:00
|
|
|
return(result);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
end_query_bar(Application_Links *app, Query_Bar *bar, u32 flags)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Panel *active_panel = layout_get_active_panel(&models->layout);
|
2018-11-18 19:47:28 +00:00
|
|
|
View *active_view = active_panel->view;
|
2019-02-10 09:18:34 +00:00
|
|
|
free_query_slot(&active_view->query_set, bar);
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
api(custom) function void
|
|
|
|
clear_all_query_bars(Application_Links *app, View_ID view_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
View *view = imp_get_view(models, view_id);
|
|
|
|
if (api_check_view(view)){
|
|
|
|
free_all_queries(&view->query_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-08 02:53:01 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
print_message(Application_Links *app, String_Const_u8 message)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-05 09:13:38 +00:00
|
|
|
Editing_File *file = models->message_buffer;
|
|
|
|
if (file != 0){
|
2019-10-22 04:10:29 +00:00
|
|
|
output_file_append(app->tctx, models, file, message);
|
|
|
|
file_cursor_to_end(app->tctx, models, file);
|
2019-02-05 09:13:38 +00:00
|
|
|
}
|
2016-06-13 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
log_string(Application_Links *app, String_Const_u8 str){
|
2019-08-16 02:54:06 +00:00
|
|
|
return(log_string(str));
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Face_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_largest_face_id(Application_Links *app)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-07-24 07:41:40 +00:00
|
|
|
return(font_set_get_largest_id(&models->font_set));
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-12-08 02:53:01 +00:00
|
|
|
set_global_face(Application_Links *app, Face_ID id)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-12-08 02:53:01 +00:00
|
|
|
b32 result = false;
|
2019-07-24 07:41:40 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, id);
|
|
|
|
if (face != 0){
|
2020-01-15 18:14:17 +00:00
|
|
|
models->global_face_id = face->id;
|
2019-12-08 02:53:01 +00:00
|
|
|
result = true;
|
2016-07-14 16:41:23 +00:00
|
|
|
}
|
2019-12-08 02:53:01 +00:00
|
|
|
return(result);
|
2016-07-14 16:41:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function History_Record_Index
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_get_max_record_index(Application_Links *app, Buffer_ID buffer_id){
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-20 04:45:58 +00:00
|
|
|
History_Record_Index result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file) && history_is_activated(&file->state.history)){
|
2019-06-20 04:45:58 +00:00
|
|
|
result = history_get_record_count(&file->state.history);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:34:54 +00:00
|
|
|
function void
|
2019-02-08 12:33:43 +00:00
|
|
|
buffer_history__fill_record_info(Record *record, Record_Info *out){
|
|
|
|
out->kind = record->kind;
|
2020-05-03 15:00:28 +00:00
|
|
|
out->pos_before_edit = record->pos_before_edit;
|
2019-02-08 12:33:43 +00:00
|
|
|
out->edit_number = record->edit_number;
|
|
|
|
switch (out->kind){
|
|
|
|
case RecordKind_Single:
|
|
|
|
{
|
2019-12-16 06:56:13 +00:00
|
|
|
out->single_string_forward = record->single.forward_text ;
|
|
|
|
out->single_string_backward = record->single.backward_text;
|
|
|
|
out->single_first = record->single.first;
|
2019-02-08 12:33:43 +00:00
|
|
|
}break;
|
|
|
|
case RecordKind_Group:
|
|
|
|
{
|
2019-12-16 06:56:13 +00:00
|
|
|
out->group_count = record->group.count;
|
2019-02-08 12:33:43 +00:00
|
|
|
}break;
|
|
|
|
default:
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
InvalidPath;
|
2019-02-08 12:33:43 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Record_Info
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_get_record_info(Application_Links *app, Buffer_ID buffer_id, History_Record_Index index){
|
2019-02-08 12:33:43 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-20 04:45:58 +00:00
|
|
|
Record_Info result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-02-08 12:33:43 +00:00
|
|
|
History *history = &file->state.history;
|
|
|
|
if (history_is_activated(history)){
|
|
|
|
i32 max_index = history_get_record_count(history);
|
|
|
|
if (0 <= index && index <= max_index){
|
|
|
|
if (0 < index){
|
|
|
|
Record *record = history_get_record(history, index);
|
2019-06-20 04:45:58 +00:00
|
|
|
buffer_history__fill_record_info(record, &result);
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_InitialStateDummyRecord;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_IndexOutOfBounds;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_NoHistoryAttached;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_InvalidBuffer;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Record_Info
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_get_group_sub_record(Application_Links *app, Buffer_ID buffer_id, History_Record_Index index, i32 sub_index){
|
2019-02-08 12:33:43 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-20 04:45:58 +00:00
|
|
|
Record_Info result = {};
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-02-08 12:33:43 +00:00
|
|
|
History *history = &file->state.history;
|
|
|
|
if (history_is_activated(history)){
|
|
|
|
i32 max_index = history_get_record_count(history);
|
|
|
|
if (0 <= index && index <= max_index){
|
|
|
|
if (0 < index){
|
|
|
|
Record *record = history_get_record(history, index);
|
|
|
|
if (record->kind == RecordKind_Group){
|
2019-06-01 23:58:28 +00:00
|
|
|
record = history_get_sub_record(record, sub_index + 1);
|
|
|
|
if (record != 0){
|
2019-06-20 04:45:58 +00:00
|
|
|
buffer_history__fill_record_info(record, &result);
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_SubIndexOutOfBounds;
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_WrongRecordTypeAtIndex;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_InitialStateDummyRecord;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_IndexOutOfBounds;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_NoHistoryAttached;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-06-20 04:45:58 +00:00
|
|
|
result.error = RecordError_InvalidBuffer;
|
2019-02-08 12:33:43 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function History_Record_Index
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_get_current_state_index(Application_Links *app, Buffer_ID buffer_id){
|
2019-02-08 10:03:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-06-20 04:45:58 +00:00
|
|
|
History_Record_Index result = 0;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file) && history_is_activated(&file->state.history)){
|
2019-06-20 04:45:58 +00:00
|
|
|
result = file_get_current_record_index(file);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
2019-03-21 03:18:08 +00:00
|
|
|
return(result);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_set_current_state_index(Application_Links *app, Buffer_ID buffer_id, History_Record_Index index){
|
2019-02-08 10:03:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file) && history_is_activated(&file->state.history)){
|
2019-02-08 10:03:48 +00:00
|
|
|
i32 max_index = history_get_record_count(&file->state.history);
|
|
|
|
if (0 <= index && index <= max_index){
|
2019-10-22 04:10:29 +00:00
|
|
|
edit_change_current_history_state(app->tctx, models, file, index);
|
2019-02-08 10:03:48 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_merge_record_range(Application_Links *app, Buffer_ID buffer_id, History_Record_Index first_index, History_Record_Index last_index, Record_Merge_Flag flags){
|
2019-02-08 11:18:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-06-17 20:05:14 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-10-22 04:10:29 +00:00
|
|
|
result = edit_merge_history_range(app->tctx, models, file, first_index, last_index, flags);
|
2019-02-08 11:18:48 +00:00
|
|
|
}
|
2019-02-08 10:03:48 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_history_clear_after_current_state(Application_Links *app, Buffer_ID buffer_id){
|
2019-02-08 11:18:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-02-13 22:14:27 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file) && history_is_activated(&file->state.history)){
|
2019-02-08 11:18:48 +00:00
|
|
|
history_dump_records_after_index(&file->state.history, file->state.current_record_index);
|
|
|
|
result = true;
|
|
|
|
}
|
2019-02-08 10:03:48 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
global_history_edit_group_begin(Application_Links *app){
|
2019-02-08 11:18:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
global_history_adjust_edit_grouping_counter(&models->global_history, 1);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
global_history_edit_group_end(Application_Links *app){
|
2019-02-08 11:18:48 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
global_history_adjust_edit_grouping_counter(&models->global_history, -1);
|
2019-02-08 10:03:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
buffer_set_face(Application_Links *app, Buffer_ID buffer_id, Face_ID id)
|
2019-02-13 22:14:27 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 did_change = false;
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, id);
|
|
|
|
if (face != 0){
|
|
|
|
file->settings.face_id = face->id;
|
2019-07-21 18:16:34 +00:00
|
|
|
did_change = true;
|
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
|
|
|
return(did_change);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Face_Description
|
2019-10-05 02:48:05 +00:00
|
|
|
get_face_description(Application_Links *app, Face_ID face_id)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-11-20 08:18:54 +00:00
|
|
|
Face_Description description = {};
|
2019-07-24 07:41:40 +00:00
|
|
|
if (face_id != 0){
|
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
2019-07-21 18:16:34 +00:00
|
|
|
if (face != 0){
|
2019-07-24 07:41:40 +00:00
|
|
|
description = face->description;
|
2019-07-21 18:16:34 +00:00
|
|
|
}
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-07-24 07:41:40 +00:00
|
|
|
description.parameters.pt_size = models->settings.font_size;
|
|
|
|
description.parameters.hinting = models->settings.use_hinting;
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
return(description);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Face_Metrics
|
2019-10-05 02:48:05 +00:00
|
|
|
get_face_metrics(Application_Links *app, Face_ID face_id){
|
2019-03-31 21:30:06 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_Metrics result = {};
|
2019-03-31 21:30:06 +00:00
|
|
|
if (face_id != 0){
|
2019-07-24 07:41:40 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
2019-07-21 18:16:34 +00:00
|
|
|
if (face != 0){
|
2019-10-29 04:27:20 +00:00
|
|
|
result = face->metrics;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function Face_Advance_Map
|
|
|
|
get_face_advance_map(Application_Links *app, Face_ID face_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Face_Advance_Map result = {};
|
|
|
|
if (face_id != 0){
|
|
|
|
Face *face = font_set_face_from_id(&models->font_set, face_id);
|
|
|
|
if (face != 0){
|
|
|
|
result = face->advance_map;
|
2019-07-21 18:16:34 +00:00
|
|
|
}
|
2019-03-31 21:30:06 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Face_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
get_face_id(Application_Links *app, Buffer_ID buffer_id)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID result = 0;
|
2019-02-13 22:14:27 +00:00
|
|
|
if (buffer_id != 0){
|
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-04-05 23:30:24 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 21:32:52 +00:00
|
|
|
result = file->settings.face_id;
|
2016-10-25 02:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-20 23:31:57 +00:00
|
|
|
else{
|
2019-09-02 21:32:52 +00:00
|
|
|
result = models->global_face_id;
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
return(result);
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Face_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
try_create_new_face(Application_Links *app, Face_Description *description)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
2019-07-26 00:18:05 +00:00
|
|
|
Face_ID result = 0;
|
2019-10-22 04:10:29 +00:00
|
|
|
if (tctx_info != 0 && tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
2019-07-26 00:18:05 +00:00
|
|
|
Assert(coroutine != 0);
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_Out *out = (Co_Out*)coroutine->out;
|
|
|
|
out->request = CoRequest_NewFontFace;
|
2019-10-13 17:36:29 +00:00
|
|
|
out->face_description = description;
|
2019-08-04 05:36:13 +00:00
|
|
|
coroutine_yield(coroutine);
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_In *in = (Co_In*)coroutine->in;
|
2019-10-13 17:36:29 +00:00
|
|
|
result = in->face_id;
|
2019-07-26 00:18:05 +00:00
|
|
|
}
|
2019-10-22 04:10:29 +00:00
|
|
|
else if (tctx_info != 0){
|
|
|
|
// This API does nothing when called from an async thread.
|
|
|
|
}
|
2019-07-26 00:18:05 +00:00
|
|
|
else{
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *new_face = font_set_new_face(&models->font_set, description);
|
2019-11-08 06:38:51 +00:00
|
|
|
if (new_face != 0){
|
|
|
|
result = new_face->id;
|
|
|
|
}
|
2019-07-26 00:18:05 +00:00
|
|
|
}
|
|
|
|
return(result);
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
try_modify_face(Application_Links *app, Face_ID id, Face_Description *description)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
2019-07-26 00:18:05 +00:00
|
|
|
b32 result = false;
|
2019-10-22 04:10:29 +00:00
|
|
|
if (tctx_info != 0 && tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
2019-07-26 00:18:05 +00:00
|
|
|
Assert(coroutine != 0);
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_Out *out = (Co_Out*)coroutine->out;
|
2019-10-15 22:30:06 +00:00
|
|
|
out->request = CoRequest_ModifyFace;
|
2019-10-13 17:36:29 +00:00
|
|
|
out->face_description = description;
|
|
|
|
out->face_id = id;
|
2019-08-04 05:36:13 +00:00
|
|
|
coroutine_yield(coroutine);
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_In *in = (Co_In*)coroutine->in;
|
2019-10-13 17:36:29 +00:00
|
|
|
result = in->success;
|
2019-07-26 00:18:05 +00:00
|
|
|
}
|
2019-10-22 04:10:29 +00:00
|
|
|
else if (tctx_info != 0){
|
|
|
|
// This API does nothing when called from an async thread.
|
|
|
|
}
|
2019-07-26 00:18:05 +00:00
|
|
|
else{
|
2019-09-02 18:59:36 +00:00
|
|
|
result = font_set_modify_face(&models->font_set, id, description);
|
2019-07-26 00:18:05 +00:00
|
|
|
}
|
|
|
|
return(result);
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
try_release_face(Application_Links *app, Face_ID id, Face_ID replacement_id)
|
2017-11-20 23:31:57 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 21:32:52 +00:00
|
|
|
Font_Set *font_set = &models->font_set;
|
|
|
|
Face *face = font_set_face_from_id(font_set, id);
|
|
|
|
Face *replacement = font_set_face_from_id(font_set, replacement_id);
|
2019-10-03 17:57:44 +00:00
|
|
|
return(release_font_and_update(models, face, replacement));
|
2017-11-20 23:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Const_u8
|
2019-10-05 02:48:05 +00:00
|
|
|
push_hot_directory(Application_Links *app, Arena *arena)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Hot_Directory *hot = &models->hot_directory;
|
2016-06-27 15:52:58 +00:00
|
|
|
hot_directory_clean_end(hot);
|
2019-08-04 00:49:40 +00:00
|
|
|
return(push_string_copy(arena, hot->string));
|
2016-06-27 15:52:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 18:46:12 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
set_hot_directory(Application_Links *app, String_Const_u8 string)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Hot_Directory *hot = &models->hot_directory;
|
2019-10-03 17:57:44 +00:00
|
|
|
hot_directory_set(hot, string);
|
2017-06-20 20:37:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
send_exit_signal(Application_Links *app)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2018-08-05 07:09:18 +00:00
|
|
|
models->keep_playing = false;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 22:37:01 +00:00
|
|
|
api(custom) function void
|
|
|
|
hard_exit(Application_Links *app)
|
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
models->hard_exit = true;
|
|
|
|
}
|
|
|
|
|
2019-12-10 18:46:12 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
set_window_title(Application_Links *app, String_Const_u8 title)
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
2018-11-18 19:47:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2017-11-30 19:02:37 +00:00
|
|
|
models->has_new_title = true;
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 cap_before_null = (u64)(models->title_capacity - 1);
|
|
|
|
u64 copy_size = clamp_top(title.size, cap_before_null);
|
2019-06-01 23:58:28 +00:00
|
|
|
block_copy(models->title_space, title.str, copy_size);
|
|
|
|
models->title_space[copy_size] = 0;
|
2017-11-30 16:39:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 10:22:35 +00:00
|
|
|
api(custom) function void
|
|
|
|
acquire_global_frame_mutex(Application_Links *app){
|
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
|
|
|
if (tctx_info != 0 && tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
|
|
|
Assert(coroutine != 0);
|
|
|
|
Co_Out *out = (Co_Out*)coroutine->out;
|
|
|
|
out->request = CoRequest_AcquireGlobalFrameMutex;
|
|
|
|
coroutine_yield(coroutine);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
system_acquire_global_frame_mutex(tctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function void
|
|
|
|
release_global_frame_mutex(Application_Links *app){
|
|
|
|
Thread_Context *tctx = app->tctx;
|
|
|
|
Thread_Context_Extra_Info *tctx_info = (Thread_Context_Extra_Info*)tctx->user_data;
|
|
|
|
if (tctx_info != 0 && tctx_info->coroutine != 0){
|
|
|
|
Coroutine *coroutine = (Coroutine*)tctx_info->coroutine;
|
|
|
|
Assert(coroutine != 0);
|
|
|
|
Co_Out *out = (Co_Out*)coroutine->out;
|
|
|
|
out->request = CoRequest_ReleaseGlobalFrameMutex;
|
|
|
|
coroutine_yield(coroutine);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
system_release_global_frame_mutex(tctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-23 01:25:40 +00:00
|
|
|
api(custom) function Vec2_f32
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_string_oriented(Application_Links *app, Face_ID font_id, ARGB_Color color,
|
2019-10-23 01:25:40 +00:00
|
|
|
String_Const_u8 str, Vec2_f32 point, u32 flags, Vec2_f32 delta)
|
2019-01-25 21:03:52 +00:00
|
|
|
{
|
2019-10-23 01:25:40 +00:00
|
|
|
Vec2_f32 result = point;
|
2019-01-25 21:03:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-07-25 19:54:58 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, font_id);
|
2019-03-31 18:55:26 +00:00
|
|
|
if (models->target == 0){
|
2019-07-25 19:54:58 +00:00
|
|
|
f32 width = font_string_width(models->target, face, str);
|
2019-03-15 08:38:28 +00:00
|
|
|
result += delta*width;
|
2019-01-26 01:12:25 +00:00
|
|
|
}
|
2019-02-24 22:54:57 +00:00
|
|
|
else{
|
2019-11-26 06:09:31 +00:00
|
|
|
f32 width = draw_string(models->target, face, str, point, color, flags, delta);
|
2019-03-15 08:38:28 +00:00
|
|
|
result += delta*width;
|
2019-02-24 22:54:57 +00:00
|
|
|
}
|
|
|
|
return(result);
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function f32
|
2019-10-05 02:48:05 +00:00
|
|
|
get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str)
|
2019-01-25 21:03:52 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-07-25 19:54:58 +00:00
|
|
|
Face *face = font_set_face_from_id(&models->font_set, font_id);
|
|
|
|
return(font_string_width(models->target, face, str));
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_rectangle(Application_Links *app, Rect_f32 rect, f32 roundness, ARGB_Color color){
|
2019-01-25 21:03:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-03-31 18:55:26 +00:00
|
|
|
if (models->in_render_mode){
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_rectangle(models->target, rect, roundness, color);
|
2019-01-26 01:12:25 +00:00
|
|
|
}
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_rectangle_outline(Application_Links *app, Rect_f32 rect, f32 roundness, f32 thickness, ARGB_Color color){
|
2019-01-25 21:03:52 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-03-31 18:55:26 +00:00
|
|
|
if (models->in_render_mode){
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_rectangle_outline(models->target, rect, roundness, thickness, color);
|
2019-01-26 01:12:25 +00:00
|
|
|
}
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-06 06:59:35 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-10-08 17:18:20 +00:00
|
|
|
draw_set_clip(Application_Links *app, Rect_f32 new_clip){
|
2019-03-15 08:38:28 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-08 17:18:20 +00:00
|
|
|
return(draw_set_clip(models->target, new_clip));
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Text_Layout_ID
|
2019-10-05 02:48:05 +00:00
|
|
|
text_layout_create(Application_Links *app, Buffer_ID buffer_id, Rect_f32 rect, Buffer_Point buffer_point){
|
2019-04-01 00:36:09 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer_id);
|
2019-12-24 00:46:58 +00:00
|
|
|
Text_Layout_ID result = 0;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-10-22 04:10:29 +00:00
|
|
|
Thread_Context *tctx = app->tctx;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
|
|
|
|
Gap_Buffer *buffer = &file->state.buffer;
|
|
|
|
|
2019-10-31 21:42:11 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
Vec2_f32 dim = rect_dim(rect);
|
|
|
|
|
|
|
|
i64 line_count = buffer_line_count(buffer);
|
|
|
|
i64 line_number = buffer_point.line_number;
|
|
|
|
f32 y = -buffer_point.pixel_shift.y;
|
|
|
|
for (;line_number <= line_count;
|
|
|
|
line_number += 1){
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Item_List line = file_get_line_layout(tctx, models, file,
|
|
|
|
layout_func, dim.x, face,
|
|
|
|
line_number);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 next_y = y + line.height;
|
|
|
|
if (next_y >= dim.y){
|
|
|
|
break;
|
2019-04-01 00:36:09 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
y = next_y;
|
2019-04-01 06:14:31 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
|
2019-12-18 03:38:08 +00:00
|
|
|
Range_i64 visible_line_number_range = Ii64(buffer_point.line_number, line_number);
|
|
|
|
Range_i64 visible_range = Ii64(buffer_get_first_pos_from_line_number(buffer, visible_line_number_range.min),
|
2020-01-15 18:14:17 +00:00
|
|
|
buffer_get_last_pos_from_line_number(buffer, visible_line_number_range.max));
|
2019-09-02 18:59:36 +00:00
|
|
|
|
|
|
|
i64 item_count = range_size_inclusive(visible_range);
|
2020-03-11 23:22:37 +00:00
|
|
|
|
|
|
|
Arena arena = make_arena_system();
|
|
|
|
Arena *arena_ptr = push_array_zero(&arena, Arena, 1);
|
|
|
|
*arena_ptr = arena;
|
|
|
|
ARGB_Color *colors_array = push_array_zero(arena_ptr, ARGB_Color, item_count);
|
|
|
|
result = text_layout_new(&models->text_layouts, arena_ptr, buffer_id, buffer_point,
|
2019-10-29 04:27:20 +00:00
|
|
|
visible_range, visible_line_number_range, rect, colors_array,
|
|
|
|
layout_func);
|
2019-04-01 06:14:31 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-06 06:59:35 +00:00
|
|
|
api(custom) function Rect_f32
|
|
|
|
text_layout_region(Application_Links *app, Text_Layout_ID text_layout_id){
|
2019-04-01 06:14:31 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-06 06:59:35 +00:00
|
|
|
Rect_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, text_layout_id);
|
|
|
|
if (layout != 0){
|
2019-10-06 06:59:35 +00:00
|
|
|
result = layout->rect;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
api(custom) function Buffer_ID
|
|
|
|
text_layout_get_buffer(Application_Links *app, Text_Layout_ID text_layout_id){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Buffer_ID result = 0;
|
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, text_layout_id);
|
|
|
|
if (layout != 0){
|
|
|
|
result = layout->buffer_id;
|
2019-04-01 00:36:09 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-11-01 03:46:53 +00:00
|
|
|
api(custom) function Range_i64
|
2019-10-05 02:48:05 +00:00
|
|
|
text_layout_get_visible_range(Application_Links *app, Text_Layout_ID text_layout_id){
|
2019-04-01 06:40:24 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, text_layout_id);
|
|
|
|
if (layout != 0){
|
|
|
|
result = layout->visible_range;
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-06 06:59:35 +00:00
|
|
|
api(custom) function Range_f32
|
2019-10-05 02:48:05 +00:00
|
|
|
text_layout_line_on_screen(Application_Links *app, Text_Layout_ID layout_id, i64 line_number){
|
2019-08-01 02:13:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-06 06:59:35 +00:00
|
|
|
Range_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id);
|
2019-10-06 06:59:35 +00:00
|
|
|
if (layout == 0){
|
|
|
|
return(result);
|
|
|
|
}
|
2019-10-29 04:27:20 +00:00
|
|
|
|
|
|
|
Layout_Function *layout_func = layout->layout_func;
|
|
|
|
|
2019-10-06 06:59:35 +00:00
|
|
|
Rect_f32 rect = layout->rect;
|
|
|
|
if (range_contains_inclusive(layout->visible_line_number_range, line_number)){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = imp_get_file(models, layout->buffer_id);
|
2019-08-01 02:13:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = rect_width(rect);
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-08-01 02:13:36 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
for (i64 line_number_it = layout->visible_line_number_range.first;;
|
|
|
|
line_number_it += 1){
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Item_List line = file_get_line_layout(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
line_number_it);
|
2019-10-06 06:59:35 +00:00
|
|
|
result.max += line.height;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (line_number_it == line_number){
|
|
|
|
break;
|
|
|
|
}
|
2019-10-06 06:59:35 +00:00
|
|
|
result.min = result.max;
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
2019-10-06 08:01:52 +00:00
|
|
|
result += rect.y0 - layout->point.pixel_shift.y;
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
2019-04-01 06:40:24 +00:00
|
|
|
}
|
2019-10-06 06:59:35 +00:00
|
|
|
else if (line_number < layout->visible_line_number_range.min){
|
|
|
|
result = If32(rect.y0, rect.y0);
|
|
|
|
}
|
|
|
|
else if (line_number > layout->visible_line_number_range.max){
|
|
|
|
result = If32(rect.y1, rect.y1);
|
|
|
|
}
|
2019-10-29 04:27:20 +00:00
|
|
|
|
2019-04-01 06:40:24 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function Rect_f32
|
2019-10-05 02:48:05 +00:00
|
|
|
text_layout_character_on_screen(Application_Links *app, Text_Layout_ID layout_id, i64 pos){
|
2019-08-01 02:13:36 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Rect_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id);
|
|
|
|
if (layout != 0 && range_contains_inclusive(layout->visible_range, pos)){
|
|
|
|
Editing_File *file = imp_get_file(models, layout->buffer_id);
|
2019-08-01 02:13:36 +00:00
|
|
|
if (api_check_buffer(file)){
|
2019-09-02 18:59:36 +00:00
|
|
|
Gap_Buffer *buffer = &file->state.buffer;
|
|
|
|
i64 line_number = buffer_get_line_index(buffer, pos) + 1;
|
2019-08-01 02:13:36 +00:00
|
|
|
|
2019-10-09 17:21:51 +00:00
|
|
|
if (range_contains_inclusive(layout->visible_line_number_range, line_number)){
|
|
|
|
Rect_f32 rect = layout->rect;
|
|
|
|
f32 width = rect_width(rect);
|
|
|
|
Face *face = file_get_face(models, file);
|
|
|
|
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Function *layout_func = layout->layout_func;
|
|
|
|
|
2019-10-09 17:21:51 +00:00
|
|
|
f32 y = 0.f;
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Item_List line = {};
|
2019-10-09 17:21:51 +00:00
|
|
|
for (i64 line_number_it = layout->visible_line_number_range.first;;
|
|
|
|
line_number_it += 1){
|
2019-10-29 04:27:20 +00:00
|
|
|
line = file_get_line_layout(app->tctx, models, file,
|
|
|
|
layout_func, width, face,
|
|
|
|
line_number_it);
|
2019-10-09 17:21:51 +00:00
|
|
|
if (line_number_it == line_number){
|
2019-09-02 18:59:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-10-09 17:21:51 +00:00
|
|
|
y += line.height;
|
|
|
|
}
|
|
|
|
|
2019-12-24 00:46:58 +00:00
|
|
|
// TODO(allen): optimization: This is some fairly heavy computation. We really
|
2019-10-09 17:21:51 +00:00
|
|
|
// need to accelerate the (pos -> item) lookup within a single
|
|
|
|
// Buffer_Layout_Item_List.
|
|
|
|
b32 is_first_item = true;
|
|
|
|
result = Rf32_negative_infinity;
|
2019-10-29 04:27:20 +00:00
|
|
|
for (Layout_Item_Block *block = line.first;
|
2019-10-09 17:21:51 +00:00
|
|
|
block != 0;
|
|
|
|
block = block->next){
|
2019-11-04 00:03:23 +00:00
|
|
|
i64 count = block->item_count;
|
2019-10-29 04:27:20 +00:00
|
|
|
Layout_Item *item_ptr = block->items;
|
2019-10-09 17:21:51 +00:00
|
|
|
for (i32 i = 0; i < count; i += 1, item_ptr += 1){
|
2019-11-04 00:03:23 +00:00
|
|
|
if (HasFlag(item_ptr->flags, LayoutItemFlag_Ghost_Character)){
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-09 17:21:51 +00:00
|
|
|
i64 index = item_ptr->index;
|
|
|
|
if (index == pos){
|
|
|
|
result = rect_union(result, item_ptr->rect);
|
|
|
|
}
|
|
|
|
else if (index > pos){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
2019-10-09 17:21:51 +00:00
|
|
|
|
|
|
|
Vec2_f32 shift = V2f32(rect.x0, rect.y0 + y) - layout->point.pixel_shift;
|
|
|
|
result.p0 += shift;
|
|
|
|
result.p1 += shift;
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-12-18 03:38:08 +00:00
|
|
|
paint_text_color(Application_Links *app, Text_Layout_ID layout_id, Range_i64 range, ARGB_Color color){
|
2019-08-01 03:16:53 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Rect_f32 result = {};
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id);
|
|
|
|
if (layout != 0){
|
|
|
|
range.min = clamp_bot(layout->visible_range.min, range.min);
|
|
|
|
range.max = clamp_top(range.max, layout->visible_range.max);
|
|
|
|
range.min -= layout->visible_range.min;
|
|
|
|
range.max -= layout->visible_range.min;
|
2020-01-15 18:14:17 +00:00
|
|
|
ARGB_Color *color_ptr = layout->item_colors + range.min;
|
2019-09-02 18:59:36 +00:00
|
|
|
for (i64 i = range.min; i < range.max; i += 1, color_ptr += 1){
|
|
|
|
*color_ptr = color;
|
2019-08-01 03:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-01 02:13:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 18:14:17 +00:00
|
|
|
api(custom) function void
|
|
|
|
paint_text_color_blend(Application_Links *app, Text_Layout_ID layout_id, Range_i64 range, ARGB_Color color, f32 blend){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
Rect_f32 result = {};
|
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id);
|
|
|
|
if (layout != 0){
|
|
|
|
range.min = clamp_bot(layout->visible_range.min, range.min);
|
|
|
|
range.max = clamp_top(range.max, layout->visible_range.max);
|
|
|
|
range.min -= layout->visible_range.min;
|
|
|
|
range.max -= layout->visible_range.min;
|
|
|
|
Vec4_f32 color_v4f32 = unpack_color(color);
|
|
|
|
Vec4_f32 color_pm_v4f32 = color_v4f32*blend;
|
|
|
|
f32 neg_blend = 1.f - blend;
|
|
|
|
ARGB_Color *color_ptr = layout->item_colors + range.min;
|
|
|
|
for (i64 i = range.min; i < range.max; i += 1, color_ptr += 1){
|
|
|
|
Vec4_f32 color_ptr_v4f32 = unpack_color(*color_ptr);
|
|
|
|
Vec4_f32 blended_v4f32 = color_ptr_v4f32*neg_blend + color_pm_v4f32;
|
|
|
|
*color_ptr = pack_color(blended_v4f32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function b32
|
2019-10-05 02:48:05 +00:00
|
|
|
text_layout_free(Application_Links *app, Text_Layout_ID text_layout_id){
|
2019-04-01 00:36:09 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(text_layout_erase(app->tctx, models, &models->text_layouts, text_layout_id));
|
2019-04-01 00:36:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-11-26 06:09:31 +00:00
|
|
|
draw_text_layout(Application_Links *app, Text_Layout_ID layout_id, ARGB_Color special_color, ARGB_Color ghost_color){
|
2019-03-31 18:55:26 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-09-02 18:59:36 +00:00
|
|
|
Text_Layout *layout = text_layout_get(&models->text_layouts, layout_id);
|
|
|
|
if (layout != 0 && models->target != 0){
|
2019-11-26 06:09:31 +00:00
|
|
|
text_layout_render(app->tctx, models, layout, special_color, ghost_color);
|
2019-03-31 18:55:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
open_color_picker(Application_Links *app, Color_Picker *picker)
|
2019-02-24 07:22:16 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-10-08 01:42:23 +00:00
|
|
|
if (picker->finished != 0){
|
2019-02-24 07:22:16 +00:00
|
|
|
*picker->finished = false;
|
|
|
|
}
|
2019-10-03 17:57:44 +00:00
|
|
|
system_open_color_picker(picker);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function void
|
2019-10-05 02:48:05 +00:00
|
|
|
animate_in_n_milliseconds(Application_Links *app, u32 n)
|
2019-02-24 07:22:16 +00:00
|
|
|
{
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-03-30 21:51:56 +00:00
|
|
|
if (n == 0){
|
|
|
|
models->animate_next_frame = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
models->next_animate_delay = Min(models->next_animate_delay, n);
|
|
|
|
}
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 21:49:05 +00:00
|
|
|
api(custom) function String_Match_List
|
2019-10-18 03:18:15 +00:00
|
|
|
buffer_find_all_matches(Application_Links *app, Arena *arena, Buffer_ID buffer,
|
|
|
|
i32 string_id, Range_i64 range, String_Const_u8 needle,
|
|
|
|
Character_Predicate *predicate, Scan_Direction direction){
|
2019-02-24 07:22:16 +00:00
|
|
|
Models *models = (Models*)app->cmd_context;
|
2019-06-16 23:38:22 +00:00
|
|
|
Editing_File *file = imp_get_file(models, buffer);
|
|
|
|
String_Match_List list = {};
|
|
|
|
if (api_check_buffer(file)){
|
|
|
|
if (needle.size > 0){
|
2020-03-12 03:35:52 +00:00
|
|
|
Scratch_Block scratch(app, arena);
|
2020-03-12 03:59:44 +00:00
|
|
|
List_String_Const_u8 chunks = buffer_get_chunks(scratch, &file->state.buffer);
|
2019-09-02 18:59:36 +00:00
|
|
|
buffer_chunks_clamp(&chunks, range);
|
|
|
|
if (chunks.node_count > 0){
|
2020-03-12 03:59:44 +00:00
|
|
|
u64_Array jump_table = string_compute_needle_jump_table(arena, needle, direction);
|
2019-06-16 23:38:22 +00:00
|
|
|
Character_Predicate dummy = {};
|
|
|
|
if (predicate == 0){
|
|
|
|
predicate = &dummy;
|
|
|
|
}
|
|
|
|
list = find_all_matches(arena, max_i32,
|
2019-10-18 03:18:15 +00:00
|
|
|
chunks, needle, jump_table, predicate,
|
|
|
|
direction, range.min, buffer, string_id);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-16 23:38:22 +00:00
|
|
|
return(list);
|
2019-02-24 07:22:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 20:48:50 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
api(custom) function Profile_Global_List*
|
|
|
|
get_core_profile_list(Application_Links *app){
|
|
|
|
Models *models = (Models*)app->cmd_context;
|
|
|
|
return(&models->profile_list);
|
|
|
|
}
|
|
|
|
|
2019-12-10 18:46:12 +00:00
|
|
|
api(custom) function Doc_Cluster*
|
|
|
|
get_custom_layer_boundary_docs(Application_Links *app, Arena *arena){
|
2019-12-13 00:03:21 +00:00
|
|
|
API_Definition *api_def = custom_api_construct(arena);
|
2019-12-10 18:46:12 +00:00
|
|
|
return(doc_custom_api(arena, api_def));
|
|
|
|
}
|
|
|
|
|
2019-01-25 21:03:52 +00:00
|
|
|
// BOTTOM
|