mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrlCore: MacOS dark mode switches suppport
This commit is contained in:
parent
f9f8306cb3
commit
daa764dab7
6 changed files with 100 additions and 127 deletions
|
|
@ -18,6 +18,31 @@ NSMenu *Cocoa_DockMenu();
|
|||
{
|
||||
return Upp::Cocoa_DockMenu();
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(themeChanged:)
|
||||
name:@"AppleColorPreferencesChangedNotification"
|
||||
object:nil];
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(themeChanged:)
|
||||
name: @"AppleInterfaceThemeChangedNotification"
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
||||
{
|
||||
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)themeChanged:(NSNotification *)aNotification
|
||||
{
|
||||
Upp::Ctrl::PostReSkin();
|
||||
DLOG("RESKIN");
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
namespace Upp {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ namespace Upp {
|
|||
|
||||
extern id menubar;
|
||||
|
||||
|
||||
bool GetShift() { return coco_flags & NSEventModifierFlagShift; }
|
||||
bool GetCtrl() { return coco_flags & NSEventModifierFlagCommand; }
|
||||
bool GetAlt() { return coco_flags & NSEventModifierFlagControl; }
|
||||
|
|
|
|||
|
|
@ -15,83 +15,87 @@
|
|||
|
||||
void Coco_PaintCh(void *cgcontext, int type, int value, int state)
|
||||
{
|
||||
auto cg = (CGContextRef) cgcontext ;
|
||||
if(Upp::IsUHDMode())
|
||||
CGContextScaleCTM(cg, 2, 2);
|
||||
CGRect cr = CGRectMake(0, 0, 140, 140);
|
||||
if(type == COCO_NSCOLOR) {
|
||||
CGContextSaveGState(cg);
|
||||
CGContextSetFillColorWithColor(cg, Upp::decode(value,
|
||||
COCO_PAPER, [NSColor textBackgroundColor].CGColor,
|
||||
COCO_SELECTEDTEXT, [NSColor selectedTextColor].CGColor,
|
||||
COCO_SELECTEDPAPER, [NSColor selectedTextBackgroundColor].CGColor,
|
||||
COCO_DISABLED, [NSColor disabledControlTextColor].CGColor,
|
||||
COCO_WINDOW, [NSColor windowBackgroundColor].CGColor,
|
||||
COCO_SELECTEDMENUTEXT, [NSColor selectedMenuItemTextColor].CGColor,
|
||||
[NSColor textColor].CGColor
|
||||
));
|
||||
CGContextFillRect(cg, cr);
|
||||
CGContextRestoreGState(cg);
|
||||
}
|
||||
else
|
||||
if(type == COCO_NSIMAGE) {
|
||||
NSImage *img = [NSImage imageNamed:(value ? NSImageNameInfo : NSImageNameCaution)];
|
||||
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:cg flipped:YES];
|
||||
NSGraphicsContext* cgc = [NSGraphicsContext currentContext];
|
||||
[NSGraphicsContext setCurrentContext:gc];
|
||||
[img drawInRect:NSMakeRect(0, 0, 48, 48)];
|
||||
[NSGraphicsContext setCurrentContext:cgc];
|
||||
}
|
||||
else {
|
||||
CGContextSaveGState(cg);
|
||||
[NSGraphicsContext saveGraphicsState];
|
||||
[NSGraphicsContext setCurrentContext:
|
||||
[NSGraphicsContext graphicsContextWithCGContext:cg flipped:YES]];
|
||||
|
||||
const CGRect dirtyRect = CGRectMake(20, 20, 100, 100);
|
||||
|
||||
if(Upp::findarg(type, COCO_SCROLLTHUMB, COCO_SCROLLTRACK) >= 0) {
|
||||
int cx = [NSScroller scrollerWidthForControlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleLegacy];
|
||||
NSScroller *scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 100, cx)];
|
||||
scroller.floatValue = 0;
|
||||
scroller.knobProportion = 1;
|
||||
scroller.knobStyle = NSScrollerKnobStyleDefault;
|
||||
scroller.scrollerStyle = NSScrollerStyleLegacy;
|
||||
scroller.frame = cr;
|
||||
if(type == COCO_SCROLLTHUMB)
|
||||
[scroller drawKnob];
|
||||
else
|
||||
[scroller drawKnobSlotInRect:CGRectMake(20, 20, 100, cx) highlight:YES];
|
||||
[scroller release];
|
||||
void (^dopaint)(void) = ^{
|
||||
auto cg = (CGContextRef) cgcontext;
|
||||
if(Upp::IsUHDMode())
|
||||
CGContextScaleCTM(cg, 2, 2);
|
||||
CGRect cr = CGRectMake(0, 0, 140, 140);
|
||||
if(type == COCO_NSCOLOR) {
|
||||
CGContextSaveGState(cg);
|
||||
CGContextSetFillColorWithColor(cg, Upp::decode(value,
|
||||
COCO_PAPER, [NSColor textBackgroundColor].CGColor,
|
||||
COCO_SELECTEDTEXT, [NSColor selectedTextColor].CGColor,
|
||||
COCO_SELECTEDPAPER, [NSColor selectedTextBackgroundColor].CGColor,
|
||||
COCO_DISABLED, [NSColor disabledControlTextColor].CGColor,
|
||||
COCO_WINDOW, [NSColor windowBackgroundColor].CGColor,
|
||||
COCO_SELECTEDMENUTEXT, [NSColor selectedMenuItemTextColor].CGColor,
|
||||
[NSColor textColor].CGColor
|
||||
));
|
||||
CGContextFillRect(cg, cr);
|
||||
CGContextRestoreGState(cg);
|
||||
}
|
||||
else
|
||||
if(type == COCO_TEXTFIELD) {
|
||||
NSTextField *tf = [[NSTextField alloc] init];
|
||||
tf.enabled = YES;
|
||||
tf.editable = YES;
|
||||
tf.bezeled = YES;
|
||||
tf.frame = CGRectMake(0, 0, 140, 40);
|
||||
[tf drawRect:dirtyRect];
|
||||
[tf release];
|
||||
if(type == COCO_NSIMAGE) {
|
||||
NSImage *img = [NSImage imageNamed:(value ? NSImageNameInfo : NSImageNameCaution)];
|
||||
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:cg flipped:YES];
|
||||
NSGraphicsContext* cgc = [NSGraphicsContext currentContext];
|
||||
[NSGraphicsContext setCurrentContext:gc];
|
||||
[img drawInRect:NSMakeRect(0, 0, 48, 48)];
|
||||
[NSGraphicsContext setCurrentContext:cgc];
|
||||
}
|
||||
else {
|
||||
NSButton *bc = type == COCO_POPUPBUTTON ? [[NSPopUpButton alloc] init] : [[NSButton alloc] init];
|
||||
bc.allowsMixedState = type == COCO_CHECKBOX;
|
||||
bc.title = @"";
|
||||
bc.controlSize = type == COCO_RADIOBUTTON ? NSControlSizeSmall : NSControlSizeRegular;
|
||||
bc.frame = cr;
|
||||
bc.buttonType = Upp::decode(type, COCO_CHECKBOX, NSButtonTypeSwitch, COCO_RADIOBUTTON, NSButtonTypeRadio, NSButtonTypePushOnPushOff);
|
||||
bc.bezelStyle = type == COCO_BUTTON ? NSBezelStyleRounded : NSBezelStyleRegularSquare;
|
||||
bc.state = Upp::decode(value, 0, NSControlStateValueOff, 1, NSControlStateValueOn, NSControlStateValueMixed);
|
||||
[bc highlight: state == Upp::CTRL_PRESSED];
|
||||
bc.enabled = state != Upp::CTRL_DISABLED;
|
||||
[bc drawRect:dirtyRect];
|
||||
[bc release];
|
||||
CGContextSaveGState(cg);
|
||||
[NSGraphicsContext saveGraphicsState];
|
||||
[NSGraphicsContext setCurrentContext:
|
||||
[NSGraphicsContext graphicsContextWithCGContext:cg flipped:YES]];
|
||||
|
||||
const CGRect dirtyRect = CGRectMake(20, 20, 100, 100);
|
||||
|
||||
if(Upp::findarg(type, COCO_SCROLLTHUMB, COCO_SCROLLTRACK) >= 0) {
|
||||
int cx = [NSScroller scrollerWidthForControlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleLegacy];
|
||||
NSScroller *scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 100, cx)];
|
||||
scroller.floatValue = 0;
|
||||
scroller.knobProportion = 1;
|
||||
scroller.knobStyle = NSScrollerKnobStyleDefault;
|
||||
scroller.scrollerStyle = NSScrollerStyleLegacy;
|
||||
scroller.frame = cr;
|
||||
if(type == COCO_SCROLLTHUMB)
|
||||
[scroller drawKnob];
|
||||
else
|
||||
[scroller drawKnobSlotInRect:CGRectMake(20, 20, 100, cx) highlight:YES];
|
||||
[scroller release];
|
||||
}
|
||||
else
|
||||
if(type == COCO_TEXTFIELD) {
|
||||
NSTextField *tf = [[NSTextField alloc] init];
|
||||
tf.enabled = YES;
|
||||
tf.editable = YES;
|
||||
tf.bezeled = YES;
|
||||
tf.frame = CGRectMake(0, 0, 140, 40);
|
||||
[tf drawRect:dirtyRect];
|
||||
[tf release];
|
||||
}
|
||||
else {
|
||||
NSButton *bc = type == COCO_POPUPBUTTON ? [[NSPopUpButton alloc] init] : [[NSButton alloc] init];
|
||||
bc.allowsMixedState = type == COCO_CHECKBOX;
|
||||
bc.title = @"";
|
||||
bc.controlSize = type == COCO_RADIOBUTTON ? NSControlSizeSmall : NSControlSizeRegular;
|
||||
bc.frame = cr;
|
||||
bc.buttonType = Upp::decode(type, COCO_CHECKBOX, NSButtonTypeSwitch, COCO_RADIOBUTTON, NSButtonTypeRadio, NSButtonTypePushOnPushOff);
|
||||
bc.bezelStyle = type == COCO_BUTTON ? NSBezelStyleRounded : NSBezelStyleRegularSquare;
|
||||
bc.state = Upp::decode(value, 0, NSControlStateValueOff, 1, NSControlStateValueOn, NSControlStateValueMixed);
|
||||
[bc highlight: state == Upp::CTRL_PRESSED];
|
||||
bc.enabled = state != Upp::CTRL_DISABLED;
|
||||
[bc drawRect:dirtyRect];
|
||||
[bc release];
|
||||
}
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
CGContextRestoreGState(cg);
|
||||
}
|
||||
};
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
CGContextRestoreGState(cg);
|
||||
}
|
||||
[NSApp.effectiveAppearance performAsCurrentDrawingAppearance:dopaint];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -120,7 +120,6 @@ file
|
|||
ChGtk3.cpp,
|
||||
ChCocoMM.h,
|
||||
ChCocoMM.mm,
|
||||
ChCoco.h,
|
||||
ChCoco.cpp,
|
||||
Meta readonly separator,
|
||||
Normal.upt,
|
||||
|
|
|
|||
|
|
@ -186,18 +186,6 @@ static void PaintArrow(Draw& draw, const Rect& rc, int pos)
|
|||
PaintArrowRaw(draw, rc, rc.bottom - pos * rc.Height() / 255);
|
||||
}
|
||||
|
||||
static const int std_palette[] =
|
||||
{
|
||||
0x000000, 0x808080,
|
||||
0xC0C0C0, 0xFFFFFF,
|
||||
0x000080, 0x0000FF,
|
||||
0x008000, 0x00FF00,
|
||||
0x008080, 0x00FFFF,
|
||||
0x800000, 0xFF0000,
|
||||
0x800080, 0xFF00FF,
|
||||
0x808000, 0xFFFF00,
|
||||
};
|
||||
|
||||
WheelRampCtrl::WheelRampCtrl(bool r)
|
||||
: ramp(r)
|
||||
{
|
||||
|
|
@ -807,24 +795,4 @@ private:
|
|||
String recent_file;
|
||||
};
|
||||
|
||||
static void InitColor(Color *out)
|
||||
{
|
||||
out[ 0] = Color(0x00, 0x00, 0x00);
|
||||
out[ 1] = Color(0x80, 0x80, 0x80);
|
||||
out[ 2] = Color(0xC0, 0xC0, 0xC0);
|
||||
out[ 3] = Color(0xFF, 0xFF, 0xFF);
|
||||
out[ 4] = Color(0x80, 0x00, 0x00);
|
||||
out[ 5] = Color(0xFF, 0x00, 0x00);
|
||||
out[ 6] = Color(0x00, 0x80, 0x00);
|
||||
out[ 7] = Color(0x00, 0xFF, 0x00);
|
||||
out[ 8] = Color(0x80, 0x80, 0x00);
|
||||
out[ 9] = Color(0xFF, 0xFF, 0x00);
|
||||
out[10] = Color(0x00, 0x00, 0x80);
|
||||
out[11] = Color(0x00, 0x00, 0xFF);
|
||||
out[12] = Color(0x80, 0x00, 0x80);
|
||||
out[13] = Color(0xFF, 0x00, 0xFF);
|
||||
out[14] = Color(0x00, 0x80, 0x80);
|
||||
out[15] = Color(0x00, 0xFF, 0xFF);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,28 +269,6 @@ bool LoadIml(const String& data, Array<ImlImage>& img, int& format)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void PutOctalString(Stream& out, const char *b, const char *e, const String& eol, bool split = false)
|
||||
{
|
||||
out.Put('\"');
|
||||
int64 start = out.GetPos();
|
||||
while(b < e) {
|
||||
if(split && out.GetPos() >= start + 200u) {
|
||||
out << "\"" << eol << "\t\"";
|
||||
start = out.GetPos();
|
||||
}
|
||||
if((byte)*b >= ' ' && *b != '\x7F' && *b != '\xFF') {
|
||||
if(*b == '\\' || *b == '\"' || *b == '\'')
|
||||
out.Put('\\');
|
||||
out.Put(*b++);
|
||||
}
|
||||
else if(IsDigit(b[1]))
|
||||
out.Put(Sprintf("\\%03o", (byte)*b++));
|
||||
else
|
||||
out.Put(Sprintf("\\%o", (byte)*b++));
|
||||
}
|
||||
out.Put('\"');
|
||||
}
|
||||
|
||||
String SaveIml(const Array<ImlImage>& iml, int format, const String& eol) {
|
||||
StringStream out;
|
||||
out << "PREMULTIPLIED" << eol;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue