window ui
This commit is contained in:
parent
a9a110f44b
commit
f2bdc89d8d
|
@ -82,6 +82,8 @@ SET(SOURCES
|
|||
src/framework/ui/uipanel.cpp
|
||||
src/framework/ui/uibutton.cpp
|
||||
src/framework/ui/uilabel.cpp
|
||||
src/framework/ui/uiwindow.cpp
|
||||
src/framework/ui/uiwindowskin.cpp
|
||||
|
||||
# network
|
||||
src/framework/net/connection.cpp
|
||||
|
|
|
@ -76,8 +76,8 @@ void BorderedImage::setTexCoords(const Rect& left,
|
|||
m_bottomRightCornerTexCoords = bottomRight;
|
||||
m_centerTexCoords = center;
|
||||
|
||||
m_cornersSize = Size(topLeft.width() + topRight.width(),
|
||||
topLeft.height() + bottomLeft.height());
|
||||
m_cornersSize = Size(left.width() + right.width(),
|
||||
top.height() + bottom.height());
|
||||
}
|
||||
|
||||
void BorderedImage::draw(const Rect& screenCoords)
|
||||
|
@ -93,7 +93,8 @@ void BorderedImage::draw(const Rect& screenCoords)
|
|||
g_graphics._beginTextureRender(m_texture.get());
|
||||
|
||||
// first the center
|
||||
rectCoords = Rect(screenCoords.topLeft() + m_topLeftCornerTexCoords.size().toPoint(),
|
||||
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width(),
|
||||
screenCoords.top() + m_topBorderTexCoords.height(),
|
||||
centerSize);
|
||||
g_graphics._drawRepeatedTexturedRect(rectCoords, m_centerTexCoords, textureSize);
|
||||
|
||||
|
@ -124,7 +125,7 @@ void BorderedImage::draw(const Rect& screenCoords)
|
|||
g_graphics._drawRepeatedTexturedRect(rectCoords, m_leftBorderTexCoords, textureSize);
|
||||
|
||||
// right
|
||||
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width() + centerSize.width(),
|
||||
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width() + centerSize.width(),
|
||||
screenCoords.top() + m_topRightCornerTexCoords.height(),
|
||||
m_rightBorderTexCoords.width(),
|
||||
centerSize.height());
|
||||
|
@ -132,7 +133,7 @@ void BorderedImage::draw(const Rect& screenCoords)
|
|||
|
||||
// bottom left corner
|
||||
rectCoords = Rect(screenCoords.left(),
|
||||
screenCoords.top() + m_topLeftCornerTexCoords.height() + centerSize.height(),
|
||||
screenCoords.top() + m_topBorderTexCoords.height() + centerSize.height(),
|
||||
m_bottomLeftCornerTexCoords.size());
|
||||
g_graphics._drawTexturedRect(rectCoords, m_bottomLeftCornerTexCoords, textureSize);
|
||||
|
||||
|
@ -149,5 +150,6 @@ void BorderedImage::draw(const Rect& screenCoords)
|
|||
m_bottomRightCornerTexCoords.size());
|
||||
g_graphics._drawTexturedRect(rectCoords, m_bottomRightCornerTexCoords, textureSize);
|
||||
|
||||
//g_graphics._drawBoundingRect(screenCoords, Color(0xFF00FF00), 1);
|
||||
g_graphics._endTextureRender();
|
||||
}
|
||||
|
|
|
@ -28,12 +28,47 @@
|
|||
#include "graphics.h"
|
||||
|
||||
Font::Font() :
|
||||
m_lineHeight(14),
|
||||
m_cursorSize(14),
|
||||
m_color(0xFFFFFFFF)
|
||||
m_glyphHeight(10),
|
||||
m_topMargin(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Font::calculateGlyphsWidthsAutomatically(const Size& glyphSize)
|
||||
{
|
||||
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
|
||||
uchar *texturePixels = m_texture->getPixels();
|
||||
|
||||
// small AI to auto calculate pixels widths
|
||||
for(int glyph = 32; glyph< 256; ++glyph) {
|
||||
Rect glyphCoords(((glyph - 32) % numHorizontalGlyphs) * glyphSize.width(),
|
||||
((glyph - 32) / numHorizontalGlyphs) * glyphSize.height(),
|
||||
glyphSize.width(),
|
||||
m_glyphHeight);
|
||||
int width = glyphSize.width();
|
||||
for(int x = glyphCoords.left() + 2; x <= glyphCoords.right(); ++x) {
|
||||
bool allAlpha = true;
|
||||
|
||||
// check if all vertical pixels are alpha
|
||||
for(int y = glyphCoords.top(); y <= glyphCoords.bottom(); ++y) {
|
||||
if(texturePixels[(y * m_texture->getSize().width() * 4) + (x*4) + 3] != 0) {
|
||||
allAlpha = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if all pixels were alpha we found the width
|
||||
if(allAlpha) {
|
||||
width = x - glyphCoords.left();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// store glyph size
|
||||
m_glyphsSize[glyph].setWidth(width);
|
||||
}
|
||||
|
||||
delete[] texturePixels;
|
||||
}
|
||||
|
||||
bool Font::load(const std::string& file)
|
||||
{
|
||||
std::string fileContents = g_resources.loadTextFile(file);
|
||||
|
@ -45,10 +80,7 @@ bool Font::load(const std::string& file)
|
|||
std::istringstream fin(fileContents);
|
||||
|
||||
std::string textureName;
|
||||
int numHorizontalGlyphs;
|
||||
int firstGlyph;
|
||||
Size glyphSize;
|
||||
Size textureSize;
|
||||
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
|
@ -56,10 +88,9 @@ bool Font::load(const std::string& file)
|
|||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
doc["line height"] >> m_lineHeight;
|
||||
doc["cursor size"] >> m_cursorSize;
|
||||
doc["color"] >> m_color;
|
||||
doc["first glyph"] >> firstGlyph;
|
||||
doc["glyph height"] >> m_glyphHeight;
|
||||
doc["glyph spacing"] >> m_glyphSpacing;
|
||||
doc["top margin"] >> m_topMargin;
|
||||
doc["image glyph size"] >> glyphSize;
|
||||
doc["image"] >> textureName;
|
||||
|
||||
|
@ -69,25 +100,33 @@ bool Font::load(const std::string& file)
|
|||
return false;
|
||||
}
|
||||
|
||||
textureSize = m_texture->getSize();
|
||||
numHorizontalGlyphs = textureSize.width() / glyphSize.width();
|
||||
// set glyphs height
|
||||
for(int glyph = 32; glyph< 256; ++glyph) {
|
||||
m_glyphsSize[glyph].setHeight(m_glyphHeight);
|
||||
}
|
||||
|
||||
calculateGlyphsWidthsAutomatically(glyphSize);
|
||||
|
||||
// read custom widths
|
||||
if(doc.FindValue("glyph widths")) {
|
||||
const YAML::Node& widthsNode = doc["glyph widths"];
|
||||
for(auto it = widthsNode.begin(); it != widthsNode.end(); ++it) {
|
||||
int glyph, glyphWidth;
|
||||
it.first() >> glyph;
|
||||
it.second() >> glyphWidth;
|
||||
|
||||
// calculate glyph texture coords
|
||||
m_glyphsTextureCoords[glyph].setRect(((glyph - firstGlyph) % numHorizontalGlyphs) * glyphSize.width(),
|
||||
((glyph - firstGlyph) / numHorizontalGlyphs) * glyphSize.height(),
|
||||
glyphWidth,
|
||||
glyphSize.height());
|
||||
|
||||
// store glyph size
|
||||
m_glyphsSize[glyph].setHeight(glyphSize.height());
|
||||
m_glyphsSize[glyph].setWidth(glyphWidth);
|
||||
}
|
||||
}
|
||||
|
||||
// calculate glyphs texture coords
|
||||
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width();
|
||||
for(int glyph = 32; glyph< 256; ++glyph) {
|
||||
m_glyphsTextureCoords[glyph].setRect(((glyph - 32) % numHorizontalGlyphs) * glyphSize.width(),
|
||||
((glyph - 32) / numHorizontalGlyphs) * glyphSize.height(),
|
||||
m_glyphsSize[glyph].width(),
|
||||
m_glyphsSize[glyph].height());
|
||||
}
|
||||
|
||||
} catch (YAML::ParserException& e) {
|
||||
logError("Malformed font file \"%s\"", file.c_str());
|
||||
return false;
|
||||
|
@ -107,6 +146,7 @@ void Font::renderText(const std::string& text,
|
|||
void Font::renderText(const std::string& text,
|
||||
const Rect& screenCoords,
|
||||
int align,
|
||||
const Color& color,
|
||||
const Point& startInternalPos,
|
||||
bool debug)
|
||||
{
|
||||
|
@ -115,7 +155,7 @@ void Font::renderText(const std::string& text,
|
|||
return;
|
||||
|
||||
// begin texture rendering
|
||||
g_graphics.setColor(m_color);
|
||||
g_graphics.setColor(color);
|
||||
g_graphics._beginTextureRender(m_texture.get());
|
||||
|
||||
const Size& textureSize = m_texture->getSize();
|
||||
|
@ -189,6 +229,8 @@ void Font::renderText(const std::string& text,
|
|||
|
||||
// render glyph
|
||||
g_graphics._drawTexturedRect(glyphScreenCoords, glyphTextureCoords, textureSize);
|
||||
|
||||
//g_graphics._drawBoundingRect(glyphScreenCoords, Color(0xFF0000FF));
|
||||
}
|
||||
|
||||
// end texture redering
|
||||
|
@ -196,7 +238,7 @@ void Font::renderText(const std::string& text,
|
|||
g_graphics.resetColor();
|
||||
|
||||
if(debug)
|
||||
g_graphics.drawBoundingRect(screenCoords.expanded(1), Color(0xFF00FF00), 1);
|
||||
g_graphics.drawBoundingRect(screenCoords.expanded(1), Color(0xFF00FF00));
|
||||
}
|
||||
|
||||
Point* Font::calculateGlyphsPositions(const std::string& text, int align, Size *textBoxSize)
|
||||
|
@ -222,13 +264,13 @@ Point* Font::calculateGlyphsPositions(const std::string& text, int align, Size *
|
|||
if(glyph == (uchar)'\n') {
|
||||
lineWidths[++lines] = 0;
|
||||
} else if(glyph >= 32) {
|
||||
lineWidths[lines] += m_glyphsSize[glyph].width();
|
||||
lineWidths[lines] += m_glyphsSize[glyph].width() + m_glyphSpacing.width();
|
||||
maxLineWidth = std::max(maxLineWidth, lineWidths[lines]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Point virtualPos;
|
||||
Point virtualPos(0, m_topMargin);
|
||||
lines = 0;
|
||||
for(i = 0; i < numGlyphs; ++i) {
|
||||
glyph = (int)text[i];
|
||||
|
@ -239,7 +281,7 @@ Point* Font::calculateGlyphsPositions(const std::string& text, int align, Size *
|
|||
// new line or first glyph
|
||||
if(glyph == (uchar)'\n' || i == 0) {
|
||||
if(glyph == (uchar)'\n') {
|
||||
virtualPos.y += m_lineHeight;
|
||||
virtualPos.y += m_glyphsSize[glyph].height() + m_glyphSpacing.height();
|
||||
lines++;
|
||||
}
|
||||
|
||||
|
@ -255,13 +297,13 @@ Point* Font::calculateGlyphsPositions(const std::string& text, int align, Size *
|
|||
|
||||
// render only if the glyph is valid
|
||||
if(glyph >= 32 && glyph != (uchar)'\n') {
|
||||
virtualPos.x += m_glyphsSize[glyph].width();
|
||||
virtualPos.x += m_glyphsSize[glyph].width() + m_glyphSpacing.width();
|
||||
}
|
||||
}
|
||||
|
||||
if(textBoxSize) {
|
||||
textBoxSize->setWidth(maxLineWidth);
|
||||
textBoxSize->setHeight(virtualPos.y + m_lineHeight);
|
||||
textBoxSize->setHeight(virtualPos.y + m_glyphHeight);
|
||||
}
|
||||
|
||||
return (Point *)glyphsPositions;
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
void renderText(const std::string& text,
|
||||
const Rect& screenCoords,
|
||||
int align = ALIGN_TOP_LEFT,
|
||||
const Color& color = Color(0xFFFFFFFF),
|
||||
const Point& startInternalPos = Point(),
|
||||
bool debug = false);
|
||||
|
||||
|
@ -74,9 +75,11 @@ public:
|
|||
Size calculateTextRectSize(const std::string& text);
|
||||
|
||||
private:
|
||||
int m_lineHeight;
|
||||
int m_cursorSize;
|
||||
Color m_color;
|
||||
void calculateGlyphsWidthsAutomatically(const Size& glyphSize);
|
||||
|
||||
int m_glyphHeight;
|
||||
int m_topMargin;
|
||||
Size m_glyphSpacing;
|
||||
TexturePtr m_texture;
|
||||
Rect m_glyphsTextureCoords[256];
|
||||
Size m_glyphsSize[256];
|
||||
|
|
|
@ -148,6 +148,9 @@ void Graphics::_endTextureRender()
|
|||
|
||||
void Graphics::drawTexturedRect(const Rect& screenCoords, const Texture *texture, const Rect& textureCoords)
|
||||
{
|
||||
if(screenCoords.size().isEmpty())
|
||||
return;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
|
||||
glBegin(GL_QUADS);
|
||||
_drawTexturedRect(screenCoords, textureCoords, texture->getSize());
|
||||
|
@ -156,6 +159,9 @@ void Graphics::drawTexturedRect(const Rect& screenCoords, const Texture *texture
|
|||
|
||||
void Graphics::_drawTexturedRect(const Rect& screenCoords, const Rect& textureCoords, const Size& textureSize)
|
||||
{
|
||||
if(screenCoords.size().isEmpty())
|
||||
return;
|
||||
|
||||
// rect correction for opengl
|
||||
int right = screenCoords.right() + 1;
|
||||
int bottom = screenCoords.bottom() + 1;
|
||||
|
@ -182,6 +188,9 @@ void Graphics::_drawTexturedRect(const Rect& screenCoords, const Rect& textureCo
|
|||
|
||||
void Graphics::drawRepeatedTexturedRect(const Rect& screenCoords, const Texture* texture, const Rect& texCoords)
|
||||
{
|
||||
if(screenCoords.size().isEmpty())
|
||||
return;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
|
||||
glBegin(GL_QUADS);
|
||||
_drawRepeatedTexturedRect(screenCoords, texCoords, texture->getSize());
|
||||
|
@ -190,6 +199,9 @@ void Graphics::drawRepeatedTexturedRect(const Rect& screenCoords, const Texture*
|
|||
|
||||
void Graphics::_drawRepeatedTexturedRect(const Rect& screenCoords, const Rect& textureCoords, const Size& textureSize)
|
||||
{
|
||||
if(screenCoords.size().isEmpty())
|
||||
return;
|
||||
|
||||
// render many repeated texture rects
|
||||
Rect virtualScreenCoords(0,0,screenCoords.size());
|
||||
for(int y = 0; y <= virtualScreenCoords.height(); y += textureCoords.height()) {
|
||||
|
@ -216,6 +228,9 @@ void Graphics::_drawRepeatedTexturedRect(const Rect& screenCoords, const Rect& t
|
|||
|
||||
void Graphics::drawColoredRect(const Rect& screenCoords, const Color& color)
|
||||
{
|
||||
if(screenCoords.size().isEmpty())
|
||||
return;
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
setColor(color);
|
||||
|
|
|
@ -72,3 +72,11 @@ void Texture::enableBilinearFilter()
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
uchar *Texture::getPixels()
|
||||
{
|
||||
uchar *pixels = new uchar[m_size.area()*4];
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
return pixels;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
|
||||
const Size& getSize() const { return m_size; }
|
||||
uint getTextureId() const { return m_textureId; }
|
||||
uchar *getPixels();
|
||||
|
||||
private:
|
||||
uint m_textureId;
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
|
||||
#include "uiconstants.h"
|
||||
#include "uielement.h"
|
||||
#include "uielementskin.h"
|
||||
#include "uicontainer.h"
|
||||
#include "uipanel.h"
|
||||
#include "uibutton.h"
|
||||
#include "uilabel.h"
|
||||
#include "uiskins.h"
|
||||
#include "uiwindow.h"
|
||||
|
||||
#endif // UI_H
|
||||
|
|
|
@ -30,7 +30,7 @@ void UIButton::render()
|
|||
{
|
||||
UIElement::render();
|
||||
|
||||
g_fonts.get("tibia-8px-antialised")->renderText(m_text, getRect(), ALIGN_CENTER);
|
||||
g_fonts.get("tibia-8px-antialised")->renderText(m_text, getRect(), ALIGN_CENTER, Color(0xFFEEEEEE));
|
||||
}
|
||||
|
||||
bool UIButton::onInputEvent(const InputEvent& event)
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
void UIButtonSkin::draw(UIElement *element)
|
||||
{
|
||||
|
||||
UIButton *button = static_cast<UIButton*>(element);
|
||||
|
||||
if(button->getState() == UI::ButtonDown && m_buttonDownImage) {
|
||||
|
|
|
@ -47,14 +47,23 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
|
|||
if(node.FindValue("bordered image")) {
|
||||
const YAML::Node& child = node["bordered image"];
|
||||
Rect left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center;
|
||||
if(child.FindValue("left border"))
|
||||
child["left border"] >> left;
|
||||
if(child.FindValue("right border"))
|
||||
child["right border"] >> right;
|
||||
if(child.FindValue("top border"))
|
||||
child["top border"] >> top;
|
||||
if(child.FindValue("bottom border"))
|
||||
child["bottom border"] >> bottom;
|
||||
if(child.FindValue("top left corner"))
|
||||
child["top left corner"] >> topLeft;
|
||||
if(child.FindValue("top right corner"))
|
||||
child["top right corner"] >> topRight;
|
||||
if(child.FindValue("bottom left corner"))
|
||||
child["bottom left corner"] >> bottomLeft;
|
||||
if(child.FindValue("bottom right corner"))
|
||||
child["bottom right corner"] >> bottomRight;
|
||||
if(child.FindValue("center"))
|
||||
child["center"] >> center;
|
||||
|
||||
TexturePtr texture;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "../textures.h"
|
||||
#include "uielementskin.h"
|
||||
#include "uibuttonskin.h"
|
||||
#include "uiwindowskin.h"
|
||||
|
||||
UISkins g_uiSkins;
|
||||
|
||||
|
@ -79,6 +80,18 @@ bool UISkins::load(const std::string& file)
|
|||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const YAML::Node& node = doc["windows"];
|
||||
for(auto it = node.begin(); it != node.end(); ++it) {
|
||||
std::string name;
|
||||
it.first() >> name;
|
||||
|
||||
UIWindowSkin *skin = new UIWindowSkin(name, UI::Window);
|
||||
skin->load(it.second());
|
||||
m_elementSkins.push_back(skin);
|
||||
}
|
||||
}
|
||||
} catch (YAML::ParserException& e) {
|
||||
logError("Malformed font file \"%s\"", file.c_str());
|
||||
return false;
|
||||
|
|
|
@ -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 "uiwindow.h"
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/* 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 UIWINDOW_H
|
||||
#define UIWINDOW_H
|
||||
|
||||
#include "../prerequisites.h"
|
||||
#include "uicontainer.h"
|
||||
|
||||
class UIWindow : public UIContainer
|
||||
{
|
||||
public:
|
||||
UIWindow(const std::string& title) :
|
||||
UIContainer(UI::Window),
|
||||
m_title(title) { }
|
||||
|
||||
const std::string& getTitle() const { return m_title; }
|
||||
|
||||
private:
|
||||
std::string m_title;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||
|
||||
#endif // UIWINDOW_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 "uiwindowskin.h"
|
||||
#include "uiwindow.h"
|
||||
#include "../fonts.h"
|
||||
|
||||
void UIWindowSkin::draw(UIElement* element)
|
||||
{
|
||||
UIElementSkin::draw(element);
|
||||
|
||||
UIWindow *window = static_cast<UIWindow*>(element);
|
||||
|
||||
Rect headRect = window->getRect();
|
||||
Rect bodyRect = window->getRect();
|
||||
|
||||
headRect.setHeight(m_headHeight);
|
||||
bodyRect.setTop(headRect.bottom() + 1);
|
||||
|
||||
m_headImage->draw(headRect);
|
||||
m_titleFont->renderText(window->getTitle(),
|
||||
headRect,
|
||||
ALIGN_CENTER,
|
||||
Color(0xFF8F8F8F));
|
||||
|
||||
m_bodyImage->draw(bodyRect);
|
||||
}
|
||||
|
||||
void UIWindowSkin::load(const YAML::Node& node)
|
||||
{
|
||||
UIElementSkin::load(node);
|
||||
|
||||
node["head"]["height"] >> m_headHeight;
|
||||
m_headImage = loadImage(node["head"]);
|
||||
m_bodyImage = loadImage(node["body"]);
|
||||
|
||||
std::string fontName;
|
||||
node["head"]["font"] >> fontName;
|
||||
m_titleFont = g_fonts.get(fontName);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/* 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 UIWINDOWSKIN_H
|
||||
#define UIWINDOWSKIN_H
|
||||
|
||||
#include "../prerequisites.h"
|
||||
#include "uiconstants.h"
|
||||
#include "uielementskin.h"
|
||||
#include "../font.h"
|
||||
|
||||
class UIWindowSkin : public UIElementSkin
|
||||
{
|
||||
public:
|
||||
UIWindowSkin(const std::string& name, UI::EElementType elementType) :
|
||||
UIElementSkin(name, elementType) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void draw(UIElement *element);
|
||||
|
||||
private:
|
||||
ImagePtr m_headImage;
|
||||
ImagePtr m_bodyImage;
|
||||
Font *m_titleFont;
|
||||
int m_headHeight;
|
||||
};
|
||||
|
||||
#endif // UIWINDOWSKIN_H
|
|
@ -52,8 +52,8 @@ void signal_handler(int sig)
|
|||
void setDefaultConfigs()
|
||||
{
|
||||
// default size
|
||||
int defWidth = 640;
|
||||
int defHeight = 480;
|
||||
int defWidth = 550;
|
||||
int defHeight = 450;
|
||||
|
||||
// init on screen center
|
||||
g_configs.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
|
||||
|
@ -101,7 +101,7 @@ int main(int argc, const char *argv[])
|
|||
// create the window
|
||||
Platform::createWindow(g_configs.getInteger("window x"), g_configs.getInteger("window y"),
|
||||
g_configs.getInteger("window width"), g_configs.getInteger("window height"),
|
||||
640, 480,
|
||||
550, 450,
|
||||
g_configs.getBoolean("window maximized"));
|
||||
Platform::setWindowTitle("OTClient");
|
||||
//Platform::setVsync();
|
||||
|
|
|
@ -91,6 +91,7 @@ void MenuState::createMainMenu()
|
|||
m_menuPanel->anchorBottom(g_ui->bottom());
|
||||
m_menuPanel->setSize(Size(118, 172));
|
||||
m_menuPanel->setMargin(0, 60, 70, 0);
|
||||
g_ui->addChild(m_menuPanel);
|
||||
|
||||
button = UIButtonPtr(new UIButton("Enter Game"));
|
||||
button->anchorTop(m_menuPanel->top());
|
||||
|
@ -123,5 +124,9 @@ void MenuState::createMainMenu()
|
|||
button->setMargin(y += 30);
|
||||
m_menuPanel->addChild(button);
|
||||
|
||||
g_ui->addChild(m_menuPanel);
|
||||
UIWindowPtr window(new UIWindow("Enter Game"));
|
||||
window->setSize(Size(236, 178));
|
||||
window->anchorHorizontalCenter(g_ui->horizontalCenter());
|
||||
window->anchorVerticalCenter(g_ui->verticalCenter());
|
||||
g_ui->addChild(window);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue