42 #import <QuartzCore/CAEAGLLayer.h> 49 #include <QtGui/QApplication> 50 #include <QtGui/QKeyEvent> 51 #include <QtGui/QPlatformGLContext> 52 #include <QtGui/QWindowSystemInterface> 59 static bool initialized =
false;
98 #if defined(QT_OPENGL_ES_2) 99 EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
101 EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
103 [
mView setContext:aContext];
121 [
mView presentFramebuffer];
143 return [CAEAGLLayer class];
146 - (id)initWithFrame:(
CGRect)frame
148 if ((
self = [super initWithFrame:frame])) {
149 CAEAGLLayer *eaglLayer = (CAEAGLLayer *)
self.layer;
150 eaglLayer.opaque =
TRUE;
151 eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
152 [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking,
153 kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
166 - (void)setContext:(EAGLContext *)newContext
173 [EAGLContext setCurrentContext:nil];
180 [EAGLContext setCurrentContext:mContext];
182 [
mContext presentRenderbuffer:GL_RENDERBUFFER];
190 [EAGLContext setCurrentContext:mContext];
210 [EAGLContext setCurrentContext:mContext];
216 [
mContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
233 if (
delegate && [
delegate respondsToSelector:
@selector(eaglView:usesFramebuffer:)]) {
234 [
delegate eaglView:self usesFramebuffer:mFramebuffer];
243 [EAGLContext setCurrentContext:mContext];
261 - (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(
Qt::MouseButtons)buttons
263 UITouch *touch = [touches anyObject];
264 CGPoint locationInView = [touch locationInView:self];
265 CGFloat scaleFactor = [
self contentScaleFactor];
266 QPoint p(locationInView.x * scaleFactor, locationInView.y * scaleFactor);
272 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)
event 274 [
self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
277 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)
event 279 [
self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
282 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)
event 284 [
self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
287 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)
event 289 [
self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
302 - (BOOL)canBecomeFirstResponder
312 - (void)insertText:(NSString *)
text 316 if ([
text isEqualToString:
@"\n"])
326 - (void)deleteBackward
364 mWindow = [[UIWindow alloc] init];
375 [
mView setMultipleTouchEnabled:YES];
392 switch ([[UIApplication sharedApplication] statusBarOrientation]) {
393 case UIInterfaceOrientationPortrait:
396 case UIInterfaceOrientationPortraitUpsideDown:
398 screen.size.height -
mFrame.origin.y -
mFrame.size.height,
403 case UIInterfaceOrientationLandscapeLeft:
410 case UIInterfaceOrientationLandscapeRight:
412 screen.size.width -
mFrame.origin.x -
mFrame.size.width,
420 geom =
QRect(geom.
x() * scale, geom.
y() * scale,
424 [
mView layer].transform = CATransform3DMakeRotation(angle, 0, 0, 1.);
426 [
mView layer].transform = CATransform3DIdentity;
428 [
mView setNeedsDisplay];
EAGLPlatformContext * mContext
GLuint mDepthRenderbuffer
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
QPlatformWindow * mWindow
#define QT_END_NAMESPACE
This macro expands to.
#define GL_RENDERBUFFER_WIDTH
UIWindow * ensureNativeWindow()
#define GL_FRAMEBUFFER_COMPLETE
virtual void doneCurrent()
Reimplement in subclass to release current context.
static Qt::MouseButtons buttons
#define glGenRenderbuffers
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
int width() const
Returns the width of the rectangle.
BOOL enablesReturnKeyAutomatically
int height() const
Returns the height of the rectangle.
The QString class provides a Unicode character string.
#define glBindFramebuffer
QUIKitWindow(QWidget *tlw)
#define glDeleteRenderbuffers
static GLint stencilBits()
#define GL_DEPTH_ATTACHMENT
void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
#define QT_BEGIN_NAMESPACE
This macro expands to.
#define GL_DEPTH_COMPONENT16
#define glCheckFramebufferStatus
#define glDeleteFramebuffers
UIKeyboardType keyboardType
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
void * getProcAddress(const QString &)
Reimplement in subclass to native getProcAddr calls.
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
#define glGenFramebuffers
GLuint mColorRenderbuffer
void updateGeometryAndOrientation()
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
#define glGetRenderbufferParameteriv
#define glBindRenderbuffer
#define TRUE
Synonym for true.
qreal angle(const QPointF &p1, const QPointF &p2)
UIKeyboardAppearance keyboardAppearance
The QPlatformGLContext class provides an abstraction for native GL contexts.
int y() const
Returns the y-coordinate of the rectangle's top edge.
void setWindow:(QPlatformWindow *window)
int x() const
Returns the x-coordinate of the rectangle's left edge.
UIReturnKeyType returnKeyType
The QPoint class defines a point in the plane using integer precision.
#define GL_STENCIL_ATTACHMENT
The QRect class defines a rectangle in the plane using integer precision.
#define GL_COLOR_ATTACHMENT0
#define glFramebufferRenderbuffer
UIScreen * uiScreen() const
void doneCurrent()
Reimplement in subclass to release current context.
#define GL_RENDERBUFFER_HEIGHT
void presentFramebuffer()
UITextAutocapitalizationType autocapitalizationType
EAGLPlatformContext(EAGLView *view)
UITextAutocorrectionType autocorrectionType
QPlatformGLContext * glContext() const
Reimplement to return the glContext associated with the window.
#define glRenderbufferStorage
QPlatformWindowFormat mFormat
QPlatformWindowFormat platformWindowFormat() const
QWidget has the function qplatformWindowFormat().