[Scummvm-cvs-logs] SF.net SVN: scummvm:[47009] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Jan 5 02:37:58 CET 2010


Revision: 47009
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47009&view=rev
Author:   thebluegr
Date:     2010-01-05 01:37:57 +0000 (Tue, 05 Jan 2010)

Log Message:
-----------
More renaming

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kevent.cpp
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/engine/kmenu.cpp
    scummvm/trunk/engines/sci/engine/kmovement.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/event.cpp
    scummvm/trunk/engines/sci/graphics/gui.cpp
    scummvm/trunk/engines/sci/graphics/gui.h
    scummvm/trunk/engines/sci/module.mk
    scummvm/trunk/engines/sci/resource.h
    scummvm/trunk/engines/sci/sci.cpp

Added Paths:
-----------
    scummvm/trunk/engines/sci/graphics/animate.cpp
    scummvm/trunk/engines/sci/graphics/animate.h
    scummvm/trunk/engines/sci/graphics/controls.cpp
    scummvm/trunk/engines/sci/graphics/controls.h
    scummvm/trunk/engines/sci/graphics/cursor.cpp
    scummvm/trunk/engines/sci/graphics/cursor.h
    scummvm/trunk/engines/sci/graphics/font.cpp
    scummvm/trunk/engines/sci/graphics/font.h
    scummvm/trunk/engines/sci/graphics/gfx.cpp
    scummvm/trunk/engines/sci/graphics/gfx.h
    scummvm/trunk/engines/sci/graphics/helpers.h
    scummvm/trunk/engines/sci/graphics/menu.cpp
    scummvm/trunk/engines/sci/graphics/menu.h
    scummvm/trunk/engines/sci/graphics/palette.cpp
    scummvm/trunk/engines/sci/graphics/palette.h
    scummvm/trunk/engines/sci/graphics/picture.cpp
    scummvm/trunk/engines/sci/graphics/picture.h
    scummvm/trunk/engines/sci/graphics/portrait.cpp
    scummvm/trunk/engines/sci/graphics/portrait.h
    scummvm/trunk/engines/sci/graphics/screen.cpp
    scummvm/trunk/engines/sci/graphics/screen.h
    scummvm/trunk/engines/sci/graphics/text.cpp
    scummvm/trunk/engines/sci/graphics/text.h
    scummvm/trunk/engines/sci/graphics/transitions.cpp
    scummvm/trunk/engines/sci/graphics/transitions.h
    scummvm/trunk/engines/sci/graphics/view.cpp
    scummvm/trunk/engines/sci/graphics/view.h
    scummvm/trunk/engines/sci/graphics/windowmgr.cpp
    scummvm/trunk/engines/sci/graphics/windowmgr.h

Removed Paths:
-------------
    scummvm/trunk/engines/sci/graphics/gui_animate.cpp
    scummvm/trunk/engines/sci/graphics/gui_animate.h
    scummvm/trunk/engines/sci/graphics/gui_controls.cpp
    scummvm/trunk/engines/sci/graphics/gui_controls.h
    scummvm/trunk/engines/sci/graphics/gui_cursor.cpp
    scummvm/trunk/engines/sci/graphics/gui_cursor.h
    scummvm/trunk/engines/sci/graphics/gui_font.cpp
    scummvm/trunk/engines/sci/graphics/gui_font.h
    scummvm/trunk/engines/sci/graphics/gui_gfx.cpp
    scummvm/trunk/engines/sci/graphics/gui_gfx.h
    scummvm/trunk/engines/sci/graphics/gui_helpers.h
    scummvm/trunk/engines/sci/graphics/gui_menu.cpp
    scummvm/trunk/engines/sci/graphics/gui_menu.h
    scummvm/trunk/engines/sci/graphics/gui_palette.cpp
    scummvm/trunk/engines/sci/graphics/gui_palette.h
    scummvm/trunk/engines/sci/graphics/gui_picture.cpp
    scummvm/trunk/engines/sci/graphics/gui_picture.h
    scummvm/trunk/engines/sci/graphics/gui_portrait.cpp
    scummvm/trunk/engines/sci/graphics/gui_portrait.h
    scummvm/trunk/engines/sci/graphics/gui_screen.cpp
    scummvm/trunk/engines/sci/graphics/gui_screen.h
    scummvm/trunk/engines/sci/graphics/gui_text.cpp
    scummvm/trunk/engines/sci/graphics/gui_text.h
    scummvm/trunk/engines/sci/graphics/gui_transitions.cpp
    scummvm/trunk/engines/sci/graphics/gui_transitions.h
    scummvm/trunk/engines/sci/graphics/gui_view.cpp
    scummvm/trunk/engines/sci/graphics/gui_view.h
    scummvm/trunk/engines/sci/graphics/gui_windowmgr.cpp
    scummvm/trunk/engines/sci/graphics/gui_windowmgr.h

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/console.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -44,7 +44,7 @@
 #include "sci/sound/softseq/mididriver.h"
 #include "sci/vocabulary.h"
 #include "sci/graphics/gui.h"
-#include "sci/graphics/gui_cursor.h"
+#include "sci/graphics/cursor.h"
 
 #include "graphics/video/avi_decoder.h"
 #include "sci/video/seq_decoder.h"

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -709,7 +709,7 @@
 	while (true) {
 		// let backend process events and update the screen
 		event->get(SCI_EVENT_PEEK);
-		// TODO: we need to call SciGuiCursor::refreshPosition() before each screen update to limit the mouse cursor position
+		// TODO: we need to call Cursor::refreshPosition() before each screen update to limit the mouse cursor position
 		g_system->updateScreen();
 		time = g_system->getMillis();
 		if (time + 10 < wakeup_time) {

Modified: scummvm/trunk/engines/sci/engine/kevent.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kevent.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/kevent.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -30,7 +30,7 @@
 #include "sci/debug.h"	// for g_debug_simulated_key
 #include "sci/event.h"
 #include "sci/graphics/gui.h"
-#include "sci/graphics/gui_cursor.h"
+#include "sci/graphics/cursor.h"
 
 namespace Sci {
 

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -34,10 +34,10 @@
 #include "sci/engine/state.h"
 #include "sci/engine/kernel.h"
 #include "sci/graphics/gui.h"
-#include "sci/graphics/gui_animate.h"
-#include "sci/graphics/gui_cursor.h"
-#include "sci/graphics/gui_screen.h"
-#include "sci/graphics/gui_view.h"
+#include "sci/graphics/animate.h"
+#include "sci/graphics/cursor.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/view.h"
 
 namespace Sci {
 
@@ -701,12 +701,12 @@
 	reg_t textReference = GET_SEL32(s->_segMan, controlObject, text);
 	Common::String text;
 	Common::Rect rect;
-	GuiTextAlignment alignment;
+	TextAlignment alignment;
 	int16 mode, maxChars, cursorPos, upperPos, listCount, i;
 	int16 upperOffset, cursorOffset;
 	GuiResourceId viewId;
-	GuiViewLoopNo loopNo;
-	GuiViewCelNo celNo;
+	LoopNo loopNo;
+	CelNo celNo;
 	reg_t listSeeker;
 	Common::String *listStrings = NULL;
 	const char **listEntries = NULL;
@@ -842,8 +842,8 @@
 
 reg_t kAddToPic(EngineState *s, int argc, reg_t *argv) {
 	GuiResourceId viewId;
-	GuiViewLoopNo loopNo;
-	GuiViewCelNo celNo;
+	LoopNo loopNo;
+	CelNo celNo;
 	int16 leftPos, topPos, priority, control;
 
 	switch (argc) {
@@ -909,8 +909,8 @@
 
 reg_t kDrawCel(EngineState *s, int argc, reg_t *argv) {
 	GuiResourceId viewId = argv[0].toSint16();
-	GuiViewLoopNo loopNo = argv[1].toSint16();
-	GuiViewCelNo celNo = argv[2].toSint16();
+	LoopNo loopNo = argv[1].toSint16();
+	CelNo celNo = argv[2].toSint16();
 	uint16 x = argv[3].toUint16();
 	uint16 y = argv[4].toUint16();
 	int16 priority = (argc > 5) ? argv[5].toSint16()  : -1;

Modified: scummvm/trunk/engines/sci/engine/kmenu.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmenu.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/kmenu.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -28,7 +28,7 @@
 #include "sci/engine/state.h"
 #include "sci/engine/kernel.h"
 #include "sci/graphics/gui.h"
-#include "sci/graphics/gui_cursor.h"
+#include "sci/graphics/cursor.h"
 
 namespace Sci {
 

Modified: scummvm/trunk/engines/sci/engine/kmovement.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmovement.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/kmovement.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -27,7 +27,7 @@
 #include "sci/resource.h"
 #include "sci/engine/state.h"
 #include "sci/engine/kernel.h"
-#include "sci/graphics/gui_animate.h"
+#include "sci/graphics/animate.h"
 
 namespace Sci {
 

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -52,7 +52,7 @@
 class SciEvent;
 class Menubar;
 class SciGui;
-class SciGuiCursor;
+class Cursor;
 class MessageState;
 class SoundCommandParser;
 

Modified: scummvm/trunk/engines/sci/event.cpp
===================================================================
--- scummvm/trunk/engines/sci/event.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/event.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -329,7 +329,7 @@
 	//sci_event_t error_event = { SCI_EVT_ERROR, 0, 0, 0 };
 	sciEvent event = { 0, 0, 0, 0 };
 
-	// TODO: we need to call SciGuiCursor::refreshPosition() before each screen update to limit the mouse cursor position
+	// TODO: we need to call Cursor::refreshPosition() before each screen update to limit the mouse cursor position
 
 	// Update the screen here, since it's called very often
 	g_system->updateScreen();

Copied: scummvm/trunk/engines/sci/graphics/animate.cpp (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_animate.cpp)
===================================================================
--- scummvm/trunk/engines/sci/graphics/animate.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/animate.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,559 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/util.h"
+#include "common/stack.h"
+#include "graphics/primitives.h"
+
+#include "sci/sci.h"
+#include "sci/engine/state.h"
+#include "sci/engine/vm.h"
+#include "sci/graphics/gfx.h"
+#include "sci/graphics/view.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/transitions.h"
+#include "sci/graphics/animate.h"
+
+namespace Sci {
+
+SciGuiAnimate::SciGuiAnimate(EngineState *state, Gfx *gfx, Screen *screen, SciPalette *palette)
+	: _s(state), _gfx(gfx), _screen(screen), _palette(palette) {
+	init();
+}
+
+SciGuiAnimate::~SciGuiAnimate() {
+	free(_listData);
+	free(_lastCastData);
+}
+
+void SciGuiAnimate::init() {
+	_listData = NULL;
+	_listCount = 0;
+	_lastCastData = NULL;
+	_lastCastCount = 0;
+
+	_ignoreFastCast = false;
+	// fastCast object is not found in any SCI games prior SCI1
+	if (getSciVersion() <= SCI_VERSION_01)
+		_ignoreFastCast = true;
+	// Also if fastCast object exists at gamestartup, we can assume that the interpreter doesnt do kAnimate aborts
+	//  (found in larry 1)
+	if (!_s->_segMan->findObjectByName("fastCast").isNull())
+		_ignoreFastCast = true;
+}
+
+void SciGuiAnimate::disposeLastCast() {
+	_lastCastCount = 0;
+}
+
+bool SciGuiAnimate::invoke(List *list, int argc, reg_t *argv) {
+	reg_t curAddress = list->first;
+	Node *curNode = _s->_segMan->lookupNode(curAddress);
+	reg_t curObject;
+	uint16 signal;
+
+	while (curNode) {
+		curObject = curNode->value;
+
+		if (!_ignoreFastCast) {
+			// Check if the game has a fastCast object set
+			//  if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
+			reg_t global84 = _s->script_000->_localsBlock->_locals[84];
+
+			if (!global84.isNull()) {
+				if (!strcmp(_s->_segMan->getObjectName(global84), "fastCast"))
+					return false;
+			}
+		}
+
+		signal = GET_SEL32V(_s->_segMan, curObject, signal);
+		if (!(signal & kSignalFrozen)) {
+			// Call .doit method of that object
+			invoke_selector(_s, curObject, _s->_kernel->_selectorCache.doit, kContinueOnInvalidSelector, argv, argc, 0);
+			// Lookup node again, since the nodetable it was in may have been reallocated
+			curNode = _s->_segMan->lookupNode(curAddress);
+		}
+		curAddress = curNode->succ;
+		curNode = _s->_segMan->lookupNode(curAddress);
+	}
+	return true;
+}
+
+bool sortHelper(const AnimateEntry* entry1, const AnimateEntry* entry2) {
+	return (entry1->y == entry2->y) ? (entry1->z < entry2->z) : (entry1->y < entry2->y);
+}
+
+void SciGuiAnimate::makeSortedList(List *list) {
+	reg_t curAddress = list->first;
+	Node *curNode = _s->_segMan->lookupNode(curAddress);
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	int16 listNr, listCount = 0;
+
+	// Count the list entries
+	while (curNode) {
+		listCount++;
+		curAddress = curNode->succ;
+		curNode = _s->_segMan->lookupNode(curAddress);
+	}
+
+	_list.clear();
+
+	// No entries -> exit immediately
+	if (listCount == 0)
+		return;
+
+	// Adjust list size, if needed
+	if ((_listData == NULL) || (_listCount < listCount)) {
+		free(_listData);
+		_listData = (AnimateEntry *)malloc(listCount * sizeof(AnimateEntry));
+		if (!_listData)
+			error("Could not allocate memory for _listData");
+		_listCount = listCount;
+
+		free(_lastCastData);
+		_lastCastData = (AnimateEntry *)malloc(listCount * sizeof(AnimateEntry));
+		if (!_lastCastData)
+			error("Could not allocate memory for _lastCastData");
+		_lastCastCount = 0;
+	}
+
+	// Fill the list
+	curAddress = list->first;
+	curNode = _s->_segMan->lookupNode(curAddress);
+	listEntry = _listData;
+	for (listNr = 0; listNr < listCount; listNr++) {
+		curObject = curNode->value;
+		listEntry->object = curObject;
+
+		// Get data from current object
+		listEntry->viewId = GET_SEL32V(_s->_segMan, curObject, view);
+		listEntry->loopNo = GET_SEL32V(_s->_segMan, curObject, loop);
+		listEntry->celNo = GET_SEL32V(_s->_segMan, curObject, cel);
+		listEntry->paletteNo = GET_SEL32V(_s->_segMan, curObject, palette);
+		listEntry->x = GET_SEL32V(_s->_segMan, curObject, x);
+		listEntry->y = GET_SEL32V(_s->_segMan, curObject, y);
+		listEntry->z = GET_SEL32V(_s->_segMan, curObject, z);
+		listEntry->priority = GET_SEL32V(_s->_segMan, curObject, priority);
+		listEntry->signal = GET_SEL32V(_s->_segMan, curObject, signal);
+		// listEntry->celRect is filled in AnimateFill()
+		listEntry->showBitsFlag = false;
+
+		_list.push_back(listEntry);
+
+		listEntry++;
+		curAddress = curNode->succ;
+		curNode = _s->_segMan->lookupNode(curAddress);
+	}
+
+	// Now sort the list according y and z (descending)
+	AnimateList::iterator listBegin = _list.begin();
+	AnimateList::iterator listEnd = _list.end();
+
+	Common::sort(_list.begin(), _list.end(), sortHelper);
+}
+
+void SciGuiAnimate::fill(byte &old_picNotValid) {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	uint16 signal;
+	View *view = NULL;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listEnd = _list.end();
+
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+
+		// Get the corresponding view
+		view = _gfx->getView(listEntry->viewId);
+		
+		// adjust loop and cel, if any of those is invalid
+		if (listEntry->loopNo >= view->getLoopCount()) {
+			listEntry->loopNo = 0;
+			PUT_SEL32V(_s->_segMan, curObject, loop, listEntry->loopNo);
+		}
+		if (listEntry->celNo >= view->getCelCount(listEntry->loopNo)) {
+			listEntry->celNo = 0;
+			PUT_SEL32V(_s->_segMan, curObject, cel, listEntry->celNo);
+		}
+
+		// Create rect according to coordinates and given cel
+		view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
+		PUT_SEL32V(_s->_segMan, curObject, nsLeft, listEntry->celRect.left);
+		PUT_SEL32V(_s->_segMan, curObject, nsTop, listEntry->celRect.top);
+		PUT_SEL32V(_s->_segMan, curObject, nsRight, listEntry->celRect.right);
+		PUT_SEL32V(_s->_segMan, curObject, nsBottom, listEntry->celRect.bottom);
+
+		signal = listEntry->signal;
+
+		// Calculate current priority according to y-coordinate
+		if (!(signal & kSignalFixedPriority)) {
+			listEntry->priority = _gfx->CoordinateToPriority(listEntry->y);
+			PUT_SEL32V(_s->_segMan, curObject, priority, listEntry->priority);
+		}
+		
+		if (signal & kSignalNoUpdate) {
+			if (signal & (kSignalForceUpdate | kSignalViewUpdated)
+				|| (signal & kSignalHidden && !(signal & kSignalRemoveView))
+				|| (!(signal & kSignalHidden) && signal & kSignalRemoveView)
+				|| (signal & kSignalAlwaysUpdate))
+				old_picNotValid++;
+			signal &= 0xFFFF ^ kSignalStopUpdate;
+		} else {
+			if (signal & kSignalStopUpdate || signal & kSignalAlwaysUpdate)
+				old_picNotValid++;
+			signal &= 0xFFFF ^ kSignalForceUpdate;
+		}
+		listEntry->signal = signal;
+
+		listIterator++;
+	}
+}
+
+void SciGuiAnimate::update() {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	uint16 signal;
+	reg_t bitsHandle;
+	Common::Rect rect;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listBegin = _list.begin();
+	AnimateList::iterator listEnd = _list.end();
+
+	// Remove all no-update cels, if requested
+	listIterator = _list.reverse_begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (signal & kSignalNoUpdate) {
+			if (!(signal & kSignalRemoveView)) {
+				bitsHandle = GET_SEL32(_s->_segMan, curObject, underBits);
+				if (_screen->_picNotValid != 1) {
+					_gfx->BitsRestore(bitsHandle);
+					listEntry->showBitsFlag = true;
+				} else	{
+					_gfx->BitsFree(bitsHandle);
+				}
+				PUT_SEL32V(_s->_segMan, curObject, underBits, 0);
+			}
+			signal &= 0xFFFF ^ kSignalForceUpdate;
+			signal &= signal & kSignalViewUpdated ? 0xFFFF ^ (kSignalViewUpdated | kSignalNoUpdate) : 0xFFFF;
+		} else if (signal & kSignalStopUpdate) {
+			signal =  (signal & (0xFFFF ^ kSignalStopUpdate)) | kSignalNoUpdate;
+		}
+		listEntry->signal = signal;
+		listIterator--;
+	}
+
+	// Draw always-update cels
+	listIterator = listBegin;
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (signal & kSignalAlwaysUpdate) {
+			// draw corresponding cel
+			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
+			listEntry->showBitsFlag = true;
+
+			signal &= 0xFFFF ^ (kSignalStopUpdate | kSignalViewUpdated | kSignalNoUpdate | kSignalForceUpdate);
+			if ((signal & kSignalIgnoreActor) == 0) {
+				rect = listEntry->celRect;
+				rect.top = CLIP<int16>(_gfx->PriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);  
+				_gfx->FillRect(rect, SCI_SCREEN_MASK_CONTROL, 0, 0, 15);
+			}
+			listEntry->signal = signal;
+		}
+		listIterator++;
+	}
+
+	// Saving background for all NoUpdate-cels
+	listIterator = listBegin;
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (signal & kSignalNoUpdate) {
+			if (signal & kSignalHidden) {
+				signal |= kSignalRemoveView;
+			} else {
+				signal &= 0xFFFF ^ kSignalRemoveView;
+				if (signal & kSignalIgnoreActor)
+					bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_VISUAL|SCI_SCREEN_MASK_PRIORITY);
+				else
+					bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_ALL);
+				PUT_SEL32(_s->_segMan, curObject, underBits, bitsHandle);
+			}
+			listEntry->signal = signal;
+		}
+		listIterator++;
+	}
+
+	// Draw NoUpdate cels
+	listIterator = listBegin;
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (signal & kSignalNoUpdate && !(signal & kSignalHidden)) {
+			// draw corresponding cel
+			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
+			listEntry->showBitsFlag = true;
+
+			if ((signal & kSignalIgnoreActor) == 0) {
+				rect = listEntry->celRect;
+				rect.top = CLIP<int16>(_gfx->PriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);  
+				_gfx->FillRect(rect, SCI_SCREEN_MASK_CONTROL, 0, 0, 15);
+			}
+		}
+		listIterator++;
+	}
+}
+
+void SciGuiAnimate::drawCels() {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	AnimateEntry *lastCastEntry = _lastCastData;
+	uint16 signal;
+	reg_t bitsHandle;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listEnd = _list.end();
+
+	_lastCastCount = 0;
+
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (!(signal & (kSignalNoUpdate | kSignalHidden | kSignalAlwaysUpdate))) {
+			// Save background
+			bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_ALL);
+			PUT_SEL32(_s->_segMan, curObject, underBits, bitsHandle);
+
+			// draw corresponding cel
+			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
+			listEntry->showBitsFlag = true;
+
+			if (signal & kSignalRemoveView) {
+				signal &= 0xFFFF ^ kSignalRemoveView;
+			}
+			listEntry->signal = signal;
+
+			// Remember that entry in lastCast
+			memcpy(lastCastEntry, listEntry, sizeof(AnimateEntry));
+			lastCastEntry++; _lastCastCount++;
+		}
+		listIterator++;
+	}
+}
+
+void SciGuiAnimate::updateScreen(byte oldPicNotValid) {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	uint16 signal;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listEnd = _list.end();
+	Common::Rect lsRect;
+	Common::Rect workerRect;
+
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		if (listEntry->showBitsFlag || !(signal & (kSignalRemoveView | kSignalNoUpdate) ||
+										(!(signal & kSignalRemoveView) && (signal & kSignalNoUpdate) && oldPicNotValid))) {
+			lsRect.left = GET_SEL32V(_s->_segMan, curObject, lsLeft);
+			lsRect.top = GET_SEL32V(_s->_segMan, curObject, lsTop);
+			lsRect.right = GET_SEL32V(_s->_segMan, curObject, lsRight);
+			lsRect.bottom = GET_SEL32V(_s->_segMan, curObject, lsBottom);
+
+			workerRect = lsRect;
+			workerRect.clip(listEntry->celRect);
+
+			if (!workerRect.isEmpty()) {
+				workerRect = lsRect;
+				workerRect.extend(listEntry->celRect);
+			} else {
+				_gfx->BitsShow(lsRect);
+				workerRect = listEntry->celRect;
+			}
+			PUT_SEL32V(_s->_segMan, curObject, lsLeft, workerRect.left);
+			PUT_SEL32V(_s->_segMan, curObject, lsTop, workerRect.top);
+			PUT_SEL32V(_s->_segMan, curObject, lsRight, workerRect.right);
+			PUT_SEL32V(_s->_segMan, curObject, lsBottom, workerRect.bottom);
+			_gfx->BitsShow(workerRect);
+
+			if (signal & kSignalHidden) {
+				listEntry->signal |= kSignalRemoveView;
+			}
+		}
+
+		listIterator++;
+	}
+	// use this for debug purposes
+	// _screen->copyToScreen();
+}
+
+void SciGuiAnimate::restoreAndDelete(int argc, reg_t *argv) {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	uint16 signal;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listEnd = _list.end();
+
+
+	// This has to be done in a separate loop. At least in sq1 some .dispose modifies FIXEDLOOP flag in signal for
+	//  another object. In that case we would overwrite the new signal with our version of the old signal
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		signal = listEntry->signal;
+
+		// Finally update signal
+		PUT_SEL32V(_s->_segMan, curObject, signal, signal);
+		listIterator++;
+	}
+
+	listIterator = _list.reverse_begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+		// We read out signal here again, this is not by accident but to ensure that we got an up-to-date signal
+		signal = GET_SEL32V(_s->_segMan, curObject, signal);
+
+		if ((signal & (kSignalNoUpdate | kSignalRemoveView)) == 0) {
+			_gfx->BitsRestore(GET_SEL32(_s->_segMan, curObject, underBits));
+			PUT_SEL32V(_s->_segMan, curObject, underBits, 0);
+		}
+
+		if (signal & kSignalDisposeMe) {
+			// Call .delete_ method of that object
+			invoke_selector(_s, curObject, _s->_kernel->_selectorCache.delete_, kContinueOnInvalidSelector, argv, argc, 0);
+		}
+		listIterator--;
+	}
+}
+
+void SciGuiAnimate::reAnimate(Common::Rect rect) {
+	AnimateEntry *lastCastEntry;
+	uint16 lastCastCount;
+
+	if (_lastCastCount > 0) {
+		lastCastEntry = _lastCastData;
+		lastCastCount = _lastCastCount;
+		while (lastCastCount > 0) {
+			lastCastEntry->castHandle = _gfx->BitsSave(lastCastEntry->celRect, SCI_SCREEN_MASK_VISUAL|SCI_SCREEN_MASK_PRIORITY);
+			_gfx->drawCel(lastCastEntry->viewId, lastCastEntry->loopNo, lastCastEntry->celNo, lastCastEntry->celRect, lastCastEntry->priority, lastCastEntry->paletteNo);
+			lastCastEntry++; lastCastCount--;
+		}
+		_gfx->BitsShow(rect);
+		// restoring
+		lastCastCount = _lastCastCount;
+		while (lastCastCount > 0) {
+			lastCastEntry--;
+			_gfx->BitsRestore(lastCastEntry->castHandle);
+			lastCastCount--;
+		}
+	} else {
+		_gfx->BitsShow(rect);
+	}
+
+	/*
+	if (!_lastCast->isEmpty()) {
+		HEAPHANDLE hnode = _lastCast->getFirst();
+		sciCast *pCast;
+		CResView *res;
+		while (hnode) {
+			pCast = (sciCast *)heap2Ptr(hnode);
+			res = (CResView *)ResMgr.ResLoad(SCI_RES_VIEW, pCast->view);
+			pCast->hSaved = _gfx->SaveBits(pCast->rect, 3);
+			res->drawCel(pCast->loop, pCast->cel, &pCast->rect, pCast->z, pCast->pal);
+			hnode = pCast->node.next;
+		}
+		_gfx->BitsShow(rect);
+		// restoring
+		hnode = _lastCast->getLast();
+		while (hnode) {
+			pCast = (sciCast *)heap2Ptr(hnode);
+			_gfx->BitsShow(pCast->hSaved);
+			hnode = pCast->node.prev;
+		}
+	*/
+}
+
+void SciGuiAnimate::addToPicDrawCels() {
+	reg_t curObject;
+	AnimateEntry *listEntry;
+	View *view = NULL;
+	AnimateList::iterator listIterator;
+	AnimateList::iterator listEnd = _list.end();
+
+	listIterator = _list.begin();
+	while (listIterator != listEnd) {
+		listEntry = *listIterator;
+		curObject = listEntry->object;
+
+		if (listEntry->priority == -1)
+			listEntry->priority = _gfx->CoordinateToPriority(listEntry->y);
+
+		// Get the corresponding view
+		view = _gfx->getView(listEntry->viewId);
+
+		// Create rect according to coordinates and given cel
+		view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
+
+		// draw corresponding cel
+		_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
+		if ((listEntry->signal & kSignalIgnoreActor) == 0) {
+			listEntry->celRect.top = CLIP<int16>(_gfx->PriorityToCoordinate(listEntry->priority) - 1, listEntry->celRect.top, listEntry->celRect.bottom - 1);
+			_gfx->FillRect(listEntry->celRect, SCI_SCREEN_MASK_CONTROL, 0, 0, 15);
+		}
+
+		listIterator++;
+	}
+}
+
+void SciGuiAnimate::addToPicDrawView(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
+	View *view = _gfx->getView(viewId);
+	Common::Rect celRect;
+
+	// Create rect according to coordinates and given cel
+	view->getCelRect(loopNo, celNo, leftPos, topPos, priority, &celRect);
+	_gfx->drawCel(view, loopNo, celNo, celRect, priority, 0);
+}
+
+} // End of namespace Sci

Copied: scummvm/trunk/engines/sci/graphics/animate.h (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_animate.h)
===================================================================
--- scummvm/trunk/engines/sci/graphics/animate.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/animate.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,99 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_GRAPHICS_ANIMATE_H
+#define SCI_GRAPHICS_ANIMATE_H
+
+#include "sci/graphics/helpers.h"
+
+namespace Sci {
+
+// Flags for the signal selector
+enum ViewSignals {
+	kSignalStopUpdate    = 0x0001,
+	kSignalViewUpdated   = 0x0002,
+	kSignalNoUpdate      = 0x0004,
+	kSignalHidden        = 0x0008,
+	kSignalFixedPriority = 0x0010,
+	kSignalAlwaysUpdate  = 0x0020,
+	kSignalForceUpdate   = 0x0040,
+	kSignalRemoveView    = 0x0080,
+	kSignalFrozen        = 0x0100,
+	kSignalExtraActor	 = 0x0200, // unused by us, defines all actors that may be included into the background if speed to slow
+	kSignalHitObstacle	 = 0x0400, // used in the actor movement code by kDoBresen()
+	kSignalDoesntTurn	 = 0x0800, // used by _k_dirloop() to determine if an actor can turn or not
+	kSignalNoCycler		 = 0x1000, // unused by us
+	kSignalIgnoreHorizon = 0x2000, // unused by us, defines actor that can ignore horizon
+	kSignalIgnoreActor   = 0x4000,
+	kSignalDisposeMe     = 0x8000,
+
+	kSignalStopUpdHack	 = 0x20000000 // View has been stop-updated (again???) - a hack used by the old GUI code only, for dynamic views
+};
+
+class Gfx;
+class Screen;
+class SciPalette;
+class Transitions;
+class SciGuiAnimate {
+public:
+	SciGuiAnimate(EngineState *state, Gfx *gfx, Screen *screen, SciPalette *palette);
+	~SciGuiAnimate();
+
+	// FIXME: Don't store EngineState
+	void resetEngineState(EngineState *newState) { _s = newState; }
+
+	void disposeLastCast();
+	bool invoke(List *list, int argc, reg_t *argv);
+	void makeSortedList(List *list);
+	void fill(byte &oldPicNotValid);
+	void update();
+	void drawCels();
+	void updateScreen(byte oldPicNotValid);
+	void restoreAndDelete(int argc, reg_t *argv);
+	void reAnimate(Common::Rect rect);
+	void addToPicDrawCels();
+	void addToPicDrawView(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control);
+
+private:
+	void init();
+
+	EngineState *_s;
+	Gfx *_gfx;
+	Screen *_screen;
+	SciPalette *_palette;
+
+	uint16 _listCount;
+	AnimateEntry *_listData;
+	AnimateList _list;
+
+	uint16 _lastCastCount;
+	AnimateEntry *_lastCastData;
+
+	bool _ignoreFastCast;
+};
+
+} // End of namespace Sci
+
+#endif

Copied: scummvm/trunk/engines/sci/graphics/controls.cpp (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_controls.cpp)
===================================================================
--- scummvm/trunk/engines/sci/graphics/controls.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/controls.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,231 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/util.h"
+#include "common/stack.h"
+#include "graphics/primitives.h"
+
+#include "sci/sci.h"
+#include "sci/event.h"
+#include "sci/engine/state.h"
+#include "sci/graphics/gfx.h"
+#include "sci/graphics/font.h"
+#include "sci/graphics/text.h"
+#include "sci/graphics/controls.h"
+
+namespace Sci {
+
+SciGuiControls::SciGuiControls(SegManager *segMan, Gfx *gfx, Text *text)
+	: _segMan(segMan), _gfx(gfx), _text(text) {
+	init();
+}
+
+SciGuiControls::~SciGuiControls() {
+}
+
+void SciGuiControls::init() {
+	_texteditCursorVisible = false;
+}
+
+const char controlListUpArrow[2]	= { 0x18, 0 };
+const char controlListDownArrow[2]	= { 0x19, 0 };
+
+void SciGuiControls::drawListControl(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 upperPos, int16 cursorPos, bool isAlias) {
+	Common::Rect workerRect = rect;
+	GuiResourceId oldFontId = _text->GetFontId();
+	int16 oldPenColor = _gfx->_curPort->penClr;
+	uint16 fontSize = 0;
+	int16 i;
+	const char *listEntry;
+	int16 listEntryLen;
+	int16 lastYpos;
+
+	// draw basic window
+	_gfx->EraseRect(workerRect);
+	workerRect.grow(1);
+	_gfx->FrameRect(workerRect);
+
+	// draw UP/DOWN arrows
+	//  we draw UP arrow one pixel lower than sierra did, because it looks nicer. Also the DOWN arrow has one pixel
+	//  line inbetween as well
+	workerRect.top++;
+	_text->Box(controlListUpArrow, 0, workerRect, SCI_TEXT_ALIGNMENT_CENTER, 0);
+	workerRect.top = workerRect.bottom - 10;
+	_text->Box(controlListDownArrow, 0, workerRect, SCI_TEXT_ALIGNMENT_CENTER, 0);
+
+	// Draw inner lines
+	workerRect.top = rect.top + 9;
+	workerRect.bottom -= 10;
+	_gfx->FrameRect(workerRect);
+	workerRect.grow(-1);
+
+	_text->SetFont(fontId);
+	fontSize = _gfx->_curPort->fontHeight;
+	_gfx->PenColor(_gfx->_curPort->penClr); _gfx->BackColor(_gfx->_curPort->backClr);
+	workerRect.bottom = workerRect.top + 9;
+	lastYpos = rect.bottom - fontSize;
+
+	// Write actual text
+	for (i = upperPos; i < count; i++) {
+		_gfx->EraseRect(workerRect);
+		listEntry = entries[i];
+		if (listEntry[0]) {
+			_gfx->MoveTo(workerRect.left, workerRect.top);
+			listEntryLen = strlen(listEntry);
+			_text->Draw(listEntry, 0, MIN(maxChars, listEntryLen), oldFontId, oldPenColor);
+			if ((!isAlias) && (i == cursorPos)) {
+				_gfx->InvertRect(workerRect);
+			}
+		}
+		workerRect.translate(0, fontSize);
+		if (workerRect.bottom > lastYpos)
+			break;
+	}
+
+	_text->SetFont(oldFontId);
+}
+
+void SciGuiControls::TexteditCursorDraw(Common::Rect rect, const char *text, uint16 curPos) {
+	int16 textWidth, i;
+	if (!_texteditCursorVisible) {
+		textWidth = 0;
+		for (i = 0; i < curPos; i++) {
+			textWidth += _text->_font->getCharWidth(text[i]);
+		}
+		_texteditCursorRect.left = rect.left + textWidth;
+		_texteditCursorRect.top = rect.top;
+		_texteditCursorRect.bottom = _texteditCursorRect.top + _text->_font->getHeight();
+		_texteditCursorRect.right = _texteditCursorRect.left + (text[curPos] == 0 ? 1 : _text->_font->getCharWidth(text[curPos]));
+		_gfx->InvertRect(_texteditCursorRect);
+		_gfx->BitsShow(_texteditCursorRect);
+		_texteditCursorVisible = true;
+		TexteditSetBlinkTime();
+	}
+}
+
+void SciGuiControls::TexteditCursorErase() {
+	if (_texteditCursorVisible) {
+		_gfx->InvertRect(_texteditCursorRect);
+		_gfx->BitsShow(_texteditCursorRect);
+		_texteditCursorVisible = false;
+	}
+	TexteditSetBlinkTime();
+}
+
+void SciGuiControls::TexteditSetBlinkTime() {
+	_texteditBlinkTime = g_system->getMillis() + (30 * 1000 / 60);
+}
+
+void SciGuiControls::TexteditChange(reg_t controlObject, reg_t eventObject) {
+	uint16 cursorPos = GET_SEL32V(_segMan, controlObject, cursor);
+	uint16 maxChars = GET_SEL32V(_segMan, controlObject, max);
+	reg_t textReference = GET_SEL32(_segMan, controlObject, text);
+	Common::String text;
+	uint16 textSize, eventType, eventKey;
+	bool textChanged = false;
+	Common::Rect rect;
+
+	if (textReference.isNull())
+		error("kEditControl called on object that doesnt have a text reference");
+	text = _segMan->getString(textReference);
+
+	if (!eventObject.isNull()) {
+		textSize = text.size();
+		eventType = GET_SEL32V(_segMan, eventObject, type);
+
+		switch (eventType) {
+		case SCI_EVENT_MOUSE_PRESS:
+			// TODO: Implement mouse support for cursor change
+			break;
+		case SCI_EVENT_KEYBOARD:
+			eventKey = GET_SEL32V(_segMan, eventObject, message);
+			switch (eventKey) {
+			case SCI_KEY_BACKSPACE:
+				if (cursorPos > 0) {
+					cursorPos--; text.deleteChar(cursorPos);
+					textChanged = true;
+				}
+				break;
+			case SCI_KEY_DELETE:
+				text.deleteChar(cursorPos);
+				textChanged = true;
+				break;
+			case SCI_KEY_HOME: // HOME
+				cursorPos = 0; textChanged = true;
+				break;
+			case SCI_KEY_END: // END
+				cursorPos = textSize; textChanged = true;
+				break;
+			case SCI_KEY_LEFT: // LEFT
+				if (cursorPos > 0) {
+					cursorPos--; textChanged = true;
+				}
+				break;
+			case SCI_KEY_RIGHT: // RIGHT
+				if (cursorPos + 1 <= textSize) {
+					cursorPos++; textChanged = true;
+				}
+				break;
+			default:
+				if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
+					// insert pressed character
+					// we check, if there is space left for this character
+					
+					text.insertChar(eventKey, cursorPos++);
+					textChanged = true;
+				}
+				break;
+			}
+			break;
+		}
+	}
+
+	if (textChanged) {
+		GuiResourceId oldFontId = _text->GetFontId();
+		GuiResourceId fontId = GET_SEL32V(_segMan, controlObject, font);
+		rect = Common::Rect(GET_SEL32V(_segMan, controlObject, nsLeft), GET_SEL32V(_segMan, controlObject, nsTop),
+							  GET_SEL32V(_segMan, controlObject, nsRight), GET_SEL32V(_segMan, controlObject, nsBottom));
+		TexteditCursorErase();
+		_gfx->EraseRect(rect);
+		_text->Box(text.c_str(), 0, rect, SCI_TEXT_ALIGNMENT_LEFT, fontId);
+		_gfx->BitsShow(rect);
+		_text->SetFont(fontId);
+		TexteditCursorDraw(rect, text.c_str(), cursorPos);
+		_text->SetFont(oldFontId);
+		// Write back string
+		_segMan->strcpy(textReference, text.c_str());
+	} else {
+		if (g_system->getMillis() >= _texteditBlinkTime) {
+			_gfx->InvertRect(_texteditCursorRect);
+			_gfx->BitsShow(_texteditCursorRect);
+			_texteditCursorVisible = !_texteditCursorVisible;
+			TexteditSetBlinkTime();
+		}
+	}
+
+	PUT_SEL32V(_segMan, controlObject, cursor, cursorPos);
+}
+
+} // End of namespace Sci

Copied: scummvm/trunk/engines/sci/graphics/controls.h (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_controls.h)
===================================================================
--- scummvm/trunk/engines/sci/graphics/controls.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/controls.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_GRAPHICS_CONTROLS_H
+#define SCI_GRAPHICS_CONTROLS_H
+
+namespace Sci {
+
+class Gfx;
+class Font;
+class Text;
+class SciGuiControls {
+public:
+	SciGuiControls(SegManager *segMan, Gfx *gfx, Text *text);
+	~SciGuiControls();
+
+	void drawListControl(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 upperPos, int16 cursorPos, bool isAlias);
+	void TexteditCursorDraw(Common::Rect rect, const char *text, uint16 curPos);
+	void TexteditCursorErase();
+	void TexteditChange(reg_t controlObject, reg_t eventObject);
+
+private:
+	void init();
+	void TexteditSetBlinkTime();
+
+	SegManager *_segMan;
+	Gfx *_gfx;
+	Text *_text;
+
+	// Textedit-Control related
+	Common::Rect _texteditCursorRect;
+	bool _texteditCursorVisible;
+	uint32 _texteditBlinkTime;
+};
+
+} // End of namespace Sci
+
+#endif

Copied: scummvm/trunk/engines/sci/graphics/cursor.cpp (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_cursor.cpp)
===================================================================
--- scummvm/trunk/engines/sci/graphics/cursor.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/cursor.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,227 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "graphics/cursorman.h"
+#include "common/util.h"
+#include "common/events.h"
+
+#include "sci/sci.h"
+#include "sci/engine/state.h"
+#include "sci/graphics/palette.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/view.h"
+#include "sci/graphics/cursor.h"
+
+namespace Sci {
+
+Cursor::Cursor(ResourceManager *resMan, SciPalette *palette, Screen *screen)
+	: _resMan(resMan), _palette(palette), _screen(screen) {
+
+	_upscaledHires = _screen->getUpscaledHires();
+	// center mouse cursor
+	setPosition(Common::Point(_screen->_displayWidth / 2, _screen->_displayHeight / 2));
+	setMoveZone(Common::Rect(0, 0, _screen->_displayWidth, _screen->_displayHeight));
+
+	_isVisible = true;
+}
+
+Cursor::~Cursor() {
+	purgeCache();
+}
+
+void Cursor::show() {
+	CursorMan.showMouse(true);
+	_isVisible = true;
+}
+
+void Cursor::hide() {
+	CursorMan.showMouse(false);
+	_isVisible = false;
+}
+
+bool Cursor::isVisible() {
+	return _isVisible;
+}
+
+void Cursor::purgeCache() {
+	for (CursorCache::iterator iter = _cachedCursors.begin(); iter != _cachedCursors.end(); ++iter) {
+		delete iter->_value;
+		iter->_value = 0;
+	}
+
+	_cachedCursors.clear();
+}
+
+void Cursor::setShape(GuiResourceId resourceId) {
+	Resource *resource;
+	byte *resourceData;
+	Common::Point hotspot = Common::Point(0, 0);
+	byte colorMapping[4];
+	int16 x, y;
+	byte color;
+	int16 maskA, maskB;
+	byte *pOut;
+	byte *rawBitmap = new byte[SCI_CURSOR_SCI0_HEIGHTWIDTH * SCI_CURSOR_SCI0_HEIGHTWIDTH];
+
+	if (resourceId == -1) {
+		// no resourceId given, so we actually hide the cursor
+		hide();
+		delete[] rawBitmap;
+		return;
+	}
+	
+	// Load cursor resource...
+	resource = _resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false);
+	if (!resource)
+		error("cursor resource %d not found", resourceId);
+	if (resource->size != SCI_CURSOR_SCI0_RESOURCESIZE)
+		error("cursor resource %d has invalid size", resourceId);
+
+	resourceData = resource->data;
+	// hotspot is specified for SCI1 cursors
+	hotspot.x = READ_LE_UINT16(resourceData);
+	hotspot.y = READ_LE_UINT16(resourceData + 2);
+	// bit 0 of resourceData[3] is set on <SCI1 games, which means center hotspot
+	if ((hotspot.x == 0) && (hotspot.y == 256))
+		hotspot.x = hotspot.y = SCI_CURSOR_SCI0_HEIGHTWIDTH / 2;
+
+	// Now find out what colors we are supposed to use
+	colorMapping[0] = 0; // Black is hardcoded
+	colorMapping[1] = _screen->_colorWhite; // White is also hardcoded
+	colorMapping[2] = SCI_CURSOR_SCI0_TRANSPARENCYCOLOR;
+	colorMapping[3] = _palette->matchColor(&_palette->_sysPalette, 170, 170, 170); // Grey
+	
+	// Seek to actual data
+	resourceData += 4;
+
+	pOut = rawBitmap;
+	for (y = 0; y < SCI_CURSOR_SCI0_HEIGHTWIDTH; y++) {
+		maskA = READ_LE_UINT16(resourceData + (y << 1));
+		maskB = READ_LE_UINT16(resourceData + 32 + (y << 1));
+
+		for (x = 0; x < SCI_CURSOR_SCI0_HEIGHTWIDTH; x++) {
+			color = (((maskA << x) & 0x8000) | (((maskB << x) >> 1) & 0x4000)) >> 14;
+			*pOut++ = colorMapping[color];
+		}
+	}
+
+	CursorMan.replaceCursor(rawBitmap, SCI_CURSOR_SCI0_HEIGHTWIDTH, SCI_CURSOR_SCI0_HEIGHTWIDTH, hotspot.x, hotspot.y, SCI_CURSOR_SCI0_TRANSPARENCYCOLOR);
+	CursorMan.showMouse(true);
+
+	delete[] rawBitmap;
+}
+
+void Cursor::setView(GuiResourceId viewNum, int loopNum, int celNum, Common::Point *hotspot) {
+	if (_cachedCursors.size() >= MAX_CACHED_CURSORS)
+		purgeCache();
+
+	if (!_cachedCursors.contains(viewNum))
+		_cachedCursors[viewNum] = new View(_resMan, _screen, _palette, viewNum);
+
+	View *cursorView = _cachedCursors[viewNum];
+
+	CelInfo *celInfo = cursorView->getCelInfo(loopNum, celNum);
+	int16 width = celInfo->width;
+	int16 height = celInfo->height;
+	byte clearKey = celInfo->clearKey;
+	Common::Point *cursorHotspot = hotspot;
+	if (!cursorHotspot)
+		// Compute hotspot from xoffset/yoffset
+		cursorHotspot = new Common::Point((celInfo->width >> 1) - celInfo->displaceX, celInfo->height - celInfo->displaceY - 1);
+
+	// Eco Quest 1 uses a 1x1 transparent cursor to hide the cursor from the user. Some scalers don't seem to support this
+	if (width < 2 || height < 2) {
+		hide();
+		delete cursorHotspot;
+		return;
+	}
+
+	byte *cursorBitmap = cursorView->getBitmap(loopNum, celNum);
+
+	if (_upscaledHires) {
+		// Scale cursor by 2x
+		width *= 2;
+		height *= 2;
+		cursorHotspot->x *= 2;
+		cursorHotspot->y *= 2;
+		cursorBitmap = new byte[width * height];
+		_screen->scale2x(celInfo->rawBitmap, cursorBitmap, celInfo->width, celInfo->height);
+	}
+
+	CursorMan.replaceCursor(cursorBitmap, width, height, cursorHotspot->x, cursorHotspot->y, clearKey);
+
+	if (_upscaledHires)
+		delete[] cursorBitmap;
+
+	show();
+
+	delete cursorHotspot;
+}
+
+void Cursor::setPosition(Common::Point pos) {
+	if (!_upscaledHires) {
+		g_system->warpMouse(pos.x, pos.y);
+	} else {
+		g_system->warpMouse(pos.x * 2, pos.y * 2);
+	}
+}
+
+Common::Point Cursor::getPosition() {
+	Common::Point mousePos = g_system->getEventManager()->getMousePos();
+	
+	if (_upscaledHires) {
+		mousePos.x /= 2;
+		mousePos.y /= 2;
+	}
+
+	return mousePos;
+}
+
+void Cursor::refreshPosition() {
+	bool clipped = false;
+	Common::Point mousePoint = getPosition();
+
+	if (mousePoint.x < _moveZone.left) {
+		mousePoint.x = _moveZone.left;
+		clipped = true;
+	} else if (mousePoint.x >= _moveZone.right) {
+		mousePoint.x = _moveZone.right - 1;
+		clipped = true;
+	}
+
+	if (mousePoint.y < _moveZone.top) {
+		mousePoint.y = _moveZone.top;
+		clipped = true;
+	} else if (mousePoint.y >= _moveZone.bottom) {
+		mousePoint.y = _moveZone.bottom - 1;
+		clipped = true;
+	}
+
+	// FIXME: Do this only when mouse is grabbed?
+	if (clipped)
+		setPosition(mousePoint);
+}
+
+} // End of namespace Sci

Copied: scummvm/trunk/engines/sci/graphics/cursor.h (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_cursor.h)
===================================================================
--- scummvm/trunk/engines/sci/graphics/cursor.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/cursor.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,84 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_GRAPHICS_CURSOR_H
+#define SCI_GRAPHICS_CURSOR_H
+
+#include "common/hashmap.h"
+
+namespace Sci {
+
+#define SCI_CURSOR_SCI0_HEIGHTWIDTH 16
+#define SCI_CURSOR_SCI0_RESOURCESIZE 68
+
+#define SCI_CURSOR_SCI0_TRANSPARENCYCOLOR 1
+
+#define MAX_CACHED_CURSORS 10
+
+class View;
+class SciPalette;
+
+typedef Common::HashMap<int, View *> CursorCache;
+
+class Cursor {
+public:
+	Cursor(ResourceManager *resMan, SciPalette *palette, Screen *screen);
+	~Cursor();
+
+	void show();
+	void hide();
+	bool isVisible();
+	void setShape(GuiResourceId resourceId);
+	void setView(GuiResourceId viewNum, int loopNum, int celNum, Common::Point *hotspot);
+	void setPosition(Common::Point pos);
+	Common::Point getPosition();
+	void refreshPosition();
+
+	/**
+	 * Limits the mouse movement to a given rectangle.
+	 *
+	 * @param[in] rect	The rectangle
+	 */
+	void setMoveZone(Common::Rect zone) { _moveZone = zone; }
+
+private:
+	void purgeCache();
+
+	ResourceManager *_resMan;
+	Screen *_screen;
+	SciPalette *_palette;
+
+	bool _upscaledHires;
+
+	Common::Rect _moveZone; // Rectangle in which the pointer can move
+
+	CursorCache _cachedCursors;
+
+	bool _isVisible;
+};
+
+} // End of namespace Sci
+
+#endif

Copied: scummvm/trunk/engines/sci/graphics/font.cpp (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_font.cpp)
===================================================================
--- scummvm/trunk/engines/sci/graphics/font.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/font.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,101 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "sci/sci.h"
+#include "sci/engine/state.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/font.h"
+
+namespace Sci {
+
+Font::Font(ResourceManager *resMan, GuiResourceId resourceId)
+	: _resourceId(resourceId), _resMan(resMan) {
+	assert(resourceId != -1);
+
+	// Workaround: lsl1sci mixes its own internal fonts with the global
+	// SCI ones, so we translate them here, by removing their extra bits
+	if (!resMan->testResource(ResourceId(kResourceTypeFont, resourceId)))
+		resourceId = resourceId & 0x7ff;
+
+	_resource = resMan->findResource(ResourceId(kResourceTypeFont, resourceId), true);
+	if (!_resource) {
+		error("font resource %d not found", resourceId);
+	}
+	_resourceData = _resource->data;
+
+	_numChars = READ_LE_UINT16(_resourceData + 2);
+	_fontHeight = READ_LE_UINT16(_resourceData + 4);
+	_chars = new Charinfo[_numChars];
+	// filling info for every char
+	for (int16 i = 0; i < _numChars; i++) {
+		_chars[i].offset = READ_LE_UINT16(_resourceData + 6 + i * 2);
+		_chars[i].w = _resourceData[_chars[i].offset];
+		_chars[i].h = _resourceData[_chars[i].offset + 1];
+	}
+}
+
+Font::~Font() {
+	delete []_chars;
+	_resMan->unlockResource(_resource);
+}
+
+GuiResourceId Font::getResourceId() {
+	return _resourceId;
+}
+
+byte Font::getHeight() {
+	return _fontHeight;
+}
+byte Font::getCharWidth(byte chr) {
+	return chr < _numChars ? _chars[chr].w : 0;
+}
+byte Font::getCharHeight(byte chr) {
+	return chr < _numChars ? _chars[chr].h : 0;
+}
+byte *Font::getCharData(byte chr) {
+	return chr < _numChars ? _resourceData + _chars[chr].offset + 2 : 0;
+}
+
+void Font::draw(Screen *screen, int16 chr, int16 top, int16 left, byte color, bool greyedOutput) {
+	int charWidth = MIN<int>(getCharWidth(chr), screen->_width - left);
+	int charHeight = MIN<int>(getCharHeight(chr), 200 - top);
+	byte b = 0, mask = 0xFF;
+	int y = top;
+
+	byte *pIn = getCharData(chr);
+	for (int i = 0; i < charHeight; i++, y++) {
+		if (greyedOutput)
+			mask = top++ % 2 ? 0xAA : 0x55;
+		for (int done = 0; done < charWidth; done++) {
+			if ((done & 7) == 0) // fetching next data byte
+				b = *(pIn++) & mask;
+			if (b & 0x80) // if MSB is set - paint it
+				screen->putPixel(left + done, y, 1, color, 0, 0);
+			b = b << 1;
+		}
+	}
+}
+
+} // End of namespace Sci

Copied: scummvm/trunk/engines/sci/graphics/font.h (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_font.h)
===================================================================
--- scummvm/trunk/engines/sci/graphics/font.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/font.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_GRAPHICS_FONT_H
+#define SCI_GRAPHICS_FONT_H
+
+#include "sci/graphics/helpers.h"
+
+namespace Sci {
+
+class Font {
+public:
+	Font(ResourceManager *resMan, GuiResourceId resourceId);
+	~Font();
+
+	GuiResourceId getResourceId();
+	byte getHeight();
+	byte getCharWidth(byte chr);
+	byte getCharHeight(byte chr);
+	byte *getCharData(byte chr);
+	void draw(Screen *screen, int16 chr, int16 top, int16 left, byte color, bool greyedOutput);
+
+private:
+	ResourceManager *_resMan;
+
+	Resource *_resource;
+	GuiResourceId _resourceId;
+	byte *_resourceData;
+
+	struct Charinfo {
+		byte w, h;
+		int16 offset;
+	};
+	byte _fontHeight;
+	uint16 _numChars;
+	Charinfo *_chars;
+};
+
+} // End of namespace Sci
+
+#endif

Copied: scummvm/trunk/engines/sci/graphics/gfx.cpp (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_gfx.cpp)
===================================================================
--- scummvm/trunk/engines/sci/graphics/gfx.cpp	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/gfx.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,536 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/util.h"
+#include "common/stack.h"
+#include "graphics/primitives.h"
+
+#include "sci/sci.h"
+#include "sci/engine/state.h"
+#include "sci/graphics/gfx.h"
+#include "sci/graphics/animate.h"
+#include "sci/graphics/font.h"
+#include "sci/graphics/picture.h"
+#include "sci/graphics/view.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/palette.h"
+#include "sci/graphics/text.h"
+
+namespace Sci {
+
+Gfx::Gfx(ResourceManager *resMan, SegManager *segMan, Kernel *kernel, Screen *screen, SciPalette *palette)
+	: _resMan(resMan), _segMan(segMan), _kernel(kernel), _screen(screen), _palette(palette) {
+}
+
+Gfx::~Gfx() {
+	purgeCache();
+
+	delete _mainPort;
+	delete _menuPort;
+}
+
+void Gfx::init(Text *text) {
+	_text = text;
+
+	// _mainPort is not known to windowmanager, that's okay according to sierra sci
+	//  its not even used currently in our engine
+	_mainPort = new Port(0);
+	SetPort(_mainPort);
+	OpenPort(_mainPort);
+
+	// _menuPort has actually hardcoded id 0xFFFF. Its not meant to be known to windowmanager according to sierra sci
+	_menuPort = new Port(0xFFFF);
+	OpenPort(_menuPort);
+	_text->SetFont(0);
+	_menuPort->rect = Common::Rect(0, 0, _screen->_width, _screen->_height);
+	_menuBarRect = Common::Rect(0, 0, _screen->_width, 9);
+}
+
+void Gfx::purgeCache() {
+	for (ViewCache::iterator iter = _cachedViews.begin(); iter != _cachedViews.end(); ++iter) {
+		delete iter->_value;
+		iter->_value = 0;
+	}
+
+	_cachedViews.clear();
+}
+
+View *Gfx::getView(GuiResourceId viewNum) {
+	if (_cachedViews.size() >= MAX_CACHED_VIEWS)
+		purgeCache();
+
+	if (!_cachedViews.contains(viewNum))
+		_cachedViews[viewNum] = new View(_resMan, _screen, _palette, viewNum);
+
+	return _cachedViews[viewNum];
+}
+
+Port *Gfx::SetPort(Port *newPort) {
+	Port *oldPort = _curPort;
+	_curPort = newPort;
+	return oldPort;
+}
+
+Port *Gfx::GetPort() {
+	return _curPort;
+}
+
+void Gfx::SetOrigin(int16 left, int16 top) {
+	_curPort->left = left;
+	_curPort->top = top;
+}
+
+void Gfx::MoveTo(int16 left, int16 top) {
+	_curPort->curTop = top;
+	_curPort->curLeft = left;
+}
+
+void Gfx::Move(int16 left, int16 top) {
+	_curPort->curTop += top;
+	_curPort->curLeft += left;
+}
+
+void Gfx::OpenPort(Port *port) {
+	port->fontId = 0;
+	port->fontHeight = 8;
+
+	Port *tmp = _curPort;
+	_curPort = port;
+	_text->SetFont(port->fontId);
+	_curPort = tmp;
+
+	port->top = 0;
+	port->left = 0;
+	port->greyedOutput = false;
+	port->penClr = 0;
+	port->backClr = 255;
+	port->penMode = 0;
+	port->rect = _bounds;
+}
+
+void Gfx::PenColor(int16 color) {
+	_curPort->penClr = color;
+}
+
+void Gfx::BackColor(int16 color) {
+	_curPort->backClr = color;
+}
+
+void Gfx::PenMode(int16 mode) {
+	_curPort->penMode = mode;
+}
+
+void Gfx::TextGreyedOutput(bool state) {
+	_curPort->greyedOutput = state;
+}
+
+int16 Gfx::GetPointSize() {
+	return _curPort->fontHeight;
+}
+
+void Gfx::ClearScreen(byte color) {
+	FillRect(_curPort->rect, SCI_SCREEN_MASK_ALL, color, 0, 0);
+}
+
+void Gfx::InvertRect(const Common::Rect &rect) {
+	int16 oldpenmode = _curPort->penMode;
+	_curPort->penMode = 2;
+	FillRect(rect, 1, _curPort->penClr, _curPort->backClr);
+	_curPort->penMode = oldpenmode;
+}
+
+void Gfx::EraseRect(const Common::Rect &rect) {
+	FillRect(rect, 1, _curPort->backClr);
+}
+
+void Gfx::PaintRect(const Common::Rect &rect) {
+	FillRect(rect, 1, _curPort->penClr);
+}
+
+void Gfx::FillRect(const Common::Rect &rect, int16 drawFlags, byte clrPen, byte clrBack, byte bControl) {
+	Common::Rect r = rect;
+	r.clip(_curPort->rect);
+	if (r.isEmpty()) // nothing to fill
+		return;
+
+	int16 oldPenMode = _curPort->penMode;
+	OffsetRect(r);
+	int16 x, y;
+	byte curVisual;
+
+	// Doing visual first
+	if (drawFlags & SCI_SCREEN_MASK_VISUAL) {
+		if (oldPenMode == 2) { // invert mode
+			for (y = r.top; y < r.bottom; y++) {
+				for (x = r.left; x < r.right; x++) {
+					curVisual = _screen->getVisual(x, y);
+					if (curVisual == clrPen) {
+						_screen->putPixel(x, y, 1, clrBack, 0, 0);
+					} else if (curVisual == clrBack) {
+						_screen->putPixel(x, y, 1, clrPen, 0, 0);
+					}
+				}
+			}
+		} else { // just fill rect with ClrPen
+			for (y = r.top; y < r.bottom; y++) {
+				for (x = r.left; x < r.right; x++) {
+					_screen->putPixel(x, y, 1, clrPen, 0, 0);
+				}
+			}
+		}
+	}
+
+	if (drawFlags < 2)
+		return;
+	drawFlags &= SCI_SCREEN_MASK_PRIORITY|SCI_SCREEN_MASK_CONTROL;
+
+	if (oldPenMode != 2) {
+		for (y = r.top; y < r.bottom; y++) {
+			for (x = r.left; x < r.right; x++) {
+				_screen->putPixel(x, y, drawFlags, 0, clrBack, bControl);
+			}
+		}
+	} else {
+		for (y = r.top; y < r.bottom; y++) {
+			for (x = r.left; x < r.right; x++) {
+				_screen->putPixel(x, y, drawFlags, 0, !_screen->getPriority(x, y), !_screen->getControl(x, y));
+			}
+		}
+	}
+}
+
+void Gfx::FrameRect(const Common::Rect &rect) {
+	Common::Rect r;
+	// left
+	r = rect;
+	r.right = rect.left + 1;
+	PaintRect(r);
+	// right
+	r.right = rect.right;
+	r.left = rect.right - 1;
+	PaintRect(r);
+	//top
+	r.left = rect.left;
+	r.bottom = rect.top + 1;
+	PaintRect(r);
+	//bottom
+	r.bottom = rect.bottom;
+	r.top = rect.bottom - 1;
+	PaintRect(r);
+}
+
+void Gfx::OffsetRect(Common::Rect &r) {
+	r.top += _curPort->top;
+	r.bottom += _curPort->top;
+	r.left += _curPort->left;
+	r.right += _curPort->left;
+}
+
+void Gfx::OffsetLine(Common::Point &start, Common::Point &end) {
+	start.x += _curPort->left;
+	start.y += _curPort->top;
+	end.x += _curPort->left;
+	end.y += _curPort->top;
+}
+
+void Gfx::BitsShow(const Common::Rect &rect) {
+	Common::Rect workerRect(rect.left, rect.top, rect.right, rect.bottom);
+	workerRect.clip(_curPort->rect);
+	if (workerRect.isEmpty()) // nothing to show
+		return;
+
+	OffsetRect(workerRect);
+	_screen->copyRectToScreen(workerRect);
+}
+
+MemoryHandle Gfx::BitsSave(const Common::Rect &rect, byte screenMask) {
+	MemoryHandle memoryId;
+	byte *memoryPtr;
+	int size;
+
+	Common::Rect workerRect(rect.left, rect.top, rect.right, rect.bottom);
+	workerRect.clip(_curPort->rect);
+	if (workerRect.isEmpty()) // nothing to save
+		return NULL_REG;
+
+	OffsetRect(workerRect);
+
+	// now actually ask _screen how much space it will need for saving
+	size = _screen->bitsGetDataSize(workerRect, screenMask);
+
+	memoryId = kalloc(_segMan, "SaveBits()", size);
+	memoryPtr = kmem(_segMan, memoryId);
+	_screen->bitsSave(workerRect, screenMask, memoryPtr);
+	return memoryId;
+}
+
+void Gfx::BitsGetRect(MemoryHandle memoryHandle, Common::Rect *destRect) {
+	byte *memoryPtr = NULL;
+
+	if (!memoryHandle.isNull()) {
+		memoryPtr = kmem(_segMan, memoryHandle);
+
+		if (memoryPtr) {
+			_screen->bitsGetRect(memoryPtr, destRect);
+		}
+	}
+}
+
+void Gfx::BitsRestore(MemoryHandle memoryHandle) {
+	byte *memoryPtr = NULL;
+
+	if (!memoryHandle.isNull()) {
+		memoryPtr = kmem(_segMan, memoryHandle);
+
+		if (memoryPtr) {
+			_screen->bitsRestore(memoryPtr);
+			kfree(_segMan, memoryHandle);
+		}
+	}
+}
+
+void Gfx::BitsFree(MemoryHandle memoryHandle) {
+	if (!memoryHandle.isNull()) {
+		kfree(_segMan, memoryHandle);
+	}
+}
+
+void Gfx::drawPicture(GuiResourceId pictureId, int16 animationNr, bool mirroredFlag, bool addToFlag, GuiResourceId paletteId) {
+	SciGuiPicture *picture = new SciGuiPicture(_resMan, this, _screen, _palette, pictureId);
+
+	// do we add to a picture? if not -> clear screen with white
+	if (!addToFlag)
+		ClearScreen(_screen->_colorWhite);
+
+	picture->draw(animationNr, mirroredFlag, addToFlag, paletteId);
+	delete picture;
+}
+
+// This one is the only one that updates screen!
+void Gfx::drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, uint16 leftPos, uint16 topPos, byte priority, uint16 paletteNo, int16 origHeight) {
+	View *view = getView(viewId);
+	Common::Rect rect;
+	Common::Rect clipRect;
+	if (view) {
+		rect.left = leftPos;
+		rect.top = topPos;
+		rect.right = rect.left + view->getWidth(loopNo, celNo);
+		rect.bottom = rect.top + view->getHeight(loopNo, celNo);
+		clipRect = rect;
+		clipRect.clip(_curPort->rect);
+		if (clipRect.isEmpty()) {	// nothing to draw
+			return;
+		}
+
+		Common::Rect clipRectTranslated = clipRect;
+		OffsetRect(clipRectTranslated);
+		view->draw(rect, clipRect, clipRectTranslated, loopNo, celNo, priority, paletteNo, origHeight);
+		if (getSciVersion() >= SCI_VERSION_1_1) {
+			if (!_screen->_picNotValidSci11)
+				BitsShow(rect);
+		} else {
+			if (!_screen->_picNotValid)
+				BitsShow(rect);
+		}
+	}
+}
+
+// This version of drawCel is not supposed to call BitsShow()!
+void Gfx::drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, Common::Rect celRect, byte priority, uint16 paletteNo) {
+	View *view = getView(viewId);
+	Common::Rect clipRect;
+	if (view) {
+		clipRect = celRect;
+		clipRect.clip(_curPort->rect);
+		if (clipRect.isEmpty()) { // nothing to draw
+			return;
+		}
+
+		Common::Rect clipRectTranslated = clipRect;
+		OffsetRect(clipRectTranslated);
+		view->draw(celRect, clipRect, clipRectTranslated, loopNo, celNo, priority, paletteNo);
+	}
+}
+
+// This version of drawCel is not supposed to call BitsShow()!
+void Gfx::drawCel(View *view, LoopNo loopNo, CelNo celNo, Common::Rect celRect, byte priority, uint16 paletteNo) {
+	Common::Rect clipRect;
+	clipRect = celRect;
+	clipRect.clip(_curPort->rect);
+	if (clipRect.isEmpty()) // nothing to draw
+		return;
+
+	Common::Rect clipRectTranslated = clipRect;
+	OffsetRect(clipRectTranslated);
+	view->draw(celRect, clipRect, clipRectTranslated, loopNo, celNo, priority, paletteNo);
+}
+
+uint16 Gfx::onControl(uint16 screenMask, Common::Rect rect) {
+	Common::Rect outRect(rect.left, rect.top, rect.right, rect.bottom);
+	int16 x, y;
+	uint16 result = 0;
+
+	outRect.clip(_curPort->rect);
+	if (outRect.isEmpty()) // nothing to control
+		return 0;
+	OffsetRect(outRect);
+
+	if (screenMask & SCI_SCREEN_MASK_PRIORITY) {
+		for (y = outRect.top; y < outRect.bottom; y++) {
+			for (x = outRect.left; x < outRect.right; x++) {
+				result |= 1 << _screen->getPriority(x, y);
+			}
+		}
+	} else {
+		for (y = outRect.top; y < outRect.bottom; y++) {
+			for (x = outRect.left; x < outRect.right; x++) {
+				result |= 1 << _screen->getControl(x, y);
+			}
+		}
+	}
+	return result;
+}
+
+static inline int sign_extend_byte(int value) {
+	if (value & 0x80)
+		return value - 256;
+	else
+		return value;
+}
+
+void Gfx::PriorityBandsInit(int16 bandCount, int16 top, int16 bottom) {
+	int16 y;
+	int32 bandSize;
+
+	if (bandCount != -1)
+		_priorityBandCount = bandCount;
+
+	_priorityTop = top;
+	_priorityBottom = bottom;
+
+	// Do NOT modify this algo or optimize it anyhow, sierra sci used int32 for calculating the
+	//  priority bands and by using double or anything rounding WILL destroy the result
+	bandSize = ((_priorityBottom - _priorityTop) * 2000) / _priorityBandCount;
+
+	memset(_priorityBands, 0, sizeof(byte) * _priorityTop);
+	for (y = _priorityTop; y < _priorityBottom; y++)
+		_priorityBands[y] = 1 + (((y - _priorityTop) * 2000) / bandSize);
+	if (_priorityBandCount == 15) {
+		// When having 15 priority bands, we actually replace band 15 with band 14, cause the original sci interpreter also
+		//  does it that way as well
+		y = _priorityBottom;
+		while (_priorityBands[--y] == _priorityBandCount)
+			_priorityBands[y]--;
+	}
+	// We fill space that is left over with the highest band
+	for (y = _priorityBottom; y < _screen->_height; y++)
+		_priorityBands[y] = _priorityBandCount;
+}
+
+void Gfx::PriorityBandsInit(byte *data) {
+	int i = 0, inx;
+	byte priority = 0;
+
+	for (inx = 0; inx < 14; inx++) {
+		priority = *data++;
+		while (i < priority)
+			_priorityBands[i++] = inx;
+	}
+	while (i < 200)
+		_priorityBands[i++] = inx;
+}
+
+byte Gfx::CoordinateToPriority(int16 y) {
+	if (y < _priorityTop) 
+		return _priorityBands[_priorityTop];
+	if (y > _priorityBottom)
+		return _priorityBands[_priorityBottom];
+	return _priorityBands[y];
+}
+
+int16 Gfx::PriorityToCoordinate(byte priority) {
+	int16 y;
+	if (priority <= _priorityBandCount) {
+		for (y = 0; y <= _priorityBottom; y++)
+			if (_priorityBands[y] == priority)
+				return y;
+	}
+	return _priorityBottom;
+}
+
+bool Gfx::CanBeHereCheckRectList(reg_t checkObject, Common::Rect checkRect, List *list) {
+	reg_t curAddress = list->first;
+	Node *curNode = _segMan->lookupNode(curAddress);
+	reg_t curObject;
+	uint16 signal;
+	Common::Rect curRect;
+
+	while (curNode) {
+		curObject = curNode->value;
+		if (curObject != checkObject) {
+			signal = GET_SEL32V(_segMan, curObject, signal);
+			if ((signal & (kSignalIgnoreActor | kSignalRemoveView | kSignalNoUpdate)) == 0) {
+				curRect.left = GET_SEL32V(_segMan, curObject, brLeft);
+				curRect.top = GET_SEL32V(_segMan, curObject, brTop);
+				curRect.right = GET_SEL32V(_segMan, curObject, brRight);
+				curRect.bottom = GET_SEL32V(_segMan, curObject, brBottom);
+				// Check if curRect is within checkRect
+				if (curRect.right > checkRect.left && curRect.left < checkRect.right && curRect.bottom > checkRect.top && curRect.top < checkRect.bottom) {
+					return false;
+				}
+			}
+		}
+		curAddress = curNode->succ;
+		curNode = _segMan->lookupNode(curAddress);
+	}
+	return true;
+}
+
+void Gfx::SetNowSeen(reg_t objectReference) {
+	View *view = NULL;
+	Common::Rect celRect(0, 0);
+	GuiResourceId viewId = (GuiResourceId)GET_SEL32V(_segMan, objectReference, view);
+	LoopNo loopNo = sign_extend_byte((LoopNo)GET_SEL32V(_segMan, objectReference, loop));
+	CelNo celNo = sign_extend_byte((CelNo)GET_SEL32V(_segMan, objectReference, cel));
+	int16 x = (int16)GET_SEL32V(_segMan, objectReference, x);
+	int16 y = (int16)GET_SEL32V(_segMan, objectReference, y);
+	int16 z = 0;
+	if (_kernel->_selectorCache.z > -1)
+		z = (int16)GET_SEL32V(_segMan, objectReference, z);
+
+	// now get cel rectangle
+	view = getView(viewId);
+	view->getCelRect(loopNo, celNo, x, y, z, &celRect);
+
+	// TODO: sometimes loop is negative. Check what it means
+	if (lookup_selector(_segMan, objectReference, _kernel->_selectorCache.nsTop, NULL, NULL) == kSelectorVariable) {
+		PUT_SEL32V(_segMan, objectReference, nsLeft, celRect.left);
+		PUT_SEL32V(_segMan, objectReference, nsRight, celRect.right);
+		PUT_SEL32V(_segMan, objectReference, nsTop, celRect.top);
+		PUT_SEL32V(_segMan, objectReference, nsBottom, celRect.bottom);
+	}
+}
+
+} // End of namespace Sci

