Esempio n. 1
0
void TPack_ExtractSelected(TPack_WindowData * pData)
{
	HWND            hLB = GetDlgItem(pData->hwnd, IDC_TEXTURELIST);
	int             nSel;
	BitmapEntry *	pEntry;
	char            szName[MAX_TEXTURE_NAME_LENGTH];
	char            szFile[MAX_PATH];
	char            szPath[MAX_PATH];
	int             nErrorCode;

	//----------------------------------------------
	// Get current selected list box entry.
	// Get the  geBitmap.
	// Write 8-bit BMP file.
	//----------------------------------------------

	// Ouput to the current directory
	GetCurrentDirectory(MAX_PATH, szPath);

	nSel = ListBox_GetCurSel(hLB);
	if (nSel != LB_ERR)

	if (ListBox_GetText(hLB, nSel, szName) != LB_ERR)
	{
		pEntry = FindBitmap(pData, szName);
		if (pEntry)
		{
			// Create an output file name
			strcpy(szFile, szPath);
			strcat(szFile, "\\");
			strcat(szFile, pEntry->Name);
			strcat(szFile, ".bmp");

			nErrorCode = WriteBMP8(szFile, pEntry->Bitmap);

			if (nErrorCode != TPACKERROR_OK)
			{
				// Error writing this bitmap
				switch (nErrorCode)
				{
					case TPACKERROR_CREATEFILE:
						NonFatalError("Unable to create output file %s", szFile);
						break;
					case TPACKERROR_WRITE:
						NonFatalError("I/O error writing %s", szFile);
						break;
					case TPACKERROR_MEMORYALLOCATION:
						NonFatalError("Memory allocation error writing %s", szFile);
						break;
					case TPACKERROR_UNKNOWN:
					default:
						NonFatalError("UInknown error writing %s", szFile);
				}
			}
		}
	}
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
static	void	Save(TPack_WindowData *pData, const char *Path)
{
	char		FileName[_MAX_PATH];
	geVFile *	VFS;
	int			i;

	if	(!Path)
	{
		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.nFileOffset = 0;
		ofn.nFileExtension = 0;
		ofn.lpstrDefExt = "txl";
		ofn.lCustData = 0;
		ofn.lpfnHook = NULL;
		ofn.lpTemplateName = NULL;

		if	(!GetSaveFileName (&ofn))
			return;

		Path = FileName;
	}
	
	unlink(Path);
	VFS = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_VIRTUAL, Path, NULL, GE_VFILE_OPEN_CREATE | GE_VFILE_OPEN_DIRECTORY);
	if	(!VFS)
	{
		NonFatalError("Could not open file %s", Path);
		return;
	}

	for	(i = 0; i < pData->BitmapCount; i++)
	{
		geVFile *	File;
		geBoolean	WriteResult;

		if	(pData->Bitmaps[i].Flags & ENTRY_DELETED)
			continue;

		File = geVFile_Open(VFS, pData->Bitmaps[i].Name, GE_VFILE_OPEN_CREATE);
		if	(!File)
		{
			NonFatalError("Could not save bitmap %s", pData->Bitmaps[i].Name);
			geVFile_Close(VFS);
			return;
		}
		WriteResult = geBitmap_WriteToFile(pData->Bitmaps[i].Bitmap, File);
		geVFile_Close(File);
		if	(WriteResult == GE_FALSE)
		{
			NonFatalError("Could not save bitmap %s", pData->Bitmaps[i].Name);
			geVFile_Close(VFS);
			return;
		}
	}

	strcpy(pData->TXLFileName, Path);
	pData->FileNameIsValid = TRUE;
	
	if	(geVFile_Close(VFS) == GE_FALSE)
		NonFatalError("I/O error writing %s", Path);
	else
		pData->Dirty = FALSE;
}
Esempio n. 6
0
void TPack_ExtractAll(TPack_WindowData * pData)
{
	HWND            hLB = GetDlgItem(pData->hwnd, IDC_TEXTURELIST);
	int             nCount;
	int             i;
	BitmapEntry *	pEntry;
	char            szName[MAX_TEXTURE_NAME_LENGTH];
	char            szFile[MAX_PATH];
	char            szPath[MAX_PATH];
	int             nErrorCode;
	HCURSOR         hCursor;

	//----------------------------------------------
	// Travese list box.
	// For each list box entry.
	//    Get the  geBitmap
	//    Write 8-bit BMP file.
	//----------------------------------------------

	// This may take a while, let them know something is happening
	// NOTE: Ideally a progress bar is needed.
	hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
	ShowCursor(FALSE);
	ShowCursor(TRUE);


	// Ouput to the current directory
	GetCurrentDirectory(MAX_PATH, szPath);

	nCount = ListBox_GetCount(hLB);

	for (i = 0; i < nCount; i++)
	{
		if (ListBox_GetText(hLB, i, szName) != LB_ERR)
		{
			pEntry = FindBitmap(pData, szName);
			if (pEntry)
			{
				strcpy(szFile, szPath);
				strcat(szFile, "\\");
				strcat(szFile, pEntry->Name);
				strcat(szFile, ".bmp");

				nErrorCode = WriteBMP8(szFile, pEntry->Bitmap);

				if (nErrorCode != TPACKERROR_OK)
				{
					// Error writing this bitmap
					switch (nErrorCode)
					{
						case TPACKERROR_CREATEFILE:
							NonFatalError("Unable to create output file %s", szFile);
							break;
						case TPACKERROR_WRITE:
							NonFatalError("I/O error writing %s", szFile);
							break;
						case TPACKERROR_MEMORYALLOCATION:
							NonFatalError("Memory allocation error writing %s", szFile);
							break;
						case TPACKERROR_UNKNOWN:
						default:
							NonFatalError("UInknown error writing %s", szFile);
					}

					// Exit extract all loop on error
					break;
				}
			}
		}
	}

	// Restore the cursor
	SetCursor(hCursor);

}
void
PlayerConnection::handleCommand( PlayerCommand command, Track t )
{
    qDebug() << command;

    try
    {
        switch (command)
        {
            case CommandStart:
                if (t.isNull()) throw FatalError("Can't start a null track");
                m_state = Playing;
                if ( m_stoppedTimer ) m_stoppedTimer->stop();
                if (t == m_track)
                {
                    emit resumed();
                    throw NonFatalError("Already playing this track");
                }
                qSwap(m_track, t);
                m_elapsed = 0;
                emit trackStarted( m_track, t );
                break;
                
            case CommandPause:
                if (m_track.isNull()) throw FatalError("Cannot pause a null track");
                if (m_state == Paused) throw NonFatalError("Already paused");
                m_state = Paused;
                emit paused();
                break;

            case CommandResume:
                if (m_track.isNull()) throw FatalError("Can't resume null track");
                if (m_state == Playing) throw NonFatalError("Already playing");
                m_state = Playing;
                emit resumed();
                break;

            case CommandTerm:
            case CommandInit:
            case CommandStop:
                // don't process the stop straight away because we could be skipping
                // track so wait a second to make sure we don't get a start command
                if ( !m_stoppedTimer )
                {
                    m_stoppedTimer = new QTimer( this );
                    m_stoppedTimer->setSingleShot( true );
                    m_stoppedTimer->setInterval( 1000 );
                    connect( m_stoppedTimer, SIGNAL(timeout()), this, SLOT(onStopped()) );
                }

                m_stoppedTimer->start();
                break;
                
            case CommandBootstrap:
				emit bootstrapReady( id() );
                break;
        }
        
    }
    catch (Error& error)
    {
        qWarning() << error.message();

        if (error.isFatal())
        {
            m_state = Stopped;
            m_track = Track();
            emit stopped();
        }
    }
}