2011-12-03 22:41:37 +01:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-12-03 22:41:37 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLATFORMWINDOW_H
|
|
|
|
#define PLATFORMWINDOW_H
|
|
|
|
|
|
|
|
#include <framework/global.h>
|
|
|
|
#include <framework/core/inputevent.h>
|
2012-01-15 22:19:52 +01:00
|
|
|
#include <framework/core/timer.h>
|
2011-12-03 22:41:37 +01:00
|
|
|
|
|
|
|
class PlatformWindow
|
|
|
|
{
|
2012-01-15 22:19:52 +01:00
|
|
|
enum {
|
|
|
|
KEY_PRESS_REPEAT_INTERVAL = 30,
|
|
|
|
};
|
|
|
|
|
2011-12-03 22:41:37 +01:00
|
|
|
typedef std::function<void(const Size&)> OnResizeCallback;
|
|
|
|
typedef std::function<void(const InputEvent&)> OnInputEventCallback;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void terminate() = 0;
|
|
|
|
|
|
|
|
virtual void move(const Point& pos) = 0;
|
|
|
|
virtual void resize(const Size& size) = 0;
|
|
|
|
virtual void show() = 0;
|
|
|
|
virtual void hide() = 0;
|
|
|
|
virtual void maximize() = 0;
|
|
|
|
virtual void poll() = 0;
|
|
|
|
virtual void swapBuffers() = 0;
|
2012-01-12 02:12:25 +01:00
|
|
|
virtual void restoreMouseCursor() = 0;
|
2011-12-03 22:41:37 +01:00
|
|
|
virtual void showMouse() = 0;
|
|
|
|
virtual void hideMouse() = 0;
|
2012-01-12 02:12:25 +01:00
|
|
|
virtual void displayFatalError(const std::string& message) { }
|
2011-12-03 22:41:37 +01:00
|
|
|
|
2012-01-20 03:48:38 +01:00
|
|
|
virtual void setMouseCursor(const std::string& file, const Point& hotSpot) = 0;
|
2011-12-03 22:41:37 +01:00
|
|
|
virtual void setTitle(const std::string& title) = 0;
|
|
|
|
virtual void setMinimumSize(const Size& minimumSize) = 0;
|
|
|
|
virtual void setFullscreen(bool fullscreen) = 0;
|
|
|
|
virtual void setVerticalSync(bool enable) = 0;
|
|
|
|
virtual void setIcon(const std::string& iconFile) = 0;
|
|
|
|
virtual void setClipboardText(const std::string& text) = 0;
|
|
|
|
|
|
|
|
virtual Size getDisplaySize() = 0;
|
|
|
|
virtual std::string getClipboardText() = 0;
|
2011-12-30 05:50:19 +01:00
|
|
|
virtual std::string getPlatformType() = 0;
|
2011-12-03 22:41:37 +01:00
|
|
|
|
|
|
|
int getDisplayWidth() { return getDisplaySize().width(); }
|
|
|
|
int getDisplayHeight() { return getDisplaySize().width(); }
|
|
|
|
|
2012-01-06 09:48:59 +01:00
|
|
|
Size getUnmaximizedSize() { return m_unmaximizedSize; }
|
2011-12-03 22:41:37 +01:00
|
|
|
Size getSize() { return m_size; }
|
|
|
|
int getWidth() { return m_size.width(); }
|
|
|
|
int getHeight() { return m_size.height(); }
|
2012-01-06 09:48:59 +01:00
|
|
|
Point getUnmaximizedPos() { return m_unmaximizedPos; }
|
2012-01-30 01:00:12 +01:00
|
|
|
Point getPosition() { return m_position; }
|
|
|
|
int getX() { return m_position.x; }
|
|
|
|
int getY() { return m_position.y; }
|
2012-02-05 23:42:35 +01:00
|
|
|
Point getMousePosition() { return m_inputEvent.mousePos; }
|
2011-12-03 22:41:37 +01:00
|
|
|
int getKeyboardModifiers() { return m_inputEvent.keyboardModifiers; }
|
2012-01-15 22:19:52 +01:00
|
|
|
bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; }
|
2011-12-03 22:41:37 +01:00
|
|
|
|
|
|
|
bool isVisible() { return m_visible; }
|
2012-02-20 03:27:08 +01:00
|
|
|
bool isMaximized() { return m_maximized; }
|
2011-12-03 22:41:37 +01:00
|
|
|
bool isFullscreen() { return m_fullscreen; }
|
|
|
|
bool hasFocus() { return m_focused; }
|
|
|
|
|
|
|
|
void setOnClose(const SimpleCallback& onClose) { m_onClose = onClose; }
|
|
|
|
void setOnResize(const OnResizeCallback& onResize) { m_onResize = onResize; }
|
|
|
|
void setOnInputEvent(const OnInputEventCallback& onInputEvent) { m_onInputEvent = onInputEvent; }
|
|
|
|
|
|
|
|
protected:
|
2012-01-06 09:48:59 +01:00
|
|
|
void updateUnmaximizedCoords();
|
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
void processKeyDown(Fw::Key keyCode);
|
2012-01-17 07:24:58 +01:00
|
|
|
void processKeyUp(Fw::Key keyCode);
|
2012-01-16 02:55:14 +01:00
|
|
|
void releaseAllKeys();
|
2012-01-15 22:19:52 +01:00
|
|
|
void fireKeysPress();
|
|
|
|
|
|
|
|
std::map<int, Fw::Key> m_keyMap;
|
|
|
|
std::map<Fw::Key, Boolean<false>> m_keysState;
|
|
|
|
std::map<Fw::Key, ticks_t> m_firstKeysPress;
|
|
|
|
std::map<Fw::Key, ticks_t> m_lastKeysPress;
|
|
|
|
Timer m_keyPressTimer;
|
|
|
|
|
2011-12-03 22:41:37 +01:00
|
|
|
Size m_size;
|
2012-01-30 01:00:12 +01:00
|
|
|
Point m_position;
|
2012-01-06 09:48:59 +01:00
|
|
|
Size m_unmaximizedSize;
|
|
|
|
Point m_unmaximizedPos;
|
2011-12-03 22:41:37 +01:00
|
|
|
InputEvent m_inputEvent;
|
|
|
|
|
|
|
|
Boolean<false> m_created;
|
|
|
|
Boolean<false> m_visible;
|
|
|
|
Boolean<false> m_focused;
|
|
|
|
Boolean<false> m_fullscreen;
|
2012-02-20 03:27:08 +01:00
|
|
|
Boolean<false> m_maximized;
|
2011-12-03 22:41:37 +01:00
|
|
|
|
|
|
|
SimpleCallback m_onClose;
|
|
|
|
OnResizeCallback m_onResize;
|
|
|
|
OnInputEventCallback m_onInputEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern PlatformWindow& g_window;
|
|
|
|
|
|
|
|
#endif
|