]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/MediaPreviewDlg.cpp
hello world
[icculus/iodoom3.git] / neo / tools / radiant / MediaPreviewDlg.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 "qe3.h"
33 #include "Radiant.h"
34 #include "mediapreviewdlg.h"
35
36
37 // CMediaPreviewDlg dialog
38
39 IMPLEMENT_DYNAMIC(CMediaPreviewDlg, CDialog)
40 CMediaPreviewDlg::CMediaPreviewDlg(CWnd* pParent /*=NULL*/)
41         : CDialog(CMediaPreviewDlg::IDD, pParent)
42 {
43         mode = MATERIALS;
44         media = "";
45 }
46
47 void CMediaPreviewDlg::SetMedia(const char *_media) {
48         media = _media;
49         Refresh();
50 }
51
52 void CMediaPreviewDlg::Refresh() {
53         if (mode == GUIS) {
54                 const idMaterial *mat = declManager->FindMaterial("guisurfs/guipreview");
55                 mat->SetGui( media );
56                 drawMaterial.setMedia("guisurfs/guipreview");
57                 drawMaterial.setScale( 4.4f );
58         } else {
59                 drawMaterial.setMedia(media);
60                 drawMaterial.setScale( 1.0f );
61         }
62         wndPreview.setDrawable(&drawMaterial);
63         wndPreview.Invalidate();
64         wndPreview.RedrawWindow();
65         RedrawWindow();
66 }
67
68 CMediaPreviewDlg::~CMediaPreviewDlg()
69 {
70 }
71
72 void CMediaPreviewDlg::DoDataExchange(CDataExchange* pDX)
73 {
74         CDialog::DoDataExchange(pDX);
75         DDX_Control(pDX, IDC_PREVIEW, wndPreview);
76 }
77
78
79 BEGIN_MESSAGE_MAP(CMediaPreviewDlg, CDialog)
80         ON_WM_SIZE()
81         ON_WM_DESTROY()
82         ON_WM_LBUTTONDOWN()
83         ON_WM_LBUTTONUP()
84         ON_WM_MOUSEMOVE()
85 END_MESSAGE_MAP()
86
87
88 // CMediaPreviewDlg message handlers
89
90 BOOL CMediaPreviewDlg::OnInitDialog()
91 {
92         CDialog::OnInitDialog();
93
94         wndPreview.setDrawable(&testDrawable);
95         CRect rct;
96         LONG lSize = sizeof(rct);
97         if (LoadRegistryInfo("Radiant::EditPreviewWindow", &rct, &lSize))  {
98                 SetWindowPos(NULL, rct.left, rct.top, rct.Width(), rct.Height(), SWP_SHOWWINDOW);
99         }
100
101         GetClientRect(rct);
102         int h = (mode == GUIS) ? (rct.Width() - 8) / 1.333333f : rct.Height() - 8;
103         wndPreview.SetWindowPos(NULL, 4, 4, rct.Width() - 8, h, SWP_SHOWWINDOW);
104         
105         return TRUE;  // return TRUE unless you set the focus to a control
106         // EXCEPTION: OCX Property Pages should return FALSE
107 }
108
109 void CMediaPreviewDlg::OnSize(UINT nType, int cx, int cy)
110 {
111         CDialog::OnSize(nType, cx, cy);
112         if (wndPreview.GetSafeHwnd() == NULL) {
113                 return;
114         }
115         CRect rect;
116         GetClientRect(rect);
117         //int h = (mode == GUIS) ? (rect.Width() - 8) / 1.333333f : rect.Height() - 8;
118         int h = rect.Height() - 8;
119         wndPreview.SetWindowPos(NULL, 4, 4, rect.Width() - 8, h, SWP_SHOWWINDOW);
120 }
121
122 void CMediaPreviewDlg::OnDestroy()
123 {
124         if (GetSafeHwnd()) {
125                 CRect rct;
126                 GetWindowRect(rct);
127                 SaveRegistryInfo("Radiant::EditPreviewWindow", &rct, sizeof(rct));
128         }
129
130         CDialog::OnDestroy();
131 }
132
133 void CMediaPreviewDlg::OnLButtonDown(UINT nFlags, CPoint point)
134 {
135         if (mode == GUIS) {
136                 idUserInterface *gui = uiManager->FindGui( media );
137                 if (gui) {
138                         sysEvent_t  ev;
139                         memset( &ev, 0, sizeof( ev ) );
140                         ev.evType = SE_KEY;
141                         ev.evValue = K_MOUSE1;
142                         ev.evValue2 = 1;
143                         gui->HandleEvent(&ev,0);
144                 }
145         }
146         CDialog::OnLButtonDown(nFlags, point);
147 }
148
149 void CMediaPreviewDlg::OnLButtonUp(UINT nFlags, CPoint point)
150 {
151         if (mode == GUIS) {
152                 idUserInterface *gui = uiManager->FindGui( media );
153                 if (gui) {
154                         sysEvent_t  ev;
155                         memset( &ev, 0, sizeof( ev ) );
156                         ev.evType = SE_KEY;
157                         ev.evValue = K_MOUSE1;
158                         ev.evValue2 = 0;
159                         gui->HandleEvent(&ev,0);
160                 }
161         }
162         CDialog::OnLButtonUp(nFlags, point);
163 }
164
165 void CMediaPreviewDlg::OnMouseMove(UINT nFlags, CPoint point)
166 {
167         if (mode == GUIS) {
168                 idUserInterface *gui = uiManager->FindGui( media );
169                 if (gui) {
170                         CRect rct;
171                         wndPreview.GetClientRect(rct);
172                         sysEvent_t  ev;
173                         memset( &ev, 0, sizeof( ev ) );
174                         ev.evType = SE_MOUSE;
175                         ev.evValue = (point.x / rct.Width()) * 640.0f;
176                         ev.evValue2 = (point.y / rct.Height()) * 480.0f;
177                         gui->HandleEvent(&ev, 0);
178                 }
179         }
180         CDialog::OnMouseMove(nFlags, point);
181 }