MAC init and basic frame update and render working
parent
f3ea38abec
commit
82882f22f5
|
@ -490,6 +490,7 @@ private_draw_glyph_mono(System_Functions *system, Render_Target *t, Render_Font
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
launch_rendering(System_Functions *system, Render_Target *t){
|
launch_rendering(System_Functions *system, Render_Target *t){
|
||||||
|
DBG_POINT();
|
||||||
char *cursor = t->push_buffer;
|
char *cursor = t->push_buffer;
|
||||||
char *cursor_end = cursor + t->size;
|
char *cursor_end = cursor + t->size;
|
||||||
|
|
||||||
|
@ -563,16 +564,21 @@ launch_rendering(System_Functions *system, Render_Target *t){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face face, b32 use_hinting, Glyph_Page *page, u32 page_number, i32 tab_width){
|
font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face face, b32 use_hinting, Glyph_Page *page, u32 page_number, i32 tab_width){
|
||||||
|
DBG_POINT();
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
Assert(page != 0);
|
Assert(page != 0);
|
||||||
page->page_number = page_number;
|
page->page_number = page_number;
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
// prepare to read glyphs into a temporary texture buffer
|
// prepare to read glyphs into a temporary texture buffer
|
||||||
i32 max_glyph_w = face->size->metrics.x_ppem;
|
i32 max_glyph_w = face->size->metrics.x_ppem;
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
i32 max_glyph_h = font_get_height(font);
|
i32 max_glyph_h = font_get_height(font);
|
||||||
i32 tex_width = 64;
|
i32 tex_width = 64;
|
||||||
i32 tex_height = 0;
|
i32 tex_height = 0;
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
do {
|
do {
|
||||||
tex_width *= 2;
|
tex_width *= 2;
|
||||||
float glyphs_per_row = ceilf(tex_width / (float) max_glyph_w);
|
float glyphs_per_row = ceilf(tex_width / (float) max_glyph_w);
|
||||||
|
@ -580,11 +586,13 @@ font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face
|
||||||
tex_height = ceil32(rows * (max_glyph_h + 2));
|
tex_height = ceil32(rows * (max_glyph_h + 2));
|
||||||
} while(tex_height > tex_width);
|
} while(tex_height > tex_width);
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
tex_height = round_up_pot_u32(tex_height);
|
tex_height = round_up_pot_u32(tex_height);
|
||||||
|
|
||||||
i32 pen_x = 0;
|
i32 pen_x = 0;
|
||||||
i32 pen_y = 0;
|
i32 pen_y = 0;
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
u32* pixels = push_array(part, u32, tex_width * tex_height);
|
u32* pixels = push_array(part, u32, tex_width * tex_height);
|
||||||
memset(pixels, 0, tex_width * tex_height * sizeof(u32));
|
memset(pixels, 0, tex_width * tex_height * sizeof(u32));
|
||||||
|
|
||||||
|
@ -655,7 +663,10 @@ font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face
|
||||||
page->tex_width = tex_width;
|
page->tex_width = tex_width;
|
||||||
page->tex_height = tex_height;
|
page->tex_height = tex_height;
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
glGenTextures(1, &page->tex);
|
glGenTextures(1, &page->tex);
|
||||||
|
|
||||||
|
DBG_POINT();
|
||||||
glBindTexture(GL_TEXTURE_2D, page->tex);
|
glBindTexture(GL_TEXTURE_2D, page->tex);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
|
|
@ -929,7 +929,7 @@ LinuxKeycodeInit(Display* dpy){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
LinuxPushKey(Key_Code code, Key_Code chr, Key_Code chr_nocaps, b8 (*mods)[MDFR_INDEX_COUNT])
|
LinuxPushKey(Key_Code code, Key_Code chr, Key_Code chr_nocaps, b8 *mods)
|
||||||
{
|
{
|
||||||
i32 *count = &linuxvars.input.keys.count;
|
i32 *count = &linuxvars.input.keys.count;
|
||||||
Key_Event_Data *data = linuxvars.input.keys.keys;
|
Key_Event_Data *data = linuxvars.input.keys.keys;
|
||||||
|
@ -939,7 +939,7 @@ LinuxPushKey(Key_Code code, Key_Code chr, Key_Code chr_nocaps, b8 (*mods)[MDFR_I
|
||||||
data[*count].character = chr;
|
data[*count].character = chr;
|
||||||
data[*count].character_no_caps_lock = chr_nocaps;
|
data[*count].character_no_caps_lock = chr_nocaps;
|
||||||
|
|
||||||
memcpy(data[*count].modifiers, *mods, sizeof(*mods));
|
memcpy(data[*count].modifiers, mods, sizeof(*mods)*MDFR_INDEX_COUNT);
|
||||||
|
|
||||||
++(*count);
|
++(*count);
|
||||||
}
|
}
|
||||||
|
@ -1307,11 +1307,11 @@ LinuxHandleX11Events(void)
|
||||||
Key_Code special_key = keycode_lookup_table[(u8)Event.xkey.keycode];
|
Key_Code special_key = keycode_lookup_table[(u8)Event.xkey.keycode];
|
||||||
|
|
||||||
if (special_key){
|
if (special_key){
|
||||||
LinuxPushKey(special_key, 0, 0, &mods);
|
LinuxPushKey(special_key, 0, 0, mods);
|
||||||
} else if (key < 256){
|
} else if (key < 256){
|
||||||
LinuxPushKey(key, key, key_no_caps, &mods);
|
LinuxPushKey(key, key, key_no_caps, mods);
|
||||||
} else {
|
} else {
|
||||||
LinuxPushKey(0, 0, 0, &mods);
|
LinuxPushKey(0, 0, 0, mods);
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
|
@ -1748,7 +1748,7 @@ main(int argc, char **argv){
|
||||||
linuxvars.input.first_step = 1;
|
linuxvars.input.first_step = 1;
|
||||||
linuxvars.input.dt = (frame_useconds / 1000000.f);
|
linuxvars.input.dt = (frame_useconds / 1000000.f);
|
||||||
|
|
||||||
while (1){
|
for (;;){
|
||||||
if (XEventsQueued(linuxvars.XDisplay, QueuedAlready)){
|
if (XEventsQueued(linuxvars.XDisplay, QueuedAlready)){
|
||||||
LinuxHandleX11Events();
|
LinuxHandleX11Events();
|
||||||
}
|
}
|
||||||
|
@ -1825,7 +1825,7 @@ main(int argc, char **argv){
|
||||||
}
|
}
|
||||||
|
|
||||||
b32 keep_running = linuxvars.keep_running;
|
b32 keep_running = linuxvars.keep_running;
|
||||||
|
|
||||||
app.step(&sysfunc, &target, &memory_vars, &linuxvars.input, &result);
|
app.step(&sysfunc, &target, &memory_vars, &linuxvars.input, &result);
|
||||||
|
|
||||||
if (result.perform_kill){
|
if (result.perform_kill){
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
#define IS_PLAT_LAYER
|
#define IS_PLAT_LAYER
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define DBG_POINT() fprintf(stdout, "%s\n", __FILE__ ":" LINE_STR ":")
|
#define DBG_POINT() fprintf(stdout, "%s\n", __FILE__ ":" LINE_STR ":")
|
||||||
|
#else
|
||||||
|
#define DBG_POINT()
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "4ed_defines.h"
|
#include "4ed_defines.h"
|
||||||
#include "4coder_API/version.h"
|
#include "4coder_API/version.h"
|
||||||
|
@ -78,8 +83,17 @@ global System_Functions sysfunc;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
|
struct OSX_Vars{
|
||||||
|
Application_Step_Input input;
|
||||||
|
String clipboard_contents;
|
||||||
|
b32 keep_running;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
|
||||||
#include "osx_objective_c_to_cpp_links.h"
|
#include "osx_objective_c_to_cpp_links.h"
|
||||||
OSX_Vars osx;
|
OSX_Objective_C_Vars osx_objc;
|
||||||
|
OSX_Vars osxvars;
|
||||||
global Render_Target target;
|
global Render_Target target;
|
||||||
global Application_Memory memory_vars;
|
global Application_Memory memory_vars;
|
||||||
global Plat_Settings plat_settings;
|
global Plat_Settings plat_settings;
|
||||||
|
@ -135,20 +149,20 @@ Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Set_Fullscreen_Sig(system_set_fullscreen){
|
Sys_Set_Fullscreen_Sig(system_set_fullscreen){
|
||||||
osx.do_toggle = (osx.full_screen != full_screen);
|
osx_objc.do_toggle = (osx_objc.full_screen != full_screen);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Is_Fullscreen_Sig(system_is_fullscreen){
|
Sys_Is_Fullscreen_Sig(system_is_fullscreen){
|
||||||
b32 result = (osx.full_screen != osx.do_toggle);
|
b32 result = (osx_objc.full_screen != osx_objc.do_toggle);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK(allen): Why does this work differently from the win32 version!?
|
// HACK(allen): Why does this work differently from the win32 version!?
|
||||||
internal
|
internal
|
||||||
Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
|
Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
|
||||||
osx.running = false;
|
osx_objc.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "4ed_coroutine_functions.cpp"
|
#include "4ed_coroutine_functions.cpp"
|
||||||
|
@ -161,16 +175,16 @@ internal
|
||||||
Sys_Post_Clipboard_Sig(system_post_clipboard){
|
Sys_Post_Clipboard_Sig(system_post_clipboard){
|
||||||
char *string = str.str;
|
char *string = str.str;
|
||||||
if (!terminate_with_null(&str)){
|
if (!terminate_with_null(&str)){
|
||||||
if (osx.clipboard_space_max <= str.size + 1){
|
if (osx_objc.clipboard_space_max <= str.size + 1){
|
||||||
if (osx.clipboard_space != 0){
|
if (osx_objc.clipboard_space != 0){
|
||||||
system_memory_free(osx.clipboard_space, osx.clipboard_space_max);
|
system_memory_free(osx_objc.clipboard_space, osx_objc.clipboard_space_max);
|
||||||
}
|
}
|
||||||
osx.clipboard_space_max = l_round_up_u32(str.size*2 + 1, KB(4096));
|
osx_objc.clipboard_space_max = l_round_up_u32(str.size*2 + 1, KB(4096));
|
||||||
osx.clipboard_space = (char*)system_memory_allocate(osx.clipboard_space_max);
|
osx_objc.clipboard_space = (char*)system_memory_allocate(osx_objc.clipboard_space_max);
|
||||||
}
|
}
|
||||||
memcpy(osx.clipboard_space, str.str, str.size);
|
memcpy(osx_objc.clipboard_space, str.str, str.size);
|
||||||
osx.clipboard_space[str.size] = 0;
|
osx_objc.clipboard_space[str.size] = 0;
|
||||||
string = osx.clipboard_space;
|
string = osx_objc.clipboard_space;
|
||||||
}
|
}
|
||||||
osx_post_to_clipboard(string);
|
osx_post_to_clipboard(string);
|
||||||
}
|
}
|
||||||
|
@ -224,37 +238,172 @@ osx_allocate(umem size){
|
||||||
external void
|
external void
|
||||||
osx_resize(int width, int height){
|
osx_resize(int width, int height){
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
osx.width = width;
|
osx_objc.width = width;
|
||||||
osx.height = height;
|
osx_objc.height = height;
|
||||||
// TODO
|
|
||||||
|
if (width > 0 && height > 0){
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glOrtho(0, width, height, 0, -1, 1);
|
||||||
|
glScissor(0, 0, width, height);
|
||||||
|
|
||||||
|
target.width = width;
|
||||||
|
target.height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
osx_push_key(Key_Code code, Key_Code chr, Key_Code chr_nocaps, b8 *mods)
|
||||||
|
{
|
||||||
|
i32 count = osxvars.input.keys.count;
|
||||||
|
|
||||||
|
if (count < KEY_INPUT_BUFFER_SIZE){
|
||||||
|
Key_Event_Data *data = osxvars.input.keys.keys;
|
||||||
|
|
||||||
|
data[count].keycode = code;
|
||||||
|
data[count].character = chr;
|
||||||
|
data[count].character_no_caps_lock = chr_nocaps;
|
||||||
|
|
||||||
|
memcpy(data[count].modifiers, mods, sizeof(*mods)*MDFR_INDEX_COUNT);
|
||||||
|
|
||||||
|
osxvars.input.keys.count = count + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
external void
|
external void
|
||||||
osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
|
osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
// TODO
|
Key_Code c = 0;
|
||||||
|
switch (code){
|
||||||
|
// TODO(allen): Find the canonical list of these things.
|
||||||
|
case 0x007F: c = key_back; break;
|
||||||
|
case 0xF700: c = key_up; break;
|
||||||
|
case 0xF701: c = key_down; break;
|
||||||
|
case 0xF702: c = key_left; break;
|
||||||
|
case 0xF703: c = key_right; break;
|
||||||
|
case 0x001B: c = key_esc; break;
|
||||||
|
|
||||||
|
case 0xF704: c = key_f1; break;
|
||||||
|
case 0xF705: c = key_f2; break;
|
||||||
|
case 0xF706: c = key_f3; break;
|
||||||
|
case 0xF707: c = key_f4; break;
|
||||||
|
|
||||||
|
case 0xF708: c = key_f5; break;
|
||||||
|
case 0xF709: c = key_f6; break;
|
||||||
|
case 0xF70A: c = key_f7; break;
|
||||||
|
case 0xF70B: c = key_f8; break;
|
||||||
|
|
||||||
|
case 0xF70C: c = key_f9; break;
|
||||||
|
case 0xF70D: c = key_f10; break;
|
||||||
|
case 0xF70E: c = key_f11; break;
|
||||||
|
case 0xF70F: c = key_f12; break;
|
||||||
|
|
||||||
|
case 0xF710: c = key_f13; break;
|
||||||
|
case 0xF711: c = key_f14; break;
|
||||||
|
case 0xF712: c = key_f15; break;
|
||||||
|
case 0xF713: c = key_f16; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
b8 mods[MDFR_INDEX_COUNT] = {0};
|
||||||
|
|
||||||
|
if (modifier_flags.shift) mods[MDFR_SHIFT_INDEX] = 1;
|
||||||
|
if (modifier_flags.command) mods[MDFR_CONTROL_INDEX] = 1;
|
||||||
|
if (modifier_flags.caps) mods[MDFR_CAPS_INDEX] = 1;
|
||||||
|
if (modifier_flags.control) mods[MDFR_ALT_INDEX] = 1;
|
||||||
|
|
||||||
|
if (c != 0){
|
||||||
|
osx_push_key(c, 0, 0, mods);
|
||||||
|
}
|
||||||
|
else if (code != 0){
|
||||||
|
if (code == '\r'){
|
||||||
|
code = '\n';
|
||||||
|
}
|
||||||
|
Key_Code nocaps = code;
|
||||||
|
if (modifier_flags.caps){
|
||||||
|
if ('a' <= nocaps && nocaps <= 'z'){
|
||||||
|
nocaps += 'A' - 'a';
|
||||||
|
}
|
||||||
|
else if ('A' <= nocaps && nocaps <= 'Z'){
|
||||||
|
nocaps += 'a' - 'A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
osx_push_key(code, code, nocaps, mods);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
osx_push_key(0, 0, 0, mods);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
external void
|
external void
|
||||||
osx_mouse(i32 mx, i32 my, u32 type){
|
osx_mouse(i32 mx, i32 my, u32 type){
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
// TODO
|
osxvars.input.mouse.x = mx;
|
||||||
|
osxvars.input.mouse.y = my;
|
||||||
|
if (type == MouseType_Press){
|
||||||
|
osxvars.input.mouse.press_l = true;
|
||||||
|
osxvars.input.mouse.l = true;
|
||||||
|
}
|
||||||
|
if (type == MouseType_Release){
|
||||||
|
osxvars.input.mouse.l = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
external void
|
external void
|
||||||
osx_mouse_wheel(float dx, float dy){
|
osx_mouse_wheel(float dx, float dy){
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
// TODO
|
if (dy > 0){
|
||||||
|
osxvars.input.mouse.wheel = 1;
|
||||||
|
}
|
||||||
|
else if (dy < 0){
|
||||||
|
osxvars.input.mouse.wheel = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
external void
|
external void
|
||||||
osx_step(){
|
osx_step(){
|
||||||
DBG_POINT();
|
Application_Step_Result result = {};
|
||||||
// TODO
|
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
||||||
|
result.trying_to_kill = !osxvars.keep_running;
|
||||||
|
|
||||||
|
osxvars.input.clipboard = null_string;
|
||||||
|
|
||||||
|
app.step(&sysfunc, &target, &memory_vars, &osxvars.input, &result);
|
||||||
|
launch_rendering(&sysfunc, &target);
|
||||||
|
|
||||||
|
osxvars.input.first_step = false;
|
||||||
|
osxvars.input.keys = null_key_input_data;
|
||||||
|
osxvars.input.mouse.press_l = false;
|
||||||
|
osxvars.input.mouse.release_l = false;
|
||||||
|
osxvars.input.mouse.press_r = false;
|
||||||
|
osxvars.input.mouse.release_r = false;
|
||||||
|
osxvars.input.mouse.wheel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
external void
|
external void
|
||||||
osx_init(){
|
osx_init(){
|
||||||
|
// TODO(allen): Setup GL DEBUG MESSAGE
|
||||||
|
#if defined(FRED_INTERNAL) && 0
|
||||||
|
//
|
||||||
|
// OpenGL Init
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackProc;
|
||||||
|
|
||||||
|
GLXLOAD(glDebugMessageCallback);
|
||||||
|
|
||||||
|
if (glDebugMessageCallback){
|
||||||
|
LOG("Enabling GL Debug Callback\n");
|
||||||
|
glDebugMessageCallback(&LinuxGLDebugCallback, 0);
|
||||||
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
//
|
//
|
||||||
// System Linkage
|
// System Linkage
|
||||||
//
|
//
|
||||||
|
@ -276,6 +425,9 @@ osx_init(){
|
||||||
memset(&custom_api, 0, sizeof(custom_api));
|
memset(&custom_api, 0, sizeof(custom_api));
|
||||||
|
|
||||||
memory_init();
|
memory_init();
|
||||||
|
|
||||||
|
osxvars.keep_running = true;
|
||||||
|
osxvars.input.first_step = true;
|
||||||
|
|
||||||
//
|
//
|
||||||
// HACK(allen):
|
// HACK(allen):
|
||||||
|
@ -303,7 +455,7 @@ osx_init(){
|
||||||
//
|
//
|
||||||
|
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
read_command_line(osx.argc, osx.argv);
|
read_command_line(osx_objc.argc, osx_objc.argv);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Threads
|
// Threads
|
||||||
|
@ -344,13 +496,13 @@ osx_init(){
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
|
|
||||||
String clipboard_string = {0};
|
String clipboard_string = {0};
|
||||||
if (osx.has_clipboard_item){
|
if (osx_objc.has_clipboard_item){
|
||||||
clipboard_string = make_string(osx.clipboard_data, osx.clipboard_size);
|
clipboard_string = make_string(osx_objc.clipboard_data, osx_objc.clipboard_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG_POINT();
|
DBG_POINT();
|
||||||
fprintf(stdout, "%p\n", app.init);
|
fprintf(stdout, "%p\n", app.init);
|
||||||
|
|
||||||
LOG("Initializing application variables\n");
|
LOG("Initializing application variables\n");
|
||||||
app.init(&sysfunc, &target, &memory_vars, clipboard_string, curdir, custom_api);
|
app.init(&sysfunc, &target, &memory_vars, clipboard_string, curdir, custom_api);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "4ed_defines.h"
|
#include "4ed_defines.h"
|
||||||
#include "4coder_API/version.h"
|
#include "4coder_API/version.h"
|
||||||
|
#include "4coder_API/keycodes.h"
|
||||||
|
|
||||||
#define WINDOW_NAME "4coder" VERSION
|
#define WINDOW_NAME "4coder" VERSION
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ osx_post_to_clipboard(char *str){
|
||||||
[board declareTypes:typesArray owner:nil];
|
[board declareTypes:typesArray owner:nil];
|
||||||
NSString *paste_string = [NSString stringWithUTF8String:str];
|
NSString *paste_string = [NSString stringWithUTF8String:str];
|
||||||
[board setString:paste_string forType:utf8_type];
|
[board setString:paste_string forType:utf8_type];
|
||||||
osx.just_posted_to_clipboard = true;
|
osx_objc.just_posted_to_clipboard = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -81,6 +82,7 @@ static DISPLINK_SIG(osx_display_link);
|
||||||
mods.command = ((flags & NSEventModifierFlagCommand) != 0);
|
mods.command = ((flags & NSEventModifierFlagCommand) != 0);
|
||||||
mods.control = ((flags & NSEventModifierFlagControl) != 0);
|
mods.control = ((flags & NSEventModifierFlagControl) != 0);
|
||||||
mods.option = ((flags & NSEventModifierFlagOption) != 0);
|
mods.option = ((flags & NSEventModifierFlagOption) != 0);
|
||||||
|
mods.caps = ((flags & NSEventModifierFlagCapsLock) != 0);
|
||||||
|
|
||||||
u32 length = real.length;
|
u32 length = real.length;
|
||||||
for (u32 i = 0; i < length; ++i){
|
for (u32 i = 0; i < length; ++i){
|
||||||
|
@ -118,10 +120,10 @@ static DISPLINK_SIG(osx_display_link);
|
||||||
- (CVReturn)getFrameForTime:(const CVTimeStamp*)time{
|
- (CVReturn)getFrameForTime:(const CVTimeStamp*)time{
|
||||||
@autoreleasepool
|
@autoreleasepool
|
||||||
{
|
{
|
||||||
if (osx.running){
|
if (osx_objc.running){
|
||||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||||
if (board.changeCount != osx.prev_clipboard_change_count){
|
if (board.changeCount != osx_objc.prev_clipboard_change_count){
|
||||||
if (!osx.just_posted_to_clipboard){
|
if (!osx_objc.just_posted_to_clipboard){
|
||||||
NSString *utf8_type = @"public.utf8-plain-text";
|
NSString *utf8_type = @"public.utf8-plain-text";
|
||||||
NSArray *array = [NSArray arrayWithObjects: utf8_type, nil];
|
NSArray *array = [NSArray arrayWithObjects: utf8_type, nil];
|
||||||
NSString *has_string = [board availableTypeFromArray:array];
|
NSString *has_string = [board availableTypeFromArray:array];
|
||||||
|
@ -131,20 +133,20 @@ static DISPLINK_SIG(osx_display_link);
|
||||||
u32 copy_length = data.length;
|
u32 copy_length = data.length;
|
||||||
if (copy_length > 0){
|
if (copy_length > 0){
|
||||||
// TODO(allen): Grow clipboard memory if needed.
|
// TODO(allen): Grow clipboard memory if needed.
|
||||||
if (copy_length+1 < osx.clipboard_max){
|
if (copy_length+1 < osx_objc.clipboard_max){
|
||||||
osx.clipboard_size = copy_length;
|
osx_objc.clipboard_size = copy_length;
|
||||||
[data getBytes: osx.clipboard_data length: copy_length];
|
[data getBytes: osx_objc.clipboard_data length: copy_length];
|
||||||
((char*)osx.clipboard_data)[copy_length] = 0;
|
((char*)osx_objc.clipboard_data)[copy_length] = 0;
|
||||||
osx.has_clipboard_item = true;
|
osx_objc.has_clipboard_item = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
osx.just_posted_to_clipboard = false;
|
osx_objc.just_posted_to_clipboard = false;
|
||||||
}
|
}
|
||||||
osx.prev_clipboard_change_count = board.changeCount;
|
osx_objc.prev_clipboard_change_count = board.changeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLLockContext([[self openGLContext] CGLContextObj]);
|
CGLLockContext([[self openGLContext] CGLContextObj]);
|
||||||
|
@ -167,7 +169,7 @@ static DISPLINK_SIG(osx_display_link);
|
||||||
|
|
||||||
- (void)init_gl
|
- (void)init_gl
|
||||||
{
|
{
|
||||||
if(osx.running)
|
if(osx_objc.running)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +203,7 @@ static DISPLINK_SIG(osx_display_link);
|
||||||
|
|
||||||
[context makeCurrentContext];
|
[context makeCurrentContext];
|
||||||
|
|
||||||
osx.running = true;
|
osx_objc.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
|
@ -284,6 +286,15 @@ DISPLINK_SIG(osx_display_link){
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
typedef struct File_Change_Queue{
|
||||||
|
char *buffer;
|
||||||
|
char *read_ptr;
|
||||||
|
char *write_ptr;
|
||||||
|
char *end;
|
||||||
|
} File_Change_Queue;
|
||||||
|
|
||||||
|
static File_Change_Queue file_change_queue = {0};
|
||||||
|
|
||||||
void
|
void
|
||||||
osx_add_file_listener(char *file_name){
|
osx_add_file_listener(char *file_name){
|
||||||
NotImplemented;
|
NotImplemented;
|
||||||
|
@ -294,24 +305,47 @@ osx_remove_file_listener(char *file_name){
|
||||||
NotImplemented;
|
NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
block_split_copy(void *dst, void *src1, i32 size1, void *src2, i32 size2){
|
||||||
|
memcpy(dst, src1, size1);
|
||||||
|
memcpy((u8*)dst + size1, src2, size2);
|
||||||
|
}
|
||||||
|
|
||||||
i32
|
i32
|
||||||
osx_get_file_change_event(char *buffer, i32 max, i32 *size){
|
osx_get_file_change_event(char *buffer, i32 max, i32 *size){
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
NotImplemented;
|
if (file_change_queue.read_ptr != file_change_queue.write_ptr){
|
||||||
|
i32 change_size = *(i32*)file_change_queue.read_ptr;
|
||||||
|
if (max <= change_size){
|
||||||
|
char *b1 = file_change_queue.read_ptr + 4;
|
||||||
|
char *b2 = file_change_queue.buffer;
|
||||||
|
i32 b1_size = Min(change_size, (i32)(file_change_queue.end - b1));
|
||||||
|
i32 b2_size = change_size - b1_size;
|
||||||
|
block_split_copy(buffer, b1, b1_size, b2, b2_size);
|
||||||
|
if (b1 < file_change_queue.end){
|
||||||
|
file_change_queue.read_ptr = b1 + change_size;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
file_change_queue.read_ptr = b2 + b2_size;
|
||||||
|
}
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv){
|
main(int argc, char **argv){
|
||||||
memset(&osx, 0, sizeof(osx));
|
memset(&osx_objc, 0, sizeof(osx_objc));
|
||||||
|
|
||||||
umem clipboard_size = MB(4);
|
umem clipboard_size = MB(4);
|
||||||
osx.clipboard_data = osx_allocate(clipboard_size);
|
osx_objc.clipboard_data = osx_allocate(clipboard_size);
|
||||||
osx.clipboard_max = clipboard_size;
|
osx_objc.clipboard_max = clipboard_size;
|
||||||
osx.argc = argc;
|
osx_objc.argc = argc;
|
||||||
osx.argv = argv;
|
osx_objc.argv = argv;
|
||||||
|
|
||||||
osx_init();
|
|
||||||
|
|
||||||
@autoreleasepool{
|
@autoreleasepool{
|
||||||
NSApplication *app = [NSApplication sharedApplication];
|
NSApplication *app = [NSApplication sharedApplication];
|
||||||
|
@ -337,6 +371,8 @@ main(int argc, char **argv){
|
||||||
[window setTitle:@WINDOW_NAME];
|
[window setTitle:@WINDOW_NAME];
|
||||||
[window makeKeyAndOrderFront:nil];
|
[window makeKeyAndOrderFront:nil];
|
||||||
|
|
||||||
|
osx_init();
|
||||||
|
|
||||||
[NSApp run];
|
[NSApp run];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,10 @@ typedef struct OSX_Keyboard_Modifiers{
|
||||||
b32 command;
|
b32 command;
|
||||||
b32 control;
|
b32 control;
|
||||||
b32 option;
|
b32 option;
|
||||||
|
b32 caps;
|
||||||
} OSX_Keyboard_Modifiers;
|
} OSX_Keyboard_Modifiers;
|
||||||
|
|
||||||
typedef struct OSX_Vars{
|
typedef struct OSX_Objective_C_Vars{
|
||||||
i32 width, height;
|
i32 width, height;
|
||||||
b32 running;
|
b32 running;
|
||||||
u32 key_count;
|
u32 key_count;
|
||||||
|
@ -45,10 +46,10 @@ typedef struct OSX_Vars{
|
||||||
|
|
||||||
i32 argc;
|
i32 argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
} OSX_Vars;
|
} OSX_Objective_C_Vars;
|
||||||
|
|
||||||
// In C++ layer.
|
// In C++ layer.
|
||||||
extern OSX_Vars osx;
|
extern OSX_Objective_C_Vars osx_objc;
|
||||||
|
|
||||||
external void*
|
external void*
|
||||||
osx_allocate(umem size);
|
osx_allocate(umem size);
|
||||||
|
|
Loading…
Reference in New Issue