rename the directory
[AROS.git] / arch / all-ios / hidd / uikit / native_api.m
blob06d35ac40a1806ed61ad742e951121ad5060b38f
1 #import <objc/runtime.h>
3 #import "alertdelegate.h"
4 #import "displaywindow.h"
5 #import "native_api.h"
6 #import "bitmapclass.h"
8 static UIScreen *getScreen(unsigned int scrNo)
10     void *ios32 = class_getClassMethod([UIScreen class], @selector(screens));
12     if (ios32)
13     {
14         NSArray *screens = [UIScreen screens];
15         
16         if (scrNo < [screens count])
17             return [screens objectAtIndex:scrNo];
18         else
19             return nil;
20     }
21     else
22     {
23         if (scrNo == 0)
24             return [UIScreen mainScreen];
25         else
26             return nil;
27     }
31  * This function is used to get logical metrics of the screen. It returns total screen
32  * size and status bar size in *POINTS*.
33  * The mechanics behind: physical iOS screen always has (0, 0) in the same place. It's
34  * not changed by rotation. Rotation is handled by UIViewController on view level by
35  * applying rotation transformation to the underlying view.
36  * Now, bu default, when the application has just started, we have some screen size
37  * and we want to know what space will be occupied by screen bar in both variants
38  * (portrait and landscape). The OS provides us with statusBarFrame for this
39  * purpose. Actually, status bar also doesn't rotate. It's just drawn rotated by 90
40  * degrees when needed. Its frame is always represented in screen's coordinates.
41  * By default status bar is placed on the top, occupying the whole screen width, and
42  * having some height. In rotated position, it occupies the *whole height*, but only
43  * *some* width.
44  * In this code we detect screenbar position, just in case, to make sure we provide
45  * the correct coordinate. The only assumption here is that other size member will
46  * have full-screen size. This seems to be always true.
47  *
48  * This function returns sizes in points, not in pixels. In order to move from points
49  * to pixels, we'll have to scale screenbar size according to pixels:points relation
50  * for every mode.
51  */
52 void GetMetrics(struct DisplayMetrics *data)
54     UIScreen *screen = [UIScreen mainScreen];
55     CGRect screenbar = [UIApplication sharedApplication].statusBarFrame;
56     UIInterfaceOrientation o = [UIApplication sharedApplication].statusBarOrientation;
58     data->width       = screen.bounds.size.width;
59     data->height      = screen.bounds.size.height;
60     
61     if (UIInterfaceOrientationIsLandscape(o))
62     {
63         data->orientation = O_LANDSCAPE;
64         data->screenbar   = screenbar.size.width;
65     }
66     else
67     {
68         data->orientation = O_PORTRAIT;
69         data->screenbar   = screenbar.size.height;
70     }
73 DisplayWindow *OpenDisplay(unsigned int scrNo)
75     UIScreen *screen = getScreen(scrNo);
76     DisplayWindow *win;
78     if (!screen)
79         return nil;
81     win = [[DisplayWindow alloc] initWithFrame:screen.bounds];
82     [win makeKeyAndVisible];
84     return win;
87 void CloseDisplay(DisplayWindow *win)
89     [win release];
92 UIView *NewBitMap(DisplayWindow *win, unsigned int w, unsigned int h)
94     UIView *bmView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, h)];
96     [win addSubview:bmView];
97     return bmView;
100 void DisposeBitMap(UIView *bitmap)
102     [bitmap removeFromSuperview];
103     [bitmap release];
106 void DisplayAlert(const char *text)
108     AlertDelegate *ad = [[AlertDelegate alloc] init];
109     NSString *alert = [NSString stringWithCString:text encoding:NSISOLatin1StringEncoding];
111     [ad DisplayAlert:alert];
112     [ad release];
115 void NewContext(struct bitmap_data *bitmap)
117     CGColorSpaceRef colspace = CGColorSpaceCreateDeviceRGB();
119     bitmap->context = CGBitmapContextCreate(bitmap->pixels, bitmap->width, bitmap->height, 8, bitmap->mod, colspace, kCGImageAlphaNoneSkipFirst);
120     CGColorSpaceRelease(colspace);
123 void DisposeContext(CGContextRef ctx)
125     CGContextRelease(ctx);
128 void PollEvents(unsigned int dummy)
130     CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);