4coder_handmade_hero.cpp ready to go
This commit is contained in:
parent
6e1abb4237
commit
d71d10434a
|
@ -1,11 +1,8 @@
|
|||
/*
|
||||
* Example use of customization API
|
||||
*/
|
||||
// Alternative customizations, set Custom_Current to select which to apply.
|
||||
#define Custom_Default 0
|
||||
#define Custom_HandmadeHero 1
|
||||
|
||||
// NOTE(allen): See exec_command and surrounding code in 4coder_helper.h
|
||||
// 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.
|
||||
#define Custom_Current Custom_Default
|
||||
|
||||
#include "4coder_custom.h"
|
||||
|
||||
|
@ -30,6 +27,23 @@ enum My_Maps{
|
|||
HOOK_SIG(my_start){
|
||||
exec_command(app, cmdid_open_panel_vsplit);
|
||||
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){
|
||||
|
@ -367,8 +381,10 @@ isearch(Application_Links *app, int start_reversed){
|
|||
int step_forward = 0;
|
||||
int step_backward = 0;
|
||||
|
||||
if (CommandEqual(in.command, search)) step_forward = 1;
|
||||
if (CommandEqual(in.command, reverse_search)) step_backward = 1;
|
||||
if (CommandEqual(in.command, search) ||
|
||||
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;
|
||||
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
|
||||
// even use app->memory to create a hash table in the start hook.
|
||||
Query_Bar bar;
|
||||
char space[1024], more_space[1024];
|
||||
char space[1024];
|
||||
bar.prompt = make_lit_string("Command: ");
|
||||
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"))){
|
||||
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"))){
|
||||
exec_command(app, cmdid_open_menu);
|
||||
}
|
||||
else{
|
||||
bar.prompt = make_fixed_width_string(more_space);
|
||||
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);
|
||||
// TODO(allen): feedback message
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -840,6 +847,8 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
|
|||
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){
|
||||
Theme_Color colors[] = {
|
||||
{Stag_Bar, 0xFF0088},
|
||||
|
@ -868,7 +877,7 @@ CUSTOM_COMMAND_SIG(ruin_theme){
|
|||
app->set_theme_colors(app, colors, count);
|
||||
}
|
||||
|
||||
// NOTE(allen|a4.0.0): scroll rule information
|
||||
// NOTE(allen|a4): scroll rule information
|
||||
//
|
||||
// The parameters:
|
||||
// target_x, target_y
|
||||
|
@ -955,10 +964,17 @@ SCROLL_RULE_SIG(smooth_scroll_rule){
|
|||
return(result);
|
||||
}
|
||||
|
||||
#if Custom_Current == Custom_HandmadeHero
|
||||
# include "4coder_handmade_hero.cpp"
|
||||
#endif
|
||||
|
||||
extern "C" GET_BINDING_DATA(get_bindings){
|
||||
Bind_Helper context_actual = begin_bind_helper(data, size);
|
||||
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
|
||||
// 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);
|
||||
|
||||
// NOTE(allen|a3.4.4): Binding this essentially binds all key combos that
|
||||
// would normally insert a character into a buffer.
|
||||
// Or apply this rule: if the code for the key is not an enum value
|
||||
// such as key_left or key_back then it is a vanilla key.
|
||||
// NOTE(allen|a3.4.4): Binding this essentially binds
|
||||
// all key combos that would normally insert a character
|
||||
// into a buffer. If the code for the key is not an enum
|
||||
// value such as key_left or key_back then it is a vanilla key.
|
||||
// It is possible to override this binding for individual keys.
|
||||
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);
|
||||
|
||||
end_map(context);
|
||||
#endif
|
||||
|
||||
end_bind_helper(context);
|
||||
|
||||
|
|
|
@ -341,57 +341,59 @@ extern "C"{
|
|||
struct Application_Links;
|
||||
|
||||
// Command exectuion
|
||||
#define PUSH_PARAMETER_SIG(name) void name(Application_Links *app, Dynamic param, Dynamic value)
|
||||
#define PUSH_MEMORY_SIG(name) char* name(Application_Links *app, int len)
|
||||
#define EXECUTE_COMMAND_SIG(name) void name(Application_Links *app, int command_id)
|
||||
#define CLEAR_PARAMETERS_SIG(name) void name(Application_Links *app)
|
||||
#define PUSH_PARAMETER_SIG(n) void n(Application_Links *app, Dynamic param, Dynamic value)
|
||||
#define PUSH_MEMORY_SIG(n) char* n(Application_Links *app, int len)
|
||||
#define EXECUTE_COMMAND_SIG(n) void n(Application_Links *app, int command_id)
|
||||
#define CLEAR_PARAMETERS_SIG(n) void n(Application_Links *app)
|
||||
|
||||
// File system navigation
|
||||
#define DIRECTORY_GET_HOT_SIG(name) int name(Application_Links *app, char *out, int capacity)
|
||||
#define FILE_EXISTS_SIG(name) int name(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 GET_FILE_LIST_SIG(name) File_List name(Application_Links *app, char *dir, int len)
|
||||
#define FREE_FILE_LIST_SIG(name) void name(Application_Links *app, File_List list)
|
||||
#define DIRECTORY_GET_HOT_SIG(n) int n(Application_Links *app, char *out, int capacity)
|
||||
#define FILE_EXISTS_SIG(n) int n(Application_Links *app, char *filename, int 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(n) File_List n(Application_Links *app, char *dir, int len)
|
||||
#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
|
||||
|
||||
// Direct buffer manipulation
|
||||
#define GET_BUFFER_FIRST_SIG(name) Buffer_Summary name(Application_Links *app)
|
||||
#define GET_BUFFER_NEXT_SIG(name) void name(Application_Links *app, Buffer_Summary *buffer)
|
||||
#define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app)
|
||||
#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_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(Application_Links *app)
|
||||
#define GET_PARAMETER_BUFFER_SIG(name) Buffer_Summary name(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_SIG(n) Buffer_Summary n(Application_Links *app, int index)
|
||||
#define GET_ACTIVE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app)
|
||||
#define GET_PARAMETER_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int param_index)
|
||||
#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_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_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(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 BUFFER_READ_RANGE_SIG(name) int name(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_SET_POS_SIG(name) int name(Application_Links *app, Buffer_Summary *buffer, int pos)
|
||||
#define REFRESH_BUFFER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer)
|
||||
#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(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len)
|
||||
#define BUFFER_SET_POS_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int pos)
|
||||
|
||||
// File view manipulation
|
||||
#define GET_VIEW_FIRST_SIG(name) View_Summary name(Application_Links *app)
|
||||
#define GET_VIEW_NEXT_SIG(name) void name(Application_Links *app, View_Summary *view)
|
||||
#define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app)
|
||||
#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_ACTIVE_VIEW_SIG(name) View_Summary name(Application_Links *app)
|
||||
#define GET_VIEW_SIG(n) View_Summary n(Application_Links *app, int index)
|
||||
#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 VIEW_SET_CURSOR_SIG(name) int name(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_HIGHLIGHT_SIG(name) int name(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 REFRESH_VIEW_SIG(n) int n(Application_Links *app, View_Summary *view)
|
||||
#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(n) int n(Application_Links *app, View_Summary *view, Buffer_Seek seek)
|
||||
#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(n) int n(Application_Links *app, View_Summary *view, int buffer_id)
|
||||
|
||||
// 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
|
||||
#define START_QUERY_BAR_SIG(name) int name(Application_Links *context, Query_Bar *bar, unsigned int flags)
|
||||
#define END_QUERY_BAR_SIG(name) void 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(n) void n(Application_Links *app, Query_Bar *bar, unsigned int flags)
|
||||
|
||||
// Setting colors
|
||||
#define SET_THEME_COLORS_SIG(name) void name(Application_Links *context, Theme_Color *colors, int count)
|
||||
// Color settings
|
||||
#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
|
||||
|
@ -467,7 +469,9 @@ extern "C"{
|
|||
typedef START_QUERY_BAR_SIG(Start_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);
|
||||
}
|
||||
|
||||
|
@ -527,6 +531,8 @@ struct Application_Links{
|
|||
End_Query_Bar_Function *end_query_bar;
|
||||
|
||||
// Theme
|
||||
Change_Theme_Function *change_theme;
|
||||
Change_Font_Function *change_font;
|
||||
Set_Theme_Colors_Function *set_theme_colors;
|
||||
|
||||
// Internal
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
}
|
||||
|
||||
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
|
||||
key_is_unmodified(Key_Event_Data *key){
|
||||
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);
|
||||
return(success);
|
||||
}
|
||||
|
||||
inline String empty_string() {String Result = {}; return(Result);}
|
||||
|
|
48
4ed.cpp
48
4ed.cpp
|
@ -948,6 +948,10 @@ COMMAND_DECL(interactive_open){
|
|||
delayed_open_background(delay, string);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2454,7 +2458,7 @@ extern "C"{
|
|||
}
|
||||
|
||||
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;
|
||||
Coroutine *coroutine = cmd->models->command_coroutine;
|
||||
User_Input result;
|
||||
|
@ -2469,7 +2473,7 @@ extern "C"{
|
|||
}
|
||||
|
||||
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;
|
||||
View *vptr;
|
||||
|
||||
|
@ -2482,19 +2486,49 @@ extern "C"{
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
vptr = cmd->view;
|
||||
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){
|
||||
Command_Data *cmd = (Command_Data*)context->cmd_context;
|
||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||
Style *style = &cmd->models->style;
|
||||
Theme_Color *theme_color;
|
||||
i32 i;
|
||||
u32 *color;
|
||||
i32 i;
|
||||
|
||||
theme_color = colors;
|
||||
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.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;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,12 +35,13 @@
|
|||
#define FCPP_LEXER_IMPLEMENTATION
|
||||
#include "4cpp_lexer.h"
|
||||
|
||||
#include "4ed_template.cpp"
|
||||
|
||||
#include "4ed_font_set.cpp"
|
||||
#include "4ed_rendering_helper.cpp"
|
||||
|
||||
#include "4ed_style.h"
|
||||
#include "4ed_style.cpp"
|
||||
#include "4ed_template.cpp"
|
||||
#include "4ed_exchange.cpp"
|
||||
#include "4ed_command.cpp"
|
||||
#include "4ed_file.cpp"
|
||||
|
|
|
@ -1724,6 +1724,11 @@ file_do_white_batch_edit(System_Functions *system, App_Models *models, Editing_F
|
|||
Mem_Options *mem = &models->mem;
|
||||
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
|
||||
General_Memory *general = &mem->general;
|
||||
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;
|
||||
|
||||
bar.rect = layout_rect(layout, line_height + 2);
|
||||
|
||||
|
||||
if (target){
|
||||
bar.font_id = font->font_id;
|
||||
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){
|
||||
case FWIDG_NONE:
|
||||
{
|
||||
if (file){
|
||||
if (file && view->showing_ui == VUI_None){
|
||||
do_file_bar(view, file, &layout, 0);
|
||||
}
|
||||
|
||||
|
@ -3733,7 +3738,7 @@ draw_file_view(System_Functions *system, Exchange *exchange,
|
|||
switch (view->widget.type){
|
||||
case FWIDG_NONE:
|
||||
{
|
||||
if (file){
|
||||
if (file && view->showing_ui == VUI_None){
|
||||
do_file_bar(view, file, &layout, target);
|
||||
}
|
||||
|
||||
|
|
462
4ed_font_set.cpp
462
4ed_font_set.cpp
|
@ -1,232 +1,230 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.12.2015
|
||||
*
|
||||
* Font set for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
inline u32
|
||||
font_hash(String name){
|
||||
u32 x = 5381;
|
||||
char *p = name.str;
|
||||
for (i32 i = 0; i < name.size; ++i, ++p){
|
||||
x = ((x << 5) + x) ^ (*p);
|
||||
}
|
||||
return(x);
|
||||
}
|
||||
|
||||
inline void
|
||||
font__insert(Font_Slot *pos, Font_Slot *slot){
|
||||
Font_Slot *nex;
|
||||
nex = pos->next;
|
||||
|
||||
slot->next = nex;
|
||||
slot->prev = pos;
|
||||
nex->prev = slot;
|
||||
pos->next = slot;
|
||||
}
|
||||
|
||||
inline void
|
||||
font__remove(Font_Slot *slot){
|
||||
Font_Slot *n, *p;
|
||||
n = slot->next;
|
||||
p = slot->prev;
|
||||
|
||||
p->next = n;
|
||||
n->prev = p;
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){
|
||||
partition_align(partition, 8);
|
||||
set->info = push_array(partition, Font_Info, max);
|
||||
partition_align(partition, 8);
|
||||
set->entries = push_array(partition, Font_Table_Entry, max);
|
||||
set->count = 0;
|
||||
set->max = max;
|
||||
|
||||
partition_align(partition, 8);
|
||||
set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot)));
|
||||
|
||||
set->free_slots = {};
|
||||
set->used_slots = {};
|
||||
|
||||
set->free_slots.next = &set->free_slots;
|
||||
set->free_slots.prev = &set->free_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){
|
||||
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;
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_can_add(Font_Set *set){
|
||||
b32 result = 0;
|
||||
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){
|
||||
Font_Table_Entry entry;
|
||||
entry.hash = font_hash(name);
|
||||
entry.name = name;
|
||||
entry.font_id = font_id;
|
||||
|
||||
u32 i, j;
|
||||
i = entry.hash % set->max;
|
||||
j = i - 1;
|
||||
if (i <= 1) j += set->max;
|
||||
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
if (set->entries[i].font_id == 0){
|
||||
set->entries[i] = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(i != j);
|
||||
}
|
||||
|
||||
inline b32
|
||||
font_set_can_load(Font_Set *set){
|
||||
b32 result = (set->free_slots.next != &set->free_slots);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_load(Partition *partition, Font_Set *set, i16 font_id){
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
Font_Slot *slot = set->free_slots.next;
|
||||
Assert(slot != &set->free_slots);
|
||||
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);
|
||||
info->font = font;
|
||||
slot->font_id = font_id;
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_evict_lru(Font_Set *set){
|
||||
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);
|
||||
Assert(((Font_Slot*)info->font) - 1 == slot);
|
||||
|
||||
set->release_font(info->font);
|
||||
|
||||
info->font = 0;
|
||||
slot->font_id = 0;
|
||||
font__remove(slot);
|
||||
font__insert(&set->free_slots, slot);
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_use(Partition *partition, Font_Set *set, i16 font_id){
|
||||
b8 already_used;
|
||||
already_used = set->font_used_flags[font_id-1];
|
||||
|
||||
if (!already_used){
|
||||
if (set->used_this_frame < set->live_max){
|
||||
++set->used_this_frame;
|
||||
set->font_used_flags[font_id-1] = 1;
|
||||
already_used = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (already_used){
|
||||
// TODO(allen): optimize if you don't mind!!!!
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
Font_Slot *slot;
|
||||
if (info->font == 0){
|
||||
if (!font_set_can_load(set)){
|
||||
font_set_evict_lru(set);
|
||||
}
|
||||
font_set_load(partition, set, font_id);
|
||||
}
|
||||
slot = ((Font_Slot*)info->font) - 1;
|
||||
|
||||
font__remove(slot);
|
||||
font__insert(&set->used_slots, slot);
|
||||
}
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_add(Partition *partition, Font_Set *set,
|
||||
String filename, String name, i32 pt_size){
|
||||
b32 result = 0;
|
||||
if (font_set_can_add(set)){
|
||||
i16 font_id = (i16)(++set->count);
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
info->filename = filename;
|
||||
info->name = name;
|
||||
info->pt_size = pt_size;
|
||||
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);
|
||||
}
|
||||
|
||||
result = 1;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_find_pos(Font_Set *set, String name, u32 *position){
|
||||
b32 result;
|
||||
u32 hash, i, j;
|
||||
hash = font_hash(name);
|
||||
i = hash % set->max;
|
||||
j = i - 1;
|
||||
if (j <= 1) j += set->max;
|
||||
|
||||
result = 0;
|
||||
Font_Table_Entry *entry;
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
entry = set->entries + i;
|
||||
if (entry->hash == hash){
|
||||
if (match(name, entry->name)){
|
||||
result = 1;
|
||||
*position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_extract(Font_Set *set, String name, i16 *font_id){
|
||||
b32 result;
|
||||
u32 position;
|
||||
|
||||
result = font_set_find_pos(set, name, &position);
|
||||
if (result){
|
||||
*font_id = set->entries[position].font_id;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
||||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.12.2015
|
||||
*
|
||||
* Font set for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
inline u32
|
||||
font_hash(String name){
|
||||
u32 x = 5381;
|
||||
char *p = name.str;
|
||||
for (i32 i = 0; i < name.size; ++i, ++p){
|
||||
x = ((x << 5) + x) ^ (*p);
|
||||
}
|
||||
return(x);
|
||||
}
|
||||
|
||||
inline void
|
||||
font__insert(Font_Slot *pos, Font_Slot *slot){
|
||||
Font_Slot *nex;
|
||||
nex = pos->next;
|
||||
|
||||
slot->next = nex;
|
||||
slot->prev = pos;
|
||||
nex->prev = slot;
|
||||
pos->next = slot;
|
||||
}
|
||||
|
||||
inline void
|
||||
font__remove(Font_Slot *slot){
|
||||
Font_Slot *n, *p;
|
||||
n = slot->next;
|
||||
p = slot->prev;
|
||||
|
||||
p->next = n;
|
||||
n->prev = p;
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_init(Font_Set *set, Partition *partition, i32 max, i16 live_max){
|
||||
partition_align(partition, 8);
|
||||
set->info = push_array(partition, Font_Info, max);
|
||||
partition_align(partition, 8);
|
||||
set->entries = push_array(partition, Font_Table_Entry, max);
|
||||
set->count = 0;
|
||||
set->max = max;
|
||||
|
||||
partition_align(partition, 8);
|
||||
set->font_block = push_block(partition, live_max*(sizeof(Render_Font) + sizeof(Font_Slot)));
|
||||
|
||||
set->free_slots = {};
|
||||
set->used_slots = {};
|
||||
|
||||
dll_init_sentinel(&set->free_slots);
|
||||
dll_init_sentinel(&set->used_slots);
|
||||
|
||||
char *ptr = (char*)set->font_block;
|
||||
for (i32 i = 0; i < live_max; ++i){
|
||||
dll_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;
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_can_add(Font_Set *set){
|
||||
b32 result = 0;
|
||||
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){
|
||||
Font_Table_Entry entry;
|
||||
entry.hash = font_hash(name);
|
||||
entry.name = name;
|
||||
entry.font_id = font_id;
|
||||
|
||||
u32 i, j;
|
||||
i = entry.hash % set->max;
|
||||
j = i - 1;
|
||||
if (i <= 1) j += set->max;
|
||||
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
if (set->entries[i].font_id == 0){
|
||||
set->entries[i] = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(i != j);
|
||||
}
|
||||
|
||||
inline b32
|
||||
font_set_can_load(Font_Set *set){
|
||||
b32 result = (set->free_slots.next != &set->free_slots);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_load(Partition *partition, Font_Set *set, i16 font_id){
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
Font_Slot *slot = set->free_slots.next;
|
||||
Assert(slot != &set->free_slots);
|
||||
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);
|
||||
info->font = font;
|
||||
slot->font_id = font_id;
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_evict_lru(Font_Set *set){
|
||||
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);
|
||||
Assert(((Font_Slot*)info->font) - 1 == slot);
|
||||
|
||||
set->release_font(info->font);
|
||||
|
||||
info->font = 0;
|
||||
slot->font_id = 0;
|
||||
font__remove(slot);
|
||||
font__insert(&set->free_slots, slot);
|
||||
}
|
||||
|
||||
internal void
|
||||
font_set_use(Partition *partition, Font_Set *set, i16 font_id){
|
||||
b8 already_used;
|
||||
already_used = set->font_used_flags[font_id-1];
|
||||
|
||||
if (!already_used){
|
||||
if (set->used_this_frame < set->live_max){
|
||||
++set->used_this_frame;
|
||||
set->font_used_flags[font_id-1] = 1;
|
||||
already_used = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (already_used){
|
||||
// TODO(allen): optimize if you don't mind!!!!
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
Font_Slot *slot;
|
||||
if (info->font == 0){
|
||||
if (!font_set_can_load(set)){
|
||||
font_set_evict_lru(set);
|
||||
}
|
||||
font_set_load(partition, set, font_id);
|
||||
}
|
||||
slot = ((Font_Slot*)info->font) - 1;
|
||||
|
||||
font__remove(slot);
|
||||
font__insert(&set->used_slots, slot);
|
||||
}
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_add(Partition *partition, Font_Set *set,
|
||||
String filename, String name, i32 pt_size){
|
||||
b32 result = 0;
|
||||
if (font_set_can_add(set)){
|
||||
i16 font_id = (i16)(++set->count);
|
||||
Font_Info *info = get_font_info(set, font_id);
|
||||
info->filename = filename;
|
||||
info->name = name;
|
||||
info->pt_size = pt_size;
|
||||
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);
|
||||
}
|
||||
|
||||
result = 1;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_find_pos(Font_Set *set, String name, u32 *position){
|
||||
b32 result;
|
||||
u32 hash, i, j;
|
||||
hash = font_hash(name);
|
||||
i = hash % set->max;
|
||||
j = i - 1;
|
||||
if (j <= 1) j += set->max;
|
||||
|
||||
result = 0;
|
||||
Font_Table_Entry *entry;
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
entry = set->entries + i;
|
||||
if (entry->hash == hash){
|
||||
if (match(name, entry->name)){
|
||||
result = 1;
|
||||
*position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal b32
|
||||
font_set_extract(Font_Set *set, String name, i16 *font_id){
|
||||
b32 result;
|
||||
u32 position;
|
||||
|
||||
result = font_set_find_pos(set, name, &position);
|
||||
if (result){
|
||||
*font_id = set->entries[position].font_id;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -44,11 +44,6 @@ struct Style_Library{
|
|||
};
|
||||
|
||||
#if 0
|
||||
struct Style_Color_Specifier{
|
||||
u32 tag;
|
||||
u32 color;
|
||||
};
|
||||
|
||||
struct Style_File_Format{
|
||||
i32 name_size;
|
||||
char name[24];
|
||||
|
|
|
@ -1056,15 +1056,19 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
|
|||
switch(seek.type){
|
||||
case buffer_seek_pos:
|
||||
if (cursor.pos >= seek.pos) goto buffer_cursor_seek_end;
|
||||
break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
if (seek.x == 0 && cursor.wrapped_y >= seek.y) goto buffer_cursor_seek_end;
|
||||
break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
if (seek.x == 0 && cursor.unwrapped_y >= seek.y) goto buffer_cursor_seek_end;
|
||||
break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
if (cursor.line >= seek.line && cursor.character >= seek.character) goto buffer_cursor_seek_end;
|
||||
break;
|
||||
}
|
||||
|
||||
if (advance_data){
|
||||
|
|
|
@ -9,8 +9,8 @@ SET STUFF=/GR- /nologo
|
|||
SET DEBUG=/Zi
|
||||
SET EXPORTS=/EXPORT:get_bindings
|
||||
SET SRC=4coder_custom.cpp
|
||||
REM SET LINKS=user32.lib gdi32.lib
|
||||
SET LINKS=
|
||||
SET LINKS=user32.lib gdi32.lib
|
||||
REM SET LINKS=
|
||||
|
||||
cl %WARNINGS% %STUFF% %DEBUG% %SRC% %LINKS% /Fe4coder_custom /LD /link /INCREMENTAL:NO /OPT:REF %EXPORTS%
|
||||
|
||||
|
|
Loading…
Reference in New Issue