~ubuntu-branches/ubuntu/precise/devil/precise

« back to all changes in this revision

Viewing changes to test/DDrawTest/test_window/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bradley Smith
  • Date: 2009-01-17 15:01:18 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090117150118-4bwb6nmvbz4srsjl
Tags: 1.7.5-4
Actually fix CVE-2008-5262. Closes: #512122.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//============================================================//
2
 
// File:                main.cpp
3
 
// 
4
 
// Date:                11-21-2000
5
 
//===========================================================//
6
 
#include "../header/Render2DCore.h"
7
 
#include "resource.h"
8
 
#include <math.h>
9
 
#include <il/ilut.h>
10
 
 
11
 
 
12
 
HWND                                            m_MainHWND;
13
 
HINSTANCE                                       hInst;
14
 
beScreen                                        m_MainDDScreen;
15
 
beSurface*                                      m_pMainSurface;
16
 
beSurface*                                      m_pMouseCursorSurface;
17
 
beSurface*                                      m_pBackgroundSurface;
18
 
DDBLTFX                                         ddbltfx;
19
 
 
20
 
int                                                     m_iWindowWidth  = 640;
21
 
int                                                     m_iWindowHeight = 480;
22
 
int                                                     m_iCurrMouseX;
23
 
int                                                     m_iCurrMouseY;
24
 
beScreenParams                          InitDisplayStruct;
25
 
 
26
 
#define BORDER_W        8
27
 
#define MENU_H          46
28
 
#define MIN_W           205  // Accomodate the menu bar.
29
 
#define MAX_W           400
30
 
#define MAX_H           300
31
 
#define TITLE           "OpenIL Direct Draw Test"
32
 
 
33
 
ILuint  NumUndosAllowed = 4, UndoSize = 0;
34
 
