Mac: more key codes, cursor hiding/setting, fullscreen toggling
This commit is contained in:
parent
5f7de6acaa
commit
7aa46e8c48
|
@ -120,7 +120,15 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
|
|||
parse_context_id = parse_context_language_rust;
|
||||
}
|
||||
|
||||
if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc") || match(ext, "glsl") || match(ext, "m")){
|
||||
if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){
|
||||
if (parse_context_language_cpp == 0){
|
||||
init_language_cpp(app);
|
||||
}
|
||||
parse_context_id = parse_context_language_cpp;
|
||||
}
|
||||
|
||||
// TODO(NAME): Real GLSL highlighting
|
||||
if (match(ext, "glsl")){
|
||||
if (parse_context_language_cpp == 0){
|
||||
init_language_cpp(app);
|
||||
}
|
||||
|
|
11
4ed.h
11
4ed.h
|
@ -86,16 +86,7 @@ void name(System_Functions *system, Render_Target *target, Application_Memory *m
|
|||
|
||||
typedef App_Init_Sig(App_Init);
|
||||
|
||||
|
||||
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
|
||||
};
|
||||
#include "4ed_cursor_codes.h"
|
||||
|
||||
struct Application_Step_Result{
|
||||
Application_Mouse_Cursor mouse_cursor_type;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 07.11.2017
|
||||
*
|
||||
* Application Cursor Codes
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#if !defined(FRED_CURSOR_CODES_H)
|
||||
#define FRED_CURSOR_CODES_H
|
||||
|
||||
typedef 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
|
||||
} Application_Mouse_Cursor;
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -144,7 +144,17 @@ system_schedule_step(void){
|
|||
|
||||
internal
|
||||
Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){
|
||||
// TODO(allen)
|
||||
switch (show){
|
||||
case MouseCursorShow_Never:
|
||||
{
|
||||
osx_show_cursor(-1, 0);
|
||||
}break;
|
||||
|
||||
case MouseCursorShow_Always:
|
||||
{
|
||||
osx_show_cursor(1, 0);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
internal
|
||||
|
@ -290,9 +300,6 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
|
|||
|
||||
cli->exit = WEXITSTATUS(status);
|
||||
|
||||
//struct epoll_event e = {};
|
||||
//epoll_ctl(linuxvars.epoll, EPOLL_CTL_DEL, *(int*)&cli->out_read, &e);
|
||||
|
||||
close(*(int*)&cli->out_read);
|
||||
close(*(int*)&cli->out_write);
|
||||
|
||||
|
@ -368,6 +375,11 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
|
|||
case 0xF701: c = key_down; break;
|
||||
case 0xF702: c = key_left; break;
|
||||
case 0xF703: c = key_right; break;
|
||||
case 0xF728: c = key_del; break;
|
||||
case 0xF729: c = key_home; break;
|
||||
case 0xF72B: c = key_end; break;
|
||||
case 0xF72C: c = key_page_up; break;
|
||||
case 0xF72D: c = key_page_down; break;
|
||||
case 0x001B: c = key_esc; break;
|
||||
|
||||
case 0xF704: c = key_f1; break;
|
||||
|
@ -403,6 +415,7 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
|
|||
osx_push_key(c, 0, 0, mods);
|
||||
}
|
||||
else if (code != 0){
|
||||
if (code < 0xE000 || code > 0xF8FF){
|
||||
if (code == '\r'){
|
||||
code = '\n';
|
||||
}
|
||||
|
@ -418,6 +431,10 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){
|
|||
}
|
||||
osx_push_key(code, chr, nocaps, mods);
|
||||
}
|
||||
else{
|
||||
fprintf(stdout, "unhandled private code %x\n", code);
|
||||
}
|
||||
}
|
||||
else{
|
||||
osx_push_key(0, 0, 0, mods);
|
||||
}
|
||||
|
@ -429,7 +446,7 @@ external void
|
|||
osx_mouse(i32 mx, i32 my, u32 type){
|
||||
i32 new_x = mx;
|
||||
i32 new_y = osx_objc.height - my;
|
||||
if (new_x != osxvars.input.mouse.x && new_y != osxvars.input.mouse.y){
|
||||
if (new_x != osxvars.input.mouse.x || new_y != osxvars.input.mouse.y){
|
||||
osxvars.input.mouse.x = new_x;
|
||||
osxvars.input.mouse.y = new_y;
|
||||
osx_schedule_step();
|
||||
|
@ -501,6 +518,9 @@ osx_step(void){
|
|||
osxvars.input.mouse.release_r = false;
|
||||
osxvars.input.mouse.wheel = 0;
|
||||
|
||||
osx_objc.do_toggle = false;
|
||||
osx_objc.full_screen = osx_is_fullscreen();
|
||||
|
||||
// HACK(allen): THIS SHIT IS FUCKED (happens on linux too)
|
||||
b32 keep_running = osxvars.keep_running;
|
||||
|
||||
|
@ -513,6 +533,12 @@ osx_step(void){
|
|||
osxvars.keep_running = true;
|
||||
}
|
||||
|
||||
if (osx_objc.do_toggle){
|
||||
osx_toggle_fullscreen();
|
||||
}
|
||||
|
||||
osx_show_cursor(0, result.mouse_cursor_type);
|
||||
|
||||
launch_rendering(&sysfunc, &target);
|
||||
|
||||
if (result.animating || cli_count > 0){
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "4coder_API/version.h"
|
||||
#include "4coder_API/keycodes.h"
|
||||
|
||||
#include "4ed_cursor_codes.h"
|
||||
|
||||
#define WINDOW_NAME "4coder " VERSION
|
||||
|
||||
#undef internal
|
||||
|
@ -256,27 +258,11 @@ static DISPLINK_SIG(osx_display_link);
|
|||
|
||||
GLint swapInt = 1;
|
||||
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
|
||||
|
||||
#if 0
|
||||
CVReturn cvreturn = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
|
||||
cvreturn = CVDisplayLinkSetOutputCallback(displayLink, &osx_display_link, (__bridge void*)(self));
|
||||
|
||||
CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
|
||||
CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
|
||||
cvreturn = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
|
||||
|
||||
CVDisplayLinkStart(displayLink);
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
|
||||
#if 0
|
||||
CVDisplayLinkStop(displayLink);
|
||||
CVDisplayLinkRelease(displayLink);
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstResponder
|
||||
|
@ -605,7 +591,49 @@ osx_get_file_change_event(char *buffer, i32 max, i32 *size){
|
|||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
osx_show_cursor(i32 show, i32 cursor_type){
|
||||
local_persist b32 cursor_is_shown = 1;
|
||||
if (show == 1){
|
||||
if (!cursor_is_shown){
|
||||
[NSCursor unhide];
|
||||
cursor_is_shown = true;
|
||||
}
|
||||
}
|
||||
else if (show == -1){
|
||||
if (cursor_is_shown){
|
||||
[NSCursor hide];
|
||||
cursor_is_shown = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor_type > 0){
|
||||
switch (cursor_type){
|
||||
case APP_MOUSE_CURSOR_ARROW:
|
||||
{
|
||||
[[NSCursor arrowCursor] set];
|
||||
}break;
|
||||
|
||||
case APP_MOUSE_CURSOR_IBEAM:
|
||||
{
|
||||
[[NSCursor IBeamCursor] set];
|
||||
}break;
|
||||
|
||||
case APP_MOUSE_CURSOR_LEFTRIGHT:
|
||||
{
|
||||
[[NSCursor resizeLeftRightCursor] set];
|
||||
}break;
|
||||
|
||||
case APP_MOUSE_CURSOR_UPDOWN:
|
||||
{
|
||||
[[NSCursor resizeUpDownCursor] set];
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
My4coderView* view = 0;
|
||||
NSWindow* window = 0;
|
||||
|
||||
void
|
||||
osx_schedule_step(void){
|
||||
|
@ -620,6 +648,17 @@ osx_schedule_step(void){
|
|||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
osx_toggle_fullscreen(void){
|
||||
[window toggleFullScreen:nil];
|
||||
}
|
||||
|
||||
b32
|
||||
osx_is_fullscreen(void){
|
||||
b32 result = (([window styleMask] & NSFullScreenWindowMask) != 0);
|
||||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
osx_close_app(void){
|
||||
[NSApp terminate: nil];
|
||||
|
@ -648,7 +687,7 @@ main(int argc, char **argv){
|
|||
NSRect frame = NSMakeRect((screenRect.size.width - w) * 0.5, (screenRect.size.height - h) * 0.5, w, h);
|
||||
|
||||
u32 flags = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||
NSWindow* window = [[NSWindow alloc] initWithContentRect:frame styleMask:flags backing:NSBackingStoreBuffered defer:NO];
|
||||
window = [[NSWindow alloc] initWithContentRect:frame styleMask:flags backing:NSBackingStoreBuffered defer:NO];
|
||||
|
||||
[window setAcceptsMouseMovedEvents:YES];
|
||||
|
||||
|
|
|
@ -102,9 +102,18 @@ osx_remove_file_listener(char *file_name);
|
|||
external i32
|
||||
osx_get_file_change_event(char *buffer, i32 max, i32 *size);
|
||||
|
||||
external void
|
||||
osx_show_cursor(i32 show_inc, i32 cursor_type);
|
||||
|
||||
external void
|
||||
osx_schedule_step(void);
|
||||
|
||||
external void
|
||||
osx_toggle_fullscreen(void);
|
||||
|
||||
external b32
|
||||
osx_is_fullscreen(void);
|
||||
|
||||
external void
|
||||
osx_close_app(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue