[Scummvm-cvs-logs] scummvm master -> 866650fccdd3bc94efbb7c13bc881bc960010370

sev- sev at scummvm.org
Thu Apr 14 12:08:35 CEST 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
866650fccd WAGE: Draw border in MacWindow


Commit: 866650fccdd3bc94efbb7c13bc881bc960010370
    https://github.com/scummvm/scummvm/commit/866650fccdd3bc94efbb7c13bc881bc960010370
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-04-14T12:08:27+02:00

Commit Message:
WAGE: Draw border in MacWindow

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/macwindow.cpp
    engines/wage/macwindow.h
    engines/wage/macwindowmanager.cpp
    engines/wage/wage.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index ae4995a..00b7e24 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -55,6 +55,8 @@
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
+#include "wage/macwindow.h"
+#include "wage/macwindowmanager.h"
 #include "wage/menu.h"
 #include "wage/gui.h"
 #include "wage/world.h"
@@ -65,7 +67,8 @@ static const byte palette[] = {
 	0, 0, 0,           // Black
 	0x80, 0x80, 0x80,  // Gray
 	0xff, 0xff, 0xff,  // White
-	0x00, 0xff, 0x00   // Green
+	0x00, 0xff, 0x00,  // Green
+	0x00, 0x7f, 0x00   // Green2
 };
 
 static byte fillPatterns[][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, // kPatternSolid
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index fac41ce..c1f8b83 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -68,7 +68,6 @@ enum {
 	kMenuDropdownPadding = 14,
 	kMenuDropdownItemHeight = 16,
 	kMenuItemHeight = 20,
-	kBorderWidth = 17,
 	kDesktopArc = 7,
 	kComponentsPadding = 10,
 	kCursorHeight = 12
@@ -81,13 +80,6 @@ enum {
 	kPatternCheckers2 = 4
 };
 
-enum {
-	kBorderNone = 0,
-	kBorderScrollUp,
-	kBorderScrollDown,
-	kBorderCloseButton
-};
-
 class Gui {
 public:
 	Gui(WageEngine *engine);
@@ -117,6 +109,8 @@ public:
 	void disableAllMenus();
 	void enableNewGameMenus();
 
+	bool builtInFonts() { return _builtInFonts; }
+
 private:
 	void drawScene();
 	void drawConsole();
diff --git a/engines/wage/macwindow.cpp b/engines/wage/macwindow.cpp
index 99d0ad0..a945589 100644
--- a/engines/wage/macwindow.cpp
+++ b/engines/wage/macwindow.cpp
@@ -45,13 +45,21 @@
  *
  */
 
+#include "graphics/primitives.h"
+
+#include "wage/wage.h"
+#include "wage/gui.h"
 #include "wage/macwindow.h"
 
 namespace Wage {
 
-MacWindow::MacWindow(bool scrollable, int id) : _scrollable(scrollable), _id(id) {
+MacWindow::MacWindow(bool scrollable) : _scrollable(scrollable) {
 	_active = false;
 	_borderIsDirty = true;
+
+	_highlightedPart = kBorderNone;
+
+	_scrollPos = _scrollSize = 0.0;
 }
 
 MacWindow::~MacWindow() {
@@ -67,24 +75,144 @@ void MacWindow::setActive(bool active) {
 
 void MacWindow::resize(int w, int h) {
 	_surface.free();
-
 	_surface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_borderSurface.free();
+	_borderSurface.create(w + 2 * kBorderWidth, h + 2 * kBorderWidth, Graphics::PixelFormat::createFormatCLUT8());
 
 	_dims.setWidth(w);
 	_dims.setHeight(h);
+
+	_borderDims.setWidth(w + 2 * kBorderWidth);
+	_borderDims.setHeight(h + 2 * kBorderWidth);
+	move(_dims.left, _dims.top); // Update _borderDims position
 }
 
 void MacWindow::move(int x, int y) {
 	_dims.moveTo(x, y);
+	_borderDims.moveTo(x - kBorderWidth, y - kBorderWidth);
 }
 
-void MacWindow::draw(Graphics::Surface *g) {
-	if (_borderIsDirty)
+void MacWindow::draw(Graphics::Surface *g, bool forceRedraw) {
+	if (_borderIsDirty || forceRedraw)
 		drawBorder();
 }
 
+const Graphics::Font *MacWindow::getTitleFont() {
+	return ((WageEngine *)g_engine)->_gui->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
+}
+
+bool MacWindow::builtInFonts() {
+	return ((WageEngine *)g_engine)->_gui->builtInFonts();
+}
+
+#define ARROW_W 12
+#define ARROW_H 6
+const int arrowPixels[ARROW_H][ARROW_W] = {
+		{0,0,0,0,0,1,1,0,0,0,0,0},
+		{0,0,0,0,1,1,1,1,0,0,0,0},
+		{0,0,0,1,1,1,1,1,1,0,0,0},
+		{0,0,1,1,1,1,1,1,1,1,0,0},
+		{0,1,1,1,1,1,1,1,1,1,1,0},
+		{1,1,1,1,1,1,1,1,1,1,1,1}};
+
+static void drawPixelInverted(int x, int y, int color, void *data) {
+	Graphics::Surface *surface = (Graphics::Surface *)data;
+
+	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
+		byte *p = (byte *)surface->getBasePtr(x, y);
+
+		*p = *p == kColorWhite ? kColorBlack : kColorWhite;
+	}
+}
+
 void MacWindow::drawBorder() {
 	_borderIsDirty = false;
+
+	bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = _title.empty();
+	const int size = kBorderWidth;
+	int x = 0;
+	int y = 0;
+	int width = _borderSurface.w;
+	int height = _borderSurface.h;
+	Graphics::ManagedSurface *g = &_borderSurface;
+
+	g->fillRect(_borderDims, kColorGreen2);
+
+	drawBox(g, x,                    y,                     size,                 size);
+	drawBox(g, x + width - size - 1, y,                     size,                 size);
+	drawBox(g, x + width - size - 1, y + height - size - 1, size,                 size);
+	drawBox(g, x,                    y + height - size - 1, size,                 size);
+	drawBox(g, x + size,             y + 2,                 width - 2 * size - 1, size - 4);
+	drawBox(g, x + size,             y + height - size + 1, width - 2 * size - 1, size - 4);
+	drawBox(g, x + 2,                y + size,              size - 4,             height - 2 * size - 1);
+	drawBox(g, x + width - size + 1, y + size,              size - 4,             height - 2 * size - 1);
+
+	if (active) {
+		fillRect(g, x + size, y + 5,           width - 2 * size - 1, 8);
+		fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8);
+		fillRect(g, x + 5,    y + size,        8,                    height - 2 * size - 1);
+		if (!scrollable) {
+			fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1);
+		} else {
+			int x1 = x + width - 15;
+			int y1 = y + size + 1;
+
+			for (int yy = 0; yy < ARROW_H; yy++) {
+				for (int xx = 0; xx < ARROW_W; xx++)
+					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite));
+			}
+
+			fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2);
+
+			y1 += height - 2 * size - ARROW_H - 2;
+			for (int yy = 0; yy < ARROW_H; yy++) {
+				for (int xx = 0; xx < ARROW_W; xx++)
+					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? kColorBlack : kColorWhite));
+			}
+
+			if (_highlightedPart == kBorderScrollUp || _highlightedPart == kBorderScrollDown) {
+				int rx1 = x + width - kBorderWidth + 2;
+				int ry1 = y + size + _dims.height() * _scrollPos;
+				int rx2 = rx1 + size - 4;
+				int ry2 = ry1 + _dims.height() * _scrollSize;
+				Common::Rect rr(rx1, ry1, rx2, ry2);
+
+				Graphics::drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
+			}
+		}
+		if (closeable) {
+			if (_highlightedPart == kBorderCloseButton) {
+				fillRect(g, x + 6, y + 6, 6, 6);
+			} else {
+				drawBox(g, x + 5, y + 5, 7, 7);
+			}
+		}
+	}
+
+	if (drawTitle) {
+		const Graphics::Font *font = getTitleFont();
+		int yOff = builtInFonts() ? 3 : 1;
+
+		int w = font->getStringWidth(_title) + 10;
+		int maxWidth = width - size * 2 - 7;
+		if (w > maxWidth)
+			w = maxWidth;
+		drawBox(g, x + (width - w) / 2, y, w, size);
+		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
+	}
+}
+
+void MacWindow::drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h) {
+	Common::Rect r(x, y, x + w + 1, y + h + 1);
+
+	g->fillRect(r, kColorWhite);
+	g->frameRect(r, kColorBlack);
+}
+
+void MacWindow::fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color) {
+	Common::Rect r(x, y, x + w, y + h);
+
+	g->fillRect(r, color);
 }
 
 } // End of namespace Wage
diff --git a/engines/wage/macwindow.h b/engines/wage/macwindow.h
index 44f25b6..6af2db2 100644
--- a/engines/wage/macwindow.h
+++ b/engines/wage/macwindow.h
@@ -57,28 +57,51 @@ enum WindowType {
 	kWindowConsole
 };
 
+enum {
+	kBorderWidth = 17
+};
+
+enum BorderHighlight {
+	kBorderNone = 0,
+	kBorderScrollUp,
+	kBorderScrollDown,
+	kBorderCloseButton
+};
+
 class MacWindow {
 public:
-	MacWindow(bool scrollable, int id);
+	MacWindow(bool scrollable);
 	~MacWindow();
 	void move(int x, int y);
 	void resize(int w, int h);
-	void draw(Graphics::Surface *g);
+	void draw(Graphics::Surface *g, bool forceRedraw = false);
 	void setActive(bool active);
 	Graphics::ManagedSurface *getSurface() { return &_surface; }
+	void setTitle(Common::String &title) { _title = title; }
+	void setHighlight(BorderHighlight highlightedPart) { _highlightedPart = highlightedPart; }
+	void setScroll(float scrollPos, float scrollSize) { _scrollPos = scrollPos; _scrollSize = scrollSize; }
 
 private:
 	void drawBorder();
+	void drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h);
+	void fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color = kColorBlack);
+	const Graphics::Font *getTitleFont();
+	bool builtInFonts();
 
 private:
 	Graphics::ManagedSurface _surface;
 	Graphics::ManagedSurface _borderSurface;
 	bool _scrollable;
-	int _id;
 	bool _active;
 	bool _borderIsDirty;
 
+	BorderHighlight _highlightedPart;
+	float _scrollPos, _scrollSize;
+
 	Common::Rect _dims;
+	Common::Rect _borderDims;
+
+	Common::String _title;
 };
 
 } // End of namespace Wage
diff --git a/engines/wage/macwindowmanager.cpp b/engines/wage/macwindowmanager.cpp
index 5717361..14c3f23 100644
--- a/engines/wage/macwindowmanager.cpp
+++ b/engines/wage/macwindowmanager.cpp
@@ -49,6 +49,8 @@
 #include "common/array.h"
 
 #include "graphics/surface.h"
+
+#include "wage/wage.h"
 #include "wage/macwindow.h"
 #include "wage/macwindowmanager.h"
 
@@ -65,7 +67,7 @@ MacWindowManager::~MacWindowManager() {
 }
 
 int MacWindowManager::add(bool scrollable) {
-    MacWindow *w = new MacWindow(scrollable, _lastId);
+    MacWindow *w = new MacWindow(scrollable);
 
     _windows.push_back(w);
     _windowStack.push_back(w);
@@ -93,12 +95,10 @@ void MacWindowManager::setActive(int id) {
 }
 
 void MacWindowManager::draw(Graphics::Surface *g) {
-    if (_fullRefresh) {
-        for (Common::List<MacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++)
-            (*it)->draw(g);
-    } else {
-        _windowStack.back()->draw(g);
-    }
+    for (Common::List<MacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++)
+        (*it)->draw(g, _fullRefresh);
+
+    _fullRefresh = false;
 }
 
 } // End of namespace Wage
diff --git a/engines/wage/wage.h b/engines/wage/wage.h
index a0be7a7..87009c2 100644
--- a/engines/wage/wage.h
+++ b/engines/wage/wage.h
@@ -104,10 +104,11 @@ enum {
 };
 
 enum {
-	kColorBlack = 0,
-	kColorGray  = 1,
-	kColorWhite = 2,
-	kColorGreen = 3
+	kColorBlack  = 0,
+	kColorGray   = 1,
+	kColorWhite  = 2,
+	kColorGreen  = 3,
+	kColorGreen2 = 4
 };
 
 Common::String readPascalString(Common::SeekableReadStream *in);






More information about the Scummvm-git-logs mailing list