mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-05 17:20:30 +00:00
GRAPHICS: MACGUI: re-organize the logic of calculating offsets of mactext and macbutton.
This commit is contained in:
parent
cff54ea5db
commit
158406487a
@ -37,50 +37,28 @@ MacButton::MacButton(MacButtonType buttonType, TextAlign textAlignment, MacWidge
|
||||
MacText(parent, x, y, w, h, wm, s, macFont, fgcolor, bgcolor, w, textAlignment), _pd(Graphics::MacPlotData(_composeSurface, nullptr, &_wm->getPatterns(), 1, 0, 0, 1, 0, true)) {
|
||||
|
||||
_buttonType = buttonType;
|
||||
_invertInner = false;
|
||||
_checkBoxType = 0;
|
||||
|
||||
switch (buttonType) {
|
||||
case kCheckBox:
|
||||
_alignOffset.x += 16;
|
||||
_dims.right += 16;
|
||||
break;
|
||||
case kRound:
|
||||
_alignOffset.x += 2;
|
||||
_alignOffset.y += 2;
|
||||
_dims.right += 2;
|
||||
_dims.bottom += 4;
|
||||
break;
|
||||
case kRadio:
|
||||
_alignOffset.x += 16;
|
||||
_dims.right += 16;
|
||||
break;
|
||||
}
|
||||
|
||||
_composeSurface->create(_dims.width(), _dims.height(), _wm->_pixelformat);
|
||||
_composeSurface->clear(_bgcolor);
|
||||
init();
|
||||
}
|
||||
|
||||
MacButton::MacButton(MacButtonType buttonType, TextAlign textAlignment, MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, Common::CodePage encodeType) :
|
||||
MacText(parent, x, y, w, h, wm, s, macFont, fgcolor, bgcolor, w, textAlignment, 0, 0, 0, 0, 0, encodeType), _pd(Graphics::MacPlotData(_composeSurface, nullptr, &_wm->getPatterns(), 1, 0, 0, 1, 0, true)) {
|
||||
MacButton::MacButton(MacButtonType buttonType, TextAlign textAlignment, MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, Common::CodePage encodeType) : MacText(parent, x, y, w, h, wm, s, macFont, fgcolor, bgcolor, w, textAlignment, 0, 0, 0, 0, 0, encodeType), _pd(Graphics::MacPlotData(_composeSurface, nullptr, &_wm->getPatterns(), 1, 0, 0, 1, 0, true)) {
|
||||
|
||||
_buttonType = buttonType;
|
||||
init();
|
||||
}
|
||||
|
||||
void MacButton::init() {
|
||||
_invertInner = false;
|
||||
_checkBoxType = 0;
|
||||
|
||||
switch (buttonType) {
|
||||
switch (_buttonType) {
|
||||
case kCheckBox:
|
||||
_alignOffset.x += 16;
|
||||
_dims.right += 16;
|
||||
break;
|
||||
case kRound:
|
||||
_alignOffset.x += 2;
|
||||
_alignOffset.y += 2;
|
||||
_dims.right += 2;
|
||||
_dims.bottom += 4;
|
||||
break;
|
||||
case kRadio:
|
||||
_alignOffset.x += 16;
|
||||
_dims.right += 16;
|
||||
break;
|
||||
}
|
||||
@ -226,8 +204,24 @@ bool MacButton::processEvent(Common::Event &event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we won't have the text with _border and _gutter in macbutton now.
|
||||
// so for the override of calculateOffset, we are passing the border and gutter which depends on buttonType
|
||||
// maybe we can cache this for optimization
|
||||
Common::Point MacButton::calculateOffset() {
|
||||
return Common::Point(_alignOffset.x + _border + _gutter, _alignOffset.y + _border + _gutter/2);
|
||||
int x = 0, y = 0;
|
||||
switch (_buttonType) {
|
||||
case kCheckBox:
|
||||
x = 16;
|
||||
break;
|
||||
case kRound:
|
||||
x = 2;
|
||||
y = 2;
|
||||
break;
|
||||
case kRadio:
|
||||
x = 16;
|
||||
break;
|
||||
}
|
||||
return Common::Point(x, y);
|
||||
}
|
||||
|
||||
} // End of namespace Graphics
|
||||
|
@ -63,6 +63,9 @@ public:
|
||||
virtual bool processEvent(Common::Event &event) override;
|
||||
virtual Common::Point calculateOffset() override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
private:
|
||||
MacButtonType _buttonType;
|
||||
MacPlotData _pd;
|
||||
|
@ -672,7 +672,7 @@ void MacText::reallocSurface() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_surface->w < _textMaxWidth || _surface->h < _textMaxHeight) {
|
||||
if (_surface->w < _maxWidth || _surface->h < _textMaxHeight) {
|
||||
// realloc surface and copy old content
|
||||
ManagedSurface *n = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
|
||||
n->clear(_bgcolor);
|
||||
@ -863,26 +863,11 @@ void MacText::recalcDims() {
|
||||
}
|
||||
|
||||
void MacText::setAlignOffset(TextAlign align) {
|
||||
Common::Point offset;
|
||||
switch(align) {
|
||||
case kTextAlignLeft:
|
||||
default:
|
||||
offset = Common::Point(0, 0);
|
||||
break;
|
||||
case kTextAlignCenter:
|
||||
offset = Common::Point((_maxWidth / 2) - (_surface->w / 2), 0);
|
||||
break;
|
||||
case kTextAlignRight:
|
||||
offset = Common::Point(_maxWidth - (_surface->w + 1), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (offset != _alignOffset) {
|
||||
_contentIsDirty = true;
|
||||
_fullRefresh = true;
|
||||
_alignOffset = offset;
|
||||
_textAlignment = align;
|
||||
}
|
||||
if (_textAlignment == align)
|
||||
return;
|
||||
_contentIsDirty = true;
|
||||
_fullRefresh = true;
|
||||
_textAlignment = align;
|
||||
}
|
||||
|
||||
Common::Point MacText::calculateOffset() {
|
||||
@ -1082,15 +1067,9 @@ bool MacText::draw(bool forceRedraw) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we are drawing the selection, then we better clear the surface
|
||||
// let me explain here, sometimes, when we are render the text in _surface, we may not render the whole line
|
||||
// such as, a line only contains \n, thus, we may only render part of this line
|
||||
// when we are drawing the selection, it will reverse all the pixels in selected area. And when you only render part of a line in selected area
|
||||
// drawSelection will reverse that not rendered part again and again, and which will lead to blinking
|
||||
|
||||
// we need to find out a way to judge whether we need to clear the surface
|
||||
// currently, we just use the _contentIsDirty
|
||||
if (_selectedText.endY != -1 || _contentIsDirty)
|
||||
if (_contentIsDirty)
|
||||
_composeSurface->clear(_bgcolor);
|
||||
|
||||
// TODO: Clear surface fully when background colour changes.
|
||||
@ -1361,8 +1340,12 @@ void MacText::setSelection(int pos, bool start) {
|
||||
colX = col = row = 0;
|
||||
} else {
|
||||
row = _textLines.size() - 1;
|
||||
colX = _surface->w;
|
||||
col = getLineCharWidth(row);
|
||||
// if we don't have any text, then we won't select the whole area.
|
||||
if (_textMaxWidth == 0)
|
||||
colX = 0;
|
||||
else
|
||||
colX = _surface->w;
|
||||
}
|
||||
|
||||
int rowY = _textLines[row].y;
|
||||
|
@ -288,8 +288,6 @@ public:
|
||||
bool _fullRefresh;
|
||||
|
||||
protected:
|
||||
Common::Point _alignOffset;
|
||||
|
||||
Common::U32String _str;
|
||||
const MacFont *_macFont;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user