ILuint  Undos[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
35
 
ILuint  Width, Height, Depth;  // Main image
36
 
ILuint  MainImage = 0;  // Main image
37
 
HBITMAP hBitmap;  // Main bitmap
38
 
 
39
 
ILuint  FilterType;
40
 
ILuint  FilterParamInt;
41
 
ILfloat FilterParamFloat;
42
 
 
43
 
 
44
 
BOOL APIENTRY AboutDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
45
 
BOOL APIENTRY FilterDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
46
 
BOOL APIENTRY ResizeDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
47
 
void GenFilterString(char *Out, char **Strings);
48
 
 
49
 
//===========================================================//
50
 
// WindowProc()
51
 
//===========================================================//
52
 
long FAR PASCAL WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
53
 
{
54
 
        static int x, y;
55
 
        static HDC hDC;
56
 
 
57
 
        static char NewTitle[2048];
58
 
        static char OpenFileName[2048];
59
 
        static char OpenFilter[2048];
60
 
        static char SaveFileName[2048];
61
 
        static char SaveFilter[2048];
62
 
        static char *OFilter[] = {
63
 
                "All Files (*.*)", "*.*",
64
 
                "Half-Life Model Files (*.mdl)", "*.mdl",
65
 
                "Homeworld Image Files (*.lif)", "*.lif",
66
 
                "Image Files (All Supported Types)", "*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx",
67
 
                "Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
68
 
                "Microsoft Bitmap Files (*.bmp)", "*.bmp",
69
 
                "Microsoft Icon Files (*.ico)", "*.ico",
70
 
                "OpenIL Files (*.oil)", "*.oil",
71
 
                "Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", "*.pbm;*.pgm;*.pnm;*.ppm",
72
 
                "Portable Network Graphics Files (*.png)", "*.png",
73
 
                "Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
74
 
                "Targa Files (*.tga)", "*.tga",
75
 
                "Tiff Files (*.tif)", "*.tif;*.tiff",
76
 
                "Quake Wal Files (*.wal)", "*.wal",
77
 
                "ZSoft Pcx Files (*.pcx)", "*.pcx",
78
 
                "\0\0"
79
 
        };
80
 
        static char *SFilter[] = {
81
 
                "All Files (*.*)", "*.*",
82
 
                "C-Style Header (*.h)", "*.h",
83
 
                "Jpeg Files (*.jpe, *.jpg, *.jpeg)", "*.jpe;*.jpg;*.jpeg",
84
 
                "Microsoft Bitmap Files (*.bmp)", "*.bmp",
85
 
                "OpenIL Files (*.oil)", "*.oil",
86
 
                "Portable AnyMap Files (*.pbm, *.pgm, *.ppm)", "*.pbm;*.pgm;*.ppm",
87
 
                "Portable Network Graphics Files (*.png)", "*.png",
88
 
                "Sgi Files (*.sgi)", "*.bw;*.rgb;*.rgba;*.sgi",
89
 
                "Targa Files (*.tga)", "*.tga",
90
 
                "ZSoft Pcx Files (*.pcx)", "*.pcx",
91
 
                "\0\0"
92
 
        };
93
 
 
94
 
        static OPENFILENAME Ofn = {
95
 
                sizeof(OPENFILENAME),
96
 
                hWnd,
97
 
                NULL,
98
 
                OpenFilter,
99
 
                NULL,
100
 
                0,
101
 
                0,
102
 
                OpenFileName,
103
 
                2048,
104
 
                NULL,
105
 
                0,
106
 
                NULL,
107
 
                NULL,
108
 
                OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
109
 
                0,
110
 
                0,
111
 
                NULL,
112
 
                NULL,
113
 
                NULL,
114
 
                NULL
115
 
        };
116
 
 
117
 
    switch (message)
118
 
    {
119
 
        case WM_ACTIVATE:
120
 
            return 0L;
121
 
 
122
 
                case WM_CREATE:
123
 
                        GenFilterString(OpenFilter, OFilter);
124
 
                        GenFilterString(SaveFilter, SFilter);
125
 
 
126
 
                        // Store the device context
127
 
                        hDC = GetDC(hWnd);
128
 
                        return 0L;
129
 
 
130
 
        case WM_DESTROY:
131
 
            // Clean up and close the app
132
 
                        m_MainDDScreen.Delete();
133
 
            PostQuitMessage(0);
134
 
            return 0L;
135
 
 
136
 
        case WM_KEYDOWN:
137
 
            // Handle any non-accelerated key commands
138
 
            switch (wParam)
139
 
            {
140
 
                case VK_ESCAPE:
141
 
                case VK_F12:
142
 
                    PostMessage(hWnd, WM_CLOSE, 0, 0);
143
 
                    return 0L;
144
 
            }
145
 
            break;
146
 
 
147
 
                case WM_MOVE:
148
 
                        m_MainDDScreen.Move();
149
 
                        break;
150
 
 
151
 
                case WM_SIZE:
152
 
            m_MainDDScreen.Move();
153
 
                        break;
154
 
 
155
 
                case WM_MOUSEMOVE:
156
 
                        m_iCurrMouseX = LOWORD(lParam); 
157
 
                        m_iCurrMouseY = HIWORD(lParam); 
158
 
 
159
 
                case WM_PAINT:
160
 
                        if (!m_pBackgroundSurface)
161
 
                                break;
162
 
 
163
 
                        // we don't need a colorfill...cause we're using a bitmap to clear the surface
164
 
                        m_pMainSurface->GetSurface()->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
165
 
                        m_pMainSurface->BltFast(0, 0, m_pBackgroundSurface, NULL, DDBLTFAST_NOCOLORKEY);
166
 
 
167
 
                        /*RECT rcRect;
168
 
                        rcRect.left = 0;
169
 
                        rcRect.right = 128;
170
 
                        rcRect.top = 0;
171
 
                        rcRect.bottom = 128;*/
172
 
 
173
 
                        DDSURFACEDESC2 ddsd;
174
 
                        if (!m_pMouseCursorSurface->Lock(ddsd))
175
 
                                return -1;
176
 
 
177
 
                        // pixel-plotting test
178
 
                        for (x = 0; x < 128; x++) {
179
 
                                for (y = 0; y < 128; y++) {     
180
 
                                        m_pMouseCursorSurface->PlotPixel(x, y, x*2%255, 0, y*2%255, &ddsd);
181
 
                                }
182
 
                        }
183
 
                        if (!m_pMouseCursorSurface->Unlock())
184
 
                                return -1;
185
 
 
186
 
                        //m_pMainSurface->BltFast(0, 0, m_pMouseCursorSurface,
187
 
                        //                   &rcRect, DDBLTFAST_NOCOLORKEY);
188
 
 
189
 
                        m_MainDDScreen.GetBackBufferSurface()->BltFast(0,0,m_pMainSurface->GetSurface(),NULL,DDBLTFAST_NOCOLORKEY);
190
 
                        m_MainDDScreen.Flip();
191
 
 
192
 
                        ValidateRect(hWnd, NULL);
193
 
                        break;
194
 
 
195
 
                case WM_COMMAND:
196
 
                        FilterType = LOWORD(wParam);
197
 
 
198
 
                        switch (LOWORD(wParam))
199
 
                        {
200
 
                                case ID_FILE_EXIT:
201
 
                                        DestroyWindow(hWnd);
202
 
                                        return (0L);
203
 
 
204
 
                                case ID_HELP_ABOUT:
205
 
                                        DialogBox (hInst,
206
 
                                                MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
207
 
                                                hWnd,
208
 
                                                AboutDlgProc);
209
 
                                        return (0L);
210
 
 
211
 
                                case ID_EFFECTS_COUNTCOLORS:
212
 
                                        int Colours;
213
 
                                        Colours = iluColoursUsed();
214
 
                                        char ColourString[255];
215
 
                                        sprintf(ColourString, "The number of colours in this image is:  %d", Colours);
216
 
                                        MessageBox(NULL, ColourString, "Colour Count", MB_OK);
217
 
                                        return (0L);
218
 
 
219
 
                                case ID_EDIT_COPY:
220
 
                                        ilutSetWinClipboard();
221
 
                                        return (0L);
222
 
 
223
 
                                case ID_EDIT_PASTE:
224
 
                                        ILuint Test;
225
 
                                        ilGenImages(1, &Test);
226
 
                                        ilBindImage(Test);
227
 
 
228
 
                                        // Check if there's anything in the clipboard.
229
 
                                        if (!ilutGetWinClipboard()) {
230
 
                                                ilDeleteImages(1, &Test);
231
 
                                                return (0L);
232
 
                                        }
233
 
                                        ilDeleteImages(1, &Test);
234
 
 
235
 
                                        ilDeleteImages(UndoSize, Undos);
236
 
                                        UndoSize = 0;
237
 
 
238
 
                                        ilGenImages(1, &MainImage);
239
 
                                        ilBindImage(MainImage);
240
 
                                        Undos[0] = MainImage;
241
 
                                        ilutGetWinClipboard();
242
 
 
243
 
                                        ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);
244
 
                                        ilutRenderer(ILUT_WIN32);
245
 
 
246
 
                                        Width = ilGetInteger(IL_IMAGE_WIDTH);
247
 
                                        Height = ilGetInteger(IL_IMAGE_HEIGHT);
248
 
                                        Depth = ilGetInteger(IL_IMAGE_DEPTH);
249
 
 
250
 
                                        hBitmap = ilutConvertToHBitmap(hDC);
251
 
                                        m_pBackgroundSurface->LoadImage(hBitmap, false);
252
 
                                        DeleteObject(hBitmap);
253
 
 
254
 
                                        RECT Rect;
255
 
                                        GetWindowRect(hWnd, &Rect);
256
 
                                        SetWindowPos(hWnd, HWND_TOP, Rect.left, Rect.top,
257
 
                                                Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
258
 
                                                Height + MENU_H, SWP_SHOWWINDOW);
259
 
                                        return (0L);
260
 
 
261
 
                                case ID_FILE_LOAD:
262
 
                                        sprintf(OpenFileName, "*.*");
263
 
                                        Ofn.lpstrFilter = OpenFilter;
264
 
                                        Ofn.lpstrFile = OpenFileName;
265
 
                                        Ofn.lpstrTitle = "Open File";
266
 
                                        Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
267
 
 
268
 
                                        if (!GetOpenFileName(&Ofn))
269
 
                                                return (0L);
270
 
 
271
 
                                        ilDeleteImages(UndoSize, Undos);
272
 
                                        UndoSize = 0;
273
 
 
274
 
                                        ilGenImages(1, &MainImage);
275
 
                                        ilBindImage(MainImage);
276
 
                                        Undos[0] = MainImage;
277
 
                                        if (!ilLoadImage(OpenFileName))
278
 
                                                return (0L);
279
 
                                        ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);
280
 
                                        ilutRenderer(ILUT_WIN32);
281
 
 
282
 
                                        Width = ilGetInteger(IL_IMAGE_WIDTH);
283
 
                                        Height = ilGetInteger(IL_IMAGE_HEIGHT);
284
 
                                        Depth = ilGetInteger(IL_IMAGE_DEPTH);
285
 
 
286
 
                                        hBitmap = ilutConvertToHBitmap(hDC);
287
 
                                        m_pBackgroundSurface->LoadImage(hBitmap, false);
288
 
                                        DeleteObject(hBitmap);
289
 
 
290
 
                                        GetWindowRect(hWnd, &Rect);
291
 
                                        SetWindowPos(hWnd, HWND_TOP, Rect.left, Rect.top,
292
 
                                                Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
293
 
                                                Height + MENU_H, SWP_SHOWWINDOW);
294
 
 
295
 
                                        sprintf(NewTitle, "%s - %s", TITLE, OpenFileName);
296
 
                                        SetWindowText(hWnd, NewTitle);
297
 
 
298
 
                                        return (0L);
299
 
 
300
 
                                case ID_FILE_SAVE:
301
 
                                        sprintf(SaveFileName, "monkey.tga");
302
 
                                        Ofn.lpstrFilter = SaveFilter;
303
 
                                        Ofn.lpstrFile = SaveFileName;
304
 
                                        Ofn.lpstrTitle = "Save File";
305
 
                                        Ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
306
 
 
307
 
                                        if (!GetSaveFileName(&Ofn))
308
 
                                                return (0L);
309
 
 
310
 
                                        ilEnable(IL_FILE_OVERWRITE);
311
 
                                        ilSaveImage(SaveFileName);
312
 
 
313
 
                                        sprintf(NewTitle, "%s - %s", TITLE, SaveFileName);
314
 
                                        SetWindowText(hWnd, NewTitle);
315
 
 
316
 
                                        return (0L);
317
 
 
318
 
                                case ID_EDIT_UNDOLEVEL:
319
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
320
 
                                                hWnd, FilterDlgProc) == TRUE) {
321
 
                                                NumUndosAllowed = FilterParamInt <= 10 ? FilterParamInt : 10;
322
 
                                        }
