[Scummvm-git-logs] scummvm master -> 091e49fb663b21231dde7809736c536e0793eac8
ysj1173886760
42030331+ysj1173886760 at users.noreply.github.com
Sat Jul 24 08:39:11 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
70e2ca433c GRAPHICS: MACGUI: fix rendering text shadow with non-black text.
091e49fb66 GRAPHICS: MACGUI: implement checked item for macmenu
Commit: 70e2ca433c0580d719951b00f7bba9ab91f0969c
https://github.com/scummvm/scummvm/commit/70e2ca433c0580d719951b00f7bba9ab91f0969c
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-24T15:10:13+08:00
Commit Message:
GRAPHICS: MACGUI: fix rendering text shadow with non-black text.
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 915f05aa09..545b0e5be6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -186,6 +186,7 @@ void MacText::init() {
_textMaxWidth = 0;
_textMaxHeight = 0;
_surface = nullptr;
+ _shadowSurface = nullptr;
if (!_fixedDims) {
int right = _dims.right;
@@ -255,6 +256,7 @@ MacText::~MacText() {
delete _cursorRect;
delete _surface;
+ delete _shadowSurface;
delete _cursorSurface;
delete _cursorSurface2;
}
@@ -842,6 +844,9 @@ void MacText::reallocSurface() {
if (!_surface) {
_surface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ if (_textShadow)
+ _shadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+
return;
}
@@ -853,31 +858,35 @@ void MacText::reallocSurface() {
delete _surface;
_surface = n;
+
+ // same as shadow surface
+ if (_textShadow) {
+ ManagedSurface *newShadowSurface = new ManagedSurface(_maxWidth, _textMaxHeight, _wm->_pixelformat);
+ newShadowSurface->clear(_bgcolor);
+ newShadowSurface->blitFrom(*_shadowSurface, Common::Point(0, 0));
+
+ delete _shadowSurface;
+ _shadowSurface = newShadowSurface;
+ }
}
}
void MacText::render() {
if (_fullRefresh) {
_surface->clear(_bgcolor);
+ if (_textShadow)
+ _shadowSurface->clear(_bgcolor);
+
render(0, _textLines.size());
_fullRefresh = false;
}
}
-void MacText::render(int from, int to) {
- if (_textLines.empty())
- return;
-
- reallocSurface();
-
- from = MAX<int>(0, from);
- to = MIN<int>(to, _textLines.size() - 1);
+void MacText::render(int from, int to, int shadow) {
int w = MIN(_maxWidth, _textMaxWidth);
-
- // Clear the screen
- _surface->fillRect(Common::Rect(0, _textLines[from].y, _surface->w, _textLines[to].y + getLineHeight(to)), _bgcolor);
+ ManagedSurface *surface = shadow ? _shadowSurface : _surface;
for (int i = from; i <= to; i++) {
int xOffset = getAlignOffset(i);
@@ -906,14 +915,33 @@ void MacText::render(int from, int to) {
if (_textLines[i].chunks[j].plainByteMode()) {
Common::String str = _textLines[i].chunks[j].getEncodedText();
- _textLines[i].chunks[j].getFont()->drawString(_surface, str, xOffset, _textLines[i].y + yOffset, w, _textLines[i].chunks[j].fgcolor);
+ _textLines[i].chunks[j].getFont()->drawString(surface, str, xOffset, _textLines[i].y + yOffset, w, shadow ? _wm->_colorBlack : _textLines[i].chunks[j].fgcolor);
xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(str);
} else {
- _textLines[i].chunks[j].getFont()->drawString(_surface, convertBiDiU32String(_textLines[i].chunks[j].text), xOffset, _textLines[i].y + yOffset, w, _textLines[i].chunks[j].fgcolor);
+ _textLines[i].chunks[j].getFont()->drawString(surface, convertBiDiU32String(_textLines[i].chunks[j].text), xOffset, _textLines[i].y + yOffset, w, shadow ? _wm->_colorBlack : _textLines[i].chunks[j].fgcolor);
xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(_textLines[i].chunks[j].text);
}
}
}
+}
+
+void MacText::render(int from, int to) {
+ if (_textLines.empty())
+ return;
+
+ reallocSurface();
+
+ from = MAX<int>(0, from);
+ to = MIN<int>(to, _textLines.size() - 1);
+
+ // Clear the screen
+ _surface->fillRect(Common::Rect(0, _textLines[from].y, _surface->w, _textLines[to].y + getLineHeight(to)), _bgcolor);
+
+ // render the shadow surface;
+ if (_textShadow)
+ render(from, to, _textShadow);
+
+ render(from, to, 0);
for (uint i = 0; i < _textLines.size(); i++) {
debugN(9, "MacText::render: %2d ", i);
@@ -1247,11 +1275,11 @@ void MacText::draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int
if (x + w < _surface->w || y + h < _surface->h)
g->fillRect(Common::Rect(x + xoff, y + yoff, x + w + xoff, y + h + yoff), _bgcolor);
- g->blitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff, yoff));
-
+ // blit shadow surface first
if (_textShadow)
- g->transBlitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow), 0xff);
+ g->blitFrom(*_shadowSurface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff + _textShadow, yoff + _textShadow));
+ g->transBlitFrom(*_surface, Common::Rect(MIN<int>(_surface->w, x), MIN<int>(_surface->h, y), MIN<int>(_surface->w, x + w), MIN<int>(_surface->h, y + h)), Common::Point(xoff, yoff), 0xff);
_contentIsDirty = false;
_cursorDirty = false;
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 2c5f28ea7d..fc1e9ce7e1 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -295,6 +295,7 @@ private:
void chopChunk(const Common::U32String &str, int *curLine);
void splitString(const Common::U32String &str, int curLine = -1);
+ void render(int from, int to, int shadow);
void render(int from, int to);
void recalcDims();
void reallocSurface();
@@ -338,6 +339,7 @@ protected:
int _textMaxHeight;
ManagedSurface *_surface;
+ ManagedSurface *_shadowSurface;
TextAlign _textAlignment;
Commit: 091e49fb663b21231dde7809736c536e0793eac8
https://github.com/scummvm/scummvm/commit/091e49fb663b21231dde7809736c536e0793eac8
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-07-24T16:38:57+08:00
Commit Message:
GRAPHICS: MACGUI: implement checked item for macmenu
Changed paths:
graphics/macgui/macmenu.cpp
graphics/macgui/macmenu.h
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
index 206d915d2a..e1dde0ccf4 100644
--- a/graphics/macgui/macmenu.cpp
+++ b/graphics/macgui/macmenu.cpp
@@ -86,16 +86,17 @@ struct MacMenuItem {
char shortcut;
int shortcutPos;
bool enabled;
+ bool checked;
Common::Rect bbox;
MacMenuSubMenu *submenu;
- MacMenuItem(const Common::String &t, int a = -1, int s = 0, char sh = 0, int sp = -1, bool e = true) :
+ MacMenuItem(const Common::String &t, int a = -1, int s = 0, char sh = 0, int sp = -1, bool e = true, bool c = false) :
text(t), unicode(false), action(a), style(s), shortcut(sh),
- shortcutPos(sp), enabled(e), submenu(nullptr) {}
- MacMenuItem(const Common::U32String &t, int a = -1, int s = 0, char sh = 0, int sp = -1, bool e = true) :
+ shortcutPos(sp), enabled(e), submenu(nullptr), checked(c) {}
+ MacMenuItem(const Common::U32String &t, int a = -1, int s = 0, char sh = 0, int sp = -1, bool e = true, bool c = false) :
unicodeText(t), unicode(true), action(a), style(s), shortcut(sh),
- shortcutPos(sp), enabled(e), submenu(nullptr) {}
+ shortcutPos(sp), enabled(e), submenu(nullptr), checked(c) {}
~MacMenuItem() {
if (submenu)
@@ -358,7 +359,7 @@ MacMenuSubMenu *MacMenu::getSubmenu(MacMenuSubMenu *submenu, int index) {
}
}
-int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::String &text, int action, int style, char shortcut, bool enabled) {
+int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::String &text, int action, int style, char shortcut, bool enabled, bool checked) {
_dimensionsDirty = true;
if (submenu == nullptr) {
@@ -370,12 +371,12 @@ int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::String &text, in
_dimensionsDirty = true;
- submenu->items.push_back(new MacMenuItem(text, action, style, shortcut, -1, enabled));
+ submenu->items.push_back(new MacMenuItem(text, action, style, shortcut, -1, enabled, checked));
return submenu->items.size() - 1;
}
-int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::U32String &text, int action, int style, char shortcut, bool enabled) {
+int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::U32String &text, int action, int style, char shortcut, bool enabled, bool checked) {
_dimensionsDirty = true;
Common::U32String amp("&");
@@ -402,7 +403,7 @@ int MacMenu::addMenuItem(MacMenuSubMenu *submenu, const Common::U32String &text,
return _items.size() - 1;
}
- submenu->items.push_back(new MacMenuItem(res, action, style, shortcut, shortcutPos, enabled));
+ submenu->items.push_back(new MacMenuItem(res, action, style, shortcut, shortcutPos, enabled, checked));
return submenu->items.size() - 1;
}
@@ -531,6 +532,7 @@ void MacMenu::createSubMenuFromString(int id, const char *str, int commandId) {
addMenuItem(submenu, NULL, 0);
} else {
bool enabled = true;
+ bool checked = false;
int style = 0;
char shortcut = 0;
const char *shortPtr = strrchr(item.c_str(), '/');
@@ -575,9 +577,13 @@ void MacMenu::createSubMenuFromString(int id, const char *str, int commandId) {
item.deleteChar(j);
break;
}
+ } else if (tmpitem.size() >= 2 && tmpitem[0] == '!' && (uint8)tmpitem[1] == 195) {
+ // this is the !â situation, we need to set item checked, 195 represent â in director
+ checked = true;
+ item = item.substr(2, Common::String::npos);
}
- addMenuItem(submenu, item, commandId, style, shortcut, enabled);
+ addMenuItem(submenu, item, commandId, style, shortcut, enabled, checked);
}
item.clear();
@@ -942,6 +948,16 @@ void MacMenu::renderSubmenu(MacMenuSubMenu *menu, bool recursive) {
font->drawString(s, text, tx, ty, r->width(), color);
}
+ if (menu->items[i]->checked) {
+ const Font *font = getMenuFont(menu->items[i]->style);
+
+ int padding = _align == kTextAlignRight ? -_menuRightDropdownPadding: _menuLeftDropdownPadding;
+ int offset = padding - font->getCharWidth(195);
+
+ // calculating the padding and offset, we draw the â at the center
+ font->drawChar(s, 195, tx - padding + offset, ty, color);
+ }
+
if (!acceleratorText.empty() && shortcutPos == -1)
_font->drawString(s, acceleratorText, accelX, ty, r->width(), color);
diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
index 5efb5011e4..852169fcd8 100644
--- a/graphics/macgui/macmenu.h
+++ b/graphics/macgui/macmenu.h
@@ -68,8 +68,8 @@ public:
void calcDimensions();
MacMenuSubMenu *addSubMenu(MacMenuSubMenu *submenu, int index = -1);
- int addMenuItem(MacMenuSubMenu *submenu, const Common::String &text, int action = -1, int style = 0, char shortcut = 0, bool enabled = true);
- int addMenuItem(MacMenuSubMenu *submenu, const Common::U32String &text, int action = 0, int style = 0, char shortcut = 0, bool enabled = true);
+ int addMenuItem(MacMenuSubMenu *submenu, const Common::String &text, int action = -1, int style = 0, char shortcut = 0, bool enabled = true, bool checked = false);
+ int addMenuItem(MacMenuSubMenu *submenu, const Common::U32String &text, int action = 0, int style = 0, char shortcut = 0, bool enabled = true, bool checked = false);
void loadMenuResource(Common::MacResManager *resFork, uint16 id);
void loadMenuBarResource(Common::MacResManager *resFork, uint16 id);
void createSubMenuFromString(int id, const char *string, int commandId);
More information about the Scummvm-git-logs
mailing list