Copied: scummvm/trunk/engines/sci/graphics/gfx.h (from rev 47007, scummvm/trunk/engines/sci/graphics/gui_gfx.h)
===================================================================
--- scummvm/trunk/engines/sci/graphics/gfx.h	                        (rev 0)
+++ scummvm/trunk/engines/sci/graphics/gfx.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -0,0 +1,130 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_GRAPHICS_GFX_H
+#define SCI_GRAPHICS_GFX_H
+
+#include "sci/graphics/gui.h"
+
+#include "common/hashmap.h"
+
+namespace Sci {
+
+#define SCI_TEXT_ALIGNMENT_RIGHT -1
+#define SCI_TEXT_ALIGNMENT_CENTER 1
+#define SCI_TEXT_ALIGNMENT_LEFT	0
+
+#define MAX_CACHED_VIEWS 50
+
+class Screen;
+class SciPalette;
+class Font;
+class SciGuiPicture;
+class View;
+
+typedef Common::HashMap<int, View *> ViewCache;
+
+class Gfx {
+public:
+	Gfx(ResourceManager *resMan, SegManager *segMan, Kernel *kernel, Screen *screen, SciPalette *palette);
+	~Gfx();
+
+	void init(Text *text);
+
+	byte *GetSegment(byte seg);
+	void ResetScreen();
+
+	Port *SetPort(Port *port);
+	Port *GetPort();
+	void SetOrigin(int16 left, int16 top);
+	void MoveTo(int16 left, int16 top);
+	void Move(int16 left, int16 top);
+	void OpenPort(Port *port);
+	void PenColor(int16 color);
+	void BackColor(int16 color);
+	void PenMode(int16 mode);
+	void TextGreyedOutput(bool state);
+	int16 GetPointSize();
+
+	void ClearScreen(byte color = 255);
+	void InvertRect(const Common::Rect &rect);
+	void EraseRect(const Common::Rect &rect);
+	void PaintRect(const Common::Rect &rect);
+	void FillRect(const Common::Rect &rect, int16 drawFlags, byte clrPen, byte clrBack = 0, byte bControl = 0);
+	void FrameRect(const Common::Rect &rect);
+	void OffsetRect(Common::Rect &r);
+	void OffsetLine(Common::Point &start, Common::Point &end);
+
+	void BitsShow(const Common::Rect &r);
+	MemoryHandle BitsSave(const Common::Rect &rect, byte screenFlags);
+	void BitsGetRect(MemoryHandle memoryHandle, Common::Rect *destRect);
+	void BitsRestore(MemoryHandle memoryHandle);
+	void BitsFree(MemoryHandle memoryHandle);
+
+	void drawPicture(GuiResourceId pictureId, int16 animationNr, bool mirroredFlag, bool addToFlag, GuiResourceId paletteId);
+	void drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, uint16 leftPos, uint16 topPos, byte priority, uint16 paletteNo, int16 origHeight = -1);
+	void drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, Common::Rect celRect, byte priority, uint16 paletteNo);
+	void drawCel(View *view, LoopNo loopNo, CelNo celNo, Common::Rect celRect, byte priority, uint16 paletteNo);
+
+	uint16 onControl(uint16 screenMask, Common::Rect rect);
+
+	void PriorityBandsInit(int16 bandCount, int16 top, int16 bottom);
+	void PriorityBandsInit(byte *data);
+	byte CoordinateToPriority(int16 y);
+	int16 PriorityToCoordinate(byte priority);
+
+	bool CanBeHereCheckRectList(reg_t checkObject, Common::Rect checkRect, List *list);
+
+	void SetNowSeen(reg_t objectReference);
+
+	Port *_menuPort;
+	Common::Rect _menuBarRect;
+	Port *_curPort;
+
+	View *getView(GuiResourceId viewNum);
+
+private:
+	void purgeCache();
+
+	ResourceManager *_resMan;
+	SegManager *_segMan;
+	Kernel *_kernel;
+	Screen *_screen;
+	SciPalette *_palette;
+	Text *_text;
+
+	Common::Rect _bounds;
+	Port *_mainPort;
+
+	// Priority Bands related variables
+	int16 _priorityTop, _priorityBottom, _priorityBandCount;
+	byte _priorityBands[200];
+
+	ViewCache _cachedViews;
+};
+
+} // End of namespace Sci
+
+#endif

Modified: scummvm/trunk/engines/sci/graphics/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/gui.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/graphics/gui.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -31,35 +31,35 @@
 #include "sci/event.h"
 #include "sci/engine/state.h"
 #include "sci/graphics/gui.h"
-#include "sci/graphics/gui_screen.h"
-#include "sci/graphics/gui_palette.h"
-#include "sci/graphics/gui_cursor.h"
-#include "sci/graphics/gui_gfx.h"
-#include "sci/graphics/gui_windowmgr.h"
-#include "sci/graphics/gui_animate.h"
-#include "sci/graphics/gui_controls.h"
-#include "sci/graphics/gui_menu.h"
-#include "sci/graphics/gui_text.h"
-#include "sci/graphics/gui_transitions.h"
-#include "sci/graphics/gui_view.h"
+#include "sci/graphics/screen.h"
+#include "sci/graphics/palette.h"
+#include "sci/graphics/cursor.h"
+#include "sci/graphics/gfx.h"
+#include "sci/graphics/windowmgr.h"
+#include "sci/graphics/animate.h"
+#include "sci/graphics/controls.h"
+#include "sci/graphics/menu.h"
+#include "sci/graphics/text.h"
+#include "sci/graphics/transitions.h"
+#include "sci/graphics/view.h"
 
 namespace Sci {
 
 // for debug purposes
 // class SciGui32 : public SciGui {
 // public:
-// 	SciGui32(EngineState *s, SciGuiScreen *screen, SciGuiPalette *palette, SciGuiCursor *cursor);
+// 	SciGui32(EngineState *s, Screen *screen, SciPalette *palette, Cursor *cursor);
 // 	~SciGui32();
 // };
 
-SciGui::SciGui(EngineState *state, SciGuiScreen *screen, SciGuiPalette *palette, SciGuiCursor *cursor)
+SciGui::SciGui(EngineState *state, Screen *screen, SciPalette *palette, Cursor *cursor)
 	: _s(state), _screen(screen), _palette(palette), _cursor(cursor) {
 
-	_gfx = new SciGuiGfx(_s->resMan, _s->_segMan, _s->_kernel, _screen, _palette);
-	_transitions = new SciGuiTransitions(this, _screen, _palette, _s->resMan->isVGA());
+	_gfx = new Gfx(_s->resMan, _s->_segMan, _s->_kernel, _screen, _palette);
+	_transitions = new Transitions(this, _screen, _palette, _s->resMan->isVGA());
 	_animate = new SciGuiAnimate(_s, _gfx, _screen, _palette);
-	_text = new SciGuiText(_s->resMan, _gfx, _screen);
-	_windowMgr = new SciGuiWindowMgr(this, _screen, _gfx, _text);
+	_text = new Text(_s->resMan, _gfx, _screen);
+	_windowMgr = new WindowMgr(this, _screen, _gfx, _text);
 	_controls = new SciGuiControls(_s->_segMan, _gfx, _text);
 	_menu = new SciGuiMenu(_s->_event, _s->_segMan, _gfx, _text, _screen, _cursor);
 //  	_gui32 = new SciGui32(_s, _screen, _palette, _cursor); // for debug purposes
@@ -142,13 +142,13 @@
 }
 
 void SciGui::globalToLocal(int16 *x, int16 *y) {
-	GuiPort *curPort = _gfx->GetPort();
+	Port *curPort = _gfx->GetPort();
 	*x = *x - curPort->left;
 	*y = *y - curPort->top;
 }
 
 void SciGui::localToGlobal(int16 *x, int16 *y) {
-	GuiPort *curPort = _gfx->GetPort();
+	Port *curPort = _gfx->GetPort();
 	*x = *x + curPort->left;
 	*y = *y + curPort->top;
 }
@@ -162,7 +162,7 @@
 }
 
 reg_t SciGui::newWindow(Common::Rect dims, Common::Rect restoreRect, uint16 style, int16 priority, int16 colorPen, int16 colorBack, const char *title) {
-	GuiWindow *wnd = NULL;
+	Window *wnd = NULL;
 
 	if (restoreRect.top != 0 && restoreRect.left != 0 && restoreRect.height() != 0 && restoreRect.width() != 0)
 		wnd = _windowMgr->NewWindow(dims, &restoreRect, title, style, priority, false);
@@ -176,7 +176,7 @@
 }
 
 void SciGui::disposeWindow(uint16 windowPtr, bool reanimate) {
-	GuiWindow *wnd = (GuiWindow *)_windowMgr->getPortById(windowPtr);
+	Window *wnd = (Window *)_windowMgr->getPortById(windowPtr);
 	_windowMgr->DisposeWindow(wnd, reanimate);
 }
 
@@ -193,13 +193,13 @@
 
 void SciGui::display(const char *text, int argc, reg_t *argv) {
 	int displayArg;
-	GuiTextAlignment alignment = SCI_TEXT_ALIGNMENT_LEFT;
+	TextAlignment alignment = SCI_TEXT_ALIGNMENT_LEFT;
 	int16 bgcolor = -1, width = -1, bRedraw = 1;
 	bool doSaveUnder = false;
 	Common::Rect rect;
 
 	// Make a "backup" of the port settings
-	GuiPort oldPort = *_gfx->GetPort();
+	Port oldPort = *_gfx->GetPort();
 
 	// setting defaults
 	_gfx->PenMode(0);
@@ -274,7 +274,7 @@
 	if (_screen->_picNotValid == 0 && bRedraw)
 		_gfx->BitsShow(rect);
 	// restoring port and cursor pos
-	GuiPort *currport = _gfx->GetPort();
+	Port *currport = _gfx->GetPort();
 	uint16 tTop = currport->curTop;
 	uint16 tLeft = currport->curLeft;
 	*currport = oldPort;
@@ -300,7 +300,7 @@
 }
 
 void SciGui::drawStatus(const char *text, int16 colorPen, int16 colorBack) {
-	GuiPort *oldPort = _gfx->SetPort(_gfx->_menuPort);
+	Port *oldPort = _gfx->SetPort(_gfx->_menuPort);
 
 	_gfx->FillRect(_gfx->_menuBarRect, 1, colorBack);
 	_gfx->PenColor(colorPen);
@@ -313,7 +313,7 @@
 
 void SciGui::drawMenuBar(bool clear) {
 	if (!clear) {
-		GuiPort *oldPort = _gfx->SetPort(_gfx->_menuPort);
+		Port *oldPort = _gfx->SetPort(_gfx->_menuPort);
 		_menu->drawBar();
 		if (_screen->_picNotValid == 0)
 			_gfx->BitsShow(_gfx->_menuBarRect);
@@ -345,7 +345,7 @@
 }
 
 void SciGui::drawPicture(GuiResourceId pictureId, int16 animationNr, bool animationBlackoutFlag, bool mirroredFlag, bool addToFlag, int16 EGApaletteNo) {
-	GuiPort *oldPort = _gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	Port *oldPort = _gfx->SetPort((Port *)_windowMgr->_picWind);
 
 	if (_windowMgr->isFrontWindow(_windowMgr->_picWind)) {
 		_screen->_picNotValid = 1;
@@ -359,7 +359,7 @@
 	_gfx->SetPort(oldPort);
 }
 
-void SciGui::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo, int16 origHeight) {
+void SciGui::drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo, int16 origHeight) {
 	_gfx->drawCel(viewId, loopNo, celNo, leftPos, topPos, priority, paletteNo, origHeight);
 	_palette->setOnScreen();
 }
@@ -392,7 +392,7 @@
 	}
 }
 
-void SciGui::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, GuiTextAlignment alignment, int16 style, bool hilite) {
+void SciGui::drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, TextAlignment alignment, int16 style, bool hilite) {
 	if (!hilite) {
 		rect.grow(1);
 		_gfx->EraseRect(rect);
@@ -430,7 +430,7 @@
 		_gfx->BitsShow(rect);
 }
 
-void SciGui::drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 style, bool hilite) {
+void SciGui::drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 style, bool hilite) {
 	if (!hilite) {
 		_gfx->drawCel(viewId, loopNo, celNo, rect.left, rect.top, 255, 0);
 		if (style & 0x20) {
@@ -510,7 +510,7 @@
 void SciGui::graphRedrawBox(Common::Rect rect) {
 	localToGlobal(&rect.left, &rect.top);
 	localToGlobal(&rect.right, &rect.bottom);
-	GuiPort *oldPort = _gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	Port *oldPort = _gfx->SetPort((Port *)_windowMgr->_picWind);
 	globalToLocal(&rect.left, &rect.top);
 	globalToLocal(&rect.right, &rect.bottom);
 
@@ -596,7 +596,7 @@
 }
 
 uint16 SciGui::onControl(byte screenMask, Common::Rect rect) {
-	GuiPort *oldPort = _gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	Port *oldPort = _gfx->SetPort((Port *)_windowMgr->_picWind);
 	uint16 result;
 
 	result = _gfx->onControl(screenMask, rect);
@@ -605,7 +605,7 @@
 }
 
 void SciGui::animateShowPic() {
-	GuiPort *picPort = _windowMgr->_picWind;
+	Port *picPort = _windowMgr->_picWind;
 	Common::Rect picRect = picPort->rect;
 	bool previousCursorState = _cursor->isVisible();
 
@@ -637,7 +637,7 @@
 			return;
 	}
 
-	GuiPort *oldPort = _gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	Port *oldPort = _gfx->SetPort((Port *)_windowMgr->_picWind);
 	_animate->disposeLastCast();
 
 	_animate->makeSortedList(list);
@@ -670,7 +670,7 @@
 void SciGui::addToPicList(reg_t listReference, int argc, reg_t *argv) {
 	List *list;
 
-	_gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	_gfx->SetPort((Port *)_windowMgr->_picWind);
 
 	list = _s->_segMan->lookupList(listReference);
 	if (!list)
@@ -682,8 +682,8 @@
 	addToPicSetPicNotValid();
 }
 
-void SciGui::addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
-	_gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+void SciGui::addToPicView(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
+	_gfx->SetPort((Port *)_windowMgr->_picWind);
 	_animate->addToPicDrawView(viewId, loopNo, celNo, leftPos, topPos, priority, control);
 	addToPicSetPicNotValid();
 }
@@ -693,7 +693,7 @@
 }
 
 bool SciGui::canBeHere(reg_t curObject, reg_t listReference) {
-	GuiPort *oldPort = _gfx->SetPort((GuiPort *)_windowMgr->_picWind);
+	Port *oldPort = _gfx->SetPort((Port *)_windowMgr->_picWind);
 	Common::Rect checkRect;
 	uint16 signal, controlMask;
 	bool result;
@@ -717,8 +717,8 @@
 }
 
 bool SciGui::isItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position) {
-	SciGuiView *tmpView = _gfx->getView(viewId);
-	sciViewCelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
+	View *tmpView = _gfx->getView(viewId);
+	CelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
 	position.x = CLIP<int>(position.x, 0, celInfo->width - 1);
 	position.y = CLIP<int>(position.y, 0, celInfo->height - 1);
 	byte *celData = tmpView->getBitmap(loopNo, celNo);
@@ -733,10 +733,10 @@
 		int16 z = (_s->_kernel->_selectorCache.z > -1) ? GET_SEL32V(_s->_segMan, object, z) : 0;
 		int16 yStep = GET_SEL32V(_s->_segMan, object, yStep);
 		GuiResourceId viewId = GET_SEL32V(_s->_segMan, object, view);
-		GuiViewLoopNo loopNo = GET_SEL32V(_s->_segMan, object, loop);
-		GuiViewCelNo celNo = GET_SEL32V(_s->_segMan, object, cel);
+		LoopNo loopNo = GET_SEL32V(_s->_segMan, object, loop);
+		CelNo celNo = GET_SEL32V(_s->_segMan, object, cel);
 
-		SciGuiView *tmpView = _gfx->getView(viewId);
+		View *tmpView = _gfx->getView(viewId);
 		Common::Rect celRect;
 
 		tmpView->getCelRect(loopNo, celNo, x, y, z, &celRect);

Modified: scummvm/trunk/engines/sci/graphics/gui.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/gui.h	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/graphics/gui.h	2010-01-05 01:37:57 UTC (rev 47009)
@@ -23,10 +23,10 @@
  *
  */
 
-#ifndef SCI_GUI_GUI_H
-#define SCI_GUI_GUI_H
+#ifndef SCI_GRAPHICS_GUI_H
+#define SCI_GRAPHICS_GUI_H
 
-#include "sci/graphics/gui_helpers.h"
+#include "sci/graphics/helpers.h"
 
 namespace Sci {
 
@@ -41,21 +41,21 @@
 	SCI_CONTROLS_TYPE_DUMMY			= 10
 };
 
-class SciGuiScreen;
-class SciGuiPalette;
-class SciGuiCursor;
-class SciGuiGfx;
-class SciGuiWindowMgr;
+class Screen;
+class SciPalette;
+class Cursor;
+class Gfx;
+class WindowMgr;
 class SciGuiAnimate;
 class SciGuiControls;
 class SciGuiMenu;
-class SciGuiText;
-class SciGuiTransitions;
+class Text;
+class Transitions;
 class SciGui32; // for debug purposes
 
 class SciGui {
 public:
-	SciGui(EngineState *s, SciGuiScreen *screen, SciGuiPalette *palette, SciGuiCursor *cursor);
+	SciGui(EngineState *s, Screen *screen, SciPalette *palette, Cursor *cursor);
 	SciGui();
 	virtual ~SciGui();
 
@@ -89,11 +89,11 @@
 	virtual reg_t menuSelect(reg_t eventObject);
 
 	virtual void drawPicture(GuiResourceId pictureId, int16 animationNr, bool animationBlackoutFlag, bool mirroredFlag, bool addToFlag, int16 EGApaletteNo);
-	virtual void drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo, int16 origHeight = -1);
+	virtual void drawCel(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, uint16 leftPos, uint16 topPos, int16 priority, uint16 paletteNo, int16 origHeight = -1);
 	virtual void drawControlButton(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 style, bool hilite);
 	virtual void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 alignment, int16 style, bool hilite);
 	virtual void drawControlTextEdit(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, int16 cursorPos, int16 maxChars, bool hilite);
-	virtual void drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 style, bool hilite);
+	virtual void drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 style, bool hilite);
 	virtual void drawControlList(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 style, int16 upperPos, int16 cursorPos, bool isAlias, bool hilite);
 	virtual void editControl(reg_t controlObject, reg_t eventObject);
 
@@ -125,7 +125,7 @@
 	virtual void animateShowPic();
 	virtual void animate(reg_t listReference, bool cycle, int argc, reg_t *argv);
 	virtual void addToPicList(reg_t listReference, int argc, reg_t *argv);
-	virtual void addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control);
+	virtual void addToPicView(GuiResourceId viewId, LoopNo loopNo, CelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control);
 	virtual void setNowSeen(reg_t objectReference);
 	virtual bool canBeHere(reg_t curObject, reg_t listReference);
 	virtual bool isItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position);
@@ -170,23 +170,23 @@
 	virtual void resetEngineState(EngineState *s);
 
 protected:
-	SciGuiCursor *_cursor;
+	Cursor *_cursor;
 	EngineState *_s;
-	SciGuiScreen *_screen;
-	SciGuiPalette *_palette;
-	SciGuiGfx *_gfx;
+	Screen *_screen;
+	SciPalette *_palette;
+	Gfx *_gfx;
 
 private:
 	virtual void initPriorityBands();
 	virtual void addToPicSetPicNotValid();
 	virtual int getControlPicNotValid();
 
-	SciGuiWindowMgr *_windowMgr;
+	WindowMgr *_windowMgr;
 	SciGuiAnimate *_animate;
 	SciGuiControls *_controls;
 	SciGuiMenu *_menu;
-	SciGuiText *_text;
-	SciGuiTransitions *_transitions;
+	Text *_text;
+	Transitions *_transitions;
 // 	SciGui32 *_gui32; // for debug purposes
 
 	bool _usesOldGfxFunctions;

