image class
This commit is contained in:
parent
77b31e425a
commit
f54ef6401d
|
@ -56,6 +56,7 @@ SET(SOURCES
|
|||
src/teststate.cpp
|
||||
|
||||
# framework sources
|
||||
src/framework/image.cpp
|
||||
src/framework/borderedimage.cpp
|
||||
src/framework/dispatcher.cpp
|
||||
src/framework/framebuffer.cpp
|
||||
|
|
|
@ -28,9 +28,32 @@
|
|||
|
||||
#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,
|
||||
|
|
|
@ -26,15 +26,34 @@
|
|||
#define BORDEREDIMAGE_H
|
||||
|
||||
#include "prerequisites.h"
|
||||
|
||||
#include "image.h"
|
||||
#include "rect.h"
|
||||
#include "texture.h"
|
||||
|
||||
class BorderedImage
|
||||
class BorderedImage : public Image
|
||||
{
|
||||
public:
|
||||
BorderedImage(TexturePtr texture) : m_texture(texture) { }
|
||||
BorderedImage(const std::string& textureName);
|
||||
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);
|
||||
|
||||
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,
|
||||
const Rect& right,
|
||||
|
@ -49,8 +68,6 @@ public:
|
|||
void draw(const Rect& screenCoords);
|
||||
|
||||
private:
|
||||
TexturePtr m_texture;
|
||||
|
||||
Rect m_leftBorderTexCoords;
|
||||
Rect m_rightBorderTexCoords;
|
||||
Rect m_topBorderTexCoords;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
@ -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
|
|
@ -27,10 +27,11 @@
|
|||
#include "../font.h"
|
||||
|
||||
UIButton::UIButton(const std::string& text) :
|
||||
m_text(text)
|
||||
m_text(text),
|
||||
m_state(UI::ButtonUp)
|
||||
{
|
||||
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png"));
|
||||
m_boderedImage->setTexCoords(Rect(45,139,1,18),
|
||||
m_imageButtonUp = ImagePtr(new BorderedImage("ui.png",
|
||||
Rect(45,139,1,18),
|
||||
Rect(130,139,1,18),
|
||||
Rect(46,138,84,1),
|
||||
Rect(46,157,84,1),
|
||||
|
@ -38,12 +39,12 @@ UIButton::UIButton(const std::string& text) :
|
|||
Rect(130,138,1,1),
|
||||
Rect(45,157,1,1),
|
||||
Rect(130,157,1,1),
|
||||
Rect(46,139,84,18));
|
||||
Rect(46,139,84,18)));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -36,11 +36,15 @@ public:
|
|||
|
||||
void render();
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Button; }
|
||||
virtual UI::EControlType getControlType() const { return UI::Button; }
|
||||
|
||||
private:
|
||||
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;
|
||||
|
|
|
@ -26,32 +26,32 @@
|
|||
#define UICONSTANTS_H
|
||||
|
||||
namespace UI {
|
||||
enum ButtonState
|
||||
enum EButtonState
|
||||
{
|
||||
Up,
|
||||
Down,
|
||||
MouseOver
|
||||
ButtonUp,
|
||||
ButtonDown,
|
||||
ButtonMouseOver
|
||||
};
|
||||
|
||||
enum ButtonEvent
|
||||
enum EButtonEvent
|
||||
{
|
||||
PressUp,
|
||||
PressDown,
|
||||
EnterMouseOver,
|
||||
LeaveMouseOver
|
||||
ButtonPressUp,
|
||||
ButtonPressDown,
|
||||
ButtonEnterMouseOver,
|
||||
ButtonLeaveMouseOver
|
||||
};
|
||||
|
||||
enum MessageBoxFlags
|
||||
enum EMessageBoxFlags
|
||||
{
|
||||
Ok = 1 << 0,
|
||||
Cancel = 1 << 1,
|
||||
Yes = 1 << 2,
|
||||
No = 1 << 3,
|
||||
OkCancel = Ok | Cancel,
|
||||
YesNo = Yes | No
|
||||
MessageBoxOk = 1 << 0,
|
||||
MessageBoxCancel = 1 << 1,
|
||||
MessageBoxYes = 1 << 2,
|
||||
MessageBoxNo = 1 << 3,
|
||||
MessageBoxOkCancel = MessageBoxOk | MessageBoxCancel,
|
||||
MessageBoxYesNo = MessageBoxYes | MessageBoxNo
|
||||
};
|
||||
|
||||
enum ControlType
|
||||
enum EControlType
|
||||
{
|
||||
Element,
|
||||
Container,
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
virtual void setActiveElement(UIElementPtr 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()); }
|
||||
|
||||
|
|
|
@ -61,12 +61,12 @@ public:
|
|||
virtual void setVisible(bool visible) { m_visible = 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(); }
|
||||
|
||||
protected:
|
||||
UI::ControlType m_type;
|
||||
UI::EControlType m_type;
|
||||
UIContainerPtr m_parent;
|
||||
Rect m_rect;
|
||||
std::string m_name;
|
||||
|
|
|
@ -33,7 +33,7 @@ class UILabel : public UIElement
|
|||
public:
|
||||
UILabel() { }
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Label; }
|
||||
virtual UI::EControlType getControlType() const { return UI::Label; }
|
||||
};
|
||||
|
||||
#endif // UILABEL_H
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
|
||||
UIPanel::UIPanel()
|
||||
{
|
||||
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png"));
|
||||
m_boderedImage->setTexCoords(Rect(0,214,5,32),
|
||||
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png",
|
||||
Rect(0,214,5,32),
|
||||
Rect(6,214,5,32),
|
||||
Rect(43,214,32,5),
|
||||
Rect(43,220,32,5),
|
||||
|
@ -36,7 +36,7 @@ UIPanel::UIPanel()
|
|||
Rect(49,225,5,5),
|
||||
Rect(43,230,5,5),
|
||||
Rect(48,231,5,5),
|
||||
Rect(11,214,32,32));
|
||||
Rect(11,214,32,32)));
|
||||
}
|
||||
|
||||
void UIPanel::render()
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
|
||||
void render();
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Panel; }
|
||||
virtual UI::EControlType getControlType() const { return UI::Panel; }
|
||||
|
||||
private:
|
||||
BorderedImagePtr m_boderedImage;
|
||||
|
|
Loading…
Reference in New Issue