image class

This commit is contained in:
Eduardo Bart 2011-04-08 15:29:59 -03:00
parent 77b31e425a
commit f54ef6401d
13 changed files with 200 additions and 54 deletions

View File

@ -56,6 +56,7 @@ SET(SOURCES
src/teststate.cpp src/teststate.cpp
# framework sources # framework sources
src/framework/image.cpp
src/framework/borderedimage.cpp src/framework/borderedimage.cpp
src/framework/dispatcher.cpp src/framework/dispatcher.cpp
src/framework/framebuffer.cpp src/framework/framebuffer.cpp

View File

@ -28,9 +28,32 @@
#include <GL/gl.h> #include <GL/gl.h>
BorderedImage::BorderedImage(const std::string& textureName) BorderedImage::BorderedImage(TexturePtr texture,
const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center) : Image(texture)
{ {
m_texture = g_textures.get(textureName); setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
}
BorderedImage::BorderedImage(const std::string& texture,
const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center) : Image(texture)
{
setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
} }
void BorderedImage::setTexCoords(const Rect& left, void BorderedImage::setTexCoords(const Rect& left,

View File

@ -26,15 +26,34 @@
#define BORDEREDIMAGE_H #define BORDEREDIMAGE_H
#include "prerequisites.h" #include "prerequisites.h"
#include "image.h"
#include "rect.h" #include "rect.h"
#include "texture.h" #include "texture.h"
class BorderedImage class BorderedImage : public Image
{ {
public: public:
BorderedImage(TexturePtr texture) : m_texture(texture) { } BorderedImage(TexturePtr texture,
BorderedImage(const std::string& textureName); const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center);
BorderedImage(const std::string& texture,
const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center);
void setTexCoords(const Rect& left, void setTexCoords(const Rect& left,
const Rect& right, const Rect& right,
@ -49,8 +68,6 @@ public:
void draw(const Rect& screenCoords); void draw(const Rect& screenCoords);
private: private:
TexturePtr m_texture;
Rect m_leftBorderTexCoords; Rect m_leftBorderTexCoords;
Rect m_rightBorderTexCoords; Rect m_rightBorderTexCoords;
Rect m_topBorderTexCoords; Rect m_topBorderTexCoords;

50
src/framework/image.cpp Normal file
View File

@ -0,0 +1,50 @@
/* 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 "image.h"
#include "graphics.h"
#include "textures.h"
Image::Image(const std::string& texture)
{
m_texture = g_textures.get(texture);
}
Image::Image(const std::string& texture, Rect textureCoords) :
m_textureCoords(textureCoords)
{
m_texture = g_textures.get(texture);
}
void Image::enableBilinearFilter()
{
m_texture->enableBilinearFilter();
}
void Image::draw(const Rect& screenCoords)
{
g_graphics.drawTexturedRect(screenCoords, m_texture.get(), m_textureCoords);
}

50
src/framework/image.h Normal file
View File

@ -0,0 +1,50 @@
/* 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 IMAGE_H
#define IMAGE_H
#include "prerequisites.h"
#include "texture.h"
#include "rect.h"
class Image
{
public:
Image(TexturePtr texture) : m_texture(texture) { }
Image(TexturePtr texture, Rect textureCoords) : m_texture(texture), m_textureCoords(textureCoords) { }
Image(const std::string& texture);
Image(const std::string& texture, Rect textureCoords);
void enableBilinearFilter();
virtual void draw(const Rect& screenCoords);
protected:
TexturePtr m_texture;
Rect m_textureCoords;
};
typedef std::shared_ptr<Image> ImagePtr;
#endif // IMAGE_H

View File

@ -27,10 +27,11 @@
#include "../font.h" #include "../font.h"
UIButton::UIButton(const std::string& text) : UIButton::UIButton(const std::string& text) :
m_text(text) m_text(text),
m_state(UI::ButtonUp)
{ {
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png")); m_imageButtonUp = ImagePtr(new BorderedImage("ui.png",
m_boderedImage->setTexCoords(Rect(45,139,1,18), Rect(45,139,1,18),
Rect(130,139,1,18), Rect(130,139,1,18),
Rect(46,138,84,1), Rect(46,138,84,1),
Rect(46,157,84,1), Rect(46,157,84,1),
@ -38,12 +39,12 @@ UIButton::UIButton(const std::string& text) :
Rect(130,138,1,1), Rect(130,138,1,1),
Rect(45,157,1,1), Rect(45,157,1,1),
Rect(130,157,1,1), Rect(130,157,1,1),
Rect(46,139,84,18)); Rect(46,139,84,18)));
} }
void UIButton::render() void UIButton::render()
{ {
m_boderedImage->draw(m_rect); m_imageButtonUp->draw(m_rect);
g_fonts.get("tibia-8px-antialised")->renderText(m_text, m_rect, ALIGN_CENTER); g_fonts.get("tibia-8px-antialised")->renderText(m_text, m_rect, ALIGN_CENTER);
} }

View File

@ -36,11 +36,15 @@ public:
void render(); void render();
virtual UI::ControlType getControlType() const { return UI::Button; } virtual UI::EControlType getControlType() const { return UI::Button; }
private: private:
std::string m_text; std::string m_text;
BorderedImagePtr m_boderedImage; UI::EButtonState m_state;
ImagePtr m_imageButtonUp;
ImagePtr m_imageButtonDown;
ImagePtr m_imageButtonOver;
}; };
typedef std::shared_ptr<UIButton> UIButtonPtr; typedef std::shared_ptr<UIButton> UIButtonPtr;

View File

@ -26,32 +26,32 @@
#define UICONSTANTS_H #define UICONSTANTS_H
namespace UI { namespace UI {
enum ButtonState enum EButtonState
{ {
Up, ButtonUp,
Down, ButtonDown,
MouseOver ButtonMouseOver
}; };
enum ButtonEvent enum EButtonEvent
{ {
PressUp, ButtonPressUp,
PressDown, ButtonPressDown,
EnterMouseOver, ButtonEnterMouseOver,
LeaveMouseOver ButtonLeaveMouseOver
}; };
enum MessageBoxFlags enum EMessageBoxFlags
{ {
Ok = 1 << 0, MessageBoxOk = 1 << 0,
Cancel = 1 << 1, MessageBoxCancel = 1 << 1,
Yes = 1 << 2, MessageBoxYes = 1 << 2,
No = 1 << 3, MessageBoxNo = 1 << 3,
OkCancel = Ok | Cancel, MessageBoxOkCancel = MessageBoxOk | MessageBoxCancel,
YesNo = Yes | No MessageBoxYesNo = MessageBoxYes | MessageBoxNo
}; };
enum ControlType enum EControlType
{ {
Element, Element,
Container, Container,

View File

@ -52,7 +52,7 @@ public:
virtual void setActiveElement(UIElementPtr activeElement); virtual void setActiveElement(UIElementPtr activeElement);
UIElementPtr getActiveElement() const { return m_activeElement; } UIElementPtr getActiveElement() const { return m_activeElement; }
virtual UI::ControlType getControlType() const { return UI::Container; } virtual UI::EControlType getControlType() const { return UI::Container; }
UIContainerPtr asUIContainer() { return std::static_pointer_cast<UIContainer>(shared_from_this()); } UIContainerPtr asUIContainer() { return std::static_pointer_cast<UIContainer>(shared_from_this()); }

View File

@ -61,12 +61,12 @@ public:
virtual void setVisible(bool visible) { m_visible = visible; } virtual void setVisible(bool visible) { m_visible = visible; }
bool isVisible() const { return m_visible; } bool isVisible() const { return m_visible; }
virtual UI::ControlType getControlType() const { return UI::Element; } virtual UI::EControlType getControlType() const { return UI::Element; }
UIElementPtr asUIElement() { return shared_from_this(); } UIElementPtr asUIElement() { return shared_from_this(); }
protected: protected:
UI::ControlType m_type; UI::EControlType m_type;
UIContainerPtr m_parent; UIContainerPtr m_parent;
Rect m_rect; Rect m_rect;
std::string m_name; std::string m_name;

View File

@ -33,7 +33,7 @@ class UILabel : public UIElement
public: public:
UILabel() { } UILabel() { }
virtual UI::ControlType getControlType() const { return UI::Label; } virtual UI::EControlType getControlType() const { return UI::Label; }
}; };
#endif // UILABEL_H #endif // UILABEL_H

View File

@ -27,8 +27,8 @@
UIPanel::UIPanel() UIPanel::UIPanel()
{ {
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png")); m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png",
m_boderedImage->setTexCoords(Rect(0,214,5,32), Rect(0,214,5,32),
Rect(6,214,5,32), Rect(6,214,5,32),
Rect(43,214,32,5), Rect(43,214,32,5),
Rect(43,220,32,5), Rect(43,220,32,5),
@ -36,7 +36,7 @@ UIPanel::UIPanel()
Rect(49,225,5,5), Rect(49,225,5,5),
Rect(43,230,5,5), Rect(43,230,5,5),
Rect(48,231,5,5), Rect(48,231,5,5),
Rect(11,214,32,32)); Rect(11,214,32,32)));
} }
void UIPanel::render() void UIPanel::render()

View File

@ -36,7 +36,7 @@ public:
void render(); void render();
virtual UI::ControlType getControlType() const { return UI::Panel; } virtual UI::EControlType getControlType() const { return UI::Panel; }
private: private:
BorderedImagePtr m_boderedImage; BorderedImagePtr m_boderedImage;