323
 
                                        return (0L);
324
 
 
325
 
                                case ID_EDIT_UNDO:
326
 
                                        if (UndoSize && NumUndosAllowed) {
327
 
                                                ilDeleteImages(1, &Undos[UndoSize]);
328
 
                                                ilBindImage(Undos[--UndoSize]);
329
 
                                                hBitmap = ilutConvertToHBitmap(hDC);
330
 
                                                m_pBackgroundSurface->LoadImage(hBitmap, false);
331
 
                                                DeleteObject(hBitmap);
332
 
 
333
 
                                                Width = ilGetInteger(IL_IMAGE_WIDTH);
334
 
                                                Height = ilGetInteger(IL_IMAGE_HEIGHT);
335
 
                                                Depth = ilGetInteger(IL_IMAGE_DEPTH);
336
 
 
337
 
                                                GetWindowRect(hWnd, &Rect);
338
 
                                                SetWindowPos(hWnd, HWND_TOP, Rect.left, Rect.top,
339
 
                                                        Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
340
 
                                                        Height + MENU_H, SWP_SHOWWINDOW);
341
 
 
342
 
 
343
 
                                                InvalidateRect(hWnd, NULL, FALSE);
344
 
                                        }
345
 
                                        return (0L);
346
 
                        }
347
 
 
348
 
 
349
 
                        if (++UndoSize > NumUndosAllowed) {
350
 
                                if (NumUndosAllowed > 0) {
351
 
                                        UndoSize = NumUndosAllowed;
352
 
                                        ilDeleteImages(1, &Undos[0]);
353
 
                                        memcpy(Undos, Undos+1, NumUndosAllowed * sizeof(ILuint));
354
 
                                        ilBindImage(Undos[UndoSize]);
355
 
                                }
356
 
                        }
357
 
 
358
 
                        if (NumUndosAllowed > 0) {
359
 
                                ilGenImages(1, &Undos[UndoSize]);
360
 
                                ilBindImage(Undos[UndoSize]);
361
 
                                ilCopyImage(Undos[UndoSize-1]);
362
 
                                MainImage = Undos[UndoSize];  // ???
363
 
                        }
364
 
 
365
 
 
366
 
                        
367
 
                        switch (LOWORD(wParam))
368
 
                        {
369
 
                                case ID_CONVERT_RGB:
370
 
                                        ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
371
 
                                        break;
372
 
 
373
 
                                case ID_CONVERT_RGBA:
374
 
                                        ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
375
 
                                        break;
376
 
 
377
 
                                case ID_CONVERT_BGR:
378
 
                                        ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
379
 
                                        break;
380
 
 
381
 
                                case ID_CONVERT_BGRA:
382
 
                                        ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);
383
 
                                        break;
384
 
 
385
 
                                case ID_CONVERT_LUMINANCE:
386
 
                                        ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
387
 
                                        break;
388
 
 
389
 
                                case ID_EFFECTS_FLIP:
390
 
                                        iluFlipImage();
391
 
                                        break;
392
 
 
393
 
                                case ID_EFFECTS_MIRROR:
394
 
                                        iluMirror();
395
 
                                        break;
396
 
 
397
 
                                case ID_FILTER_EMBOSS:
398
 
                                        iluEmboss();
399
 
                                        break;
400
 
 
401
 
                                case ID_FILTER_ALIENIFY:
402
 
                                        iluAlienify();
403
 
                                        break;
404
 
 
405
 
                                case ID_FILTER_NEGATIVE:
406
 
                                        iluNegative();
407
 
                                        break;
408
 
 
409
 
                                case ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS:
410
 
                                        iluEdgeDetectE();
411
 
                                        break;
412
 
 
413
 
                                case ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL:
414
 
                                        iluEdgeDetectS();
415
 
                                        break;
416
 
 
417
 
                                case ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT:
418
 
                                        iluEdgeDetectP();
419
 
                                        break;
420
 
 
421
 
                                case ID_FILTER_NOISE:
422
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
423
 
                                                hWnd, FilterDlgProc) == TRUE) {
424
 
                                                iluNoisify(FilterParamFloat);
425
 
                                        }
426
 
                                        break;
427
 
 
428
 
                                case ID_FILTER_PIXELIZE:
429
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
430
 
                                                hWnd, FilterDlgProc) == TRUE) {
431
 
                                                iluPixelize(FilterParamInt);
432
 
                                        }
433
 
                                        break;
434
 
 
435
 
                                case ID_FILTERS_BLUR_AVERAGE:
436
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
437
 
                                                hWnd, FilterDlgProc) == TRUE) {
438
 
                                                iluBlurAvg(FilterParamInt);
439
 
                                        }
440
 
                                        break;
441
 
 
442
 
                                case ID_FILTERS_BLUR_GAUSSIAN:
443
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
444
 
                                                hWnd, FilterDlgProc) == TRUE) {
445
 
                                                iluBlurGaussian(FilterParamInt);
446
 
                                        }
447
 
                                        break;
448
 
 
449
 
                                case ID_FILTER_GAMMACORRECT:
450
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
451
 
                                                hWnd, FilterDlgProc) == TRUE) {
452
 
                                                iluGammaCorrect(FilterParamFloat);
453
 
                                        }
454
 
                                        break;
455
 
 
456
 
                                case ID_FILTER_SHARPEN:
457
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
458
 
                                                hWnd, FilterDlgProc) == TRUE) {
459
 
                                                iluSharpen(FilterParamFloat, 1);
460
 
                                        }
461
 
                                        break;
462
 
 
463
 
                                case ID_EFFECTS_FILTERS_ROTATE:
464
 
                                        if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
465
 
                                                hWnd, FilterDlgProc) == TRUE) {
466
 
                                                iluRotate(FilterParamFloat);
467
 
 
468
 
                                                Width = ilGetInteger(IL_IMAGE_WIDTH);
469
 
                                                Height = ilGetInteger(IL_IMAGE_HEIGHT);
470
 
                                                RECT Rect;
471
 
                                                GetWindowRect(hWnd, &Rect);
472
 
                                                SetWindowPos(hWnd, HWND_TOP, Rect.left, Rect.top,
473
 
                                                        Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
474
 
                                                        Height + MENU_H, SWP_SHOWWINDOW);
475
 
                                        }
476
 
                                        break;
477
 
 
478
 
                                case ID_EFFECTS_FILTERS_SCALE:
479
 
                                        iluImageParameter(ILU_FILTER, ILU_BILINEAR);
480
 
                                        DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_RESIZE), hWnd, ResizeDlgProc);
