Example #1
0
void CheckSurfaceRecreation(LPRDATA rdPtr)
{

	fprh rhPtr = rdPtr->rHo.hoAdRunHeader;
	LPSURFACE ps = WinGetSurface((int)rhPtr->rhIdEditWin);
	LPSURFACE pProto = NULL;

	ParallaxFrame current = *rdPtr->currentPframe;

	//Recreate surface if nessecary.
	if( (rdPtr->direction == HORIZONTAL && rdPtr->rHo.hoImgWidth != rdPtr->oldWidth) ||
		(rdPtr->direction == VERTICAL && rdPtr->rHo.hoImgHeight != rdPtr->oldHeight) ||
		(rdPtr->finalImage == NULL)
	)
	{
		if( rdPtr->finalImage != NULL )
		{
			rdPtr->finalImage->Delete();
			delete rdPtr->finalImage;
		}
		rdPtr->finalImage = new cSurface();
		if ( GetSurfacePrototype( &pProto, ps->GetDepth(), ST_MEMORY, SD_DIB) )
		{
			int newWidth = (rdPtr->direction == HORIZONTAL) ? rdPtr->rHo.hoImgWidth : current.parallaxImage->GetWidth();
			int newHeight = (rdPtr->direction == HORIZONTAL) ? current.parallaxImage->GetHeight() : rdPtr->rHo.hoImgHeight;

			rdPtr->finalImage->Create(newWidth, newHeight, pProto);

			if( !rdPtr->finalImage->IsValid() )
			{
				rdPtr->finalImage->Delete();
				delete rdPtr->finalImage;
			}
				
		}
	}

	rdPtr->oldWidth = rdPtr->rHo.hoImgWidth;
	rdPtr->oldHeight = rdPtr->rHo.hoImgHeight;
}
void WINAPI DLLExport EditorDisplay(mv _far * mV, fpObjInfo oiPtr, fpLevObj loPtr,
                                    LPEDATA edPtr, RECT FAR * rc)
{
#ifndef RUN_ONLY

    LPSURFACE ps = WinGetSurface((int)mV->mvIdEditWin);
    if (ps != NULL) // Do the following if this surface exists
    {
        // ps->SetClipRect(rc->left, rc->top, rc->right-rc->left,
        // rc->bottom-rc->top);

        // Prevent the user from having a seizure
        // srand((long)mV->mvEditFrame + edPtr->width + edPtr->height);

        // Get surfaces of tilesets
        // cSurface surfs[TILESETCOUNT];
        // for (int i = 0; i < edPtr->tilesetCount; ++i)
        //{
        //	LockImageSurface(mV->mvIdAppli, edPtr->tilesets[i], surfs[i]);
        //}

        // Draw opaque background
        if (!edPtr->transparent)
            ps->Rectangle(rc->left, rc->top, rc->right, rc->bottom, edPtr->background, 0, 0, 1);

        //// For each tile
        // if (edPtr->tileWidth > 0 && edPtr->tileHeight > 0)
        //{
        //	for (int x = rc->left; x <= rc->right; x += edPtr->tileWidth)
        //	{
        //		for (int y = rc->top; y <= rc->bottom; y +=
        // edPtr->tileHeight)
        //		{
        //			// Draw a random tile
        //			if (edPtr->tilesetCount)
        //			{
        //				int tileset = 0;
        //				//int tileset = rand() %
        // edPtr->tilesetCount;
        //				int tx = rand() %
        //(surfs[tileset].GetWidth()
        ///
        // edPtr->tileWidth);
        //				int ty = rand() %
        //(surfs[tileset].GetHeight()
        ///
        // edPtr->tileHeight);
        //				surfs[tileset].Blit(*ps, x, y,
        // tx*edPtr->tileWidth,
        // ty*edPtr->tileHeight, edPtr->tileWidth, edPtr->tileHeight,
        // BMODE_TRANSP, BOP_COPY);
        //			}
        //			// Draw grid
        //			else
        //			{
        //				ps->Rectangle(x, y,
        // x+edPtr->tileWidth+1,
        // y+edPtr->tileHeight+1,
        // 1, 0x999999);
        //			}
        //		}
        //	}
        //}

        // Draw border
        ps->Rectangle(rc->left, rc->top, rc->right, rc->bottom, 1, OPAQUE_BLACK);
        ps->ClearClipRect();

        // Unlock stuff
        // for (int i = 0; i < edPtr->tilesetCount; ++i)
        //{
        //	UnlockImageSurface(surfs[i]);
        //}
    }

#endif // !RUN_ONLY
}
Example #3
0
short WINAPI DLLExport CreateRunObject(LPRDATA rdPtr, LPEDATA edPtr, fpcob cobPtr)
{
	// Do some rSDK stuff
	#include "rCreateRunObject.h"

#ifdef _DEBUG
	AllocConsole();
	freopen("conin$","r",stdin);
	freopen("conout$","w",stdout);
	freopen("conout$","w",stderr);
#ifdef UNICODE
	printf("Surface Unicode version\n");
#endif
#endif

	srand(time(NULL));

	LPRH rhPtr = rdPtr->rHo.hoAdRunHeader;
	mv* mV = rdPtr->rHo.hoAdRunHeader->rh4.rh4Mv;

	rdPtr->rHo.hoImgWidth = edPtr->width_def;
	rdPtr->rHo.hoImgHeight = edPtr->height_def;
	rdPtr->useAbs = edPtr->useAbs;
	rdPtr->keepPoints = edPtr->keepPoints;
	rdPtr->dispTarget = edPtr->dispTarget;
	rdPtr->selectLast = edPtr->selectLast;
	rdPtr->threadedIO = edPtr->threadedIO;
	rdPtr->ioFile = 0;

	//Font
	rdPtr->hFont = 0;
	memcpy(&rdPtr->textFont,&edPtr->textFont,sizeof(LOGFONT));
	rdPtr->hFlags = edPtr->textFlags;	

	//Depth
	rdPtr->depth = 24;

	//Internal blending
	rdPtr->b.mode = BMODE_TRANSP;
	rdPtr->b.operation = BOP_COPY;
	rdPtr->b.param = 0;
	rdPtr->b.param = 0xffffffff;
	rdPtr->b.flags = 0;
	rdPtr->b.destX = 0;
	rdPtr->b.destY = 0;
	rdPtr->b.destW = 0;
	rdPtr->b.destH = 0;
	rdPtr->b.StretchMode = 0;
	rdPtr->b.srcX = 0;
	rdPtr->b.srcY = 0;
	rdPtr->b.srcW = 0;
	rdPtr->b.srcH = 0;
	rdPtr->b.srcUse = false;
	rdPtr->b.callback[0] = 0;
	rdPtr->b.procOp[0] = 0;
	rdPtr->b.procOpSrc = 1;
	rdPtr->b.composeAlpha = false;
	rdPtr->b.angle = 0;
	rdPtr->b.angleResample = false;
	rdPtr->b.hotX = 0;
	rdPtr->b.hotY = 0;
	rdPtr->b.hotspotMode = 1; // no longer possible to disable
	rdPtr->blitStackCursor = -1;
	//Current & target surfaces
	rdPtr->targetId = -1;
	rdPtr->target = 0;
	rdPtr->currentId = -1;
	rdPtr->current = 0;
	rdPtr->lastId = -1;
	rdPtr->targetValid = false;
	//Default settings
	rdPtr->transCol = BLACK;
	//Collision mask and fill data
	rdPtr->collision = 0;
	rdPtr->fill = new FillDB;
	//Polygon's points
	rdPtr->points = new PolyPoints;
	//Buffer
	rdPtr->buffer = 0;
	rdPtr->buffPitch = 0;
	rdPtr->buffSurf = 0;
	//Overlay
	rdPtr->ovl = 0;
	//Callback
	rdPtr->colSrc = 0;
	rdPtr->colDest = 0;
	rdPtr->colNew = 0;
	rdPtr->colAlphaSrc = 0;
	rdPtr->colAlphaDest = 0;
	rdPtr->colAlphaNew = 0;
	rdPtr->callback = 0;
	rdPtr->callX = 0;
	rdPtr->callY = 0;
	rdPtr->colAlphaRet = 0;
	rdPtr->colRet = 0;
	//Flood fill region
	rdPtr->floodL = 0;
	rdPtr->floodT = 0;
	rdPtr->floodR = 0;
	rdPtr->floodB = 0;
	//I/O
	rdPtr->ioHandle = 0;
	//Quick store
	rdPtr->stored = 0;
	// Random color function
	rdPtr->randomSeed = 0;
	//Functions for extension integration
	rdPtr->imageAt = GetImgAt;
	rdPtr->imageCount = GetImgCount;
	//Running HWA?
	LPSURFACE wSurf = WinGetSurface((int)rhPtr->rhIdEditWin);
	int nDrv = wSurf->GetDriver();
	rdPtr->isHWA = nDrv >= SD_3DFX;
		
	//Display surface not necessary by default
	rdPtr->display = 0;
	rdPtr->rc.rcAngle = 0;
	rdPtr->rc.rcScaleX = 1.0f;
	rdPtr->rc.rcScaleY = 1.0f;

	//Images
	rdPtr->surf = new ImageBank;

	//Hotspot info
	Img imgInfo;
	//Prototype for new surfaces
	cSurface *proto = 0;

	if(edPtr->multiImg)
	{
		//First image empty
		if(!edPtr->images[0]&&edPtr->loadFirst)
		{
			cSurface *tmp = new cSurface;
			rdPtr->surf->push_back(new SImage(tmp));
			//Empty image with size
			if(edPtr->loadFirst)
			{
				GetSurfacePrototype(&proto,rdPtr->depth,ST_MEMORYWITHDC,SD_DIB);
				tmp->Create(edPtr->width,edPtr->height,proto);
				tmp->Fill(BLACK);
			}
			rdPtr->targetId = rdPtr->currentId = rdPtr->lastId = 0;
			TargetImg = CurrentImg = tmp;
			rdPtr->targetValid = true;
		}
		for(int i=0;i<edPtr->imageCount;i++)
		{
			//Get surface prototype on first loop
			if(!i)
				GetSurfacePrototype(&proto,rdPtr->depth,ST_MEMORYWITHDC,SD_DIB);
			//Valid image? Load
			if(edPtr->images[i])
			{
				cSurface is, *tmp = new cSurface;
				GetImageInfos(rhPtr->rhIdAppli,edPtr->images[i],&imgInfo);
				rdPtr->surf->push_back(new SImage(tmp,true,imgInfo.imgXSpot,imgInfo.imgYSpot));
				LockImageSurface(rhPtr->rhIdAppli,edPtr->images[i],is);
				
				if(is.GetWidth())
				{
					if(!i)
					{
						rdPtr->targetId = 0;
						TargetImg = tmp;
						rdPtr->lastId = rdPtr->targetId;
						rdPtr->targetValid = true;
						if(edPtr->loadFirst)
						{
							rdPtr->currentId = rdPtr->targetId;
							CurrentImg = TargetImg;
						}
					}
					tmp->Create(is.GetWidth(),is.GetHeight(),proto);
					tmp->SetTransparentColor(is.GetTransparentColor());
					is.Blit(*tmp,0,0,BMODE_OPAQUE,BOP_COPY,0,BLTF_COPYALPHA);
				}
				else if(!i&&edPtr->loadFirst)
				{
					rdPtr->targetId = rdPtr->currentId = 0;
					TargetImg = CurrentImg = 0;
					rdPtr->lastId = rdPtr->targetId;
				}
				UnlockImageSurface(is);
			}
			//Add prototype if there's more than one empty image
			else if(i&&edPtr->imageCount>1)
			{
				rdPtr->surf->push_back(new SImage(new cSurface));
			}

		}
	}
	//Single image
	else
	{
		//First image is set
		if(edPtr->images[0])
		{
			cSurface is, *tmp = new cSurface;
			GetImageInfos(rhPtr->rhIdAppli,edPtr->images[0],&imgInfo);
			rdPtr->surf->push_back(new SImage(tmp,true,imgInfo.imgXSpot,imgInfo.imgYSpot));
			LockImageSurface(rhPtr->rhIdAppli,edPtr->images[0],is);

			if(is.GetWidth())
			{
				GetSurfacePrototype(&proto,rdPtr->depth,ST_MEMORYWITHDC,SD_DIB);
				rdPtr->targetId = rdPtr->currentId = rdPtr->lastId = 0;
				TargetImg = CurrentImg = tmp;
				tmp->Create(is.GetWidth(),is.GetHeight(),proto);
				tmp->SetTransparentColor(is.GetTransparentColor());
				is.Blit(*tmp);
			}
			UnlockImageSurface(is);
			rdPtr->targetValid = true;
		}
		//Create empty image if wanted
		else
		{
			cSurface *tmp = new cSurface;
			rdPtr->surf->push_back(new SImage(tmp));
			//Empty image with size
			if(edPtr->loadFirst)
			{
				GetSurfacePrototype(&proto,rdPtr->depth,ST_MEMORYWITHDC,SD_DIB);
				tmp->Create(edPtr->width,edPtr->height,proto);
				tmp->Fill(BLACK);
			}
			rdPtr->targetId = rdPtr->currentId = rdPtr->lastId = 0;
			TargetImg = CurrentImg = tmp;
			rdPtr->targetValid = TargetImg->IsValid();
		}
	}
	
	//Initialize information
	if(rdPtr->current)
	{	
		rdPtr->rHo.hoImgWidth = rdPtr->current->GetWidth();
		rdPtr->rHo.hoImgHeight = rdPtr->current->GetHeight();
		rdPtr->rHo.hoImgXSpot = ImageS(rdPtr->currentId)->hotX;
		rdPtr->rHo.hoImgYSpot = ImageS(rdPtr->currentId)->hotY;
	}

	// No errors
		return 0;
}
Example #4
0
void LoadImageFile(LPRDATA rdPtr, LPSTR pFileName)
{
	LPRH	rhPtr = rdPtr->rHo.hoAdRunHeader;
	HANDLE	hf = INVALID_HANDLE_VALUE;

	do {	
		if ( pFileName == NULL || *pFileName == 0 )
			break;

		// Copy filename to temp buffer
		char fname[MAX_PATH];
		strcpy(fname, pFileName);

		// Get surface prototype
		LPSURFACE wSurf = WinGetSurface((int)rhPtr->rhIdEditWin);
		LPSURFACE proto;
		GetSurfacePrototype(&proto, (wSurf != NULL) ? wSurf->GetDepth() : 24, ST_MEMORYWITHDC, SD_DIB);
		if ( proto == NULL )
			break;

		// Ask MMF2 to open the file (opens external file and embedded files, and downloads files in Vitalize mode)
		DWORD dwSize;
		hf = rhPtr->rh4.rh4Mv->mvOpenHFile(fname, &dwSize, 0);
		if ( hf == INVALID_HANDLE_VALUE )
			break;

		// Create CInpuBufFile object associated with the file handle
		DWORD dwOff = File_GetPosition((HFILE)hf);
		CInputBufFile bf;
		if ( bf.Create((HFILE)hf, dwOff, dwSize) != 0 )
			break;

		// Create surface
		cSurface* psf = NewSurface();
		if ( psf == NULL )
			break;
		psf->Create(4, 4, proto);
		psf->Fill(RGB(0,0,0));
		if ( psf->GetDepth() == 8 )
			psf->SetPalette (*wSurf);

		// Load picture
		CImageFilterMgr* pImgMgr = rhPtr->rh4.rh4Mv->mvImgFilterMgr;
		if ( ImportImageFromInputFile(pImgMgr, &bf, psf, NULL, IMPORT_IMAGE_USESURFACEDEPTH | IMPORT_IMAGE_USESURFACEPALETTE) )
		{
			// Copy filename if file successfully loaded
			strcpy(rdPtr->sFilename, fname);
			rdPtr->nWidth = rdPtr->rHo.hoImgWidth = psf->GetWidth();
			rdPtr->nHeight = rdPtr->rHo.hoImgHeight = psf->GetHeight();

			// Replace picture surface
			if ( rdPtr->pSf != NULL )
				DeleteSurface(rdPtr->pSf);
			rdPtr->pSf = psf;

			// Free collision mask
			FreeColMask(rdPtr);

			// Set transparent color
			if ( psf->GetTransparentColor() == RGB(0,0,0) )
			{
				COLORREF trspColor = rdPtr->dwTranspColor;
				if ( (rdPtr->dwOptions & SPICTFLAGS_TRANSP_FIRSTPIXEL) != 0 )
					psf->GetPixel(0,0,trspColor);
				psf->SetTransparentColor(trspColor);
			}
		}
		else
			DeleteSurface(psf);

	} while(FALSE);

	// Close picture file (opened with mvOpenHFile)
	if ( hf != INVALID_HANDLE_VALUE )
		rhPtr->rh4.rh4Mv->mvCloseHFile(hf);
}
void WINAPI DLLExport EditorDisplay(mv _far *mV, fpObjInfo oiPtr, fpLevObj loPtr, LPEDATA edPtr, RECT FAR *rc)
{
#ifndef RUN_ONLY

	// This is a simple case of drawing an image onto MMF's frame editor window
	// First, we must get a pointer to the surface used by the frame editor

	LPSURFACE ps = WinGetSurface((int)mV->mvIdEditWin);
	if ( ps != NULL )		// Do the following if this surface exists
	{

        int x = rc->left;
        int y = rc->top;
        int w = rc->right-rc->left;
        int h = rc->bottom-rc->top;



		cSurface is;			// New surface variable for us to use
		is.Create(4, 4, ps);	// Create a surface implementation from a prototype (frame editor win)
 
		is.LoadImage(hInstLib, EXO_IMAGE, LI_NONE);	// Load our bitmap from the resource,
		
        COLORREF color;
        is.GetPixel(0,0,color);
        
        ps->Fill(x, y, w, h, color);

        ps->Rectangle(x+4,y+4,rc->right-4,rc->bottom -4, (COLORREF)0x000000, 1, (COLORREF)0x000000, false);
        ps->Rectangle(x,y,x+36,y+36,color,0,color,true);
        ps->Line(rc->right-112,rc->bottom-5,rc->right-8,rc->bottom-5,1,color);


		// This actually blits (or copies) the whole of our surface onto the frame editor's surface
		// at a specified position.
		// We could use different image effects when we copy, e.g. invert, AND, OR, XOR,
		// blend (semi-transparent, the 6th param is amount of transparency)
		// You can 'anti-alias' with the 7th param (default=0 or off)      

        is.Blit(*ps, x, y, BMODE_TRANSP, BOP_COPY, 0);	// Blit the image to the frame editor surface!

        		// Create font
		HFONT hFnt = NULL;

		// Ink effects
		BOOL bTransp = ((oiPtr->oiHdr.oiInkEffect & EFFECTFLAG_TRANSPARENT) != 0);
		BlitMode bm = (bTransp) ? BMODE_TRANSP : BMODE_OPAQUE;
		BOOL bAntiA = (oiPtr->oiHdr.oiInkEffect & EFFECTFLAG_ANTIALIAS) ? TRUE : FALSE;
		BlitOp bo = (BlitOp)(oiPtr->oiHdr.oiInkEffect & EFFECT_MASK);
		LPARAM boParam = oiPtr->oiHdr.oiInkEffectParam;

		// Draw text
		DWORD dwDTFlags =  DT_RIGHT | DT_BOTTOM | DT_NOPREFIX | DT_SINGLELINE | DT_END_ELLIPSIS;
		ps->DrawText("Exclusion Zone", 14, rc, dwDTFlags, 0x000000, hFnt,
					 bm, bo, boParam, bAntiA, 0UL,8UL);

		// Delete font
		if ( hFnt != NULL )
			DeleteObject(hFnt);

        
        
	}

#endif // !RUN_ONLY
}