mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
Replace jwidget_get_text_length/height with Widget::getTextWidth/Height
Renamed Widget::getTextSize to Widget::getTextLength as now getTextSize returns a gfx::Size() (not the strlen() of the text)
This commit is contained in:
parent
04a0845a62
commit
04f3c522ba
@ -119,7 +119,7 @@ bool FileList::onProcessMessage(Message* msg)
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
||||
View* view = View::getView(this);
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
int th = jwidget_get_text_height(this);
|
||||
int th = getTextHeight();
|
||||
int x, y = getBounds().y;
|
||||
int evenRow = 0;
|
||||
ui::Color bgcolor;
|
||||
@ -246,7 +246,7 @@ bool FileList::onProcessMessage(Message* msg)
|
||||
case kMouseMoveMessage:
|
||||
if (hasCapture()) {
|
||||
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
||||
int th = jwidget_get_text_height(this);
|
||||
int th = getTextHeight();
|
||||
int y = getBounds().y;
|
||||
IFileItem* old_selected = m_selected;
|
||||
m_selected = NULL;
|
||||
@ -321,7 +321,7 @@ bool FileList::onProcessMessage(Message* msg)
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
if (select < 0)
|
||||
select = 0;
|
||||
select += sgn * vp.h / (2+jwidget_get_text_height(this)+2);
|
||||
select += sgn * vp.h / (2+getTextHeight()+2);
|
||||
break;
|
||||
}
|
||||
case kKeyLeft:
|
||||
@ -397,7 +397,7 @@ bool FileList::onProcessMessage(Message* msg)
|
||||
View* view = View::getView(this);
|
||||
if (view) {
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
scroll.y += (jmouse_z(1)-jmouse_z(0)) * 3*(2+jwidget_get_text_height(this)+2);
|
||||
scroll.y += (jmouse_z(1)-jmouse_z(0)) * 3*(2+getTextHeight()+2);
|
||||
view->setViewScroll(scroll);
|
||||
}
|
||||
break;
|
||||
@ -484,7 +484,7 @@ gfx::Size FileList::getFileItemSize(IFileItem* fi) const
|
||||
len += ji_font_text_len(getFont(), fi->getDisplayName().c_str());
|
||||
|
||||
return gfx::Size(2+len+2,
|
||||
2+jwidget_get_text_height(this)+2);
|
||||
2+getTextHeight()+2);
|
||||
}
|
||||
|
||||
void FileList::makeSelectedFileitemVisible()
|
||||
@ -492,7 +492,7 @@ void FileList::makeSelectedFileitemVisible()
|
||||
View* view = View::getView(this);
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
int th = jwidget_get_text_height(this);
|
||||
int th = getTextHeight();
|
||||
int y = getBounds().y;
|
||||
|
||||
// rows
|
||||
|
@ -826,9 +826,9 @@ void SkinTheme::initWidget(Widget* widget)
|
||||
|
||||
if (widget->hasText()) {
|
||||
if (widget->getAlign() & JI_TOP)
|
||||
widget->border_width.t = jwidget_get_text_height(widget);
|
||||
widget->border_width.t = widget->getTextHeight();
|
||||
else if (widget->getAlign() & JI_BOTTOM)
|
||||
widget->border_width.b = jwidget_get_text_height(widget);
|
||||
widget->border_width.b = widget->getTextHeight();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -837,7 +837,7 @@ void SkinTheme::initWidget(Widget* widget)
|
||||
m_part[PART_SLIDER_EMPTY_N]->h,
|
||||
m_part[PART_SLIDER_EMPTY_E]->w-1*scale,
|
||||
m_part[PART_SLIDER_EMPTY_S]->h-1*scale);
|
||||
widget->child_spacing = jwidget_get_text_height(widget);
|
||||
widget->child_spacing = widget->getTextHeight();
|
||||
widget->setAlign(JI_CENTER | JI_MIDDLE);
|
||||
break;
|
||||
|
||||
@ -868,7 +868,7 @@ void SkinTheme::initWidget(Widget* widget)
|
||||
if (!static_cast<Window*>(widget)->isDesktop()) {
|
||||
if (widget->hasText()) {
|
||||
BORDER4(6 * scale, (4+6) * scale, 6 * scale, 6 * scale);
|
||||
widget->border_width.t += jwidget_get_text_height(widget);
|
||||
widget->border_width.t += widget->getTextHeight();
|
||||
|
||||
if (!(widget->flags & JI_INITIALIZED)) {
|
||||
Button* button = new WindowCloseButton();
|
||||
@ -1065,7 +1065,7 @@ void SkinTheme::paintEntry(PaintEvent& ev)
|
||||
bool password = widget->isPassword();
|
||||
int scroll, caret, state, selbeg, selend;
|
||||
std::string textString = widget->getText() + widget->getSuffix();
|
||||
int suffixIndex = widget->getTextSize();
|
||||
int suffixIndex = widget->getTextLength();
|
||||
const char* text = textString.c_str();
|
||||
int c, ch, x, y, w;
|
||||
int x1, y1, x2, y2;
|
||||
@ -1097,7 +1097,7 @@ void SkinTheme::paintEntry(PaintEvent& ev)
|
||||
|
||||
// Draw the text
|
||||
x = widget->getBounds().x + widget->border_width.l;
|
||||
y = widget->getBounds().y + widget->getBounds().h/2 - jwidget_get_text_height(widget)/2;
|
||||
y = widget->getBounds().y + widget->getBounds().h/2 - widget->getTextHeight()/2;
|
||||
|
||||
for (c=scroll; ugetat(text, c); c++) {
|
||||
ch = password ? '*': ugetat(text, c);
|
||||
@ -1184,7 +1184,7 @@ void SkinTheme::paintLinkLabel(PaintEvent& ev)
|
||||
widget->getBounds(), 0);
|
||||
|
||||
if (widget->hasMouseOver()) {
|
||||
int w = jwidget_get_text_length(widget);
|
||||
int w = widget->getTextWidth();
|
||||
|
||||
hline(ji_screen,
|
||||
widget->getBounds().x,
|
||||
@ -1236,8 +1236,8 @@ void SkinTheme::paintListItem(ui::PaintEvent& ev)
|
||||
widget->getBounds().x, widget->getBounds().y,
|
||||
widget->getBounds().x2()-1, widget->getBounds().y2()-1,
|
||||
x, y,
|
||||
x+jwidget_get_text_length(widget)-1,
|
||||
y+jwidget_get_text_height(widget)-1, bg);
|
||||
x+widget->getTextWidth()-1,
|
||||
y+widget->getTextHeight()-1, bg);
|
||||
}
|
||||
// Background
|
||||
else {
|
||||
@ -1444,7 +1444,7 @@ void SkinTheme::paintSeparator(ui::PaintEvent& ev)
|
||||
|
||||
// text
|
||||
if (widget->hasText()) {
|
||||
int h = jwidget_get_text_height(widget);
|
||||
int h = widget->getTextHeight();
|
||||
Rect r(Point(x1+h/2, y1-h/2),
|
||||
Point(x2+1-h, y2+1+h));
|
||||
|
||||
@ -1611,7 +1611,7 @@ void SkinTheme::paintComboBoxEntry(ui::PaintEvent& ev)
|
||||
|
||||
// Draw the text
|
||||
x = widget->getBounds().x + widget->border_width.l;
|
||||
y = widget->getBounds().y + widget->getBounds().h/2 - jwidget_get_text_height(widget)/2;
|
||||
y = widget->getBounds().y + widget->getBounds().h/2 - widget->getTextHeight()/2;
|
||||
|
||||
for (c=scroll; ugetat(text, c); c++) {
|
||||
ch = password ? '*': ugetat(text, c);
|
||||
@ -1778,7 +1778,7 @@ void SkinTheme::paintWindow(PaintEvent& ev)
|
||||
get_style("window")->paint(g, pos, NULL, Style::State());
|
||||
get_style("window_title")->paint(g,
|
||||
gfx::Rect(cpos.x, pos.y+5*jguiscale(), cpos.w, // TODO this hard-coded 5 should be configurable in skin.xml
|
||||
jwidget_get_text_height(window)),
|
||||
window->getTextHeight()),
|
||||
window->getText().c_str(), Style::State());
|
||||
}
|
||||
// menubox
|
||||
@ -1904,13 +1904,12 @@ void SkinTheme::drawTextStringDeprecated(const char* t, ui::Color fg_color, ui::
|
||||
|
||||
if (!t) {
|
||||
t = widget->getText().c_str();
|
||||
w = jwidget_get_text_length(widget);
|
||||
h = jwidget_get_text_height(widget);
|
||||
w = widget->getTextWidth();
|
||||
}
|
||||
else {
|
||||
w = ji_font_text_len(widget->getFont(), t);
|
||||
h = text_height(widget->getFont());
|
||||
}
|
||||
h = widget->getTextHeight();
|
||||
|
||||
/* horizontally text alignment */
|
||||
|
||||
@ -2034,7 +2033,7 @@ void SkinTheme::drawTextString(Graphics* g, const char *t, ui::Color fg_color, u
|
||||
|
||||
void SkinTheme::draw_entry_caret(Entry* widget, int x, int y)
|
||||
{
|
||||
int h = jwidget_get_text_height(widget);
|
||||
int h = widget->getTextHeight();
|
||||
|
||||
vline(ji_screen, x, y-1, y+h, to_system(getColor(ThemeColor::Text)));
|
||||
vline(ji_screen, x+1, y-1, y+h, to_system(getColor(ThemeColor::Text)));
|
||||
|
@ -473,7 +473,7 @@ void StatusBar::onResize(ResizeEvent& ev)
|
||||
|
||||
void StatusBar::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int s = 4*jguiscale() + jwidget_get_text_height(this) + 4*jguiscale();
|
||||
int s = 4*jguiscale() + getTextHeight() + 4*jguiscale();
|
||||
ev.setPreferredSize(Size(s, s));
|
||||
}
|
||||
|
||||
@ -535,7 +535,7 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
|
||||
}
|
||||
|
||||
// Status bar text
|
||||
if (getTextSize() > 0) {
|
||||
if (getTextLength() > 0) {
|
||||
g->drawString(getText(), text_color, ColorNone, false,
|
||||
gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));
|
||||
|
||||
|
@ -431,7 +431,7 @@ void Tabs::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
|
||||
ev.setPreferredSize(gfx::Size(0, // 4 + jwidget_get_text_height(widget) + 5,
|
||||
ev.setPreferredSize(gfx::Size(0, // 4 + widget->getTextHeight() + 5,
|
||||
theme->get_part(PART_TAB_FILLER)->h +
|
||||
theme->get_part(PART_TAB_BOTTOM_NORMAL)->h));
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ void ComboBox::openListBox()
|
||||
(viewport,
|
||||
m_button->getBounds().x2() - m_entry->getBounds().x - view->border_width.l - view->border_width.r,
|
||||
+viewport->border_width.t
|
||||
+(2*jguiscale()+jwidget_get_text_height(m_listbox))*MID(1, size, 16)+
|
||||
+(2*jguiscale()+m_listbox->getTextHeight())*MID(1, size, 16)+
|
||||
+viewport->border_width.b);
|
||||
|
||||
m_window->addChild(view);
|
||||
|
@ -411,8 +411,8 @@ void Entry::onSetText()
|
||||
{
|
||||
Widget::onSetText();
|
||||
|
||||
if (m_caret >= 0 && (size_t)m_caret > getTextSize())
|
||||
m_caret = (int)getTextSize();
|
||||
if (m_caret >= 0 && (size_t)m_caret > getTextLength())
|
||||
m_caret = (int)getTextLength();
|
||||
}
|
||||
|
||||
void Entry::onEntryChange()
|
||||
|
@ -37,10 +37,8 @@ void Label::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
gfx::Size sz(0, 0);
|
||||
|
||||
if (hasText()) {
|
||||
sz.w = jwidget_get_text_length(this);
|
||||
sz.h = jwidget_get_text_height(this);
|
||||
}
|
||||
if (hasText())
|
||||
sz = getTextSize();
|
||||
|
||||
sz.w += this->border_width.l + this->border_width.r;
|
||||
sz.h += this->border_width.t + this->border_width.b;
|
||||
|
@ -185,7 +185,7 @@ bool ListBox::onProcessMessage(Message* msg)
|
||||
View* view = View::getView(this);
|
||||
if (view) {
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
scroll.y += (jmouse_z(1) - jmouse_z(0)) * jwidget_get_text_height(this)*3;
|
||||
scroll.y += (jmouse_z(1) - jmouse_z(0)) * getTextHeight()*3;
|
||||
view->setViewScroll(scroll);
|
||||
}
|
||||
break;
|
||||
@ -214,7 +214,7 @@ bool ListBox::onProcessMessage(Message* msg)
|
||||
case kKeyPageUp:
|
||||
if (view) {
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
select -= vp.h / jwidget_get_text_height(this);
|
||||
select -= vp.h / getTextHeight();
|
||||
}
|
||||
else
|
||||
select = 0;
|
||||
@ -222,7 +222,7 @@ bool ListBox::onProcessMessage(Message* msg)
|
||||
case kKeyPageDown:
|
||||
if (view) {
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
select += vp.h / jwidget_get_text_height(this);
|
||||
select += vp.h / getTextHeight();
|
||||
}
|
||||
else
|
||||
select = bottom;
|
||||
|
@ -47,10 +47,8 @@ void ListItem::onPreferredSize(PreferredSizeEvent& ev)
|
||||
int w = 0, h = 0;
|
||||
Size maxSize;
|
||||
|
||||
if (hasText()) {
|
||||
maxSize.w = jwidget_get_text_length(this);
|
||||
maxSize.h = jwidget_get_text_height(this);
|
||||
}
|
||||
if (hasText())
|
||||
maxSize = getTextSize();
|
||||
else
|
||||
maxSize.w = maxSize.h = 0;
|
||||
|
||||
|
@ -877,13 +877,13 @@ void MenuItem::onPreferredSize(PreferredSizeEvent& ev)
|
||||
if (hasText()) {
|
||||
size.w =
|
||||
+ this->border_width.l
|
||||
+ jwidget_get_text_length(this)
|
||||
+ getTextWidth()
|
||||
+ ((bar) ? this->child_spacing/4: this->child_spacing)
|
||||
+ this->border_width.r;
|
||||
|
||||
size.h =
|
||||
+ this->border_width.t
|
||||
+ jwidget_get_text_height(this)
|
||||
+ getTextHeight()
|
||||
+ this->border_width.b;
|
||||
|
||||
if (m_accel && !m_accel->isEmpty()) {
|
||||
|
@ -44,7 +44,7 @@ void Separator::onPreferredSize(PreferredSizeEvent& ev)
|
||||
}
|
||||
|
||||
if (hasText())
|
||||
maxSize.w = MAX(maxSize.w, jwidget_get_text_length(this));
|
||||
maxSize.w = MAX(maxSize.w, getTextWidth());
|
||||
|
||||
int w = this->border_width.l + maxSize.w + this->border_width.r;
|
||||
int h = this->border_width.t + maxSize.h + this->border_width.b;
|
||||
|
@ -224,7 +224,7 @@ void Slider::onPreferredSize(PreferredSizeEvent& ev)
|
||||
max_w = ji_font_text_len(this->getFont(), buf);
|
||||
|
||||
w = MAX(min_w, max_w);
|
||||
h = jwidget_get_text_height(this);
|
||||
h = getTextHeight();
|
||||
|
||||
w += this->border_width.l + this->border_width.r;
|
||||
h += this->border_width.t + this->border_width.b;
|
||||
|
@ -41,7 +41,7 @@ bool TextBox::onProcessMessage(Message* msg)
|
||||
if (view) {
|
||||
gfx::Rect vp = view->getViewportBounds();
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
int textheight = jwidget_get_text_height(this);
|
||||
int textheight = getTextHeight();
|
||||
|
||||
switch (static_cast<KeyMessage*>(msg)->scancode()) {
|
||||
|
||||
@ -134,7 +134,7 @@ bool TextBox::onProcessMessage(Message* msg)
|
||||
if (view) {
|
||||
gfx::Point scroll = view->getViewScroll();
|
||||
|
||||
scroll.y += (jmouse_z(1) - jmouse_z(0)) * jwidget_get_text_height(this)*3;
|
||||
scroll.y += (jmouse_z(1) - jmouse_z(0)) * getTextHeight()*3;
|
||||
|
||||
view->setViewScroll(scroll);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ void drawTextBox(BITMAP* bmp, Widget* widget,
|
||||
int x, y, chr, len;
|
||||
gfx::Point scroll;
|
||||
int viewport_w, viewport_h;
|
||||
int textheight = jwidget_get_text_height(widget);
|
||||
int textheight = widget->getTextHeight();
|
||||
FONT *font = widget->getFont();
|
||||
char *beg_end, *old_end;
|
||||
int width;
|
||||
|
@ -713,20 +713,18 @@ void Widget::getDrawableRegion(gfx::Region& region, DrawableRegionFlags flags)
|
||||
}
|
||||
}
|
||||
|
||||
int jwidget_get_text_length(const Widget* widget)
|
||||
int Widget::getTextWidth() const
|
||||
{
|
||||
#if 1
|
||||
return ji_font_text_len(widget->getFont(), widget->getText().c_str());
|
||||
return ji_font_text_len(getFont(), getText().c_str());
|
||||
#else /* use cached text size */
|
||||
return widget->text_size_pix;
|
||||
return text_size_pix;
|
||||
#endif
|
||||
}
|
||||
|
||||
int jwidget_get_text_height(const Widget* widget)
|
||||
int Widget::getTextHeight() const
|
||||
{
|
||||
ASSERT_VALID_WIDGET(widget);
|
||||
|
||||
return text_height(widget->getFont());
|
||||
return text_height(getFont());
|
||||
}
|
||||
|
||||
void jwidget_get_texticon_info(Widget* widget,
|
||||
@ -752,8 +750,8 @@ void jwidget_get_texticon_info(Widget* widget,
|
||||
|
||||
// Size of the text
|
||||
if (widget->hasText()) {
|
||||
text_w = jwidget_get_text_length(widget);
|
||||
text_h = jwidget_get_text_height(widget);
|
||||
text_w = widget->getTextWidth();
|
||||
text_h = widget->getTextHeight();
|
||||
}
|
||||
else {
|
||||
text_w = text_h = 0;
|
||||
|
@ -44,8 +44,6 @@ namespace ui {
|
||||
|
||||
// Position and geometry
|
||||
|
||||
int jwidget_get_text_length(const Widget* widget);
|
||||
int jwidget_get_text_height(const Widget* widget);
|
||||
void jwidget_get_texticon_info(Widget* widget,
|
||||
gfx::Rect* box,
|
||||
gfx::Rect* text,
|
||||
@ -111,11 +109,18 @@ namespace ui {
|
||||
const base::string& getText() const { return m_text; }
|
||||
int getTextInt() const;
|
||||
double getTextDouble() const;
|
||||
size_t getTextSize() const { return m_text.size(); }
|
||||
size_t getTextLength() const { return m_text.size(); }
|
||||
void setText(const base::string& text);
|
||||
void setTextf(const char* text, ...);
|
||||
void setTextQuiet(const base::string& text);
|
||||
|
||||
int getTextWidth() const;
|
||||
int getTextHeight() const;
|
||||
|
||||
gfx::Size getTextSize() const {
|
||||
return gfx::Size(getTextWidth(), getTextHeight());
|
||||
}
|
||||
|
||||
// ===============================================================
|
||||
// COMMON PROPERTIES
|
||||
// ===============================================================
|
||||
|
@ -461,7 +461,7 @@ void Window::onPreferredSize(PreferredSizeEvent& ev)
|
||||
}
|
||||
|
||||
if (hasText())
|
||||
maxSize.w = MAX(maxSize.w, jwidget_get_text_length(this));
|
||||
maxSize.w = MAX(maxSize.w, getTextWidth());
|
||||
|
||||
ev.setPreferredSize(this->border_width.l + maxSize.w + this->border_width.r,
|
||||
this->border_width.t + maxSize.h + this->border_width.b);
|
||||
|
Loading…
x
Reference in New Issue
Block a user