481
 
                                        break;
482
 
                        }
483
 
 
484
 
                        ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);
485
 
                        hBitmap = ilutConvertToHBitmap(hDC);
486
 
                        m_pBackgroundSurface->LoadImage(hBitmap, false);
487
 
                        DeleteObject(hBitmap);
488
 
                        InvalidateRect(hWnd, NULL, FALSE);
489
 
                        break;
490
 
 
491
 
                default:
492
 
                        return DefWindowProc(hWnd, message, wParam, lParam);
493
 
 
494
 
    }
495
 
 
496
 
 
497
 
    return 0L;
498
 
}
499
 
 
500
 
 
501
 
//===========================================================//
502
 
// InitApp()
503
 
//===========================================================//
504
 
static HRESULT InitApp(HINSTANCE hInstance, int nCmdShow)
505
 
{
506
 
    HWND                hWnd;
507
 
    WNDCLASSEX  wcex;
508
 
 
509
 
        wcex.cbSize = sizeof(WNDCLASSEX); 
510
 
        wcex.style                      = CS_HREDRAW | CS_VREDRAW;
511
 
        wcex.lpfnWndProc        = (WNDPROC)WndProc;
512
 
        wcex.cbClsExtra         = 0;
513
 
        wcex.cbWndExtra         = 0;
514
 
        wcex.hInstance          = hInstance;
515
 
        wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
516
 
        wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
517
 
        wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
518
 
        wcex.lpszMenuName       = (LPCSTR)IDR_MENU1;
519
 
        wcex.lpszClassName      = TITLE;
520
 
        wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON10);
521
 
 
522
 
        RegisterClassEx(&wcex);
523
 
 
524
 
 
525
 
    // Create a window
526
 
    hWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW, 50, 50, 400, 300,
527
 
                                                NULL, NULL, hInstance, NULL);
528
 
    if (!hWnd)
529
 
        return FALSE;
530
 
    ShowWindow(hWnd, nCmdShow);
531
 
    UpdateWindow(hWnd);
532
 
    SetFocus(hWnd);
533
 
 
534
 
        m_MainHWND = hWnd;
535
 
 
536
 
        InitDisplayStruct.m_Flags = 0;
537
 
        InitDisplayStruct.m_Flags |= BE_SCREENFLAGS_WINDOWED;
538
 
        InitDisplayStruct.m_OwnerWnd = hWnd;
539
 
 
540
 
        InitDisplayStruct.m_iScreenWidth = m_iWindowWidth;
541
 
        InitDisplayStruct.m_iScreenHeight = m_iWindowHeight;
542
 
        InitDisplayStruct.m_iScreenBitCount = 16;
543
 
 
544
 
        if (!m_MainDDScreen.Initialize(InitDisplayStruct))
545
 
                MessageBox(NULL,"ah!","ahhhh",MB_OK);
546
 
        
547
 
        m_pMouseCursorSurface   = new beSurface(&m_MainDDScreen);
548
 
        m_pBackgroundSurface    = new beSurface(&m_MainDDScreen);
549
 
        m_pMainSurface                  = new beSurface(&m_MainDDScreen);
550
 
        m_pMainSurface->CreateSurface(InitDisplayStruct.m_iScreenWidth,InitDisplayStruct.m_iScreenHeight,false);
551
 
 
552
 
        ilEnable(IL_FORMAT_SET);
553
 
        ilEnable(IL_ORIGIN_SET);
554
 
        ilEnable(IL_TYPE_SET);
555
 
 
556
 
        ilFormatFunc(IL_BGRA);
557
 
        ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
558
 
        ilTypeFunc(IL_UNSIGNED_BYTE);
559
 
 
560
 
        hBitmap = ilutConvertToHBitmap(GetDC(hWnd));
561
 
        m_pBackgroundSurface->LoadImage(hBitmap, false);
562
 
 
563
 
        m_pMouseCursorSurface->CreateSurface(128, 128, true);
564
 
 
565
 
        InvalidateRect(hWnd, NULL, FALSE);
566
 
 
567
 
        return TRUE;
568
 
}
569
 
 
570
 
//===========================================================//
571
 
// WinMain()
572
 
//===========================================================//
573
 
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
574
 
