Use NSPasteboard for clipboard in Cocoa

This commit is contained in:
UnknownShadow200 2021-07-15 22:49:44 +10:00
parent 5a4e5d6fa0
commit 3a33e94a94
8 changed files with 136 additions and 107 deletions

View File

@ -60,7 +60,7 @@ void LBackend_ResetArea(int x, int y, int width, int height) {
if (Launcher_ClassicBackground && dirtBmp.scan0) { if (Launcher_ClassicBackground && dirtBmp.scan0) {
ClearTile(x, y, width, height, &stoneBmp); ClearTile(x, y, width, height, &stoneBmp);
} else { } else {
Gradient_Noise(&Launcher_Framebuffer, Launcher_BackgroundCol, 6, x, y, width, height); Gradient_Noise(&Launcher_Framebuffer, Launcher_BackgroundColor, 6, x, y, width, height);
} }
} }
@ -112,7 +112,7 @@ static void LButton_DrawBackground(struct LButton* w) {
w->x + xBorder, w->y + yBorder, w->x + xBorder, w->y + yBorder,
w->width - xBorder2, w->height - yBorder2); w->width - xBorder2, w->height - yBorder2);
} else { } else {
col = w->hovered ? Launcher_ButtonForeActiveCol : Launcher_ButtonForeCol; col = w->hovered ? Launcher_ButtonForeActiveColor : Launcher_ButtonForeColor;
Gradient_Vertical(&Launcher_Framebuffer, LButton_Expand(col, 8), LButton_Expand(col, -8), Gradient_Vertical(&Launcher_Framebuffer, LButton_Expand(col, 8), LButton_Expand(col, -8),
w->x + xBorder, w->y + yBorder, w->x + xBorder, w->y + yBorder,
w->width - xBorder2, w->height - yBorder2); w->width - xBorder2, w->height - yBorder2);
@ -121,7 +121,7 @@ static void LButton_DrawBackground(struct LButton* w) {
static void LButton_DrawBorder(struct LButton* w) { static void LButton_DrawBorder(struct LButton* w) {
BitmapCol black = BitmapCol_Make(0, 0, 0, 255); BitmapCol black = BitmapCol_Make(0, 0, 0, 255);
BitmapCol backCol = Launcher_ClassicBackground ? black : Launcher_ButtonBorderCol; BitmapCol backCol = Launcher_ClassicBackground ? black : Launcher_ButtonBorderColor;
Drawer2D_Clear(&Launcher_Framebuffer, backCol, Drawer2D_Clear(&Launcher_Framebuffer, backCol,
w->x + xBorder, w->y, w->x + xBorder, w->y,
@ -151,7 +151,7 @@ static void LButton_DrawHighlight(struct LButton* w) {
w->x + xBorder, w->y + yBorder2, w->x + xBorder, w->y + yBorder2,
xBorder, w->height - yBorder4); xBorder, w->height - yBorder4);
} else if (!w->hovered) { } else if (!w->hovered) {
Drawer2D_Clear(&Launcher_Framebuffer, Launcher_ButtonHighlightCol, Drawer2D_Clear(&Launcher_Framebuffer, Launcher_ButtonHighlightColor,
w->x + xBorder2, w->y + yBorder, w->x + xBorder2, w->y + yBorder,
w->width - xBorder4, yBorder); w->width - xBorder4, yBorder);
} }
@ -289,7 +289,7 @@ void LBackend_DrawLabel(struct LLabel* w) {
*#########################################################################################################################*/ *#########################################################################################################################*/
#define CLASSIC_LINE_COL BitmapCol_Make(128,128,128, 255) #define CLASSIC_LINE_COL BitmapCol_Make(128,128,128, 255)
void LBackend_DrawLine(struct LLine* w) { void LBackend_DrawLine(struct LLine* w) {
BitmapCol col = Launcher_ClassicBackground ? CLASSIC_LINE_COL : Launcher_ButtonBorderCol; BitmapCol col = Launcher_ClassicBackground ? CLASSIC_LINE_COL : Launcher_ButtonBorderColor;
Gradient_Blend(&Launcher_Framebuffer, col, 128, w->x, w->y, w->width, w->height); Gradient_Blend(&Launcher_Framebuffer, col, 128, w->x, w->y, w->width, w->height);
} }

View File

@ -340,11 +340,11 @@ CC_NOINLINE static void ColoursScreen_Update(struct ColoursScreen* s, int i, Bit
} }
CC_NOINLINE static void ColoursScreen_UpdateAll(struct ColoursScreen* s) { CC_NOINLINE static void ColoursScreen_UpdateAll(struct ColoursScreen* s) {
ColoursScreen_Update(s, 0, Launcher_BackgroundCol); ColoursScreen_Update(s, 0, Launcher_BackgroundColor);
ColoursScreen_Update(s, 3, Launcher_ButtonBorderCol); ColoursScreen_Update(s, 3, Launcher_ButtonBorderColor);
ColoursScreen_Update(s, 6, Launcher_ButtonHighlightCol); ColoursScreen_Update(s, 6, Launcher_ButtonHighlightColor);
ColoursScreen_Update(s, 9, Launcher_ButtonForeCol); ColoursScreen_Update(s, 9, Launcher_ButtonForeColor);
ColoursScreen_Update(s, 12, Launcher_ButtonForeActiveCol); ColoursScreen_Update(s, 12, Launcher_ButtonForeActiveColor);
} }
static void ColoursScreen_TextChanged(struct LInput* w) { static void ColoursScreen_TextChanged(struct LInput* w) {
@ -353,11 +353,11 @@ static void ColoursScreen_TextChanged(struct LInput* w) {
BitmapCol* col; BitmapCol* col;
cc_uint8 r, g, b; cc_uint8 r, g, b;
if (index < 3) col = &Launcher_BackgroundCol; if (index < 3) col = &Launcher_BackgroundColor;
else if (index < 6) col = &Launcher_ButtonBorderCol; else if (index < 6) col = &Launcher_ButtonBorderColor;
else if (index < 9) col = &Launcher_ButtonHighlightCol; else if (index < 9) col = &Launcher_ButtonHighlightColor;
else if (index < 12) col = &Launcher_ButtonForeCol; else if (index < 12) col = &Launcher_ButtonForeColor;
else col = &Launcher_ButtonForeActiveCol; else col = &Launcher_ButtonForeActiveColor;
/* if index of G input, changes to index of R input */ /* if index of G input, changes to index of R input */
index = (index / 3) * 3; index = (index / 3) * 3;

View File

@ -676,14 +676,14 @@ static void LTable_DrawGridlines(struct LTable* w) {
if (Launcher_ClassicBackground) return; if (Launcher_ClassicBackground) return;
x = w->x; x = w->x;
Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundCol, Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundColor,
x, w->y + w->hdrHeight, w->width, gridlineHeight); x, w->y + w->hdrHeight, w->width, gridlineHeight);
for (i = 0; i < w->numColumns; i++) { for (i = 0; i < w->numColumns; i++) {
x += w->columns[i].width; x += w->columns[i].width;
if (!w->columns[i].hasGridline) continue; if (!w->columns[i].hasGridline) continue;
Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundCol, Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundColor,
x, w->y, gridlineWidth, w->height); x, w->y, gridlineWidth, w->height);
x += gridlineWidth; x += gridlineWidth;
} }
@ -757,8 +757,8 @@ static void LTable_DrawRows(struct LTable* w) {
static void LTable_DrawScrollbar(struct LTable* w) { static void LTable_DrawScrollbar(struct LTable* w) {
BitmapCol classicBack = BitmapCol_Make( 80, 80, 80, 255); BitmapCol classicBack = BitmapCol_Make( 80, 80, 80, 255);
BitmapCol classicScroll = BitmapCol_Make(160, 160, 160, 255); BitmapCol classicScroll = BitmapCol_Make(160, 160, 160, 255);
BitmapCol backCol = Launcher_ClassicBackground ? classicBack : Launcher_ButtonBorderCol; BitmapCol backCol = Launcher_ClassicBackground ? classicBack : Launcher_ButtonBorderColor;
BitmapCol scrollCol = Launcher_ClassicBackground ? classicScroll : Launcher_ButtonForeActiveCol; BitmapCol scrollCol = Launcher_ClassicBackground ? classicScroll : Launcher_ButtonForeActiveColor;
int x, y, height; int x, y, height;
x = w->x + w->width - scrollbarWidth; x = w->x + w->width - scrollbarWidth;

View File

@ -355,24 +355,24 @@ void Launcher_Run(void) {
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Colours/Skin----------------------------------------------------* *---------------------------------------------------------Colours/Skin----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
#define DEFAULT_BACKGROUND_COL BitmapCol_Make(153, 127, 172, 255) #define DEFAULT_BACKGROUND_COLOR BitmapCol_Make(153, 127, 172, 255)
#define DEFAULT_BUTTON_BORDER_COL BitmapCol_Make( 97, 81, 110, 255) #define DEFAULT_BUTTON_BORDER_COLOR BitmapCol_Make( 97, 81, 110, 255)
#define DEFAULT_BUTTON_FORE_ACTIVE_COL BitmapCol_Make(189, 168, 206, 255) #define DEFAULT_BUTTON_FORE_ACTIVE_COLOR BitmapCol_Make(189, 168, 206, 255)
#define DEFAULT_BUTTON_FORE_COL BitmapCol_Make(141, 114, 165, 255) #define DEFAULT_BUTTON_FORE_COLOR BitmapCol_Make(141, 114, 165, 255)
#define DEFAULT_BUTTON_HIGHLIGHT_COL BitmapCol_Make(162, 131, 186, 255) #define DEFAULT_BUTTON_HIGHLIGHT_COLOR BitmapCol_Make(162, 131, 186, 255)
BitmapCol Launcher_BackgroundCol = DEFAULT_BACKGROUND_COL; BitmapCol Launcher_BackgroundColor = DEFAULT_BACKGROUND_COLOR;
BitmapCol Launcher_ButtonBorderCol = DEFAULT_BUTTON_BORDER_COL; BitmapCol Launcher_ButtonBorderColor = DEFAULT_BUTTON_BORDER_COLOR;
BitmapCol Launcher_ButtonForeActiveCol = DEFAULT_BUTTON_FORE_ACTIVE_COL; BitmapCol Launcher_ButtonForeActiveColor = DEFAULT_BUTTON_FORE_ACTIVE_COLOR;
BitmapCol Launcher_ButtonForeCol = DEFAULT_BUTTON_FORE_COL; BitmapCol Launcher_ButtonForeColor = DEFAULT_BUTTON_FORE_COLOR;
BitmapCol Launcher_ButtonHighlightCol = DEFAULT_BUTTON_HIGHLIGHT_COL; BitmapCol Launcher_ButtonHighlightColor = DEFAULT_BUTTON_HIGHLIGHT_COLOR;
void Launcher_ResetSkin(void) { void Launcher_ResetSkin(void) {
Launcher_BackgroundCol = DEFAULT_BACKGROUND_COL; Launcher_BackgroundColor = DEFAULT_BACKGROUND_COLOR;
Launcher_ButtonBorderCol = DEFAULT_BUTTON_BORDER_COL; Launcher_ButtonBorderColor = DEFAULT_BUTTON_BORDER_COLOR;
Launcher_ButtonForeActiveCol = DEFAULT_BUTTON_FORE_ACTIVE_COL; Launcher_ButtonForeActiveColor = DEFAULT_BUTTON_FORE_ACTIVE_COLOR;
Launcher_ButtonForeCol = DEFAULT_BUTTON_FORE_COL; Launcher_ButtonForeColor = DEFAULT_BUTTON_FORE_COLOR;
Launcher_ButtonHighlightCol = DEFAULT_BUTTON_HIGHLIGHT_COL; Launcher_ButtonHighlightColor = DEFAULT_BUTTON_HIGHLIGHT_COLOR;
} }
CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) { CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) {
@ -385,11 +385,11 @@ CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) {
} }
void Launcher_LoadSkin(void) { void Launcher_LoadSkin(void) {
Launcher_GetCol("launcher-back-col", &Launcher_BackgroundCol); Launcher_GetCol("launcher-back-col", &Launcher_BackgroundColor);
Launcher_GetCol("launcher-btn-border-col", &Launcher_ButtonBorderCol); Launcher_GetCol("launcher-btn-border-col", &Launcher_ButtonBorderColor);
Launcher_GetCol("launcher-btn-fore-active-col", &Launcher_ButtonForeActiveCol); Launcher_GetCol("launcher-btn-fore-active-col", &Launcher_ButtonForeActiveColor);
Launcher_GetCol("launcher-btn-fore-inactive-col", &Launcher_ButtonForeCol); Launcher_GetCol("launcher-btn-fore-inactive-col", &Launcher_ButtonForeColor);
Launcher_GetCol("launcher-btn-highlight-inactive-col", &Launcher_ButtonHighlightCol); Launcher_GetCol("launcher-btn-highlight-inactive-col", &Launcher_ButtonHighlightColor);
} }
CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) { CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) {
@ -403,11 +403,11 @@ CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) {
} }
void Launcher_SaveSkin(void) { void Launcher_SaveSkin(void) {
Launcher_SetCol("launcher-back-col", Launcher_BackgroundCol); Launcher_SetCol("launcher-back-col", Launcher_BackgroundColor);
Launcher_SetCol("launcher-btn-border-col", Launcher_ButtonBorderCol); Launcher_SetCol("launcher-btn-border-col", Launcher_ButtonBorderColor);
Launcher_SetCol("launcher-btn-fore-active-col", Launcher_ButtonForeActiveCol); Launcher_SetCol("launcher-btn-fore-active-col", Launcher_ButtonForeActiveColor);
Launcher_SetCol("launcher-btn-fore-inactive-col", Launcher_ButtonForeCol); Launcher_SetCol("launcher-btn-fore-inactive-col", Launcher_ButtonForeColor);
Launcher_SetCol("launcher-btn-highlight-inactive-col", Launcher_ButtonHighlightCol); Launcher_SetCol("launcher-btn-highlight-inactive-col", Launcher_ButtonHighlightColor);
} }

View File

@ -26,15 +26,15 @@ extern cc_string Launcher_AutoHash;
extern cc_string Launcher_Username; extern cc_string Launcher_Username;
/* Base colour of pixels before any widgets are drawn. */ /* Base colour of pixels before any widgets are drawn. */
extern BitmapCol Launcher_BackgroundCol; extern BitmapCol Launcher_BackgroundColor;
/* Colour of pixels on the 4 line borders around buttons. */ /* Colour of pixels on the 4 line borders around buttons. */
extern BitmapCol Launcher_ButtonBorderCol; extern BitmapCol Launcher_ButtonBorderColor;
/* Colour of button when user has mouse over it. */ /* Colour of button when user has mouse over it. */
extern BitmapCol Launcher_ButtonForeActiveCol; extern BitmapCol Launcher_ButtonForeActiveColor;
/* Colour of button when user does not have mouse over it. */ /* Colour of button when user does not have mouse over it. */
extern BitmapCol Launcher_ButtonForeCol; extern BitmapCol Launcher_ButtonForeColor;
/* Colour of line at top of buttons to give them a less flat look.*/ /* Colour of line at top of buttons to give them a less flat look.*/
extern BitmapCol Launcher_ButtonHighlightCol; extern BitmapCol Launcher_ButtonHighlightColor;
/* Resets colours to default. */ /* Resets colours to default. */
void Launcher_ResetSkin(void); void Launcher_ResetSkin(void);

View File

@ -2141,6 +2141,60 @@ CC_OBJC_VISIBLE int MapNativeKey(UInt32 key) { return key < Array_Elems(key_map)
/*Return = 52, (0x34, ??? according to that link)*/ /*Return = 52, (0x34, ??? according to that link)*/
/*Menu = 110, (0x6E, ??? according to that link)*/ /*Menu = 110, (0x6E, ??? according to that link)*/
void Cursor_SetPosition(int x, int y) {
CGPoint point;
point.x = x + windowX;
point.y = y + windowY;
CGDisplayMoveCursorToPoint(CGMainDisplayID(), point);
}
static void Cursor_DoSetVisible(cc_bool visible) {
if (visible) {
CGDisplayShowCursor(CGMainDisplayID());
} else {
CGDisplayHideCursor(CGMainDisplayID());
}
}
void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { }
void Window_SetKeyboardText(const cc_string* text) { }
void Window_CloseKeyboard(void) { }
void Window_EnableRawMouse(void) {
DefaultEnableRawMouse();
CGAssociateMouseAndMouseCursorPosition(0);
}
void Window_UpdateRawMouse(void) { CentreMousePosition(); }
void Window_DisableRawMouse(void) {
CGAssociateMouseAndMouseCursorPosition(1);
DefaultDisableRawMouse();
}
/*########################################################################################################################*
*------------------------------------------------------Carbon window------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_CARBON
#include <Carbon/Carbon.h>
static WindowRef win_handle;
static cc_bool win_fullscreen, showingDialog;
/* fullscreen is tied to OpenGL context unfortunately */
static cc_result GLContext_UnsetFullscreen(void);
static cc_result GLContext_SetFullscreen(void);
static void RefreshWindowBounds(void) {
Rect r;
if (win_fullscreen) return;
/* TODO: kWindowContentRgn ??? */
GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r);
windowX = r.left; WindowInfo.Width = r.right - r.left;
windowY = r.top; WindowInfo.Height = r.bottom - r.top;
}
/* NOTE: All Pasteboard functions are OSX 10.3 or later */ /* NOTE: All Pasteboard functions are OSX 10.3 or later */
static PasteboardRef Window_GetPasteboard(void) { static PasteboardRef Window_GetPasteboard(void) {
PasteboardRef pbRef; PasteboardRef pbRef;
@ -2202,60 +2256,6 @@ void Clipboard_SetText(const cc_string* value) {
PasteboardPutItemFlavor(pbRef, 1, FMT_UTF8, cfData, 0); PasteboardPutItemFlavor(pbRef, 1, FMT_UTF8, cfData, 0);
} }
void Cursor_SetPosition(int x, int y) {
CGPoint point;
point.x = x + windowX;
point.y = y + windowY;
CGDisplayMoveCursorToPoint(CGMainDisplayID(), point);
}
static void Cursor_DoSetVisible(cc_bool visible) {
if (visible) {
CGDisplayShowCursor(CGMainDisplayID());
} else {
CGDisplayHideCursor(CGMainDisplayID());
}
}
void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { }
void Window_SetKeyboardText(const cc_string* text) { }
void Window_CloseKeyboard(void) { }
void Window_EnableRawMouse(void) {
DefaultEnableRawMouse();
CGAssociateMouseAndMouseCursorPosition(0);
}
void Window_UpdateRawMouse(void) { CentreMousePosition(); }
void Window_DisableRawMouse(void) {
CGAssociateMouseAndMouseCursorPosition(1);
DefaultDisableRawMouse();
}
/*########################################################################################################################*
*------------------------------------------------------Carbon window------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_CARBON
#include <Carbon/Carbon.h>
static WindowRef win_handle;
static cc_bool win_fullscreen, showingDialog;
/* fullscreen is tied to OpenGL context unfortunately */
static cc_result GLContext_UnsetFullscreen(void);
static cc_result GLContext_SetFullscreen(void);
static void RefreshWindowBounds(void) {
Rect r;
if (win_fullscreen) return;
/* TODO: kWindowContentRgn ??? */
GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r);
windowX = r.left; WindowInfo.Width = r.right - r.left;
windowY = r.top; WindowInfo.Height = r.bottom - r.top;
}
static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) { static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) {
UInt32 kind, code; UInt32 kind, code;
int key; int key;

View File

@ -44,6 +44,35 @@ static void RefreshWindowBounds(void) {
WindowInfo.Height = (int)view.size.height; WindowInfo.Height = (int)view.size.height;
} }
void Clipboard_GetText(cc_string* value) {
NSPasteboard* pasteboard;
const char* src;
NSString* str;
int len;
pasteboard = [NSPasteboard generalPasteboard];
str = [pasteboard stringForType:NSStringPboardType];
if (!str) return;
src = [str UTF8String];
len = String_Length(src);
String_AppendUtf8(value, src, len);
}
void Clipboard_SetText(const cc_string* value) {
NSPasteboard* pasteboard;
char raw[NATIVE_STR_LEN];
NSString* str;
Platform_EncodeUtf8(raw, value);
str = [[NSString alloc] initWithUTF8String:raw];
pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteboard setString:str forType:NSStringPboardType];
}
@interface CCWindow : NSWindow { } @interface CCWindow : NSWindow { }
@end @end
@implementation CCWindow @implementation CCWindow
@ -182,11 +211,11 @@ void Window_Create(int width, int height) {
} }
void Window_SetTitle(const cc_string* title) { void Window_SetTitle(const cc_string* title) {
char buffer[NATIVE_STR_LEN]; char raw[NATIVE_STR_LEN];
NSString* str; NSString* str;
Platform_EncodeUtf8(buffer, title); Platform_EncodeUtf8(raw, title);
str = [[NSString alloc] initWithUTF8String:buffer]; str = [[NSString alloc] initWithUTF8String:raw];
[winHandle setTitle:str]; [winHandle setTitle:str];
[str release]; [str release];
} }

View File

@ -7,7 +7,7 @@
void Clipboard_GetText(cc_string* value) { void Clipboard_GetText(cc_string* value) {
const char* raw; const char* raw;
NSString* str; NSString* str;
int len; int len;
str = [UIPasteboard generalPasteboard].string; str = [UIPasteboard generalPasteboard].string;
if (!str) return; if (!str) return;