]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/common/RenderBumpFlatDialog.cpp
hello world
[icculus/iodoom3.git] / neo / tools / common / RenderBumpFlatDialog.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "../../sys/win32/common_resource.h"
33
34 idCVar rbfg_DefaultWidth( "rbfg_DefaultWidth", "0", 0, "" );
35 idCVar rbfg_DefaultHeight( "rbfg_DefaultHeight", "0", 0, "" );
36
37 static idStr RBFName;
38
39 static bool CheckPow2(int Num)
40 {
41         while(Num)
42         {
43                 if ((Num & 1) && (Num != 1))
44                 {
45                         return false;
46                 }
47
48                 Num >>= 1;
49         }
50
51         return true;
52 }
53
54 extern void Com_WriteConfigToFile( const char *filename );
55
56 static BOOL CALLBACK RBFProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) 
57 {  
58     switch (message) 
59     { 
60         case WM_INITDIALOG: 
61                         SetDlgItemInt(hwndDlg, IDC_RBF_WIDTH, rbfg_DefaultWidth.GetInteger(), FALSE);
62                         SetDlgItemInt(hwndDlg, IDC_RBF_HEIGHT, rbfg_DefaultHeight.GetInteger(), FALSE);
63                         SetDlgItemText(hwndDlg, IDC_RBF_FILENAME, RBFName);
64             return TRUE; 
65  
66         case WM_COMMAND: 
67             switch (LOWORD(wParam)) 
68             { 
69                 case IDOK: 
70                                         {
71                                                 int             width, height;
72
73                                                 width = GetDlgItemInt(hwndDlg, IDC_RBF_WIDTH, 0, FALSE);
74                                                 height = GetDlgItemInt(hwndDlg, IDC_RBF_HEIGHT, 0, FALSE);
75
76                                                 rbfg_DefaultWidth.SetInteger( width );
77                                                 rbfg_DefaultHeight.SetInteger( height );
78
79                                                 Com_WriteConfigToFile( CONFIG_FILE );
80
81                                                 if (!CheckPow2(width) || !CheckPow2(height))
82                                                 {
83                                                         return TRUE;
84                                                 }
85
86                                                 DestroyWindow(hwndDlg); 
87
88                                                 cmdSystem->BufferCommandText( CMD_EXEC_APPEND, va("renderbumpflat -size %d %d %s\n", width, height, RBFName.c_str() ) );
89                             return TRUE; 
90                                         }
91  
92                 case IDCANCEL: 
93                     DestroyWindow(hwndDlg); 
94                     return TRUE; 
95             } 
96     }
97
98     return FALSE; 
99
100
101 void DoRBFDialog(const char *FileName)
102 {
103         RBFName = FileName;
104
105         Sys_GrabMouseCursor( false );
106
107         DialogBox(0, MAKEINTRESOURCE(IDD_RENDERBUMPFLAT), 0, (DLGPROC)RBFProc); 
108
109         Sys_GrabMouseCursor( true );
110 }