//------------------------------------------------------------------------
    bool platform_support::load_img(unsigned idx, const char* file)
    {
        if(idx < max_images) {

#ifndef _MG_MINIMALGRAF
            if(m_specific->m_surf_img[idx]) 
                UnloadBitmap(m_specific->m_surf_img[idx]);
            else
                m_specific->m_surf_img[idx] = (PBITMAP)calloc(1, sizeof(BITMAP)); 

            if (LoadBitmapFromFile(m_specific->m_surf_window, 
                        m_specific->m_surf_img[idx], file) != 0)
                return false;
#endif
#if 0
            FillBoxWithBitmap(m_specific->m_surf_window, 0, 0, 0, 0, 
                    m_specific->m_surf_img[idx]);
#endif

#if 0
            printf("load img: w=%d, h=%d, pitch=%d, pixels=%x\n", 
                    m_specific->m_surf_img[idx]->bmWidth, 
                    m_specific->m_surf_img[idx]->bmHeight, 
                    m_specific->m_surf_img[idx]->bmPitch, 
                    m_specific->m_surf_img[idx]->bmBits);
#endif
            m_rbuf_img[idx].attach(m_specific->m_surf_img[idx]->bmBits, 
                    m_specific->m_surf_img[idx]->bmWidth, 
                    m_specific->m_surf_img[idx]->bmHeight, 
                    m_flip_y?(-m_specific->m_surf_img[idx]->bmPitch):
                            m_specific->m_surf_img[idx]->bmPitch);
            return true;
        }
        return false;
    }
