ManaPlus
Public Member Functions | Private Attributes | Static Private Attributes
TextPreview Class Reference

#include <textpreview.h>

Inheritance diagram for TextPreview:
Widget Widget2

Public Member Functions

 TextPreview (const Widget2 *const widget, const std::string &text)
 
 ~TextPreview ()
 
void setTextColor (const Color *color)
 
void setTextColor2 (const Color *color)
 
void useTextAlpha (const bool alpha)
 
void setTextBGColor (const Color *color)
 
void setBGColor (const Color *color)
 
void setFont (Font *const font)
 
void setShadow (const bool shadow)
 
void setOutline (const bool outline)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setOpaque (const Opaque opaque)
 
bool isOpaque () const
 
void adjustSize ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
virtual void logic ()
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
virtual WidgetgetWidgetAt (int x, int y)
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 

Private Attributes

FontmFont
 
std::string mText
 
const ColormTextColor
 
const ColormTextColor2
 
const ColormBGColor
 
const ColormTextBGColor
 
int mPadding
 
bool mTextAlpha
 
Opaque mOpaque
 
bool mShadow
 
bool mOutline
 

Static Private Attributes

static int instances = 0
 
static float mAlpha = 1.0
 
static SkinmSkin = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Preview widget for particle colors, etc.

Definition at line 35 of file textpreview.h.

Constructor & Destructor Documentation

◆ TextPreview()

TextPreview::TextPreview ( const Widget2 *const  widget,
const std::string &  text 
)

Definition at line 40 of file textpreview.cpp.

References adjustSize(), Skin::getOption(), Theme::getThemePath(), instances, Theme::load(), Widget::mAllowLogic, mPadding, mSkin, and theme.

