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 36 of file textpreview.h.

Constructor & Destructor Documentation

◆ TextPreview()

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

Definition at line 41 of file textpreview.cpp.

42  :
43  Widget(widget),
44  mFont(gui->getFont()),
45  mText(text),
47  mTextColor2(&getThemeColor(ThemeColorId::TEXT_OUTLINE, 255U)),
49  mTextBGColor(nullptr),
50  mPadding(0),
51  mTextAlpha(false),
53  mShadow(false),
54  mOutline(false)
55 {
56  mAllowLogic = false;
57  if (instances == 0)
58  {
59  if (theme != nullptr)
60  {
61  mSkin = theme->load("textpreview.xml",
62  "",
63  true,
65  }
66  }
67 
68  instances++;
69 
70  if (mSkin != nullptr)
71  mPadding = mSkin->getOption("padding", 0);
72 
73  adjustSize();
74 }
Font * getFont() const
Definition: gui.h:160
int getOption(const std::string &name) const
Definition: skin.h:106
const Color * mTextColor2
Definition: textpreview.h:132
void adjustSize()
const Color * mBGColor
Definition: textpreview.h:133
static int instances
Definition: textpreview.h:136
const Color * mTextBGColor
Definition: textpreview.h:134
static Skin * mSkin
Definition: textpreview.h:138
bool mTextAlpha
Definition: textpreview.h:139
Font * mFont
Definition: textpreview.h:129
Opaque mOpaque
Definition: textpreview.h:140
std::string mText
Definition: textpreview.h:130
const Color * mTextColor
Definition: textpreview.h:131
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Widget(const Widget2 *const widget)
Definition: widget.cpp:85
bool mAllowLogic
Definition: widget.h:1160
Gui * gui
Definition: gui.cpp:111
const bool Opaque_false
Definition: opaque.h:30
Theme * theme
Definition: theme.cpp:62

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

◆ ~TextPreview()

TextPreview::~TextPreview ( )

Definition at line 76 of file textpreview.cpp.

77 {
78  if (gui != nullptr)
79  gui->removeDragged(this);
80 
81  instances--;
82 
83  if (instances == 0)
84  {
85  if (theme != nullptr)
86  theme->unload(mSkin);
87  }
88 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
void unload(Skin *const skin)
Definition: theme.cpp:250

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

Member Function Documentation

◆ adjustSize()

void TextPreview::adjustSize ( )

Definition at line 154 of file textpreview.cpp.

155 {
156  setHeight(getFont()->getHeight() + 2 * mPadding);
157 }
void setHeight(const int height)
Definition: widget.cpp:140
Font * getFont() const
Definition: widget.cpp:331
int getHeight() const
Definition: widget.h:240

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

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

◆ 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 90 of file textpreview.cpp.

91 {
92  if (mFont == nullptr)
93  return;
94 
95  BLOCK_START("TextPreview::draw")
96  if (settings.guiAlpha != mAlpha)
97  mAlpha = settings.guiAlpha;
98 
99  const int intAlpha = CAST_S32(mAlpha * 255.0F);
100  const int alpha = mTextAlpha ? intAlpha : 255;
101 
102  if (mOpaque == Opaque_true)
103  {
104  graphics->setColor(Color(CAST_S32(mBGColor->r),
105  CAST_S32(mBGColor->g),
106  CAST_S32(mBGColor->b),
107  CAST_S32(mAlpha * 255.0F)));
108  graphics->fillRectangle(Rect(0, 0,
110  }
111 
112  if (mTextBGColor != nullptr)
113  {
114  const int x = mFont->getWidth(mText) + 1
115  + 2 * ((mOutline || mShadow) ? 1 :0);
116  const int y = mFont->getHeight() + 1
117  + 2 * ((mOutline || mShadow) ? 1 : 0);
118  graphics->setColor(Color(CAST_S32(mTextBGColor->r),
121  intAlpha));
122  graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
123  }
124 
125  Color color1(mTextColor->r, mTextColor->g, mTextColor->b, alpha);
126 
127  if (mOutline && mTextColor != mTextColor2)
128  {
129  const Color &color2 = getThemeColor(ThemeColorId::OUTLINE, 255U);
130  mFont->drawString(graphics,
131  color1,
132  color2,
133  mText,
134  mPadding + 1, mPadding + 1);
135  }
136  else
137  {
138  Color color2(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha);
139  mFont->drawString(graphics,
140  color1,
141  color2,
142  mText,
143  mPadding + 1, mPadding + 1);
144  }
145 
146  BLOCK_END("TextPreview::draw")
147 }
#define CAST_S32
Definition: cast.h:30
Definition: color.h:76
unsigned int b
Definition: color.h:245
unsigned int r
Definition: color.h:235
unsigned int g
Definition: color.h:240
int getHeight() const
Definition: font.cpp:362
int getWidth(const std::string &text) const
Definition: font.cpp:334
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
static float mAlpha
Definition: textpreview.h:137
Rect mDimension
Definition: widget.h:1101
if(!vert) return
const bool Opaque_true
Definition: opaque.h:30
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
Settings settings
Definition: settings.cpp:32

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, Color::r, Graphics::setColor(), settings, Rect::width, x, and y.

Referenced by safeDraw().

◆ 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 123 of file textpreview.h.

124  { return mOpaque == Opaque_true; }

References mOpaque, and Opaque_true.

◆ safeDraw()

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

Implements Widget.

Definition at line 149 of file textpreview.cpp.

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

References draw().

◆ setBGColor()

void TextPreview::setBGColor ( const Color color)
inline

Sets the background color of the widget.

Parameters
colorthe color to set

Definition at line 74 of file textpreview.h.

75  { mBGColor = color; }

References mBGColor.

Referenced by Setup_Colors::valueChanged().

◆ setFont()

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

Sets the font to render the text in.

Parameters
fontthe font to use.

Definition at line 82 of file textpreview.h.

83  { mFont = font; }

References 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 116 of file textpreview.h.

117  { mOpaque = opaque; }

References mOpaque.

Referenced by Setup_Colors::valueChanged().

◆ 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 98 of file textpreview.h.

99  { mOutline = outline; }

References mOutline.

Referenced by Setup_Colors::valueChanged().

◆ 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 90 of file textpreview.h.

91  { mShadow = shadow; }

References mShadow.

Referenced by Setup_Colors::valueChanged().

◆ 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 66 of file textpreview.h.

67  { mTextBGColor = color; }

References mTextBGColor.

Referenced by Setup_Colors::valueChanged().

◆ setTextColor()

void TextPreview::setTextColor ( const Color color)
inline

Definition at line 46 of file textpreview.h.

47  { mTextColor = color; adjustSize(); }

References adjustSize(), and mTextColor.

Referenced by Setup_Colors::valueChanged().

◆ setTextColor2()

void TextPreview::setTextColor2 ( const Color color)
inline

Definition at line 49 of file textpreview.h.

50  { mTextColor2 = color; adjustSize(); }

References adjustSize(), and mTextColor2.

◆ 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 57 of file textpreview.h.

58  { mTextAlpha = alpha; }

References mTextAlpha.

Referenced by Setup_Colors::valueChanged().

Field Documentation

◆ instances

int TextPreview::instances = 0
staticprivate

Definition at line 136 of file textpreview.h.

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

◆ mAlpha

float TextPreview::mAlpha = 1.0
staticprivate

Definition at line 137 of file textpreview.h.

Referenced by draw().

◆ mBGColor

const Color* TextPreview::mBGColor
private

Definition at line 133 of file textpreview.h.

Referenced by draw(), and setBGColor().

◆ mFont

Font* TextPreview::mFont
private

Definition at line 129 of file textpreview.h.

Referenced by draw(), and setFont().

◆ mOpaque

Opaque TextPreview::mOpaque
private

Definition at line 140 of file textpreview.h.

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

◆ mOutline

bool TextPreview::mOutline
private

Definition at line 142 of file textpreview.h.

Referenced by draw(), and setOutline().

◆ mPadding

int TextPreview::mPadding
private

Definition at line 135 of file textpreview.h.

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

◆ mShadow

bool TextPreview::mShadow
private

Definition at line 141 of file textpreview.h.

Referenced by draw(), and setShadow().

◆ mSkin

Skin * TextPreview::mSkin = 0
staticprivate

Definition at line 138 of file textpreview.h.

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

◆ mText

std::string TextPreview::mText
private

Definition at line 130 of file textpreview.h.

Referenced by draw().

◆ mTextAlpha

bool TextPreview::mTextAlpha
private

Definition at line 139 of file textpreview.h.

Referenced by draw(), and useTextAlpha().

◆ mTextBGColor

const Color* TextPreview::mTextBGColor
private

Definition at line 134 of file textpreview.h.

Referenced by draw(), and setTextBGColor().

◆ mTextColor

const Color* TextPreview::mTextColor
private

Definition at line 131 of file textpreview.h.

Referenced by draw(), and setTextColor().

◆ mTextColor2

const Color* TextPreview::mTextColor2
private

Definition at line 132 of file textpreview.h.

Referenced by draw(), and setTextColor2().


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