-
Notifications
You must be signed in to change notification settings - Fork 0
/
WndDisplayTexture.cpp
195 lines (167 loc) · 5.22 KB
/
WndDisplayTexture.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
// WndDisplayTexture.cpp : implementation file
//
#include "StdH.h"
#include "WorldEditor.h"
#include "WndDisplayTexture.h"
#ifdef _DEBUG
#undef new
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWndDisplayTexture
CWndDisplayTexture::CWndDisplayTexture()
{
m_ptd=NULL;
m_pDrawPort = NULL;
m_pViewPort = NULL;
}
CWndDisplayTexture::~CWndDisplayTexture()
{
if( m_pViewPort != NULL)
{
_pGfx->DestroyWindowCanvas( m_pViewPort);
m_pViewPort = NULL;
}
}
BEGIN_MESSAGE_MAP(CWndDisplayTexture, CWnd)
//{{AFX_MSG_MAP(CWndDisplayTexture)
ON_WM_PAINT()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWndDisplayTexture message handlers
void CWndDisplayTexture::OnPaint()
{
{
CPaintDC dc(this); // device context for painting
}
POINT ptMouse;
GetCursorPos( &ptMouse);
ScreenToClient( &ptMouse);
// if there is a valid drawport, and the drawport can be locked
if( (m_pDrawPort != NULL) && (m_pDrawPort->Lock()) )
{
CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
ASSERT( pWorldEditorView != NULL);
// clear background
m_pDrawPort->Fill( C_vdGRAY|CT_OPAQUE);
// erase z-buffer
m_pDrawPort->FillZBuffer(ZBUF_BACK);
CTextureObject to;
to.SetData(m_ptd);
m_pDrawPort->PutTexture( &to, m_boxTexture);
m_pDrawPort->DrawBorder( 0,0, m_pDrawPort->GetWidth(),m_pDrawPort->GetHeight(), C_mdGRAY|CT_OPAQUE);
m_pDrawPort->SetFont( _pfdConsoleFont);
m_pDrawPort->SetTextAspect( 1.0f);
m_pDrawPort->SetTextScaling( 1.0f);
m_pDrawPort->PutTextCXY( m_strText1, m_boxText1.Center()(1), m_boxText1.Center()(2), C_YELLOW|CT_OPAQUE);
m_pDrawPort->PutTextCXY( m_strText2, m_boxText2.Center()(1), m_boxText2.Center()(2), C_GRAY|CT_OPAQUE);
// unlock the drawport
m_pDrawPort->Unlock();
// if there is a valid viewport
if (m_pViewPort!=NULL)
{
m_pViewPort->SwapBuffers();
}
}
}
BOOL CWndDisplayTexture::Initialize(PIX pixX, PIX pixY, CTextureData *ptd,
CTString strText1/*""*/, CTString strText2/*""*/, BOOL bDown/*=FALSE*/)
{
m_ptd=ptd;
m_strText1=strText1;
m_strText2=strText2;
// calculate window's size
CRect rectWindow;
rectWindow.left = pixX;
rectWindow.bottom = pixY;
PIX pixWidth=ptd->GetPixWidth();
PIX pixHeight=ptd->GetPixHeight();
PIX pixScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
PIX pixScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
if( pixX+pixWidth>pixScreenWidth)
{
pixX=pixScreenWidth-pixWidth;
}
if( pixY+pixHeight>pixScreenHeight)
{
pixY=pixScreenHeight-pixHeight;
}
m_boxTexture=PIXaabbox2D( PIX2D(0,0), PIX2D(pixWidth,pixHeight));
if( strText1!="")
{
pixHeight+=_pfdConsoleFont->fd_pixCharHeight+4;
}
m_boxText1=PIXaabbox2D( PIX2D(0,m_boxTexture.Max()(2)), PIX2D(pixWidth,pixHeight));
if( strText2!="")
{
pixHeight+=_pfdConsoleFont->fd_pixCharHeight+4;
}
m_boxText2=PIXaabbox2D( PIX2D(0,m_boxText1.Max()(2)), PIX2D(pixWidth,pixHeight));
rectWindow.right = rectWindow.left + pixWidth;
if( bDown)
{
rectWindow.top = rectWindow.bottom;
rectWindow.bottom+=pixHeight;
}
else
{
rectWindow.top = rectWindow.bottom - pixHeight;
}
if( IsWindow(m_hWnd))
{
SetWindowPos( NULL, rectWindow.left, rectWindow.top,
rectWindow.right-rectWindow.left, rectWindow.top-rectWindow.bottom,
SWP_NOZORDER | SWP_NOACTIVATE);
ShowWindow(SW_SHOW);
}
else
{
// create window
CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
BOOL bResult = CreateEx( WS_EX_TOOLWINDOW,
NULL, _T("Display texture"), WS_CHILD|WS_POPUP|WS_VISIBLE,
rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(),
pMainFrame->m_hWnd, NULL, NULL);
if( !bResult)
{
AfxMessageBox( _T("Error: Failed to create display texture window!"));
return FALSE;
}
_pGfx->CreateWindowCanvas( m_hWnd, &m_pViewPort, &m_pDrawPort);
}
return TRUE;
}
void CWndDisplayTexture::OnKillFocus(CWnd* pNewWnd)
{
CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
if(pNewWnd!=pMainFrame->m_pwndToolTip && pNewWnd!=this)
{
DestroyWindow();
DeleteTempMap();
}
}
BOOL CWndDisplayTexture::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_ESCAPE)
{
DestroyWindow();
DeleteTempMap();
return TRUE;
}
return CWnd::PreTranslateMessage(pMsg);
}