FreeRDP
Loading...
Searching...
No Matches
RDPOverlayStyle.m
1/*
2 Shared look of the session overlays (key bar, extended keyboard, toolbar)
3
4 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
5 If a copy of the MPL was not distributed with this file, You can obtain one at
6 http://mozilla.org/MPL/2.0/.
7 */
8
9#import "RDPOverlayStyle.h"
10#import "Utils.h"
11
12void RDPApplyKeyCapColors(UIButtonConfiguration *config, BOOL latched, BOOL pressed);
13
14BOOL RDPSupportLiquidGlass(void);
15
16UIVisualEffectView *RDPCreateGlassCapsuleView(void)
17{
18 UIVisualEffect *effect;
19#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 260000
20 if (@available(iOS 26.0, *))
21 {
22 effect = [UIGlassEffect effectWithStyle:UIGlassEffectStyleRegular];
23 }
24 else
25#endif
26 {
27 effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
28 }
29
30 UIVisualEffectView *view = [[[UIVisualEffectView alloc] initWithEffect:effect] autorelease];
31#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 260000
32 if (@available(iOS 26.0, *))
33 {
34 [view setCornerConfiguration:[UICornerConfiguration capsuleConfiguration]];
35 }
36 else
37#endif
38 {
39 [view setClipsToBounds:YES];
40 [[view layer] setCornerCurve:kCACornerCurveContinuous];
41 }
42 return view;
43}
44
45void RDPUpdateGlassCapsuleCorners(UIVisualEffectView *view)
46{
47 if (RDPSupportLiquidGlass() == YES)
48 {
49 return;
50 }
51
52 CGSize size = [view bounds].size;
53 [[view layer] setCornerRadius:MIN(size.width, size.height) * 0.5];
54}
55
56UIImage *RDPWindowsLogoImage(CGFloat size)
57{
58 UIGraphicsImageRenderer *renderer =
59 [[[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(size, size)] autorelease];
60
61 // draw 4 square like windows logo
62 UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
63 const CGFloat gap = MAX(1.0, round(size * 0.08));
64 const CGFloat tile = (size - gap) * 0.5;
65 [[UIColor blackColor] setFill];
66 UIRectFill(CGRectMake(0, 0, tile, tile));
67 UIRectFill(CGRectMake(tile + gap, 0, tile, tile));
68 UIRectFill(CGRectMake(0, tile + gap, tile, tile));
69 UIRectFill(CGRectMake(tile + gap, tile + gap, tile, tile));
70 }];
71 return [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
72}
73
74UIButton *RDPCreateKeyButton(NSString *title, UIImage *image)
75{
76 UIButtonConfiguration *config = [UIButtonConfiguration grayButtonConfiguration];
77 [config setCornerStyle:UIButtonConfigurationCornerStyleMedium];
78 [config setContentInsets:NSDirectionalEdgeInsetsMake(4.0, 4.0, 4.0, 4.0)];
79
80 if (title != nil)
81 {
82 [config setTitle:title];
83 [config setTitleLineBreakMode:NSLineBreakByClipping];
84 }
85 else if (image != nil)
86 {
87 [config setImage:image];
88 }
89 else
90 {
91 return nil;
92 }
93
94 RDPApplyKeyCapColors(config, NO, NO);
95
96 UIButton *btn = [UIButton buttonWithConfiguration:config primaryAction:nil];
97 [btn setExclusiveTouch:YES];
98 [btn setConfigurationUpdateHandler:^(UIButton *button) {
99 UIButtonConfiguration *updated = [[[button configuration] copy] autorelease];
100 RDPApplyKeyCapColors(updated, [button isSelected], [button isHighlighted]);
101 [button setConfiguration:updated];
102 }];
103 return btn;
104}
105
106UIButton *RDPCreateTabButton(NSString *title)
107{
108 UIButton *btn = RDPCreateKeyButton(title, nil);
109 if (btn == nil)
110 return nil;
111
112 // set style
113 UIButtonConfiguration *config = [[[btn configuration] copy] autorelease];
114 [config setCornerStyle:UIButtonConfigurationCornerStyleCapsule];
115
116 [btn setConfiguration:config];
117 return btn;
118}
119
120void RDPApplyKeyCapColors(UIButtonConfiguration *config, BOOL latched, BOOL pressed)
121{
122 UIColor *background;
123 if (latched)
124 background = pressed ? [UIColor secondaryLabelColor] : [UIColor labelColor];
125 else
126 background = [UIColor colorWithDynamicProvider:^UIColor *(UITraitCollection *traits) {
127 if ([traits userInterfaceStyle] == UIUserInterfaceStyleDark)
128 return pressed ? [UIColor systemGray2Color] : [UIColor systemGray3Color];
129 return pressed ? [UIColor systemGray4Color] : [UIColor whiteColor];
130 }];
131
132 [[config background] setBackgroundColor:background];
133 [config
134 setBaseForegroundColor:latched ? [UIColor systemBackgroundColor] : [UIColor labelColor]];
135}
136
137BOOL RDPSupportLiquidGlass(void)
138{
139#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 260000
140 if (@available(iOS 26.0, *))
141 return YES;
142#endif
143 return NO;
144}