Ejemplo n.º 2
0
HRESULT FirstTry::CreateDeviceResources()
{
	HRESULT hr = S_OK;
	if (!m_pRenderTarget)
	{
		RECT rc;
		GetClientRect(m_hwnd, &rc);

		D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);

		// Create a Direct2D render target.
		hr = m_pD2DFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(m_hwnd, size),
			&m_pRenderTarget);

		if (SUCCEEDED(hr))
		{
			// Create a gray brush.
			hr = m_pRenderTarget->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::LightSlateGray),
				&m_pLightSlateGrayBrush);
		}

		if (SUCCEEDED(hr))
		{
			// Create a blue brush.
			hr = m_pRenderTarget->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::CornflowerBlue),
				&m_pCornflowerBlueBrush);
		}

		// Create a bitmap from an application resource.
		if (SUCCEEDED(hr))
		{
			hr = LoadResourceBitmap(
				m_pRenderTarget,
				m_pWICFactory,
				L"SAMPLEIMAGE",
				L"IMAGE",
				0,
				0,
				&m_pBitmap);
		}

		// Create a bitmap by loading it from a file.
		if (SUCCEEDED(hr))
		{
			hr = LoadBitmapFromFile(
				m_pRenderTarget,
				m_pWICFactory,
				L".\\sampleImage.jpg",
				0,
				0,
				&m_pBitmap1);
		}
	}

	return hr;
}
// 加载窗口背景图片(从文件或zip资源加载)
void CDuiVisionDesignerView::LoadBackgroundImage(CString strFileName)
{
	CBitmap bitBackground;
	if(LoadBitmapFromFile(strFileName, bitBackground, m_sizeBKImage))
	{
		DrawBackground(bitBackground);
	}
}
void mxBitmapButton::SetImage( const char *bitmapname )
{
	if ( m_bmImage.valid )
	{
		DeleteImage();
	}

	LoadBitmapFromFile( va( "%s/%s", GetGameDirectory(), bitmapname ), m_bmImage );
}
Ejemplo n.º 5
0
bool Resources::Load() {

    bool loaded = true;

    for (int i = 0; i < FILE_COUNT && loaded; i++) {
        loaded = LoadBitmapFromFile(FILES[i], *bitmaps[i]);
    }

    return loaded;
}
void IFaceposerModels::CFacePoserModel::LoadBitmapForSequence( mxbitmapdata_t *bitmap, int sequence )
{
	// See if it exists
	char filename[ 512 ];
	Q_strncpy( filename, GetBitmapFilename( sequence ), sizeof( filename ) );

	if ( !LoadBitmapFromFile( filename, *bitmap ) )
	{
		CreateNewBitmap( filename, sequence, 256, false, NULL, bitmap );
	}
}
Ejemplo n.º 7
0
InlineImage::InlineImage(
    Microsoft::WRL::ComPtr<ID2D1DeviceContext> deviceContext,
    Microsoft::WRL::ComPtr<IWICImagingFactory> IWICFactory,
    PCWSTR uri
    ) :
    refCount(0)
{
    // Save the render target for later.
    this->deviceContext = deviceContext;

    // Load the bitmap from a file.
    LoadBitmapFromFile(
        deviceContext,
        IWICFactory,
        uri,
        &bitmap
        );
}
static void* this_init(void)
{
    Context *con = malloc(sizeof(Context));

    get_dsp_app ();
    icon_info.focus = 0xFFFF;

    if(0 != strcmp(icon_info.bg_path, ""))
    {
        con->bg = (PBITMAP)malloc(sizeof(BITMAP));
        LoadBitmapFromFile(HDC_SCREEN, con->bg, icon_info.bg_path);
    }
    else
        con->bg = NULL; 

    con->icon_menu = create_icon_menu();   

    return (void *)con;
}
Ejemplo n.º 9
0
void SCALE::LoadBitmap(HWND hwnd, int LoadMethod, int scaleOrInd)
{
	HANDLE hDIB ;
	POINT  size ;

  
	if (scaleOrInd==DIAL)
		hDIB = scaleData.hScale ;
	else
		hDIB = indData.hIndicator ;

	if (LoadMethod==CLIPBOARD)
		{
		hDIB = LoadBitmapFromClipboard(hwnd, hDIB, &size) ;
		}
	else
		{
		hDIB = LoadBitmapFromFile(hwnd, hDIB, &size) ;//&rect) ;
		}

	if (hDIB)
  	{
		if (scaleOrInd==DIAL)
			{
			scaleData.hScale = hDIB; //hBitmap ;
			scaleData.rect.right  = scaleData.rect.left+size.x ;
			scaleData.rect.bottom = scaleData.rect.top+ size.y ;
			}
		else
			{
			indData.hIndicator = hDIB; //hBitmap ;
			indData.maxRect.right  = indData.maxRect.left+size.x ;
			indData.maxRect.bottom = indData.maxRect.top+size.y ;
			indData.minRect.right  = indData.minRect.left+size.x ;
      indData.minRect.bottom = indData.minRect.top +size.y ;
			}
    }
	InvalidateRect (hLayoutW, NULL, TRUE) ;
	UpdateWindow(hLayoutW) ;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *btn - 
//-----------------------------------------------------------------------------
void mxExpressionTray::AddButton( const char *name, const char *tooltip, const char *bitmap, ETMEMBERFUNC pfnCallback,
	bool active, int x, int y, int w, int h )
{
	mxETButton *btn = new mxETButton;
	strcpy( btn->m_szName, name );
	strcpy( btn->m_szToolTip, tooltip );
	btn->m_bActive = active;
	btn->m_rc.left = x;
	btn->m_rc.top = y;
	btn->m_rc.right = x + w;
	btn->m_rc.bottom = y + h;

	btn->m_pImage = new mxbitmapdata_t;
	Assert( btn->m_pImage );
	btn->m_pImage->valid = false;
	LoadBitmapFromFile( bitmap, *btn->m_pImage );

	btn->m_fnCallback = pfnCallback;

	btn->next = m_pButtons;
	m_pButtons = btn;
}
Ejemplo n.º 11
0
void CImageFile::Reload(HDC hdc)
{
	LoadBitmapFromFile(myFileName, hdc);
}
static int ControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case MSG_CREATE:
    {
        int i;
        COOLBARITEMINFO cbii;
        HWND coolbar1, coolbar2, coolbar3, coolbar4;

        coolbar1 = CreateWindow (CTRL_COOLBAR,
                              "",
                              WS_CHILD | WS_VISIBLE | CBS_BMP_CUSTOM,
                              IDC_COOLBAR1,
                              0, 0,
                              52 * (NM_BARPIC + 1), 0,
                              hWnd, MAKELONG (48, 48));
           
        coolbar2 = CreateWindow (CTRL_COOLBAR,
                              "",
                              WS_CHILD | WS_VISIBLE | CBS_BMP_32X32,
                              IDC_COOLBAR2,
                              0, 100,
                              36 * (NM_BARPIC + 1), 0, hWnd, 0);

        coolbar3 = CreateWindow (CTRL_COOLBAR,
                              "",
                              WS_CHILD | WS_VISIBLE,
                              IDC_COOLBAR3,
                              0, 230,
                              20 * (NM_BARPIC + 1), 0, hWnd, 0);
           
        coolbar4 = CreateWindow (CTRL_COOLBAR,
                              "res/bkgnd.gif",
                              WS_CHILD | WS_VISIBLE | CBS_USEBKBMP | CBS_BMP_CUSTOM,
                              IDC_COOLBAR4,
                              0, 170,
                              240, 0, hWnd, MAKELONG (20, 20));
           
        for (i = 0; i < NM_BARPIC; i++) {
            LoadBitmapFromFile (HDC_SCREEN, bmps+i, barpic[i]);
            cbii.id = IDC_BAR + i + 1;
            cbii.ItemType = TYPE_BMPITEM;
            cbii.Bmp = bmps + i;
            cbii.ItemHint = barhint[i];
            cbii.Caption = NULL;
            cbii.dwAddData = 0;
            SendMessage (coolbar1, CBM_ADDITEM, 0, (LPARAM)&cbii);
            SendMessage (coolbar2, CBM_ADDITEM, 0, (LPARAM)&cbii);
            SendMessage (coolbar3, CBM_ADDITEM, 0, (LPARAM)&cbii);

            if (i == 3) {
                cbii.ItemType = TYPE_BARITEM;
                SendMessage (coolbar4, CBM_ADDITEM, 0, (LPARAM)&cbii);
            }

            if (i >= 3) {
                cbii.ItemType = TYPE_TEXTITEM;
                cbii.Bmp = NULL;
                cbii.ItemHint = barhint[i];
                cbii.Caption = barhint[i];
                cbii.dwAddData = 0;
            }

            SendMessage (coolbar4, CBM_ADDITEM, 0, (LPARAM)&cbii);
        }
        break;
    }
       	
    case MSG_COMMAND:
    {
#if 0
        int id = LOWORD (wParam);
        int nc = HIWORD (wParam);
#endif

        break;
    }

    case MSG_DESTROY:
    {
        int i;

        for (i = 0; i < 6; i++)
            UnloadBitmap (bmps+i);

        hMainWnd = HWND_INVALID;
        return 0;
    }

    case MSG_CLOSE:
        DestroyAllControls (hWnd);
        DestroyMainWindow (hWnd);
        MainWindowCleanup (hWnd);
        return 0;

    default:
        break;
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
static int
ControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    static BITMAP folder;
    
    switch (message)
	{
	case MSG_CREATE:
	{

	    create_ctrls (hWnd);
	    hRightMenu = create_rightbutton_menu ();
	    
	    LoadBitmapFromFile (HDC_SCREEN, &folder, "./res/folder.bmp");
	    
	    hChildWnd1 = CreateWindow (CTRL_GRID, "GRID",
				       WS_CHILD | WS_VISIBLE | WS_VSCROLL |
				       WS_HSCROLL | WS_BORDER, IDC_GRID, 20, 20, 350,
				       200, hWnd, 0);
	    
	}
	break;
	
	case MSG_COMMAND:
	{
	    int id = LOWORD (wParam);
	    //int code = HIWORD (wParam);
	    int nSel, col, row;
	    char buffer[101];
	    
	    GetWindowText (GetDlgItem(hWnd, IDC_EDIT), buffer, 100);
	    nSel = atoi(buffer);
	    
	    switch (id) {
            case IDC_CTRL1:
                row = SendMessage(hChildWnd1, GRIDM_GETHEADHEIGHT, 0,0);
                sprintf(buffer, "%d", row);
                SetWindowText(GetDlgItem(hWnd, IDC_EDIT), buffer);
                break;

            case IDC_CTRL2:
                col = SendMessage(hChildWnd1, GRIDM_GETHEADWIDTH, 0,0);
                sprintf(buffer, "%d", col);
                SetWindowText(GetDlgItem(hWnd, IDC_EDIT), buffer);
                break;

            case IDC_CTRL3:
                col = SendMessage(hChildWnd1, GRIDM_GETCOLCOUNT, 0, 0);
                SendMessage(hChildWnd1, GRIDM_ADDCOL, (WPARAM)col, 0);
                break;

            case IDC_CTRL4:
                col = SendMessage(hChildWnd1, GRIDM_GETCOLCOUNT, 0, 0);
                SendMessage(hChildWnd1, GRIDM_DELCOL, (WPARAM)(col-1), 0);
                break;

            case IDC_CTRL6:
                break;

            case IDC_CTRL7:
                break;

            case IDC_CTRL8:
                break;

            case IDC_CTRL9:
                break;

            case IDM_FILE ... IDM_FILE+4:
                MessageBox (hMainWnd, "In Construction ...", "Sorry", MB_OK);
                break;
	    }
	    
	}
	break;
	
	case MSG_DESTROY:
	    UnloadBitmap (&folder);
	    DestroyMenu (hRightMenu);
	    DestroyAllControls (hWnd);
	    hMainWnd = HWND_INVALID;
	    return 0;
	    
	case MSG_CLOSE:
	    DestroyMainWindow (hWnd);
	    MainWindowCleanup (hWnd);
	    return 0;
	    
	}
    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
void IFaceposerModels::CFacePoserModel::CreateNewBitmap( char const *pchBitmapFilename, int sequence, int nSnapShotSize, bool bZoomInOnFace, CExpression *pExpression, mxbitmapdata_t *bitmap )
{
	MatSysWindow *pWnd = g_pMatSysWindow;
	if ( !pWnd ) 
		return;

	StudioModel *model = m_pModel;
	if ( !model )
		return;

	CStudioHdr *hdr = model->GetStudioHdr();
	if ( !hdr )
		return;
	if ( sequence < 0 || sequence >= hdr->GetNumSeq() )
		return;

	mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( sequence );

	Con_ColorPrintf( FILE_COLOR, "Creating bitmap %s for sequence '%s'\n", pchBitmapFilename, seqdesc.pszLabel() );

	model->ClearOverlaysSequences();
	int iLayer = model->GetNewAnimationLayer();
	model->SetOverlaySequence( iLayer, sequence, 1.0 );
	model->SetOverlayRate( iLayer, FindPoseCycle( model, sequence ), 0.0 );

	for (int i = 0; i < hdr->GetNumPoseParameters(); i++)
	{
		model->SetPoseParameter( i, 0.0 );
	}

	float flexValues[ GLOBAL_STUDIO_FLEX_CONTROL_COUNT ] = { 0 };

	if ( pExpression )
	{
		float *settings = pExpression->GetSettings();
		float *weights = pExpression->GetWeights();

		// Save existing settings from model
		for ( LocalFlexController_t i = LocalFlexController_t(0); i < hdr->numflexcontrollers(); ++i )
		{
			int j = hdr->pFlexcontroller( i )->localToGlobal;
			if ( j == -1 )
				continue;
			flexValues[ i ] = model->GetFlexController( i );
			// Set Value from passed in settings
			model->SetFlexController( i, settings[ j ] * weights[ j ] );
		}
	}

	model->ClearLookTargets( );

	QAngle oldrot, oldLight;
	Vector oldtrans;
	
	VectorCopy( model->m_angles, oldrot );
	VectorCopy( model->m_origin, oldtrans );
	VectorCopy( g_viewerSettings.lightrot, oldLight );

	model->m_angles.Init();
	model->m_origin.Init();
	g_viewerSettings.lightrot.Init();

	g_viewerSettings.lightrot.y = -180;

	bool bSaveGround = g_viewerSettings.showGround;
	g_viewerSettings.showGround = false;

	if ( bZoomInOnFace )
	{
		Vector size;
		VectorSubtract( hdr->hull_max(), hdr->hull_min(), size );

		float eyeheight = hdr->hull_min().z + 0.9 * size.z;
		//	float width = ( size.x + size.y ) / 2.0f;

		model->m_origin.x = size.z * .6f;

		if ( hdr->GetNumAttachments() > 0 )
		{
			for (int i = 0; i < hdr->GetNumAttachments(); i++)
			{
				const mstudioattachment_t &attachment = hdr->pAttachment( i );
				int iBone = hdr->GetAttachmentBone( i );

				if ( Q_stricmp( attachment.pszName(), "eyes" ) )
					continue;

				mstudiobone_t *bone = hdr->pBone( iBone );
				if ( !bone )
					continue;

				matrix3x4_t boneToPose;
				MatrixInvert( bone->poseToBone, boneToPose );

				matrix3x4_t attachmentPoseToLocal;
				ConcatTransforms( boneToPose, attachment.local, attachmentPoseToLocal );

				Vector localSpaceEyePosition;
				VectorITransform( vec3_origin, attachmentPoseToLocal, localSpaceEyePosition );

				// Not sure why this must be negative?
				eyeheight = -localSpaceEyePosition.z + hdr->hull_min().z;
				break;
			}
		}

		KeyValues *seqKeyValues = new KeyValues("");
		if ( seqKeyValues->LoadFromBuffer( model->GetFileName( ), model->GetKeyValueText( sequence ) ) )
		{
			// Do we have a build point section?
			KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer");
			if ( pkvAllFaceposer )
			{
				float flEyeheight = pkvAllFaceposer->GetFloat( "eye_height", -9999.0f );
				if ( flEyeheight != -9999.0f )
				{
					eyeheight = flEyeheight;
				}
			}
		}

		model->m_origin.z += eyeheight;
	}
	else
	{
		Vector mins, maxs;
		model->ExtractBbox(mins, maxs);
		Vector size;
		VectorSubtract( maxs, mins, size );

		float maxdim = size.x;
		if ( size.y > maxdim )
			maxdim = size.y;
		if ( size.z > maxdim )
			maxdim = size.z;

		float midpoint = mins.z + 0.5 * size.z;

		model->m_origin.x = 3 * maxdim;
		model->m_origin.z += midpoint;
	}

	pWnd->SuppressResize( true );

	RECT rcClient;
	HWND wnd = (HWND)pWnd->getHandle();

	WINDOWPLACEMENT wp;

	GetWindowPlacement( wnd, &wp );

	GetClientRect( wnd, &rcClient );

	MoveWindow( wnd, 0, 0, nSnapShotSize + 16, nSnapShotSize + 16, TRUE );

	// Snapshots are taken of the back buffer; 
	// we need to render to the back buffer but not move it to the front
	pWnd->SuppressBufferSwap( true );
	pWnd->redraw();
	pWnd->SuppressBufferSwap( false );

	// make it square, assumes w > h
	char fullpath[ 512 ];
	Q_snprintf( fullpath, sizeof( fullpath ), "%s%s", GetGameDirectory(), pchBitmapFilename );
	pWnd->TakeSnapshotRect( fullpath, 0, 0, nSnapShotSize, nSnapShotSize );

	// Move back to original position
	SetWindowPlacement( wnd, &wp );

	pWnd->SuppressResize( false );

	VectorCopy( oldrot, model->m_angles );
	VectorCopy( oldtrans, model->m_origin );
	VectorCopy( oldLight, g_viewerSettings.lightrot );

	g_viewerSettings.showGround = bSaveGround;

	if ( pExpression )
	{
		// Save existing settings from model
		for ( LocalFlexController_t i = LocalFlexController_t(0); i < hdr->numflexcontrollers(); ++i )
		{
			int j = hdr->pFlexcontroller( i )->localToGlobal;
			if ( j == -1 )
				continue;

			model->SetFlexController( i, flexValues[ i ] );
		}
	}

	model->ClearOverlaysSequences();
	
	if ( bitmap->valid )
	{
		DeleteObject( bitmap->image );
		bitmap->image = 0;
		bitmap->valid = false;
	}

	LoadBitmapFromFile( pchBitmapFilename, *bitmap );
}
Ejemplo n.º 15
0
eglDib::eglDib(const char *filename) : mBMPFileHeader(NULL),mBMPInfo(NULL),mBMPInfoHeader(NULL),
								       mRGBTable(NULL), mRawData(NULL), mNumColors(0)
{
	if(!LoadBitmapFromFile(filename))
		return ;
}
// Create device resources
HRESULT DemoApp::CreateDeviceResources()
{
	HRESULT hr = S_OK;
	if (!m_pRenderTarget)
	{
		RECT rc;
		GetClientRect(m_hwnd, &rc);

		D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);

		// Create a Direct2D render target
		hr = m_pD2DFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(m_hwnd, size),
			&m_pRenderTarget);
		if (SUCCEEDED(hr))
		{
			// Create a black brush
			hr = m_pRenderTarget->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::Black),
				&m_pBlackBrush);
		}
		if (SUCCEEDED(hr))
		{
			ID2D1GradientStopCollection *pGradientStops = NULL;
			static const D2D1_GRADIENT_STOP stops[]=
			{
				{0.f,{0.f,1.f,1.f,0.25f}},
				{1.f,{0.f,0.f,1.f,1.f}}
			};

			hr = m_pRenderTarget->CreateGradientStopCollection(
				stops, ARRAYSIZE(stops),
				&pGradientStops);
			if (SUCCEEDED(hr))
			{
				hr = m_pRenderTarget->CreateLinearGradientBrush(
					D2D1::LinearGradientBrushProperties(
						D2D1::Point2F(100, 0),
						D2D1::Point2F(100, 200)),
					D2D1::BrushProperties(),
					pGradientStops,
					&m_pLinearGradientBrush);
				pGradientStops->Release();
			}
		}

		// Create a bitmap from an application resource
		hr = LoadResourceBitmap(
			m_pRenderTarget,
			m_pWICFactory,
			L"SampleImage",
			L"Image",
			100, 0,
			&m_pBitmap);
		if (SUCCEEDED(hr))
		{
			// Create a bitmap by loading it from a file
			hr = LoadBitmapFromFile(
				m_pRenderTarget,
				m_pWICFactory,
				L".\\sampleImage.jpg",
				100, 0,
				&m_pAnotherBitmap);
		}
		if (SUCCEEDED(hr))
			hr = CreateGridPatternBrush(m_pRenderTarget, &m_pGridPatternBitmapBrush);
	}

	return hr;
}
Ejemplo n.º 17
0
BOOL CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   HDC hDC;
   TEXTMETRIC tm;
   PAINTSTRUCT ps;
   RECT rect;
   COLORREF clrref;
   LPDRAWITEMSTRUCT pDIS;
   HBRUSH hbr;
   int lineHeight;
   HWND hWndList;
   int nItem;
   HANDLE hFile;
   char filename[MAX_PATH];
   char file[MAX_PATH];
   char full_filename[MAX_PATH];
   int length;
   int index;
   HWND hItemWnd;
   BYTE palette_color;
   BYTE red, green, blue;
   float r_scale, g_scale, b_scale;
   CHAR item_name[16];
   CHAR wad_name[16];
   int x,y;
   int width, height;
   int difference, min_difference, min_index;
   DWORD dwSize;
   int mip_index;
   CHAR mip_name[16];
   int value, max_value;
   palette_t *pMipPalette;
   char src_filename[MAX_PATH], dest_filename[MAX_PATH];
   int miplevel, mipstep;
   unsigned char *pLump, *pLump0;
   int mip_width, mip_height;
   int count, xx, yy;
   int testpixel;

   switch (message)
   {
      case WM_INITDIALOG:

         if (!CenterWindow( hWnd ))
            return( FALSE );

         clrref = GetSysColor(COLOR_BTNFACE);
         h_background = CreateSolidBrush(clrref);

         hItemWnd = GetDlgItem(hWnd, IDC_ADD);
         EnableWindow(hItemWnd, FALSE);

         hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
         EnableWindow(hItemWnd, FALSE);

         hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
         EnableWindow(hItemWnd, FALSE);

         g_palette_color = 0;

         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));
         SendDlgItemMessage(hWnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)((LPCSTR)" "));

         hFile = NULL;
         strcpy(filename, szParentPath);
         strcat(filename, "\\logos\\*.bmp");

         // display the .bmp files in the logos folder...
         while ((hFile = FindFile(hFile, file, filename)) != NULL)
         {
            strcpy(full_filename, szParentPath);
            strcat(full_filename, "\\logos\\");
            strcat(full_filename, file);

            if (CheckBitmapFormat(full_filename))
            {
               length = strlen(file);

               file[length-4] = 0;

               SendDlgItemMessage(hWnd, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)file));
            }
         }

         SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);

         strcpy(filename, szParentPath);
         strcat(filename, "\\");
         strcat(filename, g_szMODdir);
         strcat(filename, "\\decals.wad");

         if (!LoadWADFile(filename))
         {
            strcpy(filename, szParentPath);
            strcat(filename, "\\");
            strcat(filename, "valve");
            strcat(filename, "\\decals.wad");

            if (!LoadWADFile(filename))
            {
               MessageBox(hWnd, "Error loading WAD file!", "Error", MB_OK);
               SendMessage(hWnd, WM_COMMAND, IDCLOSE, 0L);

               return FALSE;
            }

            strcpy(g_szMODdir, "valve");

            MessageBox(hWnd, "This MOD uses the decals.wad file\nfrom the Half-Life valve directory", "Warning", MB_OK);
         }

         // display the lumps from the WAD file...
         for (index=0; index < MAX_MIPS; index++)
         {
            if (pMips[index])
            {
               if (strncmp(pMips[index]->name, "{__", 3) == 0)
               {
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[index]->name[3])));
               }

               if (strncmp(pMips[index]->name, "__", 2) == 0)
               {
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[index]->name[2])));
               }
            }
         }


         SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);
 
        break;

      case WM_MEASUREITEM:

         hDC = GetDC( hWnd );
         GetTextMetrics( hDC, &tm );
         ReleaseDC( hWnd, hDC );

         lineHeight = tm.tmExternalLeading +
                      tm.tmInternalLeading + tm.tmHeight;

         ((MEASUREITEMSTRUCT FAR *)(lParam))->itemHeight = lineHeight;

         return TRUE;

      case WM_DRAWITEM:

         pDIS = (LPDRAWITEMSTRUCT) lParam;

         // Draw the focus rectangle for an empty list box or an
         // empty combo box to indicate that the control has the focus

         if ((int)(pDIS->itemID) < 0)
         {
//            if ((pDIS->itemState) & (ODS_FOCUS))
//               DrawFocusRect (pDIS->hDC, &pDIS->rcItem);
            return TRUE;
         }

         if ((pDIS->itemAction == ODA_SELECT) ||
             (pDIS->itemAction == ODA_DRAWENTIRE))
         {
            hbr = NULL;

            palette_color = 0;

            if ((pDIS->itemID >= 1) && (pDIS->itemID <= 8))
            {
               palette_color = pDIS->itemID;

               red   = colors[palette_color-1][0];
               green = colors[palette_color-1][1];
               blue  = colors[palette_color-1][2];

//               hDC = CreateCompatibleDC(pDIS->hDC);
               hbr = CreateSolidBrush(RGB(red,green,blue));

               SelectObject(pDIS->hDC, hbr);
               Rectangle(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top,
                                    pDIS->rcItem.right,  pDIS->rcItem.bottom);
               DeleteObject(hbr);
//               DeleteDC(hDC);
            }

//            if (pDIS->itemState & ODS_FOCUS)
//               DrawFocusRect (pDIS->hDC, &pDIS->rcItem);

//            if (pDIS->itemState & ODS_SELECTED)
//            {
//               DrawFocusRect(pDIS->hDC, &pDIS->rcItem);
//            }
         }
//         else if (pDIS->itemAction == ODA_FOCUS)
//         {
//            DrawFocusRect (pDIS->hDC, &pDIS->rcItem);
//         }

         return TRUE; 

      case WM_PAINT:

         hDC = BeginPaint(hWnd, &ps);

         RedrawClientArea(hWnd, hDC);

         EndPaint(hWnd, &ps);

         return TRUE;

      case WM_COMMAND:

         switch (LOWORD(wParam))
         {
            case IDC_LIST1:
               if (HIWORD(wParam) == LBN_SELCHANGE)
               {
                  index = SendDlgItemMessage(hWnd, IDC_LIST1, LB_GETCURSEL, 0, 0L);

                  SendDlgItemMessage(hWnd, IDC_LIST1, LB_GETTEXT, index, (LPARAM)((LPSTR)filename));

                  strcpy(g_szBitmapName, filename);

                  strcpy(g_szFileName, szParentPath);
                  strcat(g_szFileName, "\\logos\\");
                  strcat(g_szFileName, filename);
                  strcat(g_szFileName, ".bmp");

                  hDC = GetDC(hWnd);

                  if (hBitmap)
                  {
                     if ((pbmi->bmiHeader.biHeight > 128) ||
                         (pbmi->bmiHeader.biWidth > 128))
                     {
                        GetClientRect(hWnd, &rect);
                        InvalidateRect(hWnd, &rect, TRUE);
                     }
                  }

                  LoadBitmapFromFile(hDC, g_szFileName);

                  if ((hBitmap) && (h_background))
                  {
                     rect.left = offset_x;
                     rect.top = offset_y;
                     rect.right = offset_x + size_x;
                     rect.bottom = offset_y + size_y;

                     FillRect(hDC, &rect, h_background);
                  }

                  MakeBitmap(hDC, OriginalPalette, pOriginalData);

                  ReleaseDC(hWnd, hDC);


                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);

                  SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

                  g_palette_color = 0;

                  hItemWnd = GetDlgItem(hWnd, IDC_ADD);
                  EnableWindow(hItemWnd, TRUE);

                  hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
                  EnableWindow(hItemWnd, FALSE);

                  hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
                  EnableWindow(hItemWnd, TRUE);

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_LIST2:
               if (HIWORD(wParam) == LBN_SELCHANGE)
               {
                  index = SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETCURSEL, 0, 0L);

                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETTEXT, index, (LPARAM)((LPSTR)item_name));

                  strcpy(wad_name, "{__");
                  strcat(wad_name, item_name);

                  // find the correct index based on name...

                  index = 0;
                  while (index < MAX_MIPS)
                  {
                     if (pMips[index])
                     {
                        if (strcmp(wad_name, pMips[index]->name) == 0)
                           break;
                     }

                     index++;
                  }

                  if (index == MAX_MIPS)
                  {
                     strcpy(wad_name, "__");
                     strcat(wad_name, item_name);

                     // find the correct index based on name...

                     index = 0;
                     while (index < MAX_MIPS)
                     {
                        if (pMips[index])
                        {
                           if (strcmp(wad_name, pMips[index]->name) == 0)
                              break;
                        }

                        index++;
                     }
                  }

                  if (index == MAX_MIPS)
                  {
                     MessageBox(hWnd, "Error finding mip!", "Error", MB_OK);
                     return TRUE;
                  }

                  hDC = GetDC(hWnd);

                  if (hBitmap)
                  {
                     if ((pbmi->bmiHeader.biHeight > 128) ||
                         (pbmi->bmiHeader.biWidth > 128))
                     {
                        GetClientRect(hWnd, &rect);
                        InvalidateRect(hWnd, &rect, TRUE);
                     }
                  }

                  LoadBitmapFromMip(index);

                  if ((hBitmap) && (h_background))
                  {
                     rect.left = offset_x;
                     rect.top = offset_y;
                     rect.right = offset_x + size_x;
                     rect.bottom = offset_y + size_y;

                     FillRect(hDC, &rect, h_background);
                  }

                  memcpy(Palette, OriginalPalette, (1 << pbmi->bmiHeader.biBitCount) * 4);

                  if ((Palette[255].rgbRed != 0) ||
                      (Palette[255].rgbGreen != 0) ||
                      (Palette[255].rgbBlue != 255))
                  {
                     r_scale = (float)Palette[255].rgbRed / (float)255.0;
                     g_scale = (float)Palette[255].rgbGreen / (float)255.0;
                     b_scale = (float)Palette[255].rgbBlue / (float)255.0;

                     // set palette 255 index back to pure white
                     Palette[255].rgbRed   = 255;
                     Palette[255].rgbGreen = 255;
                     Palette[255].rgbBlue  = 255;

                     for (index = 0; index < (1 << pbmi->bmiHeader.biBitCount); index++)
                     {
                        Palette[index].rgbRed   = (BYTE)((float)Palette[index].rgbRed * r_scale);
                        Palette[index].rgbGreen = (BYTE)((float)Palette[index].rgbGreen * g_scale);
                        Palette[index].rgbBlue  = (BYTE)((float)Palette[index].rgbBlue * b_scale);
                        Palette[index].rgbReserved = 0;
                     }
                  }

                  MakeBitmap(hDC, Palette, pOriginalData);

                  ReleaseDC(hWnd, hDC);

                  SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);

                  SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

                  g_palette_color = 0;

                  hItemWnd = GetDlgItem(hWnd, IDC_ADD);
                  EnableWindow(hItemWnd, FALSE);

                  hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
                  EnableWindow(hItemWnd, TRUE);

                  hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
                  EnableWindow(hItemWnd, FALSE);

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_COMBO1:
               switch(HIWORD(wParam))
               {
                  case CBN_SELCHANGE:
                     hWndList = GetDlgItem(hWnd, IDC_COMBO1);
                     nItem = SendMessage(hWndList, CB_GETCURSEL, 0, 0);

                  if (nItem == 0)
                  {
                     // restore palette to original color...
                     hDC = GetDC(hWnd);
                     MakeBitmap(hDC, OriginalPalette, pOriginalData);
                     ReleaseDC(hWnd, hDC);
                  }
                  else
                  {
                     g_palette_color = nItem;

                     red   = colors[g_palette_color-1][0];
                     green = colors[g_palette_color-1][1];
                     blue  = colors[g_palette_color-1][2];

                     // set the palette color
                     hDC = GetDC(hWnd);

                     memcpy(Palette, OriginalPalette, (1 << pbmi->bmiHeader.biBitCount) * 4);

                     r_scale = (float)red / (float)255.0;
                     g_scale = (float)green / (float)255.0;
                     b_scale = (float)blue / (float)255.0;

                     for (index = 0; index < (1 << pbmi->bmiHeader.biBitCount); index++)
                     {
                        Palette[index].rgbRed   = (BYTE)((float)Palette[index].rgbRed * r_scale);
                        Palette[index].rgbGreen = (BYTE)((float)Palette[index].rgbGreen * g_scale);
                        Palette[index].rgbBlue  = (BYTE)((float)Palette[index].rgbBlue * b_scale);
                        Palette[index].rgbReserved = 0;
                     }

                     MakeBitmap(hDC, Palette, pOriginalData);

                     ReleaseDC(hWnd, hDC);
                  }

                  // Force an update of the screen
                  GetBitmapPosition(hWnd);

                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  InvalidateRect(hWnd, &rect, TRUE);
                  UpdateWindow(hWnd);
               }

               return TRUE;

            case IDC_ADD:

               if (num_mips >= MAX_MIPS)
                  return TRUE;

               changes = TRUE;

               width = pbmi->bmiHeader.biWidth;
               height = pbmi->bmiHeader.biHeight;

               // assume all of the colors are used for mip mapping...
               colors_used = 256;
               for (x=0; x < 256; x++) color_used[x] = 1;

               // write the bitmap data and palette to the lump array...
               index = 0;
               while (pMips[index])
                  index++;

               mip_index = index;

               dwSize = sizeof(miptex_t) + (width * height) +
                        (width * height / 4) + (width * height / 16) +
                        (width * height / 64) + sizeof(palette_t);

               pMips[mip_index] = (miptex_t *)LocalAlloc(LPTR, dwSize);

               pMips[mip_index]->height = pbmi->bmiHeader.biHeight;
               pMips[mip_index]->width = pbmi->bmiHeader.biWidth;
               pMips[mip_index]->offsets[0] = sizeof(miptex_t);
               pMips[mip_index]->offsets[1] = pMips[mip_index]->offsets[0] + width * height;
               pMips[mip_index]->offsets[2] = pMips[mip_index]->offsets[1] + (width * height) / 4;
               pMips[mip_index]->offsets[3] = pMips[mip_index]->offsets[2] + (width * height) / 16;

               pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[0];

               index = height - 1;

               for (y=0; y < height; y++)
               {
                  memcpy(pLump+(width * y), pOriginalData+(width * index), width);
                  index--;
               }

               pMipPalette = (palette_t *)((char *)pMips[mip_index] +
                             pMips[mip_index]->offsets[3] + (width * height / 64));

               pMipPalette->palette_size = 256;

               for (index = 0; index < 256; index++)
               {
                  pMipPalette->palette[index * 3 + 0] = OriginalPalette[index].rgbRed;
                  pMipPalette->palette[index * 3 + 1] = OriginalPalette[index].rgbGreen;
                  pMipPalette->palette[index * 3 + 2] = OriginalPalette[index].rgbBlue;
               }

               pMipPalette->padding = 0;

               memcpy(lbmpalette, pMipPalette->palette, 256 * 3);

               // calculate gamma corrected linear palette
               for (x = 0; x < 256; x++)
               {
                  for (y = 0; y < 3; y++)
                  {
                     float f;
                     f = (float)(lbmpalette[x*3+y] / 255.0);
//                     linearpalette[x][y] = (float)pow(f, 2.2 ); // assume textures are done at 2.2, we want to remap them at 1.0
                     linearpalette[x][y] = (float)pow(f, 1.0);
                  }
               }

               pLump0 = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[0];

               maxdistortion = 0;

               for (miplevel = 1; miplevel < 4; miplevel++)
      	      {
                  int pixTest;
                  d_red = d_green = d_blue = 0;	// no distortion yet

                  pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                  mipstep = 1 << miplevel;
                  pixTest = (int)((float)(mipstep * mipstep) * 0.4);	// 40% of pixels

                  for (y = 0; y < height ; y += mipstep)
                  {
                     for (x = 0 ; x < width ; x += mipstep)
                     {
                        count = 0;

                        for (yy = 0; yy < mipstep; yy++)
                        {
                           for (xx = 0; xx < mipstep; xx++)
                           {
                              testpixel = pLump0[(y+yy)*width + x + xx ];
						
                              // If this isn't a transparent pixel, add it in to the image filter
                              if ( testpixel != 255 )
                              {
                                 pixdata[count] = testpixel;
                                 count++;
                              }
                           }
                        }

                        if ( count <= pixTest )	// Solid pixels account for < 40% of this pixel, make it transparent
                        {
                           *pLump++ = 255;
                        }
                        else
                        {
                           *pLump++ = AveragePixels(count);
                        }
                     }	
                  }
               }


               if (!g_monochrome)
               {
                  // assume none of the colors are used for palette 255 setting...
                  colors_used = 0;

                  for (x=0; x < 256; x++)
                     color_used[x] = 0;

                  for (x=0; x < width; x++)
                  {
                     for (y=0; y < height; y++)
                     {
                        if (!color_used[pOriginalData[x*height + y]])
                        {
                           color_used[pOriginalData[x*height + y]] = 1;
                           colors_used++;
                        }
                     }
                  }

                  // if all colors used and index 255 is NOT pure blue...
                  if ((colors_used == 256) &&
                      ((OriginalPalette[255].rgbRed !=0) ||
                       (OriginalPalette[255].rgbGreen != 0) ||
                       (OriginalPalette[255].rgbBlue != 255)))
                  {
                     // replace index 255 color with closest color...

                     red   = OriginalPalette[255].rgbRed;
                     green = OriginalPalette[255].rgbGreen;
                     blue  = OriginalPalette[255].rgbBlue;

                     min_difference = 256*3;
                     min_index = 0;

                     for (index=0; index < 255; index++)
                     {
                        difference = abs(OriginalPalette[index].rgbRed - red) +
                                     abs(OriginalPalette[index].rgbGreen - green) +
                                     abs(OriginalPalette[index].rgbBlue - blue);

                        if (difference < min_difference)
                        {
                           min_difference = difference;
                           min_index = index;
                        }
                     }

                     for (miplevel = 0; miplevel < 4; miplevel++)
                     {
                        mipstep = 1 << miplevel;
                        pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                        mip_width = width/mipstep;
                        mip_height = height/mipstep;

                        for (x=0; x < mip_width; x++)
                        {
                           for (y=0; y < mip_height; y++)
                           {
                              if (pLump[x*mip_height + y] == 255)
                                 pLump[x*mip_height + y] = min_index;
                           }
                        }
                     }

                     colors_used--;
                     color_used[255] = 0;
                  }

                  if ((colors_used < 256) && (color_used[255]))
                  {
                     // move index 255 to first unused position...

                     index = 0;
                     while (color_used[index])
                        index++;

                     pMipPalette->palette[index * 3 + 0] = OriginalPalette[255].rgbRed;
                     pMipPalette->palette[index * 3 + 1] = OriginalPalette[255].rgbGreen;
                     pMipPalette->palette[index * 3 + 2] = OriginalPalette[255].rgbBlue;

                     for (miplevel = 0; miplevel < 4; miplevel++)
                     {
                        mipstep = 1 << miplevel;
                        pLump = (BYTE *)pMips[mip_index] + pMips[mip_index]->offsets[miplevel];

                        mip_width = width/mipstep;
                        mip_height = height/mipstep;

                        for (x=0; x < mip_width; x++)
                        {
                           for (y=0; y < mip_height; y++)
                           {
                              if (pLump[x*mip_height + y] == 255)
                                 pLump[x*mip_height + y] = index;
                           }
                        }
                     }
                  }

                  pMipPalette->palette[255 * 3 + 0] = 0;
                  pMipPalette->palette[255 * 3 + 1] = 0;
                  pMipPalette->palette[255 * 3 + 2] = 255;
               }

               if (g_palette_color != 0)
               {
                  pMipPalette->palette[255 * 3 + 0] = colors[g_palette_color-1][0];
                  pMipPalette->palette[255 * 3 + 1] = colors[g_palette_color-1][1];
                  pMipPalette->palette[255 * 3 + 2] = colors[g_palette_color-1][2];
               }


               if (strlen(g_szBitmapName) > 9)
                  g_szBitmapName[10] = 0;

               if (g_monochrome)
                  strcpy(mip_name, "__");
               else
                  strcpy(mip_name, "{__");

               strcat(mip_name, g_szBitmapName);

               length = strlen(mip_name);

               max_value = 0;

               // find the highest number for this name...
               for (index = 0; index < num_mips; index++)
               {
                  if (pMips[index])
                  {
                     if (strncmp(pMips[index]->name, mip_name, length) == 0)
                     {
                        sscanf(&(pMips[index]->name[length+1]), "%d", &value);

                        if (value > max_value)
                           max_value = value;
                     }
                  }
               }

               max_value++;

               if (max_value > 99)
               {
                  MessageBox(hWnd, "Too many mips for this file!", "Error", MB_OK);
                  LocalFree(pMips[mip_index]);
                  pMips[mip_index] = NULL;
                  return TRUE;
               }

               sprintf(pMips[mip_index]->name, "%s_%02d", mip_name, max_value);

               if (g_monochrome)
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[mip_index]->name[2])));
               else
                  SendDlgItemMessage(hWnd, IDC_LIST2, LB_ADDSTRING, 0,
                                     (LPARAM)((LPCSTR)&(pMips[mip_index]->name[3])));

               num_mips++;


               return TRUE;

            case IDC_REMOVE:

               changes = TRUE;

               index = SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETCURSEL, 0, 0L);

               SendDlgItemMessage(hWnd, IDC_LIST2, LB_GETTEXT, index, (LPARAM)((LPSTR)item_name));

               SendDlgItemMessage(hWnd, IDC_LIST2, LB_DELETESTRING, index, 0L);

               strcpy(wad_name, "{__");
               strcat(wad_name, item_name);

               // find the correct index based on name...

               index = 0;
               while (index < MAX_MIPS)
               {
                  if (pMips[index])
                  {
                     if (strcmp(wad_name, pMips[index]->name) == 0)
                        break;
                  }

                  index++;
               }

               if (index == MAX_MIPS)
               {
                  strcpy(wad_name, "__");
                  strcat(wad_name, item_name);

                  // find the correct index based on name...

                  index = 0;
                  while (index < MAX_MIPS)
                  {
                     if (pMips[index])
                     {
                        if (strcmp(wad_name, pMips[index]->name) == 0)
                           break;
                     }

                     index++;
                  }
               }

               if (index == MAX_MIPS)
               {
                  MessageBox(hWnd, "Error finding mip!", "Error", MB_OK);
                  return FALSE;
               }

               LocalFree(pMips[index]);

               pMips[index] = NULL;


               hDC = GetDC(hWnd);

               if (hBitmap)
               {
                  if ((pbmi->bmiHeader.biHeight > 128) ||
                      (pbmi->bmiHeader.biWidth > 128))
                  {
                     GetClientRect(hWnd, &rect);
                     InvalidateRect(hWnd, &rect, TRUE);
                  }
               }

               if ((hBitmap) && (h_background))
               {
                  rect.left = offset_x;
                  rect.top = offset_y;
                  rect.right = offset_x + size_x;
                  rect.bottom = offset_y + size_y;

                  FillRect(hDC, &rect, h_background);
                  InvalidateRect(hWnd, &rect, TRUE);
               }

               ReleaseDC(hWnd, hDC);

               if (hBitmap)
                  DeleteObject(hBitmap);

               UpdateWindow(hWnd);


               SendDlgItemMessage(hWnd, IDC_LIST1, LB_SETCURSEL, -1, 0L);
               SendDlgItemMessage(hWnd, IDC_LIST2, LB_SETCURSEL, -1, 0L);
               SendDlgItemMessage(hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0L);

               g_palette_color = 0;

               hItemWnd = GetDlgItem(hWnd, IDC_ADD);
               EnableWindow(hItemWnd, FALSE);

               hItemWnd = GetDlgItem(hWnd, IDC_REMOVE);
               EnableWindow(hItemWnd, FALSE);

               hItemWnd = GetDlgItem(hWnd, IDC_COMBO1);
               EnableWindow(hItemWnd, FALSE);

               return TRUE;

            case IDCLOSE:

               if (changes)
               {
                  if (MessageBox(hWnd, "Do you wish to save your changes?", "Warning", MB_YESNO) == IDYES)
                  {
                     // check if backup file is needed

                     strcpy(src_filename, szParentPath);
                     strcat(src_filename, "\\");
                     strcat(src_filename, g_szMODdir);
                     strcat(src_filename, "\\decals.wad");

                     strcpy(dest_filename, szParentPath);
                     strcat(dest_filename, "\\");
                     strcat(dest_filename, g_szMODdir);
                     strcat(dest_filename, "\\decals_old.wad");

                     if (CopyFile(src_filename, dest_filename, TRUE))
                        MessageBox(hWnd, "A backup copy of decals.wad was\ncreated called decals_old.wad", "Warning", MB_OK);

                     if (!WriteWADFile(src_filename))
                        MessageBox(hWnd, "An error occured writing decals.wad", "Error", MB_OK);
                  }
               }

               for (index = 0; index < MAX_MIPS; index++)
               {
                  if (pMips[index])
                     LocalFree(pMips[index]);
               }

               if (pbmi)
                  LocalFree(pbmi);

               if (pOriginalData)
                  LocalFree(pOriginalData);

               if (hBitmap)
                  DeleteObject(hBitmap);

               if (hPalette)
                  DeleteObject(hPalette);

               if (h_background)
                  DeleteObject(h_background);

               PostQuitMessage(0);
               return TRUE;
         }

         break;

      case WM_CLOSE:

         SendMessage(hWnd, WM_COMMAND, IDCLOSE, 0L);

         break;
   }

   return FALSE;
}
Ejemplo n.º 18
0
HRESULT DemoApp::CreateDeviceResources()
{
    HRESULT hr = S_OK;

    if (!m_pRT)
    {
        RECT rc;
        GetClientRect(m_hwnd, &rc);

        D2D1_SIZE_U size = D2D1::SizeU(
            (rc.right - rc.left),
            (rc.bottom - rc.top)
            );

        // Create a Direct2D render target
        hr = m_pD2DFactory->CreateHwndRenderTarget(
            D2D1::RenderTargetProperties(),
            D2D1::HwndRenderTargetProperties(m_hwnd, size),
            &m_pRT
            );



	  if (SUCCEEDED(hr))
      {
            // Create a bitmap by loading it from a file.
			hr = LoadBitmapFromFile(m_pRT, m_pWICFactory, L".\\eggFactory.png", 300, 179, &m_pBitmap);   //m_pBitmap
      }
		

	  if (SUCCEEDED(hr))
      {
                  // Create a bitmap by loading it from a file.
				hr = LoadBitmapFromFile(m_pRT, m_pWICFactory, L".\\minion.png", 150, 150, &m_pMinionBitmap); 
      }

	  if (SUCCEEDED(hr))
      {
                  // Create a bitmap by loading it from a file.
				hr = LoadBitmapFromFile(m_pRT, m_pWICFactory, L".\\joody.png", 150, 150, &m_pJoodyBitmap); 
      }


	  if (SUCCEEDED(hr))
      {
                  // Create a bitmap by loading it from a file.
				hr = LoadBitmapFromFile(m_pRT, m_pWICFactory, L".\\elsa.png", 150, 150, &m_pElsaBitmap); 
      }

	  if (SUCCEEDED(hr))
      {
                  // Create a bitmap by loading it from a file.
				hr = LoadBitmapFromFile(m_pRT, m_pWICFactory, L".\\max.png", 150, 150, &m_pMaxBitmap); 
      }

	  if( SUCCEEDED(hr))
	  {

		  hr = LoadBitmapFromFile(m_pRT,m_pWICFactory, L".\\blackHole.png",200,150,&m_pBlackHoleBitmap); //640 ,360
		  hr = m_pRT->CreateBitmapBrush(m_pBlackHoleBitmap,&m_pBlackHoleBrush);
	  }


			


	     if (SUCCEEDED(hr))
            {
                D2D1_BITMAP_BRUSH_PROPERTIES propertiesXClampYClamp = D2D1::BitmapBrushProperties(
                    D2D1_EXTEND_MODE_CLAMP, D2D1_EXTEND_MODE_CLAMP, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR);

				 hr = m_pRT->CreateBitmapBrush(m_pMinionBitmap, propertiesXClampYClamp, &m_pMinionBrush);
				 hr = m_pRT->CreateBitmapBrush(m_pJoodyBitmap, propertiesXClampYClamp, &m_pJoodyBrush);
				 hr = m_pRT->CreateBitmapBrush(m_pElsaBitmap, propertiesXClampYClamp, &m_pElsaBrush);
				 hr = m_pRT->CreateBitmapBrush(m_pMaxBitmap, propertiesXClampYClamp, &m_pMaxBrush);
				 //hr = m_pRT->CreateBitmapBrush(m_pBlackHoleBitmap, propertiesXClampYClamp, &m_pBlackHoleBrush);
		 }

				if (SUCCEEDED(hr))
				{
						ID2D1GradientStopCollection *pGradientStops = NULL;

						static const D2D1_GRADIENT_STOP gradientStops[] =
						{
							{   0.f,  D2D1::ColorF(D2D1::ColorF::Black, 1.0f)  },
							{   1.f,  D2D1::ColorF(D2D1::ColorF::White, 0.0f)  },
						};

						hr = m_pRT->CreateGradientStopCollection(gradientStops, 2, &pGradientStops);

						if (SUCCEEDED(hr))
						{
							hr = m_pRT->CreateRadialGradientBrush(
								D2D1::RadialGradientBrushProperties(D2D1::Point2F(75, 75), D2D1::Point2F(0, 0), 75, 75),
								pGradientStops, &m_pRadialGradientBrush);
						}

						if (SUCCEEDED(hr))
						{
							hr = m_pRT->CreateLinearGradientBrush(
								D2D1::LinearGradientBrushProperties(D2D1::Point2F(0, 0), D2D1::Point2F(150, 150)),
								pGradientStops, &m_pLinearGradientBrush);
						}

				}







        if (SUCCEEDED(hr))
        {
            hr = m_pRT->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::Black),
                &m_pBrush
                );
        }
        if (SUCCEEDED(hr))
        {
            hr = m_pRT->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::Black),
                &m_pBlackBrush
                );
        }

		   if (SUCCEEDED(hr))
        {
            hr = m_pRT->CreateSolidColorBrush(
				D2D1::ColorF(D2D1::ColorF::Gold),
                &m_pRedBrush
                );
        }
    }

	
	

	  


    return hr;
}
Ejemplo n.º 19
0
VOID CreateD2DResource(HWND hWnd)
{
	// This function was called in the DrawRectangle function which in turn called to response the
	// WM_PAINT Message, to avoid creating resource every time, we test the pointer to pRenderTarget
	// If the resource already create, skip the function
	if (!pRenderTarget)
	{
		HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create D2D factory failed!", "Error", 0) ;
			return ;
		}

		// Create WIC factory
		hr = CoCreateInstance(
			CLSID_WICImagingFactory1,
			NULL,
			CLSCTX_INPROC_SERVER,
			IID_IWICImagingFactory,
			reinterpret_cast<void **>(&pWICFactory)
			) ;

		// Obtain the size of the drawing area
		GetClientRect(hWnd, &rc) ;

		// Create a Direct2D render target
		hr = pD2DFactory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			D2D1::HwndRenderTargetProperties(
			hWnd, 
			D2D1::SizeU(rc.right - rc.left,rc.bottom - rc.top)
			), 
			&pRenderTarget
			) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create render target failed!", "Error", 0) ;
			return ;
		}

		// Create a black brush
		hr = pRenderTarget->CreateSolidColorBrush(
			D2D1::ColorF(D2D1::ColorF::Black),
			&pBlackBrush
			) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create black brush failed!", "Error", 0) ;
			return ;
		}

		// Create a red brush
		hr = pRenderTarget->CreateSolidColorBrush(
			D2D1::ColorF(D2D1::ColorF::Red),
			&pRedBrush
			) ;
		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create red brush failed!", "Error", 0) ;
			return ;
		}

		hr = LoadBitmapFromFile(
			pRenderTarget,
			pWICFactory,
			L"sampleImage.jpg",
			0,
			0,
			&pBitmap
			) ;

		if (FAILED(hr))
		{
			MessageBox(hWnd, "Create bitmap failed!", "Error", 0) ;
			return ;
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CChoreoEventWidget::LoadImages( void )
{
	for ( int i = 0; i < FP_NUM_BITMAPS; i++ )
	{
		m_Bitmaps[ i ].valid = false;
	}

	m_ResumeConditionBitmap.valid = false;

	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_expression.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::EXPRESSION ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_lookat.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::LOOKAT ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_moveto.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::MOVETO ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_speak.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::SPEAK ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_gesture.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::GESTURE ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_face.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::FACE ] );

	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_firetrigger.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::FIRETRIGGER ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_sequence.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::SEQUENCE ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_flexanimation.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::FLEXANIMATION ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_subscene.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::SUBSCENE ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_loop.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::LOOP ] );

	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/pause.bmp", GetGameDirectory() ), m_ResumeConditionBitmap );

	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_interrupt.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::INTERRUPT ] );
	LoadBitmapFromFile( va( "%s/gfx/hlfaceposer/ev_stoppoint.bmp", GetGameDirectory() ), m_Bitmaps[ CChoreoEvent::STOPPOINT ] );
}
Ejemplo n.º 21
0
static int DialogProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
	switch(message) {
	case MSG_INITDIALOG:
		{
			tipLabelData_t* tipLabelData;

			tipLabelData = (tipLabelData_t*)lParam;
			if(!tipLabelData) {
				db_error("invalid tipLabelData\n");
				return -1;
			}
			SetWindowAdditionalData(hDlg, (DWORD)tipLabelData);

			if(tipLabelData->pLogFont) {
				SetWindowFont(hDlg, tipLabelData->pLogFont);
			}
			if(tipLabelData->full_screen == 1){
				SetWindowBkColor(hDlg,FULL_BLACK);			
			}else{
				SetWindowBkColor(hDlg, tipLabelData->bgc_widget);			
			}
			if(tipLabelData->full_screen == 1){
				SetWindowElementAttr(GetDlgItem(hDlg, IDC_TITLE), WE_FGC_WINDOW, PIXEL2DWORD(HDC_SCREEN, FULL_BLACK) );
				SetWindowElementAttr(GetDlgItem(hDlg, IDC_TEXT), WE_FGC_WINDOW,  PIXEL2DWORD(HDC_SCREEN, FULL_BLACK) );
			}else{
				SetWindowElementAttr(GetDlgItem(hDlg, IDC_TITLE), WE_FGC_WINDOW, PIXEL2DWORD(HDC_SCREEN, tipLabelData->fgc_widget) );
				SetWindowElementAttr(GetDlgItem(hDlg, IDC_TEXT), WE_FGC_WINDOW,  PIXEL2DWORD(HDC_SCREEN, tipLabelData->fgc_widget) );
			}		
			SetTimerEx(hDlg, TIMEOUT_TIMER, tipLabelData->timeoutMs / 10, timerCallback);
		}
		break;
	case MSG_PAINT:
		{
			RECT rect;
			HDC hdc; 
			tipLabelData_t* tipLabelData;

			hdc = BeginPaint(hDlg);

			tipLabelData = (tipLabelData_t*)GetWindowAdditionalData(hDlg);
			GetClientRect(GetDlgItem(hDlg, IDC_TITLE), &rect);
			if(tipLabelData->full_screen == 1){
				SetPenColor(hdc, FULL_BLACK);
			}else{
				SetPenColor(hdc, tipLabelData->linec_title );	
			}
			Line2(hdc, 0, RECTH(rect) + 2, RECTW(rect), RECTH(rect) + 2);
			#if 0
			char *filepath=(char *)"/etc/res/others/wifi.png";
			LoadBitmapFromFile(HDC_SCREEN, &tipLabelData->bitImage, filepath);
			FillBoxWithBitmap(hdc,0,0,320,240,&tipLabelData->bitImage);		
			#endif
			//ShowWindow(hDlg,SW_SHOWNORMAL);
			EndPaint(hDlg, hdc);
		}
		break;
	case MSG_FONTCHANGED:
		{
			PLOGFONT pLogFont;		
			pLogFont = GetWindowFont(hDlg);
			if(pLogFont) {
				SetWindowFont(GetDlgItem(hDlg, IDC_TITLE), pLogFont);
				SetWindowFont(GetDlgItem(hDlg, IDC_TEXT), pLogFont);
			}
		}
		break;
	case MSG_KEYUP:
		{	
			switch(wParam) {
			case CDR_KEY_RIGHT:
				EndDialog(hDlg, 0);
				break;
			case CDR_KEY_LEFT:
			case CDR_KEY_OK:
			case CDR_KEY_MODE:
				break;
			}			
		}
		break;
	case MSG_KEYDOWN:
		{	
		
			//EndDialog(hDlg, 0);
		}
		break;
	case MSG_CLOSE_TIP_LABEL:	
		tipLabelData_t* tipLabelData;

		tipLabelData = (tipLabelData_t*)GetWindowAdditionalData(hDlg);
		db_info("MSG_CLOSE_LOWPOWER_DIALOG\n");
		if(IsTimerInstalled(hDlg, ONE_SHOT_TIMER) == TRUE) {
			KillTimer(hDlg, ONE_SHOT_TIMER);
		}
		if(IsTimerInstalled(hDlg, TIMEOUT_TIMER) == TRUE) {
			KillTimer(hDlg, TIMEOUT_TIMER);
		}
		if (tipLabelData->bitImage.bmBits != NULL){
			UnloadBitmap(&tipLabelData->bitImage);
		}
		EndDialog(hDlg, 0);
		break;
	}
	return DefaultDialogProc(hDlg, message, wParam, lParam);
}
Ejemplo n.º 22
0
HRESULT Game::CreateGraphics(HWND hWnd)
{
	// Initialize the Direct2D Factory.
	HRESULT hr;
	hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the Direct2D Factory."),
			_T("Direct2D Error"), MB_OK | MB_ICONERROR);
		return hr;
	}


	// Get the dimensions of the client.
	RECT rc;
	GetClientRect(hWnd, &rc);

	// Initialize a Direct2D Size Structure.
	D2D1_SIZE_U size = D2D1::SizeU(rc.right, rc.bottom);


	// Create the Direct2D Render Target.
	hr = pD2DFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(hWnd, size), &pRT);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the Direct2D Render Target."),
			_T("Direct2D Error"), MB_OK | MB_ICONERROR);
		return hr;
	}
	pRT->SetDpi(96.0f, 96.0f);


	// Create the Direct2D Solid Color Brush.
	hr = pRT->CreateSolidColorBrush(D2D1::ColorF(0x0), &pBrush);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the Direct2D Solid Color Brush."),
			_T("Direct2D Error"), MB_OK | MB_ICONERROR);
		return hr;
	}


	// Initialize the DirectWrite Factory.
	hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
		(IUnknown**)&pDWFactory);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the DirectWrite Factory."),
			_T("DirectWrite Error"), MB_OK | MB_ICONERROR);
		return hr;
	}


	// Create the DirectWrite Text Format.
	hr = pDWFactory->CreateTextFormat(_T("Veranda"), NULL,
		DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
		24, _T(""), &pTF);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the DirectWrite Text Format."),
			_T("DirectWrite Error"), MB_OK | MB_ICONERROR);
		return hr;
	}
	

	// Create WIC Interface
	hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pWICFactory));
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the WIC Interface!"),
			_T("DirectWrite Error"), MB_OK | MB_ICONERROR);
		return hr;
	}

	// Load Ninja Sprite
	hr = LoadBitmapFromFile(L"\Images\\ninjasprite.png", &black.sprite);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load ninjasprite.png"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}

	// Load Grey Ninja Sprite
	hr = LoadBitmapFromFile(L"Images\\greyninjasprite.png", &grey.sprite);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load greyninjasprite.png"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}

	// Load Floor Textures
	hr = LoadBitmapFromFile(L"Images\\stonefloor.jpg", &floor1);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load stonefloor.jpg"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}
	hr = LoadBitmapFromFile(L"Images\\stonefloor.jpg", &floor2);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load stonefloor.jpg"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}
	hr = LoadBitmapFromFile(L"Images\\stonefloor.jpg", &floor3);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load stonefloor.jpg"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}

	//Load Menu Panel
	hr = LoadBitmapFromFile(L"Images\\BlankPanel.png", &menupanel);
	if (FAILED(hr))
	{
		MessageBox(HWND_DESKTOP, _T("ERROR: Failed to load BlankPanel.png"),
			_T("WIC Error"), MB_OK | MB_ICONERROR);
		return hr;
	}
	return S_OK; // Success!
}