2015-09-28 23:34:55 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 12.12.2014
|
|
|
|
*
|
2015-11-14 04:42:06 +00:00
|
|
|
* Application Layer for 4coder
|
2015-09-28 23:34:55 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-11-14 04:42:06 +00:00
|
|
|
// TOP
|
|
|
|
|
2015-09-28 23:34:55 +00:00
|
|
|
#ifndef FRED_H
|
|
|
|
#define FRED_H
|
|
|
|
|
|
|
|
struct Application_Memory{
|
|
|
|
void *vars_memory;
|
|
|
|
i32 vars_memory_size;
|
|
|
|
void *target_memory;
|
|
|
|
i32 target_memory_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define KEY_INPUT_BUFFER_SIZE 4
|
|
|
|
#define KEY_INPUT_BUFFER_DSIZE (KEY_INPUT_BUFFER_SIZE << 1)
|
|
|
|
|
|
|
|
enum Key_Control{
|
|
|
|
CONTROL_KEY_SHIFT,
|
|
|
|
CONTROL_KEY_CONTROL,
|
|
|
|
CONTROL_KEY_ALT,
|
2016-01-17 01:34:48 +00:00
|
|
|
CONTROL_KEY_CAPS,
|
2015-09-28 23:34:55 +00:00
|
|
|
// always last
|
|
|
|
CONTROL_KEY_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Key_Event_Data{
|
2016-01-06 15:39:15 +00:00
|
|
|
u8 keycode;
|
|
|
|
u8 character;
|
|
|
|
u8 character_no_caps_lock;
|
2016-01-17 01:34:48 +00:00
|
|
|
|
|
|
|
b8 modifiers[CONTROL_KEY_COUNT];
|
2015-09-28 23:34:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Key_Input_Data{
|
|
|
|
Key_Event_Data press[KEY_INPUT_BUFFER_SIZE];
|
|
|
|
Key_Event_Data hold[KEY_INPUT_BUFFER_SIZE];
|
|
|
|
i32 press_count;
|
|
|
|
i32 hold_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Key_Summary{
|
|
|
|
i32 count;
|
|
|
|
Key_Event_Data keys[KEY_INPUT_BUFFER_DSIZE];
|
|
|
|
};
|
|
|
|
|
2016-01-17 01:34:48 +00:00
|
|
|
inline Key_Event_Data
|
2015-09-28 23:34:55 +00:00
|
|
|
get_single_key(Key_Summary *summary, i32 index){
|
|
|
|
Assert(index >= 0 && index < summary->count);
|
2016-01-17 01:34:48 +00:00
|
|
|
Key_Event_Data key;
|
|
|
|
key = summary->keys[index];
|
2015-09-28 23:34:55 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Mouse_State{
|
2015-11-16 16:15:45 +00:00
|
|
|
b32 out_of_window;
|
2016-01-17 01:34:48 +00:00
|
|
|
b8 left_button, right_button;
|
|
|
|
b8 left_button_pressed, right_button_pressed;
|
|
|
|
b8 left_button_released, right_button_released;
|
2015-09-28 23:34:55 +00:00
|
|
|
i16 wheel;
|
2016-01-17 01:34:48 +00:00
|
|
|
i32 x, y;
|
2015-09-28 23:34:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Mouse_Summary{
|
|
|
|
i32 mx, my;
|
2015-11-16 16:15:45 +00:00
|
|
|
b32 l, r;
|
|
|
|
b32 press_l, press_r;
|
|
|
|
b32 release_l, release_r;
|
|
|
|
b32 out_of_window;
|
|
|
|
b32 wheel_used;
|
2015-09-28 23:34:55 +00:00
|
|
|
i16 wheel_amount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Input_Summary{
|
|
|
|
Mouse_Summary mouse;
|
|
|
|
Key_Summary keys;
|
|
|
|
Key_Codes *codes;
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(allen): This can go, and we can just use a String for it.
|
|
|
|
struct Clipboard_Contents{
|
|
|
|
u8 *str;
|
|
|
|
i32 size;
|
|
|
|
};
|
|
|
|
|
2016-01-06 15:39:15 +00:00
|
|
|
#define FileNameMax (1 << 9)
|
|
|
|
|
|
|
|
struct File_Slot{
|
|
|
|
File_Slot *next, *prev;
|
|
|
|
byte *data;
|
|
|
|
i32 size, max;
|
|
|
|
char *filename;
|
|
|
|
i32 filename_len;
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum File_Exchange_Flag{
|
|
|
|
FEx_Request = 0x1,
|
|
|
|
FEx_Ready = 0x2,
|
|
|
|
FEx_Not_Exist = 0x4,
|
|
|
|
FEx_Save = 0x8,
|
|
|
|
FEx_Save_Complete = 0x10
|
|
|
|
};
|
|
|
|
|
|
|
|
struct File_Exchange{
|
|
|
|
File_Slot available, active, free_list;
|
|
|
|
File_Slot *files;
|
|
|
|
i32 num_active, max;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Exchange{
|
|
|
|
Thread_Exchange thread;
|
|
|
|
File_Exchange file;
|
|
|
|
};
|
2015-09-28 23:34:55 +00:00
|
|
|
|
2016-01-28 20:01:40 +00:00
|
|
|
struct Command_Line_Parameters{
|
|
|
|
char **argv;
|
|
|
|
int argc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct App_Plat_Settings{
|
|
|
|
char *custom_dll;
|
|
|
|
b32 custom_dll_is_strict;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define App_Read_Command_Line_Sig(name) \
|
|
|
|
i32 name(System_Functions *system, \
|
|
|
|
Application_Memory *memory, \
|
|
|
|
String current_directory, \
|
|
|
|
Command_Line_Parameters clparams \
|
|
|
|
)
|
|
|
|
|
|
|
|
typedef App_Read_Command_Line_Sig(App_Read_Command_Line);
|
|
|
|
|
|
|
|
#define App_Init_Sig(name) void \
|
|
|
|
name(System_Functions *system, \
|
|
|
|
Render_Target *target, \
|
|
|
|
Application_Memory *memory, \
|
|
|
|
Exchange *exchange, \
|
|
|
|
Key_Codes *codes, \
|
|
|
|
Clipboard_Contents clipboard, \
|
|
|
|
String current_directory, \
|
|
|
|
Custom_API api)
|
2015-11-14 04:42:06 +00:00
|
|
|
|
|
|
|
typedef App_Init_Sig(App_Init);
|
2015-09-28 23:34:55 +00:00
|
|
|
|
|
|
|
enum Application_Mouse_Cursor{
|
|
|
|
APP_MOUSE_CURSOR_DEFAULT,
|
|
|
|
APP_MOUSE_CURSOR_ARROW,
|
|
|
|
APP_MOUSE_CURSOR_IBEAM,
|
|
|
|
APP_MOUSE_CURSOR_LEFTRIGHT,
|
|
|
|
APP_MOUSE_CURSOR_UPDOWN,
|
|
|
|
// never below this
|
|
|
|
APP_MOUSE_CURSOR_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Application_Step_Result{
|
|
|
|
Application_Mouse_Cursor mouse_cursor_type;
|
2015-12-01 02:51:53 +00:00
|
|
|
b32 redraw;
|
2016-01-28 20:01:40 +00:00
|
|
|
b32 lctrl_lalt_is_altgr;
|
2015-09-28 23:34:55 +00:00
|
|
|
};
|
|
|
|
|
2016-01-28 20:01:40 +00:00
|
|
|
#define App_Step_Sig(name) void \
|
2015-11-14 04:42:06 +00:00
|
|
|
name(System_Functions *system, \
|
2015-11-16 16:15:45 +00:00
|
|
|
Key_Codes *codes, \
|
|
|
|
Key_Input_Data *input, \
|
|
|
|
Mouse_State *mouse, \
|
|
|
|
Render_Target *target, \
|
2015-11-14 04:42:06 +00:00
|
|
|
Application_Memory *memory, \
|
2016-01-06 15:39:15 +00:00
|
|
|
Exchange *exchange, \
|
2015-11-14 04:42:06 +00:00
|
|
|
Clipboard_Contents clipboard, \
|
2016-01-28 20:01:40 +00:00
|
|
|
b32 time_step, b32 first_step, b32 force_redraw, \
|
|
|
|
Application_Step_Result *result)
|
2015-11-14 04:42:06 +00:00
|
|
|
|
|
|
|
typedef App_Step_Sig(App_Step);
|
|
|
|
|
2016-01-06 15:39:15 +00:00
|
|
|
#define App_Alloc_Sig(name) void *name(void *handle, i32 size)
|
|
|
|
typedef App_Alloc_Sig(App_Alloc);
|
|
|
|
|
|
|
|
#define App_Free_Sig(name) void name(void *handle, void *block)
|
|
|
|
typedef App_Free_Sig(App_Free);
|
|
|
|
|
2015-11-14 04:42:06 +00:00
|
|
|
struct App_Functions{
|
2016-01-28 20:01:40 +00:00
|
|
|
App_Read_Command_Line *read_command_line;
|
2015-11-14 04:42:06 +00:00
|
|
|
App_Init *init;
|
|
|
|
App_Step *step;
|
2016-01-06 15:39:15 +00:00
|
|
|
|
|
|
|
App_Alloc *alloc;
|
|
|
|
App_Free *free;
|
2015-11-14 04:42:06 +00:00
|
|
|
};
|
2015-09-28 23:34:55 +00:00
|
|
|
|
2016-01-06 15:39:15 +00:00
|
|
|
#define App_Get_Functions_Sig(name) App_Functions name()
|
|
|
|
typedef App_Get_Functions_Sig(App_Get_Functions);
|
|
|
|
|
2015-09-28 23:34:55 +00:00
|
|
|
#endif
|
2015-11-14 04:42:06 +00:00
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|