~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/widgets/playerbox.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi, Andrei Karas, Patrick Matthäi
  • Date: 2013-05-18 21:06:29 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130518210629-3trtowluum0tekob
Tags: 1.3.5.12-1
[ Andrei Karas ]
* Add new files to copyright file.

[ Patrick Matthäi ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
#include "debug.h"
35
35
 
36
 
PlayerBox::PlayerBox(Being *const being, const std::string &skin) :
 
36
PlayerBox::PlayerBox(Being *const being, const std::string &skin,
 
37
                     const std::string &selectedSkin) :
37
38
    Widget2(),
38
39
    ScrollArea(),
39
40
    mBeing(being),
40
41
    mAlpha(1.0),
41
42
    mBackground(),
 
43
    mSelectedBackground(),
42
44
    mSkin(nullptr),
 
45
    mSelectedSkin(nullptr),
 
46
    mOffsetX(-16),
 
47
    mOffsetY(-32),
43
48
    mDrawBackground(false),
44
 
    mOffsetX(-16),
45
 
    mOffsetY(-32)
 
49
    mSelected(false)
46
50
{
47
 
    init(skin);
 
51
    init(skin, selectedSkin);
48
52
}
49
53
 
50
 
PlayerBox::PlayerBox(std::string skin) :
 
54
PlayerBox::PlayerBox(const std::string &skin,
 
55
                     const std::string &selectedSkin) :
51
56
    ScrollArea(),
52
57
    mBeing(nullptr),
53
58
    mAlpha(1.0),
54
59
    mBackground(),
 
60
    mSelectedBackground(),
55
61
    mSkin(nullptr),
 
62
    mSelectedSkin(nullptr),
 
63
    mOffsetX(-16),
 
64
    mOffsetY(-32),
56
65
    mDrawBackground(false),
57
 
    mOffsetX(-16),
58
 
    mOffsetY(-32)
 
66
    mSelected(false)
59
67
{
60
 
    init(skin);
 
68
    init(skin, selectedSkin);
61
69
}
62
70
 
63
71
PlayerBox::~PlayerBox()
68
76
    Theme *const theme = Theme::instance();
69
77
    if (theme)
70
78
    {
71
 
        theme->unload(mSkin);
72
79
        theme->unloadRect(mBackground);
 
80
        theme->unloadRect(mSelectedBackground);
73
81
    }
74
82
 
75
83
    mBeing = nullptr;
76
84
}
77
85
 
78
 
void PlayerBox::init(std::string skin)
 
86
void PlayerBox::init(std::string name, std::string selectedName)
79
87
{
80
88
    setFrameSize(2);
81
89
 
82
90
    if (Theme::instance())
83
91
    {
84
 
        if (skin.empty())
85
 
            skin = "playerbox.xml";
 
92
        if (name.empty())
 
93
            name = "playerbox.xml";
86
94
        mSkin = Theme::instance()->loadSkinRect(mBackground,
87
 
            skin, "playerbox_background.xml");
 
95
            name, "playerbox_background.xml");
88
96
        if (mSkin)
89
97
        {
90
98
            mDrawBackground = (mSkin->getOption("drawbackground") != 0);
92
100
            mOffsetY = mSkin->getOption("offsetY", -32);
93
101
            mFrameSize = mSkin->getOption("frameSize", 2);
94
102
        }
 
103
        if (selectedName.empty())
 
104
            selectedName = "playerboxselected.xml";
 
105
        mSelectedSkin = Theme::instance()->loadSkinRect(mSelectedBackground,
 
106
            selectedName, "playerbox_background.xml");
95
107
    }
96
108
    else
97
109
    {
98
110
        for (int f = 0; f < 9; f ++)
99
111
            mBackground.grid[f] = nullptr;
 
112
        for (int f = 0; f < 9; f ++)
 
113
            mSelectedBackground.grid[f] = nullptr;
100
114
    }
101
115
}
102
116
 
133
147
        w = getWidth() + bs * 2;
134
148
        h = getHeight() + bs * 2;
135
149
 
136
 
        static_cast<Graphics*>(graphics)->drawImageRect(
137
 
            0, 0, w, h, mBackground);
 
150
        if (!mSelected)
 
151
        {
 
152
            static_cast<Graphics*>(graphics)->drawImageRect(
 
153
                0, 0, w, h, mBackground);
 
154
        }
 
155
        else
 
156
        {
 
157
            static_cast<Graphics*>(graphics)->drawImageRect(
 
158
                0, 0, w, h, mSelectedBackground);
 
159
        }
138
160
    }
139
161
    BLOCK_END("PlayerBox::drawFrame")
140
162
}