[Scummvm-git-logs] scummvm master -> 2a0e6ae9d652d8349396f2fb7d7c54f336f152fe

Strangerke noreply at scummvm.org
Tue May 14 22:02:27 UTC 2024


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

Summary:
2a0e6ae9d6 BAGEL: Split more assignments out of if statements, more work on fatal errors


Commit: 2a0e6ae9d652d8349396f2fb7d7c54f336f152fe
    https://github.com/scummvm/scummvm/commit/2a0e6ae9d652d8349396f2fb7d7c54f336f152fe
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-14T23:02:11+01:00

Commit Message:
BAGEL: Split more assignments out of if statements, more work on fatal errors

Changed paths:
    engines/bagel/baglib/storage_dev_win.cpp
    engines/bagel/baglib/text_object.cpp
    engines/bagel/baglib/time_object.cpp
    engines/bagel/boflib/gfx/bitmap.cpp
    engines/bagel/boflib/gfx/text.cpp
    engines/bagel/boflib/gui/button.cpp


diff --git a/engines/bagel/baglib/storage_dev_win.cpp b/engines/bagel/baglib/storage_dev_win.cpp
index 5d2ae64ddd9..4657618b143 100644
--- a/engines/bagel/baglib/storage_dev_win.cpp
+++ b/engines/bagel/baglib/storage_dev_win.cpp
@@ -1160,7 +1160,7 @@ CBagStorageDevWnd::CBagStorageDevWnd() : CBofWindow() {
 CBagStorageDevWnd::~CBagStorageDevWnd() {
 	assert(isValidObject(this));
 
-	killWorkBmp();
+	CBagStorageDevWnd::killWorkBmp();
 }
 
 
@@ -1440,26 +1440,24 @@ ErrorCode CBagStorageDevWnd::loadFile(const CBofString &sFile) {
 		reportError(ERR_FOPEN, "Unable to open file %s", sWldFile.getBuffer());
 	else {
 		char *pBuf = (char *)bofAlloc(nLength);
-		if (pBuf != nullptr) {
-			CBagIfstream fpInput(pBuf, nLength);
+		if (pBuf == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a buffer of %d bytes", nLength);
 
-			CBofFile cFile;
-			cFile.open(sWldFile);
-			cFile.read(pBuf, nLength);
-			cFile.close();
+		CBagIfstream fpInput(pBuf, nLength);
 
-			CBagStorageDev::loadFileFromStream(fpInput, sWldFile);
+		CBofFile cFile;
+		cFile.open(sWldFile);
+		cFile.read(pBuf, nLength);
+		cFile.close();
 
-			// If the window.isCreated()
-			//
-			if (isCreated())
-				invalidateRect(nullptr);
+		CBagStorageDev::loadFileFromStream(fpInput, sWldFile);
 
-			bofFree(pBuf);
+		// If the window.isCreated()
+		//
+		if (isCreated())
+			invalidateRect(nullptr);
 
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a buffer of %d bytes", nLength);
-		}
+		bofFree(pBuf);
 	}
 
 	// Add everything to the window
diff --git a/engines/bagel/baglib/text_object.cpp b/engines/bagel/baglib/text_object.cpp
index 126dcca289f..c68482a779b 100644
--- a/engines/bagel/baglib/text_object.cpp
+++ b/engines/bagel/baglib/text_object.cpp
@@ -142,28 +142,26 @@ ErrorCode CBagTextObject::attach() {
 				// Allocate the buffers
 				uint32 nFileLen = fpTextFile.getLength();
 				char *pTextBuff = (char *)bofCAlloc(nFileLen + 1, 1);
-				if (pTextBuff != nullptr) {
-					// Read the text file into buffers
-					fpTextFile.read(pTextBuff, nFileLen);
-					fpTextFile.close();
+				if (pTextBuff == nullptr)
+					fatalError(ERR_MEMORY, "Unable to allocate a Text buffer of %u bytes", nFileLen + 1);
 
-					*_psText += pTextBuff;
+				// Read the text file into buffers
+				fpTextFile.read(pTextBuff, nFileLen);
+				fpTextFile.close();
 
-					if (_psInitInfo != nullptr) {
-						CBagVar *pVar = g_VarManager->getVariable(*_psInitInfo);
+				*_psText += pTextBuff;
 
-						if (pVar != nullptr) {
-							_bReAttach = true;
-							_psText->replaceStr("%s", pVar->getValue());
-						}
-					}
-
-					bofFree(pTextBuff);
+				if (_psInitInfo != nullptr) {
+					CBagVar *pVar = g_VarManager->getVariable(*_psInitInfo);
 
-				} else {
-					reportError(ERR_MEMORY, "Unable to allocate a Text buffer of %u bytes", nFileLen + 1);
+					if (pVar != nullptr) {
+						_bReAttach = true;
+						_psText->replaceStr("%s", pVar->getValue());
+					}
 				}
 
+				bofFree(pTextBuff);
+
 			} else {
 				reportError(ERR_FOPEN, "Failed to create a CBofFile for %s", getFileName().getBuffer());
 			}
@@ -181,17 +179,15 @@ ErrorCode CBagTextObject::attach() {
 
 		// Allocate a new string
 		_psText = new CBofString;
-		if (_psText != nullptr) {
-			*_psText = getFileName();
+		if (_psText == nullptr)
+			fatalError(ERR_MEMORY, "Unable to allocate a CBofString");
 
-			// Replace any underscores with spaces
-			_psText->replaceChar('_', ' ');
+		*_psText = getFileName();
 
-			recalcTextRect(false);
+		// Replace any underscores with spaces
+		_psText->replaceChar('_', ' ');
 
-		} else {
-			reportError(ERR_MEMORY, "Unable to allocate a CBofString");
-		}
+		recalcTextRect(false);
 	}
 
 	// If this guy is linked to a residue printing object, make sure he knows
diff --git a/engines/bagel/baglib/time_object.cpp b/engines/bagel/baglib/time_object.cpp
index fe5caa3334e..2a7b5656bd8 100644
--- a/engines/bagel/baglib/time_object.cpp
+++ b/engines/bagel/baglib/time_object.cpp
@@ -47,76 +47,68 @@ ErrorCode CBagTimeObject::attach() {
 	CBofPoint p = CBagObject::getPosition();
 
 	_xDig1 = new CBofSprite();
-	if (_xDig1 != nullptr) {
-		if (_xDig1->loadSprite(getFileName(), getCels()) != 0 && (_xDig1->width() != 0) && (_xDig1->height() != 0)) {
-			_xDig1->setAnimated(false);
-			_xDig1->setPosition(p.x, p.y);
+	if (_xDig1 == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate  Dig1 sprite");
 
-			p.offset(_xDig1->width(), 0);
+	if (_xDig1->loadSprite(getFileName(), getCels()) != 0 && (_xDig1->width() != 0) && (_xDig1->height() != 0)) {
+		_xDig1->setAnimated(false);
+		_xDig1->setPosition(p.x, p.y);
 
-		} else {
-			reportError(ERR_FOPEN, "Could Not Open Dig1 Sprite: %s", _xDig1->getFileName());
-		}
+		p.offset(_xDig1->width(), 0);
 
 	} else {
-		reportError(ERR_MEMORY, "Could not allocate  Dig1 sprite");
+		reportError(ERR_FOPEN, "Could Not Open Dig1 Sprite: %s", _xDig1->getFileName());
 	}
 
 	_xDig2 = new CBofSprite();
-	if (_xDig2 != nullptr) {
-		if (_xDig2->loadSprite(getFileName(), getCels()) != 0 && (_xDig2->width() != 0) && (_xDig2->height() != 0)) {
-			_xDig2->setAnimated(false);
-			_xDig2->setPosition(p.x, p.y);
-			p.offset(_xDig2->width(), 0);
-		} else {
-			reportError(ERR_FOPEN, "Could Not Open Dig2 Sprite: %s", _xDig2->getFileName());
-		}
+	if (_xDig2 == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate  Dig2 sprite");
+
+	if (_xDig2->loadSprite(getFileName(), getCels()) != 0 && (_xDig2->width() != 0) && (_xDig2->height() != 0)) {
+		_xDig2->setAnimated(false);
+		_xDig2->setPosition(p.x, p.y);
+		p.offset(_xDig2->width(), 0);
 	} else {
-		reportError(ERR_MEMORY, "Could not allocate  Dig2 sprite");
+		reportError(ERR_FOPEN, "Could Not Open Dig2 Sprite: %s", _xDig2->getFileName());
 	}
 
 	_xColon = new CBofSprite();
-	if (_xColon != nullptr) {
-		if (_xColon->loadSprite(getFileName(), getCels()) != 0 && (_xColon->width() != 0) && (_xColon->height() != 0)) {
+	if (_xColon == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate  Colon sprite");
 
-			_xColon->setAnimated(false);
-			// The time sprite should start with 0 and go to 9 followed by the :
-			_xColon->setCel(_nCels - 1);
-			_xColon->setPosition(p.x, p.y);
-
-			p.offset(_xColon->width(), 0);
-		} else {
-			reportError(ERR_FOPEN, "Could Not Open Colon Sprite: %s", _xColon->getFileName());
-		}
+	if (_xColon->loadSprite(getFileName(), getCels()) != 0 && (_xColon->width() != 0) && (_xColon->height() != 0)) {
+		_xColon->setAnimated(false);
+		// The time sprite should start with 0 and go to 9 followed by the :
+		_xColon->setCel(_nCels - 1);
+		_xColon->setPosition(p.x, p.y);
 
+		p.offset(_xColon->width(), 0);
 	} else {
-		reportError(ERR_MEMORY, "Could not allocate  Colon sprite");
+		reportError(ERR_FOPEN, "Could Not Open Colon Sprite: %s", _xColon->getFileName());
 	}
 
 	_xDig3 = new CBofSprite();
-	if (_xDig3 != nullptr) {
-		if (_xDig3->loadSprite(getFileName(), getCels()) != 0 && (_xDig3->width() != 0) && (_xDig3->height() != 0)) {
-			_xDig3->setAnimated(false);
-			_xDig3->setPosition(p.x, p.y);
-			p.offset(_xDig3->width(), 0);
-		} else {
-			reportError(ERR_FOPEN, "Could Not Open Dig3 Sprite: %s", _xDig3->getFileName());
-		}
+	if (_xDig3 == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate  Dig3 sprite");
+
+	if (_xDig3->loadSprite(getFileName(), getCels()) != 0 && (_xDig3->width() != 0) && (_xDig3->height() != 0)) {
+		_xDig3->setAnimated(false);
+		_xDig3->setPosition(p.x, p.y);
+		p.offset(_xDig3->width(), 0);
 	} else {
-		reportError(ERR_MEMORY, "Could not allocate  Dig3 sprite");
+		reportError(ERR_FOPEN, "Could Not Open Dig3 Sprite: %s", _xDig3->getFileName());
 	}
 
 	_xDig4 = new CBofSprite();
-	if (_xDig4 != nullptr) {
-		if (_xDig4->loadSprite(getFileName(), getCels()) != 0 && (_xDig4->width() != 0) && (_xDig4->height() != 0)) {
-			_xDig4->setAnimated(false);
-			_xDig4->setPosition(p.x, p.y);
-			p.offset(_xDig4->width(), 0);
-		} else {
-			reportError(ERR_FOPEN, "Could Not Open Dig4 Sprite: %s", _xDig4->getFileName());
-		}
+	if (_xDig4 == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate  Dig4 sprite");
+
+	if (_xDig4->loadSprite(getFileName(), getCels()) != 0 && (_xDig4->width() != 0) && (_xDig4->height() != 0)) {
+		_xDig4->setAnimated(false);
+		_xDig4->setPosition(p.x, p.y);
+		p.offset(_xDig4->width(), 0);
 	} else {
-		reportError(ERR_MEMORY, "Could not allocate  Dig4 sprite");
+		reportError(ERR_FOPEN, "Could Not Open Dig4 Sprite: %s", _xDig4->getFileName());
 	}
 
 	return CBagObject::attach();
diff --git a/engines/bagel/boflib/gfx/bitmap.cpp b/engines/bagel/boflib/gfx/bitmap.cpp
index 6a0a4bd15d2..5d287d1b4f9 100644
--- a/engines/bagel/boflib/gfx/bitmap.cpp
+++ b/engines/bagel/boflib/gfx/bitmap.cpp
@@ -166,7 +166,9 @@ ErrorCode CBofBitmap::loadBitmap(const char *pszFileName, CBofPalette *pPalette)
 		CBofFile *pFile = new CBofFile(pszFileName, CBOFFILE_READONLY);
 
 		// Open bitmap
-		if (pFile != nullptr) {
+		if (pFile == nullptr)
+			reportError(ERR_MEMORY, "Could not allocate a CBofFile for %s", pszFileName);
+		else {
 			// filename must fit into our buffer
 			assert(strlen(pszFileName) < MAX_FNAME);
 
@@ -192,9 +194,6 @@ ErrorCode CBofBitmap::loadBitmap(const char *pszFileName, CBofPalette *pPalette)
 
 			// Close bitmap file
 			delete pFile;
-
-		} else {
-			reportError(ERR_MEMORY, "Could not allocate a CBofFile for %s", pszFileName);
 		}
 	}
 
@@ -886,71 +885,67 @@ ErrorCode CBofBitmap::scrollUp(int nPixels, CBofRect *pRect) {
 			byte *pRowBuf = (byte *)bofAlloc(dx);
 
 			// Allocate a buffer to hold one horizontal line
-			if (pRowBuf != nullptr) {
+			if (pRowBuf == nullptr)
+				fatalError(ERR_MEMORY, "Error: scrollUp - Could not allocate %ld bytes for row", dx);
 
-				byte *pEnd;
-				byte *pStart = pEnd = _pBits;
+			byte *pStart = _pBits;
+			byte *pEnd = _pBits;
 
-				int32 dx1 = _nScanDX;
-				int32 dy1 = _nDY;
+			int32 dx1 = _nScanDX;
+			int32 dy1 = _nDY;
 
-				// Is bitmap top-down or bottom up?
-				if (_bTopDown) {
-					pStart += y * dx1 + x;
-					pEnd += (y + dy - 1) * dx1 + x;
-				} else {
-					pStart += (dy1 - y - 1) * dx1 + x;
-					pEnd += (dy1 - (y + dy - 1) - 1) * dx1 + x;
-					dx1 = -dx1;
-				}
-				byte *pCurRow = pStart;
-
-				// Copy 1st row into temp row buffer
-				memcpy(pRowBuf, pCurRow, dx);
+			// Is bitmap top-down or bottom up?
+			if (_bTopDown) {
+				pStart += y * dx1 + x;
+				pEnd += (y + dy - 1) * dx1 + x;
+			} else {
+				pStart += (dy1 - y - 1) * dx1 + x;
+				pEnd += (dy1 - (y + dy - 1) - 1) * dx1 + x;
+				dx1 = -dx1;
+			}
+			byte *pCurRow = pStart;
 
-				int32 lJump = dx1 * nPixels;
+			// Copy 1st row into temp row buffer
+			memcpy(pRowBuf, pCurRow, dx);
 
-				byte *pLastRow = pCurRow;
-				pCurRow += lJump;
-				byte *p1stRow = pStart;
+			int32 lJump = dx1 * nPixels;
 
-				// Working row by row
-				for (int32 i = 1; i < dy; i++) {
-					// Copy this row to row above it
-					memcpy(pLastRow, pCurRow, dx);
+			byte *pLastRow = pCurRow;
+			pCurRow += lJump;
+			byte *p1stRow = pStart;
 
-					pLastRow = pCurRow;
+			// Working row by row
+			for (int32 i = 1; i < dy; i++) {
+				// Copy this row to row above it
+				memcpy(pLastRow, pCurRow, dx);
 
-					pCurRow += lJump;
-					if (pCurRow < pEnd && !_bTopDown) {
-						pCurRow = pStart - (pEnd - pCurRow) - dx1;
+				pLastRow = pCurRow;
 
-						if (pCurRow == p1stRow) {
+				pCurRow += lJump;
+				if (pCurRow < pEnd && !_bTopDown) {
+					pCurRow = pStart - (pEnd - pCurRow) - dx1;
 
-							i++;
+					if (pCurRow == p1stRow) {
+						i++;
 
-							// Copy 1st row into this row
-							memcpy(pLastRow, pRowBuf, dx);
+						// Copy 1st row into this row
+						memcpy(pLastRow, pRowBuf, dx);
 
-							pCurRow += dx1;
-							p1stRow = pLastRow = pCurRow;
+						pCurRow += dx1;
+						p1stRow = pLastRow = pCurRow;
 
-							// Copy this next row into temp row buffer
-							memcpy(pRowBuf, p1stRow, dx);
+						// Copy this next row into temp row buffer
+						memcpy(pRowBuf, p1stRow, dx);
 
-							pCurRow += lJump;
-						}
+						pCurRow += lJump;
 					}
 				}
+			}
 
-				// Copy 1st row into last row
-				memcpy(pLastRow, pRowBuf, dx);
-
-				bofFree(pRowBuf);
+			// Copy 1st row into last row
+			memcpy(pLastRow, pRowBuf, dx);
 
-			} else {
-				reportError(ERR_MEMORY, "Error: scrollUp - Could not allocate %ld bytes for row", dx);
-			}
+			bofFree(pRowBuf);
 		}
 		unlock();
 	}
diff --git a/engines/bagel/boflib/gfx/text.cpp b/engines/bagel/boflib/gfx/text.cpp
index 7022fc5cba0..64a2c000994 100644
--- a/engines/bagel/boflib/gfx/text.cpp
+++ b/engines/bagel/boflib/gfx/text.cpp
@@ -75,14 +75,11 @@ CBofText::CBofText(const CBofRect *pRect, int nJustify, uint32 nFormatFlags) {
 }
 
 CBofText::~CBofText() {
-	if (_pWork != nullptr) {
-		delete _pWork;
-		_pWork = nullptr;
-	}
-	if (_pBackground != nullptr) {
-		delete _pBackground;
-		_pBackground = nullptr;
-	}
+	delete _pWork;
+	_pWork = nullptr;
+
+	delete _pBackground;
+	_pBackground = nullptr;
 }
 
 void CBofText::initializeFields() {
@@ -119,28 +116,23 @@ ErrorCode CBofText::setupText(const CBofRect *pRect, int nJustify, uint32 nForma
 	_cSize.cx = _cRect.width();
 	_cSize.cy = _cRect.height();
 
-	if (_pWork != nullptr) {
-		delete _pWork;
-		_pWork = nullptr;
-	}
-	if (_pBackground != nullptr) {
-		delete _pBackground;
-		_pBackground = nullptr;
-	}
+	delete _pWork;
+	_pWork = nullptr;
 
-	CBofPalette *pPalette;
-	pPalette = CBofApp::getApp()->getPalette();
+	delete _pBackground;
+	_pBackground = nullptr;
 
-	// Create a bitmap to serve as our work area as we output text
-	if ((_pWork = new CBofBitmap(_cSize.cx, _cSize.cy, pPalette)) != nullptr) {
-		// Create a bitmap to hold the background we overwrite
-		if ((_pBackground = new CBofBitmap(_cSize.cx, _cSize.cy, pPalette)) != nullptr) {
+	CBofPalette *pPalette = CBofApp::getApp()->getPalette();
 
-		} else {
-			reportError(ERR_MEMORY, "Could not allocate a (%d x %d) CBofBitmap", _cSize.cx, _cSize.cy);
-		}
-	} else {
-		reportError(ERR_MEMORY, "Could not allocate a (%d x %d) CBofBitmap", _cSize.cx, _cSize.cy);
+	// Create a bitmap to serve as our work area as we output text
+	_pWork = new CBofBitmap(_cSize.cx, _cSize.cy, pPalette);
+	if (_pWork == nullptr)
+		fatalError(ERR_MEMORY, "Could not allocate a (%d x %d) CBofBitmap", _cSize.cx, _cSize.cy);
+
+	// Create a bitmap to hold the background we overwrite
+	_pBackground = new CBofBitmap(_cSize.cx, _cSize.cy, pPalette);
+	if (_pBackground == nullptr) {
+		fatalError(ERR_MEMORY, "Could not allocate a (%d x %d) CBofBitmap", _cSize.cx, _cSize.cy);
 	}
 
 	return _errCode;
diff --git a/engines/bagel/boflib/gui/button.cpp b/engines/bagel/boflib/gui/button.cpp
index a390bd2358a..5fd6bc41a0c 100644
--- a/engines/bagel/boflib/gui/button.cpp
+++ b/engines/bagel/boflib/gui/button.cpp
@@ -80,32 +80,26 @@ ErrorCode CBofButton::paint(CBofRect *) {
 
 	// Only continue if this button is visible
 	if (isVisible() && (_parent != nullptr) && _parent->isVisible()) {
-		CBofPalette *pPalette;
-		RGBCOLOR cTextColor;
-		byte iHighlight, iShadow, iTemp;
-		int nWidth, nHeight;
-		int i, left, right, top, bottom;
-
-		pPalette = CBofApp::getApp()->getPalette();
+		CBofPalette *pPalette = CBofApp::getApp()->getPalette();
 
-		nWidth = _cRect.width();
-		nHeight = _cRect.height();
+		int nWidth = _cRect.width();
+		int nHeight = _cRect.height();
 
 		// Create our off-screen buffer
 		CBofBitmap cBmp(nWidth, nHeight, pPalette);
 
 		cBmp.fillRect(&_cRect, pPalette->getNearestIndex(_cFaceColor));
 
-		left = _cRect.left;
-		right = _cRect.right;
-		top = _cRect.top;
-		bottom = _cRect.bottom;
+		int left = _cRect.left;
+		int right = _cRect.right;
+		int top = _cRect.top;
+		int bottom = _cRect.bottom;
 
-		iShadow = pPalette->getNearestIndex(_cShadowColor);
-		iHighlight = pPalette->getNearestIndex(_cHighlightColor);
+		byte iShadow = pPalette->getNearestIndex(_cShadowColor);
+		byte iHighlight = pPalette->getNearestIndex(_cHighlightColor);
 
 		if (_nState == BUTTON_DOWN) {
-			iTemp = iShadow;
+			byte iTemp = iShadow;
 			iShadow = iHighlight;
 			iHighlight = iTemp;
 		}
@@ -113,6 +107,7 @@ ErrorCode CBofButton::paint(CBofRect *) {
 		byte c1 = iShadow;
 		byte c2 = iHighlight;
 
+		int i;
 		for (i = 1; i <= 3; i++) {
 			cBmp.line(left + i, bottom - i, right - i, bottom - i, c1);
 			cBmp.line(right - i, bottom - i, right - i, top + i - 1, c1);
@@ -135,7 +130,7 @@ ErrorCode CBofButton::paint(CBofRect *) {
 		CBofText cText(&cTempRect);
 
 		// Print text into button
-		cTextColor = _cTextColor;
+		RGBCOLOR cTextColor = _cTextColor;
 		if (_nState == BUTTON_DISABLED)
 			cTextColor = _cTextDisabledColor;
 
@@ -214,7 +209,6 @@ ErrorCode CBofButton::setState(int nNewState, bool bRepaintNow) {
 
 void CBofButton::onPaint(CBofRect *pRect) {
 	assert(isValidObject(this));
-
 	assert(pRect != nullptr);
 
 	paint(pRect);
@@ -226,9 +220,7 @@ void CBofButton::onLButtonDown(uint32, CBofPoint *pPoint, void *) {
 	assert(pPoint != nullptr);
 
 	if (!_bCaptured && _nState != BUTTON_DISABLED) {
-
 		setCapture();
-
 		setState(BUTTON_DOWN, true);
 	}
 }
@@ -240,7 +232,6 @@ void CBofButton::onLButtonUp(uint32, CBofPoint *pPoint, void *) {
 
 	if (_bCaptured) {
 		releaseCapture();
-
 		setState(BUTTON_UP, true);
 
 		if (_cRect.ptInRect(*pPoint) && (_parent != nullptr)) {
@@ -259,7 +250,6 @@ void CBofRadioButton::onLButtonDown(uint32, CBofPoint *pPoint, void *) {
 	assert(pPoint != nullptr);
 
 	if ((_nState != BUTTON_DISABLED) && (_nState == BUTTON_UP)) {
-
 		setState(BUTTON_DOWN, true);
 	}
 }
@@ -347,16 +337,13 @@ void CBofCheckButton::onLButtonDown(uint32, CBofPoint *pPoint, void *) {
 	assert(isValidObject(this));
 	assert(pPoint != nullptr);
 
-	if (_nState != BUTTON_DISABLED) {
-
-		if (_nState == BUTTON_UP) {
+	if (_nState == BUTTON_DISABLED)
+		return;
 
-			setState(BUTTON_DOWN, true);
-
-		} else if (_nState == BUTTON_DOWN) {
-
-			setState(BUTTON_UP, true);
-		}
+	if (_nState == BUTTON_UP) {
+		setState(BUTTON_DOWN, true);
+	} else if (_nState == BUTTON_DOWN) {
+		setState(BUTTON_UP, true);
 	}
 }
 
@@ -455,26 +442,20 @@ CBofBmpButton::CBofBmpButton() {
 
 
 CBofBmpButton::~CBofBmpButton() {
-	if (_pButtonUp != nullptr) {
-		delete _pButtonUp;
-		_pButtonUp = nullptr;
-	}
-	if (_pButtonDown != nullptr) {
-		delete _pButtonDown;
-		_pButtonDown = nullptr;
-	}
-	if (_pButtonDisabled != nullptr) {
-		delete _pButtonDisabled;
-		_pButtonDisabled = nullptr;
-	}
-	if (_pButtonFocus != nullptr) {
-		delete _pButtonFocus;
-		_pButtonFocus = nullptr;
-	}
-	if (_pBackground != nullptr) {
-		delete _pBackground;
-		_pBackground = nullptr;
-	}
+	delete _pButtonUp;
+	_pButtonUp = nullptr;
+
+	delete _pButtonDown;
+	_pButtonDown = nullptr;
+
+	delete _pButtonDisabled;
+	_pButtonDisabled = nullptr;
+
+	delete _pButtonFocus;
+	_pButtonFocus = nullptr;
+
+	delete _pBackground;
+	_pBackground = nullptr;
 }
 
 
@@ -498,10 +479,9 @@ ErrorCode CBofBmpButton::paint(CBofRect *) {
 		CBofBitmap cOffScreen(nWidth, nHeight, pPalette);
 
 		if (_pBackground == nullptr) {
-			if ((_pBackground = new CBofBitmap(nWidth, nHeight, pPalette)) != nullptr) {
-
-			} else {
-				reportError(ERR_MEMORY, "Could not allocate a CBofBitmap(%d x %d)", nWidth, nHeight);
+			_pBackground = new CBofBitmap(nWidth, nHeight, pPalette);
+			if (_pBackground == nullptr) {
+				fatalError(ERR_MEMORY, "Could not allocate a CBofBitmap(%d x %d)", nWidth, nHeight);
 			}
 
 		} else {
@@ -535,7 +515,6 @@ ErrorCode CBofBmpButton::paint(CBofRect *) {
 
 ErrorCode CBofBmpButton::loadBitmaps(CBofBitmap *pUp, CBofBitmap *pDown, CBofBitmap *pFocus, CBofBitmap *pDisabled, int nMaskColor) {
 	assert(isValidObject(this));
-
 	assert(pUp != nullptr);
 	assert(pDown != nullptr);
 
@@ -554,7 +533,6 @@ ErrorCode CBofBmpButton::loadBitmaps(CBofBitmap *pUp, CBofBitmap *pDown, CBofBit
 
 ErrorCode CBofBmpButton::loadBitmaps(CBofPalette *pPalette, const char *pszUp, const char *pszDown, const char *pszFocus, const char *pszDisabled, int nMaskColor) {
 	assert(isValidObject(this));
-
 	assert(pPalette != nullptr);
 	assert(pszUp != nullptr);
 	assert(pszDown != nullptr);
@@ -565,16 +543,23 @@ ErrorCode CBofBmpButton::loadBitmaps(CBofPalette *pPalette, const char *pszUp, c
 	_nMaskColor = nMaskColor;
 
 	// Load each of the bitmaps that represent the button state
-	if ((_pButtonUp = new CBofBitmap(pszUp, pPalette)) != nullptr) {
+	_pButtonUp = new CBofBitmap(pszUp, pPalette);
+	if (_pButtonUp != nullptr) {
 		_pButtonUp->setReadOnly(true);
 	}
-	if ((_pButtonDown = new CBofBitmap(pszDown, pPalette)) != nullptr) {
+
+	_pButtonDown = new CBofBitmap(pszDown, pPalette);
+	if (_pButtonDown != nullptr) {
 		_pButtonDown->setReadOnly(true);
 	}
-	if ((_pButtonFocus = new CBofBitmap(pszFocus, pPalette)) != nullptr) {
+	
+	_pButtonFocus = new CBofBitmap(pszFocus, pPalette);
+	if (_pButtonFocus != nullptr) {
 		_pButtonFocus->setReadOnly(true);
 	}
-	if ((_pButtonDisabled = new CBofBitmap(pszDisabled, pPalette)) != nullptr) {
+
+	_pButtonDisabled = new CBofBitmap(pszDisabled, pPalette);
+	if (_pButtonDisabled != nullptr) {
 		_pButtonDisabled->setReadOnly(true);
 	}
 
@@ -610,7 +595,6 @@ ErrorCode CBofBmpButton::setState(int nNewState, bool bRepaintNow) {
 
 void CBofBmpButton::onPaint(CBofRect *pRect) {
 	assert(isValidObject(this));
-
 	assert(pRect != nullptr);
 
 	paint(pRect);




More information about the Scummvm-git-logs mailing list