Deleted: scummvm/trunk/engines/sci/graphics/gui_animate.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/gui_animate.cpp	2010-01-05 01:29:04 UTC (rev 47008)
+++ scummvm/trunk/engines/sci/graphics/gui_animate.cpp	2010-01-05 01:37:57 UTC (rev 47009)
@@ -1,559 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/util.h"
-#include "common/stack.h"
-#include "graphics/primitives.h"
-
-#include "sci/sci.h"
-#include "sci/engine/state.h"
-#include "sci/engine/vm.h"
-#include "sci/graphics/gui_gfx.h"
-#include "sci/graphics/gui_view.h"
-#include "sci/graphics/gui_screen.h"
-#include "sci/graphics/gui_transitions.h"
-#include "sci/graphics/gui_animate.h"
-
-namespace Sci {
-
-SciGuiAnimate::SciGuiAnimate(EngineState *state, SciGuiGfx *gfx, SciGuiScreen *screen, SciGuiPalette *palette)
-	: _s(state), _gfx(gfx), _screen(screen), _palette(palette) {
-	init();
-}
-
-SciGuiAnimate::~SciGuiAnimate() {
-	free(_listData);
-	free(_lastCastData);
-}
-
-void SciGuiAnimate::init() {
-	_listData = NULL;
-	_listCount = 0;
-	_lastCastData = NULL;
-	_lastCastCount = 0;
-
-	_ignoreFastCast = false;
-	// fastCast object is not found in any SCI games prior SCI1
-	if (getSciVersion() <= SCI_VERSION_01)
-		_ignoreFastCast = true;
-	// Also if fastCast object exists at gamestartup, we can assume that the interpreter doesnt do kAnimate aborts
-	//  (found in larry 1)
-	if (!_s->_segMan->findObjectByName("fastCast").isNull())
-		_ignoreFastCast = true;
-}
-
-void SciGuiAnimate::disposeLastCast() {
-	_lastCastCount = 0;
-}
-
-bool SciGuiAnimate::invoke(List *list, int argc, reg_t *argv) {
-	reg_t curAddress = list->first;
-	Node *curNode = _s->_segMan->lookupNode(curAddress);
-	reg_t curObject;
-	uint16 signal;
-
-	while (curNode) {
-		curObject = curNode->value;
-
-		if (!_ignoreFastCast) {
-			// Check if the game has a fastCast object set
-			//  if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
-			reg_t global84 = _s->script_000->_localsBlock->_locals[84];
-
-			if (!global84.isNull()) {
-				if (!strcmp(_s->_segMan->getObjectName(global84), "fastCast"))
-					return false;
-			}
-		}
-
-		signal = GET_SEL32V(_s->_segMan, curObject, signal);
-		if (!(signal & kSignalFrozen)) {
-			// Call .doit method of that object
-			invoke_selector(_s, curObject, _s->_kernel->_selectorCache.doit, kContinueOnInvalidSelector, argv, argc, 0);
-			// Lookup node again, since the nodetable it was in may have been reallocated
-			curNode = _s->_segMan->lookupNode(curAddress);
-		}
-		curAddress = curNode->succ;
-		curNode = _s->_segMan->lookupNode(curAddress);
-	}
-	return true;
-}
-
-bool sortHelper(const GuiAnimateEntry* entry1, const GuiAnimateEntry* entry2) {
-	return (entry1->y == entry2->y) ? (entry1->z < entry2->z) : (entry1->y < entry2->y);
-}
-
-void SciGuiAnimate::makeSortedList(List *list) {
-	reg_t curAddress = list->first;
-	Node *curNode = _s->_segMan->lookupNode(curAddress);
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	int16 listNr, listCount = 0;
-
-	// Count the list entries
-	while (curNode) {
-		listCount++;
-		curAddress = curNode->succ;
-		curNode = _s->_segMan->lookupNode(curAddress);
-	}
-
-	_list.clear();
-
-	// No entries -> exit immediately
-	if (listCount == 0)
-		return;
-
-	// Adjust list size, if needed
-	if ((_listData == NULL) || (_listCount < listCount)) {
-		free(_listData);
-		_listData = (GuiAnimateEntry *)malloc(listCount * sizeof(GuiAnimateEntry));
-		if (!_listData)
-			error("Could not allocate memory for _listData");
-		_listCount = listCount;
-
-		free(_lastCastData);
-		_lastCastData = (GuiAnimateEntry *)malloc(listCount * sizeof(GuiAnimateEntry));
-		if (!_lastCastData)
-			error("Could not allocate memory for _lastCastData");
-		_lastCastCount = 0;
-	}
-
-	// Fill the list
-	curAddress = list->first;
-	curNode = _s->_segMan->lookupNode(curAddress);
-	listEntry = _listData;
-	for (listNr = 0; listNr < listCount; listNr++) {
-		curObject = curNode->value;
-		listEntry->object = curObject;
-
-		// Get data from current object
-		listEntry->viewId = GET_SEL32V(_s->_segMan, curObject, view);
-		listEntry->loopNo = GET_SEL32V(_s->_segMan, curObject, loop);
-		listEntry->celNo = GET_SEL32V(_s->_segMan, curObject, cel);
-		listEntry->paletteNo = GET_SEL32V(_s->_segMan, curObject, palette);
-		listEntry->x = GET_SEL32V(_s->_segMan, curObject, x);
-		listEntry->y = GET_SEL32V(_s->_segMan, curObject, y);
-		listEntry->z = GET_SEL32V(_s->_segMan, curObject, z);
-		listEntry->priority = GET_SEL32V(_s->_segMan, curObject, priority);
-		listEntry->signal = GET_SEL32V(_s->_segMan, curObject, signal);
-		// listEntry->celRect is filled in AnimateFill()
-		listEntry->showBitsFlag = false;
-
-		_list.push_back(listEntry);
-
-		listEntry++;
-		curAddress = curNode->succ;
-		curNode = _s->_segMan->lookupNode(curAddress);
-	}
-
-	// Now sort the list according y and z (descending)
-	GuiAnimateList::iterator listBegin = _list.begin();
-	GuiAnimateList::iterator listEnd = _list.end();
-
-	Common::sort(_list.begin(), _list.end(), sortHelper);
-}
-
-void SciGuiAnimate::fill(byte &old_picNotValid) {
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	uint16 signal;
-	SciGuiView *view = NULL;
-	GuiAnimateList::iterator listIterator;
-	GuiAnimateList::iterator listEnd = _list.end();
-
-	listIterator = _list.begin();
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-
-		// Get the corresponding view
-		view = _gfx->getView(listEntry->viewId);
-		
-		// adjust loop and cel, if any of those is invalid
-		if (listEntry->loopNo >= view->getLoopCount()) {
-			listEntry->loopNo = 0;
-			PUT_SEL32V(_s->_segMan, curObject, loop, listEntry->loopNo);
-		}
-		if (listEntry->celNo >= view->getCelCount(listEntry->loopNo)) {
-			listEntry->celNo = 0;
-			PUT_SEL32V(_s->_segMan, curObject, cel, listEntry->celNo);
-		}
-
-		// Create rect according to coordinates and given cel
-		view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
-		PUT_SEL32V(_s->_segMan, curObject, nsLeft, listEntry->celRect.left);
-		PUT_SEL32V(_s->_segMan, curObject, nsTop, listEntry->celRect.top);
-		PUT_SEL32V(_s->_segMan, curObject, nsRight, listEntry->celRect.right);
-		PUT_SEL32V(_s->_segMan, curObject, nsBottom, listEntry->celRect.bottom);
-
-		signal = listEntry->signal;
-
-		// Calculate current priority according to y-coordinate
-		if (!(signal & kSignalFixedPriority)) {
-			listEntry->priority = _gfx->CoordinateToPriority(listEntry->y);
-			PUT_SEL32V(_s->_segMan, curObject, priority, listEntry->priority);
-		}
-		
-		if (signal & kSignalNoUpdate) {
-			if (signal & (kSignalForceUpdate | kSignalViewUpdated)
-				|| (signal & kSignalHidden && !(signal & kSignalRemoveView))
-				|| (!(signal & kSignalHidden) && signal & kSignalRemoveView)
-				|| (signal & kSignalAlwaysUpdate))
-				old_picNotValid++;
-			signal &= 0xFFFF ^ kSignalStopUpdate;
-		} else {
-			if (signal & kSignalStopUpdate || signal & kSignalAlwaysUpdate)
-				old_picNotValid++;
-			signal &= 0xFFFF ^ kSignalForceUpdate;
-		}
-		listEntry->signal = signal;
-
-		listIterator++;
-	}
-}
-
-void SciGuiAnimate::update() {
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	uint16 signal;
-	reg_t bitsHandle;
-	Common::Rect rect;
-	GuiAnimateList::iterator listIterator;
-	GuiAnimateList::iterator listBegin = _list.begin();
-	GuiAnimateList::iterator listEnd = _list.end();
-
-	// Remove all no-update cels, if requested
-	listIterator = _list.reverse_begin();
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (signal & kSignalNoUpdate) {
-			if (!(signal & kSignalRemoveView)) {
-				bitsHandle = GET_SEL32(_s->_segMan, curObject, underBits);
-				if (_screen->_picNotValid != 1) {
-					_gfx->BitsRestore(bitsHandle);
-					listEntry->showBitsFlag = true;
-				} else	{
-					_gfx->BitsFree(bitsHandle);
-				}
-				PUT_SEL32V(_s->_segMan, curObject, underBits, 0);
-			}
-			signal &= 0xFFFF ^ kSignalForceUpdate;
-			signal &= signal & kSignalViewUpdated ? 0xFFFF ^ (kSignalViewUpdated | kSignalNoUpdate) : 0xFFFF;
-		} else if (signal & kSignalStopUpdate) {
-			signal =  (signal & (0xFFFF ^ kSignalStopUpdate)) | kSignalNoUpdate;
-		}
-		listEntry->signal = signal;
-		listIterator--;
-	}
-
-	// Draw always-update cels
-	listIterator = listBegin;
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (signal & kSignalAlwaysUpdate) {
-			// draw corresponding cel
-			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
-			listEntry->showBitsFlag = true;
-
-			signal &= 0xFFFF ^ (kSignalStopUpdate | kSignalViewUpdated | kSignalNoUpdate | kSignalForceUpdate);
-			if ((signal & kSignalIgnoreActor) == 0) {
-				rect = listEntry->celRect;
-				rect.top = CLIP<int16>(_gfx->PriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);  
-				_gfx->FillRect(rect, SCI_SCREEN_MASK_CONTROL, 0, 0, 15);
-			}
-			listEntry->signal = signal;
-		}
-		listIterator++;
-	}
-
-	// Saving background for all NoUpdate-cels
-	listIterator = listBegin;
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (signal & kSignalNoUpdate) {
-			if (signal & kSignalHidden) {
-				signal |= kSignalRemoveView;
-			} else {
-				signal &= 0xFFFF ^ kSignalRemoveView;
-				if (signal & kSignalIgnoreActor)
-					bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_VISUAL|SCI_SCREEN_MASK_PRIORITY);
-				else
-					bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_ALL);
-				PUT_SEL32(_s->_segMan, curObject, underBits, bitsHandle);
-			}
-			listEntry->signal = signal;
-		}
-		listIterator++;
-	}
-
-	// Draw NoUpdate cels
-	listIterator = listBegin;
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (signal & kSignalNoUpdate && !(signal & kSignalHidden)) {
-			// draw corresponding cel
-			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
-			listEntry->showBitsFlag = true;
-
-			if ((signal & kSignalIgnoreActor) == 0) {
-				rect = listEntry->celRect;
-				rect.top = CLIP<int16>(_gfx->PriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);  
-				_gfx->FillRect(rect, SCI_SCREEN_MASK_CONTROL, 0, 0, 15);
-			}
-		}
-		listIterator++;
-	}
-}
-
-void SciGuiAnimate::drawCels() {
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	GuiAnimateEntry *lastCastEntry = _lastCastData;
-	uint16 signal;
-	reg_t bitsHandle;
-	GuiAnimateList::iterator listIterator;
-	GuiAnimateList::iterator listEnd = _list.end();
-
-	_lastCastCount = 0;
-
-	listIterator = _list.begin();
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (!(signal & (kSignalNoUpdate | kSignalHidden | kSignalAlwaysUpdate))) {
-			// Save background
-			bitsHandle = _gfx->BitsSave(listEntry->celRect, SCI_SCREEN_MASK_ALL);
-			PUT_SEL32(_s->_segMan, curObject, underBits, bitsHandle);
-
-			// draw corresponding cel
-			_gfx->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
-			listEntry->showBitsFlag = true;
-
-			if (signal & kSignalRemoveView) {
-				signal &= 0xFFFF ^ kSignalRemoveView;
-			}
-			listEntry->signal = signal;
-
-			// Remember that entry in lastCast
-			memcpy(lastCastEntry, listEntry, sizeof(GuiAnimateEntry));
-			lastCastEntry++; _lastCastCount++;
-		}
-		listIterator++;
-	}
-}
-
-void SciGuiAnimate::updateScreen(byte oldPicNotValid) {
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	uint16 signal;
-	GuiAnimateList::iterator listIterator;
-	GuiAnimateList::iterator listEnd = _list.end();
-	Common::Rect lsRect;
-	Common::Rect workerRect;
-
-	listIterator = _list.begin();
-	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		curObject = listEntry->object;
-		signal = listEntry->signal;
-
-		if (listEntry->showBitsFlag || !(signal & (kSignalRemoveView | kSignalNoUpdate) ||
-										(!(signal & kSignalRemoveView) && (signal & kSignalNoUpdate) && oldPicNotValid))) {
-			lsRect.left = GET_SEL32V(_s->_segMan, curObject, lsLeft);
-			lsRect.top = GET_SEL32V(_s->_segMan, curObject, lsTop);
-			lsRect.right = GET_SEL32V(_s->_segMan, curObject, lsRight);
-			lsRect.bottom = GET_SEL32V(_s->_segMan, curObject, lsBottom);
-
-			workerRect = lsRect;
-			workerRect.clip(listEntry->celRect);
-
-			if (!workerRect.isEmpty()) {
-				workerRect = lsRect;
-				workerRect.extend(listEntry->celRect);
-			} else {
-				_gfx->BitsShow(lsRect);
-				workerRect = listEntry->celRect;
-			}
-			PUT_SEL32V(_s->_segMan, curObject, lsLeft, workerRect.left);
-			PUT_SEL32V(_s->_segMan, curObject, lsTop, workerRect.top);
-			PUT_SEL32V(_s->_segMan, curObject, lsRight, workerRect.right);
-			PUT_SEL32V(_s->_segMan, curObject, lsBottom, workerRect.bottom);
-			_gfx->BitsShow(workerRect);
-
-			if (signal & kSignalHidden) {
-				listEntry->signal |= kSignalRemoveView;
-			}
-		}
-
-		listIterator++;
-	}
-	// use this for debug purposes
-	// _screen->copyToScreen();
-}
-
-void SciGuiAnimate::restoreAndDelete(int argc, reg_t *argv) {
-	reg_t curObject;
-	GuiAnimateEntry *listEntry;
-	uint16 signal;
-	GuiAnimateList::iterator listIterator;
-	GuiAnimateList::iterator listEnd = _list.end();
-
-
-	// This has to be done in a separate loop. At least in sq1 some .dispose modifies FIXEDLOOP flag in signal for

@@ Diff output truncated at 100000 characters. @@

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list