~ubuntu-branches/ubuntu/hoary/devil/hoary

« back to all changes in this revision

Viewing changes to examples/WindowsTest/WindowsTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2005-01-03 19:57:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050103195742-4ipkplcwygu3irv0
Tags: upstream-1.6.7
ImportĀ upstreamĀ versionĀ 1.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//--------------------------------------------------------------------------------
 
2
//
 
3
// ImageLib Windows (GDI) Test Source
 
4
// Copyright (C) 2000-2002 by Denton Woods
 
5
// Last modified: 05/29/2002 <--Y2K Compliant! =]
 
6
//
 
7
// Filename: testil/windowstest/windowstest.c
 
8
//
 
9
// Description: Full GDI test application for DevIL.
 
10
//
 
11
// Note:  This requires FluidStudio's Colour Picker library to compile
 
12
//                      properly (available at http://www.fluidstudios.com/publications.html).
 
13
//
 
14
//--------------------------------------------------------------------------------
 
15
 
 
16
#ifdef  _DEBUG
 
17
#define IL_DEBUG
 
18
#endif//_DEBUG
 
19
 
 
20
#include <windows.h>
 
21
#include <IL/il.h>
 
22
#include <IL/ilu.h>
 
23
#include <IL/ilut.h>
 
24
//#include <sdl.h>
 
25
#include "resource.h"
 
26
 
 
27
//#pragma comment(lib, "sdl.lib")
 
28
//#pragma comment(lib, "sdlmain.lib")
 
29
#pragma comment(lib, "colorpicker.lib")
 
30
 
 
31
 
 
32
// Evil globals!
 
33
HINSTANCE hInstance;
 
34
HBITMAP hBitmap;
 
35
BITMAPINFOHEADER BmpInfo;
 
36
HDC hDC = 0, hMemDC = 0;
 
37
HWND HWnd;
 
38
HBRUSH BackBrush;
 
39
 
 
40
#define BORDER_W        8
 
41
#define MENU_H          54
 
42
#define MIN_W           205  // Accomodate the menu bar.
 
43
#define MAX_W           400
 
44
#define MAX_H           400
 
45
#define TITLE           "DevIL Windows Test"
 
46
ILuint  NumUndosAllowed = 4, UndoSize = 0;
 
47
ILuint  Undos[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
48
ILuint  Width, Height, Depth;  // Main image
 
49
char    CurFileName[2048];
 
50
 
 
51
ILint   XOff, YOff;
 
52
 
 
53
ILdouble last_elapsed, cur_elapsed, elapsed;
 
54
 
 
55
ILuint  FilterType;
 
56
ILuint  FilterParamInt;
 
57
ILfloat FilterParamFloat;
 
58
char    FilterEditString[255];
 
59
 
 
60
char    NewTitle[512];
 
61
 
 
62
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
 
63
BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
 
64
BOOL APIENTRY PropertiesDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
 
65
BOOL APIENTRY FilterDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
 
66
BOOL APIENTRY ResizeDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
 
67
BOOL APIENTRY BatchDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
 
68
void BatchConv(char *Directory, char *ExtList, char *ConvExt, bool Recurse);
 
69
void GenFilterString(char *Out, char **Strings);
 
70
void ResizeWin(void);
 
71
void CreateGDI(void);
 
72
bool IsOpenable(char *FileName);
 
73
 
 
74
extern "C"
 
75
// Colour picker export
 
76
__declspec( dllexport ) bool WINAPI FSColorPickerDoModal(unsigned int * currentColor, unsigned int * originalColor, const int initialExpansionState);
 
77
 
 
78
 
 
79
 
 
80
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 
81
{
 
82
        MSG                     msg;
 
83
        WNDCLASSEX      wcex;
 
84
        HACCEL          hAccelTable;
 
85
 
 
86
        hInstance = hInst;
 
87
 
 
88
        BackBrush = CreateSolidBrush(RGB(128,128,128));
 
89
 
 
90
        wcex.cbSize                     = sizeof(WNDCLASSEX);
 
91
        wcex.style                      = CS_HREDRAW | CS_VREDRAW;
 
92
        wcex.lpfnWndProc        = (WNDPROC)WndProc;
 
93
        wcex.cbClsExtra         = 0;
 
94
        wcex.cbWndExtra         = 0;
 
95
        wcex.hInstance          = hInstance;
 
96
        wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
 
97
        wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
 
98
        wcex.hbrBackground      = BackBrush;
 
99
        wcex.lpszMenuName       = (LPCSTR)IDR_MENU1;
 
100
        wcex.lpszClassName      = TITLE;
 
101
        wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
 
102
 
 
103
        RegisterClassEx(&wcex);
 
104
 
 
105
        HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
 
106
                                                50, 50, 400, 300, NULL, NULL, hInstance, NULL);
 
107
        if (HWnd == NULL)
 
108
                return FALSE;
 
109
 
 
110
        //if (SDL_Init(SDL_INIT_TIMER) < 0)
 
111
        //      return FALSE;
 
112
        //atexit(SDL_Quit);
 
113
 
 
114
        // Display the window
 
115
        ShowWindow(HWnd, nCmdShow);
 
116
        UpdateWindow(HWnd);
 
117
 
 
118
        // Initialize DevIL
 
119
        ilInit();
 
120
        iluInit();
 
121
        ilutRenderer(ILUT_WIN32);
 
122
 
 
123
        // Is there a file to load from the command-line?
 
124
        if (__argc > 1) {
 
125
                ilGenImages(1, Undos);
 
126
                ilBindImage(Undos[0]);
 
127
                if (ilLoadImage(__argv[1])) {
 
128
                        //ilConvertImage(IL_BGRA);
 
129
                        ilutRenderer(ILUT_WIN32);
 
130
                        ResizeWin();
 
131
                        CreateGDI();
 
132
                        sprintf(NewTitle, "%s - %s", TITLE, __argv[1]);
 
133
                        SetWindowText(HWnd, NewTitle);
 
134
                }
 
135
        }
 
136
 
 
137
        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);
 
138
 
 
139
        while (GetMessage(&msg, NULL, 0, 0)) {
 
140
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
 
141
                        TranslateMessage(&msg);
 
142
                        DispatchMessage(&msg);
 
143
                }
 
144
        }
 
145
 
 
146
        return (int)msg.wParam;
 
147
}
 
148
 
 
149
 
 
150
void CreateGDI()
 
151
{
 
152
        ILuint CopyName, CurName, CurImg, CurMip;
 
153
 
 
154
        hDC = GetDC(HWnd);
 
155
        hMemDC = CreateCompatibleDC(hDC);
 
156
        CurName = ilGetInteger(IL_CUR_IMAGE);
 
157
        CurImg = ilGetInteger(IL_ACTIVE_IMAGE);
 
158
        CurMip = ilGetInteger(IL_ACTIVE_MIPMAP);
 
159
        CopyName = ilCloneCurImage();
 
160
        ilBindImage(CopyName);
 
161
        ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
 
162
        hBitmap = ilutConvertToHBitmap(hDC);
 
163
        ilutGetBmpInfo((BITMAPINFO*)&BmpInfo);
 
164
        DeleteObject(SelectObject(hMemDC, hBitmap));
 
165
        ilBindImage(CurName);
 
166
        if (CurImg)
 
167
                ilActiveImage(CurImg);
 
168
        if (CurMip)
 
169
                ilActiveMipmap(CurMip);
 
170
        ilDeleteImages(1, &CopyName);
 
171
 
 
172
        return;
 
173
}
 
174
 
 
175
 
 
176
void DestroyGDI()
 
177
{
 
178
        if (hMemDC) {
 
179
                DeleteObject(hBitmap);
 
180
                DeleteDC(hMemDC);
 
181
        }
 
182
        if (hDC) {
 
183
                ReleaseDC(HWnd, hDC);
 
184
        }
 
185
        hBitmap = NULL;
 
186
        hMemDC = NULL;
 
187
        hDC = NULL;
 
188
 
 
189
        return;
 
190
}
 
191
 
 
192
 
 
193
void ResizeWin()
 
194
{
 
195
        static RECT Rect1, Rect2;
 
196
        static ILint NewW, NewH;
 
197
 
 
198
        SystemParametersInfo(SPI_GETWORKAREA, 0, &Rect1, 0);
 
199
 
 
200
        GetWindowRect(HWnd, &Rect2);
 
201
 
 
202
        Width = ilGetInteger(IL_IMAGE_WIDTH);
 
203
        Height = ilGetInteger(IL_IMAGE_HEIGHT);
 
204
        Depth = ilGetInteger(IL_IMAGE_DEPTH);
 
205
 
 
206
        NewW = Width < MIN_W ? MIN_W : Width + BORDER_W;
 
207
        if (NewW + Rect2.left > Rect1.right)
 
208
                NewW = Rect1.right - Rect2.left;
 
209
        NewH = Height + MENU_H;
 
210
        if (NewH + Rect2.top > Rect1.bottom)
 
211
                NewH = Rect1.bottom - Rect2.top;
 
212
 
 
213
        SetWindowPos(HWnd, HWND_TOP, Rect2.left, Rect2.top, NewW, NewH, SWP_SHOWWINDOW);
 
214
        InvalidateRect(HWnd, NULL, FALSE);
 
215
 
 
216
        return;
 
217
}
 
218
 
 
219
 
 
220
// Window procedure, handles all messages for this program
 
221
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
222
{
 
223
        static HMENU            hMenu;
 
224
        static ILuint           Colours;
 
225
        static RECT                     Rect;
 
226
        static PAINTSTRUCT      ps;
 
227
    static HDROP                hDrop;
 
228
 
 
229
        static char OpenFileName[2048];
 
230
        static char OpenFilter[2048];
 
231
        static char SaveFileName[2048];
 
232
        static char SaveFilter[2048];
 
233
        static char *OFilter[] = {
 
234
                "All Files (*.*)", "*.*",
 
235
                "Alias|Wavefront Files (*.pix)", "*.pix",
 
236
                "Cut Files (*.cut)", "*.cut",
 
237
                "Dcx Files (*.dcx)", "*.dcx",
 
238
                "Graphics Interchange Format (*.gif)", "*.gif",
 
239
                "Half-Life Model Files (*.mdl)", "*.mdl",
 
240
                "Homeworld Image Files (*.lif)", "*.lif",
 
241
                "Image Files (All Supported Types)", "*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx;*.xpm;*.psp;*.psd;*.pix;*.pxr;*.cut;*.dcx",
 
242
                "Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
 
243
                "Kodak Photo CD Files (*.pcd)", "*.pcd",
 
244
                "Microsoft Bitmap Files (*.bmp)", "*.bmp",
 
245
                "Microsoft DirectDraw Surface (*.dds)", "*.dds",
 
246
                "Microsoft Icon Files (*.ico, *.cur)", "*.ico, *.cur",
 
247
                "Multiple Network Graphics Files (*.mng)", "*.mng",
 
248
                "Paint Shop Pro Files (*.psp)", "*.psp",
 
249
                "PhotoShop Files (*.psd)", "*.psd",
 
250
                "Pic Files (*.pic)", "*.pic",
 
251
                "Pixar Files (*.pix)", "*.pix",
 
252
                "Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", "*.pbm;*.pgm;*.pnm;*.ppm",
 
253
                "Portable Network Graphics Files (*.png)", "*.png",
 
254
                "Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
 
255
                "Targa Files (*.tga, *.vda, *.icb, *.vst)", "*.tga;*.vda;*.icb;*.vst",
 
256
                "Tiff Files (*.tif)", "*.tif;*.tiff",
 
257
                "Quake Wal Files (*.wal)", "*.wal",
 
258
                "X PixelMap (*.xpm)", "*.xpm",
 
259
                "ZSoft Pcx Files (*.pcx)", "*.pcx",
 
260
                "\0\0"
 
261
        };
 
262
        static char *SFilter[] = {
 
263
                "All Files (*.*)", "*.*",
 
264
                "C-Style Header (*.h)", "*.h",
 
265
                "Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
 
266
                "Microsoft Bitmap Files (*.bmp)", "*.bmp",
 
267
                "Microsoft DirectDraw Surface (*.dds)", "*.dds",
 
268
                "PhotoShop Files (*.psd)", "*.psd",
 
269
                "Portable AnyMap Files (*.pbm, *.pgm, *.ppm)", "*.pbm;*.pgm;*.ppm",
 
270
                "Portable Network Graphics Files (*.png)", "*.png",
 
271
                "Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
 
272
                "Targa Files (*.tga)", "*.tga",
 
273
                "Tiff Files (*.tif)", "*.tif",
 
274
                "ZSoft Pcx Files (*.pcx)", "*.pcx",
 
275
                "\0\0"
 
276
        };
 
277
 
 
278
        static OPENFILENAME Ofn = {
 
279
                sizeof(OPENFILENAME),
 
280
                hWnd,
 
281
                NULL,
 
282
                OpenFilter,
 
283
                NULL,
 
284
                0,
 
285
                0,
 
286
                OpenFileName,
 
287
                2048,
 
288
                NULL,
 
289
                0,
 
290
                NULL,
 
291
                NULL,
 
292
                OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
 
293
                0,
 
294
                0,
 
295
                NULL,
 
296
                NULL,
 
297
                NULL,
 
298
                NULL
 
299
        };
 
300
 
 
301
        POINT  CurMouse;
 
302
        static POINT            PrevMouse;
 
303
        static ILboolean        MouseDown = IL_FALSE;
 
304
 
 
305
        static RECT                     WinSize;
 
306
 
 
307
        unsigned int            currentColor = 0x80000000;
 
308
        unsigned int            originalColor = 0x80000000;
 
309
        bool                            userClickedOK;
 
310
        ILclampf                        Red, Green, Blue;
 
311
        ILubyte                         *AlphaChannel;
 
312
        ILenum                          Origin;
 
313
 
 
314
        switch (message)
 
315
        {
 
316
                case WM_CREATE:
 
317
                        GenFilterString(OpenFilter, OFilter);
 
318
                        GenFilterString(SaveFilter, SFilter);
 
319
 
 
320
                        hDC = GetDC(hWnd);
 
321
                        DragAcceptFiles(hWnd, TRUE);
 
322
 
 
323
                        ReleaseDC(hWnd, hDC);
 
324
                        break;
 
325
 
 
326
                case WM_CLOSE:
 
327
                        DestroyGDI();
 
328
                        DestroyWindow(hWnd);
 
329
                        UnregisterClass(TITLE, hInstance);
 
330
                        break;
 
331
 
 
332
                case WM_DESTROY:
 
333
                        PostQuitMessage(0);
 
334
                        break;
 
335
 
 
336
                case WM_PAINT:
 
337
                        GetWindowRect(HWnd, &WinSize);  // Shouldn't be here!
 
338
                        hDC = BeginPaint(hWnd, &ps);
 
339
                        //StretchBlt(hDC, 0, 0, WinSize.right - WinSize.left,
 
340
                        //      WinSize.bottom - WinSize.top, BackHDC, 0, 0, 1, 1, SRCCOPY);
 
341
                        WinSize.right -= WinSize.left;
 
342
                        WinSize.bottom -= WinSize.top;
 
343
                        WinSize.top = 0;
 
344
                        WinSize.left = 0;
 
345
                        FillRect(hDC, &WinSize, BackBrush);
 
346
 
 
347
            BitBlt(hDC, XOff, YOff, (WORD)BmpInfo.biWidth, (WORD)BmpInfo.biHeight, 
 
348
                                  hMemDC, 0, 0, SRCCOPY);
 
349
                        EndPaint(hWnd, &ps);
 
350
                        ValidateRect(hWnd, NULL);
 
351
                        break;
 
352
 
 
353
                case WM_KEYDOWN:
 
354
                        if (wParam == VK_ESCAPE)
 
355
                                PostQuitMessage(0);
 
356
 
 
357
                        InvalidateRect(hWnd, NULL, FALSE);
 
358
                        break;
 
359
 
 
360
                // Moves the "viewport"
 
361
                case WM_MOUSEMOVE:
 
362
                        if (!MouseDown)
 
363
                                break;
 
364
                        GetCursorPos(&CurMouse);
 
365
 
 
366
                        XOff += CurMouse.x - PrevMouse.x;
 
367
                        YOff += CurMouse.y - PrevMouse.y;
 
368
 
 
369
                        PrevMouse.x = CurMouse.x;
 
370
                        PrevMouse.y = CurMouse.y;
 
371
                        InvalidateRect(hWnd, NULL, FALSE);
 
372
                        break;
 
373
 
 
374
                case WM_LBUTTONDOWN:
 
375
                        MouseDown = IL_TRUE;
 
376
                        GetCursorPos(&PrevMouse);
 
377
                        break;
 
378
 
 
379
                case WM_LBUTTONUP:
 
380
                        MouseDown = IL_FALSE;
 
381
                        break;
 
382
 
 
383
                case WM_DROPFILES:
 
384
                        hDrop = (HDROP)wParam;
 
385
                        DragQueryFile(hDrop, 0, OpenFileName, 512);
 
386
 
 
387
                        DestroyGDI();
 
388
                        ilDeleteImages(UndoSize, Undos);
 
389
                        UndoSize = 0;
 
390
 
 
391
                        ilGenImages(1, Undos);
 
392
                        ilBindImage(Undos[0]);
 
393
                        ilLoadImage(OpenFileName);
 
394
 
 
395
                        ilutRenderer(ILUT_WIN32);
 
396
                        ResizeWin();
 
397
                        CreateGDI();
 
398
 
 
399
                        sprintf(CurFileName, "%s", OpenFileName);
 
400
                        sprintf(NewTitle, "%s - %s", TITLE, OpenFileName);
 
401
                        SetWindowText(hWnd, NewTitle);
 
402
 
 
403
                        DragFinish(hDrop);
 
404
                        return 0;
 
405
 
 
406
                case WM_COMMAND:
 
407
                        FilterType = LOWORD(wParam);
 
408
        
 
409
                        switch (LOWORD(wParam))
 
410
                        {
 
411
                                case ID_FILE_EXIT:
 
412
                                        PostMessage(hWnd, WM_CLOSE, 0, 0);
 
413
                                        return (0L);
 
414
 
 
415
                                case ID_HELP_ABOUT:
 
416
                                        DialogBox (hInstance,
 
417
                                                MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
 
418
                                                hWnd,
 
419
                                                AboutDlgProc);
 
420
                                        return (0L);
 
421
 
 
422
                                case ID_FILE_PROPERTIES:
 
423
                                        DialogBox (hInstance,
 
424
                                                MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES),
 
425
                                                hWnd,
 
426
                                                PropertiesDlgProc);
 
427
                                        return (0L);
 
428
 
 
429
                                case ID_BATCHCONVERT:
 
430
                                        DialogBox (hInstance,
 
431
                                                MAKEINTRESOURCE(IDD_DIALOG_BATCHCONV),
 
432
                                                hWnd,
 
433
                                                BatchDlgProc);
 
434
                                        return (0L);
 
435
 
 
436
                                case ID_EFFECTS_COUNTCOLORS:
 
437
                                        Colours = iluColoursUsed();
 
438
                                        char ColourString[255];
 
439
                                        sprintf(ColourString, "The number of colours in this image is:  %d", Colours);
 
440
                                        MessageBox(NULL, ColourString, "Colour Count", MB_OK);
 
441
                                        return (0L);
 
442
 
 
443
                                case ID_EFFECTSTOOLS_BACKGROUNDCOLOUR:
 
444
                                        userClickedOK = FSColorPickerDoModal(&currentColor, &originalColor, 0);
 
445
 
 
446
                                        if (userClickedOK) {
 
447
                                                Red = (ILfloat)((currentColor & 0xff0000) >> 16) / 255.0f;
 
448
                                                Green = (ILfloat)((currentColor & 0xff00) >> 8) / 255.0f;
 
449
                                                Blue = (ILfloat)(currentColor & 0xff) / 255.0f;
 
450
 
 
451
                                                ilClearColour(Red, Green, Blue, 1.0f);
 
452
                                        }
 
453
 
 
454
                                        return (0L);
 
455
 
 
456
                                case ID_EDIT_COPY:
 
457
                                        ilutSetWinClipboard();
 
458
                                        return (0L);
 
459
 
 
460
                                case ID_EDIT_PASTE:
 
461
                                        ILuint Test;
 
462
                                        ilGenImages(1, &Test);
 
463
                                        ilBindImage(Test);
 
464
 
 
465
                                        // Check if there's anything in the clipboard.
 
466
                                        if (!ilutGetWinClipboard()) {
 
467
                                                ilDeleteImages(1, &Test);
 
468
                                                return (0L);
 
469
                                        }
 
470
                                        ilDeleteImages(1, &Test);
 
471
 
 
472
                                        DestroyGDI();
 
473
                                        ilDeleteImages(UndoSize, Undos);
 
474
                                        UndoSize = 0;
 
475
                                        XOff = 0;
 
476
                                        YOff = 0;
 
477
 
 
478
                                        ilGenImages(1, Undos);
 
479
                                        ilBindImage(Undos[0]);
 
480
                                        ilutGetWinClipboard();
 
481
 
 
482
                                        sprintf(CurFileName, "Clipboard Paste");
 
483
                                        sprintf(NewTitle, "%s - Pasted from the Clipboard", TITLE);
 
484
                                        SetWindowText(hWnd, NewTitle);
 
485
 
 
486
                                        //ilConvertImage(IL_BGRA);
 
487
                                        ilutRenderer(ILUT_WIN32);
 
488
                                        ResizeWin();
 
489
                                        CreateGDI();
 
490
                                        return (0L);
 
491
 
 
492
                                // @TODO:  Will probably fail if no image loaded!
 
493
                                case ID_FILE_PRINT:
 
494
                                        /*PRINTDLG      Pd;
 
495
                                        DOCINFO         Di;
 
496
                                        //HDC                   PrintDC;
 
497
                                        //HBITMAP               PrintReplace;
 
498
 
 
499
                                        memset(&Pd, 0, sizeof(PRINTDLG));
 
500
                                        Pd.lStructSize = sizeof(PRINTDLG);
 
501
                                        Pd.hwndOwner = hWnd;
 
502
                                        Pd.Flags = PD_RETURNDC;
 
503
                                        Pd.nCopies = 1;
 
504
                                        Pd.nFromPage = 0xFFFF;
 
505
                                        Pd.nToPage = 0xFFFF;
 
506
                                        Pd.nMinPage = 1;
 
507
                                        Pd.nMaxPage = 0xFFFF;
 
508
 
 
509
                                        if (!PrintDlg(&Pd))
 
510
                                                return (0L);
 
511
 
 
512
                                        Di.cbSize = sizeof(DOCINFO);
 
513
                                        Di.lpszDocName = "DevIL Printing Test";
 
514
                                        Di.lpszOutput = NULL;
 
515
                                        Di.lpszDatatype = NULL;
 
516
                                        Di.fwType = 0;
 
517
 
 
518
                                        StartDoc(Pd.hDC, &Di);
 
519
                                        StartPage(Pd.hDC);
 
520
 
 
521
                                        //PrintDC = CreateCompatibleDC(Pd.hDC);
 
522
                                        //PrintReplace = (HBITMAP)SelectObject(PrintDC, hBitmap);
 
523
                                        StretchBlt(Pd.hDC, 0, 0, Width * 2, Height * 2, hMemDC, 0, 0, Width, Height, SRCCOPY);
 
524
 
 
525
                                        EndPage(Pd.hDC);
 
526
                                        EndDoc(Pd.hDC);
 
527
                                        //DeleteObject(PrintReplace);
 
528
                                        //DeleteDC(PrintDC);
 
529
                                        DeleteDC(Pd.hDC);*/
 
530
 
 
531
                                        ilutWinPrint(0, 0, ilGetInteger(IL_IMAGE_WIDTH) * 2, ilGetInteger(IL_IMAGE_HEIGHT) * 2, hDC);
 
532
 
 
533
                                        return (0L);
 
534
 
 
535
                                case ID_FILE_LOAD:
 
536
                                        sprintf(OpenFileName, "*.*");
 
537
                                        Ofn.lpstrFilter = OpenFilter;
 
538
                                        Ofn.lpstrFile = OpenFileName;
 
539
                                        Ofn.lpstrTitle = "Open File";
 
540
                                        Ofn.nFilterIndex = 1;
 
541
                                        Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
 
542
 
 
543
                                        if (!GetOpenFileName(&Ofn))
 
544
                                                return (0L);
 
545
 
 
546
                                        DestroyGDI();
 
547
                                        ilDeleteImages(UndoSize, Undos);
 
548
                                        UndoSize = 0;
 
549
                                        XOff = 0;
 
550
                                        YOff = 0;
 
551
 
 
552
                                        ilGenImages(1, Undos);
 
553
                                        ilBindImage(Undos[0]);
 
554
 
 
555
                                        //last_elapsed = SDL_GetTicks();
 
556
                                        ilLoadImage(OpenFileName);
 
557
                                        //cur_elapsed = SDL_GetTicks();
 
558
                                        //elapsed = cur_elapsed - last_elapsed;
 
559
                                        //last_elapsed = cur_elapsed;
 
560
                                        elapsed = 0;
 
561
 
 
562
                                        ilutRenderer(ILUT_WIN32);
 
563
                                        ResizeWin();
 
564
                                        CreateGDI();
 
565
 
 
566
                                        sprintf(CurFileName, "%s", OpenFileName);
 
567
                                        sprintf(NewTitle, "%s - %s:  %g ms", TITLE, OpenFileName, elapsed);
 
568
                                        SetWindowText(hWnd, NewTitle);
 
569
 
 
570
                                        return (0L);
 
571
 
 
572
                                case ID_FILE_OPENURL:
 
573
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
574
                                                hWnd, FilterDlgProc) != TRUE) {
 
575
                                                return (0L);
 
576
                                        }
 
577
 
 
578
                                        DestroyGDI();
 
579
                                        ilDeleteImages(UndoSize, Undos);
 
580
                                        UndoSize = 0;
 
581
                                        XOff = 0;
 
582
                                        YOff = 0;
 
583
 
 
584
                                        ilGenImages(1, Undos);
 
585
                                        ilBindImage(Undos[0]);
 
586
                                        if (!ilutWinLoadUrl(FilterEditString))
 
587
                                                return (0L);
 
588
 
 
589
                                        ilutRenderer(ILUT_WIN32);
 
590
                                        ResizeWin();
 
591
                                        CreateGDI();
 
592
                                        
 
593
                                        sprintf(NewTitle, "%s - %s", TITLE, FilterEditString);
 
594
                                        SetWindowText(hWnd, NewTitle);
 
595
 
 
596
                                        return (0L);
 
597
 
 
598
                                case ID_FILE_SAVE:
 
599
                                        sprintf(SaveFileName, "monkey.tga");
 
600
                                        Ofn.lpstrFilter = SaveFilter;
 
601
                                        Ofn.lpstrFile = SaveFileName;
 
602
                                        Ofn.lpstrTitle = "Save File";
 
603
                                        Ofn.nFilterIndex = 1;
 
604
                                        Ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
 
605
 
 
606
                                        if (!GetSaveFileName(&Ofn))
 
607
                                                return (0L);
 
608
 
 
609
                                        ilEnable(IL_FILE_OVERWRITE);
 
610
                                        ilSaveImage(SaveFileName);
 
611
 
 
612
                                        sprintf(CurFileName, "%s", SaveFileName);
 
613
                                        sprintf(NewTitle, "%s - %s", TITLE, SaveFileName);
 
614
                                        SetWindowText(hWnd, NewTitle);
 
615
 
 
616
                                        return (0L);
 
617
 
 
618
                                case ID_EDIT_UNDOLEVEL:
 
619
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
620
                                                hWnd, FilterDlgProc) == TRUE) {
 
621
                                                NumUndosAllowed = FilterParamInt <= 10 ? FilterParamInt : 10;
 
622
                                        }
 
623
                                        return (0L);
 
624
 
 
625
                                case ID_EDIT_UNDO:
 
626
                                        if (UndoSize && NumUndosAllowed) {
 
627
                                                ilDeleteImages(1, &Undos[UndoSize]);
 
628
                                                ilBindImage(Undos[--UndoSize]);
 
629
                                                ResizeWin();
 
630
                                                CreateGDI();
 
631
                                        }
 
632
                                        return (0L);
 
633
 
 
634
                                case ID_EDIT_VIEWIMAGENUM:
 
635
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
636
                                                hWnd, FilterDlgProc) == TRUE) {
 
637
                                                ilActiveImage(FilterParamInt);
 
638
                                                ilutRenderer(ILUT_WIN32);
 
639
                                                ResizeWin();
 
640
                                                CreateGDI();
 
641
                                        }
 
642
                                        return (0L);
 
643
 
 
644
                                case ID_EDIT_VIEWMIPMAP:
 
645
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
646
                                                hWnd, FilterDlgProc) == TRUE) {
 
647
                                                ilActiveMipmap(FilterParamInt);
 
648
                                                ilutRenderer(ILUT_WIN32);
 
649
                                                ResizeWin();
 
650
                                                CreateGDI();
 
651
                                        }
 
652
                                        return (0L);
 
653
 
 
654
                        }
 
655
 
 
656
 
 
657
                        if (++UndoSize > NumUndosAllowed) {
 
658
                                if (NumUndosAllowed > 0) {
 
659
                                        UndoSize = NumUndosAllowed;
 
660
                                        ilDeleteImages(1, &Undos[0]);
 
661
                                        memcpy(Undos, Undos+1, NumUndosAllowed * sizeof(ILuint));
 
662
                                        ilBindImage(Undos[UndoSize]);
 
663
                                }
 
664
                        }
 
665
 
 
666
                        if (NumUndosAllowed > 0) {
 
667
                                ilGetIntegerv(IL_ACTIVE_IMAGE, (ILint*)&Undos[UndoSize]);
 
668
                                /*ilGenImages(1, &Undos[UndoSize]);
 
669
                                ilBindImage(Undos[UndoSize]);
 
670
                                ilCopyImage(Undos[UndoSize-1]);*/
 
671
                                Undos[UndoSize] = ilCloneCurImage();
 
672
                                ilBindImage(Undos[UndoSize]);
 
673
                        }
 
674
 
 
675
                        DestroyGDI();
 
676
                        switch (LOWORD(wParam))
 
677
                        {
 
678
                                case ID_CONVERT_PALETTE:
 
679
                                        ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE);
 
680
                                        break;
 
681
 
 
682
                                case ID_CONVERT_RGB:
 
683
                                        ilConvertImage(IL_RGB, ilGetInteger(IL_IMAGE_TYPE));
 
684
                                        break;
 
685
 
 
686
                                case ID_CONVERT_RGBA:
 
687
                                        ilConvertImage(IL_RGBA, ilGetInteger(IL_IMAGE_TYPE));
 
688
                                        break;
 
689
 
 
690
                                case ID_CONVERT_BGR:
 
691
                                        ilConvertImage(IL_BGR, ilGetInteger(IL_IMAGE_TYPE));
 
692
                                        break;
 
693
 
 
694
                                case ID_CONVERT_BGRA:
 
695
                                        ilConvertImage(IL_BGRA, ilGetInteger(IL_IMAGE_TYPE));
 
696
                                        break;
 
697
 
 
698
                                case ID_CONVERT_LUMINANCE:
 
699
                                        ilConvertImage(IL_LUMINANCE, ilGetInteger(IL_IMAGE_TYPE));
 
700
                                        break;
 
701
 
 
702
                                case ID_CONVERT_LUMINANCEALPHA:
 
703
                                        ilConvertImage(IL_LUMINANCE_ALPHA, ilGetInteger(IL_IMAGE_TYPE));
 
704
                                        break;
 
705
 
 
706
                                case ID_EDIT_VIEWALPHA:
 
707
                                        Origin = ilGetInteger(IL_ORIGIN_MODE);
 
708
                                        AlphaChannel = ilGetAlpha(IL_UNSIGNED_BYTE);
 
709
                                        ilTexImage(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
 
710
                                                ilGetInteger(IL_IMAGE_DEPTH), 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, AlphaChannel);
 
711
                                        free(AlphaChannel);
 
712
                                        ilRegisterOrigin(Origin);
 
713
                                        break;
 
714
 
 
715
                                case ID_EFFECTS_FLIP:
 
716
                                        iluFlipImage();
 
717
                                        break;
 
718
 
 
719
                                case ID_EFFECTS_MIRROR:
 
720
                                        iluMirror();
 
721
                                        break;
 
722
 
 
723
                                case ID_FILTER_EMBOSS:
 
724
                                        iluEmboss();
 
725
                                        break;
 
726
 
 
727
                                case ID_FILTER_EQUALIZE:
 
728
                                        iluEqualize();
 
729
                                        break;
 
730
 
 
731
                                case ID_FILTER_ALIENIFY:
 
732
                                        iluAlienify();
 
733
                                        break;
 
734
 
 
735
                                case ID_FILTER_NEGATIVE:
 
736
                                        iluNegative();
 
737
                                        break;
 
738
 
 
739
                                case ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS:
 
740
                                        iluEdgeDetectE();
 
741
                                        break;
 
742
 
 
743
                                case ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL:
 
744
                                        iluEdgeDetectS();
 
745
                                        break;
 
746
 
 
747
                                case ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT:
 
748
                                        iluEdgeDetectP();
 
749
                                        break;
 
750
 
 
751
                                case ID_FILTER_NOISE:
 
752
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
753
                                                hWnd, FilterDlgProc) == TRUE) {
 
754
                                                iluNoisify(FilterParamFloat);
 
755
                                        }
 
756
                                        break;
 
757
 
 
758
                                case ID_EFFECTS_FILTERS_WAVE:
 
759
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
760
                                                hWnd, FilterDlgProc) == TRUE) {
 
761
                                                iluWave(FilterParamFloat);
 
762
                                        }
 
763
                                        break;
 
764
 
 
765
                                case ID_FILTER_PIXELIZE:
 
766
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
767
                                                hWnd, FilterDlgProc) == TRUE) {
 
768
                                                iluPixelize(FilterParamInt);
 
769
                                        }
 
770
                                        break;
 
771
 
 
772
                                case ID_FILTERS_BLUR_AVERAGE:
 
773
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
774
                                                hWnd, FilterDlgProc) == TRUE) {
 
775
                                                iluBlurAvg(FilterParamInt);
 
776
                                        }
 
777
                                        break;
 
778
 
 
779
                                case ID_FILTERS_BLUR_GAUSSIAN:
 
780
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
781
                                                hWnd, FilterDlgProc) == TRUE) {
 
782
                                                iluBlurGaussian(FilterParamInt);
 
783
                                                /*iluMatrixMode(ILU_CONVOLUTION_MATRIX);
 
784
                                                iluLoadFilter(ILU_FILTER_GAUSSIAN_5X5);
 
785
                                                iluApplyMatrix();*/
 
786
                                        }
 
787
                                        break;
 
788
 
 
789
                                case ID_FILTER_GAMMACORRECT:
 
790
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
791
                                                hWnd, FilterDlgProc) == TRUE) {
 
792
                                                iluGammaCorrect(FilterParamFloat);
 
793
                                        }
 
794
                                        break;
 
795
 
 
796
                                case ID_FILTER_SHARPEN:
 
797
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
798
                                                hWnd, FilterDlgProc) == TRUE) {
 
799
                                                iluSharpen(FilterParamFloat, 1);
 
800
                                        }
 
801
                                        break;
 
802
 
 
803
                                case ID_EFFECTS_FILTERS_ROTATE:
 
804
                                        if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
 
805
                                                hWnd, FilterDlgProc) == TRUE) {
 
806
                                                iluRotate(FilterParamFloat);
 
807
                                                ResizeWin();
 
808
                                        }
 
809
                                        break;
 
810
 
 
811
                                case ID_EFFECTS_FILTERS_SCALE:
 
812
                                        HWnd = hWnd;
 
813
                                        iluImageParameter(ILU_FILTER, ILU_BILINEAR);
 
814
                                        DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_RESIZE), hWnd, ResizeDlgProc);
 
815
                                        break;
 
816
 
 
817
                        }
 
818
 
 
819
                        CreateGDI();
 
820
                        InvalidateRect(hWnd, NULL, FALSE);
 
821
                        break;
 
822
 
 
823
                default:
 
824
                  return (DefWindowProc(hWnd, message, wParam, lParam));
 
825
        }
 
826
 
 
827
    return (0L);
 
828
}
 
829
 
 
830
 
 
831
void GenFilterString(char *Out, char **Strings)
 
832
{
 
833
        int OutPos = 0, StringPos = 0;
 
834
 
 
835
        while (Strings[StringPos][0] != 0) {
 
836
                sprintf(Out + OutPos, Strings[StringPos]);
 
837
                OutPos += (int)strlen(Strings[StringPos++]) + 1;
 
838
        }
 
839
 
 
840
        Out[OutPos++] = 0;
 
841
        Out[OutPos] = 0;
 
842
 
 
843
        return;
 
844
}
 
845
 
 
846
 
 
847
BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
 
848
{
 
849
    switch (message)
 
850
        {
 
851
            case WM_INITDIALOG:
 
852
                {
 
853
                        int i;
 
854
                        ILenum ilError;
 
855
                        char VersionNum[256];
 
856
 
 
857
                        sprintf(VersionNum, "Num:  %d", ilGetInteger(IL_VERSION_NUM));
 
858
 
 
859
                        SetDlgItemText(hDlg, IDC_ABOUT_VENDOR, ilGetString(IL_VENDOR));
 
860
                        SetDlgItemText(hDlg, IDC_ABOUT_VER_STRING, ilGetString(IL_VERSION));
 
861
                        SetDlgItemText(hDlg, IDC_ABOUT_VER_NUM, VersionNum);
 
862
 
 
863
                        for (i = 0; i < 6; i++) {
 
864
                                ilError = ilGetError();
 
865
                                if (ilError == IL_NO_ERROR)
 
866
                                        break;
 
867
                                SetDlgItemText(hDlg, IDC_ERROR1+i, iluErrorString(ilError));
 
868
                        }
 
869
 
 
870
                        return (TRUE);
 
871
                }
 
872
                break;
 
873
 
 
874
            case WM_COMMAND:      
 
875
                {
 
876
                        if (LOWORD(wParam) == IDOK)
 
877
                                EndDialog(hDlg, TRUE);
 
878
                        if (LOWORD(wParam) == IDCANCEL)
 
879
                                EndDialog(hDlg, FALSE);
 
880
            }
 
881
                break;
 
882
 
 
883
                case WM_CLOSE:
 
884
                        EndDialog(hDlg, TRUE);
 
885
                        break;
 
886
        }
 
887
 
 
888
        return FALSE;
 
889
}
 
890
 
 
891
 
 
892
BOOL APIENTRY PropertiesDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
 
893
{
 
894
    switch (message)
 
895
        {
 
896
            case WM_INITDIALOG:
 
897
                {
 
898
                        char Temp[256];
 
899
 
 
900
                        SetDlgItemText(hDlg, IDC_PROP_FILENAME, CurFileName);
 
901
                        sprintf(Temp, "%d", ilGetInteger(IL_IMAGE_WIDTH));
 
902
                        SetDlgItemText(hDlg, IDC_PROP_WIDTH, Temp);
 
903
                        sprintf(Temp, "%d", ilGetInteger(IL_IMAGE_HEIGHT));
 
904
                        SetDlgItemText(hDlg, IDC_PROP_HEIGHT, Temp);
 
905
                        sprintf(Temp, "%d", ilGetInteger(IL_IMAGE_DEPTH));
 
906
                        SetDlgItemText(hDlg, IDC_PROP_DEPTH, Temp);
 
907
                        sprintf(Temp, "%d", ilGetInteger(IL_IMAGE_SIZE_OF_DATA));
 
908
                        SetDlgItemText(hDlg, IDC_PROP_SIZE, Temp);
 
909
 
 
910
                        return (TRUE);
 
911
                }
 
912
                break;
 
913
 
 
914
            case WM_COMMAND:      
 
915
                {
 
916
                        if (LOWORD(wParam) == IDOK)
 
917
                                EndDialog(hDlg, TRUE);
 
918
                        if (LOWORD(wParam) == IDCANCEL)
 
919
                                EndDialog(hDlg, FALSE);
 
920
            }
 
921
                break;
 
922
 
 
923
                case WM_CLOSE:
 
924
                        EndDialog(hDlg, TRUE);
 
925
                        break;
 
926
        }
 
927
 
 
928
        return FALSE;
 
929
}
 
930
 
 
931
 
 
932
BOOL APIENTRY FilterDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
 
933
{
 
934
    switch (message)
 
935
        {
 
936
            case WM_INITDIALOG:
 
937
                {
 
938
                        switch (FilterType)
 
939
                        {
 
940
                                case ID_FILTER_PIXELIZE:
 
941
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Width of pixelized block:");
 
942
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
 
943
                                        break;
 
944
                                case ID_FILTER_NOISE:
 
945
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Amount of noise threshold:");
 
946
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1.0");
 
947
                                        break;
 
948
                                case ID_EFFECTS_FILTERS_WAVE:
 
949
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Angle of wave to apply:");
 
950
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "0.0");
 
951
                                        break;
 
952
                                case ID_FILTERS_BLUR_AVERAGE:
 
953
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of iterations:");
 
954
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
 
955
                                        break;
 
956
                                case ID_FILTERS_BLUR_GAUSSIAN:
 
957
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of iterations:");
 
958
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
 
959
                                        break;
 
960
                                case ID_FILTER_GAMMACORRECT:
 
961
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Amount of gamma correction:");
 
962
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1.0");
 
963
                                        break;
 
964
                                case ID_FILTER_SHARPEN:
 
965
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Sharpening factor:");
 
966
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1.0");
 
967
                                        break;
 
968
                                case ID_EFFECTS_FILTERS_ROTATE:
 
969
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of degress to rotate:");
 
970
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "0.0");
 
971
                                        break;
 
972
 
 
973
                                case ID_EDIT_UNDOLEVEL:
 
974
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Set level of undo:");
 
975
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "4");
 
976
                                        break;
 
977
                                case ID_EDIT_VIEWIMAGENUM:
 
978
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Enter image number:");
 
979
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "0");
 
980
                                        break;
 
981
                                case ID_EDIT_VIEWMIPMAP:
 
982
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Enter mipmap number:");
 
983
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "0");
 
984
                                        break;
 
985
                                case ID_FILE_OPENURL:
 
986
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Enter url of image:");
 
987
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "");
 
988
                                        break;
 
989
                        }
 
990
 
 
991
                        return TRUE;
 
992
                }
 
993
                break;
 
994
 
 
995
            case WM_COMMAND:
 
996
                {
 
997
                        if (LOWORD(wParam) == IDOK) {
 
998
                                GetDlgItemText(hDlg, IDC_FILTER_EDIT, FilterEditString, 255);
 
999
                                FilterParamInt = atoi(FilterEditString);
 
1000
                                FilterParamFloat = (float)atof(FilterEditString);
 
1001
                                EndDialog(hDlg, TRUE);
 
1002
                        }
 
1003
                        if (LOWORD(wParam) == IDCANCEL) {
 
1004
                                EndDialog(hDlg, FALSE);
 
1005
                        }
 
1006
            }
 
1007
                break;
 
1008
 
 
1009
                case WM_CLOSE:
 
1010
                        EndDialog(hDlg, TRUE);
 
1011
                        break;
 
1012
        }
 
1013
 
 
1014
        return FALSE;
 
1015
}
 
1016
 
 
1017
 
 
1018
BOOL APIENTRY ResizeDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
 
1019
{
 
1020
        static char x[255], y[255], z[255];
 
1021
        static ILuint xsize, ysize, zsize;
 
1022
        static RECT Rect;
 
1023
 
 
1024
    switch (message)
 
1025
        {
 
1026
            case WM_INITDIALOG:
 
1027
                {
 
1028
                        sprintf(x, "%d", Width);
 
1029
                        sprintf(y, "%d", Height);
 
1030
                        sprintf(z, "%d", Depth);
 
1031
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x);
 
1032
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y);
 
1033
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z);
 
1034
                        return TRUE;
 
1035
                }
 
1036
                break;
 
1037
 
 
1038
            case WM_COMMAND:
 
1039
                {
 
1040
                        if (LOWORD(wParam) == IDOK) {
 
1041
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x, 255);
 
1042
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y, 255);
 
1043
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z, 255);
 
1044
                                xsize = atoi(x);
 
1045
                                ysize = atoi(y);
 
1046
                                zsize = atoi(z);
 
1047
                                if (xsize && ysize && zsize) {
 
1048
                                        iluScale(xsize, ysize, zsize);
 
1049
 
 
1050
                                        Width = ilGetInteger(IL_IMAGE_WIDTH);
 
1051
                                        Height = ilGetInteger(IL_IMAGE_HEIGHT);
 
1052
                                        Depth = ilGetInteger(IL_IMAGE_DEPTH);
 
1053
 
 
1054
                                        GetWindowRect(HWnd, &Rect);
 
1055
                                        SetWindowPos(HWnd, HWND_TOP, Rect.left, Rect.top,
 
1056
                                                Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
 
1057
                                                Height + MENU_H, SWP_SHOWWINDOW);
 
1058
 
 
1059
                                        InvalidateRect(HWnd, NULL, FALSE);
 
1060
                                }
 
1061
                                EndDialog(hDlg, TRUE);
 
1062
                        }
 
1063
                        if (LOWORD(wParam) == IDCANCEL) {
 
1064
                                EndDialog(hDlg, FALSE);
 
1065
                        }
 
1066
            }
 
1067
                break;
 
1068
 
 
1069
                case WM_CLOSE:
 
1070
                        EndDialog(hDlg, TRUE);
 
1071
                        break;
 
1072
        }
 
1073
 
 
1074
        return FALSE;
 
1075
}
 
1076
 
 
1077
 
 
1078
BOOL APIENTRY BatchDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
 
1079
{
 
1080
        static char     Dir[255], NewExt[255];
 
1081
        static bool     Recurse;
 
1082
        static RECT     Rect;
 
1083
 
 
1084
    switch (message)
 
1085
        {
 
1086
            case WM_INITDIALOG:
 
1087
                {
 
1088
                        sprintf(Dir, "");
 
1089
                        sprintf(NewExt, "tga");
 
1090
                        SetDlgItemText(hDlg, IDC_BATCH_DIR, Dir);
 
1091
                        SetDlgItemText(hDlg, IDC_BATCH_NEWEXT, NewExt);
 
1092
                        return TRUE;
 
1093
                }
 
1094
                break;
 
1095
 
 
1096
            case WM_COMMAND:
 
1097
                {
 
1098
                        if (LOWORD(wParam) == IDOK) {
 
1099
                                GetDlgItemText(hDlg, IDC_BATCH_DIR, Dir, 255);
 
1100
                                GetDlgItemText(hDlg, IDC_BATCH_NEWEXT, NewExt, 255);
 
1101
                                Recurse = IsDlgButtonChecked(hDlg, IDC_BATCH_CHECK1) == BST_CHECKED;
 
1102
 
 
1103
                                // Do shit here.
 
1104
 
 
1105
                                BatchConv(Dir, NULL, NewExt, Recurse);
 
1106
 
 
1107
                                EndDialog(hDlg, TRUE);
 
1108
                        }
 
1109
                        if (LOWORD(wParam) == IDCANCEL) {
 
1110
                                EndDialog(hDlg, FALSE);
 
1111
                        }
 
1112
            }
 
1113
                break;
 
1114
 
 
1115
                case WM_CLOSE:
 
1116
                        EndDialog(hDlg, TRUE);
 
1117
                        break;
 
1118
        }
 
1119
 
 
1120
        return FALSE;
 
1121
}