make styles closer to CSS syntax

This commit is contained in:
Eduardo Bart 2011-11-17 19:41:02 -02:00
parent 55136fe866
commit 5c654f685c
35 changed files with 290 additions and 269 deletions

6
TODO
View File

@ -6,11 +6,11 @@ left panel with dragging windows
console history
console text selection
console scrolling
padding
scrollbar
make otui syntax more like css
a real working border and background property in otui
load state styles in order
grid layout
fix moving windows and tooltips conflicts
todo display otclient icon in window bar
todo display otclient icon in window bar
remake otui styles states system
padding

View File

@ -5,8 +5,7 @@ local about
-- public functions
function About.create()
about = UI.display('about.otui')
UI.root:lockChild(about)
about = UI.display('about.otui', { locked = true })
end
function About.destroy()
@ -16,4 +15,4 @@ end
function About.openWebpage()
displayErrorBox("Error", "Not implemented yet")
end
end

View File

@ -7,55 +7,55 @@ MainWindow
size: 208 129
anchors.left: parent.left
anchors.top: parent.top
margin.top: 32
margin.left: 18
margin-top: 32
margin-left: 18
Label
align: center
text-align: center
text: |-
OTClient
Version 0.2.0
Created by edubart
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin.top: 20
margin-top: 20
HorizontalSeparator
size: 190 2
anchors.left: parent.left
anchors.top: parent.top
margin.top: 83
margin.left: 9
margin-top: 83
margin-left: 9
Label
text: Official Website
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.bottom: 14
margin.left: 9
margin-bottom: 14
margin-left: 9
Button
text: Github Page
size: 88 24
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 9
margin.right: 9
margin-bottom: 9
margin-right: 9
@onClick: About.openWebpage()
HorizontalSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 40
margin.left: 13
margin.right: 13
margin-bottom: 40
margin-left: 13
margin-right: 13
Button
text: Ok
size: 46 24
anchors.left: parent.left
anchors.top: parent.top
margin.top: 191
margin.left: 188
margin-top: 191
margin-left: 188
@onClick: About.destroy()

View File

@ -8,5 +8,5 @@ Panel
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.top: 1
margin-top: 1
focusable: false

View File

@ -15,13 +15,13 @@ Panel
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: chatLineEdit.top
margin.right: 6
margin.left: 6
margin.bottom: 2
margin.top: 6
margin-right: 6
margin-left: 6
margin-bottom: 2
margin-top: 6
layout:
type: verticalBox
align bottom: true
align-bottom: true
focusable: false
LineEdit
@ -29,7 +29,7 @@ Panel
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.right: 6
margin.left: 6
margin.bottom: 6
always focused: true
margin-right: 6
margin-left: 6
margin-bottom: 6
always-active: true

View File

@ -15,15 +15,15 @@ RectPanel
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: commandSymbolLabel.top
margin.left: 2
margin-left: 2
UILabel
id: commandSymbolLabel
size: 20 16
size fixed: true
fixed-size: true
anchors.bottom: parent.bottom
anchors.left: parent.left
margin.left: 2
margin-left: 2
font: terminus-14px-bold
text: >>
@ -33,5 +33,5 @@ RectPanel
anchors.bottom: parent.bottom
anchors.left: commandSymbolLabel.right
anchors.right: parent.right
margin.left: 5
margin-left: 5
font: terminus-14px-bold

View File

@ -1,8 +1,8 @@
Font
name: terminus-14px-bold
height: 16
top margin: 2
y-offset: 2
texture: terminus-14px-bold.png
glyph size: 16 16
fixed glyph width: 8
glyph-size: 16 16
fixed-glyph-width: 8

View File

@ -2,7 +2,7 @@ Font
name: verdana-11px-antialised
texture: verdana-11px-antialised.png
height: 14
glyph size: 16 16
glyph-size: 16 16
glyph widths:
glyph-widths:
32: 4

View File

@ -2,7 +2,7 @@ Font
name: verdana-11px-monochrome
texture: verdana-11px-monochrome.png
height: 14
glyph size: 16 16
glyph-size: 16 16
glyph widths:
glyph-widths:
32: 2

View File

@ -2,9 +2,9 @@ Font
name: verdana-11px-rounded
texture: verdana-11px-rounded.png
height: 14
glyph size: 16 16
glyph-size: 16 16
glyph widths:
glyph-widths:
32: 4
33: 4
34: 7

View File

@ -54,7 +54,7 @@ TopButton < UIButton
MenuButton < UIButton
color: white
size: 40 18
align: center
text-align: center
border-image:
source: /core_styles/images/menu.png
size: 64 24

View File

@ -2,7 +2,7 @@ LineEdit < UILineEdit
font: verdana-11px-antialised
color: #aaaaaa
size: 86 20
text margin: 3
text-margin: 3
border-image:
source: /core_styles/images/panel_flat.png
border: 1
@ -11,4 +11,4 @@ LineEdit < UILineEdit
color: #aaaaaa88
PasswordLineEdit < LineEdit
text hidden: true
text-hidden: true

View File

@ -4,9 +4,9 @@ Window < UIWindow
opacity: 255
color: white
background-color: white
head height: 20
head text align: center
move policy: free
head-height: 20
head-text-align: center
move-policy: free
stackable: true
border-image:
source: /core_styles/images/window.png
@ -22,12 +22,12 @@ Window < UIWindow
MiniWindow < UIWindow
font: verdana-11px-antialised
size: 192 200
head height: 25
head text align: center
margin.top: 10
margin.left: 6
margin.right: 6
move policy: free updated
head-height: 25
head-text-align: center
margin-top: 10
margin-left: 6
margin-right: 6
move-policy: free updated
border-image:
source: /core_styles/images/mini_window.png
border: 4

View File

@ -4,9 +4,9 @@ CharacterListLabel < Label
background-color: #00000000
offset: 2 0
focusable: true
margin.left: 1
margin.right: 1
margin.top: 1
margin-left: 1
margin-right: 1
margin-top: 1
$focus:
background-color: #ffffff22
@ -16,17 +16,17 @@ MainWindow
id: charactersWindow
title: Character List
size: 250 248
onEnter: CharacterList.doLogin()
onEscape: CharacterList.destroy()
@onEnter: CharacterList.doLogin()
@onEscape: CharacterList.destroy()
TextList
id: characterList
anchors.fill: parent
anchors.bottom: next.top
margin.top: 30
margin.bottom: 5
margin.left: 16
margin.right: 16
margin-top: 30
margin-bottom: 5
margin-left: 16
margin-right: 16
Label
id: accountStatusLabel
@ -36,17 +36,17 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: separator.top
margin.left: 16
margin.bottom: 5
margin-left: 16
margin-bottom: 5
HorizontalSeparator
id: separator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
margin.left: 16
margin.right: 16
margin.bottom: 10
margin-left: 16
margin-right: 16
margin-bottom: 10
//CheckBox
// id: charAutoLoginBox
@ -55,9 +55,9 @@ MainWindow
// anchors.left: parent.left
// anchors.right: parent.right
// anchors.bottom: next.top
// margin.bottom: 6
// margin.left: 18
// margin.right: 18
// margin-bottom: 6
// margin-left: 18
// margin-right: 18
Button
id: buttonOk
@ -65,8 +65,8 @@ MainWindow
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: CharacterList.doLogin()
Button
@ -75,6 +75,6 @@ MainWindow
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: CharacterList.destroy()

View File

