4coder_handmade_hero.cpp ready to go

This commit is contained in:
Allen Webster 2016-03-05 03:10:43 -05:00
parent 6e1abb4237
commit d71d10434a
11 changed files with 1651 additions and 310 deletions

View File

@ -1,11 +1,8 @@
/* // Alternative customizations, set Custom_Current to select which to apply.
* Example use of customization API #define Custom_Default 0
*/ #define Custom_HandmadeHero 1
// NOTE(allen): See exec_command and surrounding code in 4coder_helper.h #define Custom_Current Custom_Default
// to decide whether you want macro translations, without them you will
// have to manipulate the command and parameter stack through
// "app->" which may be more or less clear depending on your use.
#include "4coder_custom.h" #include "4coder_custom.h"
@ -30,6 +27,23 @@ enum My_Maps{
HOOK_SIG(my_start){ HOOK_SIG(my_start){
exec_command(app, cmdid_open_panel_vsplit); exec_command(app, cmdid_open_panel_vsplit);
exec_command(app, cmdid_change_active_panel); exec_command(app, cmdid_change_active_panel);
app->change_theme(app, literal("4coder"));
app->change_font(app, literal("liberation mono"));
// Theme options:
// "4coder"
// "Handmade Hero"
// "Twilight"
// "Woverine"
// "stb"
// Font options:
// "liberation sans"
// "liberation mono"
// "hack"
// "cutive mono"
// "inconsolata"
} }
HOOK_SIG(my_file_settings){ HOOK_SIG(my_file_settings){
@ -367,8 +381,10 @@ isearch(Application_Links *app, int start_reversed){
int step_forward = 0; int step_forward = 0;
int step_backward = 0; int step_backward = 0;
if (CommandEqual(in.command, search)) step_forward = 1; if (CommandEqual(in.command, search) ||
if (CommandEqual(in.command, reverse_search)) step_backward = 1; in.key.keycode == key_page_down || in.key.keycode == key_down) step_forward = 1;
if (CommandEqual(in.command, reverse_search) ||
in.key.keycode == key_page_down || in.key.keycode == key_up) step_backward = 1;
int start_pos = pos; int start_pos = pos;
if (step_forward && reverse){ if (step_forward && reverse){
@ -682,7 +698,7 @@ CUSTOM_COMMAND_SIG(execute_arbitrary_command){
// as an example you have everything you need to make it work already. You could // as an example you have everything you need to make it work already. You could
// even use app->memory to create a hash table in the start hook. // even use app->memory to create a hash table in the start hook.
Query_Bar bar; Query_Bar bar;
char space[1024], more_space[1024]; char space[1024];
bar.prompt = make_lit_string("Command: "); bar.prompt = make_lit_string("Command: ");
bar.string = make_fixed_width_string(space); bar.string = make_fixed_width_string(space);
@ -700,20 +716,11 @@ CUSTOM_COMMAND_SIG(execute_arbitrary_command){
else if(match(bar.string, make_lit_string("close all code"))){ else if(match(bar.string, make_lit_string("close all code"))){
exec_command(app, close_all_code); exec_command(app, close_all_code);
} }
else if (match(bar.string, make_lit_string("open in quotes"))){
exec_command(app, open_file_in_quotes);
}
else if (match(bar.string, make_lit_string("open menu"))){ else if (match(bar.string, make_lit_string("open menu"))){
exec_command(app, cmdid_open_menu); exec_command(app, cmdid_open_menu);
} }
else{ else{
bar.prompt = make_fixed_width_string(more_space); // TODO(allen): feedback message
append(&bar.prompt, make_lit_string("Unrecognized: "));
append(&bar.prompt, bar.string);
bar.string.size = 0;
app->start_query_bar(app, &bar, 0);
app->get_user_input(app, EventOnAnyKey | EventOnButton, 0);
} }
} }
@ -840,6 +847,8 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
exec_command(app, cmdid_auto_tab_line_at_cursor); exec_command(app, cmdid_auto_tab_line_at_cursor);
} }
// NOTE(allen|a4) See 4coder_styles.h for a list of available style tags.
// There are style tags corresponding to every color in the theme editor.
CUSTOM_COMMAND_SIG(improve_theme){ CUSTOM_COMMAND_SIG(improve_theme){
Theme_Color colors[] = { Theme_Color colors[] = {
{Stag_Bar, 0xFF0088}, {Stag_Bar, 0xFF0088},
@ -868,7 +877,7 @@ CUSTOM_COMMAND_SIG(ruin_theme){
app->set_theme_colors(app, colors, count); app->set_theme_colors(app, colors, count);
} }
// NOTE(allen|a4.0.0): scroll rule information // NOTE(allen|a4): scroll rule information
// //
// The parameters: // The parameters:
// target_x, target_y // target_x, target_y
@ -955,10 +964,17 @@ SCROLL_RULE_SIG(smooth_scroll_rule){
return(result); return(result);
} }
#if Custom_Current == Custom_HandmadeHero
# include "4coder_handmade_hero.cpp"
#endif
extern "C" GET_BINDING_DATA(get_bindings){ extern "C" GET_BINDING_DATA(get_bindings){
Bind_Helper context_actual = begin_bind_helper(data, size); Bind_Helper context_actual = begin_bind_helper(data, size);
Bind_Helper *context = &context_actual; Bind_Helper *context = &context_actual;
#if Custom_Current == Custom_HandmadeHero
casey_get_bindings(context);
#else
// NOTE(allen|a3.1): Right now hooks have no loyalties to maps, all hooks are // NOTE(allen|a3.1): Right now hooks have no loyalties to maps, all hooks are
// global and once set they always apply, regardless of what map is active. // global and once set they always apply, regardless of what map is active.
@ -1037,10 +1053,10 @@ extern "C" GET_BINDING_DATA(get_bindings){
begin_map(context, mapid_file); begin_map(context, mapid_file);
// NOTE(allen|a3.4.4): Binding this essentially binds all key combos that // NOTE(allen|a3.4.4): Binding this essentially binds
// would normally insert a character into a buffer. // all key combos that would normally insert a character
// Or apply this rule: if the code for the key is not an enum value // into a buffer. If the code for the key is not an enum
// such as key_left or key_back then it is a vanilla key. // value such as key_left or key_back then it is a vanilla key.
// It is possible to override this binding for individual keys. // It is possible to override this binding for individual keys.
bind_vanilla_keys(context, cmdid_write_character); bind_vanilla_keys(context, cmdid_write_character);
@ -1104,6 +1120,7 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, ' ', MDFR_SHIFT, cmdid_write_character); bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
end_map(context); end_map(context);
#endif
end_bind_helper(context); end_bind_helper(context);

View File

@ -341,57 +341,59 @@ extern "C"{
struct Application_Links; struct Application_Links;
// Command exectuion // Command exectuion
#define PUSH_PARAMETER_SIG(name) void name(Application_Links *app, Dynamic param, Dynamic value) #define PUSH_PARAMETER_SIG(n) void n(Application_Links *app, Dynamic param, Dynamic value)
#define PUSH_MEMORY_SIG(name) char* name(Application_Links *app, int len) #define PUSH_MEMORY_SIG(n) char* n(Application_Links *app, int len)
#define EXECUTE_COMMAND_SIG(name) void name(Application_Links *app, int command_id) #define EXECUTE_COMMAND_SIG(n) void n(Application_Links *app, int command_id)
#define CLEAR_PARAMETERS_SIG(name) void name(Application_Links *app) #define CLEAR_PARAMETERS_SIG(n) void n(Application_Links *app)
// File system navigation // File system navigation
#define DIRECTORY_GET_HOT_SIG(name) int name(Application_Links *app, char *out, int capacity) #define DIRECTORY_GET_HOT_SIG(n) int n(Application_Links *app, char *out, int capacity)
#define FILE_EXISTS_SIG(name) int name(Application_Links *app, char *filename, int len) #define FILE_EXISTS_SIG(n) int n(Application_Links *app, char *filename, int len)
#define DIRECTORY_CD_SIG(name) int name(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len) #define DIRECTORY_CD_SIG(n) int n(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len)
#define GET_FILE_LIST_SIG(name) File_List name(Application_Links *app, char *dir, int len) #define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int len)
#define FREE_FILE_LIST_SIG(name) void name(Application_Links *app, File_List list) #define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
// Direct buffer manipulation // Direct buffer manipulation
#define GET_BUFFER_FIRST_SIG(name) Buffer_Summary name(Application_Links *app) #define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app)
#define GET_BUFFER_NEXT_SIG(name) void name(Application_Links *app, Buffer_Summary *buffer) #define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer)
#define GET_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int index) #define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int index)
#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app) #define GET_ACTIVE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app)
#define GET_PARAMETER_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app, int param_index) #define GET_PARAMETER_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int param_index)
#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(Application_Links *app, char *filename, int len) #define GET_BUFFER_BY_NAME(n) Buffer_Summary n(Application_Links *app, char *filename, int len)
#define BUFFER_SEEK_DELIMITER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out) #define BUFFER_SEEK_DELIMITER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
#define BUFFER_SEEK_STRING_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out) #define BUFFER_SEEK_STRING_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
#define REFRESH_BUFFER_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer) #define REFRESH_BUFFER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer)
#define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) #define BUFFER_READ_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) #define BUFFER_REPLACE_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len)
#define BUFFER_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos) #define BUFFER_SET_POS_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int pos)
// File view manipulation // File view manipulation
#define GET_VIEW_FIRST_SIG(name) View_Summary name(Application_Links *app) #define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app)
#define GET_VIEW_NEXT_SIG(name) void name(Application_Links *app, View_Summary *view) #define GET_VIEW_NEXT_SIG(n) void n(Application_Links *app, View_Summary *view)
#define GET_VIEW_SIG(name) View_Summary name(Application_Links *app, int index) #define GET_VIEW_SIG(n) View_Summary n(Application_Links *app, int index)
#define GET_ACTIVE_VIEW_SIG(name) View_Summary name(Application_Links *app) #define GET_ACTIVE_VIEW_SIG(n) View_Summary n(Application_Links *app)
#define REFRESH_VIEW_SIG(name) int name(Application_Links *app, View_Summary *view) #define REFRESH_VIEW_SIG(n) int n(Application_Links *app, View_Summary *view)
#define VIEW_SET_CURSOR_SIG(name) int name(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x) #define VIEW_SET_CURSOR_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x)
#define VIEW_SET_MARK_SIG(name) int name(Application_Links *app, View_Summary *view, Buffer_Seek seek) #define VIEW_SET_MARK_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek)
#define VIEW_SET_HIGHLIGHT_SIG(name) int name(Application_Links *app, View_Summary *view, int start, int end, int turn_on) #define VIEW_SET_HIGHLIGHT_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int turn_on)
#define VIEW_SET_BUFFER_SIG(name) int name(Application_Links *app, View_Summary *view, int buffer_id) #define VIEW_SET_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, int buffer_id)
// Directly get user input // Directly get user input
#define GET_USER_INPUT_SIG(name) User_Input name(Application_Links *context, unsigned int get_type, unsigned int abort_type) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, unsigned int get_type, unsigned int abort_type)
// Queries // Queries
#define START_QUERY_BAR_SIG(name) int name(Application_Links *context, Query_Bar *bar, unsigned int flags) #define START_QUERY_BAR_SIG(n) int n(Application_Links *app, Query_Bar *bar, unsigned int flags)
#define END_QUERY_BAR_SIG(name) void name(Application_Links *context, Query_Bar *bar, unsigned int flags) #define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, unsigned int flags)
// Setting colors // Color settings
#define SET_THEME_COLORS_SIG(name) void name(Application_Links *context, Theme_Color *colors, int count) #define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int len)
#define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int len)
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int count)
// Boundry type flags // Boundry type flags
@ -467,7 +469,9 @@ extern "C"{
typedef START_QUERY_BAR_SIG(Start_Query_Bar_Function); typedef START_QUERY_BAR_SIG(Start_Query_Bar_Function);
typedef END_QUERY_BAR_SIG(End_Query_Bar_Function); typedef END_QUERY_BAR_SIG(End_Query_Bar_Function);
// Set theme colors // Color settings
typedef CHANGE_THEME_SIG(Change_Theme_Function);
typedef CHANGE_FONT_SIG(Change_Font_Function);
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function); typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
} }
@ -527,6 +531,8 @@ struct Application_Links{
End_Query_Bar_Function *end_query_bar; End_Query_Bar_Function *end_query_bar;
// Theme // Theme
Change_Theme_Function *change_theme;
Change_Font_Function *change_font;
Set_Theme_Colors_Function *set_theme_colors; Set_Theme_Colors_Function *set_theme_colors;
// Internal // Internal

1260
4coder_handmade_hero.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -244,6 +244,23 @@ active_view_to_line(Application_Links *app, int line_number){
app->view_set_cursor(app, &view, seek_line_char(line_number, 0), 1); app->view_set_cursor(app, &view, seek_line_char(line_number, 0), 1);
} }
inline View_Summary
get_first_view_with_buffer(Application_Links *app, int buffer_id){
View_Summary result = {};
View_Summary test = {};
for(test = app->get_view_first(app);
test.exists;
app->get_view_next(app, &test)){
if(test.buffer_id == buffer_id){
result = test;
break;
}
}
return(result);
}
inline int inline int
key_is_unmodified(Key_Event_Data *key){ key_is_unmodified(Key_Event_Data *key){
char *mods = key->modifiers; char *mods = key->modifiers;
@ -322,3 +339,5 @@ query_user_number(Application_Links *app, Query_Bar *bar){
int success = query_user_general(app, bar, 1); int success = query_user_general(app, bar, 1);
return(success); return(success);
} }
inline String empty_string() {String Result = {}; return(Result);}

48
4ed.cpp
View File

@ -948,6 +948,10 @@ COMMAND_DECL(interactive_open){
delayed_open_background(delay, string); delayed_open_background(delay, string);
} }
else{ else{
// TODO(allen): Change the behavior of all delayed_open/background
// calls so that they still allocate the buffer right away. This way
// it's still possible to get at the buffer if so wished in the API.
// The switch for this view doesn't need to happen until the file is ready.
delayed_open(delay, string, panel); delayed_open(delay, string, panel);
} }
} }
@ -2454,7 +2458,7 @@ extern "C"{
} }
GET_USER_INPUT_SIG(external_get_user_input){ GET_USER_INPUT_SIG(external_get_user_input){
Command_Data *cmd = (Command_Data*)context->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
System_Functions *system = cmd->system; System_Functions *system = cmd->system;
Coroutine *coroutine = cmd->models->command_coroutine; Coroutine *coroutine = cmd->models->command_coroutine;
User_Input result; User_Input result;
@ -2469,7 +2473,7 @@ extern "C"{
} }
START_QUERY_BAR_SIG(external_start_query_bar){ START_QUERY_BAR_SIG(external_start_query_bar){
Command_Data *cmd = (Command_Data*)context->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Query_Slot *slot = 0; Query_Slot *slot = 0;
View *vptr; View *vptr;
@ -2482,19 +2486,49 @@ extern "C"{
} }
END_QUERY_BAR_SIG(external_end_query_bar){ END_QUERY_BAR_SIG(external_end_query_bar){
Command_Data *cmd = (Command_Data*)context->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
View *vptr; View *vptr;
vptr = cmd->view; vptr = cmd->view;
free_query_slot(&vptr->query_set, bar); free_query_slot(&vptr->query_set, bar);
} }
CHANGE_THEME_SIG(external_change_theme){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Style_Library *styles = &cmd->models->styles;
String theme_name = make_string(name, len);
Style *s;
i32 i, count;
count = styles->count;
s = styles->styles;
for (i = 0; i < count; ++i, ++s){
if (match(s->name, theme_name)){
style_copy(&cmd->models->style, s);
break;
}
}
}
CHANGE_FONT_SIG(external_change_font){
Command_Data *cmd = (Command_Data*)app->cmd_context;
Font_Set *set = cmd->models->font_set;
Style_Font *global_font = &cmd->models->global_font;
String font_name = make_string(name, len);
i16 font_id;
if (font_set_extract(set, font_name, &font_id)){
global_font->font_id = font_id;
global_font->font_changed = 1;
}
}
SET_THEME_COLORS_SIG(external_set_theme_colors){ SET_THEME_COLORS_SIG(external_set_theme_colors){
Command_Data *cmd = (Command_Data*)context->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Style *style = &cmd->models->style; Style *style = &cmd->models->style;
Theme_Color *theme_color; Theme_Color *theme_color;
i32 i;
u32 *color; u32 *color;
i32 i;
theme_color = colors; theme_color = colors;
for (i = 0; i < count; ++i, ++theme_color){ for (i = 0; i < count; ++i, ++theme_color){
@ -2569,6 +2603,8 @@ app_links_init(System_Functions *system, void *data, int size){
app_links.start_query_bar = external_start_query_bar; app_links.start_query_bar = external_start_query_bar;
app_links.end_query_bar = external_end_query_bar; app_links.end_query_bar = external_end_query_bar;
app_links.change_theme = external_change_theme;
app_links.change_font = external_change_font;
app_links.set_theme_colors = external_set_theme_colors; app_links.set_theme_colors = external_set_theme_colors;
} }

View File

@ -35,12 +35,13 @@
#define FCPP_LEXER_IMPLEMENTATION #define FCPP_LEXER_IMPLEMENTATION
#include "4cpp_lexer.h" #include "4cpp_lexer.h"
#include "4ed_template.cpp"
#include "4ed_font_set.cpp" #include "4ed_font_set.cpp"
#include "4ed_rendering_helper.cpp" #include "4ed_rendering_helper.cpp"
#include "4ed_style.h" #include "4ed_style.h"
#include "4ed_style.cpp" #include "4ed_style.cpp"
#include "4ed_template.cpp"
#include "4ed_exchange.cpp" #include "4ed_exchange.cpp"
#include "4ed_command.cpp" #include "4ed_command.cpp"
#include "4ed_file.cpp" #include "4ed_file.cpp"

View File

@ -1724,6 +1724,11 @@ file_do_white_batch_edit(System_Functions *system, App_Models *models, Editing_F
Mem_Options *mem = &models->mem; Mem_Options *mem = &models->mem;
Editing_Layout *layout = &models->layout; 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);
file_pre_edit_maintenance(system, &mem->general, file);
// NOTE(allen): actual text replacement // NOTE(allen): actual text replacement
General_Memory *general = &mem->general; General_Memory *general = &mem->general;
Partition *part = &mem->part; Partition *part = &mem->part;
@ -3286,7 +3291,7 @@ do_file_bar(View *view, Editing_File *file, UI_Layout *layout, Render_Target *ta
u32 pop2_color = bar_style.pop2_color; u32 pop2_color = bar_style.pop2_color;
bar.rect = layout_rect(layout, line_height + 2); bar.rect = layout_rect(layout, line_height + 2);
if (target){ if (target){
bar.font_id = font->font_id; bar.font_id = font->font_id;
bar.pos_x = (f32)bar.rect.x0; bar.pos_x = (f32)bar.rect.x0;
@ -3383,7 +3388,7 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rec
switch (view->widget.type){ switch (view->widget.type){
case FWIDG_NONE: case FWIDG_NONE:
{ {
if (file){ if (file && view->showing_ui == VUI_None){
do_file_bar(view, file, &layout, 0); do_file_bar(view, file, &layout, 0);
} }
@ -3733,7 +3738,7 @@ draw_file_view(System_Functions *system, Exchange *exchange,
switch (view->widget.type){ switch (view->widget.type){
case FWIDG_NONE: case FWIDG_NONE:
{ {
if (file){ if (file && view->showing_ui == VUI_None){
do_file_bar(view, file, &layout, target); do_file_bar(view, file, &layout, target);
} }

View File

@ -1,232 +1,230 @@
/* /*
* Mr. 4th Dimention - Allen Webster * Mr. 4th Dimention - Allen Webster
* *
* 18.12.2015 * 18.12.2015
* *
* Font set for 4coder * Font set for 4coder
* *
*/ */
// TOP // TOP
inline u32 inline u32
font_hash(String name){ font_hash(String name){
u32 x = 5381; u32 x = 5381;
char *p = name.str; char *p = name.str;
for (i32 i = 0; i < name.size; ++i, ++p){ for (i32 i = 0; i < name.size; ++i, ++p){
x = ((x << 5) + x) ^ (*p); x = ((x << 5) + x) ^ (*p);
} }
return(x); return(x);
} }
inline void inline void
font__insert(Font_Slot *pos, Font_Slot *slot){ font__insert(Font_Slot *pos, Font_Slot *slot){
Font_Slot *nex; Font_Slot *nex;
nex = pos->next; nex = pos->next;
slot->next = nex; slot->next = nex;
slot->prev = pos; slot->prev = pos;
nex->prev = slot; nex->prev = slot;
pos->next = slot; pos->next = slot;
} }
inline void inline void
font__remove(Font_Slot *slot){ font__remove(Font_Slot *slot){
Font_Slot *n, *p; Font_Slot *n, *p;
n = slot->next; n = slot->next;
p = slot->prev; p = slot->prev;
p->next = n; p->next = n;
n->prev = p; n->prev = p;
} }
internal void internal void
font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){ font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){
partition_align(partition, 8); partition_align(partition, 8);
set->info = push_array(partition, Font_Info, max); set->info = push_array(partition, Font_Info, max);
partition_align(partition, 8); partition_align(partition, 8);
set->entries = push_array(partition, Font_Table_Entry, max); set->entries = push_array(partition, Font_Table_Entry, max);
set->count = 0; set->count = 0;
set->max = max; set->max = max;
partition_align(partition, 8); partition_align(partition, 8);
set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot))); set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot)));
set->free_slots = {}; set->free_slots = {};
set->used_slots = {}; set->used_slots = {};
set->free_slots.next = &set->free_slots; dll_init_sentinel(&set->free_slots);
set->free_slots.prev = &set->free_slots; dll_init_sentinel(&set->used_slots);
set->used_slots.next = &set->used_slots;
set->used_slots.prev = &set->used_slots; char *ptr = (char*)set->font_block;
for (i32 i = 0; i < live_max; ++i){
char *ptr = (char*)set->font_block; dll_insert(&set->free_slots, (Font_Slot*)ptr);
for (i32 i = 0; i < live_max; ++i){ ptr += sizeof(Font_Slot) + sizeof(Render_Font);
font__insert(&set->free_slots, (Font_Slot*)ptr); }
ptr += sizeof(Font_Slot) + sizeof(Render_Font);
} set->font_used_flags = push_array(partition, b8, max);
set->live_max = live_max;
set->font_used_flags = push_array(partition, b8, max); }
set->live_max = live_max;
} internal b32
font_set_can_add(Font_Set *set){
internal b32 b32 result = 0;
font_set_can_add(Font_Set *set){ if (set->count*8 < set->max*7) result = 1;
b32 result = 0; return(result);
if (set->count*8 < set->max*7) result = 1; }
return(result);
} internal void
font_set_add_hash(Font_Set *set, String name, i16 font_id){
internal void Font_Table_Entry entry;
font_set_add_hash(Font_Set *set, String name, i16 font_id){ entry.hash = font_hash(name);
Font_Table_Entry entry; entry.name = name;
entry.hash = font_hash(name); entry.font_id = font_id;
entry.name = name;
entry.font_id = font_id; u32 i, j;
i = entry.hash % set->max;
u32 i, j; j = i - 1;
i = entry.hash % set->max; if (i <= 1) j += set->max;
j = i - 1;
if (i <= 1) j += set->max; for (; i != j; ++i){
if (i == set->max) i = 0;
for (; i != j; ++i){ if (set->entries[i].font_id == 0){
if (i == set->max) i = 0; set->entries[i] = entry;
if (set->entries[i].font_id == 0){ break;
set->entries[i] = entry; }
break; }
}
} Assert(i != j);
}
Assert(i != j);
} inline b32
font_set_can_load(Font_Set *set){
inline b32 b32 result = (set->free_slots.next != &set->free_slots);
font_set_can_load(Font_Set *set){ return(result);
b32 result = (set->free_slots.next != &set->free_slots); }
return(result);
} internal void
font_set_load(Partition *partition, Font_Set *set, i16 font_id){
internal void Font_Info *info = get_font_info(set, font_id);
font_set_load(Partition *partition, Font_Set *set, i16 font_id){ Font_Slot *slot = set->free_slots.next;
Font_Info *info = get_font_info(set, font_id); Assert(slot != &set->free_slots);
Font_Slot *slot = set->free_slots.next; font__remove(slot);
Assert(slot != &set->free_slots); font__insert(&set->used_slots, slot);
font__remove(slot);
font__insert(&set->used_slots, slot); Render_Font *font = (Render_Font*)(slot + 1);
set->font_load(font, info->filename.str, info->pt_size, 4);
Render_Font *font = (Render_Font*)(slot + 1); info->font = font;
set->font_load(font, info->filename.str, info->pt_size, 4); slot->font_id = font_id;
info->font = font; }
slot->font_id = font_id;
} internal void
font_set_evict_lru(Font_Set *set){
internal void Font_Slot *slot = set->used_slots.prev;
font_set_evict_lru(Font_Set *set){ Assert(slot != &set->used_slots);
Font_Slot *slot = set->used_slots.prev;
Assert(slot != &set->used_slots); i16 font_id = slot->font_id;
Font_Info *info = get_font_info(set, font_id);
i16 font_id = slot->font_id; Assert(((Font_Slot*)info->font) - 1 == slot);
Font_Info *info = get_font_info(set, font_id);
Assert(((Font_Slot*)info->font) - 1 == slot); set->release_font(info->font);
set->release_font(info->font); info->font = 0;
slot->font_id = 0;
info->font = 0; font__remove(slot);
slot->font_id = 0; font__insert(&set->free_slots, slot);
font__remove(slot); }
font__insert(&set->free_slots, slot);
} internal void
font_set_use(Partition *partition, Font_Set *set, i16 font_id){
internal void b8 already_used;
font_set_use(Partition *partition, Font_Set *set, i16 font_id){ already_used = set->font_used_flags[font_id-1];
b8 already_used;
already_used = set->font_used_flags[font_id-1]; if (!already_used){
if (set->used_this_frame < set->live_max){
if (!already_used){ ++set->used_this_frame;
if (set->used_this_frame < set->live_max){ set->font_used_flags[font_id-1] = 1;
++set->used_this_frame; already_used = 1;
set->font_used_flags[font_id-1] = 1; }
already_used = 1; }
}
} if (already_used){
// TODO(allen): optimize if you don't mind!!!!
if (already_used){ Font_Info *info = get_font_info(set, font_id);
// TODO(allen): optimize if you don't mind!!!! Font_Slot *slot;
Font_Info *info = get_font_info(set, font_id); if (info->font == 0){
Font_Slot *slot; if (!font_set_can_load(set)){
if (info->font == 0){ font_set_evict_lru(set);
if (!font_set_can_load(set)){ }
font_set_evict_lru(set); font_set_load(partition, set, font_id);
} }
font_set_load(partition, set, font_id); slot = ((Font_Slot*)info->font) - 1;
}
slot = ((Font_Slot*)info->font) - 1; font__remove(slot);
font__insert(&set->used_slots, slot);
font__remove(slot); }
font__insert(&set->used_slots, slot); }
}
} internal b32
font_set_add(Partition *partition, Font_Set *set,
internal b32 String filename, String name, i32 pt_size){
font_set_add(Partition *partition, Font_Set *set, b32 result = 0;
String filename, String name, i32 pt_size){ if (font_set_can_add(set)){
b32 result = 0; i16 font_id = (i16)(++set->count);
if (font_set_can_add(set)){ Font_Info *info = get_font_info(set, font_id);
i16 font_id = (i16)(++set->count); info->filename = filename;
Font_Info *info = get_font_info(set, font_id); info->name = name;
info->filename = filename; info->pt_size = pt_size;
info->name = name; set->font_info_load(partition, filename.str, pt_size, &info->height, &info->advance);
info->pt_size = pt_size; font_set_add_hash(set, name, font_id);
set->font_info_load(partition, filename.str, pt_size, &info->height, &info->advance);
font_set_add_hash(set, name, font_id); if (font_set_can_load(set)){
font_set_load(partition, set, font_id);
if (font_set_can_load(set)){ }
font_set_load(partition, set, font_id);
} result = 1;
}
result = 1; return(result);
} }
return(result);
} internal b32
font_set_find_pos(Font_Set *set, String name, u32 *position){
internal b32 b32 result;
font_set_find_pos(Font_Set *set, String name, u32 *position){ u32 hash, i, j;
b32 result; hash = font_hash(name);
u32 hash, i, j; i = hash % set->max;
hash = font_hash(name); j = i - 1;
i = hash % set->max; if (j <= 1) j += set->max;
j = i - 1;
if (j <= 1) j += set->max; result = 0;
Font_Table_Entry *entry;
result = 0; for (; i != j; ++i){
Font_Table_Entry *entry; if (i == set->max) i = 0;
for (; i != j; ++i){ entry = set->entries + i;
if (i == set->max) i = 0; if (entry->hash == hash){
entry = set->entries + i; if (match(name, entry->name)){
if (entry->hash == hash){ result = 1;
if (match(name, entry->name)){ *position = i;
result = 1; break;
*position = i; }
break; }
} }
}
} return(result);
}
return(result);
} internal b32
font_set_extract(Font_Set *set, String name, i16 *font_id){
internal b32 b32 result;
font_set_extract(Font_Set *set, String name, i16 *font_id){ u32 position;
b32 result;
u32 position; result = font_set_find_pos(set, name, &position);
if (result){
result = font_set_find_pos(set, name, &position); *font_id = set->entries[position].font_id;
if (result){ }
*font_id = set->entries[position].font_id;
} return(result);
}
return(result);
} // BOTTOM
// BOTTOM

View File

@ -44,11 +44,6 @@ struct Style_Library{
}; };
#if 0 #if 0
struct Style_Color_Specifier{
u32 tag;
u32 color;
};
struct Style_File_Format{ struct Style_File_Format{
i32 name_size; i32 name_size;
char name[24]; char name[24];

View File

@ -1056,15 +1056,19 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
switch(seek.type){ switch(seek.type){
case buffer_seek_pos: case buffer_seek_pos:
if (cursor.pos >= seek.pos) goto buffer_cursor_seek_end; if (cursor.pos >= seek.pos) goto buffer_cursor_seek_end;
break;
case buffer_seek_wrapped_xy: case buffer_seek_wrapped_xy:
if (seek.x == 0 && cursor.wrapped_y >= seek.y) goto buffer_cursor_seek_end; if (seek.x == 0 && cursor.wrapped_y >= seek.y) goto buffer_cursor_seek_end;
break;
case buffer_seek_unwrapped_xy: case buffer_seek_unwrapped_xy:
if (seek.x == 0 && cursor.unwrapped_y >= seek.y) goto buffer_cursor_seek_end; if (seek.x == 0 && cursor.unwrapped_y >= seek.y) goto buffer_cursor_seek_end;
break;
case buffer_seek_line_char: case buffer_seek_line_char:
if (cursor.line >= seek.line && cursor.character >= seek.character) goto buffer_cursor_seek_end; if (cursor.line >= seek.line && cursor.character >= seek.character) goto buffer_cursor_seek_end;
break;
} }
if (advance_data){ if (advance_data){

View File

@ -9,8 +9,8 @@ SET STUFF=/GR- /nologo
SET DEBUG=/Zi SET DEBUG=/Zi
SET EXPORTS=/EXPORT:get_bindings SET EXPORTS=/EXPORT:get_bindings
SET SRC=4coder_custom.cpp SET SRC=4coder_custom.cpp
REM SET LINKS=user32.lib gdi32.lib SET LINKS=user32.lib gdi32.lib
SET LINKS= REM SET LINKS=
cl %WARNINGS% %STUFF% %DEBUG% %SRC% %LINKS% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS% cl %WARNINGS% %STUFF% %DEBUG% %SRC% %LINKS% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS%