2011-07-17 14:42:08 +00:00
|
|
|
#import "SkUIView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCGUtils.h"
|
|
|
|
@implementation SkUIView
|
|
|
|
|
2011-08-30 19:14:13 +00:00
|
|
|
@synthesize fWind, fTitleItem, fOptionsDelegate;
|
2011-08-08 15:12:05 +00:00
|
|
|
|
2011-08-30 19:14:13 +00:00
|
|
|
- (id)initWithDefaults {
|
|
|
|
fWind = NULL;
|
2011-07-17 14:42:08 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithCoder:(NSCoder*)coder {
|
|
|
|
if ((self = [super initWithCoder:coder])) {
|
2011-08-30 19:14:13 +00:00
|
|
|
self = [self initWithDefaults];
|
|
|
|
[self setUpWindow];
|
2011-07-17 14:42:08 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithFrame:(CGRect)frame {
|
|
|
|
if (self = [super initWithFrame:frame]) {
|
2011-08-30 19:14:13 +00:00
|
|
|
self = [self initWithDefaults];
|
|
|
|
[self setUpWindow];
|
2011-07-17 14:42:08 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-08-30 19:14:13 +00:00
|
|
|
- (void)setUpWindow {
|
|
|
|
if (NULL != fWind) {
|
|
|
|
fWind->setVisibleP(true);
|
|
|
|
fWind->resize(self.frame.size.width, self.frame.size.height,
|
|
|
|
SkBitmap::kARGB_8888_Config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 14:42:08 +00:00
|
|
|
- (void)dealloc {
|
|
|
|
delete fWind;
|
|
|
|
[fTitleItem release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-08-30 19:14:13 +00:00
|
|
|
- (void)forceRedraw {
|
|
|
|
[self drawInRaster];
|
2011-07-17 14:42:08 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 15:17:44 +00:00
|
|
|
- (void)drawInRaster {
|
2011-08-30 19:14:13 +00:00
|
|
|
SkCanvas canvas(fWind->getBitmap());
|
|
|
|
fWind->draw(&canvas);
|
2011-07-19 15:17:44 +00:00
|
|
|
CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap());
|
2011-08-30 19:14:13 +00:00
|
|
|
self.layer.contents = (id)cgimage;
|
2011-07-19 15:17:44 +00:00
|
|
|
CGImageRelease(cgimage);
|
|
|
|
}
|
|
|
|
|
2011-07-17 14:42:08 +00:00
|
|
|
//Gesture Handlers
|
|
|
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
for (UITouch *touch in touches) {
|
|
|
|
CGPoint loc = [touch locationInView:self];
|
|
|
|
fWind->handleClick(loc.x, loc.y, SkView::Click::kDown_State, touch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
for (UITouch *touch in touches) {
|
|
|
|
CGPoint loc = [touch locationInView:self];
|
|
|
|
fWind->handleClick(loc.x, loc.y, SkView::Click::kMoved_State, touch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
for (UITouch *touch in touches) {
|
|
|
|
CGPoint loc = [touch locationInView:self];
|
|
|
|
fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
|
for (UITouch *touch in touches) {
|
|
|
|
CGPoint loc = [touch locationInView:self];
|
|
|
|
fWind->handleClick(loc.x, loc.y, SkView::Click::kUp_State, touch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
- (void)setSkTitle:(const char *)title {
|
2011-08-30 19:14:13 +00:00
|
|
|
if (fTitleItem) {
|
|
|
|
fTitleItem.title = [NSString stringWithUTF8String:title];
|
2011-07-17 14:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)onHandleEvent:(const SkEvent&)evt {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-02 13:20:22 +00:00
|
|
|
#include "SkOSMenu.h"
|
|
|
|
- (void)onAddMenu:(const SkOSMenu*)menu {
|
|
|
|
[self.fOptionsDelegate view:self didAddMenu:menu];
|
|
|
|
}
|
|
|
|
- (void)onUpdateMenu:(const SkOSMenu*)menu {
|
|
|
|
[self.fOptionsDelegate view:self didUpdateMenu:menu];
|
|
|
|
}
|
|
|
|
|
2011-07-17 14:42:08 +00:00
|
|
|
- (void)postInvalWithRect:(const SkIRect*)r {
|
2011-08-30 19:14:13 +00:00
|
|
|
[self performSelector:@selector(drawInRaster) withObject:nil afterDelay:0];
|
|
|
|
[self setNeedsDisplay];
|
2011-07-17 14:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|