@ -2,39 +2,39 @@ MainWindow
id: enterGame
title: Enter Game
size: 236 240
onEnter: EnterGame.doLogin()
onEscape: EnterGame.hide()
@onEnter: EnterGame.doLogin()
@onEscape: EnterGame.hide()
LargerLabel
text: Account name
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 28
margin-left: 18
margin-top: 28
LineEdit
id: accountNameLineEdit
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 2
margin.left: 18
margin.right: 18
margin-top: 2
margin-left: 18
margin-right: 18
LargerLabel
text: Password
anchors.left: prev.left
anchors.top: prev.bottom
margin.top: 8
margin-top: 8
PasswordLineEdit
id: accountPasswordLineEdit
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 2
margin.left: 18
margin.right: 18
margin-top: 2
margin-left: 18
margin-right: 18
LargerLabel
id: serverLabel
@ -42,7 +42,7 @@ MainWindow
text: Server
anchors.left: prev.left
anchors.top: prev.bottom
margin.top: 8
margin-top: 8
LineEdit
id: serverHostLineEdit
@ -50,7 +50,7 @@ MainWindow
anchors.left: serverLabel.left
anchors.right: serverLabel.right
anchors.top: serverLabel.bottom
margin.top: 2
margin-top: 2
LargerLabel
id: portLabel
@ -58,7 +58,7 @@ MainWindow
width: 50
anchors.left: serverLabel.right
anchors.top: serverLabel.top
margin.left: 10
margin-left: 10
LineEdit
id: serverPortLineEdit
@ -66,7 +66,7 @@ MainWindow
anchors.left: portLabel.left
anchors.right: portLabel.right
anchors.top: portLabel.bottom
margin.top: 2
margin-top: 2
CheckBox
id: rememberPasswordBox
@ -75,9 +75,9 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 10
margin.left: 18
margin.right: 18
margin-top: 10
margin-left: 18
margin-right: 18
@onCheckChange: |
function(self, checked)
self:getParent():getChildById('autoLoginBox'):setEnabled(checked)
@ -91,17 +91,17 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 8
margin.left: 18
margin.right: 18
margin-top: 8
margin-left: 18
margin-right: 18
Button
text: Ok
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: EnterGame.doLogin()
Button
@ -109,6 +109,6 @@ MainWindow
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: EnterGame.hide()

View File

@ -5,7 +5,7 @@ HealthBar < UIProgressBar
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
ManaBar < UIProgressBar
color: black
height: 15
@ -16,27 +16,27 @@ ManaBar < UIProgressBar
HealthLabel < Label
color: white
align: center
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
margin.top: 2
margin-top: 2
ManaLabel < Label
color: white
align: center
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: -1
margin-bottom: -1
UIWindow
id: healthManaPanel
width: 192
margin.top: 10
margin.left: 6
margin.right: 6
move policy: free updated
margin-top: 10
margin-left: 6
margin-right: 6
move-policy: free updated

View File

@ -1,9 +1,9 @@
UIWindow
width: 192
margin.top: 10
margin.left: 6
margin.right: 6
move policy: free updated
margin-top: 10
margin-left: 6
margin-right: 6
move-policy: free updated
Item
id: head
@ -15,82 +15,82 @@ UIWindow
id: armor
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: legs
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: feet
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: necklace
anchors.top: parent.top
anchors.right: head.left
margin.top: 10
margin.right: 5
margin-top: 10
margin-right: 5
Item
id: left
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: ring
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: backpack
anchors.top: parent.top
anchors.left: head.right
margin.top: 10
margin.left: 5
margin-top: 10
margin-left: 5
Item
id: right
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Item
id: ammo
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin.top: 5
margin-top: 5
Label
id: soul
anchors.top: ring.bottom
anchors.bottom: feet.bottom
anchors.left: ring.left
anchors.right: ring.right
margin.top: 5
align: center
margin-top: 5
text-align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 1
Label
id: capacity
anchors.top: ammo.bottom
anchors.bottom: feet.bottom
anchors.left: ammo.left
anchors.right: ammo.right
margin.top: 5
align: center
margin-top: 5
text-align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 1

View File

@ -8,14 +8,14 @@ Window
id: messageBoxLabel
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin.top: 27
margin.bottom : 27
margin-top: 27
margin-bottom : 27
Button
id: messageBoxRightButton
anchors.bottom: parent.bottom
anchors.right: parent.right
margin.right: 10
margin.bottom: 10
margin-right: 10
margin-bottom: 10
width: 64
visible: true

View File

@ -10,9 +10,9 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
margin.top: 28
margin.left: 18
margin.right: 18
margin-top: 28
margin-left: 18
margin-right: 18
CheckBox
id: fpsCheckBox
@ -20,15 +20,15 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 10
margin.left: 18
margin.right: 18
margin-top: 10
margin-left: 18
margin-right: 18
Button
text: Ok
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.right: 10
margin.bottom: 10
margin-right: 10
margin-bottom: 10
@onClick: Options.destroy()

View File

