19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _SDL_QWin_h
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _SDL_QWin_h
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qimage.h>
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qpixmap.h>
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qwidget.h>
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qpainter.h>
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <qdirectpainter_qws.h>
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_events.h"
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" {
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef enum {
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_QT_NO_ROTATION = 0,
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_QT_ROTATION_90,
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_QT_ROTATION_270
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} screenRotationT;
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern screenRotationT screenRotation;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallclass SDL_QWin : public QWidget
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void QueueKey(QKeyEvent *e, int pressed);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall public:
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_QWin(const QSize& size);
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  virtual ~SDL_QWin();
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  virtual bool shown(void) {
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return isVisible();
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* If called, the next resize event will not be forwarded to SDL. */
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  virtual void inhibitResize(void) {
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    my_inhibit_resize = true;
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void setImage(QImage *image);
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void setOffset(int x, int y) {
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    my_offset = QPoint(x, y);
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void GetXYOffset(int &x, int &y) {
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    x = my_offset.x();
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    y = my_offset.y();
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  QImage *image(void) { return my_image; }
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void setWFlags(WFlags flags) {
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    QWidget::setWFlags(flags);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    my_flags = flags;
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  const QPoint& mousePos() const { return my_mouse_pos; }
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void setMousePos(const QPoint& newpos);
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void setFullscreen(bool);
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  bool lockScreen(bool force=false);
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void unlockScreen();
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void repaintRect(const QRect& rect);
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall protected:
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* Handle resizing of the window */
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  virtual void resizeEvent(QResizeEvent *e);
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void focusInEvent(QFocusEvent *);
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void focusOutEvent(QFocusEvent *);
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void closeEvent(QCloseEvent *e);
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void mouseMoveEvent(QMouseEvent *e);
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void mousePressEvent(QMouseEvent *e);
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void mouseReleaseEvent(QMouseEvent *e);
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void paintEvent(QPaintEvent *ev);
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void keyPressEvent(QKeyEvent *e)   { QueueKey(e, 1); }
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void keyReleaseEvent(QKeyEvent *e) { QueueKey(e, 0); }
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall private:
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  bool repaintRotation0(const QRect& rect);
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  bool repaintRotation1(const QRect& rect);
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  bool repaintRotation3(const QRect& rect);
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  void enableFullscreen();
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  QDirectPainter *my_painter;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  QImage *my_image;
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  bool my_inhibit_resize;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  QPoint my_offset;
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  QPoint my_mouse_pos;
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  WFlags my_flags;
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  WFlags my_has_fullscreen;
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  unsigned int my_locked;
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* _SDL_QWin_h */
111