doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MediaPreviewDlg.cpp
Go to the documentation of this file.
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 
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 {
60  drawMaterial.setScale( 1.0f );
61  }
63  wndPreview.Invalidate();
64  wndPreview.RedrawWindow();
65  RedrawWindow();
66 }
67 
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 
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) {
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) {
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) {
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 }
virtual void setMedia(const char *name)
Definition: GLWidget.cpp:476
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
virtual ~CMediaPreviewDlg()
idGLDrawableMaterial drawMaterial
afx_msg void OnLButtonUp(UINT nFlags, CPoint point)
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
bool LoadRegistryInfo(const char *pszName, void *pvBuf, long *plSize)
Definition: Radiant.cpp:405
idUserInterfaceManager * uiManager
#define IDC_PREVIEW
#define BOOL
Definition: mprintf.c:71
virtual const char * HandleEvent(const sysEvent_t *event, int time, bool *updateVisuals=NULL)=0
void setDrawable(idGLDrawable *d)
Definition: GLWidget.cpp:801
virtual idUserInterface * FindGui(const char *qpath, bool autoLoad=false, bool needUnique=false, bool forceUnique=false)=0
#define NULL
Definition: Lib.h:88
int evValue2
Definition: sys_public.h:218
GLint mode
Definition: glext.h:4165
afx_msg void OnDestroy()
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
void SetMedia(const char *_media)
bool SaveRegistryInfo(const char *pszName, void *pvBuf, long lSize)
Definition: Radiant.cpp:398
void setScale(float f)
Definition: GLWidget.h:58
sysEventType_t evType
Definition: sys_public.h:216
virtual void DoDataExchange(CDataExchange *pDX)
idDeclManager * declManager
long LONG
string media
Definition: prepare.py:6
tuple f
Definition: idal.py:89
void SetGui(const char *_gui) const
Definition: Material.cpp:2111
idGLWidget wndPreview
#define TRUE
Definition: mprintf.c:69
afx_msg void OnSize(UINT nType, int cx, int cy)