@ -9,8 +9,8 @@ Window
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onEnter: Outfit.accept()
onEscape: Outfit.destroy()
@onEnter: Outfit.accept()
@onEscape: Outfit.destroy()
Label
id: name
@ -18,34 +18,34 @@ Window
width: 100
anchors.top: parent.top
anchors.left: parent.left
margin.top: 34
margin.left: 20
margin-top: 34
margin-left: 20
Creature
id: creature
anchors.top: name.bottom
anchors.left: name.left
margin.top: 5
margin-top: 5
Button
id: head
text: Head
anchors.top: creature.top
anchors.left: creature.right
margin.left: 10
margin-left: 10
Button
id: primary
text: Primary
anchors.top: prev.bottom
anchors.left: prev.left
Button
id: secondary
text: Secondary
anchors.top: prev.bottom
anchors.left: prev.left
Button
id: detail
text: Detail
@ -56,7 +56,7 @@ Window
@onClick: Outfit.nextType()
text: >>
width: 32
margin.top: 4
margin-top: 4
anchors.top: creature.bottom
anchors.right: creature.right
@ -64,7 +64,7 @@ Window
@onClick: Outfit.previousType()
text: <<
width: 32
margin.top: 4
margin-top: 4
anchors.top: creature.bottom
anchors.left: creature.left
@ -72,7 +72,7 @@ Window
id: addon1
text: Addon 1
enabled: false
margin.top: 10
margin-top: 10
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -81,7 +81,7 @@ Window
id: addon2
text: Addon 2
enabled: false
margin.top: 10
margin-top: 10
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -90,7 +90,7 @@ Window
id: addon3
text: Addon 3
enabled: false
margin.top: 10
margin-top: 10
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -99,9 +99,9 @@ Window
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
margin.left: 16
margin.right: 16
margin.bottom: 10
margin-left: 16
margin-right: 16
margin-bottom: 10
Button
id: buttonOk
@ -109,8 +109,8 @@ Window
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: Outfit.accept()
Button
@ -119,6 +119,6 @@ Window
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
margin-bottom: 16
margin-right: 16
@onClick: Outfit.destroy()

View File

@ -2,9 +2,9 @@ SkillFirstWidget < UIWidget
SkillButton < UIButton
height: 14
margin.top: 4
margin.left: 10
margin.right: 10
margin-top: 4
margin-left: 10
margin-right: 10
SkillNameLabel < Label
font: verdana-11px-monochrome
@ -14,7 +14,7 @@ SkillNameLabel < Label
SkillLevelLabel < Label
font: verdana-11px-monochrome
align: right
text-align: right
width: 32
anchors.right: parent.right
anchors.top: parent.top
@ -25,9 +25,9 @@ SkillPercentPanel < UIProgressBar
background-color: green
tooltip: test
height: 5
margin.top: 3
margin.left: 10
margin.right: 10
margin-top: 3
margin-left: 10
margin-right: 10
MiniWindow
id: skillWindow
@ -37,8 +37,8 @@ MiniWindow
Panel
id: skillPanel
anchors.fill: parent
margin.top: 26
margin.bottom: 3
margin.left: 3
margin.right: 3
margin-top: 26
margin-bottom: 3
margin-left: 3
margin-right: 3
layout: verticalBox

View File

@ -1,7 +1,7 @@
CenterLabel < Label
font: verdana-11px-rounded
height: 16
align: center
text-align: center
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.right: parent.right
@ -9,8 +9,8 @@ CenterLabel < Label
BottomLabel < Label
font: verdana-11px-rounded
height: 16
align: center
margin.bottom: 2
text-align: center
margin-bottom: 2
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right

View File

