[Scummvm-cvs-logs] CVS: scummvm newgui.cpp,1.13,1.14 newgui.h,1.8,1.9

Max Horn fingolfin at users.sourceforge.net
Wed Jul 10 09:50:04 CEST 2002


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv17768

Modified Files:
	newgui.cpp newgui.h 
Log Message:
improved the alpha blending code, now works properly for nesting/redraw (changed meaning of WIDGET_CLEARBG a little bit for this)

Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/newgui.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- newgui.cpp	9 Jul 2002 12:38:50 -0000	1.13
+++ newgui.cpp	10 Jul 2002 16:49:44 -0000	1.14
@@ -95,8 +95,9 @@
  * - ...
  */
 
-NewGui::NewGui(Scumm *s) : _s(s), _need_redraw(false), _pauseDialog(0),
-	_saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0)
+NewGui::NewGui(Scumm *s) : _s(s), _use_alpha_blending(true),
+	_need_redraw(false),_prepare_for_gui(true),
+	_pauseDialog(0), _saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0)
 {	
 }
 
@@ -109,7 +110,6 @@
 
 void NewGui::saveloadDialog()
 {
-	ClearBlendCache(_s->_currentPalette, 128);
 	if (!_saveLoadDialog)
 		_saveLoadDialog = new SaveLoadDialog(this);
 	openDialog(_saveLoadDialog);
@@ -133,11 +133,19 @@
 {
 	Dialog *activeDialog = _dialogStack.top();
 	
+	if (_prepare_for_gui) {
+		ClearBlendCache(_s->_currentPalette, 128);
+		saveState();
+		if (_use_alpha_blending)
+			activeDialog->setupScreenBuf();
+		_prepare_for_gui = false;
+	}
+	
 	if (_need_redraw) {
 		activeDialog->draw();
-		saveState();
 		_need_redraw = false;
 	}
+	
 	_s->animateCursor();
 	_s->getKeyInput(0);
 	if (_s->_mouseButStat & MBS_LEFT_CLICK) {		
@@ -194,17 +202,31 @@
 
 void NewGui::openDialog(Dialog *dialog)
 {
+	if (_dialogStack.empty())
+		_prepare_for_gui = true;
+	else if (_use_alpha_blending)
+		dialog->setupScreenBuf();
+
 	_dialogStack.push(dialog);
 	_need_redraw = true;
 }
 
 void NewGui::closeTopDialog()
 {
+	// Don't do anything if no dialog is open
+	if (_dialogStack.empty())
+		return;
+	
+	// Tear down its screenBuf
+	if (_use_alpha_blending)
+		_dialogStack.top()->teardownScreenBuf();
+	
+	// Remove the dialog from the stack
 	_dialogStack.pop();
 	if (_dialogStack.empty())
 		restoreState();
 	else
-		_dialogStack.top()->draw();
+		_need_redraw = true;
 }
 
 #pragma mark -
@@ -298,6 +320,20 @@
 	}
 }
 
+void NewGui::blendArea(int x, int y, int w, int h, byte color)
+{
+	byte *ptr = getBasePtr(x, y);
+	if (ptr == NULL)
+		return;
+
+	while (h--) {
+		for (int i = 0; i < w; i++) {
+			ptr[i] = Blend(ptr[i], color, _s->_currentPalette);
+		}
+		ptr += 320;
+	}
+}
+
 void NewGui::fillArea(int x, int y, int w, int h, byte color)
 {
 	byte *ptr = getBasePtr(x, y);
@@ -306,10 +342,8 @@
 
 	while (h--) {
 		for (int i = 0; i < w; i++) {
-			int srcc = ptr[i];
-			ptr[i] = Blend(srcc, color, _s->_currentPalette);
+			ptr[i] = color;
 		}
-			//ptr[i] = color;
 		ptr += 320;
 	}
 }
@@ -392,3 +426,36 @@
 		ptr += 320;
 	}
 }
+
+void NewGui::blitTo(byte buffer[320*200], int x, int y, int w, int h)
+{
+	byte *dstPtr = buffer + x + y*320;
+	byte *srcPtr = getBasePtr(x, y);
+	if (srcPtr == NULL)
+		return;
+
+	while (h--) {
+		for (int i = 0; i < w; i++) {
+			*dstPtr++ = *srcPtr++;
+		}
+		dstPtr += 320 - w;
+		srcPtr += 320 - w;
+	}
+}
+
+void NewGui::blitFrom(byte buffer[320*200], int x, int y, int w, int h)
+{
+	byte *srcPtr = buffer + x + y*320;
+	byte *dstPtr = getBasePtr(x, y);
+	if (dstPtr == NULL)
+		return;
+
+	while (h--) {
+		for (int i = 0; i < w; i++) {
+			*dstPtr++ = *srcPtr++;
+		}
+		dstPtr += 320 - w;
+		srcPtr += 320 - w;
+	}
+}
+

Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/newgui.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- newgui.h	8 Jul 2002 22:11:45 -0000	1.8
+++ newgui.h	10 Jul 2002 16:49:45 -0000	1.9
@@ -63,7 +63,9 @@
 
 protected:
 	Scumm		*_s;
+	bool		_use_alpha_blending;
 	bool		_need_redraw;
+	bool		_prepare_for_gui;
 	DialogStack	_dialogStack;
 	
 	Dialog		*_pauseDialog;
@@ -94,12 +96,16 @@
 	// Drawing
 	byte *getBasePtr(int x, int y);
 	void box(int x, int y, int width, int height);
-    void line(int x, int y, int x2, int y2, byte color);
-    void fillArea(int x, int y, int w, int h, byte color);
-    void setAreaDirty(int x, int y, int w, int h);
+	void line(int x, int y, int x2, int y2, byte color);
+	void blendArea(int x, int y, int w, int h, byte color);
+	void fillArea(int x, int y, int w, int h, byte color);
+	void setAreaDirty(int x, int y, int w, int h);
 	void drawChar(const char c, int x, int y);
 	void drawString(const char *str, int x, int y, int w, byte color);
+
 	void drawBitmap(uint32 bitmap[8], int x, int y, byte color);
+	void blitTo(byte buffer[320*200], int x, int y, int w, int h);
+	void blitFrom(byte buffer[320*200], int x, int y, int w, int h);
 
 	// Query a string from the resources
 	const char *queryResString(int stringno);





More information about the Scummvm-git-logs mailing list