{
575
 
    MSG         msg;
576
 
        HACCEL  hAccelTable;
577
 
 
578
 
        hInst = hInstance;
579
 
 
580
 
    InitApp(hInstance, nCmdShow);
581
 
        ZeroMemory(&ddbltfx, sizeof(ddbltfx));
582
 
        ddbltfx.dwSize = sizeof(ddbltfx);
583
 
        ddbltfx.dwFillColor = RGB(128, 128, 128);
584
 
 
585
 
        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);
586
 
        while (GetMessage(&msg, NULL, 0, 0)) {
587
 
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
588
 
                        TranslateMessage(&msg);
589
 
                        DispatchMessage(&msg);
590
 
                }
591
 
        }
592
 
 
593
 
        delete m_pMainSurface;
594
 
        delete m_pMouseCursorSurface;
595
 
        delete m_pBackgroundSurface;
596
 
 
597
 
    return msg.wParam;
598
 
}
599
 
 
600
 
 
601
 
BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
602
 
{
603
 
    switch (message)
604
 
        {
605
 
                // Initialize the dialog box
606
 
            case WM_INITDIALOG:
607
 
                {
608
 
                        int i;
609
 
                        ILenum ilError;
610
 
                        char VersionNum[256];
611
 
 
612
 
                        sprintf(VersionNum, "Num:  %d", ilGetInteger(IL_VERSION_NUM));
613
 
 
614
 
                        // ilGetString demo
615
 
                        SetDlgItemText(hDlg, IDC_ABOUT_VENDOR, ilGetString(IL_VENDOR));
616
 
                        SetDlgItemText(hDlg, IDC_ABOUT_VER_STRING, ilGetString(IL_VERSION));
617
 
                        SetDlgItemText(hDlg, IDC_ABOUT_VER_NUM, VersionNum);
618
 
 
619
 
                        // Display any recent error messages
620
 
                        for (i = 0; i < 6; i++) {
621
 
                                ilError = ilGetError();
622
 
                                if (ilError == IL_NO_ERROR)
623
 
                                        break;
624
 
                                SetDlgItemText(hDlg, IDC_ERROR1+i, iluErrorString(ilError));
625
 
                        }
626
 
 
627
 
                        return (TRUE);
628
 
                }
629
 
                break;
630
 
 
631
 
                // Process command messages
632
 
            case WM_COMMAND:      
633
 
                {
634
 
                        // Validate and Make the changes
635
 
                        if (LOWORD(wParam) == IDOK)
636
 
                                EndDialog(hDlg, TRUE);
637
 
                        if (LOWORD(wParam) == IDCANCEL)
638
 
                                EndDialog(hDlg, FALSE);
639
 
            }
640
 
                break;
641
 
 
642
 
                // Closed from sysbox
643
 
                case WM_CLOSE:
644
 
                        EndDialog(hDlg,TRUE);
645
 
                break;
646
 
        }
647
 
 
648
 
        return FALSE;
649
 
}
650
 
 
651
 
 
652
 
// Dialog procedure.
653
 
BOOL APIENTRY FilterDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
654
 
{
655
 
        char EditString[255];
656
 
 
657
 
    switch (message)
658
 
        {
659
 
                // Initialize the dialog box
660
 
            case WM_INITDIALOG:
661
 
                {
662
 
                        switch (FilterType)
663
 
                        {
664
 
                                case ID_FILTER_PIXELIZE:
665
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Width of pixelized block:");
666
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
667
 
                                        break;
668
 
                                case ID_FILTER_NOISE:
669
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Amount of noise threshold:");
670
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
671
 
                                        break;
672
 
                                case ID_FILTERS_BLUR_AVERAGE:
673
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of iterations:");
674
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
675
 
                                        break;
676
 
                                case ID_FILTERS_BLUR_GAUSSIAN:
677
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of iterations:");
678
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1");
679
 
                                        break;
680
 
                                case ID_FILTER_GAMMACORRECT:
681
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Amount of gamma correction:");
682
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1.0");
683
 
                                        break;
684
 
                                case ID_FILTER_SHARPEN:
685
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Sharpening factor:");
686
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "1.0");
687
 
                                        break;
688
 
                                case ID_EFFECTS_FILTERS_ROTATE:
689
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Number of degress to rotate:");
690
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "0.0");
691
 
                                        break;
692
 
 
693
 
                                case ID_EDIT_UNDOLEVEL:
694
 
                                        SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, "Set level of undo:");
695
 
                                        SetDlgItemText(hDlg, IDC_FILTER_EDIT, "4");
696
 
                                        break;
697
 
 
698
 
                        }
