first gui stuff
This commit is contained in:
parent
8a33e0cf19
commit
4c6d1269a0
|
@ -53,8 +53,10 @@ SET(SOURCES
|
||||||
# game sources
|
# game sources
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/menustate.cpp
|
src/menustate.cpp
|
||||||
|
src/teststate.cpp
|
||||||
|
|
||||||
# framework sources
|
# framework sources
|
||||||
|
src/framework/dispatcher.cpp
|
||||||
src/framework/framebuffer.cpp
|
src/framework/framebuffer.cpp
|
||||||
src/framework/font.cpp
|
src/framework/font.cpp
|
||||||
src/framework/fonts.cpp
|
src/framework/fonts.cpp
|
||||||
|
@ -68,6 +70,14 @@ SET(SOURCES
|
||||||
src/framework/logger.cpp
|
src/framework/logger.cpp
|
||||||
src/framework/util.cpp
|
src/framework/util.cpp
|
||||||
|
|
||||||
|
# ui
|
||||||
|
src/framework/ui/uielement.cpp
|
||||||
|
src/framework/ui/uicontainer.cpp
|
||||||
|
src/framework/ui/uipanel.cpp
|
||||||
|
src/framework/ui/uibutton.cpp
|
||||||
|
src/framework/ui/uilabel.cpp
|
||||||
|
|
||||||
|
# network
|
||||||
src/framework/net/connection.cpp
|
src/framework/net/connection.cpp
|
||||||
src/framework/net/connections.cpp)
|
src/framework/net/connections.cpp)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "dispatcher.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
Dispatcher g_dispatcher;
|
||||||
|
|
||||||
|
void Dispatcher::poll(int ticks)
|
||||||
|
{
|
||||||
|
while(!m_taskList.empty()) {
|
||||||
|
Task *task = m_taskList.top();
|
||||||
|
if(ticks < task->ticks)
|
||||||
|
break;
|
||||||
|
|
||||||
|
task->callback();
|
||||||
|
delete task;
|
||||||
|
m_taskList.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dispatcher::scheduleTask(const Callback& callback, int delay)
|
||||||
|
{
|
||||||
|
m_taskList.push(new Task(Platform::getTicks() + delay, callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dispatcher::addTask(const Callback& callback)
|
||||||
|
{
|
||||||
|
m_taskList.push(new Task(callback));
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 DISPATCHER_H
|
||||||
|
#define DISPATCHER_H
|
||||||
|
|
||||||
|
#include "prerequisites.h"
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
typedef std::function<void (void)> Callback;
|
||||||
|
|
||||||
|
class Task {
|
||||||
|
public:
|
||||||
|
inline Task(const Callback& _callback) : ticks(0), callback(_callback) { }
|
||||||
|
inline Task(int _ticks, const Callback& _callback) : ticks(_ticks), callback(_callback) { }
|
||||||
|
inline bool operator<(const Task& other) const { return ticks > other.ticks; }
|
||||||
|
int ticks;
|
||||||
|
Callback callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
class lessTask : public std::binary_function<Task*&, Task*&, bool> {
|
||||||
|
public:
|
||||||
|
bool operator()(Task*& t1,Task*& t2) { return (*t1) < (*t2); }
|
||||||
|
};
|
||||||
|
|
||||||
|
class Dispatcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Dispatcher() { }
|
||||||
|
|
||||||
|
void poll(int ticks);
|
||||||
|
|
||||||
|
void addTask(const Callback& callback);
|
||||||
|
void scheduleTask(const Callback& callback, int delay);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::priority_queue<Task*, std::vector<Task*>, lessTask> m_taskList;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Dispatcher g_dispatcher;
|
||||||
|
|
||||||
|
#endif // DISPATCHER_H
|
|
@ -29,7 +29,9 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "configs.h"
|
#include "configs.h"
|
||||||
#include "gamestate.h"
|
#include "gamestate.h"
|
||||||
|
#include "dispatcher.h"
|
||||||
#include "net/connections.h"
|
#include "net/connections.h"
|
||||||
|
#include "ui/uicontainer.h"
|
||||||
|
|
||||||
#define MINIMUN_UPDATE_DELAY 50
|
#define MINIMUN_UPDATE_DELAY 50
|
||||||
|
|
||||||
|
@ -40,9 +42,6 @@ void Engine::init()
|
||||||
// initialize stuff
|
// initialize stuff
|
||||||
g_graphics.init();
|
g_graphics.init();
|
||||||
g_fonts.init();
|
g_fonts.init();
|
||||||
|
|
||||||
// finally show the window
|
|
||||||
onResize(Platform::getWindowWidth(), Platform::getWindowHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::terminate()
|
void Engine::terminate()
|
||||||
|
@ -72,7 +71,7 @@ void Engine::run()
|
||||||
Point fpsPos(10,10);
|
Point fpsPos(10,10);
|
||||||
|
|
||||||
while(!m_stopping) {
|
while(!m_stopping) {
|
||||||
// fire platform events
|
// poll platform events
|
||||||
Platform::poll();
|
Platform::poll();
|
||||||
|
|
||||||
// poll network events
|
// poll network events
|
||||||
|
@ -80,6 +79,10 @@ void Engine::run()
|
||||||
|
|
||||||
// update before redering
|
// update before redering
|
||||||
ticks = Platform::getTicks();
|
ticks = Platform::getTicks();
|
||||||
|
|
||||||
|
// poll diaptcher tasks
|
||||||
|
g_dispatcher.poll(ticks);
|
||||||
|
|
||||||
updateElapsedTicks = ticks - lastUpdateTicks;
|
updateElapsedTicks = ticks - lastUpdateTicks;
|
||||||
if(updateElapsedTicks >= MINIMUN_UPDATE_DELAY) {
|
if(updateElapsedTicks >= MINIMUN_UPDATE_DELAY) {
|
||||||
update(ticks, updateElapsedTicks);
|
update(ticks, updateElapsedTicks);
|
||||||
|
@ -133,6 +136,7 @@ void Engine::render()
|
||||||
g_graphics.beginRender();
|
g_graphics.beginRender();
|
||||||
if(m_currentState)
|
if(m_currentState)
|
||||||
m_currentState->render();
|
m_currentState->render();
|
||||||
|
g_gui.render();
|
||||||
g_graphics.endRender();
|
g_graphics.endRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +144,7 @@ void Engine::update(int ticks, int elapsedTicks)
|
||||||
{
|
{
|
||||||
if(m_currentState)
|
if(m_currentState)
|
||||||
m_currentState->update(ticks, elapsedTicks);
|
m_currentState->update(ticks, elapsedTicks);
|
||||||
|
g_gui.update(ticks, elapsedTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onClose()
|
void Engine::onClose()
|
||||||
|
@ -148,13 +153,18 @@ void Engine::onClose()
|
||||||
m_currentState->onClose();
|
m_currentState->onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onResize(int width, int height)
|
void Engine::onResize(const Size& size)
|
||||||
{
|
{
|
||||||
g_graphics.resize(width, height);
|
g_graphics.resize(size);
|
||||||
|
g_gui.resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onInputEvent(InputEvent *event)
|
void Engine::onInputEvent(InputEvent *event)
|
||||||
{
|
{
|
||||||
if(m_currentState)
|
// inputs goest to gui first
|
||||||
m_currentState->onInputEvent(event);
|
if(!g_gui.onInputEvent(event)) {
|
||||||
|
// if gui didnt capture the input then goes to the state
|
||||||
|
if(m_currentState)
|
||||||
|
m_currentState->onInputEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#define ENGINE_H
|
#define ENGINE_H
|
||||||
|
|
||||||
#include "prerequisites.h"
|
#include "prerequisites.h"
|
||||||
|
#include "size.h"
|
||||||
|
|
||||||
struct InputEvent;
|
struct InputEvent;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public:
|
||||||
/// Fired by platform on window close
|
/// Fired by platform on window close
|
||||||
void onClose();
|
void onClose();
|
||||||
/// Fired by platform on window resize
|
/// Fired by platform on window resize
|
||||||
void onResize(int width, int height);
|
void onResize(const Size& size);
|
||||||
/// Fired by platform on mouse/keyboard input
|
/// Fired by platform on mouse/keyboard input
|
||||||
void onInputEvent(InputEvent *event);
|
void onInputEvent(InputEvent *event);
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ Point* Font::calculateGlyphsPositions(const std::string& text, int align, Size *
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Size Font::calculateTextBoxSize(const std::string& text)
|
Size Font::calculateTextRectSize(const std::string& text)
|
||||||
{
|
{
|
||||||
Size size;
|
Size size;
|
||||||
calculateGlyphsPositions(text, ALIGN_TOP_LEFT, &size);
|
calculateGlyphsPositions(text, ALIGN_TOP_LEFT, &size);
|
||||||
|
|
|
@ -43,7 +43,7 @@ enum EAlign {
|
||||||
ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT,
|
ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT,
|
||||||
ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT
|
ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT
|
||||||
};
|
};
|
||||||
|
|
||||||
class Font
|
class Font
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -71,12 +71,7 @@ public:
|
||||||
Point *calculateGlyphsPositions(const std::string& text, int align = ALIGN_TOP_LEFT, Size *textBoxSize = NULL);
|
Point *calculateGlyphsPositions(const std::string& text, int align = ALIGN_TOP_LEFT, Size *textBoxSize = NULL);
|
||||||
|
|
||||||
/// Simulate render and calculate text size
|
/// Simulate render and calculate text size
|
||||||
Size calculateTextBoxSize(const std::string& text);
|
Size calculateTextRectSize(const std::string& text);
|
||||||
|
|
||||||
/*
|
|
||||||
/// Render a text inside a rect
|
|
||||||
void renderText(const Rect& screenCoords, EAlign align, const std::string& text);
|
|
||||||
*/
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_lineHeight;
|
int m_lineHeight;
|
||||||
|
|
|
@ -81,10 +81,9 @@ bool Graphics::isExtensionSupported(const char *extension)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::resize(int width, int height)
|
void Graphics::resize(const Size& size)
|
||||||
{
|
{
|
||||||
m_screenSize.setWidth(width);
|
m_screenSize = size;
|
||||||
m_screenSize.setHeight(height);
|
|
||||||
restoreViewport();
|
restoreViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
bool isExtensionSupported(const char *extension);
|
bool isExtensionSupported(const char *extension);
|
||||||
|
|
||||||
/// Called after every window resize
|
/// Called after every window resize
|
||||||
void resize(int width, int height);
|
void resize(const Size& size);
|
||||||
|
|
||||||
/// Restore original viewport
|
/// Restore original viewport
|
||||||
void restoreViewport();
|
void restoreViewport();
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UI_H
|
||||||
|
#define UI_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
|
||||||
|
#include "uiconstants.h"
|
||||||
|
#include "uielement.h"
|
||||||
|
#include "uicontainer.h"
|
||||||
|
#include "uipanel.h"
|
||||||
|
#include "uibutton.h"
|
||||||
|
#include "uilabel.h"
|
||||||
|
|
||||||
|
#endif // UI_H
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uibutton.h"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIBUTTON_H
|
||||||
|
#define UIBUTTON_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uielement.h"
|
||||||
|
|
||||||
|
class UIButton : public UIElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIButton(UIContainerPtr parent) : UIElement(parent) { }
|
||||||
|
|
||||||
|
virtual UI::ControlType getControlType() const { return UI::Button; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UIBUTTON_H
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UICONSTANTS_H
|
||||||
|
#define UICONSTANTS_H
|
||||||
|
|
||||||
|
namespace UI {
|
||||||
|
enum ButtonState
|
||||||
|
{
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
MouseOver
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ButtonEvent
|
||||||
|
{
|
||||||
|
PressUp,
|
||||||
|
PressDown,
|
||||||
|
EnterMouseOver,
|
||||||
|
LeaveMouseOver
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MessageBoxFlags
|
||||||
|
{
|
||||||
|
Ok = 1 << 0,
|
||||||
|
Cancel = 1 << 1,
|
||||||
|
Yes = 1 << 2,
|
||||||
|
No = 1 << 3,
|
||||||
|
OkCancel = Ok | Cancel,
|
||||||
|
YesNo = Yes | No
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ControlType
|
||||||
|
{
|
||||||
|
Element,
|
||||||
|
Container,
|
||||||
|
Panel,
|
||||||
|
Window,
|
||||||
|
Label,
|
||||||
|
TextBox,
|
||||||
|
Button,
|
||||||
|
CheckBox
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // UICONSTANTS_H
|
|
@ -0,0 +1,100 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uicontainer.h"
|
||||||
|
|
||||||
|
UIContainer g_gui;
|
||||||
|
|
||||||
|
void UIContainer::addChild(UIElementPtr child)
|
||||||
|
{
|
||||||
|
m_children.push_back(child);
|
||||||
|
child->setParent(asUIContainer());
|
||||||
|
|
||||||
|
// adjust child rect
|
||||||
|
Rect childRect = child->getRect();
|
||||||
|
childRect.translate(m_rect.topLeft());
|
||||||
|
child->setRect(childRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIContainer::removeChild(UIElementPtr child)
|
||||||
|
{
|
||||||
|
if(m_activeElement == child)
|
||||||
|
setActiveElement(UIElementPtr());
|
||||||
|
m_children.remove(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
UIElementPtr UIContainer::getChildByName(const std::string& name) const
|
||||||
|
{
|
||||||
|
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||||
|
if((*it)->getName() == name) {
|
||||||
|
return (*it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UIElementPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UIContainer::setRect(const Rect& rect)
|
||||||
|
{
|
||||||
|
// update children rect
|
||||||
|
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||||
|
UIElementPtr child = (*it)->asUIElement();
|
||||||
|
|
||||||
|
// transforme child rect
|
||||||
|
Rect childRect = child->getRect();
|
||||||
|
childRect.translate(-m_rect.topLeft());
|
||||||
|
childRect.translate(rect.topLeft());
|
||||||
|
child->setRect(childRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_rect = rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIContainer::resize(const Size& size)
|
||||||
|
{
|
||||||
|
Rect newRect = m_rect;
|
||||||
|
newRect.setSize(size);
|
||||||
|
setRect(newRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIContainer::move(const Point& trans)
|
||||||
|
{
|
||||||
|
Rect newRect = m_rect;
|
||||||
|
newRect.translate(trans);
|
||||||
|
setRect(newRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIContainer::moveTo(const Point& pos)
|
||||||
|
{
|
||||||
|
Rect newRect = m_rect;
|
||||||
|
newRect.moveTo(pos);
|
||||||
|
setRect(newRect);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIContainer::setActiveElement(UIElementPtr activeElement)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UICONTAINER_H
|
||||||
|
#define UICONTAINER_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uielement.h"
|
||||||
|
#include "../point.h"
|
||||||
|
#include "../rect.h"
|
||||||
|
|
||||||
|
class UIContainer : public UIElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIContainer(UIContainerPtr parent = UIContainerPtr()) : UIElement(parent) { }
|
||||||
|
virtual ~UIContainer() { }
|
||||||
|
|
||||||
|
virtual void addChild(UIElementPtr child);
|
||||||
|
virtual void removeChild(UIElementPtr child);
|
||||||
|
virtual UIElementPtr getChildByName(const std::string& name) const;
|
||||||
|
|
||||||
|
virtual void setRect(const Rect& rect);
|
||||||
|
virtual void resize(const Size& size);
|
||||||
|
virtual void move(const Point& trans);
|
||||||
|
virtual void moveTo(const Point& pos);
|
||||||
|
|
||||||
|
virtual void render() { }
|
||||||
|
virtual void update(int ticks, int elapsedTicks) { }
|
||||||
|
virtual bool onInputEvent(InputEvent *event) { return false; }
|
||||||
|
|
||||||
|
virtual void setActiveElement(UIElementPtr activeElement);
|
||||||
|
UIElementPtr getActiveElement() const { return m_activeElement; }
|
||||||
|
|
||||||
|
virtual UI::ControlType getControlType() const { return UI::Container; }
|
||||||
|
UIContainerPtr asUIContainer() { return UIContainerPtr(this); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::list<UIElementPtr> m_children;
|
||||||
|
UIElementPtr m_activeElement;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onMove(const Point& pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern UIContainer g_gui;
|
||||||
|
|
||||||
|
#endif // UICONTAINER_H
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uielement.h"
|
||||||
|
#include "uicontainer.h"
|
||||||
|
|
||||||
|
UIElement::UIElement(UIContainerPtr parent) :
|
||||||
|
m_visible(true),
|
||||||
|
m_active(true)
|
||||||
|
{
|
||||||
|
if(parent)
|
||||||
|
parent->addChild(asUIElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIELEMENT_H
|
||||||
|
#define UIELEMENT_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "../input.h"
|
||||||
|
#include "../rect.h"
|
||||||
|
#include "uiconstants.h"
|
||||||
|
|
||||||
|
class UIContainer;
|
||||||
|
typedef std::shared_ptr<UIContainer> UIContainerPtr;
|
||||||
|
|
||||||
|
class UIElement;
|
||||||
|
typedef std::shared_ptr<UIElement> UIElementPtr;
|
||||||
|
|
||||||
|
class UIElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIElement(UIContainerPtr parent);
|
||||||
|
virtual ~UIElement() { }
|
||||||
|
|
||||||
|
virtual void render() { }
|
||||||
|
virtual void update(int ticks, int elapsedTicks) { }
|
||||||
|
virtual bool onInputEvent(InputEvent *event) { return false; }
|
||||||
|
|
||||||
|
virtual void setParent(UIContainerPtr parent) { m_parent = parent; }
|
||||||
|
UIContainerPtr getParent() const { return m_parent; }
|
||||||
|
|
||||||
|
virtual void setName(const std::string& name) { m_name = name; }
|
||||||
|
const std::string& getName() const { return m_name; }
|
||||||
|
|
||||||
|
virtual void setRect(const Rect& rect) { m_rect = rect; }
|
||||||
|
const Rect& getRect() const{ return m_rect; }
|
||||||
|
|
||||||
|
virtual void setActive(bool active) { m_active = active; }
|
||||||
|
bool isActive() const { return m_active; }
|
||||||
|
|
||||||
|
virtual void setVisible(bool visible) { m_visible = visible; }
|
||||||
|
bool isVisible() const { return m_visible; }
|
||||||
|
|
||||||
|
virtual UI::ControlType getControlType() const { return UI::Element; }
|
||||||
|
|
||||||
|
UIElementPtr asUIElement() { return UIElementPtr(this); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI::ControlType m_type;
|
||||||
|
UIContainerPtr m_parent;
|
||||||
|
Rect m_rect;
|
||||||
|
std::string m_name;
|
||||||
|
bool m_visible;
|
||||||
|
bool m_active;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UIELEMENT_H
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uilabel.h"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UILABEL_H
|
||||||
|
#define UILABEL_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uielement.h"
|
||||||
|
|
||||||
|
class UILabel : public UIElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UILabel(UIContainerPtr parent) : UIElement(parent) { }
|
||||||
|
|
||||||
|
virtual UI::ControlType getControlType() const { return UI::Label; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UILABEL_H
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "uipanel.h"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 UIPANEL_H
|
||||||
|
#define UIPANEL_H
|
||||||
|
|
||||||
|
#include "../prerequisites.h"
|
||||||
|
#include "uicontainer.h"
|
||||||
|
|
||||||
|
class UIPanel : public UIContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIPanel(UIContainerPtr parent) : UIContainer(parent) { }
|
||||||
|
|
||||||
|
virtual UI::ControlType getControlType() const { return UI::Panel; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UIPANEL_H
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "size.h"
|
||||||
|
|
||||||
#include <dir.h>
|
#include <dir.h>
|
||||||
#include <physfs.h>
|
#include <physfs.h>
|
||||||
|
@ -411,7 +412,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
win32.height = HIWORD(lParam);
|
win32.height = HIWORD(lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_engine.onResize(LOWORD(lParam), HIWORD(lParam));
|
g_engine.onResize(Size(LOWORD(lParam), HIWORD(lParam)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "size.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -300,7 +301,7 @@ void Platform::poll()
|
||||||
static int oldWidth = -1;
|
static int oldWidth = -1;
|
||||||
static int oldHeight = -1;
|
static int oldHeight = -1;
|
||||||
if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) {
|
if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) {
|
||||||
g_engine.onResize(event.xconfigure.width, event.xconfigure.height);
|
g_engine.onResize(Size(event.xconfigure.width, event.xconfigure.height));
|
||||||
oldWidth = event.xconfigure.width;
|
oldWidth = event.xconfigure.width;
|
||||||
oldHeight = event.xconfigure.height;
|
oldHeight = event.xconfigure.height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "framework/resources.h"
|
#include "framework/resources.h"
|
||||||
#include "framework/platform.h"
|
#include "framework/platform.h"
|
||||||
#include "menustate.h"
|
#include "menustate.h"
|
||||||
|
#include "teststate.h"
|
||||||
|
|
||||||
/// Catches signals so we can exit nicely
|
/// Catches signals so we can exit nicely
|
||||||
void signal_handler(int sig)
|
void signal_handler(int sig)
|
||||||
|
@ -108,8 +109,9 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
// state scope
|
// state scope
|
||||||
{
|
{
|
||||||
std::shared_ptr<MenuState> menuState(new MenuState);
|
std::shared_ptr<MenuState> initialState(new MenuState);
|
||||||
g_engine.changeState(menuState.get());
|
//std::shared_ptr<TestState> initialState(new TestState);
|
||||||
|
g_engine.changeState(initialState.get());
|
||||||
|
|
||||||
Platform::showWindow();
|
Platform::showWindow();
|
||||||
//Platform::hideMouseCursor();
|
//Platform::hideMouseCursor();
|
||||||
|
|
|
@ -31,17 +31,28 @@
|
||||||
#include "framework/rect.h"
|
#include "framework/rect.h"
|
||||||
#include "framework/fonts.h"
|
#include "framework/fonts.h"
|
||||||
#include "framework/input.h"
|
#include "framework/input.h"
|
||||||
|
#include "framework/dispatcher.h"
|
||||||
|
#include "framework/ui/ui.h"
|
||||||
#include "framework/net/connections.h"
|
#include "framework/net/connections.h"
|
||||||
|
|
||||||
TexturePtr background;
|
|
||||||
|
|
||||||
void MenuState::onEnter()
|
void MenuState::onEnter()
|
||||||
{
|
{
|
||||||
m_background = g_textures.get("background.png");
|
m_background = g_textures.get("background.png");
|
||||||
m_background->enableBilinearFilter();
|
m_background->enableBilinearFilter();
|
||||||
|
|
||||||
m_connection = g_connections.createConnection();
|
/*
|
||||||
m_connection->connect("www.google.com.br", 80);
|
UIPanelPtr panel(new UIPanel);
|
||||||
|
panel.setAnchorsLeft(g_gui.left());
|
||||||
|
panel.setAnchorsBottom(g_gui.right());
|
||||||
|
panel.setMarginBottom(10);
|
||||||
|
panel.setMarginLeft(10);
|
||||||
|
panel.setSize(Size(100, 100));
|
||||||
|
|
||||||
|
UIButtonPtr button(new UIButton);
|
||||||
|
button.setAnchorsHorizontalCenter(panel.horizontalCenter());
|
||||||
|
button.setTop
|
||||||
|
g_gui.addChild(panel);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuState::onLeave()
|
void MenuState::onLeave()
|
||||||
|
@ -54,55 +65,27 @@ void MenuState::onClose()
|
||||||
g_engine.stop();
|
g_engine.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int x, y;
|
|
||||||
void MenuState::onInputEvent(InputEvent* event)
|
void MenuState::onInputEvent(InputEvent* event)
|
||||||
{
|
{
|
||||||
static bool moving = false;
|
|
||||||
static int lastX;
|
|
||||||
static int lastY;
|
|
||||||
if(event->type == EV_MOUSE_LDOWN) {
|
|
||||||
moving = true;
|
|
||||||
lastX = event->mouse.x;
|
|
||||||
lastY = event->mouse.y;
|
|
||||||
} else if(event->type == EV_MOUSE_LUP) {
|
|
||||||
moving = false;
|
|
||||||
} else if(event->type == EV_MOUSE_MOVE) {
|
|
||||||
if(moving) {
|
|
||||||
x = lastX - event->mouse.x;
|
|
||||||
y = lastY - event->mouse.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuState::render()
|
void MenuState::render()
|
||||||
{
|
{
|
||||||
|
// render background
|
||||||
static Size minTexCoordsSize(1240, 880);
|
static Size minTexCoordsSize(1240, 880);
|
||||||
const Size& screenSize = g_graphics.getScreenSize();
|
const Size& screenSize = g_graphics.getScreenSize();
|
||||||
const Size& texSize = m_background->getSize();
|
const Size& texSize = m_background->getSize();
|
||||||
|
|
||||||
Size texCoordsSize = screenSize;
|
Size texCoordsSize = screenSize;
|
||||||
if(texCoordsSize < minTexCoordsSize)
|
if(texCoordsSize < minTexCoordsSize)
|
||||||
texCoordsSize.scale(minTexCoordsSize, KEEP_ASPECT_RATIO_BY_EXPANDING);
|
texCoordsSize.scale(minTexCoordsSize, KEEP_ASPECT_RATIO_BY_EXPANDING);
|
||||||
texCoordsSize = texCoordsSize.boundedTo(texSize);
|
texCoordsSize = texCoordsSize.boundedTo(texSize);
|
||||||
|
|
||||||
Rect texCoords(0, 0, texCoordsSize);
|
Rect texCoords(0, 0, texCoordsSize);
|
||||||
texCoords.moveBottomRight(texSize.toPoint());
|
texCoords.moveBottomRight(texSize.toPoint());
|
||||||
g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background.get(), texCoords);
|
g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background.get(), texCoords);
|
||||||
|
|
||||||
static const char *text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
|
|
||||||
"Nulla pulvinar odio ac arcu tempor consequat.\n"
|
|
||||||
"Praesent at enim sapien, at vestibulum ligula.\n"
|
|
||||||
"Aliquam eleifend ante eu sapien vehicula consectetur.\n"
|
|
||||||
"Nunc id ligula ligula, eget vestibulum magna.\n"
|
|
||||||
"In mattis nisi non nisl semper ultricies.";
|
|
||||||
Size textSize = g_defaultFont->calculateTextBoxSize(text);
|
|
||||||
g_defaultFont->renderText(text, Rect(100, 100, textSize.width()-30, textSize.height()-30), ALIGN_CENTER, Point(x,y), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuState::update(int ticks, int elapsedTicks)
|
void MenuState::update(int ticks, int elapsedTicks)
|
||||||
{
|
{
|
||||||
if(m_connection->getLastError()){
|
|
||||||
logError("%s", m_connection->getLastError().message().c_str());
|
|
||||||
m_connection->resetLastError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TexturePtr m_background;
|
TexturePtr m_background;
|
||||||
ConnectionPtr m_connection;
|
|
||||||
int m_connectionTicks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENUSTATE_H
|
#endif // MENUSTATE_H
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "teststate.h"
|
||||||
|
#include "framework/graphics.h"
|
||||||
|
#include "framework/logger.h"
|
||||||
|
#include "framework/engine.h"
|
||||||
|
#include "framework/input.h"
|
||||||
|
|
||||||
|
void TestState::onEnter()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestState::onLeave()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestState::onClose()
|
||||||
|
{
|
||||||
|
g_engine.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestState::onInputEvent(InputEvent* event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestState::render()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestState::update(int ticks, int elapsedTicks)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* The MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||||
|
*
|
||||||
|
* 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 TESTSTATE_H
|
||||||
|
#define TESTSTATE_H
|
||||||
|
|
||||||
|
#include "framework/gamestate.h"
|
||||||
|
|
||||||
|
class TestState : public GameState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestState() { }
|
||||||
|
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual void onLeave();
|
||||||
|
|
||||||
|
virtual void onClose();
|
||||||
|
virtual void onInputEvent(InputEvent *event);
|
||||||
|
|
||||||
|
virtual void render();
|
||||||
|
virtual void update(int ticks, int elapsedTicks);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TESTSTATE_H
|
Loading…
Reference in New Issue