Finished the reorganization of the codebase to break up 4ed_view.cpp
This commit is contained in:
parent
40b5e61e91
commit
4915ed36fd
|
@ -96,6 +96,9 @@ FSTRING_INLINE String make_string(void *str, i32_4tech size);
|
|||
#ifndef make_lit_string
|
||||
# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s)))
|
||||
#endif
|
||||
#ifndef lit
|
||||
# define lit(s) make_lit_string(s)
|
||||
#endif
|
||||
#ifndef make_fixed_width_string
|
||||
# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s)))
|
||||
#endif
|
||||
|
|
7
4ed.cpp
7
4ed.cpp
|
@ -323,7 +323,7 @@ inline void
|
|||
do_feedback_message(System_Functions *system, Models *models, String value, b32 set_to_start = 0){
|
||||
Editing_File *file = models->message_buffer;
|
||||
|
||||
if (file){
|
||||
if (file != 0){
|
||||
output_file_append(system, models, file, value);
|
||||
i32 pos = 0;
|
||||
if (!set_to_start){
|
||||
|
@ -348,7 +348,6 @@ do_feedback_message(System_Functions *system, Models *models, String value, b32
|
|||
#define USE_VARS(n) App_Vars *n = command->vars
|
||||
#define USE_FILE(n,v) Editing_File *n = (v)->file_data.file
|
||||
|
||||
|
||||
#define USE_PANEL(n) Panel *n = 0; do{ \
|
||||
i32 panel_index = command->models->layout.active_panel; \
|
||||
n = command->models->layout.panels + panel_index; \
|
||||
|
@ -370,7 +369,7 @@ do_feedback_message(System_Functions *system, Models *models, String value, b32
|
|||
internal View*
|
||||
panel_make_empty(System_Functions *system, Models *models, Panel *panel){
|
||||
Assert(panel->view == 0);
|
||||
View_And_ID new_view = live_set_alloc_view(&models->live_set, panel, models);
|
||||
View_And_ID new_view = live_set_alloc_view(&models->mem.general, &models->live_set, panel);
|
||||
view_set_file(system, models, new_view.view, models->scratch_buffer);
|
||||
new_view.view->transient.map = models->scratch_buffer->settings.base_map_id;
|
||||
return(new_view.view);
|
||||
|
@ -2059,7 +2058,7 @@ App_Step_Sig(app_step){
|
|||
|
||||
view->transient.changed_context_in_step = 0;
|
||||
|
||||
View_Step_Result result = step_file_view(system, view, models, active_view, summary);
|
||||
View_Step_Result result = step_view(system, view, models, active_view, summary);
|
||||
|
||||
if (result.animating){
|
||||
app_result.animating = 1;
|
||||
|
|
|
@ -1692,12 +1692,12 @@ in the system, the call will fail.)
|
|||
Models *models = cmd->models;
|
||||
View *vptr = imp_get_view(cmd, view);
|
||||
|
||||
bool32 result = 0;
|
||||
bool32 result = false;
|
||||
|
||||
if (vptr != 0 && models->layout.panel_count > 1){
|
||||
Panel *panel = vptr->transient.panel;
|
||||
|
||||
live_set_free_view(&models->live_set, vptr, models);
|
||||
live_set_free_view(&models->mem.general, &models->live_set, vptr);
|
||||
panel->view = 0;
|
||||
|
||||
Divider_And_ID div = layout_get_divider(&models->layout, panel->parent);
|
||||
|
@ -2255,14 +2255,6 @@ DOC(This call posts a string to the *messages* buffer.)
|
|||
do_feedback_message(cmd->system, models, make_string(str, len));
|
||||
}
|
||||
|
||||
internal void
|
||||
style_set_colors(Style *style, Theme *theme){
|
||||
for (u32 i = 0; i < Stag_COUNT; ++i){
|
||||
u32 *color_ptr = style_index_by_tag(&style->main, i);
|
||||
*color_ptr = theme->colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
API_EXPORT void
|
||||
Create_Theme(Application_Links *app, Theme *theme, char *name, int32_t len)
|
||||
/*
|
||||
|
|
|
@ -75,11 +75,14 @@
|
|||
#include "4ed_file.cpp"
|
||||
#include "4ed_code_wrap.cpp"
|
||||
#include "4ed_working_set.cpp"
|
||||
#include "4ed_style.cpp"
|
||||
#include "4ed_hot_directory.cpp"
|
||||
#include "4ed_cli.cpp"
|
||||
#include "4ed_gui.cpp"
|
||||
#include "4ed_layout.cpp"
|
||||
#include "4ed_view.cpp"
|
||||
#include "4ed_edit.cpp"
|
||||
#include "4ed_view_ui.cpp"
|
||||
#include "4ed.cpp"
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -0,0 +1,401 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 25.03.2018
|
||||
*
|
||||
* High level edit procedures
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
inline void
|
||||
edit_pre_maintenance(System_Functions *system, General_Memory *general, Editing_File *file){
|
||||
if (file->state.still_lexing){
|
||||
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
|
||||
if (file->state.swap_array.tokens){
|
||||
general_memory_free(general, file->state.swap_array.tokens);
|
||||
file->state.swap_array.tokens = 0;
|
||||
}
|
||||
file->state.still_lexing = 0;
|
||||
}
|
||||
if (file->state.dirty == DirtyState_UpToDate){
|
||||
file_set_dirty_flag(file, DirtyState_UnsavedChanges);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
edit_fix_marks(System_Functions *system, Models *models, Editing_File *file, Editing_Layout *layout, Cursor_Fix_Descriptor desc){
|
||||
|
||||
Partition *part = &models->mem.part;
|
||||
|
||||
Temp_Memory cursor_temp = begin_temp_memory(part);
|
||||
i32 cursor_max = layout->panel_max_count * 3;
|
||||
cursor_max += file->markers.marker_count;
|
||||
Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max);
|
||||
Cursor_With_Index *r_cursors = push_array(part, Cursor_With_Index, cursor_max);
|
||||
Assert(cursors != 0);
|
||||
|
||||
i32 cursor_count = 0;
|
||||
i32 r_cursor_count = 0;
|
||||
|
||||
for (Panel *panel = layout->used_sentinel.next;
|
||||
panel != &layout->used_sentinel;
|
||||
panel = panel->next){
|
||||
View *view = panel->view;
|
||||
if (view->transient.file_data.file == file){
|
||||
Assert(view->transient.edit_pos != 0);
|
||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->cursor.pos);
|
||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->mark);
|
||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->scroll_i);
|
||||
}
|
||||
}
|
||||
|
||||
for (Marker_Array *marker_it = file->markers.sentinel.next;
|
||||
marker_it != &file->markers.sentinel;
|
||||
marker_it = marker_it->next){
|
||||
u32 count = marker_it->count;
|
||||
Marker *markers = MarkerArrayBase(marker_it);
|
||||
for (u32 i = 0; i < count; ++i){
|
||||
if (markers[i].lean_right){
|
||||
write_cursor_with_index(r_cursors, &r_cursor_count, markers[i].pos);
|
||||
}
|
||||
else{
|
||||
write_cursor_with_index(cursors, &cursor_count, markers[i].pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor_count > 0 || r_cursor_count > 0){
|
||||
buffer_sort_cursors(cursors, cursor_count);
|
||||
if (desc.is_batch){
|
||||
buffer_batch_edit_update_cursors(cursors, cursor_count, desc.batch, desc.batch_size, false);
|
||||
buffer_batch_edit_update_cursors(r_cursors, r_cursor_count, desc.batch, desc.batch_size, true);
|
||||
}
|
||||
else{
|
||||
buffer_update_cursors(cursors, cursor_count, desc.start, desc.end, desc.shift_amount + (desc.end - desc.start), false);
|
||||
buffer_update_cursors(r_cursors, r_cursor_count, desc.start, desc.end, desc.shift_amount + (desc.end - desc.start), true);
|
||||
}
|
||||
buffer_unsort_cursors(cursors, cursor_count);
|
||||
|
||||
cursor_count = 0;
|
||||
r_cursor_count = 0;
|
||||
for (Panel *panel = layout->used_sentinel.next;
|
||||
panel != &layout->used_sentinel;
|
||||
panel = panel->next){
|
||||
View *view = panel->view;
|
||||
if (view->transient.file_data.file == file){
|
||||
Assert(view->transient.edit_pos != 0);
|
||||
|
||||
i32 cursor_pos = cursors[cursor_count++].pos;
|
||||
Editing_File *file = view->transient.file_data.file;
|
||||
Full_Cursor new_cursor = file_compute_cursor(system, file, seek_pos(cursor_pos), 0);
|
||||
|
||||
GUI_Scroll_Vars scroll = view->transient.edit_pos->scroll;
|
||||
|
||||
view->transient.edit_pos->mark = cursors[cursor_count++].pos;
|
||||
i32 new_scroll_i = cursors[cursor_count++].pos;
|
||||
if (view->transient.edit_pos->scroll_i != new_scroll_i){
|
||||
view->transient.edit_pos->scroll_i = new_scroll_i;
|
||||
|
||||
Full_Cursor temp_cursor = file_compute_cursor(system, file, seek_pos(view->transient.edit_pos->scroll_i), 0);
|
||||
|
||||
f32 y_offset = MOD(view->transient.edit_pos->scroll.scroll_y, view->transient.line_height);
|
||||
f32 y_position = temp_cursor.wrapped_y;
|
||||
if (file->settings.unwrapped_lines){
|
||||
y_position = temp_cursor.unwrapped_y;
|
||||
}
|
||||
y_position += y_offset;
|
||||
|
||||
scroll.target_y += round32(y_position - scroll.scroll_y);
|
||||
scroll.scroll_y = y_position;
|
||||
}
|
||||
|
||||
view_set_cursor_and_scroll(view, new_cursor, 1, view->transient.file_data.file->settings.unwrapped_lines, scroll);
|
||||
}
|
||||
}
|
||||
|
||||
for (Marker_Array *marker_it = file->markers.sentinel.next;
|
||||
marker_it != &file->markers.sentinel;
|
||||
marker_it = marker_it->next){
|
||||
u32 count = marker_it->count;
|
||||
Marker *markers = MarkerArrayBase(marker_it);
|
||||
for (u32 i = 0; i < count; ++i){
|
||||
if (markers[i].lean_right){
|
||||
markers[i].pos = r_cursors[r_cursor_count++].pos;
|
||||
}
|
||||
else{
|
||||
markers[i].pos = cursors[cursor_count++].pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_temp_memory(cursor_temp);
|
||||
}
|
||||
|
||||
internal void
|
||||
edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
|
||||
Edit_Spec spec, History_Mode history_mode){
|
||||
|
||||
Mem_Options *mem = &models->mem;
|
||||
Editing_Layout *layout = &models->layout;
|
||||
|
||||
// NOTE(allen): fixing stuff beforewards????
|
||||
file_update_history_before_edit(mem, file, spec.step, spec.str, history_mode);
|
||||
edit_pre_maintenance(system, &mem->general, file);
|
||||
|
||||
// NOTE(allen): actual text replacement
|
||||
i32 shift_amount = 0;
|
||||
General_Memory *general = &mem->general;
|
||||
Partition *part = &mem->part;
|
||||
|
||||
char *str = (char*)spec.str;
|
||||
i32 start = spec.step.edit.start;
|
||||
i32 end = spec.step.edit.end;
|
||||
i32 str_len = spec.step.edit.len;
|
||||
|
||||
i32 scratch_size = partition_remaining(part);
|
||||
|
||||
Assert(scratch_size > 0);
|
||||
i32 request_amount = 0;
|
||||
Assert(end <= buffer_size(&file->state.buffer));
|
||||
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){
|
||||
void *new_data = 0;
|
||||
if (request_amount > 0){
|
||||
new_data = general_memory_allocate(general, request_amount);
|
||||
}
|
||||
void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount);
|
||||
if (old_data){
|
||||
general_memory_free(general, old_data);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(allen): token fixing
|
||||
if (file->settings.tokens_exist){
|
||||
if (!file->settings.virtual_white){
|
||||
file_relex_parallel(system, models, file, start, end, shift_amount);
|
||||
}
|
||||
else{
|
||||
file_relex_serial(models, file, start, end, shift_amount);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(allen): meta data
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 line_start = buffer_get_line_number(&file->state.buffer, start);
|
||||
i32 line_end = buffer_get_line_number(&file->state.buffer, end);
|
||||
i32 replaced_line_count = line_end - line_start;
|
||||
i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len);
|
||||
i32 line_shift = new_line_count - replaced_line_count;
|
||||
|
||||
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
||||
Assert(font.valid);
|
||||
|
||||
file_grow_starts_as_needed(general, buffer, line_shift);
|
||||
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
|
||||
|
||||
file_allocate_character_starts_as_needed(general, file);
|
||||
buffer_remeasure_character_starts(system, font, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
|
||||
|
||||
file_measure_wraps(system, &models->mem, file, font);
|
||||
|
||||
// NOTE(allen): cursor fixing
|
||||
Cursor_Fix_Descriptor desc = {0};
|
||||
desc.start = start;
|
||||
desc.end = end;
|
||||
desc.shift_amount = shift_amount;
|
||||
edit_fix_marks(system, models, file, layout, desc);
|
||||
}
|
||||
|
||||
inline void
|
||||
edit_single(System_Functions *system, Models *models, Editing_File *file,
|
||||
i32 start, i32 end, char *str, i32 len){
|
||||
Edit_Spec spec = {};
|
||||
spec.step.type = ED_NORMAL;
|
||||
spec.step.edit.start = start;
|
||||
spec.step.edit.end = end;
|
||||
spec.step.edit.len = len;
|
||||
spec.str = (u8*)str;
|
||||
edit_single__inner(system, models, file, spec,
|
||||
hist_normal);
|
||||
}
|
||||
|
||||
internal Edit_Spec
|
||||
edit_compute_batch_spec(General_Memory *general,
|
||||
Editing_File *file,
|
||||
Buffer_Edit *edits, char *str_base, i32 str_size,
|
||||
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count, i32 batch_type){
|
||||
|
||||
i32 inv_str_pos = 0;
|
||||
Buffer_Invert_Batch state = {};
|
||||
if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count,
|
||||
inverse_array, inv_str, &inv_str_pos, inv_max)){
|
||||
InvalidCodePath;
|
||||
}
|
||||
|
||||
i32 first_child = undo_children_push(general, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size);
|
||||
i32 inverse_first_child = undo_children_push(general, &file->state.undo.children, inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
|
||||
|
||||
Edit_Spec spec = {};
|
||||
spec.step.type = ED_NORMAL;
|
||||
spec.step.first_child = first_child;
|
||||
spec.step.inverse_first_child = inverse_first_child;
|
||||
spec.step.special_type = batch_type;
|
||||
spec.step.child_count = edit_count;
|
||||
spec.step.inverse_child_count = edit_count;
|
||||
return(spec);
|
||||
}
|
||||
|
||||
internal void
|
||||
edit_batch(System_Functions *system, Models *models, Editing_File *file,
|
||||
Edit_Spec spec, History_Mode history_mode, Buffer_Batch_Edit_Type batch_type){
|
||||
|
||||
Mem_Options *mem = &models->mem;
|
||||
General_Memory *general = &mem->general;
|
||||
Partition *part = &mem->part;
|
||||
Editing_Layout *layout = &models->layout;
|
||||
|
||||
// NOTE(allen): fixing stuff "beforewards"???
|
||||
Assert(spec.str == 0);
|
||||
file_update_history_before_edit(mem, file, spec.step, 0, history_mode);
|
||||
edit_pre_maintenance(system, &mem->general, file);
|
||||
|
||||
// NOTE(allen): actual text replacement
|
||||
u8 *str_base = file->state.undo.children.strings;
|
||||
i32 batch_size = spec.step.child_count;
|
||||
Buffer_Edit *batch = file->state.undo.children.edits + spec.step.first_child;
|
||||
|
||||
Assert(spec.step.first_child < file->state.undo.children.edit_count);
|
||||
Assert(batch_size >= 0);
|
||||
|
||||
i32 scratch_size = partition_remaining(part);
|
||||
Buffer_Batch_State state = {};
|
||||
i32 request_amount = 0;
|
||||
while (buffer_batch_edit_step(&state, &file->state.buffer, batch,
|
||||
(char*)str_base, batch_size, part->base + part->pos,
|
||||
scratch_size, &request_amount)){
|
||||
void *new_data = 0;
|
||||
if (request_amount > 0){
|
||||
new_data = general_memory_allocate(general, request_amount);
|
||||
}
|
||||
void *old_data = buffer_edit_provide_memory(&file->state.buffer, new_data, request_amount);
|
||||
if (old_data){
|
||||
general_memory_free(general, old_data);
|
||||
}
|
||||
}
|
||||
|
||||
i32 shift_total = state.shift_total;
|
||||
|
||||
// NOTE(allen): token fixing
|
||||
switch (batch_type){
|
||||
case BatchEdit_Normal:
|
||||
{
|
||||
if (file->settings.tokens_exist){
|
||||
// TODO(allen): Write a smart fast one here someday.
|
||||
Buffer_Edit *first_edit = batch;
|
||||
Buffer_Edit *last_edit = batch + batch_size - 1;
|
||||
|
||||
if (!file->settings.virtual_white){
|
||||
file_relex_parallel(system, models, file, first_edit->start, last_edit->end, shift_total);
|
||||
}
|
||||
else{
|
||||
file_relex_serial(models, file, first_edit->start, last_edit->end, shift_total);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
|
||||
case BatchEdit_PreserveTokens:
|
||||
{
|
||||
if (file->state.tokens_complete){
|
||||
Cpp_Token_Array tokens = file->state.token_array;
|
||||
Cpp_Token *token = tokens.tokens;
|
||||
Cpp_Token *end_token = tokens.tokens + tokens.count;
|
||||
Cpp_Token original = {(Cpp_Token_Type)0};
|
||||
|
||||
Buffer_Edit *edit = batch;
|
||||
Buffer_Edit *end_edit = batch + batch_size;
|
||||
|
||||
i32 shift_amount = 0;
|
||||
i32 local_shift = 0;
|
||||
|
||||
for (; token < end_token; ++token){
|
||||
original = *token;
|
||||
for (; edit < end_edit && edit->start <= original.start; ++edit){
|
||||
local_shift = (edit->len - (edit->end - edit->start));
|
||||
shift_amount += local_shift;
|
||||
}
|
||||
token->start += shift_amount;
|
||||
local_shift = 0;
|
||||
for (; edit < end_edit && edit->start < original.start + original.size; ++edit){
|
||||
local_shift += (edit->len - (edit->end - edit->start));
|
||||
}
|
||||
token->size += local_shift;
|
||||
shift_amount += local_shift;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
||||
// TODO(allen): Let's try to switch to remeasuring here moron!
|
||||
// We'll need to get the total shift from the actual batch edit state
|
||||
// instead of from the cursor fixing. The only reason we're getting
|
||||
// it from cursor fixing is because you're a lazy asshole.
|
||||
|
||||
// NOTE(allen): meta data
|
||||
file_measure_starts(general, &file->state.buffer);
|
||||
|
||||
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
||||
Assert(font.valid);
|
||||
|
||||
// TODO(allen): write the remeasurement version
|
||||
file_allocate_character_starts_as_needed(general, file);
|
||||
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
|
||||
|
||||
file_measure_wraps(system, &models->mem, file, font);
|
||||
|
||||
// NOTE(allen): cursor fixing
|
||||
Cursor_Fix_Descriptor desc = {0};
|
||||
desc.is_batch = 1;
|
||||
desc.batch = batch;
|
||||
desc.batch_size = batch_size;
|
||||
edit_fix_marks(system, models, file, layout, desc);
|
||||
}
|
||||
|
||||
inline void
|
||||
edit_clear(System_Functions *system, Models *models, Editing_File *file){
|
||||
if (models->hook_end_file != 0){
|
||||
models->hook_end_file(&models->app_links, file->id.id);
|
||||
}
|
||||
edit_single(system, models, file,
|
||||
0, buffer_size(&file->state.buffer), 0, 0);
|
||||
}
|
||||
|
||||
internal void
|
||||
edit_historical(System_Functions *system, Models *models, Editing_File *file, View *view, Edit_Stack *stack,
|
||||
Edit_Step step, History_Mode history_mode){
|
||||
Edit_Spec spec = {};
|
||||
spec.step = step;
|
||||
|
||||
if (step.child_count == 0){
|
||||
spec.step.edit.str_start = 0;
|
||||
spec.str = stack->strings + step.edit.str_start;
|
||||
|
||||
edit_single__inner(system, models, file,
|
||||
spec, history_mode);
|
||||
|
||||
if (view != 0){
|
||||
view_cursor_move(system, view, step.edit.start + step.edit.len);
|
||||
view->transient.edit_pos->mark = view->transient.edit_pos->cursor.pos;
|
||||
|
||||
Style *style = &models->styles.styles[0];
|
||||
view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->main.undo_color);
|
||||
}
|
||||
}
|
||||
else{
|
||||
edit_batch(system, models, view->transient.file_data.file, spec, hist_normal, spec.step.special_type);
|
||||
}
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
66
4ed_gui.cpp
66
4ed_gui.cpp
|
@ -9,6 +9,14 @@
|
|||
|
||||
// TOP
|
||||
|
||||
internal GUI_id
|
||||
gui_id(u64 a, u64 b){
|
||||
GUI_id id;
|
||||
id.id[0] = a;
|
||||
id.id[1] = b;
|
||||
return(id);
|
||||
}
|
||||
|
||||
internal void
|
||||
init_query_set(Query_Set *set){
|
||||
Query_Slot *slot = set->slots;
|
||||
|
@ -816,54 +824,59 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
if (!session->is_scrollable) scroll_v = 0;
|
||||
|
||||
switch (h->type){
|
||||
case guicom_null: Assert(0); break;
|
||||
case guicom_null: InvalidCodePath;
|
||||
|
||||
case guicom_begin_serial:
|
||||
{
|
||||
++session->t;
|
||||
Assert(session->t < ArrayCount(session->sections));
|
||||
new_section = &session->sections[session->t];
|
||||
new_section->v = y;
|
||||
new_section->max_v = y;
|
||||
new_section->top_v = y;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_end_serial:
|
||||
{
|
||||
Assert(session->t > 0);
|
||||
prev_section = &session->sections[--session->t];
|
||||
end_v = section->max_v;
|
||||
end_section = prev_section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_top_bar:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_fixed_h(session, y, session->line_height + 2);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_file:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_top_bottom(session, y, session->full_rect.y1);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
scroll_v = 0;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_text_with_cursor:
|
||||
case guicom_text_field:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_fixed_h(session, y, session->line_height + 2);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_color_button:
|
||||
case guicom_font_button:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_fixed_h(session, y, session->line_height + 2);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_begin_list:
|
||||
{
|
||||
|
@ -883,10 +896,11 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
}break;
|
||||
|
||||
case guicom_end_list:
|
||||
{
|
||||
Assert(session->list.in_list == 1);
|
||||
session->list.in_list = 0;
|
||||
target->list_max = session->list.index;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_file_option:
|
||||
case guicom_fixed_option:
|
||||
|
@ -915,25 +929,27 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
}break;
|
||||
|
||||
case guicom_button:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_fixed_h(session, y, session->line_height * 2);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_style_preview:
|
||||
{
|
||||
give_to_user = 1;
|
||||
rect = gui_layout_fixed_h(session, y, session->line_height * 3 + 6);
|
||||
end_v = rect.y1;
|
||||
end_section = section;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable:
|
||||
{
|
||||
Assert(session->is_scrollable == 0);
|
||||
session->is_scrollable = 1;
|
||||
always_give_to_user = 1;
|
||||
|
||||
{
|
||||
i32_Rect scrollable_rect = {0};
|
||||
scrollable_rect.x0 = session->full_rect.x0;
|
||||
scrollable_rect.x1 = session->full_rect.x1;
|
||||
|
@ -942,10 +958,10 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
result.has_region = 1;
|
||||
result.region = scrollable_rect;
|
||||
session->scroll_region = scrollable_rect;
|
||||
}
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable_bar:
|
||||
{
|
||||
Assert(session->is_scrollable);
|
||||
give_to_user = 1;
|
||||
rect.x1 = session->full_rect.x1;
|
||||
|
@ -954,7 +970,6 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
rect.y1 = session->full_rect.y1;
|
||||
session->scroll_rect = rect;
|
||||
|
||||
{
|
||||
i32_Rect scrollable_rect = {0};
|
||||
scrollable_rect.x0 = session->full_rect.x0;
|
||||
scrollable_rect.x1 = rect.x0;
|
||||
|
@ -963,18 +978,19 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
result.has_region = 1;
|
||||
result.region = scrollable_rect;
|
||||
session->scroll_region = scrollable_rect;
|
||||
}
|
||||
scroll_v = 0;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable_top:
|
||||
{
|
||||
Assert(session->is_scrollable);
|
||||
give_to_user = 1;
|
||||
gui_scrollbar_top(session->scroll_rect, &rect);
|
||||
scroll_v = 0;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable_slider:
|
||||
{
|
||||
Assert(session->is_scrollable);
|
||||
give_to_user = 1;
|
||||
|
||||
|
@ -987,34 +1003,38 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
|
|||
&session->scroll_top, &session->scroll_bottom,
|
||||
0, max_y);
|
||||
scroll_v = 0;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable_invisible:
|
||||
{
|
||||
Assert(session->is_scrollable);
|
||||
always_give_to_user = 1;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_scrollable_bottom:
|
||||
{
|
||||
Assert(session->is_scrollable);
|
||||
give_to_user = 1;
|
||||
gui_scrollbar_bottom(session->scroll_rect, &rect);
|
||||
scroll_v = 0;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_begin_scrollable_section:
|
||||
{
|
||||
always_give_to_user = 1;
|
||||
session->scrollable_items_bottom = 0;
|
||||
rect = gui_layout_top_bottom(session, y, session->full_rect.y1);
|
||||
end_v = rect.y1;
|
||||
break;
|
||||
}break;
|
||||
|
||||
case guicom_end_scrollable_section:
|
||||
{
|
||||
always_give_to_user = 1;
|
||||
session->suggested_max_y = ceil32(session->scrollable_items_bottom - (session->full_rect.y0 + session->full_rect.y1)*.5f);
|
||||
if (session->suggested_max_y < 0){
|
||||
session->suggested_max_y = 0;
|
||||
}
|
||||
break;
|
||||
}break;
|
||||
}
|
||||
|
||||
if (do_layout){
|
||||
|
|
56
4ed_gui.h
56
4ed_gui.h
|
@ -9,60 +9,11 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#ifndef FCODER_GUI_H
|
||||
#define FCODER_GUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef FRED_GUI_H
|
||||
#define FRED_GUI_H
|
||||
|
||||
struct GUI_id{
|
||||
uint64_t id[2];
|
||||
};
|
||||
inline GUI_id
|
||||
gui_id_zero(){
|
||||
GUI_id id = {0};
|
||||
return(id);
|
||||
}
|
||||
|
||||
typedef struct GUI GUI;
|
||||
|
||||
#define GUI_BEGIN_SIG(n) void n(GUI *gui)
|
||||
#define GUI_END_SIG(n) void n(GUI *gui)
|
||||
|
||||
#define GUI_TOP_BAR_SIG(n) void n(GUI *gui)
|
||||
|
||||
// TODO(allen): Do we want to break this call
|
||||
// down a little more? I think maybe we do.
|
||||
#define GUI_GET_SCROLL_VARS_SIG(n) void n(GUI *gui, GUI_id scroll_id, GUI_Scroll_Vars *vars, i32_Rect *region)
|
||||
|
||||
#define GUI_BEGIN_SCROLLABLE_SIG(n) int32_t n(GUI *gui, GUI_id scroll_id, GUI_Scroll_Vars vars, float delta, int32_t show_scrollbar)
|
||||
#define GUI_END_SCROLLABLE_SIG(n) void n(GUI *gui)
|
||||
|
||||
#define GUI_FILE_SIG(n) void n(GUI *gui, int32_t buffer_id)
|
||||
|
||||
typedef GUI_BEGIN_SIG(GUI_Begin_Function);
|
||||
typedef GUI_END_SIG(GUI_End_Function);
|
||||
|
||||
typedef GUI_TOP_BAR_SIG(GUI_Top_Bar_Function);
|
||||
|
||||
typedef GUI_GET_SCROLL_VARS_SIG(GUI_Get_Scroll_Vars_Function);
|
||||
|
||||
typedef GUI_BEGIN_SCROLLABLE_SIG(GUI_Begin_Scrollable_Function);
|
||||
typedef GUI_END_SCROLLABLE_SIG(GUI_End_Scrollable_Function);
|
||||
|
||||
typedef GUI_FILE_SIG(GUI_File_Function);
|
||||
|
||||
struct GUI_Functions{
|
||||
GUI_Begin_Function *begin;
|
||||
GUI_End_Function *end;
|
||||
|
||||
GUI_Top_Bar_Function *top_bar;
|
||||
|
||||
GUI_Get_Scroll_Vars_Function *get_scroll_vars;
|
||||
|
||||
GUI_Begin_Scrollable_Function *begin_scrollable;
|
||||
GUI_End_Scrollable_Function *end_scrollable;
|
||||
|
||||
GUI_File_Function *file;
|
||||
u64 id[2];
|
||||
};
|
||||
|
||||
struct Query_Slot{
|
||||
|
@ -148,7 +99,6 @@ enum GUI_Command_Type{
|
|||
guicom_file,
|
||||
guicom_text_field,
|
||||
guicom_color_button,
|
||||
guicom_font_button,
|
||||
guicom_text_with_cursor,
|
||||
guicom_begin_list,
|
||||
guicom_end_list,
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 25.03.2018
|
||||
*
|
||||
* Styles
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
internal void
|
||||
style_set_colors(Style *style, Theme *theme){
|
||||
for (u32 i = 0; i < Stag_COUNT; ++i){
|
||||
u32 *color_ptr = style_index_by_tag(&style->main, i);
|
||||
*color_ptr = theme->colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
internal u32
|
||||
style_get_margin_color(i32 active_level, Style *style){
|
||||
u32 margin = 0xFFFFFFFF;
|
||||
|
||||
switch (active_level){
|
||||
default:
|
||||
{
|
||||
margin = style->main.list_item_color;
|
||||
}break;
|
||||
|
||||
case 1: case 2:
|
||||
{
|
||||
margin = style->main.list_item_hover_color;
|
||||
}break;
|
||||
|
||||
case 3: case 4:
|
||||
{
|
||||
margin = style->main.list_item_active_color;
|
||||
}break;
|
||||
}
|
||||
|
||||
return(margin);
|
||||
}
|
||||
|
||||
internal u32*
|
||||
style_get_color(Style *style, Cpp_Token token){
|
||||
u32 *result = 0;
|
||||
if ((token.flags & CPP_TFLAG_IS_KEYWORD) != 0){
|
||||
if (token.type == CPP_TOKEN_BOOLEAN_CONSTANT){
|
||||
result = &style->main.bool_constant_color;
|
||||
}
|
||||
else{
|
||||
result = &style->main.keyword_color;
|
||||
}
|
||||
}
|
||||
else if ((token.flags & CPP_TFLAG_PP_DIRECTIVE) != 0){
|
||||
result = &style->main.preproc_color;
|
||||
}
|
||||
else{
|
||||
switch (token.type){
|
||||
case CPP_TOKEN_COMMENT:
|
||||
{
|
||||
result = &style->main.comment_color;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_STRING_CONSTANT:
|
||||
{
|
||||
result = &style->main.str_constant_color;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_CHARACTER_CONSTANT:
|
||||
{
|
||||
result = &style->main.char_constant_color;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_INTEGER_CONSTANT:
|
||||
{
|
||||
result = &style->main.int_constant_color;
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_FLOATING_CONSTANT:
|
||||
{
|
||||
result = &style->main.float_constant_color;
|
||||
}break;
|
||||
|
||||
case CPP_PP_INCLUDE_FILE:
|
||||
{
|
||||
result = &style->main.include_color;
|
||||
}break;
|
||||
|
||||
default:
|
||||
{
|
||||
result = &style->main.default_color;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
Assert(result != 0);
|
||||
return(result);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
2699
4ed_view.cpp
2699
4ed_view.cpp
File diff suppressed because it is too large
Load Diff
29
4ed_view.h
29
4ed_view.h
|
@ -42,6 +42,7 @@ enum Interactive_Action{
|
|||
|
||||
typedef i32 Unsaved_Changes_User_Response;
|
||||
enum{
|
||||
UnsavedChangesUserResponse_Error = -1,
|
||||
UnsavedChangesUserResponse_ContinueAnyway = 0,
|
||||
UnsavedChangesUserResponse_Cancel = 1,
|
||||
UnsavedChangesUserResponse_SaveAndContinue = 2,
|
||||
|
@ -113,7 +114,6 @@ struct View_Transient{
|
|||
b32 changed_context_in_step;
|
||||
|
||||
// theme stuff
|
||||
View *hot_file_view;
|
||||
u32 *palette;
|
||||
Color_View_Mode color_mode;
|
||||
Face_ID font_edit_id;
|
||||
|
@ -210,31 +210,14 @@ struct Cursor_Fix_Descriptor{
|
|||
};
|
||||
|
||||
struct File_Bar{
|
||||
f32 pos_x, pos_y;
|
||||
f32 text_shift_x, text_shift_y;
|
||||
f32 pos_x;
|
||||
f32 pos_y;
|
||||
f32 text_shift_x;
|
||||
f32 text_shift_y;
|
||||
i32_Rect rect;
|
||||
Face_ID font_id;
|
||||
};
|
||||
|
||||
struct Exhaustive_File_Loop{
|
||||
char front_name_[256];
|
||||
char full_path_[256];
|
||||
String front_name, full_path;
|
||||
|
||||
Absolutes absolutes;
|
||||
|
||||
File_Info *infos;
|
||||
i32 count, r;
|
||||
};
|
||||
|
||||
struct Exhaustive_File_Info{
|
||||
File_Info *info;
|
||||
String message;
|
||||
b8 is_folder;
|
||||
b8 name_match;
|
||||
b8 is_loaded;
|
||||
};
|
||||
|
||||
struct Style_Color_Edit{
|
||||
Style_Tag target;
|
||||
Style_Tag fore;
|
||||
|
@ -263,8 +246,6 @@ struct Single_Line_Mode{
|
|||
String *string;
|
||||
Hot_Directory *hot_directory;
|
||||
b32 fast_folder_select;
|
||||
b32 try_to_match;
|
||||
b32 case_sensitive;
|
||||
};
|
||||
|
||||
struct View_Step_Result{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -212,6 +212,10 @@ API_EXPORT_MACRO
|
|||
/* DOC(This macro takes a literal string in quotes and uses it to create a String with the correct size and memory size. Strings created this way should usually not be mutated.) */
|
||||
#define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s)))
|
||||
|
||||
API_EXPORT_MACRO
|
||||
/* DOC(Rename for make_lit_string.) DOC_SEE(make_lit_string) */
|
||||
#define lit(s) make_lit_string(s)
|
||||
|
||||
API_EXPORT_MACRO
|
||||
/* DOC(This macro takes a local char array with a fixed width and uses it to create an empty String with the correct size and memory size to operate on the array.) */
|
||||
#define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s)))
|
||||
|
|
Loading…
Reference in New Issue