first gui stuff

This commit is contained in:
Eduardo Bart
2011-04-08 02:10:00 -03:00
parent 8a33e0cf19
commit 4c6d1269a0
28 changed files with 863 additions and 63 deletions

View File

@@ -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));
}

View File

@@ -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

View File

@@ -29,7 +29,9 @@
#include "input.h"
#include "configs.h"
#include "gamestate.h"
#include "dispatcher.h"
#include "net/connections.h"
#include "ui/uicontainer.h"
#define MINIMUN_UPDATE_DELAY 50
@@ -40,9 +42,6 @@ void Engine::init()
// initialize stuff
g_graphics.init();
g_fonts.init();
// finally show the window
onResize(Platform::getWindowWidth(), Platform::getWindowHeight());
}
void Engine::terminate()
@@ -72,7 +71,7 @@ void Engine::run()
Point fpsPos(10,10);
while(!m_stopping) {
// fire platform events
// poll platform events
Platform::poll();
// poll network events
@@ -80,6 +79,10 @@ void Engine::run()
// update before redering
ticks = Platform::getTicks();
// poll diaptcher tasks
g_dispatcher.poll(ticks);
updateElapsedTicks = ticks - lastUpdateTicks;
if(updateElapsedTicks >= MINIMUN_UPDATE_DELAY) {
update(ticks, updateElapsedTicks);
@@ -133,6 +136,7 @@ void Engine::render()
g_graphics.beginRender();
if(m_currentState)
m_currentState->render();
g_gui.render();
g_graphics.endRender();
}
@@ -140,6 +144,7 @@ void Engine::update(int ticks, int elapsedTicks)
{
if(m_currentState)
m_currentState->update(ticks, elapsedTicks);
g_gui.update(ticks, elapsedTicks);
}
void Engine::onClose()
@@ -148,13 +153,18 @@ void Engine::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)
{
if(m_currentState)
m_currentState->onInputEvent(event);
// inputs goest to gui first
if(!g_gui.onInputEvent(event)) {
// if gui didnt capture the input then goes to the state
if(m_currentState)
m_currentState->onInputEvent(event);
}
}

View File

@@ -26,6 +26,7 @@
#define ENGINE_H
#include "prerequisites.h"
#include "size.h"
struct InputEvent;
@@ -57,7 +58,7 @@ public:
/// Fired by platform on window close
void onClose();
/// Fired by platform on window resize
void onResize(int width, int height);
void onResize(const Size& size);
/// Fired by platform on mouse/keyboard input
void onInputEvent(InputEvent *event);

View File

@@ -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;
calculateGlyphsPositions(text, ALIGN_TOP_LEFT, &size);

View File

@@ -43,7 +43,7 @@ enum EAlign {
ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT,
ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT
};
class Font
{
public:
@@ -71,12 +71,7 @@ public:
Point *calculateGlyphsPositions(const std::string& text, int align = ALIGN_TOP_LEFT, Size *textBoxSize = NULL);
/// Simulate render and calculate text size
Size calculateTextBoxSize(const std::string& text);
/*
/// Render a text inside a rect
void renderText(const Rect& screenCoords, EAlign align, const std::string& text);
*/
Size calculateTextRectSize(const std::string& text);
private:
int m_lineHeight;

View File

@@ -81,10 +81,9 @@ bool Graphics::isExtensionSupported(const char *extension)
return 0;
}
void Graphics::resize(int width, int height)
void Graphics::resize(const Size& size)
{
m_screenSize.setWidth(width);
m_screenSize.setHeight(height);
m_screenSize = size;
restoreViewport();
}

View File

@@ -44,7 +44,7 @@ public:
bool isExtensionSupported(const char *extension);
/// Called after every window resize
void resize(int width, int height);
void resize(const Size& size);
/// Restore original viewport
void restoreViewport();

37
src/framework/ui/ui.h Normal file
View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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)
{
}

View File

@@ -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

View File

@@ -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());
}

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -23,6 +23,7 @@
#include "platform.h"
#include "engine.h"
#include "size.h"
#include <dir.h>
#include <physfs.h>
@@ -411,7 +412,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
win32.height = HIWORD(lParam);
}
g_engine.onResize(LOWORD(lParam), HIWORD(lParam));
g_engine.onResize(Size(LOWORD(lParam), HIWORD(lParam)));
break;
}
default:

View File

@@ -26,6 +26,7 @@
#include "engine.h"
#include "input.h"
#include "logger.h"
#include "size.h"
#include <sys/time.h>
#include <sys/stat.h>
@@ -300,7 +301,7 @@ void Platform::poll()
static int oldWidth = -1;
static int oldHeight = -1;
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;
oldHeight = event.xconfigure.height;
}