1 #import <objc/runtime.h>
3 #import "alertdelegate.h"
4 #import "displaywindow.h"
6 #import "bitmapclass.h"
8 static UIScreen *getScreen(unsigned int scrNo)
10 void *ios32 = class_getClassMethod([UIScreen class], @selector(screens));
14 NSArray *screens = [UIScreen screens];
16 if (scrNo < [screens count])
17 return [screens objectAtIndex:scrNo];
24 return [UIScreen mainScreen];
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
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.
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
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;
61 if (UIInterfaceOrientationIsLandscape(o))
63 data->orientation = O_LANDSCAPE;
64 data->screenbar = screenbar.size.width;
68 data->orientation = O_PORTRAIT;
69 data->screenbar = screenbar.size.height;
73 DisplayWindow *OpenDisplay(unsigned int scrNo)
75 UIScreen *screen = getScreen(scrNo);
81 win = [[DisplayWindow alloc] initWithFrame:screen.bounds];
82 [win makeKeyAndVisible];
87 void CloseDisplay(DisplayWindow *win)
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];
100 void DisposeBitMap(UIView *bitmap)
102 [bitmap removeFromSuperview];
106 void DisplayAlert(const char *text)
108 AlertDelegate *ad = [[AlertDelegate alloc] init];
109 NSString *alert = [NSString stringWithCString:text encoding:NSISOLatin1StringEncoding];
111 [ad DisplayAlert:alert];
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);