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
|
|
|
|
|
2018-08-04 02:41:38 +00:00
|
|
|
internal i32
|
|
|
|
view_get_map(View *view){
|
2019-02-10 09:18:34 +00:00
|
|
|
if (view->ui_mode){
|
|
|
|
return(view->ui_map_id);
|
2018-08-04 02:41:38 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-27 05:49:35 +00:00
|
|
|
return(view->file->settings.base_map_id);
|
2018-08-04 02:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:14:27 +00:00
|
|
|
internal u32
|
|
|
|
view_get_access_flags(View *view){
|
|
|
|
u32 result = AccessOpen;
|
|
|
|
if (view->ui_mode){
|
|
|
|
result |= AccessHidden;
|
|
|
|
}
|
2019-02-27 05:49:35 +00:00
|
|
|
result |= file_get_access_flags(view->file);
|
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-03-31 18:55:26 +00:00
|
|
|
view_get_buffer_rect(Models *models, View *view){
|
2019-06-19 02:31:59 +00:00
|
|
|
Rect_f32 region = {};
|
2019-02-27 05:49:35 +00:00
|
|
|
if (models->get_view_buffer_region != 0){
|
2019-06-19 02:31:59 +00:00
|
|
|
Rect_f32 rect = Rf32(view->panel->rect_inner);
|
|
|
|
Rect_f32 sub_region = Rf32(V2(0, 0), rect_dim(rect));
|
2019-02-27 05:49:35 +00:00
|
|
|
sub_region = models->get_view_buffer_region(&models->app_links, view_get_id(&models->live_set, view), sub_region);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else{
|
2019-06-19 02:31:59 +00:00
|
|
|
region = Rf32(view->panel->rect_inner);
|
2019-02-27 05:49:35 +00:00
|
|
|
}
|
|
|
|
return(region);
|
|
|
|
}
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
internal f32
|
2019-02-27 05:49:35 +00:00
|
|
|
view_width(Models *models, View *view){
|
2019-03-31 18:55:26 +00:00
|
|
|
return(rect_width(view_get_buffer_rect(models, view)));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
internal f32
|
2019-02-27 05:49:35 +00:00
|
|
|
view_height(Models *models, View *view){
|
2019-03-31 18:55:26 +00:00
|
|
|
return(rect_height(view_get_buffer_rect(models, view)));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
internal Buffer_Layout_Item_List
|
|
|
|
view_get_line_layout(Models *models, View *view, i64 line_number){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_get_line_layout(models, file, width, face, line_number));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal Line_Shift_Vertical
|
|
|
|
view_line_shift_y(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-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_line_shift_y(models, file, width, face, line_number, y_delta));
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal f32
|
|
|
|
view_line_y_difference(Models *models, View *view, i64 line_a, i64 line_b){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_line_y_difference(models, file, width, face, line_a, line_b));
|
2018-07-17 03:21:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal i64
|
|
|
|
view_pos_at_relative_xy(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-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_pos_at_relative_xy(models, file, width, face, base_line, relative_xy));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Vec2_f32
|
|
|
|
view_relative_xy_of_pos(Models *models, View *view, i64 base_line, i64 pos){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_relative_xy_of_pos(models, file, width, face, base_line, pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Buffer_Point
|
|
|
|
view_normalize_buffer_point(Models *models, View *view, Buffer_Point point){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_normalize_buffer_point(models, file, width, face, point));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Vec2_f32
|
|
|
|
view_buffer_point_difference(Models *models, View *view, Buffer_Point a, Buffer_Point b){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_buffer_point_difference(models, file, width, face, a, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Buffer_Point
|
|
|
|
view_move_buffer_point(Models *models, View *view, Buffer_Point buffer_point, Vec2_f32 delta){
|
|
|
|
delta += buffer_point.pixel_shift;
|
|
|
|
Line_Shift_Vertical shift = view_line_shift_y(models, view, buffer_point.line_number, delta.y);
|
|
|
|
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
|
|
|
|
view_line_shift_characters(Models *models, View *view, i64 line_number, i64 character_delta){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_line_shift_characters(models, file, width, face, line_number, character_delta));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
|
|
|
view_line_character_difference(Models *models, View *view, i64 line_a, i64 line_b){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_line_character_difference(models, file, width, face, line_a, line_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
|
|
|
view_pos_from_relative_character(Models *models, View *view, i64 base_line, i64 relative_character){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_pos_from_relative_character(models, file, width, face, base_line, relative_character));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal i64
|
|
|
|
view_relative_character_from_pos(Models *models, View *view, i64 base_line, i64 pos){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 width = view_width(models, view);
|
|
|
|
return(file_relative_character_from_pos(models, file, 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
|
|
|
////////////////////////////////
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal Interval_f32
|
|
|
|
view_acceptable_y(f32 view_height, f32 line_height){
|
|
|
|
Interval_f32 acceptable_y = {};
|
|
|
|
if (view_height <= line_height*5.f){
|
|
|
|
if (view_height < line_height){
|
|
|
|
acceptable_y.max = view_height;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
acceptable_y.max = view_height - line_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
acceptable_y = If32(line_height*2.f, view_height - line_height*2.f);
|
|
|
|
}
|
|
|
|
return(acceptable_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Vec2_f32
|
|
|
|
view_safety_margin(f32 view_width, f32 acceptable_y_height, f32 line_height, f32 typical_advance){
|
|
|
|
Vec2_f32 safety = {};
|
|
|
|
safety.y = min(line_height*5.f, (acceptable_y_height + 1.f)*0.5f);
|
|
|
|
safety.x = min(view_width*0.5f, typical_advance*8.f);
|
|
|
|
return(safety);
|
|
|
|
}
|
|
|
|
|
2018-03-24 10:06:45 +00:00
|
|
|
internal b32
|
2019-09-02 18:59:36 +00:00
|
|
|
view_move_view_to_cursor(Models *models, View *view, Buffer_Scroll *scroll){
|
|
|
|
Editing_File *file = view->file;
|
2019-09-02 21:32:52 +00:00
|
|
|
Face *face = file_get_face(models, file);
|
2019-09-02 18:59:36 +00:00
|
|
|
Rect_f32 rect = view_get_buffer_rect(models, view);
|
|
|
|
Vec2_f32 view_dim = rect_dim(rect);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
File_Edit_Positions edit_pos = view_get_edit_pos(view);
|
2019-09-02 21:32:52 +00:00
|
|
|
Vec2_f32 p = file_relative_xy_of_pos(models, file, view_dim.x, face, scroll->target.line_number,
|
2019-09-02 18:59:36 +00:00
|
|
|
edit_pos.cursor_pos);
|
|
|
|
p -= scroll->target.pixel_shift;
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
f32 line_height = face->height;
|
|
|
|
f32 typical_advance = face->typical_advance;
|
|
|
|
Interval_f32 acceptable_y = view_acceptable_y(view_dim.y, line_height);
|
|
|
|
Vec2_f32 safety = view_safety_margin(view_dim.x, range_size(acceptable_y), line_height, typical_advance);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
Vec2_f32 target_p_relative = {};
|
|
|
|
if (p.y < acceptable_y.min){
|
|
|
|
target_p_relative.y = p.y - safety.y;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
else if (p.y > acceptable_y.max){
|
|
|
|
target_p_relative.y = (p.y + safety.y) - view_dim.y;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
if (p.x < 0.f){
|
|
|
|
target_p_relative.x = p.x - safety.x;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
else if (p.x > view_dim.x){
|
|
|
|
target_p_relative.x = (p.x + safety.x) - view_dim.x;
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
scroll->target.pixel_shift = target_p_relative;
|
|
|
|
scroll->target = view_normalize_buffer_point(models, view, scroll->target);
|
|
|
|
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-09-02 18:59:36 +00:00
|
|
|
view_move_cursor_to_view(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-09-02 18:59:36 +00:00
|
|
|
Rect_f32 rect = view_get_buffer_rect(models, view);
|
|
|
|
Vec2_f32 view_dim = rect_dim(rect);
|
2018-03-24 10:06:45 +00:00
|
|
|
|
2019-09-02 21:32:52 +00:00
|
|
|
Vec2_f32 p = file_relative_xy_of_pos(models, file, 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-09-02 18:59:36 +00:00
|
|
|
f32 line_height = face->height;
|
|
|
|
Interval_f32 acceptable_y = view_acceptable_y(view_dim.y, line_height);
|
|
|
|
Vec2_f32 safety = view_safety_margin(view_dim.x, range_size(acceptable_y),
|
|
|
|
line_height, face->typical_advance);
|
|
|
|
|
|
|
|
b32 adjusted_y = true;
|
|
|
|
if (p.y < acceptable_y.min){
|
|
|
|
p.y = acceptable_y.min + safety.y;
|
|
|
|
}
|
|
|
|
else if (p.y > acceptable_y.max){
|
|
|
|
p.y = acceptable_y.max - safety.y;
|
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-09-02 21:32:52 +00:00
|
|
|
*pos_in_out = file_pos_at_relative_xy(models, file, 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-09-02 18:59:36 +00:00
|
|
|
view_set_cursor(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-07-24 07:41:40 +00:00
|
|
|
if (view_move_view_to_cursor(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-09-02 18:59:36 +00:00
|
|
|
view_set_scroll(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-09-02 18:59:36 +00:00
|
|
|
if (view_move_cursor_to_view(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-09-02 18:59:36 +00:00
|
|
|
view_set_cursor_and_scroll(Models *models, View *view, i64 pos, b32 set_preferred_x, 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);
|
|
|
|
view->preferred_x = 0.f;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-31 13:06:42 +00:00
|
|
|
internal void
|
2019-09-02 18:59:36 +00:00
|
|
|
view_post_paste_effect(View *view, f32 seconds, i64 start, i64 size, u32 color){
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *file = view->file;
|
2018-03-25 06:43:56 +00:00
|
|
|
file->state.paste_effect.start = start;
|
|
|
|
file->state.paste_effect.end = start + size;
|
|
|
|
file->state.paste_effect.color = color;
|
|
|
|
file->state.paste_effect.seconds_down = seconds;
|
|
|
|
file->state.paste_effect.seconds_max = seconds;
|
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
|
|
|
|
view_set_file(System_Functions *system, Models *models, View *view, Editing_File *file){
|
|
|
|
Assert(file != 0);
|
|
|
|
|
2019-02-27 05:49:35 +00:00
|
|
|
Editing_File *old_file = view->file;
|
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));
|
|
|
|
Vec2_f32 p = view_relative_xy_of_pos(models, view, cursor.line, edit_pos.cursor_pos);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
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
|
2018-03-25 06:43:56 +00:00
|
|
|
adjust_views_looking_at_file_to_new_cursor(System_Functions *system, 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-09-02 18:59:36 +00:00
|
|
|
view_set_cursor(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-09-02 21:32:52 +00:00
|
|
|
global_set_font_and_update_files(System_Functions *system, 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-09-02 21:32:52 +00:00
|
|
|
release_font_and_update(System_Functions *system, 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-02-25 23:42:13 +00:00
|
|
|
internal argb_color
|
|
|
|
finalize_color(Color_Table color_table, int_color color){
|
|
|
|
argb_color color_argb = color;
|
|
|
|
if ((color & 0xFF000000) == 0){
|
|
|
|
color_argb = color_table.vals[color % color_table.count];
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
2019-02-25 23:42:13 +00:00
|
|
|
return(color_argb);
|
2019-01-25 21:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 15:21:10 +00:00
|
|
|
internal u32
|
2019-09-04 05:31:35 +00:00
|
|
|
get_token_color(Color_Table color_table, Token token){
|
2018-11-27 15:21:10 +00:00
|
|
|
u32 result = 0;
|
|
|
|
if ((token.flags & CPP_TFLAG_IS_KEYWORD) != 0){
|
2019-02-05 01:06:48 +00:00
|
|
|
if (cpp_token_category_from_type(token.type) == CPP_TOKEN_CAT_BOOLEAN_CONSTANT){
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Bool_Constant];
|
2018-11-27 15:21:10 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Keyword];
|
2018-11-27 15:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((token.flags & CPP_TFLAG_PP_DIRECTIVE) != 0){
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Preproc];
|
2018-11-27 15:21:10 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
switch (token.type){
|
|
|
|
case CPP_TOKEN_COMMENT:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Comment];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
case CPP_TOKEN_STRING_CONSTANT:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Str_Constant];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
case CPP_TOKEN_CHARACTER_CONSTANT:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Char_Constant];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
case CPP_TOKEN_INTEGER_CONSTANT:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Int_Constant];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
case CPP_TOKEN_FLOATING_CONSTANT:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Float_Constant];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
case CPP_PP_INCLUDE_FILE:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Include];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
default:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
result = color_table.vals[Stag_Default];
|
2018-11-27 15:21:10 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
internal void
|
|
|
|
view_quit_ui(System_Functions *system, Models *models, View *view){
|
|
|
|
Assert(view != 0);
|
|
|
|
view->ui_mode = false;
|
|
|
|
if (view->ui_quit != 0){
|
|
|
|
view->ui_quit(&models->app_links, view_get_id(&models->live_set, view));
|
|
|
|
view->ui_quit = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
internal View*
|
|
|
|
imp_get_view(Models *models, View_ID view_id){
|
|
|
|
Live_Views *live_set = &models->live_set;
|
|
|
|
View *view = 0;
|
|
|
|
view_id -= 1;
|
|
|
|
if (0 <= view_id && view_id < live_set->max){
|
|
|
|
view = live_set->views + view_id;
|
|
|
|
if (!view->in_use){
|
|
|
|
view = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
#if 0
|
2018-09-22 23:45:24 +00:00
|
|
|
internal void
|
2018-09-30 12:14:47 +00:00
|
|
|
render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *view,
|
2019-09-02 18:59:36 +00:00
|
|
|
Rect_i32 rect,
|
|
|
|
Full_Cursor render_cursor,
|
|
|
|
Interval_i64 on_screen_range,
|
|
|
|
Buffer_Layout_Item_List list,
|
|
|
|
int_color *item_colors){
|
2018-09-30 12:14:47 +00:00
|
|
|
Cpp_Token_Array token_array = file->state.token_array;
|
2019-08-04 05:36:13 +00:00
|
|
|
b32 tokens_use = (token_array.tokens != 0);
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 token_i = 0;
|
2018-09-22 23:45:24 +00:00
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
u32 main_color = color_table.vals[Stag_Default];
|
|
|
|
u32 special_color = color_table.vals[Stag_Special_Character];
|
|
|
|
u32 ghost_color = color_table.vals[Stag_Ghost_Character];
|
2018-03-24 10:06:45 +00:00
|
|
|
if (tokens_use){
|
2019-09-02 18:59:36 +00:00
|
|
|
Cpp_Get_Token_Result result = cpp_get_token(token_array, (i32)items->index);
|
2019-02-25 23:42:13 +00:00
|
|
|
main_color = get_token_color(color_table, token_array.tokens[result.token_index]);
|
2018-03-24 10:06:45 +00:00
|
|
|
token_i = result.token_index + 1;
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
{
|
|
|
|
i64 ind = item->index;
|
2018-09-22 23:45:24 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Token scanning
|
2018-09-22 00:29:32 +00:00
|
|
|
u32 highlight_this_color = 0;
|
2018-03-24 10:06:45 +00:00
|
|
|
if (tokens_use && ind != prev_ind){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token current_token = token_array.tokens[token_i-1];
|
2018-03-24 10:06:45 +00:00
|
|
|
|
|
|
|
if (token_i < token_array.count){
|
|
|
|
if (ind >= token_array.tokens[token_i].start){
|
|
|
|
for (;token_i < token_array.count && ind >= token_array.tokens[token_i].start; ++token_i){
|
2019-02-25 23:42:13 +00:00
|
|
|
main_color = get_token_color(color_table, token_array.tokens[token_i]);
|
2018-03-24 10:06:45 +00:00
|
|
|
current_token = token_array.tokens[token_i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ind >= current_token.start + current_token.size){
|
2019-02-25 23:42:13 +00:00
|
|
|
main_color = color_table.vals[Stag_Default];
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_token.type == CPP_TOKEN_JUNK && ind >= current_token.start && ind < current_token.start + current_token.size){
|
2019-02-25 23:42:13 +00:00
|
|
|
highlight_color = color_table.vals[Stag_Highlight_Junk];
|
2018-03-24 10:06:45 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
highlight_color = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
u32 char_color = main_color;
|
|
|
|
if (on_screen_range.min <= ind && ind < on_screen_range.max){
|
|
|
|
i64 index_shifted = ind - on_screen_range.min;
|
|
|
|
if (item_colors[index_shifted] != 0){
|
|
|
|
char_color = finalize_color(color_table, item_colors[index_shifted]);
|
2018-12-17 04:31:04 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
}
|
|
|
|
if (HasFlag(item->flags, BRFlag_Special_Character)){
|
|
|
|
char_color = special_color;
|
|
|
|
}
|
|
|
|
else if (HasFlag(item->flags, BRFlag_Ghost_Character)){
|
|
|
|
char_color = ghost_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->show_whitespace && highlight_color == 0 && codepoint_is_whitespace(item->codepoint)){
|
|
|
|
highlight_this_color = color_table.vals[Stag_Highlight_White];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
highlight_this_color = highlight_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Perform highlight, wireframe, and ibar renders
|
|
|
|
u32 color_highlight = 0;
|
|
|
|
u32 color_wireframe = 0;
|
|
|
|
u32 color_ibar = 0;
|
|
|
|
|
|
|
|
if (highlight_this_color != 0){
|
|
|
|
if (color_highlight == 0){
|
|
|
|
color_highlight = highlight_this_color;
|
2018-12-17 04:31:04 +00:00
|
|
|
}
|
2018-09-22 00:29:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
if (color_highlight != 0){
|
|
|
|
draw_rectangle(target, char_rect, color_highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 fade_color = 0xFFFF00FF;
|
|
|
|
f32 fade_amount = 0.f;
|
|
|
|
if (file->state.paste_effect.seconds_down > 0.f &&
|
|
|
|
file->state.paste_effect.start <= ind &&
|
|
|
|
ind < file->state.paste_effect.end){
|
|
|
|
fade_color = file->state.paste_effect.color;
|
|
|
|
fade_amount = file->state.paste_effect.seconds_down;
|
|
|
|
fade_amount /= file->state.paste_effect.seconds_max;
|
|
|
|
}
|
|
|
|
char_color = color_blend(char_color, fade_amount, fade_color);
|
|
|
|
|
|
|
|
if (color_wireframe != 0){
|
|
|
|
draw_rectangle_outline(target, char_rect, color_wireframe);
|
2019-04-05 23:30:24 +00:00
|
|
|
}
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
2019-09-02 18:59:36 +00:00
|
|
|
|
2019-02-26 19:59:57 +00:00
|
|
|
}
|
2017-07-17 23:35:13 +00:00
|
|
|
|
2019-09-02 18:59:36 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-17 23:35:13 +00:00
|
|
|
// BOTTOM
|
|
|
|
|