@ -9,8 +9,8 @@ TopPanel
id: settingsButton
anchors.top: parent.top
anchors.left: parent.left
margin.top: 4
margin.left: 6
margin-top: 4
margin-left: 6
tooltip: Options
icon: /core_styles/icons/settings.png
@onClick: Options.create()
@ -20,7 +20,7 @@ TopPanel
id: enterGameButton
anchors.top: prev.top
anchors.left: prev.right
margin.left: 6
margin-left: 6
tooltip: Enter game with a character
icon: /core_styles/icons/login.png
@onClick: |
@ -34,7 +34,7 @@ TopPanel
id: motdButton
anchors.top: prev.top
anchors.left: prev.right
margin.left: 6
margin-left: 6
tooltip: Message of the day
icon: /core_styles/icons/motd.png
visible: false
@ -43,8 +43,8 @@ TopPanel
TopButton
anchors.top: parent.top
anchors.right: parent.right
margin.top: 4
margin.right: 6
margin-top: 4
margin-right: 6
tooltip: Logout
icon: /core_styles/icons/logout.png
@onClick: |
@ -57,8 +57,8 @@ TopPanel
TopButton
anchors.top: parent.top
anchors.right: prev.left
margin.top: 4
margin.right: 6
margin-top: 4
margin-right: 6
tooltip: About OTClient
icon: /core_styles/icons/about.png
@onClick: About.create()
@ -67,5 +67,5 @@ TopPanel
id: frameCounter
anchors.top: parent.top
anchors.right: prev.left
margin.top: 8
margin.right: 12
margin-top: 8
margin-right: 12

View File

@ -1,6 +1,6 @@
VipListLabel < Label
font: verdana-11px-monochrome
margin.left: 5
margin-left: 5
$disabled: ~
@ -12,7 +12,7 @@ MiniWindow
id: vipList
border-image: ~
anchors.fill: parent
margin.top: 26
margin.bottom: 6
margin.left: 6
margin.right: 6
margin-top: 26
margin-bottom: 6
margin-left: 6
margin-right: 6

View File

@ -29,10 +29,10 @@
void Font::load(const OTMLNodePtr& fontNode)
{
std::string textureName = fontNode->valueAt("texture");
Size glyphSize = fontNode->valueAt<Size>("glyph size");
Size glyphSize = fontNode->valueAt<Size>("glyph-size");
m_glyphHeight = fontNode->valueAt<int>("height");
m_topMargin = fontNode->valueAt("top margin", 0);
m_firstGlyph = fontNode->valueAt("first glyph", 32);
m_yOffset = fontNode->valueAt("y-offset", 0);
m_firstGlyph = fontNode->valueAt("first-glyph", 32);
m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0));
// load font texture
@ -40,14 +40,14 @@ void Font::load(const OTMLNodePtr& fontNode)
if(!m_texture)
throw std::runtime_error("failed to load texture for font");
if(OTMLNodePtr node = fontNode->get("fixed glyph width")) {
if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
for(int glyph = m_firstGlyph; glyph < 256; ++glyph)
m_glyphsSize[glyph] = Size(node->value<int>(), m_glyphHeight);
} else
calculateGlyphsWidthsAutomatically(glyphSize);
// read custom widths
if(OTMLNodePtr node = fontNode->get("glyph widths")) {
if(OTMLNodePtr node = fontNode->get("glyph-widths")) {
for(const OTMLNodePtr& child : node->children())
m_glyphsSize[Fw::safeCast<int>(child->tag())].setWidth(child->value<int>());
}
@ -200,7 +200,7 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
}
}
Point virtualPos(0, m_topMargin);
Point virtualPos(0, m_yOffset);
lines = 0;
for(i = 0; i < textLength; ++i) {
glyph = (uchar)text[i];

View File

@ -59,7 +59,7 @@ public:
const Rect* getGlyphsTextureCoords() const { return m_glyphsTextureCoords; }
const Size* getGlyphsSize() const { return m_glyphsSize; }
const TexturePtr& getTexture() const { return m_texture; }
int getTopMargin() const { return m_topMargin; }
int getYOffset() const { return m_yOffset; }
Size getGlyphSpacing() const { return m_glyphSpacing; }
private:
@ -69,7 +69,7 @@ private:
std::string m_name;
int m_glyphHeight;
int m_firstGlyph;
int m_topMargin;
int m_yOffset;
Size m_glyphSpacing;
TexturePtr m_texture;
Rect m_glyphsTextureCoords[256];

View File

@ -29,15 +29,15 @@ UILabel::UILabel()
{
m_focusable = false;
m_phantom = true;
m_align = Fw::AlignLeft;
m_textAlign = Fw::AlignLeft;
}
void UILabel::render()
{
UIWidget::render();
Rect textRect = m_rect;
textRect.setTopLeft(textRect.topLeft() + m_offset);
m_font->renderText(m_text, textRect, m_align, m_foregroundColor);
textRect.setTopLeft(textRect.topLeft() + m_textOffset);
m_font->renderText(m_text, textRect, m_textAlign, m_foregroundColor);
}
void UILabel::setText(const std::string& text)
@ -66,10 +66,10 @@ void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "text")
setText(node->value());
else if(node->tag() == "align")
setAlign(Fw::translateAlignment(node->value()));
else if(node->tag() == "offset") {
setOffset(node->value<Point>());
else if(node->tag() == "text-align")
setTextAlign(Fw::translateAlignment(node->value()));
else if(node->tag() == "text-offset") {
setTextOffset(node->value<Point>());
}
}
}

