[Scummvm-git-logs] scummvm master -> bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d
whiterandrek
whiterandrek at gmail.com
Sun Jul 29 20:23:13 CEST 2018
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
841e0c11d8 GRAPHICS: MACGUI: fixed SIGSEGV when ptr to menu in MacTextWindow is NULL
75eceedfa5 GRAPHICS: MACGUI: add additional arg to MacTextWindow's constructor to disable cursor handler
bb732cd9c8 PINK: add partial implementation of ActionText
Commit: 841e0c11d82fe784b9153d0cb6fff3063969ca41
https://github.com/scummvm/scummvm/commit/841e0c11d82fe784b9153d0cb6fff3063969ca41
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2018-07-29T21:23:04+03:00
Commit Message:
GRAPHICS: MACGUI: fixed SIGSEGV when ptr to menu in MacTextWindow is NULL
Changed paths:
graphics/macgui/mactextwindow.cpp
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index b43948a..5535923 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -356,7 +356,7 @@ bool MacTextWindow::processEvent(Common::Event &event) {
startMarking(event.mouse.x, event.mouse.y);
return true;
- } else if (event.type == Common::EVENT_LBUTTONUP) {
+ } else if (event.type == Common::EVENT_LBUTTONUP && _menu) {
if (_inTextSelection) {
_inTextSelection = false;
Commit: 75eceedfa515c652d0698de11a9f605fe23c336d
https://github.com/scummvm/scummvm/commit/75eceedfa515c652d0698de11a9f605fe23c336d
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2018-07-29T21:23:04+03:00
Commit Message:
GRAPHICS: MACGUI: add additional arg to MacTextWindow's constructor to disable cursor handler
Changed paths:
graphics/macgui/mactextwindow.cpp
graphics/macgui/mactextwindow.h
graphics/macgui/macwindowmanager.cpp
graphics/macgui/macwindowmanager.h
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index 5535923..8aabaed 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -43,7 +43,7 @@ enum {
static void cursorTimerHandler(void *refCon);
-MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu) :
+MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler) :
MacWindow(wm->getLastId(), true, true, true, wm) {
_font = font;
@@ -72,7 +72,8 @@ MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgco
_cursorSurface = new ManagedSurface(1, kCursorHeight);
_cursorSurface->fillRect(*_cursorRect, _wm->_colorBlack);
- g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "textWindowCursor");
+ if (cursorHandler)
+ g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "textWindowCursor");
}
void MacTextWindow::resize(int w, int h) {
diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h
index 5791da3..942fdd4 100644
--- a/graphics/macgui/mactextwindow.h
+++ b/graphics/macgui/mactextwindow.h
@@ -48,7 +48,7 @@ struct SelectedText {
class MacTextWindow : public MacWindow {
public:
- MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu);
+ MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler = true);
virtual ~MacTextWindow();
virtual void resize(int w, int h);
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index e37332c..57da022 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -201,8 +201,8 @@ MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool edi
return w;
}
-MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu) {
- MacTextWindow *w = new MacTextWindow(this, font, fgcolor, bgcolor, maxWidth, textAlignment, menu);
+MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler) {
+ MacTextWindow *w = new MacTextWindow(this, font, fgcolor, bgcolor, maxWidth, textAlignment, menu, cursorHandler);
addWindowInitialized(w);
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 0a8a5a4..97272d3 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -115,7 +115,7 @@ public:
* @return Pointer to the newly created window.
*/
MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
- MacTextWindow *addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu);
+ MacTextWindow *addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, bool cursorHandler = true);
/**
* Adds a window that has already been initialized to the registry.
Commit: bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d
https://github.com/scummvm/scummvm/commit/bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2018-07-29T21:23:04+03:00
Commit Message:
PINK: add partial implementation of ActionText
Changed paths:
engines/pink/director.cpp
engines/pink/director.h
engines/pink/objects/actions/action_text.cpp
engines/pink/objects/actions/action_text.h
diff --git a/engines/pink/director.cpp b/engines/pink/director.cpp
index 0bd707b..eef2506 100644
--- a/engines/pink/director.cpp
+++ b/engines/pink/director.cpp
@@ -20,13 +20,15 @@
*
*/
-#include "graphics/managed_surface.h"
+#include "graphics/macgui/macfontmanager.h"
+#include "graphics/macgui/mactext.h"
#include "graphics/palette.h"
#include "pink/cel_decoder.h"
#include "pink/director.h"
#include "pink/objects/actions/action_sound.h"
#include "pink/objects/actions/action_cel.h"
+#include "pink/objects/actions/action_text.h"
#include "pink/objects/actors/actor.h"
#include "graphics/macgui/macmenu.h"
@@ -78,7 +80,7 @@ static const Graphics::MacMenuData menuSubItems[] = {
*/
Director::Director()
- : _surface(640, 480) {
+ : _surface(640, 480), _textRendered(false) {
_wm.setScreen(&_surface);
_wm.setMode(Graphics::kWMModeNoDesktop | Graphics::kWMModeAutohideMenu | Graphics::kWMModalMenuMode);
_wm.setMenuHotzone(Common::Rect(0, 0, 640, 23));
@@ -116,6 +118,19 @@ void Director::setPalette(const byte *palette) {
_wm.passPalette(palette, 256);
}
+void Director::addTextAction(ActionText *txt) {
+ _textActions.push_back(txt);
+ _textRendered = false;
+}
+
+void Director::removeTextAction(ActionText *action) {
+ for (uint i = 0; i < _textActions.size(); ++i) {
+ if (_textActions[i] == action) {
+ _textActions.remove_at(i);
+ break;
+ }
+ }
+}
void Director::addSprite(ActionCEL *sprite) {
_sprites.push_back(sprite);
@@ -188,13 +203,20 @@ Actor *Director::getActorByPoint(const Common::Point point) {
}
void Director::draw() {
- if (!_dirtyRects.empty()) {
+ if (!_dirtyRects.empty() || !_textRendered) {
mergeDirtyRects();
for (uint i = 0; i < _dirtyRects.size(); ++i) {
drawRect(_dirtyRects[i]);
}
+ if (!_textRendered) {
+ _textRendered = true;
+ for (uint i = 0; i < _textActions.size(); ++i) {
+ _textActions[i]->draw(&_surface);
+ }
+ }
+
_dirtyRects.resize(0);
_surface.update();
} else
@@ -253,4 +275,4 @@ void Director::drawRect(const Common::Rect &rect) {
}
}
-}
+} // End of namespace Pink
diff --git a/engines/pink/director.h b/engines/pink/director.h
index 7a5b57c..7273b65 100644
--- a/engines/pink/director.h
+++ b/engines/pink/director.h
@@ -43,6 +43,7 @@ namespace Pink {
class Actor;
class ActionCEL;
class ActionSound;
+class ActionText;
class Director {
public:
@@ -53,6 +54,9 @@ public:
void setPalette(const byte *palette);
+ void addTextAction(ActionText *action);
+ void removeTextAction(ActionText *action);
+
void addSprite(ActionCEL *sprite);
void removeSprite(ActionCEL *sprite);
@@ -85,6 +89,8 @@ private:
Common::Array<ActionCEL *> _sprites;
Common::Array<ActionCEL *> _savedSprites;
Common::Array<ActionSound *> _sounds;
+ Common::Array<ActionText *> _textActions;
+ bool _textRendered;
};
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_text.cpp b/engines/pink/objects/actions/action_text.cpp
index 1af06d5..174ad8c 100644
--- a/engines/pink/objects/actions/action_text.cpp
+++ b/engines/pink/objects/actions/action_text.cpp
@@ -21,15 +21,37 @@
*/
#include "common/debug.h"
+#include "common/substream.h"
#include "pink/archive.h"
#include "pink/director.h"
#include "pink/pink.h"
#include "pink/objects/actors/actor.h"
#include "pink/objects/actions/action_text.h"
+#include "pink/objects/pages/page.h"
namespace Pink {
+ActionText::ActionText() {
+ _txtWnd = nullptr;
+
+ _xLeft = _xRight = 0;
+ _yTop = _yBottom = 0;
+
+ _centered = 0;
+ _scrollBar = 0;
+
+ _textRGB = 0;
+ _backgroundRGB = 0;
+
+ _textColorIndex = 0;
+ _backgroundColorIndex = 0;
+}
+
+ActionText::~ActionText() {
+ end();
+}
+
void ActionText::deserialize(Archive &archive) {
Action::deserialize(archive);
_fileName = archive.readString();
@@ -41,22 +63,82 @@ void ActionText::deserialize(Archive &archive) {
_centered = archive.readDWORD();
_scrollBar = archive.readDWORD();
- _textColor = archive.readDWORD();
- _backgroundColor = archive.readDWORD();
+ _textRGB = archive.readDWORD();
+ _backgroundRGB = archive.readDWORD();
}
void ActionText::toConsole() {
debugC(6, kPinkDebugLoadingObjects, "\tActionText: _name = %s, _fileName = %s, "
"_xLeft = %u, _yTop = %u, _xRight = %u, _yBottom = %u _centered = %u, _scrollBar = %u, _textColor = %u _backgroundColor = %u",
- _name.c_str(), _fileName.c_str(), _xLeft, _yTop, _xRight, _yBottom, _centered, _scrollBar, _textColor, _backgroundColor);
+ _name.c_str(), _fileName.c_str(), _xLeft, _yTop, _xRight, _yBottom, _centered, _scrollBar, _textRGB, _backgroundRGB);
}
void ActionText::start() {
+ findColorsInPalette();
+ Director *director = _actor->getPage()->getGame()->getDirector();
+ Graphics::TextAlign align = _centered ? Graphics::kTextAlignCenter : Graphics::kTextAlignLeft;
+
+ if (_scrollBar) {
+ Graphics::MacFont *font = new Graphics::MacFont;
+ _txtWnd = director->getWndManager().addTextWindow(font, _textColorIndex, _backgroundColorIndex,
+ _xRight - _xLeft, align, nullptr, false);
+ _txtWnd->move(_xLeft, _yTop);
+ _txtWnd->resize(_xRight - _xLeft, _yBottom - _yTop);
+ _txtWnd->appendText("Testing ActionText", font);
+ } else {
+ director->addTextAction(this);
+ }
}
void ActionText::end() {
+ Director *director = _actor->getPage()->getGame()->getDirector();
+ if (_scrollBar && _txtWnd) {
+ director->getWndManager().removeWindow(_txtWnd);
+ _txtWnd = nullptr;
+ } else {
+ director->removeTextAction(this);
+ }
+}
+
+void ActionText::draw(Graphics::ManagedSurface *surface) {
+ // not working
+ /*Graphics::TextAlign alignment = _centered ? Graphics::kTextAlignCenter : Graphics::kTextAlignLeft;
+ Graphics::MacFont *font = new Graphics::MacFont;
+ Director *director = _actor->getPage()->getGame()->getDirector();
+ Graphics::MacText text("", &director->getWndManager(), font, _textColorIndex, _backgroundColorIndex, _xRight - _xLeft, alignment);
+ text.appendText("TESTING", font->getId(), font->getSize(), font->getSlant(), 0);
+ text.draw(surface, _xLeft, _yTop, _xRight - _xLeft, _yBottom - _yTop, 0, 0);*/
+}
+
+#define RED(rgb) ((rgb) & 0xFF)
+#define GREEN(rgb) (((rgb) >> 8) & 0xFF)
+#define BLUE(rgb) (((rgb) >> 16) & 0xFF)
+
+static uint findBestColor(byte *palette, uint32 rgb) {
+ uint bestColor = 0;
+ double min = 0xFFFFFFFF;
+ for (uint i = 0; i < 256; ++i) {
+ int rmean = (*(palette + 3 * i + 0) + RED(rgb)) / 2;
+ int r = *(palette + 3 * i + 0) - RED(rgb);
+ int g = *(palette + 3 * i + 1) - GREEN(rgb);
+ int b = *(palette + 3 * i + 2) - BLUE(rgb);
+
+ double dist = sqrt((((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8));
+ if (min > dist) {
+ bestColor = i;
+ min = dist;
+ }
+ }
+ return bestColor;
+}
+
+void ActionText::findColorsInPalette() {
+ byte palette[256 * 3];
+ g_system->getPaletteManager()->grabPalette(palette, 0, 255);
+ _textColorIndex = findBestColor(palette, _textRGB);
+ _backgroundColorIndex = findBestColor(palette, _backgroundRGB);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_text.h b/engines/pink/objects/actions/action_text.h
index bcf0a35..6a3a966 100644
--- a/engines/pink/objects/actions/action_text.h
+++ b/engines/pink/objects/actions/action_text.h
@@ -23,12 +23,20 @@
#ifndef PINK_ACTION_TEXT_H
#define PINK_ACTION_TEXT_H
+#include "common/events.h"
+
+#include "graphics/macgui/macwindow.h"
+#include "graphics/macgui/macmenu.h"
+#include "graphics/macgui/mactextwindow.h"
+
#include "pink/objects/actions/action.h"
namespace Pink {
class ActionText : public Action {
public:
+ ActionText();
+ ~ActionText() override;
void deserialize(Archive &archive) override;
void toConsole() override;
@@ -36,8 +44,15 @@ public:
void start() override;
void end() override;
+ void draw(Graphics::ManagedSurface *surface); // only for non-scrollable text
+
+private:
+
+ void findColorsInPalette();
+
private:
Common::String _fileName;
+ Graphics::MacTextWindow *_txtWnd;
uint32 _xLeft;
uint32 _yTop;
@@ -46,8 +61,11 @@ private:
uint32 _centered;
uint32 _scrollBar;
- uint32 _textColor;
- uint32 _backgroundColor;
+ uint32 _textRGB;
+ uint32 _backgroundRGB;
+
+ byte _textColorIndex;
+ byte _backgroundColorIndex;
};
} // End of namespace Pink
More information about the Scummvm-git-logs
mailing list