print_message
parent
ef3fff35d4
commit
4a43a580c5
|
@ -383,6 +383,7 @@ struct Application_Links;
|
||||||
// Queries
|
// Queries
|
||||||
#define START_QUERY_BAR_SIG(n) int n(Application_Links *app, 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)
|
#define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, unsigned int flags)
|
||||||
|
#define PRINT_MESSAGE_SIG(n) void n(Application_Links *app, char *string, int len)
|
||||||
|
|
||||||
// Color settings
|
// Color settings
|
||||||
#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int len)
|
#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int len)
|
||||||
|
@ -463,6 +464,7 @@ extern "C"{
|
||||||
// Queries
|
// Queries
|
||||||
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);
|
||||||
|
typedef PRINT_MESSAGE_SIG(Print_Message_Function);
|
||||||
|
|
||||||
// Color settings
|
// Color settings
|
||||||
typedef CHANGE_THEME_SIG(Change_Theme_Function);
|
typedef CHANGE_THEME_SIG(Change_Theme_Function);
|
||||||
|
@ -525,6 +527,7 @@ struct Application_Links{
|
||||||
// Queries
|
// Queries
|
||||||
Start_Query_Bar_Function *start_query_bar;
|
Start_Query_Bar_Function *start_query_bar;
|
||||||
End_Query_Bar_Function *end_query_bar;
|
End_Query_Bar_Function *end_query_bar;
|
||||||
|
Print_Message_Function *print_message;
|
||||||
|
|
||||||
// Theme
|
// Theme
|
||||||
Change_Theme_Function *change_theme;
|
Change_Theme_Function *change_theme;
|
||||||
|
|
|
@ -568,7 +568,7 @@ CUSTOM_COMMAND_SIG(execute_arbitrary_command){
|
||||||
exec_command(app, cmdid_eol_nixify);
|
exec_command(app, cmdid_eol_nixify);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// TODO(allen): feedback message
|
app->print_message(app, literal("unrecognized command\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,7 +646,7 @@ CUSTOM_COMMAND_SIG(build_search){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(allen): feedback message - couldn't find build.bat
|
app->print_message(app, literal("couldn't find build.bat\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){
|
CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){
|
||||||
|
|
78
4ed.cpp
78
4ed.cpp
|
@ -2515,11 +2515,16 @@ extern "C"{
|
||||||
END_QUERY_BAR_SIG(external_end_query_bar){
|
END_QUERY_BAR_SIG(external_end_query_bar){
|
||||||
Command_Data *cmd = (Command_Data*)app->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINT_MESSAGE_SIG(external_print_message){
|
||||||
|
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||||
|
Models *models = cmd->models;
|
||||||
|
do_feedback_message(cmd->system, models, make_string(string, len));
|
||||||
|
}
|
||||||
|
|
||||||
CHANGE_THEME_SIG(external_change_theme){
|
CHANGE_THEME_SIG(external_change_theme){
|
||||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||||
Style_Library *styles = &cmd->models->styles;
|
Style_Library *styles = &cmd->models->styles;
|
||||||
|
@ -2630,6 +2635,7 @@ 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.print_message = external_print_message;
|
||||||
|
|
||||||
app_links.change_theme = external_change_theme;
|
app_links.change_theme = external_change_theme;
|
||||||
app_links.change_font = external_change_font;
|
app_links.change_font = external_change_font;
|
||||||
|
@ -3091,6 +3097,7 @@ execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){
|
||||||
if (match(clparams.argv[2], "version")){
|
if (match(clparams.argv[2], "version")){
|
||||||
result = sizeof(VERSION) - 1;
|
result = sizeof(VERSION) - 1;
|
||||||
memcpy(memory, VERSION, result);
|
memcpy(memory, VERSION, result);
|
||||||
|
((char*)memory)[result++] = '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(result);
|
return(result);
|
||||||
|
@ -3133,7 +3140,6 @@ extern "C" SCROLL_RULE_SIG(fallback_scroll_rule){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
App_Init_Sig(app_init){
|
App_Init_Sig(app_init){
|
||||||
App_Vars *vars;
|
App_Vars *vars;
|
||||||
Models *models;
|
Models *models;
|
||||||
|
@ -3446,6 +3452,43 @@ App_Init_Sig(app_init){
|
||||||
models->buffer_param_indices = push_array(partition, i32, models->buffer_param_max);
|
models->buffer_param_indices = push_array(partition, i32, models->buffer_param_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
update_cli_handle_with_file(System_Functions *system, Models *models,
|
||||||
|
CLI_Handles *cli, Editing_File *file, char *dest, i32 max, b32 cursor_at_end){
|
||||||
|
i32 result = 0;
|
||||||
|
u32 amount;
|
||||||
|
|
||||||
|
for (system->cli_begin_update(cli);
|
||||||
|
system->cli_update_step(cli, dest, max, &amount);){
|
||||||
|
amount = eol_in_place_convert_in(dest, amount);
|
||||||
|
output_file_append(system, models, file, make_string(dest, amount), cursor_at_end);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (system->cli_end_update(cli)){
|
||||||
|
char str_space[256];
|
||||||
|
String str = make_fixed_width_string(str_space);
|
||||||
|
append(&str, "exited with code ");
|
||||||
|
append_int_to_str(cli->exit, &str);
|
||||||
|
output_file_append(system, models, file, str, cursor_at_end);
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 new_cursor = 0;
|
||||||
|
|
||||||
|
if (cursor_at_end){
|
||||||
|
new_cursor = buffer_size(&file->state.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (View_Iter iter = file_view_iter_init(&models->layout, file, 0);
|
||||||
|
file_view_iter_good(iter);
|
||||||
|
iter = file_view_iter_next(iter)){
|
||||||
|
view_cursor_move(iter.view, new_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
App_Step_Sig(app_step){
|
App_Step_Sig(app_step){
|
||||||
ProfileStart(OS_syncing);
|
ProfileStart(OS_syncing);
|
||||||
Application_Step_Result app_result = *result;
|
Application_Step_Result app_result = *result;
|
||||||
|
@ -3498,7 +3541,6 @@ App_Step_Sig(app_step){
|
||||||
Temp_Memory temp = begin_temp_memory(&models->mem.part);
|
Temp_Memory temp = begin_temp_memory(&models->mem.part);
|
||||||
u32 max = Kbytes(32);
|
u32 max = Kbytes(32);
|
||||||
char *dest = push_array(&models->mem.part, char, max);
|
char *dest = push_array(&models->mem.part, char, max);
|
||||||
u32 amount;
|
|
||||||
|
|
||||||
i32 count = vars->cli_processes.count;
|
i32 count = vars->cli_processes.count;
|
||||||
for (i32 i = 0; i < count; ++i){
|
for (i32 i = 0; i < count; ++i){
|
||||||
|
@ -3506,33 +3548,11 @@ App_Step_Sig(app_step){
|
||||||
Editing_File *file = proc->out_file;
|
Editing_File *file = proc->out_file;
|
||||||
|
|
||||||
if (file != 0){
|
if (file != 0){
|
||||||
|
i32 r = update_cli_handle_with_file(system, models, &proc->cli, file, dest, max, 0);
|
||||||
for (system->cli_begin_update(&proc->cli);
|
if (r) app_result.redraw = 1;
|
||||||
system->cli_update_step(&proc->cli, dest, max, &amount);){
|
if (r < 0){
|
||||||
amount = eol_in_place_convert_in(dest, amount);
|
|
||||||
output_file_append(system, models, file, make_string(dest, amount), 0);
|
|
||||||
app_result.redraw = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (system->cli_end_update(&proc->cli)){
|
|
||||||
*proc = vars->cli_processes.procs[--count];
|
*proc = vars->cli_processes.procs[--count];
|
||||||
--i;
|
--i;
|
||||||
|
|
||||||
char str_space[256];
|
|
||||||
String str = make_fixed_width_string(str_space);
|
|
||||||
append(&str, "exited with code ");
|
|
||||||
append_int_to_str(proc->cli.exit, &str);
|
|
||||||
|
|
||||||
output_file_append(system, models, file, str, 0);
|
|
||||||
app_result.redraw = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i32 new_cursor = 0;
|
|
||||||
|
|
||||||
for (View_Iter iter = file_view_iter_init(&models->layout, file, 0);
|
|
||||||
file_view_iter_good(iter);
|
|
||||||
iter = file_view_iter_next(iter)){
|
|
||||||
view_cursor_move(iter.view, new_cursor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3732,7 +3752,7 @@ App_Step_Sig(app_step){
|
||||||
"-The file count limit is over 8 million now\n"
|
"-The file count limit is over 8 million now\n"
|
||||||
"-File equality is handled better so renamings (such as 'subst') are safe now\n"
|
"-File equality is handled better so renamings (such as 'subst') are safe now\n"
|
||||||
"-This buffer will report events including errors that happen in 4coder\n"
|
"-This buffer will report events including errors that happen in 4coder\n"
|
||||||
"-Super users can post their own messages here with printf\n"
|
"-Super users can post their own messages here with app->print_message\n"
|
||||||
"-Set font size on command line with -f N, N = 16 by default\n\n"
|
"-Set font size on command line with -f N, N = 16 by default\n\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
1
4ed.h
1
4ed.h
|
@ -107,7 +107,6 @@ struct Application_Step_Result{
|
||||||
name(System_Functions *system, \
|
name(System_Functions *system, \
|
||||||
Key_Input_Data *input, \
|
Key_Input_Data *input, \
|
||||||
Mouse_State *mouse, \
|
Mouse_State *mouse, \
|
||||||
CLI_Handles self, \
|
|
||||||
Render_Target *target, \
|
Render_Target *target, \
|
||||||
Application_Memory *memory, \
|
Application_Memory *memory, \
|
||||||
Exchange *exchange, \
|
Exchange *exchange, \
|
||||||
|
|
|
@ -95,12 +95,12 @@ struct Text_Effect{
|
||||||
|
|
||||||
// NOTE(allen): The Editing_File struct is now divided into two
|
// NOTE(allen): The Editing_File struct is now divided into two
|
||||||
// parts. Variables in the Settings part can be set even when the
|
// parts. Variables in the Settings part can be set even when the
|
||||||
// file is still streaming in, and all operations except for the
|
// file is still streaming in, and persists thorugh all operations except
|
||||||
// initial allocation of the file.
|
// for the initial allocation of the file.
|
||||||
struct Editing_File_Settings{
|
struct Editing_File_Settings{
|
||||||
i32 base_map_id;
|
i32 base_map_id;
|
||||||
i32 dos_write_mode;
|
i32 dos_write_mode;
|
||||||
b32 unwrapped_lines;
|
b8 unwrapped_lines;
|
||||||
b8 tokens_exist;
|
b8 tokens_exist;
|
||||||
b8 is_initialized;
|
b8 is_initialized;
|
||||||
b8 unimportant;
|
b8 unimportant;
|
||||||
|
|
3
TODO.txt
3
TODO.txt
|
@ -131,6 +131,7 @@
|
||||||
; theme related business
|
; theme related business
|
||||||
; [] fix the versioning system for themes
|
; [] fix the versioning system for themes
|
||||||
; [] theme switch per panel?
|
; [] theme switch per panel?
|
||||||
|
; [] allow multiple font faces with effects
|
||||||
;
|
;
|
||||||
; [] control schemes
|
; [] control schemes
|
||||||
; [] emacs style sub-maps
|
; [] emacs style sub-maps
|
||||||
|
@ -146,7 +147,7 @@
|
||||||
; [] cuber's return to previous buffer idea
|
; [] cuber's return to previous buffer idea
|
||||||
; [] miblo's various number editors
|
; [] miblo's various number editors
|
||||||
;
|
;
|
||||||
; [] keep copy of unedited orignal, somewhere (compressed, restore by history?)
|
; [] keep copy of unedited orignal, somewhere (compressed? restore by history?)
|
||||||
;
|
;
|
||||||
; [] diff
|
; [] diff
|
||||||
; [] cloc
|
; [] cloc
|
||||||
|
|
|
@ -1836,18 +1836,6 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
current_directory = make_string(curdir_mem, curdir_size, curdir_req);
|
current_directory = make_string(curdir_mem, curdir_size, curdir_req);
|
||||||
|
|
||||||
int stdout_redir[2] = {};
|
|
||||||
if(pipe(stdout_redir) == -1){
|
|
||||||
perror("pipe");
|
|
||||||
} else {
|
|
||||||
if(dup2(stdout_redir[1], STDOUT_FILENO) == -1){
|
|
||||||
perror("dup2");
|
|
||||||
} else {
|
|
||||||
memcpy(&linuxvars.cli_self.out_read, stdout_redir, sizeof(int));
|
|
||||||
memcpy(&linuxvars.cli_self.out_write, stdout_redir + 1, sizeof(int));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Command_Line_Parameters clparams;
|
Command_Line_Parameters clparams;
|
||||||
clparams.argv = argv;
|
clparams.argv = argv;
|
||||||
clparams.argc = argc;
|
clparams.argc = argc;
|
||||||
|
@ -1866,10 +1854,24 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (output_size > 0){
|
if (output_size > 0){
|
||||||
// TODO(allen): crt free version
|
// TODO(allen): crt free version
|
||||||
fprintf(stderr, "%.*s", output_size, (char*)memory_vars.target_memory);
|
fprintf(stdout, "%.*s", output_size, (char*)memory_vars.target_memory);
|
||||||
}
|
}
|
||||||
if (output_size != 0) return 0;
|
if (output_size != 0) return 0;
|
||||||
|
|
||||||
|
// NOTE(allen): Now that we are done using the normal stdout stuff
|
||||||
|
// redirect it to a pipe so the application can render future printf itself.
|
||||||
|
int stdout_redir[2] = {};
|
||||||
|
if(pipe(stdout_redir) == -1){
|
||||||
|
perror("pipe");
|
||||||
|
} else {
|
||||||
|
if(dup2(stdout_redir[1], STDOUT_FILENO) == -1){
|
||||||
|
perror("dup2");
|
||||||
|
} else {
|
||||||
|
memcpy(&linuxvars.cli_self.out_read, stdout_redir, sizeof(int));
|
||||||
|
memcpy(&linuxvars.cli_self.out_write, stdout_redir + 1, sizeof(int));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sysshared_filter_real_files(files, file_count);
|
sysshared_filter_real_files(files, file_count);
|
||||||
|
|
||||||
linuxvars.XDisplay = XOpenDisplay(0);
|
linuxvars.XDisplay = XOpenDisplay(0);
|
||||||
|
|
800
win32_4ed.cpp
800
win32_4ed.cpp
|
@ -164,10 +164,6 @@ struct Win32_Vars{
|
||||||
// it up if needed.
|
// it up if needed.
|
||||||
Win32_Coroutine coroutine_data[2];
|
Win32_Coroutine coroutine_data[2];
|
||||||
Win32_Coroutine *coroutine_free;
|
Win32_Coroutine *coroutine_free;
|
||||||
|
|
||||||
// TODO(allen): Initialize this by redirecting std out to these CLI
|
|
||||||
// handles so that the application step can read from them.
|
|
||||||
CLI_Handles cli_self;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
globalvar Win32_Vars win32vars;
|
globalvar Win32_Vars win32vars;
|
||||||
|
@ -910,9 +906,9 @@ Sys_CLI_Call_Sig(system_cli_call){
|
||||||
|
|
||||||
Assert(sizeof(Plat_Handle) >= sizeof(HANDLE));
|
Assert(sizeof(Plat_Handle) >= sizeof(HANDLE));
|
||||||
if (CreateProcess(cmd, command_line,
|
if (CreateProcess(cmd, command_line,
|
||||||
0, 0, TRUE, 0,
|
0, 0, TRUE, 0,
|
||||||
env_variables, path,
|
env_variables, path,
|
||||||
&startup, &info)){
|
&startup, &info)){
|
||||||
success = 1;
|
success = 1;
|
||||||
CloseHandle(info.hThread);
|
CloseHandle(info.hThread);
|
||||||
*(HANDLE*)&cli_out->proc = info.hProcess;
|
*(HANDLE*)&cli_out->proc = info.hProcess;
|
||||||
|
@ -993,21 +989,15 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
|
||||||
DWORD result = 0;
|
DWORD result = 0;
|
||||||
|
|
||||||
if (WaitForSingleObject(proc, 0) == WAIT_OBJECT_0){
|
if (WaitForSingleObject(proc, 0) == WAIT_OBJECT_0){
|
||||||
if (!handle_equal(cli->proc, win32vars.cli_self.proc)){
|
if (GetExitCodeProcess(proc, &result) == 0)
|
||||||
if (GetExitCodeProcess(proc, &result) == 0)
|
cli->exit = -1;
|
||||||
cli->exit = -1;
|
else
|
||||||
else
|
cli->exit = (i32)result;
|
||||||
cli->exit = (i32)result;
|
|
||||||
|
|
||||||
close_me = 1;
|
close_me = 1;
|
||||||
CloseHandle(*(HANDLE*)&cli->proc);
|
CloseHandle(*(HANDLE*)&cli->proc);
|
||||||
CloseHandle(*(HANDLE*)&cli->out_read);
|
CloseHandle(*(HANDLE*)&cli->out_read);
|
||||||
CloseHandle(*(HANDLE*)&cli->out_write);
|
CloseHandle(*(HANDLE*)&cli->out_write);
|
||||||
}
|
|
||||||
else{
|
|
||||||
// TODO(allen): wtf? How does this happen? It doesn't right?
|
|
||||||
Assert(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return close_me;
|
return close_me;
|
||||||
}
|
}
|
||||||
|
@ -1050,16 +1040,16 @@ Win32LoadAppCode(){
|
||||||
img.size = dll_total_loaded_size(&dll_data);
|
img.size = dll_total_loaded_size(&dll_data);
|
||||||
img.data = (byte*)
|
img.data = (byte*)
|
||||||
VirtualAlloc((LPVOID)Tbytes(3), img.size,
|
VirtualAlloc((LPVOID)Tbytes(3), img.size,
|
||||||
MEM_COMMIT | MEM_RESERVE,
|
MEM_COMMIT | MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
|
||||||
dll_load(img, &win32vars.app_dll, file, &dll_data);
|
dll_load(img, &win32vars.app_dll, file, &dll_data);
|
||||||
|
|
||||||
DWORD extra_;
|
DWORD extra_;
|
||||||
VirtualProtect(img.data + win32vars.app_dll.text_start,
|
VirtualProtect(img.data + win32vars.app_dll.text_start,
|
||||||
win32vars.app_dll.text_size,
|
win32vars.app_dll.text_size,
|
||||||
PAGE_EXECUTE_READ,
|
PAGE_EXECUTE_READ,
|
||||||
&extra_);
|
&extra_);
|
||||||
|
|
||||||
get_funcs = (App_Get_Functions*)
|
get_funcs = (App_Get_Functions*)
|
||||||
dll_load_function(&win32vars.app_dll, "app_get_functions", 17);
|
dll_load_function(&win32vars.app_dll, "app_get_functions", 17);
|
||||||
|
@ -1142,8 +1132,8 @@ Font_Load_Sig(system_draw_font_load){
|
||||||
params->tab_width = tab_width;
|
params->tab_width = tab_width;
|
||||||
|
|
||||||
SendMessage(win32vars.window_handle,
|
SendMessage(win32vars.window_handle,
|
||||||
WM_4coder_LOAD_FONT,
|
WM_4coder_LOAD_FONT,
|
||||||
0, (i32)(params - win32vars.fnt.params));
|
0, (i32)(params - win32vars.fnt.params));
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1169,312 +1159,312 @@ Win32RedrawScreen(HDC hdc){
|
||||||
|
|
||||||
internal LRESULT
|
internal LRESULT
|
||||||
Win32Callback(HWND hwnd, UINT uMsg,
|
Win32Callback(HWND hwnd, UINT uMsg,
|
||||||
WPARAM wParam, LPARAM lParam){
|
WPARAM wParam, LPARAM lParam){
|
||||||
LRESULT result = {};
|
LRESULT result = {};
|
||||||
switch (uMsg){
|
switch (uMsg){
|
||||||
case WM_MENUCHAR:
|
case WM_MENUCHAR:
|
||||||
case WM_SYSCHAR:break;
|
case WM_SYSCHAR:break;
|
||||||
|
|
||||||
case WM_SYSKEYDOWN:
|
case WM_SYSKEYDOWN:
|
||||||
case WM_SYSKEYUP:
|
case WM_SYSKEYUP:
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
{
|
|
||||||
switch (wParam){
|
|
||||||
case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL:
|
|
||||||
case VK_MENU:case VK_LMENU:case VK_RMENU:
|
|
||||||
case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT:
|
|
||||||
{
|
{
|
||||||
Control_Keys *controls = 0;
|
switch (wParam){
|
||||||
b8 *control_keys = 0;
|
case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL:
|
||||||
controls = &win32vars.input_chunk.pers.controls;
|
case VK_MENU:case VK_LMENU:case VK_RMENU:
|
||||||
control_keys = win32vars.input_chunk.pers.control_keys;
|
case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT:
|
||||||
|
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
|
|
||||||
b8 down = ((lParam & Bit_31)?(0):(1));
|
|
||||||
b8 is_right = ((lParam & Bit_24)?(1):(0));
|
|
||||||
|
|
||||||
if (wParam != 255){
|
|
||||||
switch (wParam){
|
|
||||||
case VK_SHIFT:
|
|
||||||
{
|
{
|
||||||
control_keys[MDFR_SHIFT_INDEX] = down;
|
Control_Keys *controls = 0;
|
||||||
|
b8 *control_keys = 0;
|
||||||
|
controls = &win32vars.input_chunk.pers.controls;
|
||||||
|
control_keys = win32vars.input_chunk.pers.control_keys;
|
||||||
|
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
|
||||||
|
b8 down = ((lParam & Bit_31)?(0):(1));
|
||||||
|
b8 is_right = ((lParam & Bit_24)?(1):(0));
|
||||||
|
|
||||||
|
if (wParam != 255){
|
||||||
|
switch (wParam){
|
||||||
|
case VK_SHIFT:
|
||||||
|
{
|
||||||
|
control_keys[MDFR_SHIFT_INDEX] = down;
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case VK_CONTROL:
|
||||||
|
{
|
||||||
|
if (is_right) controls->r_ctrl = down;
|
||||||
|
else controls->l_ctrl = down;
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case VK_MENU:
|
||||||
|
{
|
||||||
|
if (is_right) controls->r_alt = down;
|
||||||
|
else controls->l_alt = down;
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
|
||||||
|
b8 ctrl, alt;
|
||||||
|
ctrl = (controls->r_ctrl || (controls->l_ctrl && !controls->r_alt));
|
||||||
|
alt = (controls->l_alt || (controls->r_alt && !controls->l_ctrl));
|
||||||
|
|
||||||
|
if (win32vars.lctrl_lalt_is_altgr){
|
||||||
|
if (controls->l_alt && controls->l_ctrl){
|
||||||
|
ctrl = 0;
|
||||||
|
alt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
control_keys[MDFR_CONTROL_INDEX] = ctrl;
|
||||||
|
control_keys[MDFR_ALT_INDEX] = alt;
|
||||||
|
}
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case VK_CONTROL:
|
default:
|
||||||
{
|
b8 previous_state, current_state;
|
||||||
if (is_right) controls->r_ctrl = down;
|
previous_state = ((lParam & Bit_30)?(1):(0));
|
||||||
else controls->l_ctrl = down;
|
current_state = ((lParam & Bit_31)?(0):(1));
|
||||||
}break;
|
|
||||||
|
|
||||||
case VK_MENU:
|
if (current_state){
|
||||||
{
|
u8 key = keycode_lookup((u8)wParam);
|
||||||
if (is_right) controls->r_alt = down;
|
|
||||||
else controls->l_alt = down;
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
|
|
||||||
b8 ctrl, alt;
|
i32 *count = 0;
|
||||||
ctrl = (controls->r_ctrl || (controls->l_ctrl && !controls->r_alt));
|
Key_Event_Data *data = 0;
|
||||||
alt = (controls->l_alt || (controls->r_alt && !controls->l_ctrl));
|
b8 *control_keys = 0;
|
||||||
|
i32 control_keys_size = 0;
|
||||||
|
|
||||||
if (win32vars.lctrl_lalt_is_altgr){
|
system_acquire_lock(INPUT_LOCK);
|
||||||
if (controls->l_alt && controls->l_ctrl){
|
if (!previous_state){
|
||||||
ctrl = 0;
|
count = &win32vars.input_chunk.trans.key_data.press_count;
|
||||||
alt = 0;
|
data = win32vars.input_chunk.trans.key_data.press;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
count = &win32vars.input_chunk.trans.key_data.hold_count;
|
||||||
|
data = win32vars.input_chunk.trans.key_data.hold;
|
||||||
|
}
|
||||||
|
control_keys = win32vars.input_chunk.pers.control_keys;
|
||||||
|
control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
|
||||||
|
|
||||||
|
if (*count < KEY_INPUT_BUFFER_SIZE){
|
||||||
|
if (!key){
|
||||||
|
UINT vk = (UINT)wParam;
|
||||||
|
UINT scan = (UINT)((lParam >> 16) & 0x7F);
|
||||||
|
BYTE state[256];
|
||||||
|
WORD x1 = 0, x2 = 0, x = 0;
|
||||||
|
int result1 = 0, result2 = 0, result = 0;
|
||||||
|
|
||||||
|
GetKeyboardState(state);
|
||||||
|
x1 = 0;
|
||||||
|
result1 = ToAscii(vk, scan, state, &x1, 0);
|
||||||
|
state[VK_CONTROL] = 0;
|
||||||
|
x2 = 0;
|
||||||
|
result2 = ToAscii(vk, scan, state, &x2, 0);
|
||||||
|
|
||||||
|
if (result1){
|
||||||
|
x = x1;
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else if (result2){
|
||||||
|
x = x2;
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == 1 && x < 128){
|
||||||
|
key = (u8)x;
|
||||||
|
if (key == '\r') key = '\n';
|
||||||
|
data[*count].character = key;
|
||||||
|
|
||||||
|
state[VK_CAPITAL] = 0;
|
||||||
|
x = 0;
|
||||||
|
result = ToAscii(vk, scan, state, &x, 0);
|
||||||
|
if (result == 1 && x < 128){
|
||||||
|
key = (u8)x;
|
||||||
|
if (key == '\r') key = '\n';
|
||||||
|
data[*count].character_no_caps_lock = key;
|
||||||
|
data[*count].keycode = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result != 1 || x >= 128){
|
||||||
|
data[*count].character = 0;
|
||||||
|
data[*count].character_no_caps_lock = 0;
|
||||||
|
data[*count].keycode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
data[*count].character = 0;
|
||||||
|
data[*count].character_no_caps_lock = 0;
|
||||||
|
data[*count].keycode = key;
|
||||||
|
}
|
||||||
|
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
||||||
|
++(*count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
|
||||||
control_keys[MDFR_CONTROL_INDEX] = ctrl;
|
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||||
control_keys[MDFR_ALT_INDEX] = alt;
|
}
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_INPUT:
|
||||||
|
|
||||||
|
|
||||||
|
case WM_MOUSEMOVE:
|
||||||
|
{
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
win32vars.input_chunk.pers.mouse_x = LOWORD(lParam);
|
||||||
|
win32vars.input_chunk.pers.mouse_y = HIWORD(lParam);
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_MOUSEWHEEL:
|
||||||
|
{
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
i16 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||||
|
if (rotation > 0){
|
||||||
|
win32vars.input_chunk.trans.mouse_wheel = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
win32vars.input_chunk.trans.mouse_wheel = -1;
|
||||||
}
|
}
|
||||||
system_release_lock(INPUT_LOCK);
|
system_release_lock(INPUT_LOCK);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
default:
|
case WM_LBUTTONDOWN:
|
||||||
b8 previous_state, current_state;
|
{
|
||||||
previous_state = ((lParam & Bit_30)?(1):(0));
|
system_acquire_lock(INPUT_LOCK);
|
||||||
current_state = ((lParam & Bit_31)?(0):(1));
|
win32vars.input_chunk.trans.mouse_l_press = 1;
|
||||||
|
win32vars.input_chunk.pers.mouse_l = 1;
|
||||||
if (current_state){
|
|
||||||
u8 key = keycode_lookup((u8)wParam);
|
|
||||||
|
|
||||||
i32 *count = 0;
|
|
||||||
Key_Event_Data *data = 0;
|
|
||||||
b8 *control_keys = 0;
|
|
||||||
i32 control_keys_size = 0;
|
|
||||||
|
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
if (!previous_state){
|
|
||||||
count = &win32vars.input_chunk.trans.key_data.press_count;
|
|
||||||
data = win32vars.input_chunk.trans.key_data.press;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
count = &win32vars.input_chunk.trans.key_data.hold_count;
|
|
||||||
data = win32vars.input_chunk.trans.key_data.hold;
|
|
||||||
}
|
|
||||||
control_keys = win32vars.input_chunk.pers.control_keys;
|
|
||||||
control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
|
|
||||||
|
|
||||||
if (*count < KEY_INPUT_BUFFER_SIZE){
|
|
||||||
if (!key){
|
|
||||||
UINT vk = (UINT)wParam;
|
|
||||||
UINT scan = (UINT)((lParam >> 16) & 0x7F);
|
|
||||||
BYTE state[256];
|
|
||||||
WORD x1 = 0, x2 = 0, x = 0;
|
|
||||||
int result1 = 0, result2 = 0, result = 0;
|
|
||||||
|
|
||||||
GetKeyboardState(state);
|
|
||||||
x1 = 0;
|
|
||||||
result1 = ToAscii(vk, scan, state, &x1, 0);
|
|
||||||
state[VK_CONTROL] = 0;
|
|
||||||
x2 = 0;
|
|
||||||
result2 = ToAscii(vk, scan, state, &x2, 0);
|
|
||||||
|
|
||||||
if (result1){
|
|
||||||
x = x1;
|
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
else if (result2){
|
|
||||||
x = x2;
|
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 1 && x < 128){
|
|
||||||
key = (u8)x;
|
|
||||||
if (key == '\r') key = '\n';
|
|
||||||
data[*count].character = key;
|
|
||||||
|
|
||||||
state[VK_CAPITAL] = 0;
|
|
||||||
x = 0;
|
|
||||||
result = ToAscii(vk, scan, state, &x, 0);
|
|
||||||
if (result == 1 && x < 128){
|
|
||||||
key = (u8)x;
|
|
||||||
if (key == '\r') key = '\n';
|
|
||||||
data[*count].character_no_caps_lock = key;
|
|
||||||
data[*count].keycode = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result != 1 || x >= 128){
|
|
||||||
data[*count].character = 0;
|
|
||||||
data[*count].character_no_caps_lock = 0;
|
|
||||||
data[*count].keycode = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
data[*count].character = 0;
|
|
||||||
data[*count].character_no_caps_lock = 0;
|
|
||||||
data[*count].keycode = key;
|
|
||||||
}
|
|
||||||
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
|
||||||
++(*count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
system_release_lock(INPUT_LOCK);
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
|
case WM_RBUTTONDOWN:
|
||||||
}
|
{
|
||||||
}break;
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
win32vars.input_chunk.trans.mouse_r_press = 1;
|
||||||
|
win32vars.input_chunk.pers.mouse_r = 1;
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
case WM_INPUT:
|
case WM_LBUTTONUP:
|
||||||
|
{
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
win32vars.input_chunk.trans.mouse_l_release = 1;
|
||||||
|
win32vars.input_chunk.pers.mouse_l = 0;
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
{
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
win32vars.input_chunk.trans.mouse_r_release = 1;
|
||||||
|
win32vars.input_chunk.pers.mouse_r = 0;
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_KILLFOCUS:
|
||||||
{
|
case WM_SETFOCUS:
|
||||||
system_acquire_lock(INPUT_LOCK);
|
{
|
||||||
win32vars.input_chunk.pers.mouse_x = LOWORD(lParam);
|
system_acquire_lock(INPUT_LOCK);
|
||||||
win32vars.input_chunk.pers.mouse_y = HIWORD(lParam);
|
win32vars.input_chunk.pers.mouse_l = 0;
|
||||||
system_release_lock(INPUT_LOCK);
|
win32vars.input_chunk.pers.mouse_r = 0;
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_MOUSEWHEEL:
|
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
||||||
{
|
for (int i = 0; i < MDFR_INDEX_COUNT; ++i) control_keys[i] = 0;
|
||||||
system_acquire_lock(INPUT_LOCK);
|
win32vars.input_chunk.pers.controls = {};
|
||||||
i16 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
|
|
||||||
if (rotation > 0){
|
|
||||||
win32vars.input_chunk.trans.mouse_wheel = 1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
win32vars.input_chunk.trans.mouse_wheel = -1;
|
|
||||||
}
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_LBUTTONDOWN:
|
system_release_lock(INPUT_LOCK);
|
||||||
{
|
}break;
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
win32vars.input_chunk.trans.mouse_l_press = 1;
|
|
||||||
win32vars.input_chunk.pers.mouse_l = 1;
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_RBUTTONDOWN:
|
case WM_SIZE:
|
||||||
{
|
{
|
||||||
system_acquire_lock(INPUT_LOCK);
|
if (win32vars.target.handle){
|
||||||
win32vars.input_chunk.trans.mouse_r_press = 1;
|
i32 new_width = LOWORD(lParam);
|
||||||
win32vars.input_chunk.pers.mouse_r = 1;
|
i32 new_height = HIWORD(lParam);
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_LBUTTONUP:
|
Win32Resize(new_width, new_height);
|
||||||
{
|
win32vars.input_chunk.trans.redraw = 1;
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
win32vars.input_chunk.trans.mouse_l_release = 1;
|
|
||||||
win32vars.input_chunk.pers.mouse_l = 0;
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_RBUTTONUP:
|
|
||||||
{
|
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
win32vars.input_chunk.trans.mouse_r_release = 1;
|
|
||||||
win32vars.input_chunk.pers.mouse_r = 0;
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_KILLFOCUS:
|
|
||||||
case WM_SETFOCUS:
|
|
||||||
{
|
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
win32vars.input_chunk.pers.mouse_l = 0;
|
|
||||||
win32vars.input_chunk.pers.mouse_r = 0;
|
|
||||||
|
|
||||||
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
|
||||||
for (int i = 0; i < MDFR_INDEX_COUNT; ++i) control_keys[i] = 0;
|
|
||||||
win32vars.input_chunk.pers.controls = {};
|
|
||||||
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_SIZE:
|
|
||||||
{
|
|
||||||
if (win32vars.target.handle){
|
|
||||||
i32 new_width = LOWORD(lParam);
|
|
||||||
i32 new_height = HIWORD(lParam);
|
|
||||||
|
|
||||||
Win32Resize(new_width, new_height);
|
|
||||||
win32vars.input_chunk.trans.redraw = 1;
|
|
||||||
}
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_PAINT:
|
|
||||||
{
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
|
||||||
Win32RedrawScreen(hdc);
|
|
||||||
EndPaint(hwnd, &ps);
|
|
||||||
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_4coder_PAINT:
|
|
||||||
{
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
|
||||||
Win32RedrawScreen(hdc);
|
|
||||||
EndPaint(hwnd, &ps);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_4coder_SET_CURSOR:
|
|
||||||
{
|
|
||||||
switch (wParam){
|
|
||||||
case APP_MOUSE_CURSOR_ARROW:
|
|
||||||
SetCursor(win32vars.cursor_arrow); break;
|
|
||||||
|
|
||||||
case APP_MOUSE_CURSOR_IBEAM:
|
|
||||||
SetCursor(win32vars.cursor_ibeam); break;
|
|
||||||
|
|
||||||
case APP_MOUSE_CURSOR_LEFTRIGHT:
|
|
||||||
SetCursor(win32vars.cursor_leftright); break;
|
|
||||||
|
|
||||||
case APP_MOUSE_CURSOR_UPDOWN:
|
|
||||||
SetCursor(win32vars.cursor_updown); break;
|
|
||||||
}
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_CLOSE: // NOTE(allen): I expect WM_CLOSE not WM_DESTROY
|
|
||||||
case WM_DESTROY:
|
|
||||||
{
|
|
||||||
system_acquire_lock(INPUT_LOCK);
|
|
||||||
win32vars.input_chunk.trans.trying_to_kill = 1;
|
|
||||||
system_release_lock(INPUT_LOCK);
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case WM_4coder_LOAD_FONT:
|
|
||||||
{
|
|
||||||
if (win32vars.fnt.part.base == 0){
|
|
||||||
win32vars.fnt.part = Win32ScratchPartition(Mbytes(8));
|
|
||||||
}
|
|
||||||
|
|
||||||
Font_Load_Parameters *params = win32vars.fnt.params + lParam;
|
|
||||||
i32 oversample = DpiMultiplier(2, win32vars.target.dpi);
|
|
||||||
|
|
||||||
for (b32 success = 0; success == 0;){
|
|
||||||
success = draw_font_load(win32vars.fnt.part.base,
|
|
||||||
win32vars.fnt.part.max,
|
|
||||||
params->font_out,
|
|
||||||
params->filename,
|
|
||||||
params->pt_size,
|
|
||||||
params->tab_width,
|
|
||||||
oversample);
|
|
||||||
|
|
||||||
if (!success){
|
|
||||||
Win32ScratchPartitionDouble(&win32vars.fnt.part);
|
|
||||||
}
|
}
|
||||||
}
|
}break;
|
||||||
|
|
||||||
system_acquire_lock(FONT_LOCK);
|
case WM_PAINT:
|
||||||
fnt__remove(params);
|
{
|
||||||
fnt__insert(&win32vars.fnt.free_param, params);
|
PAINTSTRUCT ps;
|
||||||
system_release_lock(FONT_LOCK);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
}break;
|
Win32RedrawScreen(hdc);
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
|
||||||
default:
|
}break;
|
||||||
{
|
|
||||||
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
|
case WM_4coder_PAINT:
|
||||||
}break;
|
{
|
||||||
}
|
PAINTSTRUCT ps;
|
||||||
return result;
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
|
Win32RedrawScreen(hdc);
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_4coder_SET_CURSOR:
|
||||||
|
{
|
||||||
|
switch (wParam){
|
||||||
|
case APP_MOUSE_CURSOR_ARROW:
|
||||||
|
SetCursor(win32vars.cursor_arrow); break;
|
||||||
|
|
||||||
|
case APP_MOUSE_CURSOR_IBEAM:
|
||||||
|
SetCursor(win32vars.cursor_ibeam); break;
|
||||||
|
|
||||||
|
case APP_MOUSE_CURSOR_LEFTRIGHT:
|
||||||
|
SetCursor(win32vars.cursor_leftright); break;
|
||||||
|
|
||||||
|
case APP_MOUSE_CURSOR_UPDOWN:
|
||||||
|
SetCursor(win32vars.cursor_updown); break;
|
||||||
|
}
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_CLOSE: // NOTE(allen): I expect WM_CLOSE not WM_DESTROY
|
||||||
|
case WM_DESTROY:
|
||||||
|
{
|
||||||
|
system_acquire_lock(INPUT_LOCK);
|
||||||
|
win32vars.input_chunk.trans.trying_to_kill = 1;
|
||||||
|
system_release_lock(INPUT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case WM_4coder_LOAD_FONT:
|
||||||
|
{
|
||||||
|
if (win32vars.fnt.part.base == 0){
|
||||||
|
win32vars.fnt.part = Win32ScratchPartition(Mbytes(8));
|
||||||
|
}
|
||||||
|
|
||||||
|
Font_Load_Parameters *params = win32vars.fnt.params + lParam;
|
||||||
|
i32 oversample = DpiMultiplier(2, win32vars.target.dpi);
|
||||||
|
|
||||||
|
for (b32 success = 0; success == 0;){
|
||||||
|
success = draw_font_load(win32vars.fnt.part.base,
|
||||||
|
win32vars.fnt.part.max,
|
||||||
|
params->font_out,
|
||||||
|
params->filename,
|
||||||
|
params->pt_size,
|
||||||
|
params->tab_width,
|
||||||
|
oversample);
|
||||||
|
|
||||||
|
if (!success){
|
||||||
|
Win32ScratchPartitionDouble(&win32vars.fnt.part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
system_acquire_lock(FONT_LOCK);
|
||||||
|
fnt__remove(params);
|
||||||
|
fnt__insert(&win32vars.fnt.free_param, params);
|
||||||
|
system_release_lock(FONT_LOCK);
|
||||||
|
}break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
|
@ -1494,7 +1484,7 @@ UpdateLoop(LPVOID param){
|
||||||
POINT mouse_point;
|
POINT mouse_point;
|
||||||
if (GetCursorPos(&mouse_point) && ScreenToClient(win32vars.window_handle, &mouse_point)){
|
if (GetCursorPos(&mouse_point) && ScreenToClient(win32vars.window_handle, &mouse_point)){
|
||||||
if (mouse_point.x < 0 || mouse_point.x >= win32vars.target.width ||
|
if (mouse_point.x < 0 || mouse_point.x >= win32vars.target.width ||
|
||||||
mouse_point.y < 0 || mouse_point.y >= win32vars.target.height){
|
mouse_point.y < 0 || mouse_point.y >= win32vars.target.height){
|
||||||
input_chunk.trans.out_of_window = 1;
|
input_chunk.trans.out_of_window = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1560,7 +1550,6 @@ UpdateLoop(LPVOID param){
|
||||||
win32vars.app.step(win32vars.system,
|
win32vars.app.step(win32vars.system,
|
||||||
&input_data,
|
&input_data,
|
||||||
&mouse,
|
&mouse,
|
||||||
win32vars.cli_self,
|
|
||||||
&win32vars.target,
|
&win32vars.target,
|
||||||
&memory_vars,
|
&memory_vars,
|
||||||
&exchange_vars,
|
&exchange_vars,
|
||||||
|
@ -1589,8 +1578,8 @@ UpdateLoop(LPVOID param){
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
for (file = exchange_vars.file.active.next;
|
for (file = exchange_vars.file.active.next;
|
||||||
file != &exchange_vars.file.active;
|
file != &exchange_vars.file.active;
|
||||||
file = file->next){
|
file = file->next){
|
||||||
++d;
|
++d;
|
||||||
|
|
||||||
if (file->flags & FEx_Save){
|
if (file->flags & FEx_Save){
|
||||||
|
@ -1667,135 +1656,134 @@ UpdateLoop(LPVOID param){
|
||||||
#if 0
|
#if 0
|
||||||
int
|
int
|
||||||
WinMain(HINSTANCE hInstance,
|
WinMain(HINSTANCE hInstance,
|
||||||
HINSTANCE hPrevInstance,
|
HINSTANCE hPrevInstance,
|
||||||
LPSTR lpCmdLine,
|
LPSTR lpCmdLine,
|
||||||
int nCmdShow){
|
int nCmdShow){
|
||||||
#else
|
#else
|
||||||
int
|
int
|
||||||
main(int argc, char **argv){
|
main(int argc, char **argv){
|
||||||
#endif
|
#endif
|
||||||
HINSTANCE hInstance = GetModuleHandle(0);
|
HINSTANCE hInstance = GetModuleHandle(0);
|
||||||
|
HANDLE original_out = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
|
||||||
win32vars = {};
|
win32vars = {};
|
||||||
exchange_vars = {};
|
exchange_vars = {};
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
win32vars.internal_bubble.next = &win32vars.internal_bubble;
|
win32vars.internal_bubble.next = &win32vars.internal_bubble;
|
||||||
win32vars.internal_bubble.prev = &win32vars.internal_bubble;
|
win32vars.internal_bubble.prev = &win32vars.internal_bubble;
|
||||||
win32vars.internal_bubble.flags = MEM_BUBBLE_SYS_DEBUG;
|
win32vars.internal_bubble.flags = MEM_BUBBLE_SYS_DEBUG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!Win32LoadAppCode()){
|
if (!Win32LoadAppCode()){
|
||||||
// TODO(allen): Failed to load app code, serious problem.
|
// TODO(allen): Failed to load app code, serious problem.
|
||||||
return 99;
|
return 99;
|
||||||
}
|
}
|
||||||
|
|
||||||
System_Functions system_;
|
System_Functions system_;
|
||||||
System_Functions *system = &system_;
|
System_Functions *system = &system_;
|
||||||
win32vars.system = system;
|
win32vars.system = system;
|
||||||
Win32LoadSystemCode();
|
Win32LoadSystemCode();
|
||||||
|
|
||||||
ConvertThreadToFiber(0);
|
ConvertThreadToFiber(0);
|
||||||
win32vars.coroutine_free = win32vars.coroutine_data;
|
win32vars.coroutine_free = win32vars.coroutine_data;
|
||||||
for (i32 i = 0; i+1 < ArrayCount(win32vars.coroutine_data); ++i){
|
for (i32 i = 0; i+1 < ArrayCount(win32vars.coroutine_data); ++i){
|
||||||
win32vars.coroutine_data[i].next = win32vars.coroutine_data + i + 1;
|
win32vars.coroutine_data[i].next = win32vars.coroutine_data + i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPVOID base;
|
LPVOID base;
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
base = (LPVOID)Tbytes(1);
|
base = (LPVOID)Tbytes(1);
|
||||||
#else
|
#else
|
||||||
base = (LPVOID)0;
|
base = (LPVOID)0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memory_vars.vars_memory_size = Mbytes(2);
|
memory_vars.vars_memory_size = Mbytes(2);
|
||||||
memory_vars.vars_memory = VirtualAlloc(base, memory_vars.vars_memory_size,
|
memory_vars.vars_memory = VirtualAlloc(base, memory_vars.vars_memory_size,
|
||||||
MEM_COMMIT | MEM_RESERVE,
|
MEM_COMMIT | MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
base = (LPVOID)Tbytes(2);
|
base = (LPVOID)Tbytes(2);
|
||||||
#else
|
#else
|
||||||
base = (LPVOID)0;
|
base = (LPVOID)0;
|
||||||
#endif
|
#endif
|
||||||
memory_vars.target_memory_size = Mbytes(512);
|
memory_vars.target_memory_size = Mbytes(512);
|
||||||
memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size,
|
memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size,
|
||||||
MEM_COMMIT | MEM_RESERVE,
|
MEM_COMMIT | MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
|
||||||
base = (LPVOID)0;
|
base = (LPVOID)0;
|
||||||
memory_vars.user_memory_size = Mbytes(2);
|
memory_vars.user_memory_size = Mbytes(2);
|
||||||
memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size,
|
memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size,
|
||||||
MEM_COMMIT | MEM_RESERVE,
|
MEM_COMMIT | MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
//
|
//
|
||||||
|
|
||||||
if (!memory_vars.vars_memory){
|
if (!memory_vars.vars_memory){
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD required = GetCurrentDirectory(0, 0);
|
DWORD required = GetCurrentDirectory(0, 0);
|
||||||
required += 1;
|
required += 1;
|
||||||
required *= 4;
|
required *= 4;
|
||||||
char *current_directory_mem = (char*)system_get_memory(required);
|
char *current_directory_mem = (char*)system_get_memory(required);
|
||||||
DWORD written = GetCurrentDirectory(required, current_directory_mem);
|
DWORD written = GetCurrentDirectory(required, current_directory_mem);
|
||||||
|
|
||||||
String current_directory = make_string(current_directory_mem, written, required);
|
String current_directory = make_string(current_directory_mem, written, required);
|
||||||
terminate_with_null(¤t_directory);
|
terminate_with_null(¤t_directory);
|
||||||
replace_char(current_directory, '\\', '/');
|
replace_char(current_directory, '\\', '/');
|
||||||
|
|
||||||
Command_Line_Parameters clparams;
|
Command_Line_Parameters clparams;
|
||||||
clparams.argv = argv;
|
clparams.argv = argv;
|
||||||
clparams.argc = argc;
|
clparams.argc = argc;
|
||||||
|
|
||||||
char **files;
|
char **files;
|
||||||
i32 *file_count;
|
i32 *file_count;
|
||||||
|
|
||||||
files = 0;
|
files = 0;
|
||||||
file_count = 0;
|
file_count = 0;
|
||||||
|
|
||||||
i32 output_size =
|
i32 output_size =
|
||||||
win32vars.app.read_command_line(system,
|
win32vars.app.read_command_line(system,
|
||||||
&memory_vars,
|
&memory_vars,
|
||||||
current_directory,
|
current_directory,
|
||||||
&win32vars.settings,
|
&win32vars.settings,
|
||||||
&files, &file_count,
|
&files, &file_count,
|
||||||
clparams);
|
clparams);
|
||||||
//
|
//
|
||||||
|
|
||||||
if (output_size > 0){
|
|
||||||
// TODO(allen): crt free version
|
|
||||||
printf("%.*s", output_size, memory_vars.target_memory);
|
|
||||||
}
|
|
||||||
if (output_size != 0) return 0;
|
|
||||||
|
|
||||||
|
if (output_size > 0){
|
||||||
|
DWORD written;
|
||||||
|
WriteFile(original_out, memory_vars.target_memory, output_size, &written, 0);
|
||||||
|
}
|
||||||
|
if (output_size != 0) return 0;
|
||||||
|
|
||||||
#ifdef FRED_SUPER
|
#ifdef FRED_SUPER
|
||||||
char *custom_file_default = "4coder_custom.dll";
|
char *custom_file_default = "4coder_custom.dll";
|
||||||
char *custom_file;
|
char *custom_file;
|
||||||
if (win32vars.settings.custom_dll) custom_file = win32vars.settings.custom_dll;
|
if (win32vars.settings.custom_dll) custom_file = win32vars.settings.custom_dll;
|
||||||
else custom_file = custom_file_default;
|
else custom_file = custom_file_default;
|
||||||
|
|
||||||
win32vars.custom = LoadLibraryA(custom_file);
|
win32vars.custom = LoadLibraryA(custom_file);
|
||||||
if (!win32vars.custom && custom_file != custom_file_default){
|
if (!win32vars.custom && custom_file != custom_file_default){
|
||||||
if (!win32vars.settings.custom_dll_is_strict){
|
if (!win32vars.settings.custom_dll_is_strict){
|
||||||
win32vars.custom = LoadLibraryA(custom_file_default);
|
win32vars.custom = LoadLibraryA(custom_file_default);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (win32vars.custom){
|
|
||||||
win32vars.custom_api.get_alpha_4coder_version = (_Get_Version_Function*)
|
|
||||||
GetProcAddress(win32vars.custom, "get_alpha_4coder_version");
|
|
||||||
//
|
|
||||||
if (win32vars.custom_api.get_alpha_4coder_version == 0 ||
|
|
||||||
win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
|
||||||
printf("Error: application and custom version numbers don't match");
|
|
||||||
return 22;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
if (win32vars.custom){
|
||||||
GetProcAddress(win32vars.custom, "get_bindings");
|
win32vars.custom_api.get_alpha_4coder_version = (_Get_Version_Function*)
|
||||||
}
|
GetProcAddress(win32vars.custom, "get_alpha_4coder_version");
|
||||||
|
//
|
||||||
|
if (win32vars.custom_api.get_alpha_4coder_version == 0 ||
|
||||||
|
win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
||||||
|
printf("Error: application and custom version numbers don't match");
|
||||||
|
return 22;
|
||||||
|
}
|
||||||
|
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
||||||
|
GetProcAddress(win32vars.custom, "get_bindings");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//FreeConsole();
|
//FreeConsole();
|
||||||
|
|
Loading…
Reference in New Issue