41  :
42  Widget(widget),
43  mFont(gui->getFont()),
44  mText(text),
48  mTextBGColor(nullptr),
49  mPadding(0),
50  mTextAlpha(false),
52  mShadow(false),
53  mOutline(false)
54 {
55  mAllowLogic = false;
56  if (instances == 0)
57  {
58  if (theme != nullptr)
59  {
60  mSkin = theme->load("textpreview.xml",
61  "",
62  true,
64  }
65  }
66 
67  instances++;
68 
69  if (mSkin != nullptr)
70  mPadding = mSkin->getOption("padding", 0);
71 
72  adjustSize();
73 }
Gui * gui
Definition: gui.cpp:110
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
Font * getFont() const
Definition: gui.h:159
bool mTextAlpha
Definition: textpreview.h:138
const Color * mTextColor2
Definition: textpreview.h:131
int getOption(const std::string &name) const
Definition: skin.h:105
std::string mText
Definition: textpreview.h:129
const Color * mTextColor
Definition: textpreview.h:130
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
const bool Opaque_false
Definition: opaque.h:29
const Color * mTextBGColor
Definition: textpreview.h:133
Opaque mOpaque
Definition: textpreview.h:139
Theme * theme
Definition: theme.cpp:61
static int instances
Definition: textpreview.h:135
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
Font * mFont
Definition: textpreview.h:128
const Color * mBGColor
Definition: textpreview.h:132
static Skin * mSkin
Definition: textpreview.h:137
void adjustSize()

◆ ~TextPreview()

TextPreview::~TextPreview ( )

Definition at line 75 of file textpreview.cpp.

References gui, instances, mSkin, Gui::removeDragged(), theme, and Theme::unload().

76 {
77  if (gui != nullptr)
78  gui->removeDragged(this);
79 
80  instances--;
81 
82  if (instances == 0)
83  {
84  if (theme != nullptr)
85  theme->unload(mSkin);
86  }
87 }
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
static int instances
Definition: textpreview.h:135
static Skin * mSkin
Definition: textpreview.h:137

Member Function Documentation

◆ adjustSize()

void TextPreview::adjustSize ( )

Definition at line 153 of file textpreview.cpp.

References Widget::getFont(), Widget::getHeight(), mPadding, and Widget::setHeight().

Referenced by isOpaque(), setTextColor(), setTextColor2(), and TextPreview().

154 {
155  setHeight(getFont()->getHeight() + 2 * mPadding);
156 }
Font * getFont() const
Definition: widget.cpp:330
void setHeight(const int height)
Definition: widget.cpp:139
int getHeight() const
Definition: widget.h:239

◆ draw()

void TextPreview::draw ( Graphics *const  graphics)
virtual

Widget's draw method. Does the actual job.

Parameters
graphicsgraphics to draw into

Implements Widget.

Definition at line 89 of file textpreview.cpp.

References Color::b, BLOCK_END, BLOCK_START, CAST_S32, Font::drawString(), Graphics::fillRectangle(), Color::g, Font::getHeight(), Widget2::getThemeColor(), Font::getWidth(), Settings::guiAlpha, Rect::height, mAlpha, mBGColor, Widget::mDimension, mFont, mOpaque, mOutline, mPadding, mShadow, mText, mTextAlpha, mTextBGColor, mTextColor, mTextColor2, Opaque_true, ThemeColorId::OUTLINE, Color::r, Graphics::setColor(), settings, Rect::width, x, and y.

Referenced by safeDraw(), and setOutline().

90 {
91  if (mFont == nullptr)
92  return;
93 
94  BLOCK_START("TextPreview::draw")
95  if (settings.guiAlpha != mAlpha)
96  mAlpha = settings.guiAlpha;
97 
98  const int intAlpha = CAST_S32(mAlpha * 255.0F);
99  const int alpha = mTextAlpha ? intAlpha : 255;
100 
101  if (mOpaque == Opaque_true)
102  {
103  graphics->setColor(Color(CAST_S32(mBGColor->r),
104  CAST_S32(mBGColor->g),
105  CAST_S32(mBGColor->b),
106  CAST_S32(mAlpha * 255.0F)));
107  graphics->fillRectangle(Rect(0, 0,
109  }
110 
111  if (mTextBGColor != nullptr)
112  {
113  const int x = mFont->getWidth(mText) + 1
114  + 2 * ((mOutline || mShadow) ? 1 :0);
115  const int y = mFont->getHeight() + 1
116  + 2 * ((mOutline || mShadow) ? 1 : 0);
117  graphics->setColor(Color(CAST_S32(mTextBGColor->r),
120  intAlpha));
121  graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
122  }
123 
124  Color color1(mTextColor->r, mTextColor->g, mTextColor->b, alpha);
125 
126  if (mOutline && mTextColor != mTextColor2)
127  {
128  const Color &color2 = getThemeColor(ThemeColorId::OUTLINE, 255U);
129  mFont->drawString(graphics,
130  color1,
131  color2,
132  mText,
133  mPadding + 1, mPadding + 1);
134  }
135  else
136  {
137  Color color2(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha);
138  mFont->drawString(graphics,
139  color1,
140  color2,
141  mText,
142  mPadding + 1, mPadding + 1);
143  }
144 
145  BLOCK_END("TextPreview::draw")
146 }
int width
Definition: rect.h:218
unsigned int g
Definition: color.h:239
Definition: rect.h:72
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
static float mAlpha
Definition: textpreview.h:136
bool mTextAlpha
Definition: textpreview.h:138
const Color * mTextColor2
Definition: textpreview.h:131
std::string mText
Definition: textpreview.h:129
Settings settings
Definition: settings.cpp:31
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
unsigned int b
Definition: color.h:244
const Color * mTextColor
Definition: textpreview.h:130
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
int height
Definition: rect.h:223
const Color * mTextBGColor
Definition: textpreview.h:133
Opaque mOpaque
Definition: textpreview.h:139
virtual void fillRectangle(const Rect &rectangle)=0
const bool Opaque_true
Definition: opaque.h:29
int getWidth(const std::string &text) const
Definition: font.cpp:333
Definition: color.h:74
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
Font * mFont
Definition: textpreview.h:128
const Color * mBGColor
Definition: textpreview.h:132
int getHeight() const
Definition: font.cpp:361
Rect mDimension
Definition: widget.h:1100
unsigned int r
Definition: color.h:234

◆ isOpaque()

bool TextPreview::isOpaque ( ) const
inline

Gets opacity for this widget (whether or not the background color is shown below the widget)

Definition at line 122 of file textpreview.h.

References adjustSize(), mOpaque, and Opaque_true.

123  { return mOpaque == Opaque_true; }
Opaque mOpaque
Definition: textpreview.h:139
const bool Opaque_true
Definition: opaque.h:29

◆ safeDraw()

void TextPreview::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 148 of file textpreview.cpp.

References draw().

Referenced by setOutline().

149 {
150  TextPreview::draw(graphics);
151 }
void draw(Graphics *const graphics)
Definition: textpreview.cpp:89

◆ setBGColor()

void TextPreview::setBGColor ( const Color color)
inline

Sets the background color of the widget.

Parameters
colorthe color to set

Definition at line 73 of file textpreview.h.

References mBGColor.

Referenced by Setup_Colors::valueChanged().

74  { mBGColor = color; }
const Color * mBGColor
Definition: textpreview.h:132

◆ setFont()

void TextPreview::setFont ( Font *const  font)
inline

Sets the font to render the text in.

Parameters
fontthe font to use.

Definition at line 81 of file textpreview.h.

References ServerCommandType::font, and mFont.

Referenced by Setup_Colors::valueChanged().

◆ setOpaque()

void TextPreview::setOpaque ( const Opaque  opaque)
inline

Set opacity for this widget (whether or not to show the background color)

Parameters
opaqueWhether the widget should be opaque or not

Definition at line 115 of file textpreview.h.

References mOpaque.

Referenced by Setup_Colors::valueChanged().

116  { mOpaque = opaque; }
Opaque mOpaque
Definition: textpreview.h:139

◆ setOutline()

void TextPreview::setOutline ( const bool  outline)
inline

Sets whether to use an outline while rendering.

Parameters
outlinetrue, if an outline is wanted, false else

Definition at line 97 of file textpreview.h.

References A_NONNULL, draw(), mOutline, and safeDraw().

Referenced by Setup_Colors::valueChanged().

98  { mOutline = outline; }

◆ setShadow()

void TextPreview::setShadow ( const bool  shadow)
inline

Sets whether to use a shadow while rendering.

Parameters
shadowtrue, if a shadow is wanted, false else

Definition at line 89 of file textpreview.h.

References mShadow.

Referenced by Setup_Colors::valueChanged().

90  { mShadow = shadow; }

◆ setTextBGColor()

void TextPreview::setTextBGColor ( const Color color)
inline

Sets the color the text background is drawn in. This is only the rectangle directly behind the text, not to full widget.

Parameters
colorthe color to set

Definition at line 65 of file textpreview.h.

References mTextBGColor.

Referenced by Setup_Colors::valueChanged().

66  { mTextBGColor = color; }
const Color * mTextBGColor
Definition: textpreview.h:133

◆ setTextColor()

void TextPreview::setTextColor ( const Color color)
inline

Definition at line 45 of file textpreview.h.

References adjustSize(), and mTextColor.

Referenced by Setup_Colors::valueChanged().

46  { mTextColor = color; adjustSize(); }
const Color * mTextColor
Definition: textpreview.h:130
void adjustSize()

◆ setTextColor2()

void TextPreview::setTextColor2 ( const Color color)
inline

Definition at line 48 of file textpreview.h.

References adjustSize(), and mTextColor2.

49  { mTextColor2 = color; adjustSize(); }
const Color * mTextColor2
Definition: textpreview.h:131
void adjustSize()

◆ useTextAlpha()

void TextPreview::useTextAlpha ( const bool  alpha)
inline

Sets the text to use the set alpha value.

Parameters
alphawhether to use alpha values for the text or not

Definition at line 56 of file textpreview.h.

References mTextAlpha.

Referenced by Setup_Colors::valueChanged().

57  { mTextAlpha = alpha; }
bool mTextAlpha
Definition: textpreview.h:138

Field Documentation

◆ instances

int TextPreview::instances = 0
staticprivate

Definition at line 135 of file textpreview.h.

Referenced by TextPreview(), and ~TextPreview().

◆ mAlpha

float TextPreview::mAlpha = 1.0
staticprivate

Definition at line 136 of file textpreview.h.

Referenced by draw().

◆ mBGColor

const Color* TextPreview::mBGColor
private

Definition at line 132 of file textpreview.h.

Referenced by draw(), and setBGColor().

◆ mFont

Font* TextPreview::mFont
private

Definition at line 128 of file textpreview.h.

Referenced by draw(), and setFont().

◆ mOpaque

Opaque TextPreview::mOpaque
private

Definition at line 139 of file textpreview.h.

Referenced by draw(), isOpaque(), and setOpaque().

◆ mOutline

bool TextPreview::mOutline
private

Definition at line 141 of file textpreview.h.

Referenced by draw(), and setOutline().

◆ mPadding

int TextPreview::mPadding
private

Definition at line 134 of file textpreview.h.

Referenced by adjustSize(), draw(), and TextPreview().

◆ mShadow

bool TextPreview::mShadow
private

Definition at line 140 of file textpreview.h.

Referenced by draw(), and setShadow().

◆ mSkin

Skin * TextPreview::mSkin = 0
staticprivate

Definition at line 137 of file textpreview.h.

Referenced by TextPreview(), and ~TextPreview().

◆ mText

std::string TextPreview::mText
private

Definition at line 129 of file textpreview.h.

Referenced by draw().

◆ mTextAlpha

bool TextPreview::mTextAlpha
private

Definition at line 138 of file textpreview.h.

Referenced by draw(), and useTextAlpha().

◆ mTextBGColor

const Color* TextPreview::mTextBGColor
private

Definition at line 133 of file textpreview.h.

Referenced by draw(), and setTextBGColor().

◆ mTextColor

const Color* TextPreview::mTextColor
private

Definition at line 130 of file textpreview.h.

Referenced by draw(), and setTextColor().

◆ mTextColor2

const Color* TextPreview::mTextColor2
private

Definition at line 131 of file textpreview.h.

Referenced by draw(), and setTextColor2().


The documentation for this class was generated from the following files: