aboutsummaryrefslogtreecommitdiff
path: root/engines/pink/objects
diff options
context:
space:
mode:
authorAndrei Prykhodko2018-07-29 21:22:01 +0300
committerAndrei Prykhodko2018-07-29 21:23:04 +0300
commitbb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d (patch)
tree321912f0e63e4aa25b87fa7a37bb0d7981ddae9c /engines/pink/objects
parent75eceedfa515c652d0698de11a9f605fe23c336d (diff)
downloadscummvm-rg350-bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d.tar.gz
scummvm-rg350-bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d.tar.bz2
scummvm-rg350-bb732cd9c8675a4ea09bd6f2e491e4ea471a1c1d.zip
PINK: add partial implementation of ActionText
Diffstat (limited to 'engines/pink/objects')
-rw-r--r--engines/pink/objects/actions/action_text.cpp88
-rw-r--r--engines/pink/objects/actions/action_text.h22
2 files changed, 105 insertions, 5 deletions
diff --git a/engines/pink/objects/actions/action_text.cpp b/engines/pink/objects/actions/action_text.cpp
index 1af06d5e82..174ad8c65f 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 bcf0a3520f..6a3a96642d 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