699
 
 
700
 
                        return TRUE;
701
 
                }
702
 
                break;
703
 
 
704
 
                // Process command messages
705
 
            case WM_COMMAND:
706
 
                {
707
 
                        // Validate and Make the changes
708
 
                        if (LOWORD(wParam) == IDOK) {
709
 
                                GetDlgItemText(hDlg, IDC_FILTER_EDIT, EditString, 255);
710
 
                                FilterParamInt = atoi(EditString);
711
 
                                FilterParamFloat = (float)atof(EditString);
712
 
                                EndDialog(hDlg, TRUE);
713
 
                        }
714
 
                        if (LOWORD(wParam) == IDCANCEL) {
715
 
                                EndDialog(hDlg, FALSE);
716
 
                        }
717
 
            }
718
 
                break;
719
 
 
720
 
                // Closed from sysbox
721
 
                case WM_CLOSE:
722
 
                        EndDialog(hDlg,TRUE);
723
 
                break;
724
 
        }
725
 
 
726
 
        return FALSE;
727
 
}
728
 
 
729
 
 
730
 
// Dialog procedure.
731
 
BOOL APIENTRY ResizeDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
732
 
{
733
 
        static char x[255], y[255], z[255];
734
 
        static ILuint xsize, ysize, zsize;
735
 
        static RECT Rect;
736
 
 
737
 
    switch (message)
738
 
        {
739
 
                // Initialize the dialog box
740
 
            case WM_INITDIALOG:
741
 
                {
742
 
                        sprintf(x, "%d", Width);
743
 
                        sprintf(y, "%d", Height);
744
 
                        sprintf(z, "%d", Depth);
745
 
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x);
746
 
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y);
747
 
                        SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z);
748
 
                        return TRUE;
749
 
                }
750
 
                break;
751
 
 
752
 
                // Process command messages
753
 
            case WM_COMMAND:
754
 
                {
755
 
                        // Validate and Make the changes
756
 
                        if (LOWORD(wParam) == IDOK) {
757
 
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x, 255);
758
 
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y, 255);
759
 
                                GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z, 255);
760
 
                                xsize = atoi(x);
761
 
                                ysize = atoi(y);
762
 
                                zsize = atoi(z);
763
 
                                if (xsize && ysize && zsize) {
764
 
                                        iluScale(xsize, ysize, zsize);
765
 
 
766
 
                                        Width = ilGetInteger(IL_IMAGE_WIDTH);
767
 
                                        Height = ilGetInteger(IL_IMAGE_HEIGHT);
768
 
                                        Depth = ilGetInteger(IL_IMAGE_DEPTH);
769
 
 
770
 
                                        GetWindowRect(m_MainHWND, &Rect);
771
 
                                        SetWindowPos(m_MainHWND, HWND_TOP, Rect.left, Rect.top,
772
 
                                                Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
773
 
                                                Height + MENU_H, SWP_SHOWWINDOW);
774
 
 
775
 
 
776
 
                                        InvalidateRect(m_MainHWND, NULL, FALSE);
777
 
                                }
778
 
                                EndDialog(hDlg, TRUE);
779
 
                        }
780
 
                        if (LOWORD(wParam) == IDCANCEL) {
781
 
                                EndDialog(hDlg, FALSE);
782
 
                        }
783
 
            }
784
 
                break;
785
 
 
786
 
                // Closed from sysbox
787
 
                case WM_CLOSE:
788
 
                        EndDialog(hDlg,TRUE);
789
 
                break;
790
 
        }
791
 
 
792
 
        return FALSE;
793
 
}
794
 
 
795
 
 
796
 
void GenFilterString(char *Out, char **Strings)
797
 
{
798
 
        int OutPos = 0, StringPos = 0;
799
 
 
800
 
        while (Strings[StringPos][0] != 0) {
801
 
                sprintf(Out + OutPos, Strings[StringPos]);
802
 
                OutPos += strlen(Strings[StringPos++]) + 1;
803
 
        }
804
 
 
805
 
        Out[OutPos++] = 0;
806
 
        Out[OutPos] = 0;
807
 
 
808
 
        return;
809
 
}