parent
8a33e0cf19
commit
4c6d1269a0
@ -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
|
@ -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
|
@ -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