2017-07-17 23:35:13 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
2018-03-24 10:06:45 +00:00
|
|
|
* 19.08.2015
|
2017-07-17 23:35:13 +00:00
|
|
|
*
|
2018-03-24 21:43:57 +00:00
|
|
|
* Viewing
|
2017-07-17 23:35:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
function void
|
|
|
|
begin_handling_input(Models *models, User_Input *input){
|
|
|
|
block_copy_struct(&models->current_input, input);
|
|
|
|
models->current_input_sequence_number += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
internal void
|
|
|
|
init_query_set(Query_Set *set){
|
|
|
|
Query_Slot *slot = set->slots;
|
|
|
|
set->free_slot = slot;
|
|
|
|
set->used_slot = 0;
|
|
|
|
for (i32 i = 0; i+1 < ArrayCount(set->slots); ++i, ++slot){
|
|
|
|
slot->next = slot + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Query_Slot*
|
|
|
|
alloc_query_slot(Query_Set *set){
|
|
|
|
Query_Slot *slot = set->free_slot;
|
|
|
|
if (slot != 0){
|
|
|
|
set->free_slot = slot->next;
|
|
|
|
slot->next = set->used_slot;
|
|
|
|
set->used_slot = slot;
|
|
|
|
}
|
|
|
|
return(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
free_query_slot(Query_Set *set, Query_Bar *match_bar){
|
|
|
|
Query_Slot *slot = 0;
|
|
|
|
Query_Slot *prev = 0;
|
|
|
|
|
|
|
|
for (slot = set->used_slot; slot != 0; slot = slot->next){
|
|
|
|
if (slot->query_bar == match_bar) break;
|
|
|
|
prev = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slot){
|
|
|
|
if (prev){
|
|
|
|
prev->next = slot->next;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
set->used_slot = slot->next;
|
|
|
|
}
|
|
|
|
slot->next = set->free_slot;
|
|
|
|
set->free_slot = slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function void
|
|
|
|
free_all_queries(Query_Set *set){
|
|
|
|
for (;set->used_slot != 0;){
|
|
|
|
Query_Slot *slot = set->used_slot;
|
|
|
|
set->used_slot = slot->next;
|
|
|
|
slot->next = set->free_slot;
|
|
|
|
set->free_slot = slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-18 02:54:02 +00:00
|
|
|
internal Access_Flag
|
2019-02-13 22:14:27 +00:00
|
|
|
view_get_access_flags(View *view){
|
2019-10-18 02:54:02 +00:00
|
|
|
Access_Flag result = file_get_access_flags(view->file);
|
2019-10-14 02:13:15 +00:00
|
|
|
View_Context_Node *node = view->ctx;
|
2019-10-18 02:54:02 +00:00
|
|
|
b32 hides_buffer = (node != 0 && node->ctx.hides_buffer);
|
|
|
|
if (hides_buffer){
|
|
|
|
RemFlag(result, Access_Visible);
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-02-10 09:18:34 +00:00
|
|
|
internal i32
|
|
|
|
view_get_index(Live_Views *live_set, View *view){
|
|
|
|
return((i32)(view - live_set->views));
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal View_ID
|
2019-02-10 09:18:34 +00:00
|
|
|
view_get_id(Live_Views *live_set, View *view){
|
2019-09-02 18:59:36 +00:00
|
|
|
return((View_ID)(view - live_set->views) + 1);
|
2019-02-10 09:18:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 09:13:38 +00:00
|
|
|
internal View*
|
2019-09-04 05:31:35 +00:00
|
|
|
live_set_alloc_view(Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, Panel *panel){
|
2018-03-26 05:19:08 +00:00
|
|
|
Assert(live_set->count < live_set->max);
|
|
|
|
++live_set->count;
|
|
|
|
|
2019-02-10 09:18:34 +00:00
|
|
|
View *result = live_set->free_sentinel.next;
|
2019-02-27 05:49:35 +00:00
|
|
|
dll_remove(result);
|
2019-02-10 09:18:34 +00:00
|
|
|
block_zero_struct(result);
|
2018-03-26 05:19:08 +00:00
|
|
|
|
2019-02-10 09:18:34 +00:00
|
|
|
result->in_use = true;
|
|
|
|
init_query_set(&result->query_set);
|
2019-09-04 05:31:35 +00:00
|
|
|
result->lifetime_object = lifetime_alloc_object(lifetime_allocator, DynamicWorkspace_View, result);
|
2019-02-27 05:49:35 +00:00
|
|
|
panel->view = result;
|
|
|
|
result->panel = panel;
|
2018-06-23 03:03:58 +00:00
|
|
|
|
2018-03-26 05:19:08 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-01-31 13:06:42 +00:00
|
|
|
internal void
|
2019-09-04 05:31:35 +00:00
|
|
|
live_set_free_view(Lifetime_Allocator *lifetime_allocator, Live_Views *live_set, View *view){
|
2018-03-26 05:19:08 +00:00
|
|
|
Assert(live_set->count > 0);
|
|
|
|
--live_set->count;
|
|
|
|
|
2019-02-10 09:18:34 +00:00
|
|
|
view->next = live_set->free_sentinel.next;
|
|
|
|
view->prev = &live_set->free_sentinel;
|
|
|
|
live_set->free_sentinel.next = view;
|
|
|
|
view->next->prev = view;
|
|
|
|
view->in_use = false;
|
2018-06-23 03:03:58 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
lifetime_free_object(lifetime_allocator, view->lifetime_object);
|
2018-03-26 05:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-02-09 22:48:53 +00:00
|
|
|
internal File_Edit_Positions
|
|
|
|
view_get_edit_pos(View *view){
|
2019-02-10 09:18:34 +00:00
|
|
|
return(view->edit_pos_);
|
2019-02-09 22:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
view_set_edit_pos(View *view, File_Edit_Positions edit_pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
edit_pos.scroll.position.line_number = clamp_bot(1, edit_pos.scroll.position.line_number);
|
|
|
|
edit_pos.scroll.target.line_number = clamp_bot(1, edit_pos.scroll.target.line_number);
|
2019-02-10 09:18:34 +00:00
|
|
|
view->edit_pos_ = edit_pos;
|
2019-02-27 05:49:35 +00:00
|
|
|
view->file->state.edit_pos_most_recent = edit_pos;
|
2019-02-09 22:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
internal Rect_f32
|
2019-10-22 04:10:29 +00:00
|
|
|
view_get_buffer_rect(Thread_Context *tctx, Models *models, View *view){
|
2019-10-16 22:31:59 +00:00
|
|
|
Rect_f32 region = Rf32(view->panel->rect_full);
|
2019-10-14 22:57:47 +00:00
|
|
|
if (models->buffer_region != 0){
|
2019-10-16 22:31:59 +00:00
|
|
|
Rect_f32 rect = region;
|
2019-12-18 00:19:03 +00:00
|
|
|
Rect_f32 sub_region = Rf32(V2f32(0, 0), rect_dim(rect));
|
2019-10-22 04:10:29 +00:00
|
|
|
Application_Links app = {};
|
|
|
|
app.tctx = tctx;
|
|
|
|
app.cmd_context = models;
|
2019-10-25 23:33:50 +00:00
|
|
|
sub_region = models->buffer_region(&app, view_get_id(&models->view_set, view), sub_region);
|
2019-02-27 05:49:35 +00:00
|
|
|
region.p0 = rect.p0 + sub_region.p0;
|
|
|
|
region.p1 = rect.p0 + sub_region.p1;
|
|
|
|
region.x1 = clamp_top(region.x1, rect.x1);
|
|
|
|
region.y1 = clamp_top(region.y1, rect.y1);
|
|
|
|
region.x0 = clamp_top(region.x0, region.x1);
|
|
|
|
region.y0 = clamp_top(region.y0, region.y1);
|
|
|
|
}
|
|
|
|
return(region);
|
|
|
|
}
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
internal f32
|
2019-10-22 04:10:29 +00:00
|
|
|
view_width(Thread_Context *tctx, Models *models, View *view){
|
|
|
|
return(rect_width(view_get_buffer_rect(tctx, models, view)));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
internal f32
|
2019-10-22 04:10:29 +00:00
|
|
|
view_height(Thread_Context *tctx, Models *models, View *view){
|
|
|
|
return(rect_height(view_get_buffer_rect(tctx, models, view)));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-29 04:27:20 +00:00
|
|
|
internal Layout_Item_List
|
2019-10-22 04:10:29 +00:00
|
|
|
view_get_line_layout(Thread_Context *tctx, Models *models, View *view, i64 line_number){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_get_line_layout(tctx, models, file, layout_func, width, face, line_number));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal Line_Shift_Vertical
|
2019-10-29 04:27:20 +00:00
|
|
|
view_line_shift_y(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 line_number, f32 y_delta){
|
2019-07-31 20:43:27 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_line_shift_y(tctx, models, file, layout_func, width, face,
|
|
|
|
line_number, y_delta));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal f32
|
2019-10-29 04:27:20 +00:00
|
|
|
view_line_y_difference(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 line_a, i64 line_b){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_line_y_difference(tctx, models, file,
|
|
|
|
layout_func, width, face, line_a, line_b));
|
2018-07-17 03:21:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal i64
|
2019-10-29 04:27:20 +00:00
|
|
|
view_pos_at_relative_xy(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 base_line, Vec2_f32 relative_xy){
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_pos_at_relative_xy(tctx, models, file,
|
|
|
|
layout_func, width, face, base_line, relative_xy));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 23:27:37 +00:00
|
|
|
internal Rect_f32
|
|
|
|
view_relative_box_of_pos(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 base_line, i64 pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-30 23:27:37 +00:00
|
|
|
return(file_relative_box_of_pos(tctx, models, file,
|
|
|
|
layout_func, width, face, base_line, pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Vec2_f32
|
|
|
|
view_relative_xy_of_pos(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 base_line, i64 pos){
|
|
|
|
Rect_f32 rect = view_relative_box_of_pos(tctx, models, view, base_line, pos);
|
|
|
|
return(rect_center(rect));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 05:20:19 +00:00
|
|
|
function Rect_f32
|
|
|
|
view_padded_box_of_pos(Thread_Context *tctx, Models *models, View *view,
|
2020-01-15 18:14:17 +00:00
|
|
|
i64 base_line, i64 pos){
|
2019-12-27 05:20:19 +00:00
|
|
|
Editing_File *file = view->file;
|
|
|
|
Face *face = file_get_face(models, file);
|
|
|
|
f32 width = view_width(tctx, models, view);
|
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
|
|
|
return(file_padded_box_of_pos(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
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal Buffer_Point
|
2019-10-29 04:27:20 +00:00
|
|
|
view_normalize_buffer_point(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
Buffer_Point point){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_normalize_buffer_point(tctx, models, file,
|
|
|
|
layout_func, width, face, point));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal Vec2_f32
|
2019-10-29 04:27:20 +00:00
|
|
|
view_buffer_point_difference(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
Buffer_Point a, Buffer_Point b){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_buffer_point_difference(tctx, models, file,
|
|
|
|
layout_func, width, face, a, b));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal Buffer_Point
|
2019-10-29 04:27:20 +00:00
|
|
|
view_move_buffer_point(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
Buffer_Point buffer_point, Vec2_f32 delta){
|
2019-09-02 18:59:36 +00:00
|
|
|
delta += buffer_point.pixel_shift;
|
2019-10-22 04:10:29 +00:00
|
|
|
Line_Shift_Vertical shift = view_line_shift_y(tctx, models, view, buffer_point.line_number, delta.y);
|
2019-09-02 18:59:36 +00:00
|
|
|
buffer_point.line_number = shift.line;
|
|
|
|
buffer_point.pixel_shift = V2f32(delta.x, delta.y - shift.y_delta);
|
|
|
|
return(buffer_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Line_Shift_Character
|
2019-10-29 04:27:20 +00:00
|
|
|
view_line_shift_characters(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 line_number, i64 character_delta){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_line_shift_characters(tctx, models, file,
|
|
|
|
layout_func, width, face, line_number, character_delta));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
2019-10-29 04:27:20 +00:00
|
|
|
view_line_character_difference(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 line_a, i64 line_b){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_line_character_difference(tctx, models, file, layout_func, width, face,
|
|
|
|
line_a, line_b));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
2019-10-29 04:27:20 +00:00
|
|
|
view_pos_from_relative_character(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 base_line, i64 relative_character){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_pos_from_relative_character(tctx, models, file, layout_func, width, face,
|
|
|
|
base_line, relative_character));
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
2019-10-29 04:27:20 +00:00
|
|
|
view_relative_character_from_pos(Thread_Context *tctx, Models *models, View *view,
|
|
|
|
i64 base_line, i64 pos){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
f32 width = view_width(tctx, models, view);
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
return(file_relative_character_from_pos(tctx, models, file,
|
|
|
|
layout_func, width, face, base_line, pos));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 21:32:52 +00:00
|
|
|
internal Buffer_Cursor
|
|
|
|
view_compute_cursor(View *view, Buffer_Seek seek){
|
|
|
|
Editing_File *file = view->file;
|
|
|
|
return(file_compute_cursor(file, seek));
|
|
|
|
}
|
|
|
|
|
2018-03-25 06:43:56 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2018-03-24 10:06:45 +00:00
|
|
|
internal b32
|
2019-10-22 04:10:29 +00:00
|
|
|
view_move_view_to_cursor(Thread_Context *tctx, Models *models, View *view, Buffer_Scroll *scroll){
|
2019-09-02 18:59:36 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
Rect_f32 rect = view_get_buffer_rect(tctx, models, view);
|
2019-09-02 18:59:36 +00:00
|
|
|
Vec2_f32 view_dim = rect_dim(rect);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-10-31 17:05:38 +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
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-10-29 04:27:20 +00:00
|
|
|
Vec2_f32 p = file_relative_xy_of_pos(tctx, models, file,
|
|
|
|
layout_func, view_dim.x, face,
|
|
|
|
scroll->target.line_number, edit_pos.cursor_pos);
|
2019-09-02 18:59:36 +00:00
|
|
|
p -= scroll->target.pixel_shift;
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-10-29 04:27:20 +00:00
|
|
|
f32 line_height = face->metrics.line_height;
|
|
|
|
f32 normal_advance = face->metrics.normal_advance;
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2020-05-09 17:22:53 +00:00
|
|
|
Vec2_f32 margin = view->cursor_margin;
|
|
|
|
Vec2_f32 push_in = view->cursor_push_in_multiplier;
|
|
|
|
|
|
|
|
Vec2_f32 lim_dim = view_dim*0.45f;
|
|
|
|
margin.x = clamp_top(margin.x, lim_dim.x);
|
|
|
|
margin.y = clamp_top(margin.y, lim_dim.y);
|
|
|
|
|
|
|
|
Vec2_f32 push_in_lim_dim = hadamard(lim_dim, V2f32(1.f/line_height, 1.f/normal_advance)) - margin;
|
|
|
|
push_in_lim_dim.x = clamp_bot(0.f, push_in_lim_dim.x);
|
|
|
|
push_in_lim_dim.y = clamp_bot(0.f, push_in_lim_dim.y);
|
|
|
|
push_in.x = clamp_top(push_in.x, push_in_lim_dim.x);
|
|
|
|
push_in.y = clamp_top(push_in.y, push_in_lim_dim.y);
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
Vec2_f32 target_p_relative = {};
|
2020-05-09 17:22:53 +00:00
|
|
|
if (p.y < margin.y){
|
|
|
|
target_p_relative.y = p.y - margin.y - line_height*push_in.y;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2020-05-09 17:22:53 +00:00
|
|
|
else if (p.y > view_dim.y - margin.y){
|
|
|
|
target_p_relative.y = (p.y + margin.y + line_height*push_in.y) - view_dim.y;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2020-05-09 17:22:53 +00:00
|
|
|
if (p.x < margin.x){
|
|
|
|
target_p_relative.x = p.x - margin.x - normal_advance*push_in.x;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2020-05-09 17:22:53 +00:00
|
|
|
else if (p.x > view_dim.x - margin.x){
|
|
|
|
target_p_relative.x = (p.x + margin.x + normal_advance*push_in.x) - view_dim.x;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2019-10-18 02:54:02 +00:00
|
|
|
scroll->target.pixel_shift += target_p_relative;
|
2019-10-22 04:10:29 +00:00
|
|
|
scroll->target = view_normalize_buffer_point(tctx, models, view, scroll->target);
|
2019-09-02 18:59:36 +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);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
return(target_p_relative != V2f32(0.f, 0.f));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
2019-10-22 04:10:29 +00:00
|
|
|
view_move_cursor_to_view(Thread_Context *tctx, Models *models, View *view, Buffer_Scroll scroll, i64 *pos_in_out, f32 preferred_x){
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-10-22 04:10:29 +00:00
|
|
|
Rect_f32 rect = view_get_buffer_rect(tctx, models, view);
|
2019-09-02 18:59:36 +00:00
|
|
|
Vec2_f32 view_dim = rect_dim(rect);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-10-31 17:05:38 +00:00
|
|
|
Layout_Function *layout_func = file_get_layout_func(file);
|
2019-10-29 04:27:20 +00:00
|
|
|
|
|
|
|
Vec2_f32 p = file_relative_xy_of_pos(tctx, models, file,
|
|
|
|
layout_func, view_dim.x, face,
|
|
|
|
scroll.target.line_number, *pos_in_out);
|
2019-09-02 18:59:36 +00:00
|
|
|
p -= scroll.target.pixel_shift;
|
2019-02-04 03:51:43 +00:00
|
|
|
|
2019-10-29 04:27:20 +00:00
|
|
|
f32 line_height = face->metrics.line_height;
|
2019-09-02 18:59:36 +00:00
|
|
|
|
|
|
|
b32 adjusted_y = true;
|
2019-10-18 02:54:02 +00:00
|
|
|
if (p.y < 0.f){
|
|
|
|
p.y = line_height*1.5f;
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
2019-10-18 02:54:02 +00:00
|
|
|
else if (p.y > view_dim.y){
|
|
|
|
p.y = view_dim.y - line_height*1.5f;
|
2019-02-04 03:51:43 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
else{
|
|
|
|
adjusted_y = false;
|
2019-02-04 03:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b32 result = false;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (adjusted_y){
|
|
|
|
p += scroll.target.pixel_shift;
|
2019-10-29 04:27:20 +00:00
|
|
|
*pos_in_out = file_pos_at_relative_xy(tctx, models, file,
|
|
|
|
layout_func, view_dim.x, face,
|
|
|
|
scroll.target.line_number, p);
|
2019-02-04 03:51:43 +00:00
|
|
|
result = true;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2018-03-24 21:43:57 +00:00
|
|
|
|
|
|
|
return(result);
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 21:43:57 +00:00
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_cursor(Thread_Context *tctx, Models *models, View *view, i64 pos){
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-09-02 18:59:36 +00:00
|
|
|
file_edit_positions_set_cursor(&edit_pos, pos);
|
2019-02-10 00:20:55 +00:00
|
|
|
view_set_edit_pos(view, edit_pos);
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Scroll scroll = edit_pos.scroll;
|
2019-10-22 04:10:29 +00:00
|
|
|
if (view_move_view_to_cursor(tctx, models, view, &scroll)){
|
2019-02-09 22:48:53 +00:00
|
|
|
edit_pos.scroll = scroll;
|
2019-02-10 00:20:55 +00:00
|
|
|
view_set_edit_pos(view, edit_pos);
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_scroll(Thread_Context *tctx, Models *models, View *view, Buffer_Scroll scroll){
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-09-02 18:59:36 +00:00
|
|
|
file_edit_positions_set_scroll(&edit_pos, scroll);
|
2019-02-09 22:48:53 +00:00
|
|
|
view_set_edit_pos(view, edit_pos);
|
2019-10-22 04:10:29 +00:00
|
|
|
if (view_move_cursor_to_view(tctx, models, view, edit_pos.scroll, &edit_pos.cursor_pos, view->preferred_x)){
|
2019-02-10 00:20:55 +00:00
|
|
|
view_set_edit_pos(view, edit_pos);
|
|
|
|
}
|
2018-03-24 21:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_cursor_and_scroll(Thread_Context *tctx, Models *models, View *view, i64 pos, Buffer_Scroll scroll){
|
2019-02-09 22:48:53 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-09-02 18:59:36 +00:00
|
|
|
file_edit_positions_set_cursor(&edit_pos, pos);
|
2019-10-08 19:16:20 +00:00
|
|
|
Buffer_Cursor cursor = view_compute_cursor(view, seek_pos(pos));
|
2019-10-22 04:10:29 +00:00
|
|
|
Vec2_f32 p = view_relative_xy_of_pos(tctx, models, view, cursor.line, pos);
|
2019-10-08 19:16:20 +00:00
|
|
|
view->preferred_x = p.x;
|
2019-09-02 18:59:36 +00:00
|
|
|
file_edit_positions_set_scroll(&edit_pos, scroll);
|
2019-02-09 22:48:53 +00:00
|
|
|
edit_pos.last_set_type = EditPos_None;
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-25 06:43:56 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2018-03-26 05:19:08 +00:00
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_file(Thread_Context *tctx, Models *models, View *view, Editing_File *file){
|
2018-03-26 05:19:08 +00:00
|
|
|
Assert(file != 0);
|
|
|
|
|
2020-05-03 13:40:07 +00:00
|
|
|
Editing_File *old_file = view->file;
|
|
|
|
|
2020-05-03 13:24:39 +00:00
|
|
|
if (models->view_change_buffer != 0){
|
|
|
|
Application_Links app = {};
|
|
|
|
app.tctx = tctx;
|
|
|
|
app.cmd_context = models;
|
2020-05-03 13:40:07 +00:00
|
|
|
models->view_change_buffer(&app, view_get_id(&models->view_set, view),
|
|
|
|
(old_file != 0)?old_file->id:0, file->id);
|
2020-05-03 13:24:39 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 03:51:43 +00:00
|
|
|
if (old_file != 0){
|
|
|
|
file_touch(&models->working_set, old_file);
|
2019-02-10 00:20:55 +00:00
|
|
|
file_edit_positions_push(old_file, view_get_edit_pos(view));
|
2018-03-26 05:19:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
view->file = file;
|
2018-03-26 05:19:08 +00:00
|
|
|
|
2019-02-10 00:35:47 +00:00
|
|
|
File_Edit_Positions edit_pos = file_edit_positions_pop(file);
|
|
|
|
view_set_edit_pos(view, edit_pos);
|
2019-02-10 09:18:34 +00:00
|
|
|
view->mark = edit_pos.cursor_pos;
|
2019-09-02 21:32:52 +00:00
|
|
|
Buffer_Cursor cursor = view_compute_cursor(view, seek_pos(edit_pos.cursor_pos));
|
2019-10-22 04:10:29 +00:00
|
|
|
Vec2_f32 p = view_relative_xy_of_pos(tctx, models, view, cursor.line, edit_pos.cursor_pos);
|
2019-09-02 21:32:52 +00:00
|
|
|
view->preferred_x = p.x;
|
2019-07-21 18:16:34 +00:00
|
|
|
|
2019-02-24 07:22:16 +00:00
|
|
|
models->layout.panel_state_dirty = true;
|
2018-03-26 05:19:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
function void
|
2019-10-15 03:26:00 +00:00
|
|
|
view_push_context(View *view, View_Context *ctx){
|
2020-03-11 23:22:37 +00:00
|
|
|
Temp_Memory pop_me = begin_temp(&view->node_arena);
|
|
|
|
View_Context_Node *node = push_array_zero(&view->node_arena, View_Context_Node, 1);
|
2019-10-14 06:58:49 +00:00
|
|
|
sll_stack_push(view->ctx, node);
|
2019-10-15 03:26:00 +00:00
|
|
|
node->pop_me = pop_me;
|
2019-10-14 06:58:49 +00:00
|
|
|
block_copy_struct(&node->ctx, ctx);
|
2020-03-11 23:22:37 +00:00
|
|
|
node->delta_rule_memory = push_array_zero(&view->node_arena, u8, ctx->delta_rule_memory_size);
|
2019-10-14 06:58:49 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 01:46:57 +00:00
|
|
|
function void
|
|
|
|
view_alter_context(View *view, View_Context *ctx){
|
|
|
|
View_Context_Node *node = view->ctx;
|
|
|
|
Assert(node != 0);
|
|
|
|
block_copy_struct(&node->ctx, ctx);
|
|
|
|
}
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
function void
|
2019-10-15 03:26:00 +00:00
|
|
|
view_pop_context(View *view){
|
2019-10-14 06:58:49 +00:00
|
|
|
View_Context_Node *node = view->ctx;
|
2019-10-15 03:26:00 +00:00
|
|
|
if (node != 0 && node->next != 0){
|
2019-10-14 06:58:49 +00:00
|
|
|
sll_stack_pop(view->ctx);
|
2019-10-15 03:26:00 +00:00
|
|
|
end_temp(node->pop_me);
|
2019-10-14 06:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 03:26:00 +00:00
|
|
|
function View_Context_Node*
|
2019-10-18 02:54:02 +00:00
|
|
|
view_current_context_node(View *view){
|
2019-10-15 03:26:00 +00:00
|
|
|
return(view->ctx);
|
|
|
|
}
|
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
function View_Context
|
2019-10-18 02:54:02 +00:00
|
|
|
view_current_context(View *view){
|
2019-10-14 06:58:49 +00:00
|
|
|
View_Context ctx = {};
|
|
|
|
View_Context_Node *node = view->ctx;
|
|
|
|
if (node != 0){
|
|
|
|
block_copy_struct(&ctx, &node->ctx);
|
|
|
|
}
|
|
|
|
return(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
internal Coroutine*
|
2020-02-09 10:22:35 +00:00
|
|
|
co_handle_request(Thread_Context *tctx, Models *models, Coroutine *co, Co_Out *out){
|
2019-10-13 20:17:22 +00:00
|
|
|
Coroutine *result = 0;
|
|
|
|
switch (out->request){
|
|
|
|
case CoRequest_NewFontFace:
|
|
|
|
{
|
|
|
|
Face_Description *description = out->face_description;
|
|
|
|
Face *face = font_set_new_face(&models->font_set, description);
|
|
|
|
Co_In in = {};
|
2020-01-15 18:14:17 +00:00
|
|
|
in.face_id = (face != 0)?face->id:0;
|
2019-10-13 20:17:22 +00:00
|
|
|
result = coroutine_run(&models->coroutines, co, &in, out);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CoRequest_ModifyFace:
|
|
|
|
{
|
|
|
|
Face_Description *description = out->face_description;
|
|
|
|
Face_ID face_id = out->face_id;
|
|
|
|
Co_In in = {};
|
|
|
|
in.success = font_set_modify_face(&models->font_set, face_id, description);
|
|
|
|
result = coroutine_run(&models->coroutines, co, &in, out);
|
|
|
|
}break;
|
2020-02-09 10:22:35 +00:00
|
|
|
|
|
|
|
case CoRequest_AcquireGlobalFrameMutex:
|
|
|
|
{
|
|
|
|
system_acquire_global_frame_mutex(tctx);
|
|
|
|
result = coroutine_run(&models->coroutines, co, 0, out);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case CoRequest_ReleaseGlobalFrameMutex:
|
|
|
|
{
|
|
|
|
system_release_global_frame_mutex(tctx);
|
|
|
|
result = coroutine_run(&models->coroutines, co, 0, out);
|
|
|
|
}break;
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Coroutine*
|
2019-10-22 04:10:29 +00:00
|
|
|
co_run(Thread_Context *tctx, Models *models, Coroutine *co, Co_In *in, Co_Out *out){
|
2019-10-13 20:17:22 +00:00
|
|
|
Coroutine *result = coroutine_run(&models->coroutines, co, in, out);
|
|
|
|
for (;result != 0 && out->request != CoRequest_None;){
|
2020-02-09 10:22:35 +00:00
|
|
|
result = co_handle_request(tctx, models, result, out);
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
view_event_context_base__inner(Coroutine *coroutine){
|
|
|
|
Co_In *in = (Co_In*)coroutine->in;
|
|
|
|
Models *models = in->models;
|
|
|
|
Custom_Command_Function *event_context_base = in->event_context_base;
|
|
|
|
Assert(event_context_base != 0);
|
2019-10-22 04:10:29 +00:00
|
|
|
Application_Links app = {};
|
|
|
|
app.tctx = coroutine->tctx;
|
|
|
|
app.cmd_context = models;
|
|
|
|
event_context_base(&app);
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function void
|
2019-10-22 04:10:29 +00:00
|
|
|
view_init(Thread_Context *tctx, Models *models, View *view, Editing_File *initial_buffer,
|
2019-10-13 20:17:22 +00:00
|
|
|
Custom_Command_Function *event_context_base){
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_file(tctx, models, view, initial_buffer);
|
2019-10-14 06:58:49 +00:00
|
|
|
|
2020-03-11 23:22:37 +00:00
|
|
|
view->node_arena = make_arena_system();
|
2019-10-15 03:26:00 +00:00
|
|
|
|
2019-10-14 06:58:49 +00:00
|
|
|
View_Context first_ctx = {};
|
|
|
|
first_ctx.render_caller = models->render_caller;
|
2019-10-15 03:26:00 +00:00
|
|
|
first_ctx.delta_rule = models->delta_rule;
|
|
|
|
first_ctx.delta_rule_memory_size = models->delta_rule_memory_size;
|
|
|
|
view_push_context(view, &first_ctx);
|
2019-10-14 06:58:49 +00:00
|
|
|
|
2020-05-09 17:22:53 +00:00
|
|
|
view->cursor_margin = V2f32(0.f, 0.f);
|
|
|
|
view->cursor_push_in_multiplier = V2f32(1.5f, 1.5f);
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
view->co = coroutine_create(&models->coroutines, view_event_context_base__inner);
|
2019-10-25 23:33:50 +00:00
|
|
|
view->co->user_data = view;
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_In in = {};
|
|
|
|
in.models = models;
|
|
|
|
in.event_context_base = event_context_base;
|
2019-10-22 04:10:29 +00:00
|
|
|
view->co = co_run(tctx, models, view->co, &in, &view->co_out);
|
2019-10-13 20:17:22 +00:00
|
|
|
// TODO(allen): deal with this kind of problem!
|
|
|
|
Assert(view->co != 0);
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:38:57 +00:00
|
|
|
// TODO(allen): This doesn't make any sense!!!!!! COROUTINE SHUTDOWN? VIEW CLOSING? WADAFUQ?
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
function b32
|
|
|
|
view_close(Models *models, View *view){
|
|
|
|
Layout *layout = &models->layout;
|
|
|
|
b32 result = false;
|
|
|
|
if (layout_close_panel(layout, view->panel)){
|
2020-05-01 14:38:57 +00:00
|
|
|
if (view->co != 0){
|
|
|
|
models_push_wind_down(models, view->co);
|
|
|
|
}
|
2019-10-25 23:33:50 +00:00
|
|
|
live_set_free_view(&models->lifetime_allocator, &models->view_set, view);
|
2019-10-13 20:17:22 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
view_check_co_exited(Models *models, View *view){
|
|
|
|
if (view->co == 0){
|
|
|
|
b32 result = view_close(models, view);
|
|
|
|
// TODO(allen): Here it looks like the final view has
|
2019-11-07 02:09:16 +00:00
|
|
|
// exited from it's event handler. We should probably
|
|
|
|
// have a failsafe restarter for the event handler when
|
|
|
|
// this happens.
|
2019-10-13 20:17:22 +00:00
|
|
|
Assert(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:38:57 +00:00
|
|
|
// TODO(allen): This is dumb. Let's rethink view cleanup strategy.
|
|
|
|
|
2019-10-13 20:17:22 +00:00
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
co_single_abort(Thread_Context *tctx, Models *models, View *view){
|
2019-10-13 20:17:22 +00:00
|
|
|
Coroutine *co = view->co;
|
|
|
|
Co_In in = {};
|
|
|
|
in.user_input.abort = true;
|
2019-10-22 04:10:29 +00:00
|
|
|
view->co = co_run(tctx, models, co, &in, &view->co_out);
|
2019-10-13 20:17:22 +00:00
|
|
|
view_check_co_exited(models, view);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
co_full_abort(Thread_Context *tctx, Models *models, View *view){
|
2019-10-13 20:17:22 +00:00
|
|
|
Coroutine *co = view->co;
|
|
|
|
Co_In in = {};
|
|
|
|
in.user_input.abort = true;
|
|
|
|
for (u32 j = 0; j < 100 && co != 0; ++j){
|
2019-10-22 04:10:29 +00:00
|
|
|
co = co_run(tctx, models, co, &in, &view->co_out);
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
if (co != 0){
|
2019-10-22 04:10:29 +00:00
|
|
|
Application_Links app = {};
|
|
|
|
app.tctx = tctx;
|
|
|
|
app.cmd_context = models;
|
2019-11-07 02:09:16 +00:00
|
|
|
#define M "SERIOUS ERROR: full stack abort did not complete"
|
2019-10-22 04:10:29 +00:00
|
|
|
print_message(&app, string_u8_litexpr(M));
|
2019-10-13 20:17:22 +00:00
|
|
|
#undef M
|
|
|
|
}
|
|
|
|
view->co = 0;
|
|
|
|
init_query_set(&view->query_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_event(Thread_Context *tctx, Models *models, View *view, Input_Event *event){
|
2019-10-13 20:17:22 +00:00
|
|
|
b32 event_was_handled = false;
|
|
|
|
|
|
|
|
Coroutine *co = view->co;
|
|
|
|
Co_Out *co_out = &view->co_out;
|
|
|
|
Event_Property abort_flags = co_out->abort_flags;
|
|
|
|
Event_Property get_flags = co_out->get_flags|abort_flags;
|
|
|
|
|
|
|
|
Event_Property event_flags = get_event_properties(event);
|
|
|
|
if ((get_flags&event_flags) != 0){
|
2019-10-14 22:57:47 +00:00
|
|
|
models->current_input_unhandled = false;
|
2019-10-13 20:17:22 +00:00
|
|
|
Co_In in = {};
|
|
|
|
in.user_input.event = *event;
|
|
|
|
in.user_input.abort = ((abort_flags & event_flags) != 0);
|
2019-10-14 22:57:47 +00:00
|
|
|
begin_handling_input(models, &in.user_input);
|
2019-10-22 04:10:29 +00:00
|
|
|
view->co = co_run(tctx, models, view->co, &in, &view->co_out);
|
2019-10-13 20:17:22 +00:00
|
|
|
view_check_co_exited(models, view);
|
|
|
|
if (!HasFlag(event_flags, EventProperty_Animate)){
|
|
|
|
models->animate_next_frame = true;
|
|
|
|
}
|
2019-10-14 22:57:47 +00:00
|
|
|
event_was_handled = !models->current_input_unhandled;
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(event_was_handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, View *view, Core_Code code, String_Const_u8 string){
|
2019-10-13 20:17:22 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_Core;
|
|
|
|
event.core.code = code;
|
2019-10-14 22:57:47 +00:00
|
|
|
event.core.string = string;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(co_send_event(tctx, models, view, &event));
|
2019-10-13 20:17:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 22:57:47 +00:00
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, View *view, Core_Code code, Buffer_ID id){
|
2019-10-14 22:57:47 +00:00
|
|
|
Input_Event event = {};
|
|
|
|
event.kind = InputEventKind_Core;
|
|
|
|
event.core.code = code;
|
|
|
|
event.core.id = id;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(co_send_event(tctx, models, view, &event));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, View *view, Core_Code code){
|
|
|
|
return(co_send_core_event(tctx, models, view, code, SCu8()));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_event(Thread_Context *tctx, Models *models, Input_Event *event){
|
2019-10-14 22:57:47 +00:00
|
|
|
Panel *active_panel = models->layout.active_panel;
|
|
|
|
View *view = active_panel->view;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(co_send_event(tctx, models, view, event));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, Core_Code code, String_Const_u8 string){
|
2019-10-14 22:57:47 +00:00
|
|
|
Panel *active_panel = models->layout.active_panel;
|
|
|
|
View *view = active_panel->view;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(co_send_core_event(tctx, models, view, code, string));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, Core_Code code, Buffer_ID buffer_id){
|
2019-10-14 22:57:47 +00:00
|
|
|
Panel *active_panel = models->layout.active_panel;
|
|
|
|
View *view = active_panel->view;
|
2019-10-22 04:10:29 +00:00
|
|
|
return(co_send_core_event(tctx, models, view, code, buffer_id));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function b32
|
2019-10-22 04:10:29 +00:00
|
|
|
co_send_core_event(Thread_Context *tctx, Models *models, Core_Code code){
|
|
|
|
return(co_send_core_event(tctx, models, code, SCu8()));
|
2019-10-14 22:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 05:19:08 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-11-07 02:09:16 +00:00
|
|
|
function void
|
|
|
|
view_quit_ui(Thread_Context *tctx, Models *models, View *view){
|
|
|
|
for (u32 j = 0;; j += 1){
|
|
|
|
if (j == 100){
|
|
|
|
Application_Links app = {};
|
|
|
|
app.tctx = tctx;
|
|
|
|
app.cmd_context = models;
|
|
|
|
#define M "SERIOUS ERROR: view quit ui did not complete"
|
|
|
|
print_message(&app, string_u8_litexpr(M));
|
|
|
|
#undef M
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
View_Context_Node *ctx = view->ctx;
|
|
|
|
if (ctx->next == 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
co_single_abort(tctx, models, view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2018-03-24 21:43:57 +00:00
|
|
|
internal b32
|
2019-02-05 09:13:38 +00:00
|
|
|
file_is_viewed(Layout *layout, Editing_File *file){
|
2018-03-24 21:43:57 +00:00
|
|
|
b32 is_viewed = false;
|
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-03-24 21:43:57 +00:00
|
|
|
View *view = panel->view;
|
2019-02-27 05:49:35 +00:00
|
|
|
if (view->file == file){
|
2018-03-24 21:43:57 +00:00
|
|
|
is_viewed = true;
|
|
|
|
break;
|
|
|
|
}
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2018-03-24 21:43:57 +00:00
|
|
|
return(is_viewed);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2019-10-22 04:10:29 +00:00
|
|
|
adjust_views_looking_at_file_to_new_cursor(Thread_Context *tctx, Models *models, Editing_File *file){
|
2019-02-05 09:13:38 +00:00
|
|
|
Layout *layout = &models->layout;
|
|
|
|
for (Panel *panel = layout_get_first_open_panel(layout);
|
|
|
|
panel != 0;
|
|
|
|
panel = layout_get_next_open_panel(layout, panel)){
|
2018-03-24 21:43:57 +00:00
|
|
|
View *view = panel->view;
|
2019-02-27 05:49:35 +00:00
|
|
|
if (view->file == file){
|
2019-02-10 00:20:55 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-10-22 04:10:29 +00:00
|
|
|
view_set_cursor(tctx, models, view, edit_pos.cursor_pos);
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 06:43:56 +00:00
|
|
|
internal void
|
2019-10-03 17:57:44 +00:00
|
|
|
global_set_font_and_update_files(Models *models, Face *new_global_face){
|
2019-08-12 09:16:04 +00:00
|
|
|
for (Node *node = models->working_set.active_file_sentinel.next;
|
|
|
|
node != &models->working_set.active_file_sentinel;
|
2018-03-25 06:43:56 +00:00
|
|
|
node = node->next){
|
2019-01-31 12:38:24 +00:00
|
|
|
Editing_File *file = CastFromMember(Editing_File, main_chain_node, node);
|
2019-09-02 21:32:52 +00:00
|
|
|
file->settings.face_id = new_global_face->id;
|
2018-03-25 06:43:56 +00:00
|
|
|
}
|
2019-09-02 21:32:52 +00:00
|
|
|
models->global_face_id = new_global_face->id;
|
2018-03-25 06:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal b32
|
2019-10-03 17:57:44 +00:00
|
|
|
release_font_and_update(Models *models, Face *face, Face *replacement_face){
|
2018-03-25 06:43:56 +00:00
|
|
|
b32 success = false;
|
2019-09-02 21:32:52 +00:00
|
|
|
Assert(replacement_face != 0 && replacement_face != face);
|
|
|
|
if (font_set_release_face(&models->font_set, face->id)){
|
2019-08-12 09:16:04 +00:00
|
|
|
for (Node *node = models->working_set.active_file_sentinel.next;
|
|
|
|
node != &models->working_set.active_file_sentinel;
|
2018-03-25 06:43:56 +00:00
|
|
|
node = node->next){
|
2019-01-31 12:38:24 +00:00
|
|
|
Editing_File *file = CastFromMember(Editing_File, main_chain_node, node);
|
2019-09-02 21:32:52 +00:00
|
|
|
if (file->settings.face_id == face->id){
|
|
|
|
file->settings.face_id = replacement_face->id;
|
2018-03-25 06:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 21:32:52 +00:00
|
|
|
if (models->global_face_id == face->id){
|
|
|
|
models->global_face_id = replacement_face->id;
|
|
|
|
}
|
2019-07-24 07:41:40 +00:00
|
|
|
success = true;
|
2018-03-25 06:43:56 +00:00
|
|
|
}
|
|
|
|
return(success);
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 05:19:08 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal View*
|
|
|
|
imp_get_view(Models *models, View_ID view_id){
|
2019-10-25 23:33:50 +00:00
|
|
|
Live_Views *view_set = &models->view_set;
|
2019-09-02 18:59:36 +00:00
|
|
|
View *view = 0;
|
|
|
|
view_id -= 1;
|
2019-10-25 23:33:50 +00:00
|
|
|
if (0 <= view_id && view_id < view_set->max){
|
|
|
|
view = view_set->views + view_id;
|
2019-09-02 18:59:36 +00:00
|
|
|
if (!view->in_use){
|
|
|
|
view = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(view);
|
|
|
|
}
|
|
|
|
|
2017-07-17 23:35:13 +00:00
|
|
|
// BOTTOM
|
|
|
|
|