Rise
The Vieneo Province
Loading...
Searching...
No Matches
Controls.cpp
Go to the documentation of this file.
1//--------------------------------------------------------------------------------------
2// File: UIgui.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//--------------------------------------------------------------------------------------
7#include "Controls.h"
8#pragma warning(disable:4100)
9
10
11#undef min // use __min instead
12#undef max // use __max instead
13
14#ifndef WM_XBUTTONDOWN
15#define WM_XBUTTONDOWN 0x020B // (not always defined)
16#endif
17#ifndef WM_XBUTTONUP
18#define WM_XBUTTONUP 0x020C // (not always defined)
19#endif
20#ifndef WM_MOUSEWHEEL
21#define WM_MOUSEWHEEL 0x020A // (not always defined)
22#endif
23#ifndef WHEEL_DELTA
24#define WHEEL_DELTA 120 // (not always defined)
25#endif
26
27// Minimum scroll bar thumb size
28#define SCROLLBAR_MINTHUMBSIZE 8
29
30// Delay and repeat period when clicking on the scroll bar arrows
31#define SCROLLBAR_ARROWCLICK_DELAY 0.33
32#define SCROLLBAR_ARROWCLICK_REPEAT 0.05
33
34#define UI_NEAR_BUTTON_DEPTH 0.6f
35#define UI_FAR_BUTTON_DEPTH 0.8f
36
37#define UI_MAX_GUI_SPRITES 500
38
40{
41 RiseMath::Color cv = { ((c >> 16) & 0xFF) / 255.0f,
42 ((c >> 8) & 0xFF) / 255.0f,
43 (c & 0xFF) / 255.0f,
44 ((c >> 24) & 0xFF) / 255.0f };
45 return cv;
46}
47
48#define UNISCRIBE_DLLNAME L"usp10.dll"
49
50#define GETPROCADDRESS( Module, APIName, Temp ) \
51 Temp = GetProcAddress( Module, #APIName ); \
52 if( Temp ) \
53 *(FARPROC*)&_##APIName = Temp
54
55#define PLACEHOLDERPROC( APIName ) \
56 _##APIName = Dummy_##APIName
57
58#define IMM32_DLLNAME L"imm32.dll"
59#define VER_DLLNAME L"version.dll"
60
61
62
63
64// UI_MAX_EDITBOXLENGTH is the maximum string length allowed in edit boxes,
65// including the NULL terminator.
66//
67// Uniscribe does not support strings having bigger-than-16-bits length.
68// This means that the string must be less than 65536 characters long,
69// including the NULL terminator.
70#define UI_MAX_EDITBOXLENGTH 0xFFFF
71
72
73double RiseDialog::s_fTimeRefresh = 0.0f;
74RiseControl* RiseDialog::s_pControlFocus = NULL; // The control which has focus
75RiseControl* RiseDialog::s_pControlPressed = NULL; // The control currently pressed
76
77
79{
80 float x, y, z, h;
82 float tu, tv;
83
84 static DWORD FVF;
85};
87
88
97
98
99
100
101
102inline int RectWidth(RECT& rc)
103{
104 return ((rc).right - (rc).left);
105}
106inline int RectHeight(RECT& rc)
107{
108 return ((rc).bottom - (rc).top);
109}
110
111
112
113//--------------------------------------------------------------------------------------
114// RiseDialog class
115//--------------------------------------------------------------------------------------
116
117//--------------------------------------------------------------------------------------
119{
120 m_x = 0;
121 m_y = 0;
122 m_width = 0;
123 m_height = 0;
124
125 m_pManager = NULL;
126 m_bVisible = true;
127 m_bCaption = false;
128 m_bMinimized = false;
129 m_bDrag = false;
130 m_wszCaption[0] = L'\0';
131 m_nCaptionHeight = 18;
132
133 m_colorTopLeft = 0;
134 m_colorTopRight = 0;
137
138 m_pCallbackEvent = NULL;
140
142
143 m_pControlMouseOver = NULL;
144
145 m_pNextDialog = this;
146 m_pPrevDialog = this;
147
148 m_nDefaultControlID = 0xffff;
149 m_bNonUserEvents = false;
150 m_bKeyboardInput = false;
151 m_bMouseInput = true;
152}
153
154
155//--------------------------------------------------------------------------------------
157{
158 int i = 0;
159
161
164
165 for (i = 0; i < m_DefaultElements.GetSize(); i++)
166 {
167 UIElementHolder* pElementHolder = m_DefaultElements.GetAt(i);
168 SAFE_DELETE(pElementHolder);
169 }
170
172}
173
174
175//--------------------------------------------------------------------------------------
176void RiseDialog::Init(RiseDialogResourceManager* pManager, bool bRegisterDialog)
177{
178 m_pManager = pManager;
179 if (bRegisterDialog)
180 pManager->RegisterDialog(this);
181
182 SetTexture(0, MAKEINTRESOURCE(0xFFFF), (HMODULE)0xFFFF);
184}
185
186
187//--------------------------------------------------------------------------------------
188void RiseDialog::Init(RiseDialogResourceManager* pManager, bool bRegisterDialog, LPCWSTR pszControlTextureFilename)
189{
190 m_pManager = pManager;
191 if (bRegisterDialog)
192 pManager->RegisterDialog(this);
193 SetTexture(0, pszControlTextureFilename);
195}
196
197
198//--------------------------------------------------------------------------------------
199void RiseDialog::Init(RiseDialogResourceManager* pManager, bool bRegisterDialog,
200 LPCWSTR szControlTextureResourceName, HMODULE hControlTextureResourceModule)
201{
202 m_pManager = pManager;
203 if (bRegisterDialog)
204 pManager->RegisterDialog(this);
205
206 SetTexture(0, szControlTextureResourceName, hControlTextureResourceModule);
208}
209
210
211//--------------------------------------------------------------------------------------
212void RiseDialog::SetCallback(UICallback pCallback, void* pUserContext)
213{
214 // If this assert triggers, you need to call RiseDialog::Init() first. This change
215 // was made so that the DXUT's GUI could become seperate and optional from DXUT's core. The
216 // creation and interfacing with RiseDialogResourceManager is now the responsibility
217 // of the application if it wishes to use DXUT's GUI.
218 assert(m_pManager != NULL && L"To fix call RiseDialog::Init() first. See comments for details.");
219
220 m_pCallbackEvent = pCallback;
221 m_pCallbackEventUserContext = pUserContext;
222}
223
224
225//--------------------------------------------------------------------------------------
227{
228 for (int i = 0; i < m_Controls.GetSize(); i++)
229 {
230 RiseControl* pControl = m_Controls.GetAt(i);
231 if (pControl->GetID() == ID)
232 {
233 // Clean focus first
234 ClearFocus();
235
236 // Clear references to this control
237 if (s_pControlFocus == pControl)
238 s_pControlFocus = NULL;
239 if (s_pControlPressed == pControl)
240 s_pControlPressed = NULL;
241 if (m_pControlMouseOver == pControl)
242 m_pControlMouseOver = NULL;
243
244 SAFE_DELETE(pControl);
246
247 return;
248 }
249 }
250}
251
252
253//--------------------------------------------------------------------------------------
255{
257 s_pControlFocus = NULL;
259 s_pControlPressed = NULL;
260 m_pControlMouseOver = NULL;
261
262 for (int i = 0; i < m_Controls.GetSize(); i++)
263 {
264 RiseControl* pControl = m_Controls.GetAt(i);
265 SAFE_DELETE(pControl);
266 }
267
269}
270
271
272//--------------------------------------------------------------------------------------
274{
275 // Begin D3D9-specific
276 m_renderer = NULL;
277 m_pStateBlock = NULL;
278 m_pSprite = NULL;
279 // End D3D9-specific
280}
281
282
283//--------------------------------------------------------------------------------------
285{
286 int i;
287 for (i = 0; i < m_FontCache.GetSize(); i++)
288 {
289 UIFontNode* pFontNode = m_FontCache.GetAt(i);
290 SAFE_DELETE(pFontNode);
291 }
293
294 for (i = 0; i < m_TextureCache.GetSize(); i++)
295 {
296 UITextureNode* pTextureNode = m_TextureCache.GetAt(i);
297 SAFE_DELETE(pTextureNode);
298 }
300
302}
303
304
305//--------------------------------------------------------------------------------------
307{
308 HRESULT hr = S_OK;
309 int i = 0;
310
311 m_renderer = pd3dDevice;
312
313 for (i = 0; i < m_FontCache.GetSize(); i++)
314 {
315 hr = CreateFont(i);
316 if (FAILED(hr))
317 return hr;
318 }
319
320 for (i = 0; i < m_TextureCache.GetSize(); i++)
321 {
322 hr = CreateTexture(i);
323 if (FAILED(hr))
324 return hr;
325 }
326
327 hr = Rendering::CreateSprite(pd3dDevice, &m_pSprite);
328 if (FAILED(hr))
329 return Rendering::TraceFailure(L"Rendering::CreateSprite", hr);
330
331 return S_OK;
332}
333
334
335//--------------------------------------------------------------------------------------
337{
338 HRESULT hr = S_OK;
339
340 for (int i = 0; i < m_FontCache.GetSize(); i++)
341 {
342 UIFontNode* pFontNode = m_FontCache.GetAt(i);
343
344 if (pFontNode->font)
345 pFontNode->font->OnResetDevice();
346 }
347
348 if (m_pSprite)
350
352
353 return S_OK;
354}
355
356//--------------------------------------------------------------------------------------
357bool RiseDialogResourceManager::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
358{
359 return false;
360}
361
362
363//--------------------------------------------------------------------------------------
365{
366 for (int i = 0; i < m_FontCache.GetSize(); i++)
367 {
368 UIFontNode* pFontNode = m_FontCache.GetAt(i);
369
370 if (pFontNode->font)
371 pFontNode->font->OnLostDevice();
372 }
373
374 if (m_pSprite)
376
378}
379
380
381//--------------------------------------------------------------------------------------
383{
384 int i = 0;
385
386 m_renderer = NULL;
387
388 // Release the resources but don't clear the cache, as these will need to be
389 // recreated if the device is recreated
390 for (i = 0; i < m_FontCache.GetSize(); i++)
391 {
392 UIFontNode* pFontNode = m_FontCache.GetAt(i);
393 SAFE_RELEASE(pFontNode->font);
394 }
395
396 for (i = 0; i < m_TextureCache.GetSize(); i++)
397 {
398 UITextureNode* pTextureNode = m_TextureCache.GetAt(i);
399 SAFE_RELEASE(pTextureNode->texture);
400 }
401
403}
404
405
406//--------------------------------------------------------------------------------------
407
408
409
410//--------------------------------------------------------------------------------------
411
412
413
414//--------------------------------------------------------------------------------------
415
416
417
418//--------------------------------------------------------------------------------------
419
420
421
422//--------------------------------------------------------------------------------------
424{
425 // Check that the dialog isn't already registered.
426 for (int i = 0; i < m_Dialogs.GetSize(); ++i)
427 if (m_Dialogs.GetAt(i) == pDialog)
428 return true;
429
430 // Add to the list.
431 if (FAILED(m_Dialogs.Add(pDialog)))
432 return false;
433
434 // Set up next and prev pointers.
435 if (m_Dialogs.GetSize() > 1)
436 m_Dialogs[m_Dialogs.GetSize() - 2]->SetNextDialog(pDialog);
437 m_Dialogs[m_Dialogs.GetSize() - 1]->SetNextDialog(m_Dialogs[0]);
438
439 return true;
440}
441
442
443//--------------------------------------------------------------------------------------
445{
446 // Search for the dialog in the list.
447 for (int i = 0; i < m_Dialogs.GetSize(); ++i)
448 if (m_Dialogs.GetAt(i) == pDialog)
449 {
450 m_Dialogs.Remove(i);
451 if (m_Dialogs.GetSize() > 0)
452 {
453 int l, r;
454
455 if (0 == i)
456 l = m_Dialogs.GetSize() - 1;
457 else
458 l = i - 1;
459
460 if (m_Dialogs.GetSize() == i)
461 r = 0;
462 else
463 r = i;
464
465 m_Dialogs[l]->SetNextDialog(m_Dialogs[r]);
466 }
467 return;
468 }
469}
470
471
472//--------------------------------------------------------------------------------------
474{
475 // Enable keyboard input for all registered dialogs
476 for (int i = 0; i < m_Dialogs.GetSize(); ++i)
477 m_Dialogs[i]->EnableKeyboardInput(true);
478}
479
480
481//--------------------------------------------------------------------------------------
483{
484 if (s_pControlFocus)
486
489
490 s_pControlFocus = NULL;
491 s_pControlPressed = NULL;
492 m_pControlMouseOver = NULL;
493
494 for (int i = 0; i < m_Controls.GetSize(); i++)
495 {
496 RiseControl* pControl = m_Controls.GetAt(i);
497 pControl->Refresh();
498 }
499
502}
503
504
505//--------------------------------------------------------------------------------------
506
507
508
509//--------------------------------------------------------------------------------------
510void RiseDialog::AppendVisibleBounds(std::vector<RECT>& rectangles) const
511{
512 if (!m_bVisible)return;
513 if (m_bCaption)rectangles.push_back({m_x,m_y,m_x+m_width,m_y+m_nCaptionHeight});
514 if (m_bMinimized)return;
516 rectangles.push_back({m_x,m_y,m_x+m_width,m_y+m_height});
517 for (int i=0;i<m_Controls.GetSize();++i)
518 {
519 const auto* control=m_Controls.GetAt(i);
520 if (!control->m_bVisible || control->m_width<=0 || control->m_height<=0)continue;
521 const int x=m_x+control->m_x,y=m_y+control->m_y+(m_bCaption ? m_nCaptionHeight : 0);
522 rectangles.push_back({x,y,x+control->m_width,y+control->m_height});
523 }
524}
525
526HRESULT RiseDialog::OnRender(float fElapsedTime)
527{
528 // If this assert triggers, you need to call RiseDialogResourceManager::On*Device() from inside
529 // the application's device callbacks. See the SDK samples for an example of how to do this.
531 L"To fix hook up RiseDialogResourceManager to device callbacks. See comments for details");
532
533 // See if the dialog needs to be refreshed
535 {
537 Refresh();
538 }
539
540 // For invisible dialog, out now.
541 if (!m_bVisible ||
543 return S_OK;
544
546
547 // Set up a state block here and restore it when finished drawing all the controls
549
563
571
573 0xff000000;
574 if (!m_bMinimized && bBackgroundIsVisible)
575 {
576 UI_SCREEN_VERTEX_UNTEX vertices[4] =
577 {
578 (float)m_x, (float)m_y, 0.5f, 1.0f, m_colorTopLeft,
579 (float)m_x + m_width, (float)m_y, 0.5f, 1.0f, m_colorTopRight,
580 (float)m_x + m_width, (float)m_y + m_height, 0.5f, 1.0f, m_colorBottomRight,
581 (float)m_x, (float)m_y + m_height, 0.5f, 1.0f, m_colorBottomLeft,
582 };
583
584 pd3dDevice->SetVertexShader(NULL);
585 pd3dDevice->SetPixelShader(NULL);
586
588
591 }
592
596
600
602
603 UITextureNode* pTextureNode = GetTexture(0);
604 pd3dDevice->SetTexture(0, pTextureNode->texture);
605
607
608 // Render the caption if it's enabled.
609 if (m_bCaption)
610 {
611 // DrawSprite will offset the rect down by
612 // m_nCaptionHeight, so adjust the rect higher
613 // here to negate the effect.
614 RECT rc = { 0, -m_nCaptionHeight, m_width, 0 };
616 rc.left += 5; // Make a left margin
617 WCHAR wszOutput[256];
618 wcscpy_s(wszOutput, 256, m_wszCaption);
619 if (m_bMinimized)
620 wcscat_s(wszOutput, 256, L" (Minimized)");
621 DrawText(wszOutput, &m_CapElement, &rc, true);
622 }
623
624 // If the dialog is minimized, skip rendering
625 // its controls.
626 if (!m_bMinimized)
627 {
628 for (int i = 0; i < m_Controls.GetSize(); i++)
629 {
630 RiseControl* pControl = m_Controls.GetAt(i);
631
632 // Focused control is drawn last
633 if (pControl == s_pControlFocus)
634 continue;
635
636 pControl->Render(fElapsedTime);
637 }
638
639 if (s_pControlFocus != NULL && s_pControlFocus->m_pDialog == this)
640 s_pControlFocus->Render(fElapsedTime);
641 }
642
644
646
647 return S_OK;
648}
649
650
651//--------------------------------------------------------------------------------------
652
653
654//--------------------------------------------------------------------------------------
655VOID RiseDialog::SendEvent(UINT nEvent, bool bTriggeredByUser, RiseControl* pControl)
656{
657 // If no callback has been registered there's nowhere to send the event to
658 if (m_pCallbackEvent == NULL)
659 return;
660
661 // Discard events triggered programatically if these types of events haven't been
662 // enabled
663 if (!bTriggeredByUser && !m_bNonUserEvents)
664 return;
665
666 m_pCallbackEvent(nEvent, pControl->GetID(), pControl, m_pCallbackEventUserContext);
667}
668
669
670//--------------------------------------------------------------------------------------
671int RiseDialogResourceManager::AddFont(LPCWSTR strFaceName, LONG height, LONG weight)
672{
673 // See if this font already exists
674 for (int i = 0; i < m_FontCache.GetSize(); i++)
675 {
676 UIFontNode* pFontNode = m_FontCache.GetAt(i);
677 size_t nLen = 0;
678 nLen = wcslen(strFaceName);
679 if (0 == _wcsnicmp(pFontNode->strFace, strFaceName, nLen) &&
680 pFontNode->nHeight == height &&
681 pFontNode->nWeight == weight)
682 {
683 return i;
684 }
685 }
686
687 // Add a new font and try to create it
688 UIFontNode* pNewFontNode = new UIFontNode;
689 if (pNewFontNode == NULL)
690 return -1;
691
692 ZeroMemory(pNewFontNode, sizeof(UIFontNode));
693 wcscpy_s(pNewFontNode->strFace, MAX_PATH, strFaceName);
694 pNewFontNode->nHeight = height;
695 pNewFontNode->nWeight = weight;
696 m_FontCache.Add(pNewFontNode);
697
698 int iFont = m_FontCache.GetSize() - 1;
699
700 // If a device is available, try to create immediately
701 if (m_renderer)
702 CreateFont(iFont);
703
704 return iFont;
705}
706
707
708//--------------------------------------------------------------------------------------
709HRESULT RiseDialog::SetFont(UINT index, LPCWSTR strFaceName, LONG height, LONG weight)
710{
711 // If this assert triggers, you need to call RiseDialog::Init() first. This change
712 // was made so that the DXUT's GUI could become seperate and optional from DXUT's core. The
713 // creation and interfacing with RiseDialogResourceManager is now the responsibility
714 // of the application if it wishes to use DXUT's GUI.
715 assert(m_pManager != NULL && L"To fix call RiseDialog::Init() first. See comments for details.");
716
717 // Make sure the list is at least as large as the index being set
718 UINT i;
719 for (i = m_Fonts.GetSize(); i <= index; i++)
720 {
721 m_Fonts.Add(-1);
722 }
723
724 int iFont = m_pManager->AddFont(strFaceName, height, weight);
725 m_Fonts.SetAt(index, iFont);
726
727 return S_OK;
728}
729
730
731//--------------------------------------------------------------------------------------
733{
734 if (NULL == m_pManager)
735 return NULL;
736 return m_pManager->GetFontNode(m_Fonts.GetAt(index));
737}
738
739
740//--------------------------------------------------------------------------------------
742{
743 // See if this texture already exists
744 for (int i = 0; i < m_TextureCache.GetSize(); i++)
745 {
746 UITextureNode* pTextureNode = m_TextureCache.GetAt(i);
747 size_t nLen = 0;
748 nLen = wcslen(strFilename);
749 if (pTextureNode->bFileSource && // Sources must match
750 0 == _wcsnicmp(pTextureNode->strFilename, strFilename, nLen))
751 {
752 return i;
753 }
754 }
755
756 // Add a new texture and try to create it
757 UITextureNode* pNewTextureNode = new UITextureNode;
758 if (pNewTextureNode == NULL)
759 return -1;
760
761 ZeroMemory(pNewTextureNode, sizeof(UITextureNode));
762 pNewTextureNode->bFileSource = true;
763 wcscpy_s(pNewTextureNode->strFilename, MAX_PATH, strFilename);
764
765 m_TextureCache.Add(pNewTextureNode);
766
767 int iTexture = m_TextureCache.GetSize() - 1;
768
769 // If a device is available, try to create immediately
770 if (m_renderer)
771 CreateTexture(iTexture);
772
773 return iTexture;
774}
775
776
777//--------------------------------------------------------------------------------------
778int RiseDialogResourceManager::AddTexture(LPCWSTR strResourceName, HMODULE hResourceModule)
779{
780 // See if this texture already exists
781 for (int i = 0; i < m_TextureCache.GetSize(); i++)
782 {
783 UITextureNode* pTextureNode = m_TextureCache.GetAt(i);
784 if (!pTextureNode->bFileSource && // Sources must match
785 pTextureNode->hResourceModule == hResourceModule) // Module handles must match
786 {
787 if (IS_INTRESOURCE(strResourceName))
788 {
789 // Integer-based ID
790 if ((INT_PTR)strResourceName == pTextureNode->nResourceID)
791 return i;
792 }
793 else
794 {
795 // String-based ID
796 size_t nLen = 0;
797 nLen = wcslen(strResourceName);
798 if (0 == _wcsnicmp(pTextureNode->strFilename, strResourceName, nLen))
799 return i;
800 }
801 }
802 }
803
804 // Add a new texture and try to create it
805 UITextureNode* pNewTextureNode = new UITextureNode;
806 if (pNewTextureNode == NULL)
807 return -1;
808
809 ZeroMemory(pNewTextureNode, sizeof(UITextureNode));
810 pNewTextureNode->hResourceModule = hResourceModule;
811 if (IS_INTRESOURCE(strResourceName))
812 {
813 pNewTextureNode->nResourceID = (int)(size_t)strResourceName;
814 }
815 else
816 {
817 pNewTextureNode->nResourceID = 0;
818 wcscpy_s(pNewTextureNode->strFilename, MAX_PATH, strResourceName);
819 }
820
821 m_TextureCache.Add(pNewTextureNode);
822
823 int iTexture = m_TextureCache.GetSize() - 1;
824
825 // If a device is available, try to create immediately
826 if (m_renderer)
827 CreateTexture(iTexture);
828
829 return iTexture;
830}
831
832
833//--------------------------------------------------------------------------------------
834HRESULT RiseDialog::SetTexture(UINT index, LPCWSTR strFilename)
835{
836 // If this assert triggers, you need to call RiseDialog::Init() first. This change
837 // was made so that the DXUT's GUI could become seperate and optional from DXUT's core. The
838 // creation and interfacing with RiseDialogResourceManager is now the responsibility
839 // of the application if it wishes to use DXUT's GUI.
840 assert(m_pManager != NULL && L"To fix this, call RiseDialog::Init() first. See comments for details.");
841
842 // Make sure the list is at least as large as the index being set
843 for (UINT i = m_Textures.GetSize(); i <= index; i++)
844 {
845 m_Textures.Add(-1);
846 }
847
848 int iTexture = m_pManager->AddTexture(strFilename);
849
850 m_Textures.SetAt(index, iTexture);
851 return S_OK;
852}
853
854
855//--------------------------------------------------------------------------------------
856HRESULT RiseDialog::SetTexture(UINT index, LPCWSTR strResourceName, HMODULE hResourceModule)
857{
858 // If this assert triggers, you need to call RiseDialog::Init() first. This change
859 // was made so that the DXUT's GUI could become seperate and optional from DXUT's core. The
860 // creation and interfacing with RiseDialogResourceManager is now the responsibility
861 // of the application if it wishes to use DXUT's GUI.
862 assert(m_pManager != NULL && L"To fix this, call RiseDialog::Init() first. See comments for details.");
863
864 // Make sure the list is at least as large as the index being set
865 for (UINT i = m_Textures.GetSize(); i <= index; i++)
866 {
867 m_Textures.Add(-1);
868 }
869
870 int iTexture = m_pManager->AddTexture(strResourceName, hResourceModule);
871
872 m_Textures.SetAt(index, iTexture);
873 return S_OK;
874}
875
876
877//--------------------------------------------------------------------------------------
879{
880 if (NULL == m_pManager)
881 return NULL;
883}
884
885
886
887//--------------------------------------------------------------------------------------
888bool RiseDialog::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
889{
890 bool bHandled = false;
891
892 // For invisible dialog, do not handle anything.
893 if (!m_bVisible)
894 return false;
895
896 // If automation command-line switch is on, enable this dialog's keyboard input
897 // upon any key press or mouse click.
898 if (false &&
899 (WM_LBUTTONDOWN == uMsg || WM_LBUTTONDBLCLK == uMsg || WM_KEYDOWN == uMsg))
900 {
902 }
903
904 // If caption is enable, check for clicks in the caption area.
905 if (m_bCaption)
906 {
907 if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONDBLCLK)
908 {
909 POINT mousePoint = { short(LOWORD(lParam)), short(HIWORD(lParam)) };
910
911 if (mousePoint.x >= m_x && mousePoint.x < m_x + m_width &&
912 mousePoint.y >= m_y && mousePoint.y < m_y + m_nCaptionHeight)
913 {
914 m_bDrag = true;
915 SetCapture(Rendering::ClientWindow());
916 return true;
917 }
918 }
919 else if (uMsg == WM_LBUTTONUP && m_bDrag)
920 {
921 POINT mousePoint = { short(LOWORD(lParam)), short(HIWORD(lParam)) };
922
923 if (mousePoint.x >= m_x && mousePoint.x < m_x + m_width &&
924 mousePoint.y >= m_y && mousePoint.y < m_y + m_nCaptionHeight)
925 {
926 ReleaseCapture();
927 m_bDrag = false;
929 return true;
930 }
931 }
932 }
933
934 // If the dialog is minimized, don't send any messages to controls.
935 if (m_bMinimized)
936 return false;
937
938 // If a control is in focus, it belongs to this dialog, and it's enabled, then give
939 // it the first chance at handling the message.
940 if (s_pControlFocus &&
941 s_pControlFocus->m_pDialog == this &&
943 {
944 // If the control MsgProc handles it, then we don't.
945 if (s_pControlFocus->MsgProc(uMsg, wParam, lParam))
946 return true;
947 }
948
949 switch (uMsg)
950 {
951 case WM_SIZE:
952 case WM_MOVE:
953 {
954 // Handle sizing and moving messages so that in case the mouse cursor is moved out
955 // of an UI control because of the window adjustment, we can properly
956 // unhighlight the highlighted control.
957 POINT pt = { -1, -1 };
958 OnMouseMove(pt);
959 break;
960 }
961
962 case WM_ACTIVATEAPP:
963 // Call OnFocusIn()/OnFocusOut() of the control that currently has the focus
964 // as the application is activated/deactivated. This matches the Windows
965 // behavior.
966 if (s_pControlFocus &&
967 s_pControlFocus->m_pDialog == this &&
969 {
970 if (wParam)
972 else
974 }
975 break;
976
977 // Keyboard messages
978 case WM_KEYDOWN:
979 case WM_SYSKEYDOWN:
980 case WM_KEYUP:
981 case WM_SYSKEYUP:
982 case WM_CHAR: // added for hotkey support
983 {
984 if (!m_bKeyboardInput)
985 return false;
986
987 // If a control is in focus, it belongs to this dialog, and it's enabled, then give
988 // it the first chance at handling the message.
990 {
991 if (s_pControlFocus->HandleKeyboard(uMsg, wParam, lParam))
992 return true;
993 }
994
995 // Not yet handled, see if this matches a control's hotkey
996 // Activate the hotkey if the focus doesn't belong to an
997 // edit box.
999 {
1000 for (int i = 0; i < m_Controls.GetSize(); i++)
1001 {
1002 RiseControl* pControl = m_Controls.GetAt(i);
1003 if (pControl->GetHotkey() == wParam)
1004 {
1005 pControl->OnHotkey();
1006 return true;
1007 }
1008 }
1009 }
1010
1011 // Not yet handled, check for focus messages
1012 if (uMsg == WM_KEYDOWN)
1013 {
1014 // If keyboard input is not enabled, this message should be ignored
1015 if (!m_bKeyboardInput)
1016 return false;
1017
1018 switch (wParam)
1019 {
1020 case VK_RIGHT:
1021 case VK_DOWN:
1022 if (s_pControlFocus != NULL)
1023 {
1024 return OnCycleFocus(true);
1025 }
1026 break;
1027
1028 case VK_LEFT:
1029 case VK_UP:
1030 if (s_pControlFocus != NULL)
1031 {
1032 return OnCycleFocus(false);
1033 }
1034 break;
1035
1036 case VK_TAB:
1037 {
1038 bool bShiftDown = ((GetKeyState(VK_SHIFT) & 0x8000) != 0);
1039 return OnCycleFocus(!bShiftDown);
1040 }
1041 }
1042 }
1043
1044 break;
1045 }
1046
1047
1048 // Mouse messages
1049 case WM_MOUSEMOVE:
1050 case WM_LBUTTONDOWN:
1051 case WM_LBUTTONUP:
1052 case WM_MBUTTONDOWN:
1053 case WM_MBUTTONUP:
1054 case WM_RBUTTONDOWN:
1055 case WM_RBUTTONUP:
1056 case WM_XBUTTONDOWN:
1057 case WM_XBUTTONUP:
1058 case WM_LBUTTONDBLCLK:
1059 case WM_MBUTTONDBLCLK:
1060 case WM_RBUTTONDBLCLK:
1061 case WM_XBUTTONDBLCLK:
1062 case WM_MOUSEWHEEL:
1063 {
1064 // If not accepting mouse input, return false to indicate the message should still
1065 // be handled by the application (usually to move the camera).
1066 if (!m_bMouseInput)
1067 return false;
1068
1069 POINT mousePoint = { short(LOWORD(lParam)), short(HIWORD(lParam)) };
1070 mousePoint.x -= m_x;
1071 mousePoint.y -= m_y;
1072
1073 // If caption is enabled, offset the Y coordinate by the negative of its height.
1074 if (m_bCaption)
1075 mousePoint.y -= m_nCaptionHeight;
1076
1077 // If a control is in focus, it belongs to this dialog, and it's enabled, then give
1078 // it the first chance at handling the message.
1079 if (s_pControlFocus &&
1080 s_pControlFocus->m_pDialog == this &&
1082 {
1083 if (s_pControlFocus->HandleMouse(uMsg, mousePoint, wParam, lParam))
1084 return true;
1085 }
1086
1087 // Not yet handled, see if the mouse is over any controls
1088 RiseControl* pControl = GetControlAtPoint(mousePoint);
1089 if (pControl != NULL && pControl->GetEnabled())
1090 {
1091 bHandled = pControl->HandleMouse(uMsg, mousePoint, wParam, lParam);
1092 if (bHandled)
1093 return true;
1094 }
1095 else
1096 {
1097 // Mouse not over any controls in this dialog, if there was a control
1098 // which had focus it just lost it
1099 if (uMsg == WM_LBUTTONDOWN &&
1101 s_pControlFocus->m_pDialog == this)
1102 {
1104 s_pControlFocus = NULL;
1105 }
1106 }
1107
1108 // Still not handled, hand this off to the dialog. Return false to indicate the
1109 // message should still be handled by the application (usually to move the camera).
1110 switch (uMsg)
1111 {
1112 case WM_MOUSEMOVE:
1113 OnMouseMove(mousePoint);
1114 return false;
1115 }
1116
1117 break;
1118 }
1119
1120 case WM_CAPTURECHANGED:
1121 {
1122 // The application has lost mouse capture.
1123 // The dialog object may not have received
1124 // a WM_MOUSEUP when capture changed. Reset
1125 // m_bDrag so that the dialog does not mistakenly
1126 // think the mouse button is still held down.
1127 if ((HWND)lParam != hWnd)
1128 m_bDrag = false;
1129 }
1130 }
1131
1132 return false;
1133}
1134
1135//--------------------------------------------------------------------------------------
1137{
1138 // Search through all child controls for the first one which
1139 // contains the mouse point
1140 for (int i = 0; i < m_Controls.GetSize(); i++)
1141 {
1142 RiseControl* pControl = m_Controls.GetAt(i);
1143
1144 if (pControl == NULL)
1145 {
1146 continue;
1147 }
1148
1149 // We only return the current control if it is visible
1150 // and enabled. Because GetControlAtPoint() is used to do mouse
1151 // hittest, it makes sense to perform this filtering.
1152 if (pControl->ContainsPoint(pt) && pControl->GetEnabled() && pControl->GetVisible())
1153 {
1154 return pControl;
1155 }
1156 }
1157
1158 return NULL;
1159}
1160
1161
1162//--------------------------------------------------------------------------------------
1164{
1165 RiseControl* pControl = GetControl(ID);
1166 if (pControl == NULL)
1167 return false;
1168
1169 return pControl->GetEnabled();
1170}
1171
1172
1173
1174//--------------------------------------------------------------------------------------
1175void RiseDialog::SetControlEnabled(int ID, bool bEnabled)
1176{
1177 RiseControl* pControl = GetControl(ID);
1178 if (pControl == NULL)
1179 return;
1180
1181 pControl->SetEnabled(bEnabled);
1182}
1183
1184
1185//--------------------------------------------------------------------------------------
1187{
1188 s_pControlPressed = NULL;
1189 m_pControlMouseOver = NULL;
1190}
1191
1192
1193//--------------------------------------------------------------------------------------
1195{
1196 // Figure out which control the mouse is over now
1197 RiseControl* pControl = GetControlAtPoint(pt);
1198
1199 // If the mouse is still over the same control, nothing needs to be done
1200 if (pControl == m_pControlMouseOver)
1201 return;
1202
1203 // Handle mouse leaving the old control
1206
1207 // Handle mouse entering the new control
1208 m_pControlMouseOver = pControl;
1209 if (pControl != NULL)
1211}
1212
1213
1214//--------------------------------------------------------------------------------------
1215HRESULT RiseDialog::SetDefaultElement(UINT nControlType, UINT iElement, RiseElement* pElement)
1216{
1217 // If this Element type already exist in the list, simply update the stored Element
1218 for (int i = 0; i < m_DefaultElements.GetSize(); i++)
1219 {
1220 UIElementHolder* pElementHolder = m_DefaultElements.GetAt(i);
1221
1222 if (pElementHolder->nControlType == nControlType &&
1223 pElementHolder->iElement == iElement)
1224 {
1225 pElementHolder->Element = *pElement;
1226 return S_OK;
1227 }
1228 }
1229
1230 // Otherwise, add a new entry
1231 UIElementHolder* pNewHolder;
1232 pNewHolder = new UIElementHolder;
1233 if (pNewHolder == NULL)
1234 return E_OUTOFMEMORY;
1235
1236 pNewHolder->nControlType = nControlType;
1237 pNewHolder->iElement = iElement;
1238 pNewHolder->Element = *pElement;
1239
1240 HRESULT hr = m_DefaultElements.Add(pNewHolder);
1241 if (FAILED(hr))
1242 {
1243 delete pNewHolder;
1244 }
1245 return hr;
1246}
1247
1248
1249//--------------------------------------------------------------------------------------
1250RiseElement* RiseDialog::GetDefaultElement(UINT nControlType, UINT iElement)
1251{
1252 for (int i = 0; i < m_DefaultElements.GetSize(); i++)
1253 {
1254 UIElementHolder* pElementHolder = m_DefaultElements.GetAt(i);
1255
1256 if (pElementHolder->nControlType == nControlType &&
1257 pElementHolder->iElement == iElement)
1258 {
1259 return &pElementHolder->Element;
1260 }
1261 }
1262
1263 return NULL;
1264}
1265
1266
1267
1268//--------------------------------------------------------------------------------------
1269HRESULT RiseDialog::AddStatic(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault,
1270 RiseStatic** ppCreated, bool bShadow)
1271{
1272 HRESULT hr = S_OK;
1273
1274 RiseStatic* pStatic = new RiseStatic(this);
1275
1276 if (ppCreated != NULL)
1277 *ppCreated = pStatic;
1278
1279 if (pStatic == NULL)
1280 return E_OUTOFMEMORY;
1281
1282 hr = AddControl(pStatic);
1283 if (FAILED(hr))
1284 return hr;
1285
1286 // Set the ID and list index
1287 pStatic->SetID(ID);
1288 pStatic->SetText(strText);
1289 pStatic->SetLocation(x, y);
1290 pStatic->SetSize(width, height);
1291 pStatic->m_bIsDefault = bIsDefault;
1292 pStatic->m_bShadow = bShadow;
1293
1294 return S_OK;
1295}
1296
1297
1298//--------------------------------------------------------------------------------------
1299HRESULT RiseDialog::AddButton(int ID, LPCWSTR strText, int x, int y, int width, int height, UINT nHotkey,
1300 bool bIsDefault, RiseButton** ppCreated)
1301{
1302 HRESULT hr = S_OK;
1303
1304 RiseButton* pButton = new RiseButton(this);
1305
1306 if (ppCreated != NULL)
1307 *ppCreated = pButton;
1308
1309 if (pButton == NULL)
1310 return E_OUTOFMEMORY;
1311
1312 hr = AddControl(pButton);
1313 if (FAILED(hr))
1314 return hr;
1315
1316 // Set the ID and list index
1317 pButton->SetID(ID);
1318 pButton->SetText(strText);
1319 pButton->SetLocation(x, y);
1320 pButton->SetSize(width, height);
1321 pButton->SetHotkey(nHotkey);
1322 pButton->m_bIsDefault = bIsDefault;
1323
1324 return S_OK;
1325}
1326
1327
1328//--------------------------------------------------------------------------------------
1329HRESULT RiseDialog::AddCheckBox(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bChecked,
1330 UINT nHotkey, bool bIsDefault, RiseCheckBox** ppCreated)
1331{
1332 HRESULT hr = S_OK;
1333
1334 RiseCheckBox* pCheckBox = new RiseCheckBox(this);
1335
1336 if (ppCreated != NULL)
1337 *ppCreated = pCheckBox;
1338
1339 if (pCheckBox == NULL)
1340 return E_OUTOFMEMORY;
1341
1342 hr = AddControl(pCheckBox);
1343 if (FAILED(hr))
1344 return hr;
1345
1346 // Set the ID and list index
1347 pCheckBox->SetID(ID);
1348 pCheckBox->SetText(strText);
1349 pCheckBox->SetLocation(x, y);
1350 pCheckBox->SetSize(width, height);
1351 pCheckBox->SetHotkey(nHotkey);
1352 pCheckBox->m_bIsDefault = bIsDefault;
1353 pCheckBox->SetChecked(bChecked);
1354
1355 return S_OK;
1356}
1357
1358
1359
1360//--------------------------------------------------------------------------------------
1361HRESULT RiseDialog::AddRadioButton(int ID, UINT nButtonGroup, LPCWSTR strText, int x, int y, int width, int height,
1362 bool bChecked, UINT nHotkey, bool bIsDefault, RiseRadioButton** ppCreated)
1363{
1364 HRESULT hr = S_OK;
1365
1366 RiseRadioButton* pRadioButton = new RiseRadioButton(this);
1367
1368 if (ppCreated != NULL)
1369 *ppCreated = pRadioButton;
1370
1371 if (pRadioButton == NULL)
1372 return E_OUTOFMEMORY;
1373
1374 hr = AddControl(pRadioButton);
1375 if (FAILED(hr))
1376 return hr;
1377
1378 // Set the ID and list index
1379 pRadioButton->SetID(ID);
1380 pRadioButton->SetText(strText);
1381 pRadioButton->SetButtonGroup(nButtonGroup);
1382 pRadioButton->SetLocation(x, y);
1383 pRadioButton->SetSize(width, height);
1384 pRadioButton->SetHotkey(nHotkey);
1385 pRadioButton->SetChecked(bChecked);
1386 pRadioButton->m_bIsDefault = bIsDefault;
1387 pRadioButton->SetChecked(bChecked);
1388
1389 return S_OK;
1390}
1391
1392
1393
1394
1395//--------------------------------------------------------------------------------------
1396HRESULT RiseDialog::AddComboBox(int ID, int x, int y, int width, int height, UINT nHotkey, bool bIsDefault,
1397 RiseComboBox** ppCreated)
1398{
1399 HRESULT hr = S_OK;
1400
1401 RiseComboBox* pComboBox = new RiseComboBox(this);
1402
1403 if (ppCreated != NULL)
1404 *ppCreated = pComboBox;
1405
1406 if (pComboBox == NULL)
1407 return E_OUTOFMEMORY;
1408
1409 hr = AddControl(pComboBox);
1410 if (FAILED(hr))
1411 return hr;
1412
1413 // Set the ID and list index
1414 pComboBox->SetID(ID);
1415 pComboBox->SetLocation(x, y);
1416 pComboBox->SetSize(width, height);
1417 pComboBox->SetHotkey(nHotkey);
1418 pComboBox->m_bIsDefault = bIsDefault;
1419
1420 return S_OK;
1421}
1422
1423
1424
1425//--------------------------------------------------------------------------------------
1426HRESULT RiseDialog::AddSlider(int ID, int x, int y, int width, int height, int min, int max, int value,
1427 bool bIsDefault, RiseSlider** ppCreated)
1428{
1429 HRESULT hr = S_OK;
1430
1431 RiseSlider* pSlider = new RiseSlider(this);
1432
1433 if (ppCreated != NULL)
1434 *ppCreated = pSlider;
1435
1436 if (pSlider == NULL)
1437 return E_OUTOFMEMORY;
1438
1439 hr = AddControl(pSlider);
1440 if (FAILED(hr))
1441 return hr;
1442
1443 // Set the ID and list index
1444 pSlider->SetID(ID);
1445 pSlider->SetLocation(x, y);
1446 pSlider->SetSize(width, height);
1447 pSlider->m_bIsDefault = bIsDefault;
1448 pSlider->SetRange(min, max);
1449 pSlider->SetValue(value);
1450 pSlider->UpdateRects();
1451
1452 return S_OK;
1453}
1454
1455
1456
1457//--------------------------------------------------------------------------------------
1458HRESULT RiseDialog::AddEditBox(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault, bool bIsPassword,
1459 RiseEditBox** ppCreated)
1460{
1461 HRESULT hr = S_OK;
1462
1463 RiseEditBox* pEditBox = new RiseEditBox(this);
1464
1465 if (ppCreated != NULL)
1466 *ppCreated = pEditBox;
1467
1468 if (pEditBox == NULL)
1469 return E_OUTOFMEMORY;
1470
1471 hr = AddControl(pEditBox);
1472 if (FAILED(hr))
1473 return hr;
1474
1475 // Set the ID and position
1476 pEditBox->SetID(ID);
1477 pEditBox->SetLocation(x, y);
1478 pEditBox->SetSize(width, height);
1479 pEditBox->m_bIsDefault = bIsDefault;
1480 pEditBox->m_bIsPassword = bIsPassword;
1481
1482 if (strText)
1483 pEditBox->SetText(strText);
1484
1485 return S_OK;
1486}
1487
1488
1489//--------------------------------------------------------------------------------------
1490HRESULT RiseDialog::AddListBox(int ID, int x, int y, int width, int height, DWORD dwStyle, RiseListBox** ppCreated)
1491{
1492 HRESULT hr = S_OK;
1493 RiseListBox* pListBox = new RiseListBox(this);
1494
1495 if (ppCreated != NULL)
1496 *ppCreated = pListBox;
1497
1498 if (pListBox == NULL)
1499 return E_OUTOFMEMORY;
1500
1501 hr = AddControl(pListBox);
1502 if (FAILED(hr))
1503 return hr;
1504
1505 // Set the ID and position
1506 pListBox->SetID(ID);
1507 pListBox->SetLocation(x, y);
1508 pListBox->SetSize(width, height);
1509 pListBox->SetStyle(dwStyle);
1510
1511 return S_OK;
1512}
1513
1514
1515
1516//--------------------------------------------------------------------------------------
1518{
1519 HRESULT hr;
1520
1521 if (pControl == NULL)
1522 return E_INVALIDARG;
1523
1524 pControl->m_Index = m_Controls.GetSize();
1525
1526 // Look for a default Element entries
1527 for (int i = 0; i < m_DefaultElements.GetSize(); i++)
1528 {
1529 UIElementHolder* pElementHolder = m_DefaultElements.GetAt(i);
1530 if (pElementHolder->nControlType == pControl->GetType())
1531 pControl->SetElement(pElementHolder->iElement, &pElementHolder->Element);
1532 }
1533
1534 V_RETURN(pControl->OnInit());
1535
1536 return S_OK;
1537}
1538
1539
1540
1541//--------------------------------------------------------------------------------------
1543{
1544 HRESULT hr = S_OK;
1545
1546 hr = InitControl(pControl);
1547 if (FAILED(hr))
1548 return Rendering::TraceFailure(L"RiseDialog::InitControl", hr);
1549
1550 // Add to the list
1551 hr = m_Controls.Add(pControl);
1552 if (FAILED(hr))
1553 {
1554 return Rendering::TraceFailure(L"ControlArray::Add", hr);
1555 }
1556
1557 return S_OK;
1558}
1559
1560
1561//--------------------------------------------------------------------------------------
1563{
1564 // Try to find the control with the given ID
1565 for (int i = 0; i < m_Controls.GetSize(); i++)
1566 {
1567 RiseControl* pControl = m_Controls.GetAt(i);
1568
1569 if (pControl->GetID() == ID)
1570 {
1571 return pControl;
1572 }
1573 }
1574
1575 // Not found
1576 return NULL;
1577}
1578
1579
1580
1581//--------------------------------------------------------------------------------------
1582RiseControl* RiseDialog::GetControl(int ID, UINT nControlType)
1583{
1584 // Try to find the control with the given ID
1585 for (int i = 0; i < m_Controls.GetSize(); i++)
1586 {
1587 RiseControl* pControl = m_Controls.GetAt(i);
1588
1589 if (pControl->GetID() == ID && pControl->GetType() == nControlType)
1590 {
1591 return pControl;
1592 }
1593 }
1594
1595 // Not found
1596 return NULL;
1597}
1598
1599
1600
1601//--------------------------------------------------------------------------------------
1603{
1604 int index = pControl->m_Index + 1;
1605
1606 RiseDialog* pDialog = pControl->m_pDialog;
1607
1608 // Cycle through dialogs in the loop to find the next control. Note
1609 // that if only one control exists in all looped dialogs it will
1610 // be the returned 'next' control.
1611 while (index >= (int)pDialog->m_Controls.GetSize())
1612 {
1613 pDialog = pDialog->m_pNextDialog;
1614 index = 0;
1615 }
1616
1617 return pDialog->m_Controls.GetAt(index);
1618}
1619
1620//--------------------------------------------------------------------------------------
1622{
1623 int index = pControl->m_Index - 1;
1624
1625 RiseDialog* pDialog = pControl->m_pDialog;
1626
1627 // Cycle through dialogs in the loop to find the next control. Note
1628 // that if only one control exists in all looped dialogs it will
1629 // be the returned 'previous' control.
1630 while (index < 0)
1631 {
1632 pDialog = pDialog->m_pPrevDialog;
1633 if (pDialog == NULL)
1634 pDialog = pControl->m_pDialog;
1635
1636 index = pDialog->m_Controls.GetSize() - 1;
1637 }
1638
1639 return pDialog->m_Controls.GetAt(index);
1640}
1641
1642
1643//--------------------------------------------------------------------------------------
1645{
1646 // Find all radio buttons with the given group number
1647 for (int i = 0; i < m_Controls.GetSize(); i++)
1648 {
1649 RiseControl* pControl = m_Controls.GetAt(i);
1650
1651 if (pControl->GetType() == UI_CONTROL_RADIOBUTTON)
1652 {
1653 RiseRadioButton* pRadioButton = (RiseRadioButton*)pControl;
1654
1655 if (pRadioButton->GetButtonGroup() == nButtonGroup)
1656 pRadioButton->SetChecked(false, false);
1657 }
1658 }
1659}
1660
1661
1662
1663//--------------------------------------------------------------------------------------
1665{
1666 RiseComboBox* pComboBox = GetComboBox(ID);
1667 if (pComboBox == NULL)
1668 return;
1669
1670 pComboBox->RemoveAllItems();
1671}
1672
1673
1674
1675
1676//--------------------------------------------------------------------------------------
1678{
1679 if (s_pControlFocus == pControl)
1680 return;
1681
1682 if (!pControl->CanHaveFocus())
1683 return;
1684
1685 if (s_pControlFocus)
1687
1688 pControl->OnFocusIn();
1689 s_pControlFocus = pControl;
1690}
1691
1692
1693//--------------------------------------------------------------------------------------
1694
1695
1696
1697//--------------------------------------------------------------------------------------
1699{
1700 RECT rcScreen = *pRect;
1701 OffsetRect(&rcScreen, m_x, m_y);
1702
1703 // If caption is enabled, offset the Y position by its height.
1704 if (m_bCaption)
1705 OffsetRect(&rcScreen, 0, m_nCaptionHeight);
1706
1707 UI_SCREEN_VERTEX vertices[4] =
1708 {
1709 (float)rcScreen.left - 0.5f, (float)rcScreen.top - 0.5f, 0.5f, 1.0f, color, 0, 0,
1710 (float)rcScreen.right - 0.5f, (float)rcScreen.top - 0.5f, 0.5f, 1.0f, color, 0, 0,
1711 (float)rcScreen.right - 0.5f, (float)rcScreen.bottom - 0.5f, 0.5f, 1.0f, color, 0, 0,
1712 (float)rcScreen.left - 0.5f, (float)rcScreen.bottom - 0.5f, 0.5f, 1.0f, color, 0, 0,
1713 };
1714
1716
1717 // Since we're doing our own drawing here we need to flush the sprites
1719 auto savedDrawState = pd3dDevice->Capture();
1720 pd3dDevice->SetFVF(UI_SCREEN_VERTEX::FVF);
1721
1724
1725 pd3dDevice->DrawPrimitiveUP(Rendering::Primitive::TriangleFan, 2, vertices, sizeof(UI_SCREEN_VERTEX));
1726
1729
1730 // Restore the vertex decl
1731 pd3dDevice->Restore(savedDrawState);
1733
1734 return S_OK;
1735}
1736
1737
1738//--------------------------------------------------------------------------------------
1739
1740
1741
1742//--------------------------------------------------------------------------------------
1743HRESULT RiseDialog::DrawPolyLine(POINT* apPoints, UINT nNumPoints, Rendering::PackedColor color)
1744{
1745 UI_SCREEN_VERTEX* vertices = new UI_SCREEN_VERTEX[nNumPoints];
1746 if (vertices == NULL)
1747 return E_OUTOFMEMORY;
1748
1749 UI_SCREEN_VERTEX* pVertex = vertices;
1750 POINT* pt = apPoints;
1751 for (UINT i = 0; i < nNumPoints; i++)
1752 {
1753 pVertex->x = m_x + (float)pt->x;
1754 pVertex->y = m_y + (float)pt->y;
1755 pVertex->z = 0.5f;
1756 pVertex->h = 1.0f;
1757 pVertex->color = color;
1758 pVertex->tu = 0.0f;
1759 pVertex->tv = 0.0f;
1760
1761 pVertex++;
1762 pt++;
1763 }
1764
1766
1767 // Since we're doing our own drawing here we need to flush the sprites
1769 auto savedDrawState = pd3dDevice->Capture();
1770 pd3dDevice->SetFVF(UI_SCREEN_VERTEX::FVF);
1771
1774
1775 pd3dDevice->DrawPrimitiveUP(Rendering::Primitive::LineStrip, nNumPoints - 1, vertices, sizeof(UI_SCREEN_VERTEX));
1776
1779
1780 // Restore the vertex decl
1781 pd3dDevice->Restore(savedDrawState);
1783
1784 SAFE_DELETE_ARRAY(vertices);
1785 return S_OK;
1786}
1787
1788
1789//--------------------------------------------------------------------------------------
1790
1791
1792
1793//--------------------------------------------------------------------------------------
1794HRESULT RiseDialog::DrawSprite(RiseElement* pElement, RECT* prcDest, float)
1795{
1796 // No need to draw fully transparent layers
1797 if (pElement->TextureColor.Current.a == 0)
1798 return S_OK;
1799
1800 RECT rcTexture = pElement->rcTexture;
1801
1802 RECT rcScreen = *prcDest;
1803 OffsetRect(&rcScreen, m_x, m_y);
1804
1805 // If caption is enabled, offset the Y position by its height.
1806 if (m_bCaption)
1807 OffsetRect(&rcScreen, 0, m_nCaptionHeight);
1808
1809 UITextureNode* pTextureNode = GetTexture(pElement->iTexture);
1810 if (pTextureNode == NULL)
1811 return E_FAIL;
1812
1813 float fScaleX = (float)RectWidth(rcScreen) / RectWidth(rcTexture);
1814 float fScaleY = (float)RectHeight(rcScreen) / RectHeight(rcTexture);
1815
1816 RiseMath::Matrix matTransform;
1817 RiseMath::MatrixScaling(&matTransform, fScaleX, fScaleY, 1.0f);
1818
1819 m_pManager->m_pSprite->SetTransform(&matTransform);
1820
1821 RiseMath::Vector3 vPos((float)rcScreen.left, (float)rcScreen.top, 0.0f);
1822
1823 vPos.x /= fScaleX;
1824 vPos.y /= fScaleY;
1825
1826 return m_pManager->m_pSprite->Draw(pTextureNode->texture, &rcTexture, NULL, &vPos,
1827 pElement->TextureColor.Current);
1828}
1829
1830
1831//--------------------------------------------------------------------------------------
1832
1833
1834
1835//--------------------------------------------------------------------------------------
1836HRESULT RiseDialog::CalcTextRect(LPCWSTR strText, RiseElement* pElement, RECT* prcDest, int nCount)
1837{
1838 HRESULT hr = S_OK;
1839
1840 UIFontNode* pFontNode = GetFont(pElement->iFont);
1841 if (pFontNode == NULL)
1842 return E_FAIL;
1843
1844 DWORD dwTextFormat = pElement->dwTextFormat | DT_CALCRECT;
1845 // Since we are only computing the rectangle, we don't need a sprite.
1846 if (pFontNode->font)
1847 {
1848 hr = pFontNode->font->DrawText(NULL, strText, nCount, prcDest, dwTextFormat, pElement->FontColor.Current);
1849 if (FAILED(hr))
1850 return hr;
1851 }
1852
1853 return S_OK;
1854}
1855
1856
1857//--------------------------------------------------------------------------------------
1858
1859
1860
1861//--------------------------------------------------------------------------------------
1862HRESULT RiseDialog::DrawText(LPCWSTR strText, RiseElement* pElement, RECT* prcDest, bool bShadow, int nCount)
1863{
1864 HRESULT hr = S_OK;
1865
1866 // No need to draw fully transparent layers
1867 if (pElement->FontColor.Current.a == 0)
1868 return S_OK;
1869
1870 RECT rcScreen = *prcDest;
1871 OffsetRect(&rcScreen, m_x, m_y);
1872
1873 // If caption is enabled, offset the Y position by its height.
1874 if (m_bCaption)
1875 OffsetRect(&rcScreen, 0, m_nCaptionHeight);
1876
1877 RiseMath::Matrix matTransform;
1878 RiseMath::MatrixIdentity(&matTransform);
1879 m_pManager->m_pSprite->SetTransform(&matTransform);
1880
1881 UIFontNode* pFontNode = GetFont(pElement->iFont);
1882
1883 if (bShadow)
1884 {
1885 RECT rcShadow = rcScreen;
1886 OffsetRect(&rcShadow, 1, 1);
1887 hr = pFontNode->font->DrawText(m_pManager->m_pSprite, strText, nCount, &rcShadow, pElement->dwTextFormat,
1888 Rendering::ColorARGB(DWORD(pElement->FontColor.Current.a * 255), 0, 0, 0));
1889 if (FAILED(hr))
1890 return hr;
1891 }
1892
1893 hr = pFontNode->font->DrawText(m_pManager->m_pSprite, strText, nCount, &rcScreen, pElement->dwTextFormat,
1894 pElement->FontColor.Current);
1895 if (FAILED(hr))
1896 return hr;
1897
1898 return S_OK;
1899}
1900
1901
1902//--------------------------------------------------------------------------------------
1903
1904
1905
1906//--------------------------------------------------------------------------------------
1908 Rendering::PackedColor colorBottomRight)
1909{
1910 m_colorTopLeft = colorTopLeft;
1911 m_colorTopRight = colorTopRight;
1912 m_colorBottomLeft = colorBottomLeft;
1913 m_colorBottomRight = colorBottomRight;
1914}
1915
1916
1917//--------------------------------------------------------------------------------------
1919{
1920 if (pNextDialog == NULL)
1921 pNextDialog = this;
1922
1923 m_pNextDialog = pNextDialog;
1924 if (pNextDialog)
1926}
1927
1928
1929//--------------------------------------------------------------------------------------
1931{
1932 if (s_pControlFocus)
1933 {
1935 s_pControlFocus = NULL;
1936 }
1937
1938 ReleaseCapture();
1939}
1940
1941
1942//--------------------------------------------------------------------------------------
1944{
1945 // Check for default control in this dialog
1946 for (int i = 0; i < m_Controls.GetSize(); i++)
1947 {
1948 RiseControl* pControl = m_Controls.GetAt(i);
1949 if (pControl->m_bIsDefault)
1950 {
1951 // Remove focus from the current control
1952 ClearFocus();
1953
1954 // Give focus to the default control
1955 s_pControlFocus = pControl;
1957 return;
1958 }
1959 }
1960}
1961
1962
1963//--------------------------------------------------------------------------------------
1964bool RiseDialog::OnCycleFocus(bool bForward)
1965{
1966 RiseControl* pControl = NULL;
1967 RiseDialog* pDialog = NULL; // pDialog and pLastDialog are used to track wrapping of
1968 RiseDialog* pLastDialog; // focus from first control to last or vice versa.
1969
1970 if (s_pControlFocus == NULL)
1971 {
1972 // If s_pControlFocus is NULL, we focus the first control of first dialog in
1973 // the case that bForward is true, and focus the last control of last dialog when
1974 // bForward is false.
1975 //
1976 if (bForward)
1977 {
1978 // Search for the first control from the start of the dialog
1979 // array.
1980 for (int d = 0; d < m_pManager->m_Dialogs.GetSize(); ++d)
1981 {
1982 pDialog = pLastDialog = m_pManager->m_Dialogs.GetAt(d);
1983 if (pDialog && pDialog->m_Controls.GetSize() > 0)
1984 {
1985 pControl = pDialog->m_Controls.GetAt(0);
1986 break;
1987 }
1988 }
1989
1990 if (!pDialog || !pControl)
1991 {
1992 // No dialog has been registered yet or no controls have been
1993 // added to the dialogs. Cannot proceed.
1994 return true;
1995 }
1996 }
1997 else
1998 {
1999 // Search for the first control from the end of the dialog
2000 // array.
2001 for (int d = m_pManager->m_Dialogs.GetSize() - 1; d >= 0; --d)
2002 {
2003 pDialog = pLastDialog = m_pManager->m_Dialogs.GetAt(d);
2004 if (pDialog && pDialog->m_Controls.GetSize() > 0)
2005 {
2006 pControl = pDialog->m_Controls.GetAt(pDialog->m_Controls.GetSize() - 1);
2007 break;
2008 }
2009 }
2010
2011 if (!pDialog || !pControl)
2012 {
2013 // No dialog has been registered yet or no controls have been
2014 // added to the dialogs. Cannot proceed.
2015 return true;
2016 }
2017 }
2018 }
2019 else if (s_pControlFocus->m_pDialog != this)
2020 {
2021 // If a control belonging to another dialog has focus, let that other
2022 // dialog handle this event by returning false.
2023 //
2024 return false;
2025 }
2026 else
2027 {
2028 // Focused control belongs to this dialog. Cycle to the
2029 // next/previous control.
2030 pLastDialog = s_pControlFocus->m_pDialog;
2032 pDialog = pControl->m_pDialog;
2033 }
2034
2035 for (int i = 0; i < 0xffff; i++)
2036 {
2037 // If we just wrapped from last control to first or vice versa,
2038 // set the focused control to NULL. This state, where no control
2039 // has focus, allows the camera to work.
2040 int nLastDialogIndex = m_pManager->m_Dialogs.IndexOf(pLastDialog);
2041 int nDialogIndex = m_pManager->m_Dialogs.IndexOf(pDialog);
2042 if ((!bForward && nLastDialogIndex < nDialogIndex) ||
2043 (bForward && nDialogIndex < nLastDialogIndex))
2044 {
2045 if (s_pControlFocus)
2047 s_pControlFocus = NULL;
2048 return true;
2049 }
2050
2051 // If we've gone in a full circle then focus doesn't change
2052 if (pControl == s_pControlFocus)
2053 return true;
2054
2055 // If the dialog accepts keybord input and the control can have focus then
2056 // move focus
2057 if (pControl->m_pDialog->m_bKeyboardInput && pControl->CanHaveFocus())
2058 {
2059 if (s_pControlFocus)
2061 s_pControlFocus = pControl;
2063 return true;
2064 }
2065
2066 pLastDialog = pDialog;
2067 pControl = (bForward) ? GetNextControl(pControl) : GetPrevControl(pControl);
2068 pDialog = pControl->m_pDialog;
2069 }
2070
2071 // If we reached this point, the chain of dialogs didn't form a complete loop
2072 Rendering::TraceFailure(L"RiseDialog: Multiple dialogs are improperly chained together", E_FAIL);
2073 return false;
2074}
2075
2076
2077//--------------------------------------------------------------------------------------
2079{
2080 HRESULT hr = S_OK;
2081
2082 UIFontNode* pFontNode = m_FontCache.GetAt(iFont);
2083
2084 SAFE_RELEASE(pFontNode->font);
2085
2086 V_RETURN(Rendering::CreateFontW(m_renderer, pFontNode->nHeight, 0, pFontNode->nWeight, 1, FALSE, DEFAULT_CHARSET,
2087 OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
2088 pFontNode->strFace, &pFontNode->font));
2089
2090 return S_OK;
2091}
2092
2093
2094//--------------------------------------------------------------------------------------
2095
2096
2097
2098//--------------------------------------------------------------------------------------
2100{
2101 auto* node=m_TextureCache.GetAt(index);
2102 SAFE_RELEASE(node->texture);
2103 HRESULT hr;
2104 if(node->bFileSource)
2105 hr=Rendering::LoadTexture(m_renderer,node->strFilename,&node->texture,1);
2106 else
2107 {
2108 const bool builtin=node->nResourceID==0xffff && node->hResourceModule==(HMODULE)0xffff;
2109 HMODULE module=builtin ? GetModuleHandleW(nullptr) : node->hResourceModule;
2110 LPCWSTR id=builtin ? MAKEINTRESOURCEW(6100) : node->nResourceID ? MAKEINTRESOURCEW(node->nResourceID) : node->strFilename;
2111 hr=Rendering::LoadTextureResource(m_renderer,module,id,&node->texture,1);
2112 }
2113 if(FAILED(hr))return hr;
2114 Rendering::SurfaceDescription description{};
2115 if(FAILED(hr=node->texture->GetLevelDesc(0,&description)))return hr;
2116 node->dwWidth=description.Width;node->dwHeight=description.Height;return S_OK;
2117}
2118
2119
2120//--------------------------------------------------------------------------------------
2121
2122
2123
2124//--------------------------------------------------------------------------------------
2126{
2127 SetFont(0, L"Arial", 14, FW_NORMAL);
2128
2130 RECT rcTexture;
2131
2132 //-------------------------------------
2133 // Element for the caption
2134 //-------------------------------------
2136 SetRect(&rcTexture, 17, 269, 241, 287);
2137 m_CapElement.SetTexture(0, &rcTexture);
2140 m_CapElement.SetFont(0, Rendering::ColorARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER);
2141 // Pre-blend as we don't need to transition the state
2144
2145 //-------------------------------------
2146 // RiseStatic
2147 //-------------------------------------
2148 Element.SetFont(0);
2149 Element.FontColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(200, 200, 200, 200);
2150
2151 // Assign the Element
2153
2154
2155 //-------------------------------------
2156 // RiseButton - Button
2157 //-------------------------------------
2158 SetRect(&rcTexture, 0, 0, 136, 54);
2159 Element.SetTexture(0, &rcTexture);
2160 Element.SetFont(0);
2161 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 255, 255, 255);
2162 Element.TextureColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(200, 255, 255, 255);
2163 Element.FontColor.States[UI_STATE_MOUSEOVER] = Rendering::ColorARGB(255, 0, 0, 0);
2164
2165 // Assign the Element
2167
2168
2169 //-------------------------------------
2170 // RiseButton - Fill layer
2171 //-------------------------------------
2172 SetRect(&rcTexture, 136, 0, 252, 54);
2173 Element.SetTexture(0, &rcTexture, Rendering::ColorARGB(0, 255, 255, 255));
2174 Element.TextureColor.States[UI_STATE_MOUSEOVER] = Rendering::ColorARGB(160, 255, 255, 255);
2175 Element.TextureColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(60, 0, 0, 0);
2176 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(30, 255, 255, 255);
2177
2178
2179 // Assign the Element
2181
2182
2183 //-------------------------------------
2184 // RiseCheckBox - Box
2185 //-------------------------------------
2186 SetRect(&rcTexture, 0, 54, 27, 81);
2187 Element.SetTexture(0, &rcTexture);
2188 Element.SetFont(0, Rendering::ColorARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER);
2189 Element.FontColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(200, 200, 200, 200);
2190 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 255, 255, 255);
2191 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(200, 255, 255, 255);
2192 Element.TextureColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(255, 255, 255, 255);
2193
2194 // Assign the Element
2196
2197
2198 //-------------------------------------
2199 // RiseCheckBox - Check
2200 //-------------------------------------
2201 SetRect(&rcTexture, 27, 54, 54, 81);
2202 Element.SetTexture(0, &rcTexture);
2203
2204 // Assign the Element
2206
2207
2208 //-------------------------------------
2209 // RiseRadioButton - Box
2210 //-------------------------------------
2211 SetRect(&rcTexture, 54, 54, 81, 81);
2212 Element.SetTexture(0, &rcTexture);
2213 Element.SetFont(0, Rendering::ColorARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER);
2214 Element.FontColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(200, 200, 200, 200);
2215 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 255, 255, 255);
2216 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(200, 255, 255, 255);
2217 Element.TextureColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(255, 255, 255, 255);
2218
2219 // Assign the Element
2221
2222
2223 //-------------------------------------
2224 // RiseRadioButton - Check
2225 //-------------------------------------
2226 SetRect(&rcTexture, 81, 54, 108, 81);
2227 Element.SetTexture(0, &rcTexture);
2228
2229 // Assign the Element
2231
2232
2233 //-------------------------------------
2234 // RiseComboBox - Main
2235 //-------------------------------------
2236 SetRect(&rcTexture, 7, 81, 247, 123);
2237 Element.SetTexture(0, &rcTexture);
2238 Element.SetFont(0);
2239 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 200, 200, 200);
2240 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(170, 230, 230, 230);
2241 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(70, 200, 200, 200);
2242 Element.FontColor.States[UI_STATE_MOUSEOVER] = Rendering::ColorARGB(255, 0, 0, 0);
2243 Element.FontColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(255, 0, 0, 0);
2244 Element.FontColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(200, 200, 200, 200);
2245
2246
2247 // Assign the Element
2249
2250
2251 //-------------------------------------
2252 // RiseComboBox - Button
2253 //-------------------------------------
2254 SetRect(&rcTexture, 98, 189, 151, 238);
2255 Element.SetTexture(0, &rcTexture);
2256 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 255, 255, 255);
2257 Element.TextureColor.States[UI_STATE_PRESSED] = Rendering::ColorARGB(255, 150, 150, 150);
2258 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(200, 255, 255, 255);
2259 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(70, 255, 255, 255);
2260
2261 // Assign the Element
2263
2264
2265 //-------------------------------------
2266 // RiseComboBox - Dropdown
2267 //-------------------------------------
2268 SetRect(&rcTexture, 13, 123, 241, 160);
2269 Element.SetTexture(0, &rcTexture);
2270 Element.SetFont(0, Rendering::ColorARGB(255, 200, 200, 200), DT_LEFT | DT_TOP);
2271
2272 // Assign the Element
2274
2275
2276 //-------------------------------------
2277 // RiseComboBox - Selection
2278 //-------------------------------------
2279 SetRect(&rcTexture, 12, 163, 239, 183);
2280 Element.SetTexture(0, &rcTexture);
2281 Element.SetFont(0, Rendering::ColorARGB(255, 255, 255, 255), DT_LEFT | DT_TOP);
2282
2283 // Assign the Element
2285
2286
2287 //-------------------------------------
2288 // RiseSlider - Track
2289 //-------------------------------------
2290 SetRect(&rcTexture, 1, 187, 93, 228);
2291 Element.SetTexture(0, &rcTexture);
2292 Element.TextureColor.States[UI_STATE_NORMAL] = Rendering::ColorARGB(150, 255, 255, 255);
2293 Element.TextureColor.States[UI_STATE_FOCUS] = Rendering::ColorARGB(200, 255, 255, 255);
2294 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(70, 255, 255, 255);
2295
2296 // Assign the Element
2298
2299 //-------------------------------------
2300 // RiseSlider - Button
2301 //-------------------------------------
2302 SetRect(&rcTexture, 151, 193, 192, 234);
2303 Element.SetTexture(0, &rcTexture);
2304
2305 // Assign the Element
2307
2308 //-------------------------------------
2309 // RiseScrollBar - Track
2310 //-------------------------------------
2311 int nScrollBarStartX = 196;
2312 int nScrollBarStartY = 191;
2313 SetRect(&rcTexture, nScrollBarStartX + 0, nScrollBarStartY + 21, nScrollBarStartX + 22, nScrollBarStartY + 32);
2314 Element.SetTexture(0, &rcTexture);
2315 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(255, 200, 200, 200);
2316
2317 // Assign the Element
2319
2320 //-------------------------------------
2321 // RiseScrollBar - Up Arrow
2322 //-------------------------------------
2323 SetRect(&rcTexture, nScrollBarStartX + 0, nScrollBarStartY + 1, nScrollBarStartX + 22, nScrollBarStartY + 21);
2324 Element.SetTexture(0, &rcTexture);
2325 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(255, 200, 200, 200);
2326
2327
2328 // Assign the Element
2330
2331 //-------------------------------------
2332 // RiseScrollBar - Down Arrow
2333 //-------------------------------------
2334 SetRect(&rcTexture, nScrollBarStartX + 0, nScrollBarStartY + 32, nScrollBarStartX + 22, nScrollBarStartY + 53);
2335 Element.SetTexture(0, &rcTexture);
2336 Element.TextureColor.States[UI_STATE_DISABLED] = Rendering::ColorARGB(255, 200, 200, 200);
2337
2338
2339 // Assign the Element
2341
2342 //-------------------------------------
2343 // RiseScrollBar - Button
2344 //-------------------------------------
2345 SetRect(&rcTexture, 220, 192, 238, 234);
2346 Element.SetTexture(0, &rcTexture);
2347
2348 // Assign the Element
2350
2351
2352 //-------------------------------------
2353 // RiseEditBox
2354 //-------------------------------------
2355 // Element assignment:
2356 // 0 - text area
2357 // 1 - top left border
2358 // 2 - top border
2359 // 3 - top right border
2360 // 4 - left border
2361 // 5 - right border
2362 // 6 - lower left border
2363 // 7 - lower border
2364 // 8 - lower right border
2365
2366 Element.SetFont(0, Rendering::ColorARGB(255, 0, 0, 0), DT_LEFT | DT_TOP);
2367
2368 // Assign the style
2369 SetRect(&rcTexture, 14, 90, 241, 113);
2370 Element.SetTexture(0, &rcTexture);
2372 SetRect(&rcTexture, 8, 82, 14, 90);
2373 Element.SetTexture(0, &rcTexture);
2375 SetRect(&rcTexture, 14, 82, 241, 90);
2376 Element.SetTexture(0, &rcTexture);
2378 SetRect(&rcTexture, 241, 82, 246, 90);
2379 Element.SetTexture(0, &rcTexture);
2381 SetRect(&rcTexture, 8, 90, 14, 113);
2382 Element.SetTexture(0, &rcTexture);
2384 SetRect(&rcTexture, 241, 90, 246, 113);
2385 Element.SetTexture(0, &rcTexture);
2387 SetRect(&rcTexture, 8, 113, 14, 121);
2388 Element.SetTexture(0, &rcTexture);
2390 SetRect(&rcTexture, 14, 113, 241, 121);
2391 Element.SetTexture(0, &rcTexture);
2393 SetRect(&rcTexture, 241, 113, 246, 121);
2394 Element.SetTexture(0, &rcTexture);
2396
2397 //-------------------------------------
2398 // RiseListBox - Main
2399 //-------------------------------------
2400 SetRect(&rcTexture, 13, 123, 241, 160);
2401 Element.SetTexture(0, &rcTexture);
2402 Element.SetFont(0, Rendering::ColorARGB(255, 0, 0, 0), DT_LEFT | DT_TOP);
2403
2404 // Assign the Element
2406
2407 //-------------------------------------
2408 // RiseListBox - Selection
2409 //-------------------------------------
2410
2411 SetRect(&rcTexture, 16, 166, 240, 183);
2412 Element.SetTexture(0, &rcTexture);
2413 Element.SetFont(0, Rendering::ColorARGB(255, 255, 255, 255), DT_LEFT | DT_TOP);
2414
2415 // Assign the Element
2417}
2418
2419
2420
2421//--------------------------------------------------------------------------------------
2422// RiseControl class
2423//--------------------------------------------------------------------------------------
2424
2425//--------------------------------------------------------------------------------------
2427{
2429 m_pDialog = pDialog;
2430 m_ID = 0;
2431 m_Index = 0;
2432 m_nHotkey = 0; // No hotkey unless explicitly assigned by the caller.
2433 m_pUserData = NULL;
2434
2435 m_bEnabled = true;
2436 m_bVisible = true;
2437 m_bMouseOver = false;
2438 m_bHasFocus = false;
2439 m_bIsDefault = false;
2440
2441 m_pDialog = NULL;
2442
2443 m_x = 0;
2444 m_y = 0;
2445 m_width = 0;
2446 m_height = 0;
2447
2448 ZeroMemory(&m_rcBoundingBox, sizeof(m_rcBoundingBox));
2449}
2450
2451
2453{
2454 for (int i = 0; i < m_Elements.GetSize(); ++i)
2455 {
2456 delete m_Elements[i];
2457 }
2459}
2460
2461
2462//--------------------------------------------------------------------------------------
2464{
2465 RiseElement* pElement = m_Elements.GetAt(0);
2466
2467 if (pElement)
2468 {
2469 pElement->FontColor.States[UI_STATE_NORMAL] = Color;
2470 }
2471}
2472
2473
2474//--------------------------------------------------------------------------------------
2476{
2477 HRESULT hr = S_OK;
2478
2479 if (pElement == NULL)
2480 return E_INVALIDARG;
2481
2482 // Make certain the array is this large
2483 for (UINT i = m_Elements.GetSize(); i <= iElement; i++)
2484 {
2485 RiseElement* pNewElement = new RiseElement();
2486 if (pNewElement == NULL)
2487 return E_OUTOFMEMORY;
2488
2489 hr = m_Elements.Add(pNewElement);
2490 if (FAILED(hr))
2491 {
2492 SAFE_DELETE(pNewElement);
2493 return hr;
2494 }
2495 }
2496
2497 // Update the data
2498 RiseElement* pCurElement = m_Elements.GetAt(iElement);
2499 *pCurElement = *pElement;
2500
2501 return S_OK;
2502}
2503
2504
2505//--------------------------------------------------------------------------------------
2507{
2508 m_bMouseOver = false;
2509 m_bHasFocus = false;
2510
2511 for (int i = 0; i < m_Elements.GetSize(); i++)
2512 {
2513 RiseElement* pElement = m_Elements.GetAt(i);
2514 pElement->Refresh();
2515 }
2516}
2517
2518
2519//--------------------------------------------------------------------------------------
2521{
2522 SetRect(&m_rcBoundingBox, m_x, m_y, m_x + m_width, m_y + m_height);
2523}
2524
2525
2526//--------------------------------------------------------------------------------------
2527// RiseStatic class
2528//--------------------------------------------------------------------------------------
2529
2530//--------------------------------------------------------------------------------------
2532{
2534 m_pDialog = pDialog;
2535
2536 ZeroMemory(&m_strText, sizeof m_strText);
2537
2538 for (int i = 0; i < m_Elements.GetSize(); i++)
2539 {
2540 RiseElement* pElement = m_Elements.GetAt(i);
2541 SAFE_DELETE(pElement);
2542 }
2543
2545}
2546
2547
2548//--------------------------------------------------------------------------------------
2549void RiseStatic::Render(float fElapsedTime)
2550{
2551 if (m_bVisible == false)
2552 return;
2553
2555
2556 if (m_bEnabled == false)
2557 iState = UI_STATE_DISABLED;
2558
2559 RiseElement* pElement = m_Elements.GetAt(0);
2560
2561 pElement->FontColor.Blend(iState, fElapsedTime);
2562
2564}
2565
2566
2567//--------------------------------------------------------------------------------------
2568HRESULT RiseStatic::GetTextCopy(__out_ecount(bufferCount) LPWSTR strDest,
2569 UINT bufferCount)
2570{
2571 // Validate incoming parameters
2572 if (strDest == NULL || bufferCount == 0)
2573 {
2574 return E_INVALIDARG;
2575 }
2576
2577 // Copy the window text
2578 wcscpy_s(strDest, bufferCount, m_strText);
2579
2580 return S_OK;
2581}
2582
2583
2584//--------------------------------------------------------------------------------------
2586{
2587 if (strText == NULL)
2588 {
2589 m_strText[0] = 0;
2590 return S_OK;
2591 }
2592
2593 wcscpy_s(m_strText, MAX_TEXT, strText);
2594 return S_OK;
2595}
2596
2597
2598//--------------------------------------------------------------------------------------
2599// RiseButton class
2600//--------------------------------------------------------------------------------------
2601
2602//--------------------------------------------------------------------------------------
2604{
2606 m_pDialog = pDialog;
2607
2608 m_bPressed = false;
2609 m_nHotkey = 0;
2610}
2611
2612//--------------------------------------------------------------------------------------
2613bool RiseButton::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
2614{
2615 if (!m_bEnabled || !m_bVisible)
2616 return false;
2617
2618 switch (uMsg)
2619 {
2620 case WM_KEYDOWN:
2621 {
2622 switch (wParam)
2623 {
2624 case VK_SPACE:
2625 m_bPressed = true;
2626 return true;
2627 }
2628 }
2629
2630 case WM_KEYUP:
2631 {
2632 switch (wParam)
2633 {
2634 case VK_SPACE:
2635 if (m_bPressed == true)
2636 {
2637 m_bPressed = false;
2639 }
2640 return true;
2641 }
2642 }
2643 }
2644 return false;
2645}
2646
2647
2648//--------------------------------------------------------------------------------------
2649bool RiseButton::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
2650{
2651 if (!m_bEnabled || !m_bVisible)
2652 return false;
2653
2654 switch (uMsg)
2655 {
2656 case WM_LBUTTONDOWN:
2657 case WM_LBUTTONDBLCLK:
2658 {
2659 if (ContainsPoint(pt))
2660 {
2661 // Pressed while inside the control
2662 m_bPressed = true;
2663 SetCapture(Rendering::ClientWindow());
2664
2665 if (!m_bHasFocus)
2666 m_pDialog->RequestFocus(this);
2667
2668 return true;
2669 }
2670
2671 break;
2672 }
2673
2674 case WM_LBUTTONUP:
2675 {
2676 if (m_bPressed)
2677 {
2678 m_bPressed = false;
2679 ReleaseCapture();
2680
2683
2684 // Button click
2685 if (ContainsPoint(pt))
2687
2688 return true;
2689 }
2690
2691 break;
2692 }
2693 };
2694
2695 return false;
2696}
2697
2698//--------------------------------------------------------------------------------------
2699void RiseButton::Render(float fElapsedTime)
2700{
2701 int nOffsetX = 0;
2702 int nOffsetY = 0;
2703
2705
2706 if (m_bVisible == false)
2707 {
2708 iState = UI_STATE_HIDDEN;
2709 }
2710 else if (m_bEnabled == false)
2711 {
2712 iState = UI_STATE_DISABLED;
2713 }
2714 else if (m_bPressed)
2715 {
2716 iState = UI_STATE_PRESSED;
2717
2718 nOffsetX = 1;
2719 nOffsetY = 2;
2720 }
2721 else if (m_bMouseOver)
2722 {
2723 iState = UI_STATE_MOUSEOVER;
2724
2725 nOffsetX = -1;
2726 nOffsetY = -2;
2727 }
2728 else if (m_bHasFocus)
2729 {
2730 iState = UI_STATE_FOCUS;
2731 }
2732
2733 // Background fill layer
2734 RiseElement* pElement = m_Elements.GetAt(0);
2735
2736 float fBlendRate = (iState == UI_STATE_PRESSED) ? 0.0f : 0.8f;
2737
2738 RECT rcWindow = m_rcBoundingBox;
2739 OffsetRect(&rcWindow, nOffsetX, nOffsetY);
2740
2741
2742 // Blend current color
2743 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
2744 pElement->FontColor.Blend(iState, fElapsedTime, fBlendRate);
2745
2746 m_pDialog->DrawSprite(pElement, &rcWindow, UI_FAR_BUTTON_DEPTH);
2747 m_pDialog->DrawText(m_strText, pElement, &rcWindow);
2748
2749 // Main button
2750 pElement = m_Elements.GetAt(1);
2751
2752 // Blend current color
2753 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
2754 pElement->FontColor.Blend(iState, fElapsedTime, fBlendRate);
2755
2756 m_pDialog->DrawSprite(pElement, &rcWindow, UI_NEAR_BUTTON_DEPTH);
2757 m_pDialog->DrawText(m_strText, pElement, &rcWindow);
2758}
2759
2760
2761
2762//--------------------------------------------------------------------------------------
2763// RiseCheckBox class
2764//--------------------------------------------------------------------------------------
2765
2766//--------------------------------------------------------------------------------------
2768{
2770 m_pDialog = pDialog;
2771
2772 m_bChecked = false;
2773}
2774
2775
2776//--------------------------------------------------------------------------------------
2777bool RiseCheckBox::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
2778{
2779 if (!m_bEnabled || !m_bVisible)
2780 return false;
2781
2782 switch (uMsg)
2783 {
2784 case WM_KEYDOWN:
2785 {
2786 switch (wParam)
2787 {
2788 case VK_SPACE:
2789 m_bPressed = true;
2790 return true;
2791 }
2792 }
2793
2794 case WM_KEYUP:
2795 {
2796 switch (wParam)
2797 {
2798 case VK_SPACE:
2799 if (m_bPressed == true)
2800 {
2801 m_bPressed = false;
2803 }
2804 return true;
2805 }
2806 }
2807 }
2808 return false;
2809}
2810
2811
2812//--------------------------------------------------------------------------------------
2813bool RiseCheckBox::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
2814{
2815 if (!m_bEnabled || !m_bVisible)
2816 return false;
2817
2818 switch (uMsg)
2819 {
2820 case WM_LBUTTONDOWN:
2821 case WM_LBUTTONDBLCLK:
2822 {
2823 if (ContainsPoint(pt))
2824 {
2825 // Pressed while inside the control
2826 m_bPressed = true;
2827 SetCapture(Rendering::ClientWindow());
2828
2829 if (!m_bHasFocus)
2830 m_pDialog->RequestFocus(this);
2831
2832 return true;
2833 }
2834
2835 break;
2836 }
2837
2838 case WM_LBUTTONUP:
2839 {
2840 if (m_bPressed)
2841 {
2842 m_bPressed = false;
2843 ReleaseCapture();
2844
2845 // Button click
2846 if (ContainsPoint(pt))
2848
2849 return true;
2850 }
2851
2852 break;
2853 }
2854 };
2855
2856 return false;
2857}
2858
2859
2860//--------------------------------------------------------------------------------------
2861void RiseCheckBox::SetCheckedInternal(bool bChecked, bool bFromInput)
2862{
2863 m_bChecked = bChecked;
2864
2865 m_pDialog->SendEvent(EVENT_CHECKBOX_CHANGED, bFromInput, this);
2866}
2867
2868
2869//--------------------------------------------------------------------------------------
2871{
2872 return (PtInRect(&m_rcBoundingBox, pt) ||
2873 PtInRect(&m_rcButton, pt));
2874}
2875
2876
2877
2878//--------------------------------------------------------------------------------------
2880{
2882
2885
2887 m_rcText.left += (int)(1.25f * RectWidth(m_rcButton));
2888}
2889
2890
2891
2892//--------------------------------------------------------------------------------------
2893void RiseCheckBox::Render(float fElapsedTime)
2894{
2896
2897 if (m_bVisible == false)
2898 iState = UI_STATE_HIDDEN;
2899 else if (m_bEnabled == false)
2900 iState = UI_STATE_DISABLED;
2901 else if (m_bPressed)
2902 iState = UI_STATE_PRESSED;
2903 else if (m_bMouseOver)
2904 iState = UI_STATE_MOUSEOVER;
2905 else if (m_bHasFocus)
2906 iState = UI_STATE_FOCUS;
2907
2908 RiseElement* pElement = m_Elements.GetAt(0);
2909
2910 float fBlendRate = (iState == UI_STATE_PRESSED) ? 0.0f : 0.8f;
2911
2912 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
2913 pElement->FontColor.Blend(iState, fElapsedTime, fBlendRate);
2914
2916 m_pDialog->DrawText(m_strText, pElement, &m_rcText, true);
2917
2918 if (!m_bChecked)
2919 iState = UI_STATE_HIDDEN;
2920
2921 pElement = m_Elements.GetAt(1);
2922
2923 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
2925}
2926
2927
2928
2929
2930//--------------------------------------------------------------------------------------
2931// RiseRadioButton class
2932//--------------------------------------------------------------------------------------
2933
2934//--------------------------------------------------------------------------------------
2940
2941
2942
2943//--------------------------------------------------------------------------------------
2944bool RiseRadioButton::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
2945{
2946 // turned this off altogether because of the space bar
2947 //if (!m_bEnabled || !m_bVisible)
2948 return false;
2949
2950 /*
2951 switch (uMsg)
2952 {
2953 case WM_KEYDOWN:
2954 {
2955 switch (wParam)
2956 {
2957 case VK_SPACE:
2958 m_bPressed = true;
2959 return true;
2960 }
2961 }
2962
2963 case WM_KEYUP:
2964 {
2965 switch (wParam)
2966 {
2967 case VK_SPACE:
2968 if (m_bPressed == true)
2969 {
2970 m_bPressed = false;
2971
2972 m_pDialog->ClearRadioButtonGroup(m_nButtonGroup);
2973 m_bChecked = !m_bChecked;
2974
2975 m_pDialog->SendEvent(EVENT_RADIOBUTTON_CHANGED, true, this);
2976 }
2977 return true;
2978 }
2979 }
2980 }
2981 return false;
2982 */
2983}
2984
2985
2986//--------------------------------------------------------------------------------------
2987bool RiseRadioButton::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
2988{
2989 if (!m_bEnabled || !m_bVisible)
2990 return false;
2991
2992 switch (uMsg)
2993 {
2994 case WM_LBUTTONDOWN:
2995 case WM_LBUTTONDBLCLK:
2996 {
2997 if (ContainsPoint(pt))
2998 {
2999 // Pressed while inside the control
3000 m_bPressed = true;
3001 SetCapture(Rendering::ClientWindow());
3002
3003 if (!m_bHasFocus)
3004 m_pDialog->RequestFocus(this);
3005
3006 return true;
3007 }
3008
3009 break;
3010 }
3011
3012 case WM_LBUTTONUP:
3013 {
3014 if (m_bPressed)
3015 {
3016 m_bPressed = false;
3017 ReleaseCapture();
3018
3019 // Button click
3020 if (ContainsPoint(pt))
3021 {
3024
3026 }
3027
3028 return true;
3029 }
3030
3031 break;
3032 }
3033 };
3034
3035 return false;
3036}
3037
3038//--------------------------------------------------------------------------------------
3039void RiseRadioButton::SetCheckedInternal(bool bChecked, bool bClearGroup, bool bFromInput)
3040{
3041 if (bChecked && bClearGroup)
3043
3044 m_bChecked = bChecked;
3045 m_pDialog->SendEvent(EVENT_RADIOBUTTON_CHANGED, bFromInput, this);
3046}
3047
3048
3049
3050
3051//--------------------------------------------------------------------------------------
3052// RiseComboBox class
3053//--------------------------------------------------------------------------------------
3054
3055//--------------------------------------------------------------------------------------
3057{
3059 m_pDialog = pDialog;
3060
3061 m_nDropHeight = 100;
3062
3063 m_nSBWidth = 16;
3064 m_bOpened = false;
3065 m_iSelected = -1;
3066 m_iFocused = -1;
3067}
3068
3069
3070//--------------------------------------------------------------------------------------
3075
3076
3077//--------------------------------------------------------------------------------------
3079{
3080 RiseElement* pElement = m_Elements.GetAt(0);
3081
3082 if (pElement)
3083 {
3084 pElement->FontColor.States[UI_STATE_NORMAL] = Color;
3085 pElement->FontColor.States[UI_STATE_DISABLED] = DisabledColor;
3086 }
3087
3088 pElement = m_Elements.GetAt(2);
3089
3090 if (pElement)
3091 {
3092 pElement->FontColor.States[UI_STATE_NORMAL] = Color;
3093 pElement->FontColor.States[UI_STATE_DISABLED] = DisabledColor;
3094 }
3095}
3096
3097
3098//--------------------------------------------------------------------------------------
3100{
3102
3104
3106
3107 //m_rcDropdown = m_rcText;
3108 m_rcDropdown = RECT();
3109 m_rcDropdown.left = m_x;
3112 m_rcDropdown.right = m_x + m_width;
3113
3115
3116 //UIFontNode* pFontNode = m_pDialog->GetManager()->GetFontNode(m_Elements.GetAt(2)->iFont);
3117 //if (pFontNode && pFontNode->nHeight)
3118 {
3119 m_rcDropdownText.left += m_nFontHeight;// pFontNode->nHeight;
3120 m_rcDropdownText.top += m_nFontHeight;//pFontNode->nHeight;
3121 m_rcDropdown.bottom += m_nFontHeight;//pFontNode->nHeight;
3122 }
3123
3124 // Update the scrollbar's rects
3127 //if (pFontNode && pFontNode->nHeight)
3128 {
3129 // The way I explained this is the system generates the "font" as a sprite of 14px ...
3130 // We scale up the whole system but the math is still based on the sprite that is 14px?
3131 m_ScrollBar.SetPageSize(RectHeight(m_rcDropdownText) / m_nFontHeight); // to make sure the bottom items don't get cut off
3132
3133 // The selected item may have been scrolled off the page.
3134 // Ensure that it is in page again.
3136 }
3137}
3138
3139
3140//--------------------------------------------------------------------------------------
3142{
3144
3145 m_bOpened = false;
3146}
3147
3148
3149//--------------------------------------------------------------------------------------
3150bool RiseComboBox::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
3151{
3152 const DWORD REPEAT_MASK = (0x40000000);
3153
3154 if (!m_bEnabled || !m_bVisible)
3155 return false;
3156
3157 // Let the scroll bar have a chance to handle it first
3158 if (m_ScrollBar.HandleKeyboard(uMsg, wParam, lParam))
3159 return true;
3160
3161 switch (uMsg)
3162 {
3163 case WM_KEYDOWN:
3164 {
3165 switch (wParam)
3166 {
3167 case VK_RETURN:
3168 if (m_bOpened)
3169 {
3170 if (m_iSelected != m_iFocused)
3171 {
3174 }
3175 m_bOpened = false;
3176
3179
3180 return true;
3181 }
3182 break;
3183
3184 case VK_F4:
3185 // Filter out auto-repeats
3186 if (lParam & REPEAT_MASK)
3187 return true;
3188
3190
3191 if (!m_bOpened)
3192 {
3194
3197 }
3198
3199 return true;
3200
3201 case VK_LEFT:
3202 case VK_UP:
3203 if (m_iFocused > 0)
3204 {
3205 m_iFocused--;
3207
3208 if (!m_bOpened)
3210 }
3211
3212 return true;
3213
3214 case VK_RIGHT:
3215 case VK_DOWN:
3216 if (m_iFocused + 1 < (int)GetNumItems())
3217 {
3218 m_iFocused++;
3220
3221 if (!m_bOpened)
3223 }
3224
3225 return true;
3226 }
3227 break;
3228 }
3229 }
3230
3231 return false;
3232}
3233
3234
3235//--------------------------------------------------------------------------------------
3236bool RiseComboBox::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
3237{
3238 if (!m_bEnabled || !m_bVisible)
3239 return false;
3240
3241 // Let the scroll bar handle it first.
3242 if (m_ScrollBar.HandleMouse(uMsg, pt, wParam, lParam))
3243 return true;
3244
3245 switch (uMsg)
3246 {
3247 case WM_MOUSEMOVE:
3248 {
3249 if (m_bOpened && PtInRect(&m_rcDropdown, pt))
3250 {
3251 // Determine which item has been selected
3252 for (int i = 0; i < m_Items.GetSize(); i++)
3253 {
3254 UIComboBoxItem* pItem = m_Items.GetAt(i);
3255 if (pItem->bVisible &&
3256 PtInRect(&pItem->rcActive, pt))
3257 {
3258 m_iFocused = i;
3259 }
3260 }
3261 return true;
3262 }
3263 break;
3264 }
3265
3266 case WM_LBUTTONDOWN:
3267 case WM_LBUTTONDBLCLK:
3268 {
3269 if (ContainsPoint(pt))
3270 {
3271 // Pressed while inside the control
3272 m_bPressed = true;
3273 SetCapture(Rendering::ClientWindow());
3274
3275 if (!m_bHasFocus)
3276 m_pDialog->RequestFocus(this);
3277
3278 // Toggle dropdown
3279 if (m_bHasFocus)
3280 {
3282
3283 if (!m_bOpened)
3284 {
3287 }
3288 }
3289
3290 return true;
3291 }
3292
3293 // Perhaps this click is within the dropdown
3294 if (m_bOpened && PtInRect(&m_rcDropdown, pt))
3295 {
3296 // Determine which item has been selected
3297 for (int i = m_ScrollBar.GetTrackPos(); i < m_Items.GetSize(); i++)
3298 {
3299 UIComboBoxItem* pItem = m_Items.GetAt(i);
3300 if (pItem->bVisible &&
3301 PtInRect(&pItem->rcActive, pt))
3302 {
3303 m_iFocused = m_iSelected = i;
3307 m_bOpened = false;
3308
3309 break;
3310 }
3311 }
3312
3313 return true;
3314 }
3315
3316 // Mouse click not on main control or in dropdown, fire an event if needed
3317 if (m_bOpened)
3318 {
3320
3322 m_bOpened = false;
3323 }
3324
3325 // Make sure the control is no longer in a pressed state
3326 m_bPressed = false;
3327
3328 // Release focus if appropriate
3331
3332 break;
3333 }
3334
3335 case WM_LBUTTONUP:
3336 {
3337 if (m_bPressed && ContainsPoint(pt))
3338 {
3339 // Button click
3340 m_bPressed = false;
3341 ReleaseCapture();
3342 return true;
3343 }
3344
3345 break;
3346 }
3347
3348 case WM_MOUSEWHEEL:
3349 {
3350 int zDelta = (short)HIWORD(wParam) / WHEEL_DELTA;
3351 if (m_bOpened)
3352 {
3353 UINT uLines;
3354 SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &uLines, 0);
3355 m_ScrollBar.Scroll(-zDelta * uLines);
3356 }
3357 else
3358 {
3359 if (zDelta > 0)
3360 {
3361 if (m_iFocused > 0)
3362 {
3363 m_iFocused--;
3365
3366 if (!m_bOpened)
3368 }
3369 }
3370 else
3371 {
3372 if (m_iFocused + 1 < (int)GetNumItems())
3373 {
3374 m_iFocused++;
3376
3377 if (!m_bOpened)
3379 }
3380 }
3381 }
3382 return true;
3383 }
3384 };
3385
3386 return false;
3387}
3388
3389
3390//--------------------------------------------------------------------------------------
3392{
3393 if (m_bOpened)
3394 return;
3395
3396 if (m_iSelected == -1)
3397 return;
3398
3400 m_pDialog->RequestFocus(this);
3401
3402 m_iSelected++;
3403
3404 if (m_iSelected >= (int)m_Items.GetSize())
3405 m_iSelected = 0;
3406
3409}
3410
3411
3412//--------------------------------------------------------------------------------------
3413void RiseComboBox::Render(float fElapsedTime)
3414{
3416
3417 if (!m_bVisible)
3418 m_bOpened = false;
3419
3420 if (!m_bOpened)
3421 iState = UI_STATE_HIDDEN;
3422
3423 // Dropdown box
3424 RiseElement* pElement = m_Elements.GetAt(2);
3425
3426 // If we have not initialized the scroll bar page size,
3427 // do that now.
3428 static bool bSBInit = false;
3429 if (!bSBInit)
3430 {
3431 // Update the page size of the scroll bar
3432 if (m_pDialog->GetManager()->GetFontNode(pElement->iFont)->nHeight)
3434 m_pDialog->GetManager()->GetFontNode(pElement->iFont)->nHeight);
3435 else
3437 bSBInit = true;
3438 }
3439
3440 // Scroll bar
3441 if (m_bOpened)
3442 m_ScrollBar.Render(fElapsedTime);
3443
3444 // Blend current color
3445 pElement->TextureColor.Blend(iState, fElapsedTime);
3446 pElement->FontColor.Blend(iState, fElapsedTime);
3447
3449
3450 // Selection outline
3451 RiseElement* pSelectionElement = m_Elements.GetAt(3);
3452 pSelectionElement->TextureColor.Current = pElement->TextureColor.Current;
3453 pSelectionElement->FontColor.Current = pSelectionElement->FontColor.States[UI_STATE_NORMAL];
3454
3455 int curY = m_rcDropdownText.top;
3456 int nRemainingHeight = RectHeight(m_rcDropdownText);
3457 //WCHAR strDropdown[4096] = {0};
3458
3459 for (int i = m_ScrollBar.GetTrackPos(); i < m_Items.GetSize(); i++)
3460 {
3461 UIComboBoxItem* pItem = m_Items.GetAt(i);
3462
3463 // Make sure there's room left in the dropdown
3464 nRemainingHeight -= m_nFontHeight;
3465 if (nRemainingHeight < 0)
3466 {
3467 pItem->bVisible = false;
3468 continue;
3469 }
3470
3471 SetRect(&pItem->rcActive, m_rcDropdownText.left, curY, m_rcDropdownText.right, curY + m_nFontHeight);
3472 curY += m_nFontHeight;
3473
3474 //debug
3475 //int blue = 50 * i;
3476 //m_pDialog->DrawRect( &pItem->rcActive, 0xFFFF0000 | blue );
3477
3478 pItem->bVisible = true;
3479
3480 if (m_bOpened)
3481 {
3482 if ((int)i == m_iFocused)
3483 {
3484 RECT rc;
3485 SetRect(&rc, m_rcDropdown.left, pItem->rcActive.top - 2, m_rcDropdown.right,
3486 pItem->rcActive.bottom + 2);
3487 m_pDialog->DrawSprite(pSelectionElement, &rc, UI_NEAR_BUTTON_DEPTH);
3488 m_pDialog->DrawText(pItem->strText, pSelectionElement, &pItem->rcActive);
3489 }
3490 else
3491 {
3492 m_pDialog->DrawText(pItem->strText, pElement, &pItem->rcActive);
3493 }
3494 }
3495 }
3496
3497 int nOffsetX = 0;
3498 int nOffsetY = 0;
3499
3500 iState = UI_STATE_NORMAL;
3501
3502 if (m_bVisible == false)
3503 iState = UI_STATE_HIDDEN;
3504 else if (m_bEnabled == false)
3505 iState = UI_STATE_DISABLED;
3506 else if (m_bPressed)
3507 {
3508 iState = UI_STATE_PRESSED;
3509
3510 nOffsetX = 1;
3511 nOffsetY = 2;
3512 }
3513 else if (m_bMouseOver)
3514 {
3515 iState = UI_STATE_MOUSEOVER;
3516
3517 nOffsetX = -1;
3518 nOffsetY = -2;
3519 }
3520 else if (m_bHasFocus)
3521 iState = UI_STATE_FOCUS;
3522
3523 float fBlendRate = (iState == UI_STATE_PRESSED) ? 0.0f : 0.8f;
3524
3525 // Button
3526 pElement = m_Elements.GetAt(1);
3527
3528 // Blend current color
3529 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
3530
3531 RECT rcWindow = m_rcButton;
3532 OffsetRect(&rcWindow, nOffsetX, nOffsetY);
3533 m_pDialog->DrawSprite(pElement, &rcWindow, UI_FAR_BUTTON_DEPTH);
3534
3535 if (m_bOpened)
3536 iState = UI_STATE_PRESSED;
3537
3538 // Main text box
3539 pElement = m_Elements.GetAt(0);
3540
3541 // Blend current color
3542 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
3543 pElement->FontColor.Blend(iState, fElapsedTime, fBlendRate);
3544
3546
3547 if (m_iSelected >= 0 && m_iSelected < (int)m_Items.GetSize())
3548 {
3550 if (pItem != NULL)
3551 {
3552 m_pDialog->DrawText(pItem->strText, pElement, &m_rcText);
3553
3554 }
3555 }
3556}
3557
3558
3559//--------------------------------------------------------------------------------------
3560HRESULT RiseComboBox::AddItem(const WCHAR* strText, void* pData)
3561{
3562 // Validate parameters
3563 if (strText == NULL)
3564 {
3565 return E_INVALIDARG;
3566 }
3567
3568 // Create a new item and set the data
3569 UIComboBoxItem* pItem = new UIComboBoxItem;
3570 if (pItem == NULL)
3571 {
3572 return Rendering::TraceFailure(L"new", E_OUTOFMEMORY);
3573 }
3574
3575 ZeroMemory(pItem, sizeof(UIComboBoxItem));
3576 wcscpy_s(pItem->strText, 256, strText);
3577 pItem->pData = pData;
3578
3579 m_Items.Add(pItem);
3580
3581 // Update the scroll bar with new range
3583
3584 // If this is the only item in the list, it's selected
3585 if (GetNumItems() == 1)
3586 {
3587 m_iSelected = 0;
3588 m_iFocused = 0;
3590 }
3591
3592 return S_OK;
3593}
3594
3595
3596//--------------------------------------------------------------------------------------
3598{
3599 UIComboBoxItem* pItem = m_Items.GetAt(index);
3600 SAFE_DELETE(pItem);
3601 m_Items.Remove(index);
3603 if (m_iSelected >= m_Items.GetSize())
3604 m_iSelected = m_Items.GetSize() - 1;
3605}
3606
3607
3608//--------------------------------------------------------------------------------------
3610{
3611 for (int i = 0; i < m_Items.GetSize(); i++)
3612 {
3613 UIComboBoxItem* pItem = m_Items.GetAt(i);
3614 SAFE_DELETE(pItem);
3615 }
3616
3619 m_iFocused = m_iSelected = -1;
3620}
3621
3622
3623
3624//--------------------------------------------------------------------------------------
3625bool RiseComboBox::ContainsItem(const WCHAR* strText, UINT iStart)
3626{
3627 return (-1 != FindItem(strText, iStart));
3628}
3629
3630
3631//--------------------------------------------------------------------------------------
3632int RiseComboBox::FindItem(const WCHAR* strText, UINT iStart)
3633{
3634 if (strText == NULL)
3635 return -1;
3636
3637 for (int i = iStart; i < m_Items.GetSize(); i++)
3638 {
3639 UIComboBoxItem* pItem = m_Items.GetAt(i);
3640
3641 if (0 == wcscmp(pItem->strText, strText))
3642 {
3643 return i;
3644 }
3645 }
3646
3647 return -1;
3648}
3649
3650
3651//--------------------------------------------------------------------------------------
3653{
3654 if (m_iSelected < 0)
3655 return NULL;
3656
3658 return pItem->pData;
3659}
3660
3661
3662//--------------------------------------------------------------------------------------
3664{
3665 if (m_iSelected < 0)
3666 return NULL;
3667
3668 return m_Items.GetAt(m_iSelected);
3669}
3670
3671
3672//--------------------------------------------------------------------------------------
3673void* RiseComboBox::GetItemData(const WCHAR* strText)
3674{
3675 int index = FindItem(strText);
3676 if (index == -1)
3677 {
3678 return NULL;
3679 }
3680
3681 UIComboBoxItem* pItem = m_Items.GetAt(index);
3682 if (pItem == NULL)
3683 {
3684 Rendering::TraceFailure(L"ControlArray::GetAt", E_FAIL);
3685 return NULL;
3686 }
3687
3688 return pItem->pData;
3689}
3690
3691
3692//--------------------------------------------------------------------------------------
3694{
3695 if (nIndex < 0 || nIndex >= m_Items.GetSize())
3696 return NULL;
3697
3698 return m_Items.GetAt(nIndex)->pData;
3699}
3700
3701
3702//--------------------------------------------------------------------------------------
3704{
3705 if (index >= GetNumItems())
3706 return E_INVALIDARG;
3707
3708 m_iFocused = m_iSelected = index;
3710
3711 return S_OK;
3712}
3713
3714
3715
3716//--------------------------------------------------------------------------------------
3718{
3719 if (strText == NULL)
3720 return E_INVALIDARG;
3721
3722 int index = FindItem(strText);
3723 if (index == -1)
3724 return E_FAIL;
3725
3726 m_iFocused = m_iSelected = index;
3728
3729 return S_OK;
3730}
3731
3732
3733
3734//--------------------------------------------------------------------------------------
3736{
3737 for (int i = 0; i < m_Items.GetSize(); i++)
3738 {
3739 UIComboBoxItem* pItem = m_Items.GetAt(i);
3740
3741 if (pItem->pData == pData)
3742 {
3743 m_iFocused = m_iSelected = i;
3745 return S_OK;
3746 }
3747 }
3748
3749 return E_FAIL;
3750}
3751
3752
3753
3754//--------------------------------------------------------------------------------------
3756{
3758 m_pDialog = pDialog;
3759
3760 m_nMin = 0;
3761 m_nMax = 100;
3762 m_nValue = 50;
3763
3764 m_bPressed = false;
3765}
3766
3767
3768//--------------------------------------------------------------------------------------
3770{
3771 return (PtInRect(&m_rcBoundingBox, pt) ||
3772 PtInRect(&m_rcButton, pt));
3773}
3774
3775
3776//--------------------------------------------------------------------------------------
3778{
3780
3783 OffsetRect(&m_rcButton, -RectWidth(m_rcButton) / 2, 0);
3784
3786 OffsetRect(&m_rcButton, m_nButtonX, 0);
3787}
3788
3790{
3791 float fValuePerPixel = (float)(m_nMax - m_nMin) / RectWidth(m_rcBoundingBox);
3792 return (int)(0.5f + m_nMin + fValuePerPixel * (x - m_rcBoundingBox.left));
3793}
3794
3795//--------------------------------------------------------------------------------------
3796bool RiseSlider::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
3797{
3798 if (!m_bEnabled || !m_bVisible)
3799 return false;
3800
3801 switch (uMsg)
3802 {
3803 case WM_KEYDOWN:
3804 {
3805 switch (wParam)
3806 {
3807 case VK_HOME:
3808 SetValueInternal(m_nMin, true);
3809 return true;
3810
3811 case VK_END:
3812 SetValueInternal(m_nMax, true);
3813 return true;
3814
3815 case VK_LEFT:
3816 case VK_DOWN:
3817 SetValueInternal(m_nValue - 1, true);
3818 return true;
3819
3820 case VK_RIGHT:
3821 case VK_UP:
3822 SetValueInternal(m_nValue + 1, true);
3823 return true;
3824
3825 case VK_NEXT:
3826 SetValueInternal(m_nValue - (10 > (m_nMax - m_nMin) / 10 ? 10 : (m_nMax - m_nMin) / 10),
3827 true);
3828 return true;
3829
3830 case VK_PRIOR:
3831 SetValueInternal(m_nValue + (10 > (m_nMax - m_nMin) / 10 ? 10 : (m_nMax - m_nMin) / 10),
3832 true);
3833 return true;
3834 }
3835 break;
3836 }
3837 }
3838
3839
3840 return false;
3841}
3842
3843
3844//--------------------------------------------------------------------------------------
3845bool RiseSlider::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
3846{
3847 if (!m_bEnabled || !m_bVisible)
3848 return false;
3849
3850 switch (uMsg)
3851 {
3852 case WM_LBUTTONDOWN:
3853 case WM_LBUTTONDBLCLK:
3854 {
3855 if (PtInRect(&m_rcButton, pt))
3856 {
3857 // Pressed while inside the control
3858 m_bPressed = true;
3859 SetCapture(Rendering::ClientWindow());
3860
3861 m_nDragX = pt.x;
3862 //m_nDragY = pt.y;
3864
3865 //m_nDragValue = m_nValue;
3866
3867 if (!m_bHasFocus)
3868 m_pDialog->RequestFocus(this);
3869
3870 return true;
3871 }
3872
3873 if (PtInRect(&m_rcBoundingBox, pt))
3874 {
3875 m_nDragX = pt.x;
3876 m_nDragOffset = 0;
3877 m_bPressed = true;
3878
3879 if (!m_bHasFocus)
3880 m_pDialog->RequestFocus(this);
3881
3882 if (pt.x > m_nButtonX + m_x)
3883 {
3884 SetValueInternal(m_nValue + 1, true);
3885 return true;
3886 }
3887
3888 if (pt.x < m_nButtonX + m_x)
3889 {
3890 SetValueInternal(m_nValue - 1, true);
3891 return true;
3892 }
3893 }
3894
3895 break;
3896 }
3897
3898 case WM_LBUTTONUP:
3899 {
3900 if (m_bPressed)
3901 {
3902 m_bPressed = false;
3903 ReleaseCapture();
3905
3906 return true;
3907 }
3908
3909 break;
3910 }
3911
3912 case WM_MOUSEMOVE:
3913 {
3914 if (m_bPressed)
3915 {
3917 return true;
3918 }
3919
3920 break;
3921 }
3922
3923 case WM_MOUSEWHEEL:
3924 {
3925 int nScrollAmount = int((short)HIWORD(wParam)) / WHEEL_DELTA;
3926 SetValueInternal(m_nValue - nScrollAmount, true);
3927 return true;
3928 }
3929 };
3930
3931 return false;
3932}
3933
3934
3935//--------------------------------------------------------------------------------------
3936void RiseSlider::SetRange(int nMin, int nMax)
3937{
3938 m_nMin = nMin;
3939 m_nMax = nMax;
3940
3941 SetValueInternal(m_nValue, false);
3942}
3943
3944
3945//--------------------------------------------------------------------------------------
3946void RiseSlider::SetValueInternal(int nValue, bool bFromInput)
3947{
3948 // Clamp to range
3949 nValue = __max(m_nMin, nValue);
3950 nValue = __min(m_nMax, nValue);
3951
3952 if (nValue == m_nValue)
3953 return;
3954
3955 m_nValue = nValue;
3956 UpdateRects();
3957
3959}
3960
3961
3962//--------------------------------------------------------------------------------------
3963void RiseSlider::Render(float fElapsedTime)
3964{
3965 int nOffsetX = 0;
3966 int nOffsetY = 0;
3967
3969
3970 if (m_bVisible == false)
3971 {
3972 iState = UI_STATE_HIDDEN;
3973 }
3974 else if (m_bEnabled == false)
3975 {
3976 iState = UI_STATE_DISABLED;
3977 }
3978 else if (m_bPressed)
3979 {
3980 iState = UI_STATE_PRESSED;
3981
3982 nOffsetX = 1;
3983 nOffsetY = 2;
3984 }
3985 else if (m_bMouseOver)
3986 {
3987 iState = UI_STATE_MOUSEOVER;
3988
3989 nOffsetX = -1;
3990 nOffsetY = -2;
3991 }
3992 else if (m_bHasFocus)
3993 {
3994 iState = UI_STATE_FOCUS;
3995 }
3996
3997 float fBlendRate = (iState == UI_STATE_PRESSED) ? 0.0f : 0.8f;
3998
3999 RiseElement* pElement = m_Elements.GetAt(0);
4000
4001 // Blend current color
4002 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4004
4005 pElement = m_Elements.GetAt(1);
4006
4007 // Blend current color
4008 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4010}
4011
4012
4013//--------------------------------------------------------------------------------------
4014// RiseScrollBar class
4015//--------------------------------------------------------------------------------------
4016
4017//--------------------------------------------------------------------------------------
4019{
4021 m_pDialog = pDialog;
4022
4023 m_bShowThumb = true;
4024 m_bDrag = false;
4025
4026 SetRect(&m_rcUpButton, 0, 0, 0, 0);
4027 SetRect(&m_rcDownButton, 0, 0, 0, 0);
4028 SetRect(&m_rcTrack, 0, 0, 0, 0);
4029 SetRect(&m_rcThumb, 0, 0, 0, 0);
4030 m_nPosition = 0;
4031 m_nPageSize = 1;
4032 m_nStart = 0;
4033 m_nEnd = 1;
4034 m_Arrow = CLEAR;
4035 m_dArrowTS = 0.0;
4036}
4037
4038
4039//--------------------------------------------------------------------------------------
4043
4044
4045//--------------------------------------------------------------------------------------
4047{
4049
4050 // Make the buttons square
4051
4052 SetRect(&m_rcUpButton, m_rcBoundingBox.left, m_rcBoundingBox.top,
4055 m_rcBoundingBox.right, m_rcBoundingBox.bottom);
4056 SetRect(&m_rcTrack, m_rcUpButton.left, m_rcUpButton.bottom,
4057 m_rcDownButton.right, m_rcDownButton.top);
4058 m_rcThumb.left = m_rcUpButton.left;
4059 m_rcThumb.right = m_rcUpButton.right;
4060
4062}
4063
4064
4065//--------------------------------------------------------------------------------------
4066// Compute the dimension of the scroll thumb
4068{
4069 if (m_nEnd - m_nStart > m_nPageSize)
4070 {
4071 int nThumbHeight = __max(RectHeight(m_rcTrack) * m_nPageSize / (m_nEnd - m_nStart),
4073 int nMaxPosition = m_nEnd - m_nStart - m_nPageSize;
4074 m_rcThumb.top = m_rcTrack.top + (m_nPosition - m_nStart) * (RectHeight(m_rcTrack) - nThumbHeight)
4075 / nMaxPosition;
4076 m_rcThumb.bottom = m_rcThumb.top + nThumbHeight;
4077 m_bShowThumb = true;
4078
4079 }
4080 else
4081 {
4082 // No content to scroll
4083 m_rcThumb.bottom = m_rcThumb.top;
4084 m_bShowThumb = false;
4085 }
4086}
4087
4088
4089//--------------------------------------------------------------------------------------
4090// Scroll() scrolls by nDelta items. A positive value scrolls down, while a negative
4091// value scrolls up.
4093{
4094 // Perform scroll
4095 m_nPosition += nDelta;
4096
4097 // Cap position
4098 Cap();
4099
4100 // Update thumb position
4102}
4103
4104
4105//--------------------------------------------------------------------------------------
4107{
4108 // Cap the index
4109
4110 if (nIndex < 0)
4111 nIndex = 0;
4112
4113 if (nIndex >= m_nEnd)
4114 nIndex = m_nEnd - 1;
4115
4116 // Adjust position
4117
4118 if (m_nPosition > nIndex)
4119 m_nPosition = nIndex;
4120 else if (m_nPosition + m_nPageSize <= nIndex)
4121 m_nPosition = nIndex - m_nPageSize + 1;
4122
4124}
4125
4126
4127//--------------------------------------------------------------------------------------
4128bool RiseScrollBar::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
4129{
4130 return false;
4131}
4132
4133
4134//--------------------------------------------------------------------------------------
4135bool RiseScrollBar::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
4136{
4137 static int ThumbOffsetY;
4138
4139 m_LastMouse = pt;
4140 switch (uMsg)
4141 {
4142 case WM_LBUTTONDOWN:
4143 case WM_LBUTTONDBLCLK:
4144 {
4145 // Check for click on up button
4146
4147 if (PtInRect(&m_rcUpButton, pt))
4148 {
4149 SetCapture(Rendering::ClientWindow());
4150 if (m_nPosition > m_nStart)
4151 --m_nPosition;
4155 return true;
4156 }
4157
4158 // Check for click on down button
4159
4160 if (PtInRect(&m_rcDownButton, pt))
4161 {
4162 SetCapture(Rendering::ClientWindow());
4164 ++m_nPosition;
4168 return true;
4169 }
4170
4171 // Check for click on thumb
4172
4173 if (PtInRect(&m_rcThumb, pt))
4174 {
4175 SetCapture(Rendering::ClientWindow());
4176 m_bDrag = true;
4177 ThumbOffsetY = pt.y - m_rcThumb.top;
4178 return true;
4179 }
4180
4181 // Check for click on track
4182
4183 if (m_rcThumb.left <= pt.x &&
4184 m_rcThumb.right > pt.x)
4185 {
4186 SetCapture(Rendering::ClientWindow());
4187 if (m_rcThumb.top > pt.y &&
4188 m_rcTrack.top <= pt.y)
4189 {
4190 Scroll(-(m_nPageSize - 1));
4191 return true;
4192 }
4193 else if (m_rcThumb.bottom <= pt.y &&
4194 m_rcTrack.bottom > pt.y)
4195 {
4196 Scroll(m_nPageSize - 1);
4197 return true;
4198 }
4199 }
4200
4201 break;
4202 }
4203
4204 case WM_LBUTTONUP:
4205 {
4206 m_bDrag = false;
4207 ReleaseCapture();
4209 m_Arrow = CLEAR;
4210 break;
4211 }
4212
4213 case WM_MOUSEMOVE:
4214 {
4215 if (m_bDrag)
4216 {
4217 m_rcThumb.bottom += pt.y - ThumbOffsetY - m_rcThumb.top;
4218 m_rcThumb.top = pt.y - ThumbOffsetY;
4219 if (m_rcThumb.top < m_rcTrack.top)
4220 OffsetRect(&m_rcThumb, 0, m_rcTrack.top - m_rcThumb.top);
4221 else if (m_rcThumb.bottom > m_rcTrack.bottom)
4222 OffsetRect(&m_rcThumb, 0, m_rcTrack.bottom - m_rcThumb.bottom);
4223
4224 // Compute first item index based on thumb position
4225
4226 int nMaxFirstItem = m_nEnd - m_nStart - m_nPageSize + 1; // Largest possible index for first item
4227 int nMaxThumb = RectHeight(m_rcTrack) - RectHeight(m_rcThumb); // Largest possible thumb position from the top
4228
4230 (m_rcThumb.top - m_rcTrack.top +
4231 nMaxThumb / (nMaxFirstItem * 2)) * // Shift by half a row to avoid last row covered by only one pixel
4232 nMaxFirstItem / nMaxThumb;
4233
4234 return true;
4235 }
4236
4237 break;
4238 }
4239 }
4240
4241 return false;
4242}
4243
4244
4245//--------------------------------------------------------------------------------------
4246bool RiseScrollBar::MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
4247{
4248 if (WM_CAPTURECHANGED == uMsg)
4249 {
4250 // The application just lost mouse capture. We may not have gotten
4251 // the WM_MOUSEUP message, so reset m_bDrag here.
4252 if ((HWND)lParam != Rendering::ClientWindow())
4253 m_bDrag = false;
4254 }
4255
4256 return false;
4257}
4258
4259
4260//--------------------------------------------------------------------------------------
4261void RiseScrollBar::Render(float fElapsedTime)
4262{
4263 // Check if the arrow button has been held for a while.
4264 // If so, update the thumb position to simulate repeated
4265 // scroll.
4266 if (m_Arrow != CLEAR)
4267 {
4268 double dCurrTime = Rendering::ClientTime();
4269 if (PtInRect(&m_rcUpButton, m_LastMouse))
4270 {
4271 switch (m_Arrow)
4272 {
4273 case CLICKED_UP:
4274 if (SCROLLBAR_ARROWCLICK_DELAY < dCurrTime - m_dArrowTS)
4275 {
4276 Scroll(-1);
4277 m_Arrow = HELD_UP;
4278 m_dArrowTS = dCurrTime;
4279 }
4280 break;
4281 case HELD_UP:
4282 if (SCROLLBAR_ARROWCLICK_REPEAT < dCurrTime - m_dArrowTS)
4283 {
4284 Scroll(-1);
4285 m_dArrowTS = dCurrTime;
4286 }
4287 break;
4288 }
4289 }
4290 else if (PtInRect(&m_rcDownButton, m_LastMouse))
4291 {
4292 switch (m_Arrow)
4293 {
4294 case CLICKED_DOWN:
4295 if (SCROLLBAR_ARROWCLICK_DELAY < dCurrTime - m_dArrowTS)
4296 {
4297 Scroll(1);
4299 m_dArrowTS = dCurrTime;
4300 }
4301 break;
4302 case HELD_DOWN:
4303 if (SCROLLBAR_ARROWCLICK_REPEAT < dCurrTime - m_dArrowTS)
4304 {
4305 Scroll(1);
4306 m_dArrowTS = dCurrTime;
4307 }
4308 break;
4309 }
4310 }
4311 }
4312
4314
4315 if (m_bVisible == false)
4316 iState = UI_STATE_HIDDEN;
4317 else if (m_bEnabled == false || m_bShowThumb == false)
4318 iState = UI_STATE_DISABLED;
4319 else if (m_bMouseOver)
4320 iState = UI_STATE_MOUSEOVER;
4321 else if (m_bHasFocus)
4322 iState = UI_STATE_FOCUS;
4323
4324
4325 float fBlendRate = (iState == UI_STATE_PRESSED) ? 0.0f : 0.8f;
4326
4327 // Background track layer
4328 RiseElement* pElement = m_Elements.GetAt(0);
4329
4330 // Blend current color
4331 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4333
4334 // Up Arrow
4335 pElement = m_Elements.GetAt(1);
4336
4337 // Blend current color
4338 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4340
4341 // Down Arrow
4342 pElement = m_Elements.GetAt(2);
4343
4344 // Blend current color
4345 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4347
4348 // Thumb button
4349 pElement = m_Elements.GetAt(3);
4350
4351 // Blend current color
4352 pElement->TextureColor.Blend(iState, fElapsedTime, fBlendRate);
4354
4355}
4356
4357
4358//--------------------------------------------------------------------------------------
4359void RiseScrollBar::SetTrackRange(int nStart, int nEnd)
4360{
4361 m_nStart = nStart; m_nEnd = nEnd;
4362 Cap();
4364}
4365
4366
4367//--------------------------------------------------------------------------------------
4368void RiseScrollBar::Cap() // Clips position at boundaries. Ensures it stays within legal range.
4369{
4370 if (m_nPosition < m_nStart ||
4372 {
4374 }
4375 else if (m_nPosition + m_nPageSize > m_nEnd)
4377}
4378
4379//--------------------------------------------------------------------------------------
4380// RiseListBox class
4381//--------------------------------------------------------------------------------------
4382
4383//--------------------------------------------------------------------------------------
4385{
4387 m_pDialog = pDialog;
4388
4389 m_dwStyle = 0;
4390 m_nSBWidth = 16;
4391 m_nSelected = -1;
4392 m_nSelStart = 0;
4393 m_bDrag = false;
4394 m_nBorder = 6;
4395 m_nMargin = 5;
4396 m_nTextHeight = 0;
4397}
4398
4399
4400//--------------------------------------------------------------------------------------
4405
4406
4407//--------------------------------------------------------------------------------------
4409{
4411
4413 m_rcSelection.right -= m_nSBWidth;
4414 InflateRect(&m_rcSelection, -m_nBorder, -m_nBorder);
4416 InflateRect(&m_rcText, -m_nMargin, 0);
4417
4418 // Update the scrollbar's rects
4422 if (pFontNode && pFontNode->nHeight)
4423 {
4425
4426 // The selected item may have been scrolled off the page.
4427 // Ensure that it is in page again.
4429 }
4430}
4431
4432
4433//--------------------------------------------------------------------------------------
4434HRESULT RiseListBox::AddItem(const WCHAR* wszText, void* pData)
4435{
4436 UIListBoxItem* pNewItem = new UIListBoxItem;
4437 if (!pNewItem)
4438 return E_OUTOFMEMORY;
4439
4440 wcscpy_s(pNewItem->strText, 256, wszText);
4441 pNewItem->pData = pData;
4442 SetRect(&pNewItem->rcActive, 0, 0, 0, 0);
4443 pNewItem->bSelected = false;
4444
4445 HRESULT hr = m_Items.Add(pNewItem);
4446 if (FAILED(hr))
4447 {
4448 SAFE_DELETE(pNewItem);
4449 }
4450 else
4451 {
4453 }
4454
4455 return hr;
4456}
4457
4458
4459//--------------------------------------------------------------------------------------
4460HRESULT RiseListBox::InsertItem(int nIndex, const WCHAR* wszText, void* pData)
4461{
4462 UIListBoxItem* pNewItem = new UIListBoxItem;
4463 if (!pNewItem)
4464 return E_OUTOFMEMORY;
4465
4466 wcscpy_s(pNewItem->strText, 256, wszText);
4467 pNewItem->pData = pData;
4468 SetRect(&pNewItem->rcActive, 0, 0, 0, 0);
4469 pNewItem->bSelected = false;
4470
4471 HRESULT hr = m_Items.Insert(nIndex, pNewItem);
4472 if (SUCCEEDED(hr))
4474 else
4475 SAFE_DELETE(pNewItem);
4476
4477 return hr;
4478}
4479
4480
4481//--------------------------------------------------------------------------------------
4483{
4484 if (nIndex < 0 || nIndex >= (int)m_Items.GetSize())
4485 return;
4486
4487 UIListBoxItem* pItem = m_Items.GetAt(nIndex);
4488
4489 delete pItem;
4490 m_Items.Remove(nIndex);
4492 if (m_nSelected >= (int)m_Items.GetSize())
4493 m_nSelected = m_Items.GetSize() - 1;
4494
4496}
4497
4498
4499//--------------------------------------------------------------------------------------
4500
4501
4502
4503//--------------------------------------------------------------------------------------
4505{
4506}
4507
4508
4509//--------------------------------------------------------------------------------------
4511{
4512 for (int i = 0; i < m_Items.GetSize(); ++i)
4513 {
4514 UIListBoxItem* pItem = m_Items.GetAt(i);
4515 delete pItem;
4516 }
4517
4520}
4521
4522
4523//--------------------------------------------------------------------------------------
4525{
4526 if (nIndex < 0 || nIndex >= (int)m_Items.GetSize())
4527 return NULL;
4528
4529 return m_Items[nIndex];
4530}
4531
4532
4533//--------------------------------------------------------------------------------------
4534// For single-selection listbox, returns the index of the selected item.
4535// For multi-selection, returns the first selected item after the nPreviousSelected position.
4536// To search for the first selected item, the app passes -1 for nPreviousSelected. For
4537// subsequent searches, the app passes the returned index back to GetSelectedIndex as.
4538// nPreviousSelected.
4539// Returns -1 on error or if no item is selected.
4540int RiseListBox::GetSelectedIndex(int nPreviousSelected)
4541{
4542 if (nPreviousSelected < -1)
4543 return -1;
4544
4546 {
4547 // Multiple selection enabled. Search for the next item with the selected flag.
4548 for (int i = nPreviousSelected + 1; i < (int)m_Items.GetSize(); ++i)
4549 {
4550 UIListBoxItem* pItem = m_Items.GetAt(i);
4551
4552 if (pItem->bSelected)
4553 return i;
4554 }
4555
4556 return -1;
4557 }
4558 else
4559 {
4560 // Single selection
4561 return m_nSelected;
4562 }
4563}
4564
4565
4566//--------------------------------------------------------------------------------------
4567void RiseListBox::SelectItem(int nNewIndex)
4568{
4569 // If no item exists, do nothing.
4570 if (m_Items.GetSize() == 0)
4571 return;
4572
4573 int nOldSelected = m_nSelected;
4574
4575 // Adjust m_nSelected
4576 m_nSelected = nNewIndex;
4577
4578 // Perform capping
4579 if (m_nSelected < 0)
4580 m_nSelected = 0;
4581 if (m_nSelected >= (int)m_Items.GetSize())
4582 m_nSelected = m_Items.GetSize() - 1;
4583
4584 if (nOldSelected != m_nSelected)
4585 {
4587 {
4588 m_Items[m_nSelected]->bSelected = true;
4589 }
4590
4591 // Update selection start
4593
4594 // Adjust scroll bar
4596 }
4597
4599}
4600
4601
4602//--------------------------------------------------------------------------------------
4603bool RiseListBox::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
4604{
4605 if (!m_bEnabled || !m_bVisible)
4606 return false;
4607
4608 // Let the scroll bar have a chance to handle it first
4609 if (m_ScrollBar.HandleKeyboard(uMsg, wParam, lParam))
4610 return true;
4611
4612 switch (uMsg)
4613 {
4614 case WM_KEYDOWN:
4615 switch (wParam)
4616 {
4617 case VK_UP:
4618 case VK_DOWN:
4619 case VK_NEXT:
4620 case VK_PRIOR:
4621 case VK_HOME:
4622 case VK_END:
4623 {
4624 // If no item exists, do nothing.
4625 if (m_Items.GetSize() == 0)
4626 return true;
4627
4628 int nOldSelected = m_nSelected;
4629
4630 // Adjust m_nSelected
4631 switch (wParam)
4632 {
4633 case VK_UP:
4634 --m_nSelected; break;
4635 case VK_DOWN:
4636 ++m_nSelected; break;
4637 case VK_NEXT:
4638 m_nSelected += m_ScrollBar.GetPageSize() - 1; break;
4639 case VK_PRIOR:
4640 m_nSelected -= m_ScrollBar.GetPageSize() - 1; break;
4641 case VK_HOME:
4642 m_nSelected = 0; break;
4643 case VK_END:
4644 m_nSelected = m_Items.GetSize() - 1; break;
4645 }
4646
4647 // Perform capping
4648 if (m_nSelected < 0)
4649 m_nSelected = 0;
4650 if (m_nSelected >= (int)m_Items.GetSize())
4651 m_nSelected = m_Items.GetSize() - 1;
4652
4653 if (nOldSelected != m_nSelected)
4654 {
4656 {
4657 // Multiple selection
4658
4659 // Clear all selection
4660 for (int i = 0; i < (int)m_Items.GetSize(); ++i)
4661 {
4662 UIListBoxItem* pItem = m_Items[i];
4663 pItem->bSelected = false;
4664 }
4665
4666 if (GetKeyState(VK_SHIFT) < 0)
4667 {
4668 // Select all items from m_nSelStart to
4669 // m_nSelected
4670 int nEnd = __max(m_nSelStart, m_nSelected);
4671
4672 for (int n = __min(m_nSelStart, m_nSelected); n <= nEnd; ++n)
4673 m_Items[n]->bSelected = true;
4674 }
4675 else
4676 {
4677 m_Items[m_nSelected]->bSelected = true;
4678
4679 // Update selection start
4681 }
4682 }
4683 else
4685
4686 // Adjust scroll bar
4687
4689
4690 // Send notification
4691
4693 }
4694 return true;
4695 }
4696
4697 // Space is the hotkey for double-clicking an item.
4698 //
4699 case VK_SPACE:
4701 return true;
4702 }
4703 break;
4704 }
4705
4706 return false;
4707}
4708
4709
4710//--------------------------------------------------------------------------------------
4711bool RiseListBox::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
4712{
4713 if (!m_bEnabled || !m_bVisible)
4714 return false;
4715
4716 // First acquire focus
4717 if (WM_LBUTTONDOWN == uMsg)
4718 if (!m_bHasFocus)
4719 m_pDialog->RequestFocus(this);
4720
4721 // Let the scroll bar handle it first.
4722 if (m_ScrollBar.HandleMouse(uMsg, pt, wParam, lParam))
4723 return true;
4724
4725 switch (uMsg)
4726 {
4727 case WM_LBUTTONDOWN:
4728 case WM_LBUTTONDBLCLK:
4729 // Check for clicks in the text area
4730 if (m_Items.GetSize() > 0 && PtInRect(&m_rcSelection, pt))
4731 {
4732 // Compute the index of the clicked item
4733
4734 int nClicked;
4735 if (m_nTextHeight)
4736 nClicked = m_ScrollBar.GetTrackPos() + (pt.y - m_rcText.top) / m_nTextHeight;
4737 else
4738 nClicked = -1;
4739
4740 // Only proceed if the click falls on top of an item.
4741
4742 if (nClicked >= m_ScrollBar.GetTrackPos() &&
4743 nClicked < (int)m_Items.GetSize() &&
4745 {
4746 SetCapture(Rendering::ClientWindow());
4747 m_bDrag = true;
4748
4749 // If this is a double click, fire off an event and exit
4750 // since the first click would have taken care of the selection
4751 // updating.
4752 if (uMsg == WM_LBUTTONDBLCLK)
4753 {
4755 return true;
4756 }
4757
4758 m_nSelected = nClicked;
4759 if (!(wParam & MK_SHIFT))
4761
4762 // If this is a multi-selection listbox, update per-item
4763 // selection data.
4764
4766 {
4767 // Determine behavior based on the state of Shift and Ctrl
4768
4770 if ((wParam & (MK_SHIFT | MK_CONTROL)) == MK_CONTROL)
4771 {
4772 // Control click. Reverse the selection of this item.
4773
4774 pSelItem->bSelected = !pSelItem->bSelected;
4775 }
4776 else if ((wParam & (MK_SHIFT | MK_CONTROL)) == MK_SHIFT)
4777 {
4778 // Shift click. Set the selection for all items
4779 // from last selected item to the current item.
4780 // Clear everything else.
4781
4782 int nBegin = __min(m_nSelStart, m_nSelected);
4783 int nEnd = __max(m_nSelStart, m_nSelected);
4784
4785 for (int i = 0; i < nBegin; ++i)
4786 {
4787 UIListBoxItem* pItem = m_Items.GetAt(i);
4788 pItem->bSelected = false;
4789 }
4790
4791 for (int i = nEnd + 1; i < (int)m_Items.GetSize(); ++i)
4792 {
4793 UIListBoxItem* pItem = m_Items.GetAt(i);
4794 pItem->bSelected = false;
4795 }
4796
4797 for (int i = nBegin; i <= nEnd; ++i)
4798 {
4799 UIListBoxItem* pItem = m_Items.GetAt(i);
4800 pItem->bSelected = true;
4801 }
4802 }
4803 else if ((wParam & (MK_SHIFT | MK_CONTROL)) == (MK_SHIFT | MK_CONTROL))
4804 {
4805 // Control-Shift-click.
4806
4807 // The behavior is:
4808 // Set all items from m_nSelStart to m_nSelected to
4809 // the same state as m_nSelStart, not including m_nSelected.
4810 // Set m_nSelected to selected.
4811
4812 int nBegin = __min(m_nSelStart, m_nSelected);
4813 int nEnd = __max(m_nSelStart, m_nSelected);
4814
4815 // The two ends do not need to be set here.
4816
4817 bool bLastSelected = m_Items.GetAt(m_nSelStart)->bSelected;
4818 for (int i = nBegin + 1; i < nEnd; ++i)
4819 {
4820 UIListBoxItem* pItem = m_Items.GetAt(i);
4821 pItem->bSelected = bLastSelected;
4822 }
4823
4824 pSelItem->bSelected = true;
4825
4826 // Restore m_nSelected to the previous value
4827 // This matches the Windows behavior
4828
4830 }
4831 else
4832 {
4833 // Simple click. Clear all items and select the clicked
4834 // item.
4835
4836
4837 for (int i = 0; i < (int)m_Items.GetSize(); ++i)
4838 {
4839 UIListBoxItem* pItem = m_Items.GetAt(i);
4840 pItem->bSelected = false;
4841 }
4842
4843 pSelItem->bSelected = true;
4844 }
4845 } // End of multi-selection case
4846
4848 }
4849
4850 return true;
4851 }
4852 break;
4853
4854 case WM_LBUTTONUP:
4855 {
4856 ReleaseCapture();
4857 m_bDrag = false;
4858
4859 if (m_nSelected != -1)
4860 {
4861 // Set all items between m_nSelStart and m_nSelected to
4862 // the same state as m_nSelStart
4863 int nEnd = __max(m_nSelStart, m_nSelected);
4864
4865 for (int n = __min(m_nSelStart, m_nSelected) + 1; n < nEnd; ++n)
4866 m_Items[n]->bSelected = m_Items[m_nSelStart]->bSelected;
4867 m_Items[m_nSelected]->bSelected = m_Items[m_nSelStart]->bSelected;
4868
4869 // If m_nSelStart and m_nSelected are not the same,
4870 // the user has dragged the mouse to make a selection.
4871 // Notify the application of this.
4872 if (m_nSelStart != m_nSelected)
4874
4876 }
4877 return false;
4878 }
4879
4880 case WM_MOUSEMOVE:
4881 if (m_bDrag)
4882 {
4883 // Compute the index of the item below cursor
4884
4885 int nItem;
4886 if (m_nTextHeight)
4887 nItem = m_ScrollBar.GetTrackPos() + (pt.y - m_rcText.top) / m_nTextHeight;
4888 else
4889 nItem = -1;
4890
4891 // Only proceed if the cursor is on top of an item.
4892
4893 if (nItem >= (int)m_ScrollBar.GetTrackPos() &&
4894 nItem < (int)m_Items.GetSize() &&
4896 {
4897 m_nSelected = nItem;
4899 }
4900 else if (nItem < (int)m_ScrollBar.GetTrackPos())
4901 {
4902 // User drags the mouse above window top
4903 m_ScrollBar.Scroll(-1);
4906 }
4907 else if (nItem >= m_ScrollBar.GetTrackPos() + m_ScrollBar.GetPageSize())
4908 {
4909 // User drags the mouse below window bottom
4912 m_ScrollBar.GetPageSize()) - 1;
4914 }
4915 }
4916 break;
4917
4918 case WM_MOUSEWHEEL:
4919 {
4920 UINT uLines;
4921 SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &uLines, 0);
4922 int nScrollAmount = int((short)HIWORD(wParam)) / WHEEL_DELTA * uLines;
4923 m_ScrollBar.Scroll(-nScrollAmount);
4924 return true;
4925 }
4926 }
4927
4928 return false;
4929}
4930
4931
4932//--------------------------------------------------------------------------------------
4933bool RiseListBox::MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
4934{
4935 if (WM_CAPTURECHANGED == uMsg)
4936 {
4937 // The application just lost mouse capture. We may not have gotten
4938 // the WM_MOUSEUP message, so reset m_bDrag here.
4939 if ((HWND)lParam != Rendering::ClientWindow())
4940 m_bDrag = false;
4941 }
4942
4943 return false;
4944}
4945
4946
4947//--------------------------------------------------------------------------------------
4948void RiseListBox::Render(float fElapsedTime)
4949{
4950 if (m_bVisible == false)
4951 return;
4952
4953 RiseElement* pElement = m_Elements.GetAt(0);
4954 pElement->TextureColor.Blend(UI_STATE_NORMAL, fElapsedTime);
4955 pElement->FontColor.Blend(UI_STATE_NORMAL, fElapsedTime);
4956
4957 RiseElement* pSelElement = m_Elements.GetAt(1);
4958 pSelElement->TextureColor.Blend(UI_STATE_NORMAL, fElapsedTime);
4959 pSelElement->FontColor.Blend(UI_STATE_NORMAL, fElapsedTime);
4960
4962
4963 // Render the text
4964 if (m_Items.GetSize() > 0)
4965 {
4966 // Find out the height of a single line of text
4967 RECT rc = m_rcText;
4968 RECT rcSel = m_rcSelection;
4969 rc.bottom = rc.top + m_pDialog->GetManager()->GetFontNode(pElement->iFont)->nHeight;
4970
4971 // Update the line height formation
4972 m_nTextHeight = rc.bottom - rc.top;
4973
4974 static bool bSBInit;
4975 if (!bSBInit)
4976 {
4977 // Update the page size of the scroll bar
4978 if (m_nTextHeight)
4980 else
4982 bSBInit = true;
4983 }
4984
4985 rc.right = m_rcText.right;
4986 for (int i = m_ScrollBar.GetTrackPos(); i < (int)m_Items.GetSize(); ++i)
4987 {
4988 if (rc.bottom > m_rcText.bottom)
4989 break;
4990
4991 UIListBoxItem* pItem = m_Items.GetAt(i);
4992
4993 // Determine if we need to render this item with the
4994 // selected element.
4995 bool bSelectedStyle = false;
4996
4997 if (!(m_dwStyle & MULTISELECTION) && i == m_nSelected)
4998 bSelectedStyle = true;
4999 else if (m_dwStyle & MULTISELECTION)
5000 {
5001 if (m_bDrag &&
5002 ((i >= m_nSelected && i < m_nSelStart) ||
5003 (i <= m_nSelected && i > m_nSelStart)))
5004 bSelectedStyle = m_Items[m_nSelStart]->bSelected;
5005 else if (pItem->bSelected)
5006 bSelectedStyle = true;
5007 }
5008
5009 if (bSelectedStyle)
5010 {
5011 rcSel.top = rc.top; rcSel.bottom = rc.bottom;
5012 m_pDialog->DrawSprite(pSelElement, &rcSel, UI_NEAR_BUTTON_DEPTH);
5013 m_pDialog->DrawText(pItem->strText, pSelElement, &rc);
5014 }
5015 else
5016 m_pDialog->DrawText(pItem->strText, pElement, &rc);
5017
5018 OffsetRect(&rc, 0, m_nTextHeight);
5019 }
5020 }
5021
5022 // Render the scroll bar
5023
5024 m_ScrollBar.Render(fElapsedTime);
5025}
5026
5027
5028// Static member initialization
5029HINSTANCE CUniBuffer::s_hDll = NULL;
5030HRESULT(WINAPI* CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*,
5031 SCRIPT_STATE*) = Dummy_ScriptApplyDigitSubstitution;
5032HRESULT(WINAPI* CUniBuffer::_ScriptStringAnalyse)(HDC, const void*, int, int, int, DWORD, int, SCRIPT_CONTROL*,
5033 SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*,
5034 SCRIPT_STRING_ANALYSIS*) = Dummy_ScriptStringAnalyse;
5035HRESULT(WINAPI* CUniBuffer::_ScriptStringCPtoX)(SCRIPT_STRING_ANALYSIS, int, BOOL, int*) = Dummy_ScriptStringCPtoX;
5036HRESULT(WINAPI* CUniBuffer::_ScriptStringXtoCP)(SCRIPT_STRING_ANALYSIS, int, int*, int*) = Dummy_ScriptStringXtoCP;
5037HRESULT(WINAPI* CUniBuffer::_ScriptStringFree)(SCRIPT_STRING_ANALYSIS*) = Dummy_ScriptStringFree;
5038const SCRIPT_LOGATTR* (WINAPI* CUniBuffer::_ScriptString_pLogAttr)(SCRIPT_STRING_ANALYSIS) =
5039Dummy_ScriptString_pLogAttr;
5040const int* (WINAPI* CUniBuffer::_ScriptString_pcOutChars)(SCRIPT_STRING_ANALYSIS) =
5041Dummy_ScriptString_pcOutChars;
5042bool RiseEditBox::s_bHideCaret; // If true, we don't render the caret.
5043
5044
5045
5046//--------------------------------------------------------------------------------------
5047// RiseEditBox class
5048//--------------------------------------------------------------------------------------
5049
5050// When scrolling, EDITBOX_SCROLLEXTENT is reciprocal of the amount to scroll.
5051// If EDITBOX_SCROLLEXTENT = 4, then we scroll 1/4 of the control each time.
5052#define EDITBOX_SCROLLEXTENT 4
5053
5054//--------------------------------------------------------------------------------------
5056{
5058 m_pDialog = pDialog;
5059
5060 m_nBorder = 5; // Default border width
5061 m_nSpacing = 4; // Default spacing
5062
5063 m_bCaretOn = true;
5064 m_dfBlink = GetCaretBlinkTime() * 0.001f;
5066 s_bHideCaret = false;
5067 m_nFirstVisible = 0;
5068 m_TextColor = Rendering::ColorARGB(255, 16, 16, 16);
5069 m_SelTextColor = Rendering::ColorARGB(255, 255, 255, 255);
5070 m_SelBkColor = Rendering::ColorARGB(255, 40, 50, 92);
5071 m_CaretColor = Rendering::ColorARGB(255, 0, 0, 0);
5072 m_nCaret = m_nSelStart = 0;
5073 m_bInsertMode = true;
5074
5075 m_bMouseDrag = false;
5076}
5077
5078
5079//--------------------------------------------------------------------------------------
5083
5084
5085//--------------------------------------------------------------------------------------
5086// PlaceCaret: Set the caret to a character position, and adjust the scrolling if
5087// necessary.
5088//--------------------------------------------------------------------------------------
5090{
5091 assert(nCP >= 0 && nCP <= m_Buffer.GetTextSize());
5092 m_nCaret = nCP;
5093
5094 // Obtain the X offset of the character.
5095 int nX1st, nX, nX2;
5096 m_Buffer.CPtoX(m_nFirstVisible, FALSE, &nX1st); // 1st visible char
5097 m_Buffer.CPtoX(nCP, FALSE, &nX); // LEAD
5098 // If nCP is the NULL terminator, get the leading edge instead of trailing.
5099 if (nCP == m_Buffer.GetTextSize())
5100 nX2 = nX;
5101 else
5102 m_Buffer.CPtoX(nCP, TRUE, &nX2); // TRAIL
5103
5104 // If the left edge of the char is smaller than the left edge of the 1st visible char,
5105 // we need to scroll left until this char is visible.
5106 if (nX < nX1st)
5107 {
5108 // Simply make the first visible character the char at the new caret position.
5109 m_nFirstVisible = nCP;
5110 }
5111 else // If the right of the character is bigger than the offset of the control's
5112 // right edge, we need to scroll right to this character.
5113 if (nX2 > nX1st + RectWidth(m_rcText))
5114 {
5115 // Compute the X of the new left-most pixel
5116 int nXNewLeft = nX2 - RectWidth(m_rcText);
5117
5118 // Compute the char position of this character
5119 int nCPNew1st, nNewTrail;
5120 m_Buffer.XtoCP(nXNewLeft, &nCPNew1st, &nNewTrail);
5121
5122 // If this coordinate is not on a character border,
5123 // start from the next character so that the caret
5124 // position does not fall outside the text rectangle.
5125 int nXNew1st;
5126 m_Buffer.CPtoX(nCPNew1st, FALSE, &nXNew1st);
5127 if (nXNew1st < nXNewLeft)
5128 ++nCPNew1st;
5129
5130 m_nFirstVisible = nCPNew1st;
5131 }
5132}
5133
5134
5135//--------------------------------------------------------------------------------------
5137{
5138 m_Buffer.Clear();
5139 m_nFirstVisible = 0;
5140 PlaceCaret(0);
5141 m_nSelStart = 0;
5142}
5143
5144
5145//--------------------------------------------------------------------------------------
5146void RiseEditBox::SetText(LPCWSTR wszText, bool bSelected)
5147{
5148 assert(wszText != NULL);
5149
5150 m_Buffer.SetText(wszText);
5151 m_nFirstVisible = 0;
5152 // Move the caret to the end of the text
5154 m_nSelStart = bSelected ? 0 : m_nCaret;
5155}
5156
5157
5158//--------------------------------------------------------------------------------------
5159HRESULT RiseEditBox::GetTextCopy(__out_ecount(bufferCount) LPWSTR strDest,
5160 UINT bufferCount)
5161{
5162 assert(strDest);
5163
5164 wcscpy_s(strDest, bufferCount, m_Buffer.GetBuffer());
5165
5166 return S_OK;
5167}
5168
5169
5170//--------------------------------------------------------------------------------------
5172{
5173 int nFirst = __min(m_nCaret, m_nSelStart);
5174 int nLast = __max(m_nCaret, m_nSelStart);
5175 // Update caret and selection
5176 PlaceCaret(nFirst);
5178 // Remove the characters
5179 for (int i = nFirst; i < nLast; ++i)
5180 m_Buffer.RemoveChar(nFirst);
5181}
5182
5183
5184//--------------------------------------------------------------------------------------
5186{
5188
5189 // Update the text rectangle
5191 // First inflate by m_nBorder to compute render rects
5192 InflateRect(&m_rcText, -m_nBorder, -m_nBorder);
5193
5194 // Update the render rectangles
5195 m_rcRender[0] = m_rcText;
5196 SetRect(&m_rcRender[1], m_rcBoundingBox.left, m_rcBoundingBox.top, m_rcText.left, m_rcText.top);
5197 SetRect(&m_rcRender[2], m_rcText.left, m_rcBoundingBox.top, m_rcText.right, m_rcText.top);
5198 SetRect(&m_rcRender[3], m_rcText.right, m_rcBoundingBox.top, m_rcBoundingBox.right, m_rcText.top);
5199 SetRect(&m_rcRender[4], m_rcBoundingBox.left, m_rcText.top, m_rcText.left, m_rcText.bottom);
5200 SetRect(&m_rcRender[5], m_rcText.right, m_rcText.top, m_rcBoundingBox.right, m_rcText.bottom);
5201 SetRect(&m_rcRender[6], m_rcBoundingBox.left, m_rcText.bottom, m_rcText.left, m_rcBoundingBox.bottom);
5202 SetRect(&m_rcRender[7], m_rcText.left, m_rcText.bottom, m_rcText.right, m_rcBoundingBox.bottom);
5203 SetRect(&m_rcRender[8], m_rcText.right, m_rcText.bottom, m_rcBoundingBox.right, m_rcBoundingBox.bottom);
5204
5205 // Inflate further by m_nSpacing
5206 InflateRect(&m_rcText, -m_nSpacing, -m_nSpacing);
5207}
5208
5209
5211{
5212 if (m_bIsPassword) return;
5213
5214 // Copy the selection text to the clipboard
5215 if (m_nCaret != m_nSelStart && OpenClipboard(NULL))
5216 {
5217 EmptyClipboard();
5218
5219 HGLOBAL hBlock = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * (m_Buffer.GetTextSize() + 1));
5220 if (hBlock)
5221 {
5222 WCHAR* pwszText = (WCHAR*)GlobalLock(hBlock);
5223 if (pwszText)
5224 {
5225 int nFirst = __min(m_nCaret, m_nSelStart);
5226 int nLast = __max(m_nCaret, m_nSelStart);
5227 if (nLast - nFirst > 0)
5228 CopyMemory(pwszText, m_Buffer.GetBuffer() + nFirst, (nLast - nFirst) * sizeof(WCHAR));
5229 pwszText[nLast - nFirst] = L'\0'; // Terminate it
5230 GlobalUnlock(hBlock);
5231 }
5232 SetClipboardData(CF_UNICODETEXT, hBlock);
5233 }
5234 CloseClipboard();
5235 // We must not free the object until CloseClipboard is called.
5236 if (hBlock)
5237 GlobalFree(hBlock);
5238 }
5239}
5240
5241
5243{
5245
5246 if (OpenClipboard(NULL))
5247 {
5248 HANDLE handle = GetClipboardData(CF_UNICODETEXT);
5249 if (handle)
5250 {
5251 // Convert the ANSI string to Unicode, then
5252 // insert to our buffer.
5253 WCHAR* pwszText = (WCHAR*)GlobalLock(handle);
5254 if (pwszText)
5255 {
5256 // Copy all characters up to null.
5257 if (m_Buffer.InsertString(m_nCaret, pwszText))
5258 PlaceCaret(m_nCaret + lstrlenW(pwszText));
5260 GlobalUnlock(handle);
5261 }
5262 }
5263 CloseClipboard();
5264 }
5265}
5266
5267
5268//--------------------------------------------------------------------------------------
5269bool RiseEditBox::HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
5270{
5271 if (!m_bEnabled || !m_bVisible)
5272 return false;
5273
5274 bool bHandled = false;
5275 int keystate = GetKeyState(VK_SHIFT);
5276 bool g_bShift = keystate < 0;
5277
5278 switch (uMsg)
5279 {
5280 case WM_KEYDOWN:
5281 {
5282 switch (wParam)
5283 {
5284 case VK_TAB:
5285 // We don't process Tab in case keyboard input is enabled and the user
5286 // wishes to Tab to other controls.
5287 break;
5288
5289 case VK_HOME:
5290 m_nCaret = m_nSelStart; // end
5291 m_nSelStart = 0;
5292 if (!g_bShift)
5293 {
5294 // Shift is not down. Update selection
5295 // start along with the caret.
5296 m_nCaret = 0;
5297 }
5299 bHandled = true;
5300 break;
5301
5302 case VK_END:
5304 if (!g_bShift)
5305 {
5306 // Shift is not down. Update selection
5307 // start along with the caret.
5309 }
5311 bHandled = true;
5312 break;
5313
5314 case VK_INSERT:
5315 if (GetKeyState(VK_CONTROL) < 0)
5316 {
5317 // Control Insert. Copy to clipboard
5319 }
5320 else if (GetKeyState(VK_SHIFT) < 0)
5321 {
5322 // Shift Insert. Paste from clipboard
5324 }
5325 else
5326 {
5327 // Toggle caret insert mode
5329 }
5330 break;
5331
5332 case VK_DELETE:
5333 // Check if there is a text selection.
5334 if (m_nCaret != m_nSelStart)
5335 {
5338 }
5339 else
5340 {
5341 // Deleting one character
5344 }
5346 bHandled = true;
5347 break;
5348
5349 case VK_LEFT:
5350 if (GetKeyState(VK_CONTROL) < 0)
5351 {
5352 // Control is down. Move the caret to a new item
5353 // instead of a character.
5356 }
5357 else if (m_nCaret > 0)
5358 PlaceCaret(m_nCaret - 1);
5359 if (!g_bShift)
5360 // Shift is not down. Update selection
5361 // start along with the caret.
5364 bHandled = true;
5365 break;
5366
5367 case VK_RIGHT:
5368 if (GetKeyState(VK_CONTROL) < 0)
5369 {
5370 // Control is down. Move the caret to a new item
5371 // instead of a character.
5374 }
5375 else if (m_nCaret < m_Buffer.GetTextSize())
5376 PlaceCaret(m_nCaret + 1);
5377 if (!g_bShift)
5378 // Shift is not down. Update selection
5379 // start along with the caret.
5382 bHandled = true;
5383 break;
5384
5385 case VK_UP:
5386 case VK_DOWN:
5387 // Trap up and down arrows so that the dialog
5388 // does not switch focus to another control.
5389 bHandled = true;
5390 break;
5391
5392 default:
5393 bHandled = wParam != VK_ESCAPE; // Let the application handle Esc.
5394 }
5395 }
5396 }
5397 return bHandled;
5398}
5399
5400
5401//--------------------------------------------------------------------------------------
5402bool RiseEditBox::HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
5403{
5404 if (!m_bEnabled || !m_bVisible)
5405 return false;
5406
5407 switch (uMsg)
5408 {
5409 case WM_LBUTTONDOWN:
5410 {
5411 if (!m_bHasFocus)
5412 m_pDialog->RequestFocus(this);
5413
5414 if (!ContainsPoint(pt))
5415 return false;
5416
5417 m_bMouseDrag = true;
5418 SetCapture(Rendering::ClientWindow());
5419 // Determine the character corresponding to the coordinates.
5420 int nCP, nTrail, nX1st;
5421 m_Buffer.CPtoX(m_nFirstVisible, FALSE, &nX1st); // X offset of the 1st visible char
5422 if (SUCCEEDED(m_Buffer.XtoCP(pt.x - m_rcText.left + nX1st, &nCP, &nTrail)))
5423 {
5424 // Cap at the NULL character.
5425 if (nTrail && nCP < m_Buffer.GetTextSize())
5426 PlaceCaret(nCP + 1);
5427 else
5428 PlaceCaret(nCP);
5431 }
5432 return true;
5433 }
5434
5435 case WM_LBUTTONDBLCLK:
5436 {
5437 m_nSelStart = 0;
5439 return true;
5440 }
5441
5442 case WM_LBUTTONUP:
5443 ReleaseCapture();
5444 m_bMouseDrag = false;
5445 break;
5446
5447 case WM_MOUSEMOVE:
5448 if (m_bMouseDrag)
5449 {
5450 // Determine the character corresponding to the coordinates.
5451 int nCP, nTrail, nX1st;
5452 m_Buffer.CPtoX(m_nFirstVisible, FALSE, &nX1st); // X offset of the 1st visible char
5453 if (SUCCEEDED(m_Buffer.XtoCP(pt.x - m_rcText.left + nX1st, &nCP, &nTrail)))
5454 {
5455 // Cap at the NULL character.
5456 if (nTrail && nCP < m_Buffer.GetTextSize())
5457 PlaceCaret(nCP + 1);
5458 else
5459 PlaceCaret(nCP);
5460 }
5461 }
5462 break;
5463 }
5464
5465 return false;
5466}
5467
5468
5469//--------------------------------------------------------------------------------------
5471{
5473
5475}
5476
5477
5478//--------------------------------------------------------------------------------------
5479bool RiseEditBox::MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
5480{
5481 if (!m_bEnabled || !m_bVisible)
5482 return false;
5483
5484 switch (uMsg)
5485 {
5486 // Make sure that while editing, the keyup and keydown messages associated with
5487 // WM_CHAR messages don't go to any non-focused controls or cameras
5488 case WM_KEYUP:
5489 case WM_KEYDOWN:
5490 {
5491 // home, left right ctrl-home ctrl-shift-left ctrl-shift-right ctrl-end ctrl-shift-end
5492 switch ((WCHAR)wParam)
5493 {
5494 case VK_SHIFT:
5495 return true;
5496 default:
5497 break;
5498
5499 }
5500 }
5501 break;
5502
5503 case WM_CHAR:
5504 {
5505 switch ((WCHAR)wParam)
5506 {
5507 // Backspace
5508 case VK_BACK:
5509 {
5510 // If there's a selection, treat this
5511 // like a delete key.
5512 if (m_nCaret != m_nSelStart)
5513 {
5516 }
5517 else if (m_nCaret > 0)
5518 {
5519 // Move the caret, then delete the char.
5520 PlaceCaret(m_nCaret - 1);
5524 }
5526 break;
5527 }
5528
5529 case 24: // Ctrl-X Cut
5530 case VK_CANCEL: // Ctrl-C Copy
5531 {
5533
5534 // If the key is Ctrl-X, delete the selection too.
5535 if ((WCHAR)wParam == 24)
5536 {
5539 }
5540
5541 break;
5542 }
5543
5544 // Ctrl-V Paste
5545 case 22:
5546 {
5549 break;
5550 }
5551
5552 // Ctrl-A Select All
5553 case 1:
5554 if (m_nSelStart == m_nCaret)
5555 {
5556 m_nSelStart = 0;
5558 }
5559 break;
5560
5561 case VK_RETURN:
5562 // Invoke the callback when the user presses Enter.
5564 break;
5565
5566 case VK_ESCAPE:
5568 break;
5569
5570 // Junk characters we don't want in the string
5571 case 26: // Ctrl Z
5572 case 2: // Ctrl B
5573 case 14: // Ctrl N
5574 case 19: // Ctrl S
5575 case 4: // Ctrl D
5576 case 6: // Ctrl F
5577 case 7: // Ctrl G
5578 case 10: // Ctrl J
5579 case 11: // Ctrl K
5580 case 12: // Ctrl L
5581 case 17: // Ctrl Q
5582 case 23: // Ctrl W
5583 case 5: // Ctrl E
5584 case 18: // Ctrl R
5585 case 20: // Ctrl T
5586 case 25: // Ctrl Y
5587 case 21: // Ctrl U
5588 case 9: // Ctrl I
5589 case 15: // Ctrl O
5590 case 16: // Ctrl P
5591 //case 27: // Ctrl [
5592 case 29: // Ctrl ]
5593 case 28: // Ctrl backslash
5594 break;
5595
5596 default:
5597 {
5598 // If there's a selection and the user
5599 // starts to type, the selection should
5600 // be deleted.
5601 if (m_nCaret != m_nSelStart)
5603
5604 // If we are in overwrite mode and there is already
5605 // a char at the caret's position, simply replace it.
5606 // Otherwise, we insert the char as normal.
5608 {
5609 m_Buffer[m_nCaret] = (WCHAR)wParam;
5610 PlaceCaret(m_nCaret + 1);
5612 }
5613 else
5614 {
5615 // Insert the char
5616 if (m_Buffer.InsertChar(m_nCaret, (WCHAR)wParam))
5617 {
5618 PlaceCaret(m_nCaret + 1);
5620 }
5621 }
5624 }
5625 }
5626 return true;
5627 }
5628 }
5629 return false;
5630}
5631
5632
5633//--------------------------------------------------------------------------------------
5634void RiseEditBox::Render(float fElapsedTime)
5635{
5636 if (!m_bVisible) return;
5637
5638 int nSelStartX = 0, nCaretX = 0; // Left and right X cordinates of the selection region
5639
5640 RiseElement* pElement = GetElement(0);
5641 if (pElement)
5642 {
5644 PlaceCaret(m_nCaret); // Call PlaceCaret now that we have the font info (node),
5645 // so that scrolling can be handled.
5646 }
5647
5648 // Render the control graphics
5649 for (int e = 0; e < 9; ++e)
5650 {
5651 pElement = m_Elements.GetAt(e);
5652 pElement->TextureColor.Blend(UI_STATE_NORMAL, fElapsedTime);
5653
5655 }
5656
5657 //
5658 // Compute the X coordinates of the first visible character.
5659 //
5660 int nXFirst;
5661 m_Buffer.CPtoX(m_nFirstVisible, FALSE, &nXFirst);
5662
5663 //
5664 // Compute the X coordinates of the selection rectangle
5665 //
5666 m_Buffer.CPtoX(m_nCaret, FALSE, &nCaretX);
5667 if (m_nCaret != m_nSelStart)
5668 m_Buffer.CPtoX(m_nSelStart, FALSE, &nSelStartX);
5669 else
5670 nSelStartX = nCaretX;
5671
5672 //
5673 // Render the selection rectangle
5674 //
5675 RECT rcSelection; // Make this available for rendering selected text
5676 if (m_nCaret != m_nSelStart)
5677 {
5678 int nSelLeftX = nCaretX, nSelRightX = nSelStartX;
5679 // Swap if left is bigger than right
5680 if (nSelLeftX > nSelRightX)
5681 {
5682 const int nTemp = nSelLeftX;
5683 nSelLeftX = nSelRightX;
5684 nSelRightX = nTemp;
5685 }
5686
5687 SetRect(&rcSelection, nSelLeftX, m_rcText.top, nSelRightX, m_rcText.bottom);
5688 OffsetRect(&rcSelection, m_rcText.left - nXFirst, 0);
5689 IntersectRect(&rcSelection, &m_rcText, &rcSelection);
5690
5692 if (pd3dDevice)
5694 m_pDialog->DrawRect(&rcSelection, m_SelBkColor);
5695 if (pd3dDevice)
5697 }
5698
5699 //
5700 // Render the text
5701 //
5702 // Element 0 for text
5704 const int count = wcslen(m_Buffer.GetBuffer() + m_nFirstVisible);
5705 if (!m_bIsPassword)
5707 else
5708 {
5709 WCHAR str[99];
5710 wmemset(str, passwordcharC, 98);
5711 m_pDialog->DrawText(str, m_Elements.GetAt(0), &m_rcText, false, count);
5712 }
5713
5714 // Render the selected text
5715 if (m_nCaret != m_nSelStart)
5716 {
5717 int nFirstToRender = __max(m_nFirstVisible, __min(m_nSelStart, m_nCaret));
5718 int nNumChatToRender = __max(m_nSelStart, m_nCaret) - nFirstToRender;
5720 if (!m_bIsPassword)
5721 m_pDialog->DrawText(m_Buffer.GetBuffer() + nFirstToRender, m_Elements.GetAt(0), &rcSelection, false, nNumChatToRender);
5722 else
5723 {
5724 WCHAR str[99];
5725 wmemset(str, passwordcharC, 98);
5726 m_pDialog->DrawText(str, m_Elements.GetAt(0), &rcSelection, false, nNumChatToRender);
5727 }
5728 }
5729
5730 //
5731 // Blink the caret
5732 //
5734 {
5737 }
5738
5739 //
5740 // Render the caret if this control has the focus
5741 //
5743 {
5744 // Start the rectangle with insert mode caret
5745 RECT rcCaret = { m_rcText.left - nXFirst + nCaretX - 1, m_rcText.top,
5746 m_rcText.left - nXFirst + nCaretX + 1, m_rcText.bottom };
5747
5748 // If we are in overwrite mode, adjust the caret rectangle
5749 // to fill the entire character.
5750 if (!m_bInsertMode)
5751 {
5752 // Obtain the right edge X coord of the current character
5753 int nRightEdgeX;
5754 m_Buffer.CPtoX(m_nCaret, TRUE, &nRightEdgeX);
5755 rcCaret.right = m_rcText.left - nXFirst + nRightEdgeX;
5756 }
5757
5758 m_pDialog->DrawRect(&rcCaret, m_CaretColor);
5759 }
5760}
5761
5762
5763#define IN_FLOAT_CHARSET( c ) \
5764 ( (c) == L'-' || (c) == L'.' || ( (c) >= L'0' && (c) <= L'9' ) )
5765
5766void RiseEditBox::ParseFloatArray(float* pNumbers, int nCount)
5767{
5768 int nWritten = 0; // Number of floats written
5769 const WCHAR* pToken, * pEnd;
5770 WCHAR wszToken[60];
5771
5772 pToken = m_Buffer.GetBuffer();
5773 while (nWritten < nCount && *pToken != L'\0')
5774 {
5775 // Skip leading spaces
5776 while (*pToken == L' ')
5777 ++pToken;
5778
5779 if (*pToken == L'\0')
5780 break;
5781
5782 // Locate the end of number
5783 pEnd = pToken;
5784 while (IN_FLOAT_CHARSET(*pEnd))
5785 ++pEnd;
5786
5787 // Copy the token to our buffer
5788 int nTokenLen = __min(sizeof(wszToken) / sizeof(wszToken[0]) - 1, int(pEnd - pToken));
5789 wcscpy_s(wszToken, nTokenLen, pToken);
5790 *pNumbers = (float)wcstod(wszToken, NULL);
5791 ++nWritten;
5792 ++pNumbers;
5793 pToken = pEnd;
5794 }
5795}
5796
5797
5798void RiseEditBox::SetTextFloatArray(const float* pNumbers, int nCount)
5799{
5800 WCHAR wszBuffer[512] = { 0 };
5801 WCHAR wszTmp[64];
5802
5803 if (pNumbers == NULL)
5804 return;
5805
5806 for (int i = 0; i < nCount; ++i)
5807 {
5808 swprintf_s(wszTmp, 64, L"%.4f ", pNumbers[i]);
5809 wcscat_s(wszBuffer, 512, wszTmp);
5810 }
5811
5812 // Don't want the last space
5813 if (nCount > 0 && wcslen(wszBuffer) > 0)
5814 wszBuffer[wcslen(wszBuffer) - 1] = 0;
5815
5816 SetText(wszBuffer);
5817}
5818
5819
5820
5821
5822//--------------------------------------------------------------------------------------
5824{
5825 if (s_hDll) // Only need to do once
5826 return;
5827
5828 s_hDll = LoadLibrary(UNISCRIBE_DLLNAME);
5829 if (s_hDll)
5830 {
5831 FARPROC Temp;
5832 GETPROCADDRESS(s_hDll, ScriptApplyDigitSubstitution, Temp);
5833 GETPROCADDRESS(s_hDll, ScriptStringAnalyse, Temp);
5834 GETPROCADDRESS(s_hDll, ScriptStringCPtoX, Temp);
5835 GETPROCADDRESS(s_hDll, ScriptStringXtoCP, Temp);
5836 GETPROCADDRESS(s_hDll, ScriptStringFree, Temp);
5837 GETPROCADDRESS(s_hDll, ScriptString_pLogAttr, Temp);
5838 GETPROCADDRESS(s_hDll, ScriptString_pcOutChars, Temp);
5839 }
5840}
5841
5842
5843//--------------------------------------------------------------------------------------
5845{
5846 if (s_hDll)
5847 {
5848 PLACEHOLDERPROC(ScriptApplyDigitSubstitution);
5849 PLACEHOLDERPROC(ScriptStringAnalyse);
5850 PLACEHOLDERPROC(ScriptStringCPtoX);
5851 PLACEHOLDERPROC(ScriptStringXtoCP);
5852 PLACEHOLDERPROC(ScriptStringFree);
5853 PLACEHOLDERPROC(ScriptString_pLogAttr);
5854 PLACEHOLDERPROC(ScriptString_pcOutChars);
5855
5856 FreeLibrary(s_hDll);
5857 s_hDll = NULL;
5858 }
5859}
5860
5861
5862//--------------------------------------------------------------------------------------
5864{
5865 // If the current size is already the maximum allowed,
5866 // we can't possibly allocate more.
5868 return false;
5869
5870 int nAllocateSize = (nNewSize == -1 || nNewSize < m_nBufferSize * 2) ? (m_nBufferSize ? m_nBufferSize *
5871 2 : 256) : nNewSize * 2;
5872
5873 // Cap the buffer size at the maximum allowed.
5874 if (nAllocateSize > UI_MAX_EDITBOXLENGTH)
5875 nAllocateSize = UI_MAX_EDITBOXLENGTH;
5876
5877 WCHAR* pTempBuffer = new WCHAR[nAllocateSize];
5878 if (!pTempBuffer)
5879 return false;
5880
5881 ZeroMemory(pTempBuffer, sizeof(WCHAR) * nAllocateSize);
5882
5883 if (m_pwszBuffer)
5884 {
5885 CopyMemory(pTempBuffer, m_pwszBuffer, m_nBufferSize * sizeof(WCHAR));
5886 delete[] m_pwszBuffer;
5887 }
5888
5889 m_pwszBuffer = pTempBuffer;
5890 m_nBufferSize = nAllocateSize;
5891 return true;
5892}
5893
5894
5895//--------------------------------------------------------------------------------------
5896// Uniscribe -- Analyse() analyses the string in the buffer
5897//--------------------------------------------------------------------------------------
5899{
5900 if (m_Analysis)
5901 _ScriptStringFree(&m_Analysis);
5902
5903 SCRIPT_CONTROL ScriptControl; // For uniscribe
5904 SCRIPT_STATE ScriptState; // For uniscribe
5905 ZeroMemory(&ScriptControl, sizeof(ScriptControl));
5906 ZeroMemory(&ScriptState, sizeof(ScriptState));
5907 _ScriptApplyDigitSubstitution(NULL, &ScriptControl, &ScriptState);
5908
5909 if (!m_pFontNode)
5910 return E_FAIL;
5911
5912 HDC hDC = m_pFontNode->font ? m_pFontNode->font->GetDC() : NULL;
5913 HRESULT hr = _ScriptStringAnalyse(hDC,
5915 lstrlenW(m_pwszBuffer) + 1, // NULL is also analyzed.
5916 lstrlenW(m_pwszBuffer) * 3 / 2 + 16,
5917 -1,
5918 SSA_BREAK | SSA_GLYPHS | SSA_FALLBACK | SSA_LINK,
5919 0,
5920 &ScriptControl,
5921 &ScriptState,
5922 NULL,
5923 NULL,
5924 NULL,
5925 &m_Analysis);
5926 if (SUCCEEDED(hr))
5927 m_bAnalyseRequired = false; // Analysis is up-to-date
5928 return hr;
5929}
5930
5931
5932//--------------------------------------------------------------------------------------
5933CUniBuffer::CUniBuffer(int nInitialSize)
5934{
5935 CUniBuffer::Initialize(); // ensure static vars are properly init'ed first
5936
5937 m_nBufferSize = 0;
5938 m_pwszBuffer = NULL;
5939 m_bAnalyseRequired = true;
5940 m_Analysis = NULL;
5941 m_pFontNode = NULL;
5942
5943 if (nInitialSize > 0)
5944 SetBufferSize(nInitialSize);
5945}
5946
5947
5948//--------------------------------------------------------------------------------------
5950{
5951 delete[] m_pwszBuffer;
5952 if (m_Analysis)
5953 _ScriptStringFree(&m_Analysis);
5954}
5955
5956
5957//--------------------------------------------------------------------------------------
5958WCHAR& CUniBuffer::operator[](int n) // No param checking
5959{
5960 // This version of operator[] is called only
5961 // if we are asking for write access, so
5962 // re-analysis is required.
5963 m_bAnalyseRequired = true;
5964 return m_pwszBuffer[n];
5965}
5966
5967
5968//--------------------------------------------------------------------------------------
5970{
5971 *m_pwszBuffer = L'\0';
5972 m_bAnalyseRequired = true;
5973}
5974
5975
5976//--------------------------------------------------------------------------------------
5977// Inserts the char at specified index.
5978// If nIndex == -1, insert to the end.
5979//--------------------------------------------------------------------------------------
5980bool CUniBuffer::InsertChar(int nIndex, WCHAR wChar)
5981{
5982 assert(nIndex >= 0);
5983
5984 if (nIndex < 0 || nIndex > lstrlenW(m_pwszBuffer))
5985 return false; // invalid index
5986
5987 // Check for maximum length allowed
5988 if (GetTextSize() + 1 >= UI_MAX_EDITBOXLENGTH)
5989 return false;
5990
5991 if (lstrlenW(m_pwszBuffer) + 1 >= m_nBufferSize)
5992 {
5993 if (!SetBufferSize(-1))
5994 return false; // out of memory
5995 }
5996
5997 assert(m_nBufferSize >= 2);
5998
5999 // Shift the characters after the index, start by copying the null terminator
6000 WCHAR* dest = m_pwszBuffer + lstrlenW(m_pwszBuffer) + 1;
6001 WCHAR* stop = m_pwszBuffer + nIndex;
6002 WCHAR* src = dest - 1;
6003
6004 while (dest > stop)
6005 {
6006 *dest-- = *src--;
6007 }
6008
6009 // Set new character
6010 m_pwszBuffer[nIndex] = wChar;
6011 m_bAnalyseRequired = true;
6012
6013 return true;
6014}
6015
6016
6017//--------------------------------------------------------------------------------------
6018// Removes the char at specified index.
6019// If nIndex == -1, remove the last char.
6020//--------------------------------------------------------------------------------------
6022{
6023 if (!lstrlenW(m_pwszBuffer) || nIndex < 0 || nIndex >= lstrlenW(m_pwszBuffer))
6024 return false; // Invalid index
6025
6026 MoveMemory(m_pwszBuffer + nIndex, m_pwszBuffer + nIndex + 1, sizeof(WCHAR) *
6027 (lstrlenW(m_pwszBuffer) - nIndex));
6028 m_bAnalyseRequired = true;
6029 return true;
6030}
6031
6032
6033//--------------------------------------------------------------------------------------
6034// Inserts the first nCount characters of the string pStr at specified index.
6035// If nCount == -1, the entire string is inserted.
6036// If nIndex == -1, insert to the end.
6037//--------------------------------------------------------------------------------------
6038bool CUniBuffer::InsertString(int nIndex, const WCHAR* pStr, int nCount)
6039{
6040 assert(nIndex >= 0);
6041 if (nIndex < 0)
6042 return false;
6043
6044 if (nIndex > lstrlenW(m_pwszBuffer))
6045 return false; // invalid index
6046
6047 if (-1 == nCount)
6048 nCount = lstrlenW(pStr);
6049
6050 // Check for maximum length allowed
6051 if (GetTextSize() + nCount >= UI_MAX_EDITBOXLENGTH)
6052 return false;
6053
6054 if (lstrlenW(m_pwszBuffer) + nCount >= m_nBufferSize)
6055 {
6056 if (!SetBufferSize(lstrlenW(m_pwszBuffer) + nCount + 1))
6057 return false; // out of memory
6058 }
6059
6060 MoveMemory(m_pwszBuffer + nIndex + nCount, m_pwszBuffer + nIndex, sizeof(WCHAR) *
6061 (lstrlenW(m_pwszBuffer) - nIndex + 1));
6062 CopyMemory(m_pwszBuffer + nIndex, pStr, nCount * sizeof(WCHAR));
6063 m_bAnalyseRequired = true;
6064
6065 return true;
6066}
6067
6068
6069//--------------------------------------------------------------------------------------
6070bool CUniBuffer::SetText(LPCWSTR wszText)
6071{
6072 assert(wszText != NULL);
6073
6074 int nRequired = int(wcslen(wszText) + 1);
6075
6076 // Check for maximum length allowed
6077 if (nRequired >= UI_MAX_EDITBOXLENGTH)
6078 return false;
6079
6080 while (GetBufferSize() < nRequired)
6081 if (!SetBufferSize(-1))
6082 break;
6083 // Check again in case out of memory occurred inside while loop.
6084 if (GetBufferSize() >= nRequired)
6085 {
6086 wcscpy_s(m_pwszBuffer, GetBufferSize(), wszText);
6087 m_bAnalyseRequired = true;
6088 return true;
6089 }
6090 else
6091 return false;
6092}
6093
6094
6095//--------------------------------------------------------------------------------------
6096HRESULT CUniBuffer::CPtoX(int nCP, BOOL bTrail, int* pX)
6097{
6098 assert(pX);
6099 *pX = 0; // Default
6100
6101 HRESULT hr = S_OK;
6103 hr = Analyse();
6104
6105 if (SUCCEEDED(hr))
6106 hr = _ScriptStringCPtoX(m_Analysis, nCP, bTrail, pX);
6107
6108 return hr;
6109}
6110
6111
6112//--------------------------------------------------------------------------------------
6113HRESULT CUniBuffer::XtoCP(int nX, int* pCP, int* pnTrail)
6114{
6115 assert(pCP && pnTrail);
6116 *pCP = 0; *pnTrail = FALSE; // Default
6117
6118 HRESULT hr = S_OK;
6120 hr = Analyse();
6121
6122 if (SUCCEEDED(hr))
6123 hr = _ScriptStringXtoCP(m_Analysis, nX, pCP, pnTrail);
6124
6125 // If the coordinate falls outside the text region, we
6126 // can get character positions that don't exist. We must
6127 // filter them here and convert them to those that do exist.
6128 if (*pCP == -1 && *pnTrail == TRUE)
6129 {
6130 *pCP = 0; *pnTrail = FALSE;
6131 }
6132 else if (*pCP > lstrlenW(m_pwszBuffer) && *pnTrail == FALSE)
6133 {
6134 *pCP = lstrlenW(m_pwszBuffer); *pnTrail = TRUE;
6135 }
6136
6137 return hr;
6138}
6139
6140
6141//--------------------------------------------------------------------------------------
6142void CUniBuffer::GetPriorItemPos(int nCP, int* pPrior)
6143{
6144 *pPrior = nCP; // Default is the char itself
6145
6147 if (FAILED(Analyse()))
6148 return;
6149
6150 const SCRIPT_LOGATTR* pLogAttr = _ScriptString_pLogAttr(m_Analysis);
6151 if (!pLogAttr)
6152 return;
6153
6155 return;
6156 int nInitial = *_ScriptString_pcOutChars(m_Analysis);
6157 if (nCP - 1 < nInitial)
6158 nInitial = nCP - 1;
6159 for (int i = nInitial; i > 0; --i)
6160 if (pLogAttr[i].fWordStop || // Either the fWordStop flag is set
6161 (!pLogAttr[i].fWhiteSpace && // Or the previous char is whitespace but this isn't.
6162 pLogAttr[i - 1].fWhiteSpace))
6163 {
6164 *pPrior = i;
6165 return;
6166 }
6167 // We have reached index 0. 0 is always a break point, so simply return it.
6168 *pPrior = 0;
6169}
6170
6171
6172//--------------------------------------------------------------------------------------
6173void CUniBuffer::GetNextItemPos(int nCP, int* pPrior)
6174{
6175 *pPrior = nCP; // Default is the char itself
6176
6177 HRESULT hr = S_OK;
6179 hr = Analyse();
6180 if (FAILED(hr))
6181 return;
6182
6183 const SCRIPT_LOGATTR* pLogAttr = _ScriptString_pLogAttr(m_Analysis);
6184 if (!pLogAttr)
6185 return;
6186
6188 return;
6189 int nInitial = *_ScriptString_pcOutChars(m_Analysis);
6190 if (nCP + 1 < nInitial)
6191 nInitial = nCP + 1;
6192
6193 int i = nInitial;
6195 while (limit > 0 && i < limit - 1)
6196 {
6197 if (pLogAttr[i].fWordStop) // Either the fWordStop flag is set
6198 {
6199 *pPrior = i;
6200 return;
6201 }
6202 else if (pLogAttr[i].fWhiteSpace && // Or this whitespace but the next char isn't.
6203 !pLogAttr[i + 1].fWhiteSpace)
6204 {
6205 *pPrior = i + 1; // The next char is a word stop
6206 return;
6207 }
6208
6209 ++i;
6211 }
6212 // We have reached the end. It's always a word stop, so simply return it.
6213 *pPrior = *_ScriptString_pcOutChars(m_Analysis) - 1;
6214}
6215
6216
6217//--------------------------------------------------------------------------------------
6223
6224
6225//--------------------------------------------------------------------------------------
6227{
6228 for (int i = 0; i < MAX_CONTROL_STATES; i++)
6229 {
6230 States[i] = defaultColor;
6231 }
6232
6233 States[UI_STATE_DISABLED] = disabledColor;
6234 States[UI_STATE_HIDDEN] = hiddenColor;
6235 Current = hiddenColor;
6236}
6237
6238
6239//--------------------------------------------------------------------------------------
6240void UIBlendColor::Blend(UINT iState, float fElapsedTime, float fRate)
6241{
6242 RiseMath::Color destColor = States[iState];
6243 RiseMath::ColorLerp(&Current, &Current, &destColor, 1.0f - powf(fRate, 30 * fElapsedTime));
6244}
6245
6246
6247
6248//--------------------------------------------------------------------------------------
6249void RiseElement::SetTexture(UINT prmTexture, RECT* prcTexture, Rendering::PackedColor defaultTextureColor)
6250{
6251 this->iTexture = prmTexture;
6252
6253 if (prcTexture)
6254 rcTexture = *prcTexture;
6255 else
6256 SetRectEmpty(&rcTexture);
6257
6258 TextureColor.Init(defaultTextureColor);
6259}
6260
6261
6262//--------------------------------------------------------------------------------------
6263void RiseElement::SetFont(UINT prmFont, Rendering::PackedColor defaultFontColor, DWORD prmTextFormat)
6264{
6265 this->iFont = prmFont;
6266 this->dwTextFormat = prmTextFormat;
6267
6268 FontColor.Init(defaultFontColor);
6269}
6270
6271
6272//--------------------------------------------------------------------------------------
#define SAFE_DELETE_ARRAY(value)
#define V_RETURN(expression)
#define SAFE_RELEASE(value)
#define SAFE_DELETE(value)
int RectHeight(RECT &rc)
Definition Controls.cpp:106
#define UNISCRIBE_DLLNAME
Definition Controls.cpp:48
int RectWidth(RECT &rc)
Definition Controls.cpp:102
#define GETPROCADDRESS(Module, APIName, Temp)
Definition Controls.cpp:50
#define WHEEL_DELTA
Definition Controls.cpp:24
#define SCROLLBAR_ARROWCLICK_REPEAT
Definition Controls.cpp:32
#define IN_FLOAT_CHARSET(c)
#define SCROLLBAR_MINTHUMBSIZE
Definition Controls.cpp:28
#define UI_FAR_BUTTON_DEPTH
Definition Controls.cpp:35
#define UI_MAX_EDITBOXLENGTH
Definition Controls.cpp:70
RiseMath::Color ColorValue(Rendering::PackedColor c)
Definition Controls.cpp:39
#define WM_XBUTTONUP
Definition Controls.cpp:18
SCRIPT_CONTROL SCRIPT_STATE const void int
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
#define WM_XBUTTONDOWN
Definition Controls.cpp:15
#define WM_MOUSEWHEEL
Definition Controls.cpp:21
SCRIPT_CONTROL SCRIPT_STATE const void SCRIPT_CONTROL SCRIPT_STATE const int SCRIPT_TABDEF const BYTE SCRIPT_STRING_ANALYSIS BOOL
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
#define UI_NEAR_BUTTON_DEPTH
Definition Controls.cpp:34
#define SCROLLBAR_ARROWCLICK_DELAY
Definition Controls.cpp:31
#define PLACEHOLDERPROC(APIName)
Definition Controls.cpp:55
#define EVENT_LISTBOX_ITEM_DBLCLK
Definition Controls.h:32
UI_CONTROL_STATE
Definition Controls.h:80
@ UI_STATE_DISABLED
Definition Controls.h:82
@ UI_STATE_NORMAL
Definition Controls.h:81
@ UI_STATE_MOUSEOVER
Definition Controls.h:85
@ UI_STATE_HIDDEN
Definition Controls.h:83
@ UI_STATE_PRESSED
Definition Controls.h:86
@ UI_STATE_FOCUS
Definition Controls.h:84
#define EVENT_CHECKBOX_CHANGED
Definition Controls.h:25
@ UI_CONTROL_LISTBOX
Definition Controls.h:75
@ UI_CONTROL_BUTTON
Definition Controls.h:67
@ UI_CONTROL_COMBOBOX
Definition Controls.h:71
@ UI_CONTROL_CHECKBOX
Definition Controls.h:69
@ UI_CONTROL_IMEEDITBOX
Definition Controls.h:74
@ UI_CONTROL_SLIDER
Definition Controls.h:72
@ UI_CONTROL_STATIC
Definition Controls.h:68
@ UI_CONTROL_EDITBOX
Definition Controls.h:73
@ UI_CONTROL_SCROLLBAR
Definition Controls.h:76
@ UI_CONTROL_RADIOBUTTON
Definition Controls.h:70
#define EVENT_EDITBOX_STRING
Definition Controls.h:27
#define EVENT_LISTBOX_SELECTION
Definition Controls.h:35
#define EVENT_BUTTON_CLICKED
Definition Controls.h:22
VOID(CALLBACK *) UICallback(UINT nEvent, int nControlID, RiseControl *pControl, void *pUserContext)
Definition Controls.h:58
#define EVENT_SLIDER_VALUE_CHANGED
Definition Controls.h:26
#define EVENT_EDITBOX_CHANGE
Definition Controls.h:30
#define MAX_TEXT
Definition Controls.h:17
#define EVENT_LISTBOX_SELECTION_END
Definition Controls.h:36
#define EVENT_EDITBOX_CANCEL
Definition Controls.h:31
#define MAX_CONTROL_STATES
Definition Controls.h:89
#define passwordcharC
Definition Controls.h:38
#define EVENT_RADIOBUTTON_CHANGED
Definition Controls.h:24
#define EVENT_COMBOBOX_SELECTION_CHANGED
Definition Controls.h:23
static void WINAPI Initialize()
WCHAR * m_pwszBuffer
Definition Controls.h:1189
bool SetText(LPCWSTR wszText)
bool InsertChar(int nIndex, WCHAR wChar)
static HRESULT(WINAPI *_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
bool RemoveChar(int nIndex)
int GetTextSize()
Definition Controls.h:1152
SCRIPT_STRING_ANALYSIS m_Analysis
Definition Controls.h:1195
const WCHAR * GetBuffer()
Definition Controls.h:1156
static SCRIPT_CONTROL SCRIPT_STATE *static const void int
Definition Controls.h:1234
UIFontNode * m_pFontNode
Definition Controls.h:1193
static SCRIPT_CONTROL SCRIPT_STATE *static const void SCRIPT_CONTROL SCRIPT_STATE const int SCRIPT_TABDEF const BYTE SCRIPT_STRING_ANALYSIS *static BOOL
Definition Controls.h:1238
const WCHAR & operator[](int n) const
Definition Controls.h:1160
int m_nBufferSize
Definition Controls.h:1190
void SetFontNode(UIFontNode *pFontNode)
Definition Controls.h:1169
void Clear()
static void WINAPI Uninitialize()
static HINSTANCE s_hDll
Definition Controls.h:1244
bool InsertString(int nIndex, const WCHAR *pStr, int nCount=-1)
void GetNextItemPos(int nCP, int *pPrior)
HRESULT CPtoX(int nCP, BOOL bTrail, int *pX)
bool SetBufferSize(int nSize)
int GetBufferSize()
Definition Controls.h:1147
HRESULT Analyse()
bool m_bAnalyseRequired
Definition Controls.h:1194
HRESULT XtoCP(int nX, int *pCP, int *pnTrail)
static const int *WINAPI * _ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS)
static const SCRIPT_LOGATTR *WINAPI * _ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS)
void GetPriorItemPos(int nCP, int *pPrior)
CUniBuffer(int nInitialSize=1)
void RemoveAll()
T & GetAt(int index)
HRESULT SetAt(int index, const T &value)
int GetSize() const
HRESULT Add(const T &value)
HRESULT Remove(int index)
HRESULT Insert(int index, const T &value)
int IndexOf(const T &value) const
HRESULT CreateStateBlock(UINT type, RenderStateSnapshot **result)
HRESULT SetPixelShader(std::nullptr_t)
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT SetFVF(DWORD value)
HRESULT DrawPrimitiveUP(Primitive type, UINT count, const void *vertices, UINT stride)
HRESULT SetTextureStageState(DWORD stage, DWORD state, DWORD value)
HRESULT SetTexture(DWORD stage, RenderTexture *texture)
HRESULT SetSamplerState(DWORD sampler, DWORD state, DWORD value)
HRESULT SetVertexShader(std::nullptr_t)
HRESULT Restore(const Saved &value)
HRESULT Begin(DWORD flags)
HRESULT SetTransform(const RiseMath::Matrix *value)
HRESULT Draw(RenderTexture *image, const RECT *rectangle, const RiseMath::Vector3 *center, const RiseMath::Vector3 *position, PackedColor color)
virtual void Render(float fElapsedTime)
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
bool m_bPressed
Definition Controls.h:741
RiseButton(RiseDialog *pDialog=NULL)
virtual BOOL ContainsPoint(POINT pt)
Definition Controls.h:729
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
virtual void SetCheckedInternal(bool bChecked, bool bFromInput)
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
RECT m_rcText
Definition Controls.h:780
RECT m_rcButton
Definition Controls.h:779
virtual void Render(float fElapsedTime)
virtual void UpdateRects()
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
virtual BOOL ContainsPoint(POINT pt)
RiseCheckBox(RiseDialog *pDialog=NULL)
bool m_bChecked
Definition Controls.h:778
void SetChecked(bool bChecked)
Definition Controls.h:770
int m_nDropHeight
Definition Controls.h:1065
ControlArray< UIComboBoxItem * > m_Items
Definition Controls.h:1078
virtual void SetTextColor(Rendering::PackedColor Color, Rendering::PackedColor DisabledColor=Rendering::ColorARGB(200, 128, 128, 128))
virtual ~RiseComboBox()
RECT m_rcDropdownText
Definition Controls.h:1075
void * GetItemData(const WCHAR *strText)
int FindItem(const WCHAR *strText, UINT iStart=0)
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
int m_nFontHeight
Definition Controls.h:1066
void * GetSelectedData()
UINT GetNumItems()
Definition Controls.h:1049
HRESULT SetSelectedByIndex(UINT index)
RECT m_rcDropdown
Definition Controls.h:1074
virtual void UpdateRects()
virtual void Render(float fElapsedTime)
void RemoveAllItems()
virtual void OnHotkey()
bool ContainsItem(const WCHAR *strText, UINT iStart=0)
UIComboBoxItem * GetSelectedItem()
void RemoveItem(UINT index)
RiseScrollBar m_ScrollBar
Definition Controls.h:1067
RECT m_rcButton
Definition Controls.h:1073
virtual void OnFocusOut()
HRESULT AddItem(const WCHAR *strText, void *pData)
HRESULT SetSelectedByData(void *pData)
HRESULT SetSelectedByText(const WCHAR *strText)
RiseComboBox(RiseDialog *pDialog=NULL)
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition Controls.h:537
bool m_bVisible
Definition Controls.h:642
UINT m_Index
Definition Controls.h:655
RiseElement * GetElement(UINT iElement)
Definition Controls.h:636
virtual void OnFocusOut()
Definition Controls.h:554
virtual void OnMouseLeave()
Definition Controls.h:562
void SetLocation(int x, int y)
Definition Controls.h:606
virtual bool GetEnabled()
Definition Controls.h:579
RECT m_rcBoundingBox
Definition Controls.h:669
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
Definition Controls.h:541
bool m_bShadow
Definition Controls.h:643
virtual HRESULT OnInit()
Definition Controls.h:522
void SetHotkey(UINT nHotkey)
Definition Controls.h:617
virtual void Refresh()
bool m_bIsDefault
Definition Controls.h:646
virtual void OnMouseEnter()
Definition Controls.h:558
UI_CONTROL_TYPE m_Type
Definition Controls.h:663
bool m_bHasFocus
Definition Controls.h:645
void SetID(int ID)
Definition Controls.h:601
bool m_bEnabled
Definition Controls.h:667
UINT GetType() const
Definition Controls.h:592
virtual void Render(float fElapsedTime)
Definition Controls.h:527
UINT GetHotkey()
Definition Controls.h:621
virtual bool MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition Controls.h:532
virtual bool GetVisible()
Definition Controls.h:587
virtual bool CanHaveFocus()
Definition Controls.h:546
UINT m_nHotkey
Definition Controls.h:664
HRESULT SetElement(UINT iElement, RiseElement *pElement)
virtual void OnHotkey()
Definition Controls.h:566
bool m_bMouseOver
Definition Controls.h:644
virtual void UpdateRects()
virtual ~RiseControl()
int GetID() const
Definition Controls.h:597
void SetSize(int width, int height)
Definition Controls.h:610
RiseControl(RiseDialog *pDialog=NULL)
virtual BOOL ContainsPoint(POINT pt)
Definition Controls.h:570
virtual void OnFocusIn()
Definition Controls.h:550
void * m_pUserData
Definition Controls.h:665
RiseDialog * m_pDialog
Definition Controls.h:654
virtual void SetEnabled(bool bEnabled)
Definition Controls.h:575
ControlArray< RiseElement * > m_Elements
Definition Controls.h:657
bool m_bIsPassword
Definition Controls.h:647
virtual void SetTextColor(Rendering::PackedColor Color)
RiseElement * GetDefaultElement(UINT nControlType, UINT iElement)
static RiseControl * s_pControlFocus
Definition Controls.h:379
void RemoveControl(int ID)
Definition Controls.cpp:226
double m_fTimeLastRefresh
Definition Controls.h:365
void SetNextDialog(RiseDialog *pNextDialog)
HRESULT DrawPolyLine(POINT *apPoints, UINT nNumPoints, Rendering::PackedColor color)
void SendEvent(UINT nEvent, bool bTriggeredByUser, RiseControl *pControl)
Definition Controls.cpp:655
bool m_bDrag
Definition Controls.h:387
Rendering::PackedColor m_colorTopLeft
Definition Controls.h:396
void Init(RiseDialogResourceManager *pManager, bool bRegisterDialog=true)
Definition Controls.cpp:176
RiseControl * GetControlAtPoint(POINT pt)
HRESULT InitControl(RiseControl *pControl)
RiseDialog * m_pNextDialog
Definition Controls.h:413
bool m_bMouseInput
Definition Controls.h:356
HRESULT SetTexture(UINT index, LPCWSTR strFilename)
Definition Controls.cpp:834
Rendering::PackedColor m_colorBottomRight
Definition Controls.h:399
HRESULT SetDefaultElement(UINT nControlType, UINT iElement, RiseElement *pElement)
HRESULT CalcTextRect(LPCWSTR strText, RiseElement *pElement, RECT *prcDest, int nCount=-1)
Rendering::PackedColor m_colorTopRight
Definition Controls.h:397
bool m_bKeyboardInput
Definition Controls.h:355
HRESULT AddComboBox(int ID, int x, int y, int width, int height, UINT nHotKey=0, bool bIsDefault=false, RiseComboBox **ppCreated=NULL)
UICallback m_pCallbackEvent
Definition Controls.h:402
friend class RiseDialogResourceManager
Definition Controls.h:133
void RemoveAllControls()
Definition Controls.cpp:254
RiseControl * m_pControlMouseOver
Definition Controls.h:382
static double s_fTimeRefresh
Definition Controls.h:364
void OnMouseUp(POINT pt)
bool m_bCaption
Definition Controls.h:385
RiseComboBox * GetComboBox(int ID)
Definition Controls.h:188
void ClearComboBox(int ID)
HRESULT AddListBox(int ID, int x, int y, int width, int height, DWORD dwStyle=0, RiseListBox **ppCreated=NULL)
UITextureNode * GetTexture(UINT index)
Definition Controls.cpp:878
bool m_bVisible
Definition Controls.h:384
HRESULT AddCheckBox(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bChecked=false, UINT nHotkey=0, bool bIsDefault=false, RiseCheckBox **ppCreated=NULL)
static RiseControl *WINAPI GetPrevControl(RiseControl *pControl)
ControlArray< RiseControl * > m_Controls
Definition Controls.h:408
void ClearRadioButtonGroup(UINT nGroup)
bool MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition Controls.cpp:888
void OnMouseMove(POINT pt)
int m_height
Definition Controls.h:393
void AppendVisibleBounds(std::vector< RECT > &rectangles) const
Definition Controls.cpp:510
void FocusDefaultControl()
UIFontNode * GetFont(UINT index)
Definition Controls.cpp:732
RiseDialogResourceManager * m_pManager
Definition Controls.h:401
RiseControl * GetControl(int ID)
static RiseControl *WINAPI GetNextControl(RiseControl *pControl)
HRESULT DrawText(LPCWSTR strText, RiseElement *pElement, RECT *prcDest, bool bShadow=false, int nCount=-1)
void Refresh()
Definition Controls.cpp:482
Rendering::PackedColor m_colorBottomLeft
Definition Controls.h:398
HRESULT AddStatic(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, RiseStatic **ppCreated=NULL, bool bShadow=true)
RiseDialog * m_pPrevDialog
Definition Controls.h:414
static void WINAPI ClearFocus()
bool m_bMinimized
Definition Controls.h:386
ControlArray< UIElementHolder * > m_DefaultElements
Definition Controls.h:409
RiseElement m_CapElement
Definition Controls.h:411
void SetBackgroundColors(Rendering::PackedColor colorAllCorners)
Definition Controls.h:255
ControlArray< int > m_Fonts
Definition Controls.h:406
int m_nCaptionHeight
Definition Controls.h:394
int m_nDefaultControlID
Definition Controls.h:360
bool OnCycleFocus(bool bForward)
bool GetControlEnabled(int ID)
HRESULT OnRender(float fElapsedTime)
Definition Controls.cpp:526
HRESULT AddEditBox(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, bool bIsPassword=false, RiseEditBox **ppCreated=NULL)
ControlArray< int > m_Textures
Definition Controls.h:405
void RequestFocus(RiseControl *pControl)
static RiseControl * s_pControlPressed
Definition Controls.h:380
HRESULT AddRadioButton(int ID, UINT nButtonGroup, LPCWSTR strText, int x, int y, int width, int height, bool bChecked=false, UINT nHotkey=0, bool bIsDefault=false, RiseRadioButton **ppCreated=NULL)
void InitDefaultElements()
int m_width
Definition Controls.h:392
void * m_pCallbackEventUserContext
Definition Controls.h:403
HRESULT DrawRect(RECT *pRect, Rendering::PackedColor color)
HRESULT AddControl(RiseControl *pControl)
WCHAR m_wszCaption[256]
Definition Controls.h:388
HRESULT SetFont(UINT index, LPCWSTR strFaceName, LONG height, LONG weight)
Definition Controls.cpp:709
void SetCallback(UICallback pCallback, void *pUserContext=NULL)
Definition Controls.cpp:212
HRESULT AddButton(int ID, LPCWSTR strText, int x, int y, int width, int height, UINT nHotkey=0, bool bIsDefault=false, RiseButton **ppCreated=NULL)
bool m_bNonUserEvents
Definition Controls.h:354
RiseDialogResourceManager * GetManager()
Definition Controls.h:346
bool IsKeyboardInputEnabled() const
Definition Controls.h:328
HRESULT DrawSprite(RiseElement *pElement, RECT *prcDest, float fDepth=0)
void SetControlEnabled(int ID, bool bEnabled)
HRESULT AddSlider(int ID, int x, int y, int width, int height, int min=0, int max=100, int value=50, bool bIsDefault=false, RiseSlider **ppCreated=NULL)
HRESULT CreateTexture(UINT index)
Rendering::RenderDevice * GetRenderer()
Definition Controls.h:457
void EnableKeyboardInputForAllDialogs()
Definition Controls.cpp:473
Rendering::RenderSprite * m_pSprite
Definition Controls.h:490
UITextureNode * GetTextureNode(int iIndex)
Definition Controls.h:473
void UnregisterDialog(RiseDialog *pDialog)
Definition Controls.cpp:444
UIFontNode * GetFontNode(int iIndex)
Definition Controls.h:469
HRESULT OnCreateDevice(Rendering::RenderDevice *pd3dDevice)
Definition Controls.cpp:306
bool RegisterDialog(RiseDialog *pDialog)
Definition Controls.cpp:423
ControlArray< UIFontNode * > m_FontCache
Definition Controls.h:509
int AddTexture(LPCWSTR strFilename)
Definition Controls.cpp:741
Rendering::RenderStateSnapshot * m_pStateBlock
Definition Controls.h:489
int AddFont(LPCWSTR strFaceName, LONG height, LONG weight)
Definition Controls.cpp:671
ControlArray< UITextureNode * > m_TextureCache
Definition Controls.h:508
HRESULT CreateFont(UINT index)
Rendering::RenderDevice * m_renderer
Definition Controls.h:500
bool MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition Controls.cpp:357
ControlArray< RiseDialog * > m_Dialogs
Definition Controls.h:496
Rendering::PackedColor m_SelBkColor
Definition Controls.h:1328
void DeleteSelectionText()
double m_dfLastBlink
Definition Controls.h:1320
void ClearText()
void PlaceCaret(int nCP)
bool m_bInsertMode
Definition Controls.h:1323
void CopyToClipboard()
double m_dfBlink
Definition Controls.h:1319
int m_nSelStart
Definition Controls.h:1324
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
int m_nFirstVisible
Definition Controls.h:1325
void PasteFromClipboard()
RECT m_rcRender[9]
Definition Controls.h:1318
bool m_bCaretOn
Definition Controls.h:1321
void ResetCaretBlink()
virtual void Render(float fElapsedTime)
virtual bool MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
virtual void OnFocusIn()
Rendering::PackedColor m_CaretColor
Definition Controls.h:1329
void SetText(LPCWSTR wszText, bool bSelected=false)
CUniBuffer m_Buffer
Definition Controls.h:1314
RiseEditBox(RiseDialog *pDialog=NULL)
Rendering::PackedColor m_TextColor
Definition Controls.h:1326
static bool s_bHideCaret
Definition Controls.h:1335
void SetTextFloatArray(const float *pNumbers, int nCount)
virtual ~RiseEditBox()
HRESULT GetTextCopy(__out_ecount(bufferCount) LPWSTR strDest, UINT bufferCount)
bool m_bMouseDrag
Definition Controls.h:1332
virtual void UpdateRects()
RECT m_rcText
Definition Controls.h:1317
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
Rendering::PackedColor m_SelTextColor
Definition Controls.h:1327
void ParseFloatArray(float *pNumbers, int nCount)
void SetFont(UINT prmFont, Rendering::PackedColor defaultFontColor=Rendering::ColorARGB(255, 255, 255, 255), DWORD prmTextFormat=DT_CENTER|DT_VCENTER)
UIBlendColor TextureColor
Definition Controls.h:122
RECT rcTexture
Definition Controls.h:120
UINT iTexture
Definition Controls.h:116
UIBlendColor FontColor
Definition Controls.h:123
DWORD dwTextFormat
Definition Controls.h:118
void Refresh()
void SetTexture(UINT prmTexture, RECT *prcTexture, Rendering::PackedColor defaultTextureColor=Rendering::ColorARGB(255, 255, 255, 255))
RECT m_rcText
Definition Controls.h:968
UIListBoxItem * GetItem(int nIndex)
int m_nSBWidth
Definition Controls.h:971
RECT m_rcSelection
Definition Controls.h:969
int m_nTextHeight
Definition Controls.h:974
RiseListBox(RiseDialog *pDialog=NULL)
int m_nSelected
Definition Controls.h:976
DWORD m_dwStyle
Definition Controls.h:975
void RemoveAllItems()
virtual void Render(float fElapsedTime)
virtual void UpdateRects()
int m_nSelStart
Definition Controls.h:977
void RemoveItem(int nIndex)
HRESULT AddItem(const WCHAR *wszText, void *pData)
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
virtual bool MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
bool m_bDrag
Definition Controls.h:978
void SetStyle(DWORD dwStyle)
Definition Controls.h:932
int m_nBorder
Definition Controls.h:972
void SelectItem(int nNewIndex)
ControlArray< UIListBoxItem * > m_Items
Definition Controls.h:980
virtual ~RiseListBox()
void RemoveItemByData(void *pData)
int m_nMargin
Definition Controls.h:973
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
RiseScrollBar m_ScrollBar
Definition Controls.h:970
int GetSelectedIndex(int nPreviousSelected=-1)
HRESULT InsertItem(int nIndex, const WCHAR *wszText, void *pData)
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
UINT m_nButtonGroup
Definition Controls.h:815
void SetChecked(bool bChecked, bool bClearGroup=true)
Definition Controls.h:800
virtual void SetCheckedInternal(bool bChecked, bool bClearGroup, bool bFromInput)
RiseRadioButton(RiseDialog *pDialog=NULL)
UINT GetButtonGroup()
Definition Controls.h:808
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
void SetButtonGroup(UINT nButtonGroup)
Definition Controls.h:804
virtual void Render(float fElapsedTime)
int GetTrackPos()
Definition Controls.h:836
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
virtual ~RiseScrollBar()
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
void Scroll(int nDelta)
void SetPageSize(int nPageSize)
Definition Controls.h:848
RiseScrollBar(RiseDialog *pDialog=NULL)
RECT m_rcUpButton
Definition Controls.h:877
virtual void UpdateRects()
POINT m_LastMouse
Definition Controls.h:885
void ShowItem(int nIndex)
RECT m_rcDownButton
Definition Controls.h:878
void UpdateThumbRect()
ARROWSTATE m_Arrow
Definition Controls.h:886
void SetTrackRange(int nStart, int nEnd)
virtual bool MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
int GetPageSize()
Definition Controls.h:844
double m_dArrowTS
Definition Controls.h:887
bool m_bShowThumb
Definition Controls.h:875
int m_nDragOffset
Definition Controls.h:1127
int ValueFromPos(int x)
virtual void Render(float fElapsedTime)
virtual bool HandleKeyboard(UINT uMsg, WPARAM wParam, LPARAM lParam)
virtual bool HandleMouse(UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam)
RECT m_rcButton
Definition Controls.h:1131
void SetValue(int nValue)
Definition Controls.h:1102
virtual void UpdateRects()
virtual BOOL ContainsPoint(POINT pt)
bool m_bPressed
Definition Controls.h:1130
int m_nButtonX
Definition Controls.h:1128
RiseSlider(RiseDialog *pDialog=NULL)
void SetValueInternal(int nValue, bool bFromInput)
void SetRange(int nMin, int nMax)
RiseStatic(RiseDialog *pDialog=NULL)
WCHAR m_strText[MAX_TEXT]
Definition Controls.h:709
HRESULT SetText(LPCWSTR strText)
virtual void Render(float fElapsedTime)
HRESULT GetTextCopy(__out_ecount(bufferCount) LPWSTR strDest, UINT bufferCount)
constexpr uint32_t INVSRCALPHA
constexpr uint32_t SRCALPHA
constexpr uint32_t ADD
constexpr uint32_t RED
constexpr uint32_t GREEN
constexpr uint32_t BLUE
constexpr uint32_t ALPHA
constexpr uint32_t CCW
constexpr uint32_t SOLID
constexpr uint32_t LINEAR
constexpr uint32_t COLORWRITEENABLE
constexpr uint32_t SRCBLEND
constexpr uint32_t SHADEMODE
constexpr uint32_t SEPARATEALPHABLENDENABLE
constexpr uint32_t CULLMODE
constexpr uint32_t ALPHABLENDENABLE
constexpr uint32_t ALPHATESTENABLE
constexpr uint32_t FOGENABLE
constexpr uint32_t FILLMODE
constexpr uint32_t DESTBLEND
constexpr uint32_t ZWRITEENABLE
constexpr uint32_t ZENABLE
constexpr uint32_t BLENDOP
constexpr uint32_t MINFILTER
constexpr uint32_t DIFFUSE
constexpr uint32_t TEXTURE
constexpr uint32_t CURRENT
constexpr uint32_t DISABLE
constexpr uint32_t SELECTARG1
constexpr uint32_t MODULATE
constexpr uint32_t SELECTARG2
constexpr uint32_t COLOROP
constexpr uint32_t COLORARG1
constexpr uint32_t ALPHAARG2
constexpr uint32_t RESULTARG
constexpr uint32_t ALPHAARG1
constexpr uint32_t ALPHAOP
constexpr uint32_t COLORARG2
constexpr uint32_t TEX1
constexpr uint32_t XYZRHW
constexpr uint32_t DIFFUSE
HWND ClientWindow()
HRESULT CreateFontW(RenderDevice *owner, INT height, UINT width, UINT weight, UINT mipLevels, BOOL italic, DWORD charset, DWORD precision, DWORD quality, DWORD pitch, const wchar_t *face, RenderFont **result)
HRESULT TraceFailure(const wchar_t *operation, HRESULT code)
HRESULT LoadTextureResource(RenderDevice *owner, HMODULE module, LPCWSTR id, RenderTexture **result, UINT levels)
double ClientTime()
HRESULT CreateSprite(RenderDevice *owner, RenderSprite **result)
double ClientAbsoluteTime()
HRESULT LoadTexture(RenderDevice *owner, const wchar_t *path, RenderTexture **result, UINT levels=0, UINT width=0, UINT height=0)
constexpr PackedColor ColorARGB(unsigned a, unsigned r, unsigned g, unsigned b)
uint32_t PackedColor
Color * ColorLerp(Color *out, const Color *a, const Color *b, float t)
Definition ClientMath.h:173
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
Matrix * MatrixScaling(Matrix *out, float x, float y, float z)
Definition ClientMath.h:124
Rendering::PackedColor color
Definition Controls.cpp:92
Rendering::PackedColor color
Definition Controls.cpp:81
static DWORD FVF
Definition Controls.cpp:84
void Blend(UINT iState, float fElapsedTime, float fRate=0.7f)
void Init(Rendering::PackedColor defaultColor, Rendering::PackedColor disabledColor=Rendering::ColorARGB(200, 128, 128, 128), Rendering::PackedColor hiddenColor=0)
RiseMath::Color Current
Definition Controls.h:98
Rendering::PackedColor States[MAX_CONTROL_STATES]
Definition Controls.h:97
WCHAR strText[256]
Definition Controls.h:989
RiseElement Element
Definition Controls.h:681
LONG nWeight
Definition Controls.h:436
Rendering::RenderFont * font
Definition Controls.h:437
WCHAR strFace[MAX_PATH]
Definition Controls.h:434
LONG nHeight
Definition Controls.h:435
void * pData
Definition Controls.h:897
WCHAR strText[256]
Definition Controls.h:896
WCHAR strFilename[MAX_PATH]
Definition Controls.h:426
Rendering::RenderTexture * texture
Definition Controls.h:429
bool bFileSource
Definition Controls.h:423
HMODULE hResourceModule
Definition Controls.h:424