ManaPlus
src
gui
popups
textboxpopup.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2008 The Legend of Mazzeroth Development Team
4
* Copyright (C) 2008-2009 The Mana World Development Team
5
* Copyright (C) 2009-2010 The Mana Developers
6
* Copyright (C) 2011-2019 The ManaPlus Developers
7
* Copyright (C) 2019-2021 Andrei Karas
8
*
9
* This file is part of The ManaPlus Client.
10
*
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*/
24
25
#include "
gui/popups/textboxpopup.h
"
26
27
#include "
gui/widgets/textbox.h
"
28
29
#include "
gui/fonts/font.h
"
30
31
#include "render/graphics.h"
32
33
#include "
debug.h
"
34
35
TextBoxPopup
*
textBoxPopup
=
nullptr
;
36
37
TextBoxPopup::TextBoxPopup
() :
38
Popup
(
"TextBoxPopup"
,
"textboxpopup.xml"
),
39
mTextBox(
new
TextBox
(this))
40
{
41
}
42
43
void
TextBoxPopup::postInit
()
44
{
45
Popup::postInit
();
46
const
int
fontHeight =
getFont
()->
getHeight
();
47
setMinHeight
(fontHeight);
48
mTextBox
->
setEditable
(
false
);
49
mTextBox
->
setOpaque
(
Opaque_false
);
50
mTextBox
->
setForegroundColorAll
(
51
getThemeColor
(ThemeColorId::POPUP, 255U),
52
getThemeColor
(ThemeColorId::POPUP_OUTLINE, 255U));
53
add
(
mTextBox
);
54
addMouseListener
(
this
);
55
}
56
57
TextBoxPopup::~TextBoxPopup
()
58
{
59
}
60
61
void
TextBoxPopup::show
(
const
int
x
,
const
int
y
,
const
std::string &str)
62
{
63
mTextBox
->
setTextWrapped
(str, 190);
64
setContentSize
(
mTextBox
->
getWidth
(),
mTextBox
->
getHeight
());
65
const
int
distance = 20;
66
67
const
Rect
&rect =
mDimension
;
68
int
posX = std::max(0,
x
- rect.
width
/ 2);
69
int
posY =
y
+ distance;
70
71
if
(posX + rect.
width
>
mainGraphics
->
mWidth
)
72
posX =
mainGraphics
->
mWidth
- rect.
width
;
73
if
(posY + rect.
height
>
mainGraphics
->
mHeight
)
74
posY =
y
- rect.
height
- distance;
75
76
setPosition
(posX, posY);
77
setVisible
(
Visible_true
);
78
requestMoveToTop
();
79
}
80
81
void
TextBoxPopup::mouseMoved
(
MouseEvent
&event)
82
{
83
Popup::mouseMoved
(event);
84
85
// When the mouse moved on top of the popup, hide it
86
setVisible
(
Visible_false
);
87
}
BasicContainer2::add
virtual void add(Widget *const widget)
Definition:
basiccontainer2.cpp:113
Font::getHeight
int getHeight() const
Definition:
font.cpp:362
Graphics::mWidth
int mWidth
Definition:
graphics.h:484
Graphics::mHeight
int mHeight
Definition:
graphics.h:485
MouseEvent
Definition:
mouseevent.h:81
Popup
Definition:
popup.h:52
Popup::setMinHeight
void setMinHeight(const int height)
Definition:
popup.cpp:207
Popup::setContentSize
void setContentSize(int width, int height)
Definition:
popup.cpp:155
Popup::mouseMoved
void mouseMoved(MouseEvent &event)
Definition:
popup.cpp:255
Popup::postInit
void postInit()
Definition:
popup.h:177
Rect
Definition:
rect.h:74
Rect::width
int width
Definition:
rect.h:219
Rect::height
int height
Definition:
rect.h:224
TextBoxPopup
Definition:
textboxpopup.h:36
TextBoxPopup::TextBoxPopup
TextBoxPopup()
Definition:
textboxpopup.cpp:37
TextBoxPopup::show
void show(const int x, const int y, const std::string &str)
Definition:
textboxpopup.cpp:61
TextBoxPopup::~TextBoxPopup
~TextBoxPopup()
Definition:
textboxpopup.cpp:57
TextBoxPopup::mTextBox
TextBox * mTextBox
Definition:
textboxpopup.h:60
TextBoxPopup::mouseMoved
void mouseMoved(MouseEvent &event)
Definition:
textboxpopup.cpp:81
TextBoxPopup::postInit
void postInit()
Definition:
textboxpopup.cpp:43
TextBox
Definition:
textbox.h:89
TextBox::setEditable
void setEditable(const bool editable)
Definition:
textbox.cpp:650
TextBox::setOpaque
void setOpaque(const Opaque opaque)
Definition:
textbox.h:273
TextBox::setForegroundColorAll
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition:
textbox.cpp:488
TextBox::setTextWrapped
void setTextWrapped(const std::string &text, const int minDimension)
Definition:
textbox.cpp:109
Widget2::getThemeColor
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition:
widget2.h:45
Widget::setVisible
void setVisible(Visible visible)
Definition:
widget.cpp:225
Widget::requestMoveToTop
virtual void requestMoveToTop()
Definition:
widget.cpp:213
Widget::mDimension
Rect mDimension
Definition:
widget.h:1101
Widget::addMouseListener
void addMouseListener(MouseListener *const mouseListener)
Definition:
widget.cpp:292
Widget::getFont
Font * getFont() const
Definition:
widget.cpp:331
Widget::setPosition
void setPosition(const int x, const int y)
Definition:
widget.cpp:161
Widget::getHeight
int getHeight() const
Definition:
widget.h:240
Widget::getWidth
int getWidth() const
Definition:
widget.h:221
debug.h
new
#define new
Definition:
debug_new.h:147
font.h
mainGraphics
Graphics * mainGraphics
Definition:
graphics.cpp:109
y
y
Definition:
graphics_calcImageRect.hpp:73
x
x
Definition:
graphics_calcImageRect.hpp:73
Opaque_false
const bool Opaque_false
Definition:
opaque.h:30
textbox.h
textBoxPopup
TextBoxPopup * textBoxPopup
Definition:
textboxpopup.cpp:35
textboxpopup.h
Visible_false
const bool Visible_false
Definition:
visible.h:30
Visible_true
const bool Visible_true
Definition:
visible.h:30
Generated on Wed Mar 17 2021 19:19:06 for ManaPlus by
1.9.1