View File

@ -34,20 +34,20 @@ public:
void resizeToText();
void setText(const std::string& text);
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
void setOffset(const Point& offset) { m_offset = offset; }
void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; }
void setTextOffset(const Point& offset) { m_textOffset = offset; }
std::string getText() const { return m_text; }
Fw::AlignmentFlag getAlign() const { return m_align; }
Point getOffset() const { return m_offset; }
Fw::AlignmentFlag getTextAlign() const { return m_textAlign; }
Point getTextOffset() const { return m_textOffset; }
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
private:
std::string m_text;
Point m_offset;
Fw::AlignmentFlag m_align;
Point m_textOffset;
Fw::AlignmentFlag m_textAlign;
};
#endif

View File

@ -33,7 +33,7 @@ UILineEdit::UILineEdit()
m_startRenderPos = 0;
m_textHorizontalMargin = 0;
m_textHidden = false;
m_alwaysFocused = false;
m_alwaysActive = false;
blinkCursor();
}
@ -51,7 +51,7 @@ void UILineEdit::render()
g_graphics.drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
// render cursor
if(isExplicitlyEnabled() && (isActive() || m_alwaysFocused) && m_cursorPos >= 0) {
if(isExplicitlyEnabled() && (isActive() || m_alwaysActive) && m_cursorPos >= 0) {
assert(m_cursorPos <= textLength);
// draw every 333ms
const int delay = 333;
@ -98,7 +98,7 @@ void UILineEdit::update()
if(m_cursorPos < m_startRenderPos) // cursor is before the previuos first rendered glyph, so we need to update
{
m_startInternalPos.x = glyphsPositions[m_cursorPos].x;
m_startInternalPos.y = glyphsPositions[m_cursorPos].y - m_font->getTopMargin();
m_startInternalPos.y = glyphsPositions[m_cursorPos].y - m_font->getYOffset();
m_startRenderPos = m_cursorPos;
} else if(m_cursorPos > m_startRenderPos || // cursor is after the previuos first rendered glyph
(m_cursorPos == m_startRenderPos && textLength == m_cursorPos)) // cursor is at the previuos rendered element, and is the last text element
@ -119,13 +119,13 @@ void UILineEdit::update()
for(pos = 0; pos < textLength; ++pos) {
glyph = (uchar)text[pos];
glyphRect = Rect(glyphsPositions[pos], glyphsSize[glyph]);
glyphRect.setTop(std::max(glyphRect.top() - m_font->getTopMargin() - m_font->getGlyphSpacing().height(), 0));
glyphRect.setTop(std::max(glyphRect.top() - m_font->getYOffset() - m_font->getGlyphSpacing().height(), 0));
glyphRect.setLeft(std::max(glyphRect.left() - m_font->getGlyphSpacing().width(), 0));
// first glyph entirely visible found
if(glyphRect.topLeft() >= startGlyphPos) {
m_startInternalPos.x = glyphsPositions[pos].x;
m_startInternalPos.y = glyphsPositions[pos].y - m_font->getTopMargin();
m_startInternalPos.y = glyphsPositions[pos].y - m_font->getYOffset();
m_startRenderPos = pos;
break;
}
@ -351,7 +351,7 @@ int UILineEdit::getTextPos(Point pos)
int candidatePos = -1;
for(int i=0;i<textLength;++i) {
Rect clickGlyphRect = m_glyphsCoords[i];
clickGlyphRect.addTop(m_font->getTopMargin() + m_font->getGlyphSpacing().height());
clickGlyphRect.addTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
clickGlyphRect.addLeft(m_font->getGlyphSpacing().width()+1);
if(clickGlyphRect.contains(pos))
return i;
@ -381,12 +381,12 @@ void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
if(node->tag() == "text") {
setText(node->value());
setCursorPos(m_text.length());
} else if(node->tag() == "text hidden") {
} else if(node->tag() == "text-hidden") {
setTextHidden(node->value<bool>());
} else if(node->tag() == "text margin") {
} else if(node->tag() == "text-margin") {
m_textHorizontalMargin = node->value<int>();
} else if(node->tag() == "always focused") {
m_alwaysFocused = true;
} else if(node->tag() == "always-active") {
m_alwaysActive = true;
}
}
}
@ -398,7 +398,7 @@ void UILineEdit::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
{
if(focused && !m_alwaysFocused) {
if(focused && !m_alwaysActive) {
if(reason == Fw::TabFocusReason)
setCursorPos(m_text.length());
else
@ -423,7 +423,7 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
appendText(g_platform.getClipboardText());
else if(keyCode == Fw::KeyTab) {
if(!m_alwaysFocused) {
if(!m_alwaysActive) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::TabFocusReason);
}

View File

@ -71,7 +71,7 @@ private:
int m_cursorTicks;
int m_textHorizontalMargin;
bool m_textHidden;
bool m_alwaysFocused;
bool m_alwaysActive;
std::vector<Rect> m_glyphsCoords;
std::vector<Rect> m_glyphsTexCoords;

View File

@ -36,7 +36,7 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
UILayout::applyStyle(styleNode);
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "align bottom")
if(node->tag() == "align-bottom")
m_alignBottom = node->value<bool>();
else if(node->tag() == "padding")
m_padding = node->value<int>();

View File

@ -40,7 +40,7 @@ UIWidget::UIWidget()
m_states = Fw::DefaultState;
m_font = g_fonts.getDefaultFont();
m_opacity = 255;
m_marginTop = m_marginBottom = m_marginLeft = m_marginRight = 0;
m_marginTop = m_marginRight = m_marginBottom = m_marginLeft = 0;
// generate an unique id, this is need because anchored layouts find widgets by id
static unsigned long id = 1;
@ -817,7 +817,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
setWidth(node->value<int>());
else if(node->tag() == "height")
setHeight(node->value<int>());
else if(node->tag() == "size fixed")
else if(node->tag() == "fixed-size")
setSizeFixed(node->value<bool>());
else if(node->tag() == "position")
moveTo(node->value<Point>());
@ -825,14 +825,46 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
setX(node->value<int>());
else if(node->tag() == "y")
setY(node->value<int>());
else if(node->tag() == "margin.left")
setMarginLeft(node->value<int>());
else if(node->tag() == "margin.right")
setMarginRight(node->value<int>());
else if(node->tag() == "margin.top")
else if(node->tag() == "margin-top")
setMarginTop(node->value<int>());
else if(node->tag() == "margin.bottom")
else if(node->tag() == "margin-right")
setMarginRight(node->value<int>());
else if(node->tag() == "margin-bottom")
setMarginBottom(node->value<int>());
else if(node->tag() == "margin-left")
setMarginLeft(node->value<int>());
else if(node->tag() == "margin") {
std::string marginDesc = node->value();
std::vector<std::string> split;
boost::split(split, marginDesc, boost::is_any_of(std::string(" ")));
if(split.size() == 4) {
setMarginTop(Fw::safeCast<int>(split[0]));
setMarginRight(Fw::safeCast<int>(split[1]));
setMarginBottom(Fw::safeCast<int>(split[2]));
setMarginLeft(Fw::safeCast<int>(split[3]));
} else if(split.size() == 3) {
int marginTop = Fw::safeCast<int>(split[0]);
int marginHorizontal = Fw::safeCast<int>(split[1]);
int marginBottom = Fw::safeCast<int>(split[2]);
setMarginTop(marginTop);
setMarginRight(marginHorizontal);
setMarginBottom(marginBottom);
setMarginLeft(marginHorizontal);
} else if(split.size() == 2) {
int marginVertical = Fw::safeCast<int>(split[0]);
int marginHorizontal = Fw::safeCast<int>(split[1]);
setMarginTop(marginVertical);
setMarginRight(marginHorizontal);
setMarginBottom(marginVertical);
setMarginLeft(marginHorizontal);
} else if(split.size() == 1) {
int margin = Fw::safeCast<int>(split[0]);
setMarginTop(margin);
setMarginRight(margin);
setMarginBottom(margin);
setMarginLeft(margin);
}
}
// layouts
else if(node->tag() == "layout") {
// layout is set only once

View File

@ -62,10 +62,10 @@ public:
void setOpacity(int opacity) { m_opacity = opacity; }
void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
void setForegroundColor(const Color& color) { m_foregroundColor = color; }
void setMarginLeft(int margin) { m_marginLeft = margin; updateParentLayout(); }
void setMarginRight(int margin) { m_marginRight = margin; updateParentLayout(); }
void setMarginTop(int margin) { m_marginTop = margin; updateParentLayout(); }
void setMarginRight(int margin) { m_marginRight = margin; updateParentLayout(); }
void setMarginBottom(int margin) { m_marginBottom = margin; updateParentLayout(); }
void setMarginLeft(int margin) { m_marginLeft = margin; updateParentLayout(); }
void setSizeFixed(bool fixed) { m_fixedSize = fixed; updateParentLayout(); }
void setLastFocusReason(Fw::FocusReason reason) { m_lastFocusReason = reason; }
@ -112,10 +112,10 @@ public:
Color getForegroundColor() { return m_foregroundColor; }
Color getBackgroundColor() { return m_backgroundColor; }
int getOpacity() { return m_opacity; }
int getMarginLeft() { return m_marginLeft; }
int getMarginRight() { return m_marginRight; }
int getMarginTop() { return m_marginTop; }
int getMarginRight() { return m_marginRight; }
int getMarginBottom() { return m_marginBottom; }
int getMarginLeft() { return m_marginLeft; }
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
OTMLNodePtr getStyle() { return m_style; }
@ -205,10 +205,10 @@ protected:
Color m_foregroundColor;
int m_states;
int m_opacity;
int m_marginLeft;
int m_marginRight;
int m_marginTop;
int m_marginRight;
int m_marginBottom;
int m_marginLeft;
};
#endif

View File

@ -41,19 +41,17 @@ void UIWindow::render()
// render children
UIWidget::render();
// draw window head
// draw window head text
Rect headTextRect = m_rect;
headTextRect.addTop(-m_headOffset.y);
headTextRect.addTop(-m_headTextOffset.y);
headTextRect.setHeight(m_headHeight);
if(m_titleAlign & Fw::AlignLeft)
headTextRect.addLeft(-m_headOffset.x);
headTextRect.addLeft(-m_headTextOffset.x);
else if(m_titleAlign & Fw::AlignRight)
headTextRect.addRight(-m_headOffset.x);
headTextRect.addRight(-m_headTextOffset.x);
else {
headTextRect.addLeft(-m_headOffset.x);
headTextRect.addRight(-m_headOffset.x);
headTextRect.addLeft(-m_headTextOffset.x);
headTextRect.addRight(-m_headTextOffset.x);
}
m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor);
}
@ -63,15 +61,15 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
UIWidget::onStyleApply(styleNode);
for(OTMLNodePtr node : styleNode->children()) {
if(node->tag() == "head height")
if(node->tag() == "head-height")
m_headHeight = node->value<int>();
else if(node->tag() == "head offset")
m_headOffset = node->value<Point>();
else if(node->tag() == "head-text-offset")
m_headTextOffset = node->value<Point>();
else if(node->tag() == "title")
setTitle(node->value());
else if(node->tag() == "head text align")
else if(node->tag() == "head-text-align")
m_titleAlign = Fw::translateAlignment(node->value());
else if(node->tag() == "move policy") {
else if(node->tag() == "move-policy") {
if(node->value() == "free")
m_movePolicy = FREE_MOVE;
else if(node->value() == "free updated")
@ -79,14 +77,6 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
else
m_movePolicy = DONT_MOVE;
}
else if(node->tag() == "onEnter") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
else if(node->tag() == "onEscape") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(node->tag());
}
}
}

View File

@ -53,7 +53,7 @@ private:
bool m_moving;
MovePolicy m_movePolicy;
Fw::AlignmentFlag m_titleAlign;
Point m_headOffset;
Point m_headTextOffset;
Point m_movingReference;
Point m_oldPos;
int m_oldIndex;