Skip to content

Commit c9e8e1a

Browse files
committed
Merge WinUtil and GUIRect from GUI.h into GUIUtil
Replace RTEAssert with CoreCRT assert Misc cleanup
1 parent d5e1587 commit c9e8e1a

File tree

11 files changed

+226
-405
lines changed

11 files changed

+226
-405
lines changed

GUILibrary/Source/GUI.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

GUILibrary/Source/GUI.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
#ifndef _GUI_
22
#define _GUI_
33

4-
#pragma region Rectangle Structure
54
/// <summary>
6-
/// The GUIRect structure defines a rectangle by the coordinates of its upper-left and lower-right corners.
5+
/// Main header file for the GUI library.
6+
/// Original Author: Jason Boettcher
7+
8+
/// www.shplorb.com/~jackal
79
/// </summary>
8-
struct GUIRect { long left; long top; long right; long bottom; };
9-
10-
/// <summary>
11-
/// Sets the bounds of a GUIRect.
12-
/// </summary>
13-
/// <param name="pRect">Pointer to the GUIRect.</param>
14-
/// <param name="left">Position of top left corner on X axis.</param>
15-
/// <param name="top">Position of top left corner on Y axis.</param>
16-
/// <param name="right">Position of bottom right corner on X axis.</param>
17-
/// <param name="bottom">Position of bottom right corner on Y axis.</param>
18-
void SetRect(GUIRect *pRect, int left, int top, int right, int bottom);
19-
#pragma endregion
20-
21-
//#include "RTETools.h"
2210

11+
#include "GUIUtil.h"
2312
#include "GUIInterface.h"
2413
#include "GUIProperties.h"
2514
#include "GUIInput.h"
2615
#include "GUIFont.h"
2716
#include "GUISkin.h"
2817
#include "GUIPanel.h"
2918
#include "GUIManager.h"
30-
#include "GUIUtil.h"
3119
#include "GUIControl.h"
3220
#include "GUIEvent.h"
3321
#include "GUIControlFactory.h"

