FreeRDP
Loading...
Searching...
No Matches
RDPCursor.m
1//
2// RDPCursor.m
3// iFreeRDP
4//
5// Created by byungho on 6/19/26.
6//
7
8#import "RDPCursor.h"
9
10#include <winpr/wtypes.h>
11
12@implementation RDPCursor
13
14@synthesize image = _image;
15@synthesize hotspot = _hotspot;
16
17- (id)initWithRGBABytes:(const void *)bytes
18 width:(NSUInteger)width
19 height:(NSUInteger)height
20 hotspot:(CGPoint)hotspot
21{
22 self = [super init];
23 if (!self)
24 return nil;
25
26 if (!bytes || (width == 0) || (height == 0))
27 {
28 [self release];
29 return nil;
30 }
31
32 NSData *pixelData = [NSData dataWithBytes:bytes length:width * height * 4];
33 CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)pixelData);
34 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
35 CGImageRef imageRef = CGImageCreate(width, height, 8, 32, width * 4, colorSpace,
36 kCGBitmapByteOrderDefault | kCGImageAlphaLast, provider,
37 nullptr, NO, kCGRenderingIntentDefault);
38
39 CGColorSpaceRelease(colorSpace);
40 CGDataProviderRelease(provider);
41
42 if (!imageRef)
43 {
44 [self release];
45 return nil;
46 }
47
48 _image = [[UIImage imageWithCGImage:imageRef scale:1.0
49 orientation:UIImageOrientationUp] retain];
50 _hotspot = hotspot;
51 CGImageRelease(imageRef);
52 return self;
53}
54
55// default white cursor
56+ (RDPCursor *)defaultCursor
57{
58 const CGSize size = CGSizeMake(24.0, 32.0);
59 UIGraphicsBeginImageContextWithOptions(size, NO, 1.0);
60
61 UIBezierPath *path = [UIBezierPath bezierPath];
62 [path moveToPoint:CGPointMake(2.0, 1.0)];
63 [path addLineToPoint:CGPointMake(2.0, 25.0)];
64 [path addLineToPoint:CGPointMake(8.5, 19.0)];
65 [path addLineToPoint:CGPointMake(13.0, 30.0)];
66 [path addLineToPoint:CGPointMake(18.0, 28.0)];
67 [path addLineToPoint:CGPointMake(13.5, 17.0)];
68 [path addLineToPoint:CGPointMake(22.0, 17.0)];
69 [path closePath];
70 [[UIColor whiteColor] setFill];
71 [[UIColor blackColor] setStroke];
72 [path setLineWidth:2.0];
73 [path fill];
74 [path stroke];
75
76 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
77 UIGraphicsEndImageContext();
78
79 RDPCursor *cursor = [[[RDPCursor alloc] init] autorelease];
80 [cursor setImage:image];
81 [cursor setHotspot:CGPointMake(2.0, 1.0)];
82 return cursor;
83}
84
85- (void)dealloc
86{
87 [_image release];
88 [super dealloc];
89}
90
91@end