| 1 | /* |
| 2 | SDL - Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2009 Sam Lantinga |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | Sam Lantinga |
| 20 | slouken@libsdl.org |
| 21 | */ |
| 22 | #include "SDL_config.h" |
| 23 | |
| 24 | #ifndef _SDL_QWin_h |
| 25 | #define _SDL_QWin_h |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | #include <qimage.h> |
| 30 | #include <qpixmap.h> |
| 31 | #include <qwidget.h> |
| 32 | #include <qpainter.h> |
| 33 | #include <qdirectpainter_qws.h> |
| 34 | |
| 35 | #include "SDL_events.h" |
| 36 | |
| 37 | extern "C" { |
| 38 | #include "../../events/SDL_events_c.h" |
| 39 | }; |
| 40 | |
| 41 | typedef enum { |
| 42 | SDL_QT_NO_ROTATION = 0, |
| 43 | SDL_QT_ROTATION_90, |
| 44 | SDL_QT_ROTATION_270 |
| 45 | } screenRotationT; |
| 46 | |
| 47 | extern screenRotationT screenRotation; |
| 48 | |
| 49 | class SDL_QWin : public QWidget |
| 50 | { |
| 51 | void QueueKey(QKeyEvent *e, int pressed); |
| 52 | public: |
| 53 | SDL_QWin(const QSize& size); |
| 54 | virtual ~SDL_QWin(); |
| 55 | virtual bool shown(void) { |
| 56 | return isVisible(); |
| 57 | } |
| 58 | /* If called, the next resize event will not be forwarded to SDL. */ |
| 59 | virtual void inhibitResize(void) { |
| 60 | my_inhibit_resize = true; |
| 61 | } |
| 62 | void setImage(QImage *image); |
| 63 | void setOffset(int x, int y) { |
| 64 | my_offset = QPoint(x, y); |
| 65 | } |
| 66 | void GetXYOffset(int &x, int &y) { |
| 67 | x = my_offset.x(); |
| 68 | y = my_offset.y(); |
| 69 | } |
| 70 | QImage *image(void) { return my_image; } |
| 71 | |
| 72 | void setWFlags(WFlags flags) { |
| 73 | QWidget::setWFlags(flags); |
| 74 | my_flags = flags; |
| 75 | } |
| 76 | const QPoint& mousePos() const { return my_mouse_pos; } |
| 77 | void setMousePos(const QPoint& newpos); |
| 78 | void setFullscreen(bool); |
| 79 | |
| 80 | bool lockScreen(bool force=false); |
| 81 | void unlockScreen(); |
| 82 | void repaintRect(const QRect& rect); |
| 83 | protected: |
| 84 | /* Handle resizing of the window */ |
| 85 | virtual void resizeEvent(QResizeEvent *e); |
| 86 | void focusInEvent(QFocusEvent *); |
| 87 | void focusOutEvent(QFocusEvent *); |
| 88 | void closeEvent(QCloseEvent *e); |
| 89 | void mouseMoveEvent(QMouseEvent *e); |
| 90 | void mousePressEvent(QMouseEvent *e); |
| 91 | void mouseReleaseEvent(QMouseEvent *e); |
| 92 | void paintEvent(QPaintEvent *ev); |
| 93 | void keyPressEvent(QKeyEvent *e) { QueueKey(e, 1); } |
| 94 | void keyReleaseEvent(QKeyEvent *e) { QueueKey(e, 0); } |
| 95 | private: |
| 96 | bool repaintRotation0(const QRect& rect); |
| 97 | bool repaintRotation1(const QRect& rect); |
| 98 | bool repaintRotation3(const QRect& rect); |
| 99 | void enableFullscreen(); |
| 100 | QDirectPainter *my_painter; |
| 101 | QImage *my_image; |
| 102 | bool my_inhibit_resize; |
| 103 | QPoint my_offset; |
| 104 | QPoint my_mouse_pos; |
| 105 | WFlags my_flags; |
| 106 | WFlags my_has_fullscreen; |
| 107 | unsigned int my_locked; |
| 108 | }; |
| 109 | |
| 110 | #endif /* _SDL_QWin_h */ |