summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2ImageObj.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2ImageObj.cpp150
1 files changed, 79 insertions, 71 deletions
diff --git a/src/T2DLL/T2ImageObj.cpp b/src/T2DLL/T2ImageObj.cpp
index 08ae773..a770e6a 100644
--- a/src/T2DLL/T2ImageObj.cpp
+++ b/src/T2DLL/T2ImageObj.cpp
@@ -1,7 +1,14 @@
+#define ATOI_KLUDGE
#include "GlobalFunc.h"
#include "T2BitImage.h"
#include "T2ImageObj.h"
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
T2ImageObj::T2ImageObj() {
mCount = 0;
mHandle = GlobalAlloc(GHND, 1);
@@ -22,30 +29,30 @@ void T2ImageObj::AddObject(HINSTANCE instance, unsigned int resourceID, T2BitIma
CString nameStr;
nameStr.Format("%d", resourceID);
- CString err = "T2ImageObj::AddObject ERROR : " + nameStr + " @" + GetModuleName(instance) + "\n";
- OutputDebugString(err);
+ CString error = "T2ImageObj::AddObject ERROR : " + nameStr + " @" + GetModuleName(instance) + "\n";
+ OutputDebugString(error);
}
#line 45
_ASSERT(rsrc);
- HGLOBAL h = LoadResource(instance, rsrc);
+ HGLOBAL theHandle = LoadResource(instance, rsrc);
#line 47
- _ASSERT(h);
-
- void *resData = LockResource(h);
- DWORD size = SizeofResource(instance, rsrc);
- char *buffer = (char *) malloc(size);
- memcpy(buffer, resData, size);
- UnlockResource(h);
- FreeResource(h);
-
- char *token = strtok(buffer, " \t\r\n\x1A");
- while (token) {
- if (!_stricmp(token, "End"))
+ _ASSERT(theHandle);
+
+ void *theRes = LockResource(theHandle);
+ DWORD theResSize = SizeofResource(instance, rsrc);
+ char *theData = (char *) malloc(theResSize);
+ memcpy(theData, theRes, theResSize);
+ UnlockResource(theHandle);
+ FreeResource(theHandle);
+
+ char *theCmd = strtok(theData, " \t\r\n\x1A");
+ while (theCmd) {
+ if (!_stricmp(theCmd, "End"))
break;
- if (!_stricmp(token, "DefParts")) {
+ if (!_stricmp(theCmd, "DefParts")) {
mCount++;
mHandle = GlobalReAlloc(mHandle, mCount * sizeof(ObjectData), GHND);
mData = (ObjectData *) GlobalLock(mHandle);
@@ -58,46 +65,46 @@ void T2ImageObj::AddObject(HINSTANCE instance, unsigned int resourceID, T2BitIma
mData[mCount - 1].grade = 0;
mData[mCount - 1].span = 0;
mData[mCount - 1].offset = -1;
- } else if (!_stricmp(token, "Name")) {
+ } else if (!_stricmp(theCmd, "Name")) {
strcpy(mData[mCount - 1].name, strtok(NULL, "\t\r\n\x1A"));
- } else if (!_stricmp(token, "ID")) {
+ } else if (!_stricmp(theCmd, "ID")) {
mData[mCount - 1].id = atoi(strtok(NULL, " \t\r\n\x1A"));
- } else if (!_stricmp(token, "Pattern")) {
+ } else if (!_stricmp(theCmd, "Pattern")) {
mData[mCount - 1].pattern = atoi(strtok(NULL, " \t\r\n\x1A"));
- } else if (!_stricmp(token, "Grade")) {
+ } else if (!_stricmp(theCmd, "Grade")) {
mData[mCount - 1].grade = atoi(strtok(NULL, " \t\r\n\x1A"));
- } else if (!_stricmp(token, "Span")) {
+ } else if (!_stricmp(theCmd, "Span")) {
mData[mCount - 1].span = atoi(strtok(NULL, " \t\r\n\x1A"));
- } else if (!_stricmp(token, "Offset")) {
+ } else if (!_stricmp(theCmd, "Offset")) {
mData[mCount - 1].offset = atoi(strtok(NULL, " \t\r\n\x1A"));
- } else if (!_stricmp(token, "Roof")) {
+ } else if (!_stricmp(theCmd, "Roof")) {
if (!_stricmp(strtok(NULL, " \t\r\n\x1A"), "Yes"))
mData[mCount - 1].roof = true;
- } else if (!_stricmp(token, "Floor")) {
+ } else if (!_stricmp(theCmd, "Floor")) {
if (!_stricmp(strtok(NULL, " \t\r\n\x1A"), "Yes"))
mData[mCount - 1].floor = true;
- } else if (!_stricmp(token, "List")) {
+ } else if (!_stricmp(theCmd, "List")) {
// nothing
- } else if (!_stricmp(token, "Loop")) {
+ } else if (!_stricmp(theCmd, "Loop")) {
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags |= SPD_LOOP;
- } else if (!_stricmp(token, "Transparent")) {
+ } else if (!_stricmp(theCmd, "Transparent")) {
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags |= SPD_TRANSPARENT;
- } else if (!_stricmp(token, "Halftone")) {
+ } else if (!_stricmp(theCmd, "Halftone")) {
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags |= SPD_HALFTONE;
- } else if (!_stricmp(token, "Rect")) {
+ } else if (!_stricmp(theCmd, "Rect")) {
mData[mCount - 1].subPartCount++;
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags = SPD_RECT;
- char *argToken = strtok(NULL, " \t\r\n\x1A");
- char *arg = (char *) malloc(strlen(argToken) + 1);
- strcpy(arg, argToken);
+ char *arg = strtok(NULL, " \t\r\n\x1A");
+ char *argCopy = (char *) malloc(strlen(arg) + 1);
+ strcpy(argCopy, arg);
char *p;
- while ((p = strchr(arg, ',')))
+ while ((p = strchr(argCopy, ',')))
*p = ' ';
sscanf(
- arg,
+ argCopy,
"%hd %hd %hd %hd",
&mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].left,
&mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].top,
@@ -105,13 +112,13 @@ void T2ImageObj::AddObject(HINSTANCE instance, unsigned int resourceID, T2BitIma
&mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].bottom
);
- free(arg);
- } else if (!_stricmp(token, "Parts")) {
- char *argToken = strtok(NULL, " \t\r\n\x1A");
- if (argToken[0] != '#') {
+ free(argCopy);
+ } else if (!_stricmp(theCmd, "Parts")) {
+ char *arg = strtok(NULL, " \t\r\n\x1A");
+ if (arg[0] != '#') {
int i;
for (i = 0; i < (mCount - 1); i++) {
- if (!strcmp(mData[i].name, argToken)) {
+ if (!strcmp(mData[i].name, arg)) {
mData[mCount - 1].subPartCount++;
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags = SPD_PARTS_BY_NAME;
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].partIndex = i;
@@ -121,26 +128,26 @@ void T2ImageObj::AddObject(HINSTANCE instance, unsigned int resourceID, T2BitIma
if (i == (mCount - 1)) {
char buf[256];
- wsprintf(buf, "Undefined parts [%s]", argToken);
+ wsprintf(buf, "Undefined parts [%s]", arg);
MessageBox(NULL, buf, "ERROR", MB_OK | MB_ICONWARNING | MB_TASKMODAL);
}
} else {
mData[mCount - 1].subPartCount++;
mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].flags = SPD_PARTS_BY_ID;
- mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].objectID = atoi(&argToken[1]);
+ mData[mCount - 1].subParts[mData[mCount - 1].subPartCount - 1].objectID = atoi(&arg[1]);
}
- } else if (token[0] == '#') {
+ } else if (theCmd[0] == '#') {
// nothing
} else {
char buf[256];
- wsprintf(buf, "Undefined token [%s]", token);
+ wsprintf(buf, "Undefined theCmd [%s]", theCmd);
MessageBox(NULL, buf, "ERROR", MB_OK | MB_ICONWARNING | MB_TASKMODAL);
}
- token = strtok(NULL, " \t\r\n\x1A");
+ theCmd = strtok(NULL, " \t\r\n\x1A");
}
- free(buffer);
+ free(theData);
}
void T2ImageObj::AddObject(const char* name, int pattern, T2BitImage& image, const RECT* rect, BOOL transparent, BOOL halftoneMode) {
@@ -317,48 +324,49 @@ void T2ImageObj::DrawObject(void* target, int index, RECT rect, int factor, BOOL
_ASSERT(index >= 0);
static PARTSLIST parts[500];
- int width = rect.right - rect.left;
- int num = 0;
- EnumParts(index, width, parts, &num);
+ RECT srcRect, dstRect;
+ int theSize = rect.right - rect.left;
+ int numOfParts = 0;
+ EnumParts(index, theSize, parts, &numOfParts);
- if (num >= 500)
+ if (numOfParts >= 500)
MessageBox(NULL, "Too many parts", "T2ImageObj::DrawObject", MB_OK | MB_ICONERROR | MB_TASKMODAL);
- for (int i = 0; i < num; i++) {
- RECT srcRect = parts[i].rect;
- RECT destRect = srcRect;
+ for (int n = 0; n < numOfParts; n++) {
+ srcRect = parts[n].rect;
+ dstRect = rect;
- if ((srcRect.right - srcRect.left) > ((destRect.right - destRect.left) << factor))
- srcRect.right = srcRect.left + ((destRect.right - destRect.left) << factor);
+ if ((srcRect.right - srcRect.left) > ((dstRect.right - dstRect.left) << factor))
+ srcRect.right = srcRect.left + ((dstRect.right - dstRect.left) << factor);
- if ((destRect.right - destRect.left) > ((srcRect.right - srcRect.left) >> factor))
- destRect.right = destRect.left + ((srcRect.right - srcRect.left) >> factor);
+ if ((dstRect.right - dstRect.left) > ((srcRect.right - srcRect.left) >> factor))
+ dstRect.right = dstRect.left + ((srcRect.right - srcRect.left) >> factor);
- if ((srcRect.bottom - srcRect.top) > ((destRect.bottom - destRect.top) << factor))
- srcRect.bottom = srcRect.top + ((destRect.bottom - destRect.top) << factor);
+ if ((srcRect.bottom - srcRect.top) > ((dstRect.bottom - dstRect.top) << factor))
+ srcRect.bottom = srcRect.top + ((dstRect.bottom - dstRect.top) << factor);
- if ((destRect.bottom - destRect.top) > ((srcRect.bottom - srcRect.top) >> factor))
- destRect.bottom = destRect.top + ((srcRect.bottom - srcRect.top) >> factor);
+ if ((dstRect.bottom - dstRect.top) > ((srcRect.bottom - srcRect.top) >> factor))
+ dstRect.bottom = dstRect.top + ((srcRect.bottom - srcRect.top) >> factor);
- if (parts[i].transparent)
- parts[i].image->SetBackGndColor(0);
+ if (parts[n].transparent)
+ parts[n].image->SetBackGndColor(0);
else
- parts[i].image->SetBackGndColor(-1);
+ parts[n].image->SetBackGndColor(-1);
- if (parts[i].halftoneMode)
- parts[i].image->SetHalftoneMode(true);
+ if (parts[n].halftoneMode)
+ parts[n].image->SetHalftoneMode(true);
else
- parts[i].image->SetHalftoneMode(false);
+ parts[n].image->SetHalftoneMode(false);
- parts[i].image->SetForeGndColor(foreGndColor);
+ parts[n].image->SetForeGndColor(foreGndColor);
if (targetIsDC) {
- parts[i].image->CopyImage((CDC *) target, srcRect, destRect, false, NULL);
+ parts[n].image->CopyImage((CDC *) target, srcRect, dstRect, false, NULL);
} else {
- parts[i].image->CopyImage(*((T2BitImage *) target), srcRect, destRect, false, NULL);
+ parts[n].image->CopyImage(*((T2BitImage *) target), srcRect, dstRect, false, NULL);
}
- parts[i].image->SetHalftoneMode(false);
+ parts[n].image->SetHalftoneMode(false);
- rect.left += (destRect.right - destRect.left);
+ rect.left += (dstRect.right - dstRect.left);
}
}