GUILibrary/Source/GUIBanner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ bool GUIBanner::Create(const std::string fontFilePath, const std::string fontBlu
7171
// Load the font images
7272
fontFile.SetDataPath(filePaths[mode].c_str());
7373
m_pFontImage[mode] = fontFile.GetAsBitmap(bitDepth == 8 ? COLORCONV_REDUCE_TO_256 : COLORCONV_8_TO_32);
74-
RTEAssert(m_pFontImage[mode], "Couldn't load font bitmap for banner font from this file:\n" + fontFilePath);
74+
//RTEAssert(m_pFontImage[mode], "Couldn't load font bitmap for banner font from this file:\n" + fontFilePath);
75+
assert(m_pFontImage[mode]);
7576

7677
// Check the color key to be the same color as the Bottom-Right hand corner pixel
7778
int keyColor = getpixel(m_pFontImage[mode], m_pFontImage[mode]->w - 1, m_pFontImage[mode]->h - 1);

GUILibrary/Source/GUIBanner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "Vector.h"
1515
#include "Timer.h"
16-
#include "allegro.h"
1716

1817
struct BITMAP;
1918

GUILibrary/Source/GUIInterface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// Header file for abstract classes used by the GUI library.
55

6-
//#include "GUI.h"
7-
86
namespace RTE {
97

108
#pragma region GUIBitmap

GUILibrary/Source/GUIManager.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using namespace RTE;
1919

2020

21+
22+
2123
//////////////////////////////////////////////////////////////////////////////////////////
2224
// Constructor: GUIManager
2325
//////////////////////////////////////////////////////////////////////////////////////////
@@ -76,9 +78,9 @@ void GUIManager::Clear(void)
7678
m_HoverPanel = 0;
7779

7880
// Double click times
79-
m_LastMouseDown[0] = -99999.0f;
80-
m_LastMouseDown[1] = -99999.0f;
81-
m_LastMouseDown[2] = -99999.0f;
81+
m_LastMouseDown[0] = -99999.0F;
82+
m_LastMouseDown[1] = -99999.0F;
83+
m_LastMouseDown[2] = -99999.0F;
8284
}
8385

8486

@@ -186,7 +188,7 @@ void GUIManager::Update(void)
186188
if (Released != GUIPanel::MOUSE_NONE && m_DoubleClickButtons != GUIPanel::MOUSE_NONE) {
187189
if (CurPanel)
188190
CurPanel->OnDoubleClick(MouseX, MouseY, m_DoubleClickButtons, Mod);
189-
m_LastMouseDown[0] = m_LastMouseDown[1] = m_LastMouseDown[2] = -99999.0f;
191+
m_LastMouseDown[0] = m_LastMouseDown[1] = m_LastMouseDown[2] = -99999.0F;
190192
}
191193

192194
// Mouse Down
@@ -336,7 +338,8 @@ void GUIManager::Draw(GUIScreen *Screen)
336338

337339
void GUIManager::CaptureMouse(GUIPanel *Panel)
338340
{
339-
RTEAssert(Panel, "No panel!");
341+
//RTEAssert(Panel, "No panel!");
342+
assert(Panel);
340343

341344
// Release any old capture
342345
ReleaseMouse();
@@ -486,11 +489,12 @@ bool GUIManager::MouseInRect(GUIRect *Rect, int X, int Y)
486489

487490
void GUIManager::TrackMouseHover(GUIPanel *Pan, bool Enabled, int Delay)
488491
{
489-
RTEAssert(Pan, "No Panel!");
492+
//RTEAssert(Pan, "No Panel!");
493+
assert(Pan);
490494
m_HoverTrack = Enabled;
491495
m_HoverPanel = Pan;
492496
if (m_HoverTrack)
493-
m_HoverTime = m_pTimer->GetElapsedRealTimeMS() + ((float)Delay/1000.0f);
497+
m_HoverTime = m_pTimer->GetElapsedRealTimeMS() + ((float)Delay/1000.0F);
494498
}
495499

496500

GUILibrary/Source/GUITextPanel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "GUI.h"
1515
#include "GUITextPanel.h"
1616

17-
#include "WinUtil.h"
18-
1917
using namespace RTE;
2018

2119
//////////////////////////////////////////////////////////////////////////////////////////

GUILibrary/Source/GUIUtil.cpp

Lines changed: 113 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,113 @@
1-
//////////////////////////////////////////////////////////////////////////////////////////
2-
// File: GUIUtil.h
3-
//////////////////////////////////////////////////////////////////////////////////////////
4-
// Description: GUIUtil class
5-
// Project: GUI Library
6-
// Author(s): Jason Boettcher
7-
8-
// www.shplorb.com/~jackal
9-
10-
//////////////////////////////////////////////////////////////////////////////////////////
11-
// Inclusions of header files
12-
13-
#include "GUI.h"
14-
15-
using namespace RTE;
16-
17-
//////////////////////////////////////////////////////////////////////////////////////////
18-
// Method: TrimString
19-
//////////////////////////////////////////////////////////////////////////////////////////
20-
// Description: Removes the preceeding and ending spaces from a c type string.
21-
22-
char *GUIUtil::TrimString(char *String)
23-
{
24-
char *ptr = String;
25-
26-
// Find the first non-space character
27-
while(*ptr) {
28-
if (*ptr != ' ')
29-
break;
30-
ptr++;
31-
}
32-
33-
// Add a null terminator after the last character
34-
for(int i=strlen(ptr)-1; i>=0; i--) {
35-
if (ptr[i] != ' ') {
36-
ptr[i+1] = '\0';
37-
break;
38-
}
39-
}
40-
41-
return ptr;
42-
}
43-
44-
char* GUIUtil::SafeOverlappingStrCpy(char* dst, char* src)
45-
{
46-
memmove(dst, src, strlen(src) + 1);
47-
return dst;
48-
}
49-
50-
//////////////////////////////////////////////////////////////////////////////////////////
51-
// Method: GetClipboardText
52-
//////////////////////////////////////////////////////////////////////////////////////////
53-
// Description: Gets the text from the clipboard.
54-
55-
bool GUIUtil::GetClipboardText(std::string *Text)
56-
{
57-
/* Platform dependent, moved to WinUtil
58-
HANDLE CBDataHandle; // handle to the clipboard data
59-
LPSTR CBDataPtr; // pointer to data to send
60-
61-
// Check the pointer
62-
assert(Text);
63-
64-
// Does the clipboard contain text?
65-
if (IsClipboardFormatAvailable(CF_TEXT)) {
66-
67-
// Open the clipboard
68-
if (OpenClipboard(m_hWnd)) {
69-
CBDataHandle = GetClipboardData(CF_TEXT);
70-
71-
if (CBDataHandle) {
72-
CBDataPtr = (LPSTR)GlobalLock(CBDataHandle);
73-
int TextSize = strlen(CBDataPtr);
74-
75-
// Insert the text
76-
Text->erase();
77-
Text->insert(0, CBDataPtr);
78-
CloseClipboard();
79-
80-
GlobalUnlock(CBDataHandle);
81-
82-
return true;
83-
}
84-
85-
CloseClipboard();
86-
}
87-
}
88-
*/
89-
return false;
90-
}
91-
92-
93-
//////////////////////////////////////////////////////////////////////////////////////////
94-
// Method: SetClipboardText
95-
//////////////////////////////////////////////////////////////////////////////////////////
96-
// Description: Sets the text in the clipboard.
97-
98-
bool GUIUtil::SetClipboardText(std::string Text)
99-
{
100-
/* Platform dependent
101-
// Open the clipboard
102-
if (OpenClipboard(m_hWnd)) {
103-
104-
// Allocate global memory for the text
105-
HGLOBAL hMemory = GlobalAlloc(GMEM_MOVEABLE, Text.size()+1);
106-
if (hMemory == 0) {
107-
CloseClipboard();
108-
return false;
109-
}
110-
111-
// Empty the clipboard
112-
EmptyClipboard();
113-
114-
// Copy the text into memory
115-
char *CText = (char *)GlobalLock(hMemory);
116-
memcpy(CText, Text.c_str(), Text.size());
117-
CText[Text.size()] = '\0';
118-
GlobalUnlock(hMemory);
119-
120-
// Set the data
121-
SetClipboardData(CF_TEXT, hMemory);
122-
123-
CloseClipboard();
124-
125-
return true;
126-
}
127-
*/
128-
return false;
129-
}
1+
#include "GUIUtil.h"
2+
#ifdef WIN32
3+
#include <Windows.h>
4+
#endif
5+
6+
namespace RTE {
7+
8+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9+
10+
void SetRect(GUIRect *pRect, int left, int top, int right, int bottom) {
11+
pRect->left = left;
12+
pRect->top = top;
13+
pRect->right = right;
14+
pRect->bottom = bottom;
15+
}
16+
17+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18+
19+
char *GUIUtil::TrimString(char *String) {
20+
char *ptr = String;
21+
22+
// Find the first non-space character
23+
while (*ptr) {
24+
if (*ptr != ' ') { break; }
25+
ptr++;
26+
}
27+
// Add a null terminator after the last character
28+
for (int i = strlen(ptr) - 1; i >= 0; i--) {
29+
if (ptr[i] != ' ') {
30+
ptr[i + 1] = '\0';
31+
break;
32+
}
33+
}
34+
return ptr;
35+
}
36+
37+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38+
39+
char* GUIUtil::SafeOverlappingStrCpy(char* dst, char* src) {
40+
memmove(dst, src, strlen(src) + 1);
41+
return dst;
42+
}
43+
44+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45+
46+
bool GUIUtil::GetClipboardText(std::string *Text) { return 0; }
47+
48+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49+
50+
bool GUIUtil::SetClipboardText(std::string Text) { return 0; }
51+
52+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53+
54+
#ifdef WIN32
55+
bool WinUtil::GetClipboardText(std::string *Text) {
56+
HANDLE CBDataHandle; // handle to the clipboard data
57+
LPSTR CBDataPtr; // pointer to data to send
58+
59+
// Check the pointer
60+
assert(Text);
61+
62+
// Does the clipboard contain text?
63+
if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(0)) {
64+
CBDataHandle = GetClipboardData(CF_TEXT);
65+
66+
if (CBDataHandle) {
67+
CBDataPtr = (LPSTR)GlobalLock(CBDataHandle);
68+
int TextSize = strlen(CBDataPtr);
69+
70+
// Insert the text
71+
Text->erase();
72+
Text->insert(0, CBDataPtr);
73+
CloseClipboard();
74+
75+
GlobalUnlock(CBDataHandle);
76+
77+
return true;
78+
}
79+
CloseClipboard();
80+
81+
}
82+
return false;
83+
}
84+
85+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86+
87+
bool WinUtil::SetClipboardText(std::string Text) {
88+
// Open the clipboard
89+
if (OpenClipboard(0)) {
90+
// Allocate global memory for the text
91+
HGLOBAL hMemory = GlobalAlloc(GMEM_MOVEABLE, Text.size() + 1);
92+
if (hMemory == 0) {
93+
CloseClipboard();
94+
return false;
95+
}
96+
// Empty the clipboard
97+
EmptyClipboard();
98+
99+
// Copy the text into memory
100+
char *CText = (char *)GlobalLock(hMemory);
101+
memcpy(CText, Text.c_str(), Text.size());
102+
CText[Text.size()] = '\0';
103+
GlobalUnlock(hMemory);
104+
105+
// Set the data
106+
SetClipboardData(CF_TEXT, hMemory);
107+
CloseClipboard();
108+
return true;
109+
}
110+
return false;
111+
}
112+
#endif
113+
}

0 commit comments

Comments
 (0)