Mana
Loading...
Searching...
No Matches
src
gui
textpopup.cpp
Go to the documentation of this file.
1
/*
2
* The Mana World
3
* Copyright (C) 2008 The Legend of Mazzeroth Development Team
4
* Copyright (C) 2008-2009 The Mana World Development Team
5
* Copyright (C) 2009-2012 The Mana Developers
6
*
7
* This file is part of The Mana World.
8
*
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
*/
23
24
#include "
gui/textpopup.h
"
25
26
#include "
gui/gui.h
"
27
28
#include "
gui/widgets/label.h
"
29
30
#include "
graphics.h
"
31
32
#include <guichan/font.hpp>
33
#include <guichan/widgets/label.hpp>
34
35
TextPopup::TextPopup
():
36
Popup
(
"TextPopup"
)
37
{
38
setMinWidth
(0);
39
setMinHeight
(0);
40
41
const
int
fontHeight = getFont()->getHeight();
42
43
mText1
=
new
Label
;
44
mText1
->setPosition(0, 0);
45
46
mText2
=
new
Label
;
47
mText2
->setPosition(0, fontHeight);
48
49
add
(
mText1
);
50
add
(
mText2
);
51
addMouseListener(
this
);
52
}
53
54
void
TextPopup::show
(
int
x,
int
y,
55
const
std::string &str1,
56
const
std::string &str2)
57
{
58
mText1
->setCaption(str1);
59
mText1
->adjustSize();
60
mText2
->setCaption(str2);
61
mText2
->adjustSize();
62
63
int
width = std::max(
mText1
->getWidth(),
mText2
->getWidth());
64
int
height =
mText1
->getHeight();
65
if
(!str2.empty())
66
height +=
mText2
->getHeight();
67
68
setContentSize
(width, height);
69
70
const
int
distance = 20;
71
72
int
posX = std::max(0, x - getWidth() / 2);
73
int
posY = y + distance;
74
75
if
(posX + getWidth() >
graphics
->
getWidth
())
76
posX =
graphics
->
getWidth
() - getWidth();
77
if
(posY + getHeight() >
graphics
->
getHeight
())
78
posY = y - getHeight() - distance;
79
80
setPosition(posX, posY);
81
setVisible(
true
);
82
requestMoveToTop();
83
}
84
85
void
TextPopup::mouseMoved
(gcn::MouseEvent &event)
86
{
87
Popup::mouseMoved
(event);
88
89
// When the mouse moved on top of the popup, hide it
90
setVisible(
false
);
91
}
Graphics::getHeight
int getHeight() const
Returns the logical height of the screen.
Definition
graphics.h:226
Graphics::getWidth
int getWidth() const
Returns the logical width of the screen.
Definition
graphics.h:221
Label
Label widget.
Definition
label.h:34
Popup
A light version of the Window class.
Definition
popup.h:48
Popup::setMinHeight
void setMinHeight(int height)
Sets the minimum height of the popup.
Definition
popup.cpp:163
Popup::add
void add(gcn::Widget *widget) override
Definition
popup.cpp:69
Popup::mouseMoved
void mouseMoved(gcn::MouseEvent &event) override
Definition
popup.cpp:205
Popup::setMinWidth
void setMinWidth(int width)
Sets the minimum width of the popup.
Definition
popup.cpp:158
Popup::setContentSize
void setContentSize(int width, int height)
Sets the size of this popup.
Definition
popup.cpp:127
TextPopup::show
void show(int x, int y, const std::string &str1, const std::string &str2=std::string())
Sets the text to be displayed.
Definition
textpopup.cpp:54
TextPopup::mText2
gcn::Label * mText2
Definition
textpopup.h:51
TextPopup::mText1
gcn::Label * mText1
Definition
textpopup.h:50
TextPopup::mouseMoved
void mouseMoved(gcn::MouseEvent &mouseEvent) override
Definition
textpopup.cpp:85
TextPopup::TextPopup
TextPopup()
Definition
textpopup.cpp:35
graphics
Graphics * graphics
Definition
client.cpp:104
graphics.h
gui.h
label.h
textpopup.h
Generated by
1.9.8