/* ------------------------------------------------------------------------------------ */
bool CAnimGif::DisplayNextFrameTexture(const char *szTextureName, bool FFrame)
{
	if(!Active)
		return false;

	if(FFrame)
	{
		geBitmap_Info Info;
		geBitmap *theBitmap = geWorld_GetBitmapByName(CCD->World(), szTextureName);

		if(!theBitmap)
		{
			Active = false;
			return false;
		}

		geBitmap_GetInfo(theBitmap, &Info, NULL);

		if(nWidth!=Info.Width || nHeight!=Info.Height)
		{
			Active = false;
			return false;
		}

		if(theBmp)
		{
// changed QD 12/15/05
			geEngine_RemoveBitmap(CCD->Engine()->Engine(), theBmp);
// end change
			geBitmap_Destroy(&theBmp);
		}

		theBmp = theBitmap;
		Texture = true;
		TotalReadByte = 0;
		pcGifTrack=pcGif;
		VAnimTime = (float)CCD->FreeRunningCounter();

		if(GetImage(true))
		{
			FirstFrame = false;
			return true;
		}

		FirstFrame = false;
		return false;
	}
	else
	{
		NextFrame(true);
	}

	return true;
}
static void WadFileEntry_Free (WadFileEntry *pe)
{
	if (pe->LockedBitmap != NULL)
	{
		geBitmap_UnLock (pe->LockedBitmap);
	}
	if (pe->bmp != NULL)
	{
		geBitmap_Destroy (&pe->bmp);
	}
	if (pe->Name != NULL)
	{
		geRam_Free (pe->Name);
	}
}
/* ------------------------------------------------------------------------------------ */
void Particles_Destroy(Procedural *Proc)
{
	if(!Proc)
		return;

	if(Proc->Bitmap)
		geBitmap_Destroy(&(Proc->Bitmap)); // we did creatref

	if(Proc->Particles)
		geRam_Free(Proc->Particles);

	if(Proc->Sources)
		geRam_Free(Proc->Sources);

	geRam_Free(Proc);
}
Exemple #4
0
void XFont_Destroy(XFont* fnt){
	int i;
	if ( fnt->m_world )
	{
		// remove the bitmaps from the world
		for ( i = kFontLowRange; i <= kFontHighRange; i++ )
		{
			if ( fnt->m_chars[i].bitmap )
			{
				geWorld_RemoveBitmap( fnt->m_world, fnt->m_chars[i].bitmap );
				geBitmap_Destroy( &(fnt->m_chars[i].bitmap) );
			}
		}

		geEngine_RemoveWorld( fnt->m_engine, fnt->m_world );
		geWorld_Free( fnt->m_world );
		fnt->m_world = NULL;
	}
}
/* ------------------------------------------------------------------------------------ */
CAnimGif::~CAnimGif()
{
	if(GlobalColorTable)
		delete[] GlobalColorTable;

	if(pcGif)
		delete[] pcGif;

	geBitmap_Palette_Destroy(&Palette);

	if(theBmp && !Texture)
	{
// changed QD 12/15/05
		geEngine_RemoveBitmap(CCD->Engine()->Engine(), theBmp);
// end change
		geBitmap_Destroy(&theBmp);
	}

	return;
}
geBoolean CWadFile::Setup(const char *Filename)
{
	geVFile *			Library;

	geBoolean			NoErrors = GE_FALSE;

	Library = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_VIRTUAL, Filename, NULL, GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_DIRECTORY);
	if (Library != NULL)
	{
		NoErrors = GE_TRUE;

		DestroyBitmapArray ();

		int nFiles = wadCountFiles (Library, "*.*");

		if (nFiles > 0)
		{
			// make new array and fill it with loaded bitmaps
			mBitmaps = (WadFileEntry *)geRam_Allocate (nFiles * sizeof (WadFileEntry));

			// and fill array with filenames
			NoErrors = GE_FALSE;
			geVFile_Finder *Finder = geVFile_CreateFinder (Library, "*.*");
			if (Finder != NULL)
			{
				NoErrors = GE_TRUE;
				geVFile_Properties Props;

				while (geVFile_FinderGetNextFile (Finder) != GE_FALSE)
				{
					geVFile_FinderGetProperties (Finder, &Props);

					// load the file and create a DibBitmap from it
					geVFile *BmpFile = geVFile_Open (Library, Props.Name, GE_VFILE_OPEN_READONLY);
					geBitmap *TheBitmap;

					if (BmpFile == NULL)
					{
						NoErrors = GE_FALSE;
					}
					else
					{
						TheBitmap = geBitmap_CreateFromFile (BmpFile);
						geVFile_Close (BmpFile);
						if (TheBitmap == NULL)
						{
							NoErrors = GE_FALSE;
						}
						else
						{
							if (geBitmap_SetFormat (TheBitmap, GE_PIXELFORMAT_16BIT_555_RGB, GE_FALSE, 0, NULL) != GE_FALSE)
							{
								WadFileEntry *pe;
								geBitmap_Info info, info2;

								geBitmap_GetInfo (TheBitmap, &info, &info2);
								pe = &mBitmaps[mBitmapCount];
								pe->bmp = TheBitmap;
								pe->Height = info.Height;
								pe->Width = info.Width;
								pe->Name = Util_Strdup (Props.Name);
								geBitmap_LockForReadNative (pe->bmp, &pe->LockedBitmap, 0, 0);
								pe->BitsPtr = geBitmap_GetBits (pe->LockedBitmap);

								++mBitmapCount;
							}
							else
							{
								geBitmap_Destroy (&TheBitmap);
								NoErrors = GE_FALSE;
							}
						}
					}
				}

				geVFile_DestroyFinder (Finder);
			}
		}
		geVFile_Close (Library);
	}

	return GE_TRUE;
}
static BOOL CALLBACK TPack_DlgProc
	(
	  HWND hwnd,
	  UINT msg,
	  WPARAM wParam,
	  LPARAM lParam
	)
{
	TPack_WindowData *pData = TPack_GetWindowData (hwnd);

	switch (msg)
	{
	case WM_INITDIALOG :
		return TPack_InitializeDialog (hwnd);

	case WM_DESTROY :
		TPack_ShutdownAll (hwnd, pData);
		PostQuitMessage (0);
		break;

	case WM_COMMAND :
	{
		WORD wNotifyCode = HIWORD (wParam);
		WORD wID = LOWORD (wParam);
		HWND hwndCtl = (HWND)lParam;

		return wm_Command (hwnd, pData, wNotifyCode, wID, hwndCtl);
	}


	case	MSG_DELETE_BITMAP:
	{
		BitmapEntry *	Entry;

		Entry = FindBitmap(pData, (const char *)lParam);
		assert(Entry);
		if	(Entry->Name)
		{
			free(Entry->Name);
			Entry->Name = NULL;
		}
		if	(Entry->Bitmap)
			geBitmap_Destroy(&Entry->Bitmap);
		if	(Entry->WinBitmap)
			DeleteObject(Entry->WinBitmap);
		Entry->Flags |= ENTRY_DELETED;
		pData->Dirty = TRUE;
		return 0;
	}
		
	case	MSG_SELECT_BITMAP:
	{
		char	Buff[128];
		int		Index;
		char	TextureName[MAX_TEXTURE_NAME_LENGTH];
		BitmapEntry *	Entry;

		Index = SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
		if	(Index == LB_ERR)
		{
			Entry = NULL;
		}
		else
		{
			SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_GETTEXT, (WPARAM)Index, (LPARAM)&TextureName[0]);
			Entry = FindBitmap(pData, TextureName);
			assert(Entry);
			if	(!Entry->WinBitmap)
			{
				HWND	PreviewWnd;
				HBITMAP	hbm;
				HDC		hDC;
	
				PreviewWnd = GetDlgItem(pData->hwnd, IDC_PREVIEW);
				hDC = GetDC(PreviewWnd);
				hbm = CreateHBitmapFromgeBitmap(Entry->Bitmap, hDC);
				Entry->WinBitmap = hbm;
				ReleaseDC(PreviewWnd, hDC);
			}
	
			if	(!Entry->WinBitmap)
			{
				NonFatalError("Memory allocation error creating bitmap");
				return 0;
			}
		}

		InvalidateRect(GetDlgItem(hwnd, IDC_PREVIEW), NULL, TRUE);
		pData->SelectedEntry = Entry;
		
		if	(Entry)
			sprintf(Buff, "%dx%d", geBitmap_Width(Entry->Bitmap), geBitmap_Height(Entry->Bitmap));
		else
			Buff[0] = '\0';
		SetWindowText(GetDlgItem(hwnd, IDC_TEXTURESIZE), Buff);
		return 0;
	}

	case WM_DROPFILES :
	{
		// Files dropped.
		HDROP hDrop;
		UINT FileCount;
		char Buff[MAX_PATH];

		hDrop = (HDROP)wParam;
		FileCount = DragQueryFile (hDrop, 0xffffffff, Buff, sizeof (Buff));
		while	(FileCount--)
		{
			DragQueryFile (hDrop, FileCount, Buff, sizeof (Buff));
			AddTexture(pData, NULL, Buff);
		}
		pData->Dirty = TRUE;
		DragFinish (hDrop);
		return 0;
	}

	// Initialize the pulldown
	// Added DJT (see revision note - 4/18/99)
	case WM_INITMENU:

		if (GetMenu(hwnd) == (HMENU)wParam)
			HandleInitMenu(pData, (HMENU)wParam);
		break;


	default :
		break;

	}
	return FALSE;
}
static	void	Load(TPack_WindowData *pData)
{
	char				FileName[_MAX_PATH];
	geVFile *			VFS;
	int					i;
	geVFile_Finder *	Finder;

	if	(pData->Dirty)
	{
		int	Result;

		Result = MessageBox(NULL,
							"Do you want to save changes to the current file?",
							"Texture Packer",
							MB_YESNOCANCEL);
		
		if	(Result == IDCANCEL)
			return;

		if	(Result == IDYES)
		{
#pragma message ("We don't respect CANCEL of saving dirty data in Load")
			if	(pData->FileNameIsValid)
				Save(pData, pData->TXLFileName);
			else
				Save(pData, NULL);
		}
	}

	for	(i = 0; i < pData->BitmapCount; i++)
	{
		if	(!(pData->Bitmaps[i].Flags & ENTRY_DELETED))
		{
			SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_DELETESTRING, (WPARAM)0, (LPARAM)0);
			free(pData->Bitmaps[i].Name);
			geBitmap_Destroy(&pData->Bitmaps[i].Bitmap);
			if	(pData->Bitmaps[i].WinBitmap)
				DeleteObject(pData->Bitmaps[i].WinBitmap);
		}
	}
	if	(pData->Bitmaps)
		geRam_Free(pData->Bitmaps);
	pData->Bitmaps = NULL;
	pData->BitmapCount = 0;
	pData->SelectedEntry = NULL;

	{
		OPENFILENAME ofn;	// Windows open filename structure...
		char Filter[_MAX_PATH];
		char	Dir[_MAX_PATH];
	
		FileName[0] = '\0';

		GetCurrentDirectory(sizeof(Dir), Dir);
	
		ofn.lStructSize = sizeof (OPENFILENAME);
		ofn.hwndOwner = pData->hwnd;
		ofn.hInstance = pData->Instance;
		{
			char *c;
	
			// build actor file filter string
			strcpy (Filter, "Texture Libraries (*.txl)");
			c = &Filter[strlen (Filter)] + 1;
			// c points one beyond end of string
			strcpy (c, "*.txl");
			c = &c[strlen (c)] + 1;
			*c = '\0';	// 2nd terminating nul character
		}
		ofn.lpstrFilter = Filter;
		ofn.lpstrCustomFilter = NULL;
		ofn.nMaxCustFilter = 0;
		ofn.nFilterIndex = 1;
		ofn.lpstrFile = FileName;
		ofn.nMaxFile = sizeof(FileName);
		ofn.lpstrFileTitle = FileName;
		ofn.nMaxFileTitle = sizeof(FileName);
		ofn.lpstrInitialDir = Dir;
		ofn.lpstrTitle = NULL;
		ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
		ofn.nFileOffset = 0;
		ofn.nFileExtension = 0;
		ofn.lpstrDefExt = "txl";
		ofn.lCustData = 0;
		ofn.lpfnHook = NULL;
		ofn.lpTemplateName = NULL;

		if	(!GetOpenFileName (&ofn))
			return;
	}
	
	VFS = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_VIRTUAL, FileName, NULL, GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_DIRECTORY);
	if	(!VFS)
	{
		NonFatalError("Could not open file %s", FileName);
		return;
	}

	Finder = geVFile_CreateFinder(VFS, "*.*");
	if	(!Finder)
	{
		NonFatalError("Could not load textures from %s", FileName);
		geVFile_Close(VFS);
		return;
	}
	
	while	(geVFile_FinderGetNextFile(Finder) != GE_FALSE)
	{
		geVFile_Properties	Properties;

		geVFile_FinderGetProperties(Finder, &Properties);
		if	(!AddTexture(pData, VFS, Properties.Name))
		{
			geVFile_Close(VFS);
			return;
		}
	}

	strcpy(pData->TXLFileName, FileName);
	pData->FileNameIsValid = TRUE;
	pData->Dirty = FALSE;
	
	geVFile_Close(VFS);
}
static	BOOL	AddTexture(TPack_WindowData *pData, geVFile *BaseFile, const char *Path)
{
	geBitmap_Info	PInfo;
	geBitmap_Info	SInfo;
	geBitmap *		Bitmap;
	BitmapEntry *	NewBitmapList;
	geVFile *		File;
	char			FileName[_MAX_FNAME];
	char *			Name;

	Bitmap = NULL;
	File = NULL;

	_splitpath(Path, NULL, NULL, FileName, NULL);
	Name = strdup(FileName);
	if	(!Name)
	{
		NonFatalError("Memory allocation error processing %s", Path);
		return FALSE;
	}

	if	(BaseFile)
		File = geVFile_Open(BaseFile, Path, GE_VFILE_OPEN_READONLY);
	else
		File = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, Path, NULL, GE_VFILE_OPEN_READONLY);

	if	(!File)
	{
		NonFatalError("Could not open %s", Path);
		goto fail;
	}

	Bitmap = geBitmap_CreateFromFile(File);
	geVFile_Close(File);
	if	(!Bitmap)
	{
		NonFatalError("%s is not a valid bitmap", Path);
		goto fail;
	}
	geBitmap_GetInfo(Bitmap, &PInfo, &SInfo);
	if	(PInfo.Format != GE_PIXELFORMAT_8BIT)
	{
		NonFatalError("%s is not an 8bit bitmap", Path);
		goto fail;
	}
	NewBitmapList = geRam_Realloc(pData->Bitmaps, sizeof(*NewBitmapList) * (pData->BitmapCount + 1));
	if	(!NewBitmapList)
	{
		NonFatalError("Memory allocation error processing %s", Path);
		goto fail;
	}

	NewBitmapList[pData->BitmapCount].Name		= Name;
	NewBitmapList[pData->BitmapCount].Bitmap	= Bitmap;
	NewBitmapList[pData->BitmapCount].WinBitmap	= NULL;
	NewBitmapList[pData->BitmapCount].Flags		= 0;
	pData->BitmapCount++;
	pData->Bitmaps = NewBitmapList;

	SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)Name);
	return TRUE;

fail:
	if	(Name)
		free(Name);
	if	(Bitmap)
		geBitmap_Destroy(&Bitmap);
	return FALSE;
}