Skip to content

Commit 9d288ff

Browse files
committed
Image: new class for to store texture path and handle to it. Apparently fixes not found texture spam in console :)
1 parent 2ca8d16 commit 9d288ff

18 files changed

+156
-52
lines changed

BaseMenu.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ void UI_DisableAlphaFactor()
180180
UI_DrawPic
181181
=================
182182
*/
183-
void UI_DrawPic( int x, int y, int width, int height, const unsigned int color, const char *pic, const ERenderMode eRenderMode )
183+
void UI_DrawPic( int x, int y, int width, int height, const unsigned int color, CImage &pic, const ERenderMode eRenderMode )
184184
{
185-
HIMAGE hPic = EngFuncs::PIC_Load( pic );
185+
HIMAGE hPic = pic.Handle();
186186

187187
if( !hPic )
188188
return;

BaseMenu.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GNU General Public License for more details.
2626
#include "FontManager.h"
2727
#include "BtnsBMPTable.h"
2828
#include "WindowSystem.h"
29+
#include "Image.h"
2930

3031
#define UI_MAX_MENUDEPTH 64
3132
#define UI_MAX_MENUITEMS 64
@@ -192,11 +193,21 @@ inline int UI_DrawString( HFont font, Point pos, Size size, const char *str, con
192193
return UI_DrawString( font, pos.x, pos.y, size.w, size.h, str, col, charH, justify, flags );
193194
}
194195

195-
void UI_DrawPic(int x, int y, int w, int h, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL );
196-
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
196+
void UI_DrawPic( int x, int y, int w, int h, const unsigned int color, CImage &pic, const ERenderMode eRenderMode = QM_DRAWNORMAL );
197+
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, CImage &pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
197198
{
198199
UI_DrawPic( pos.x, pos.y, size.w, size.h, color, pic, eRenderMode );
199200
}
201+
inline void UI_DrawPic( int x, int y, int w, int h, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
202+
{
203+
CImage img = pic;
204+
UI_DrawPic( x, y, w, h, color, img, eRenderMode );
205+
}
206+
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
207+
{
208+
CImage img = pic;
209+
UI_DrawPic( pos, size, color, img, eRenderMode );
210+
}
200211
void UI_FillRect( int x, int y, int w, int h, const unsigned int color );
201212
inline void UI_FillRect( Point pos, Size size, const unsigned int color )
202213
{

EngineCallback.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GNU General Public License for more details.
1717
#include "BaseMenu.h"
1818
#include "Utils.h"
1919

20-
void EngFuncs::PIC_Set(HIMAGE hPic, int r, int g, int b, int a)
20+
void EngFuncs::PIC_Set( HIMAGE hPic, int r, int g, int b, int a)
2121
{
2222
if( uiStatic.enableAlphaFactor )
2323
a *= uiStatic.alphaFactor;

Image.h

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Image.h -- image class
3+
Copyright (C) 2019 a1batross
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
*/
15+
#ifndef IMAGE_H
16+
#define IMAGE_H
17+
18+
#include "enginecallback_menu.h"
19+
20+
class CImage
21+
{
22+
public:
23+
CImage() : m_szPath( NULL ), m_hPic( 0 ) { }
24+
CImage( HIMAGE hPic ) : m_szPath( NULL ), m_hPic( hPic ) { }
25+
CImage( const char *szPath, int flags = 0 )
26+
{
27+
Load( szPath, flags );
28+
}
29+
CImage( const char *szPath, const byte *rgbdata, int size, int flags = 0 )
30+
{
31+
Load( szPath, rgbdata, size, flags );
32+
}
33+
34+
void Set( HIMAGE handle )
35+
{
36+
m_hPic = handle;
37+
m_szPath = NULL;
38+
}
39+
40+
void Load( const char *szPath, int flags = 0 )
41+
{
42+
Set( EngFuncs::PIC_Load( szPath, flags ) );
43+
m_szPath = szPath;
44+
}
45+
46+
void Load( const char *szPath, const byte *rgbdata, int size, int flags = 0 )
47+
{
48+
Set( EngFuncs::PIC_Load( szPath, rgbdata, size, flags ));
49+
m_szPath = szPath;
50+
}
51+
52+
// a1ba: why there is no destructor?
53+
// Engine doesn't track the reference count of texture
54+
// so unloading texture may behave not as you may expect
55+
// Moreover, you can't unload texture by it's handle, only by name
56+
// If you still want to unload image, there is a function for you
57+
void ForceUnload()
58+
{
59+
if( m_szPath )
60+
EngFuncs::PIC_Free( m_szPath );
61+
m_hPic = 0;
62+
}
63+
64+
const char * operator =( const char *path )
65+
{
66+
Load( path );
67+
return path;
68+
}
69+
70+
HIMAGE operator = ( HIMAGE handle )
71+
{
72+
Set( handle );
73+
return handle;
74+
}
75+
76+
operator HIMAGE()
77+
{
78+
return m_hPic;
79+
}
80+
81+
friend inline bool operator == ( CImage &a, CImage &b )
82+
{
83+
return a.m_hPic == b.m_hPic;
84+
}
85+
86+
bool IsValid() { return m_hPic != 0; }
87+
const char *Path() { return m_szPath; }
88+
HIMAGE Handle() { return m_hPic; }
89+
private:
90+
const char *m_szPath;
91+
HIMAGE m_hPic;
92+
};
93+
94+
#endif // IMAGE_H

controls/Action.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GNU General Public License for more details.
2121

2222
CMenuAction::CMenuAction() : BaseClass()
2323
{
24-
m_szBackground = NULL;
24+
m_szBackground = 0;
2525
m_bfillBackground = false;
2626
forceCalcW = forceCalcY = false;
2727
}
@@ -45,9 +45,8 @@ void CMenuAction::VidInit( )
4545
{
4646
if( m_szBackground )
4747
{
48-
HIMAGE handle = EngFuncs::PIC_Load( m_szBackground );
49-
size.w = EngFuncs::PIC_Width( handle );
50-
size.h = EngFuncs::PIC_Height( handle );
48+
size.w = EngFuncs::PIC_Width( m_szBackground );
49+
size.h = EngFuncs::PIC_Height( m_szBackground );
5150
}
5251
else
5352
{
@@ -186,7 +185,7 @@ void CMenuAction::SetBackground(const char *path, unsigned int color)
186185
void CMenuAction::SetBackground(unsigned int color, unsigned int focused )
187186
{
188187
m_bfillBackground = true;
189-
m_szBackground = NULL;
188+
m_szBackground = 0;
190189
m_iBackcolor = color;
191190
m_iBackColorFocused = focused;
192191
}

controls/Action.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CMenuAction : public CMenuBaseItem
3939
private:
4040
CColor m_iBackcolor;
4141
CColor m_iBackColorFocused;
42-
const char *m_szBackground;
42+
CImage m_szBackground;
4343
bool m_bfillBackground;
4444
bool forceCalcW, forceCalcY;
4545
};

controls/Bitmap.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,14 @@ void CMenuBannerBitmap::VidInit()
166166
if( !szPic )
167167
return;
168168

169-
HIMAGE hPic = EngFuncs::PIC_Load( szPic );
170-
171-
if( !hPic )
172-
return;
173-
174-
Size sz = EngFuncs::PIC_Size( hPic );
169+
Size sz = EngFuncs::PIC_Size( szPic );
175170
float factor = (float)m_scSize.h / (float)sz.h;
176171
m_scSize.w = sz.w * factor;
177172

178173
// CMenuPicButton::SetTitleAnim( CMenuPicButton::AS_TO_TITLE );
179174
CMenuPicButton::SetupTitleQuadForLast( uiStatic.xOffset + pos.x, uiStatic.yOffset + pos.y, m_scSize.w, m_scSize.h );
180175
#if defined(TA_ALT_MODE2) && !defined(TA_ALT_MODE)
181-
CMenuPicButton::SetTransPicForLast( EngFuncs::PIC_Load( szPic ) );
176+
CMenuPicButton::SetTransPicForLast( szPic );
182177
#endif
183178
#endif // CS16CLIENT
184179
}

controls/Bitmap.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ class CMenuBitmap : public CMenuBaseItem
4444
ePressRenderMode = pressRenderMode;
4545
}
4646

47-
const char *szPic;
47+
protected:
48+
CImage szPic;
4849
ERenderMode eRenderMode;
4950

50-
const char *szFocusPic;
51+
CImage szFocusPic;
5152
ERenderMode eFocusRenderMode;
5253

53-
const char *szPressPic;
54+
CImage szPressPic;
5455
ERenderMode ePressRenderMode;
5556
};
5657

controls/CheckBox.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class CMenuCheckBox : public CMenuEditable
5454
bool bInvertMask;
5555
bool bChangeOnPressed;
5656

57-
const char *szEmptyPic;
58-
const char *szFocusPic;
59-
const char *szPressPic;
60-
const char *szCheckPic;
61-
const char *szGrayedPic; // when QMF_GRAYED is set
57+
CImage szEmptyPic;
58+
CImage szFocusPic;
59+
CImage szPressPic;
60+
CImage szCheckPic;
61+
CImage szGrayedPic; // when QMF_GRAYED is set
6262

6363
unsigned int iMask; // used only for BitMaskCb
6464
static void BitMaskCb( CMenuBaseItem *pSelf, void *pExtra )

controls/Field.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CMenuField::CMenuField() : BaseClass(), szBuffer()
3535
iCursor = 0;
3636
iScroll = 0;
3737
iRealWidth = 0;
38-
szBackground = NULL;
38+
szBackground = 0;
3939
}
4040

4141
void CMenuField::Init()

controls/Field.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class CMenuField : public CMenuEditable
5858
bool bAllowColorstrings;
5959
bool bHideInput;
6060
bool bNumbersOnly;
61-
const char *szBackground;
62-
int iMaxLength; // can't be more than UI_MAX_FIELD_LINE
61+
CImage szBackground;
62+
int iMaxLength; // can't be more than UI_MAX_FIELD_LINE
6363

6464
protected:
6565
void _Event( int ev ) override;

controls/ItemsHolder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GNU General Public License for more details.
2323
CMenuItemsHolder::CMenuItemsHolder() :
2424
BaseClass(), m_iCursor( 0 ), m_iCursorPrev( 0 ), m_pItems( ),
2525
m_events(), m_bInit( false ),
26-
m_bWrapCursor( true ), m_szResFile( 0 )
26+
m_bWrapCursor( true ), m_szResFile( 0 ), m_pItemAtCursorOnDown( 0 )
2727
{
2828
;
2929
}

controls/Slider.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ CMenuSlider::CMenuSlider() : BaseClass(), m_flMinValue(), m_flMaxValue(), m_flCu
3333

3434
SetCharSize( QM_DEFAULTFONT );
3535

36+
imgSlider = UI_SLIDER_MAIN;
37+
3638
iFlags |= QMF_DROPSHADOW;
3739
}
3840

@@ -193,9 +195,9 @@ void CMenuSlider::Draw( void )
193195

194196
UI_DrawRectangleExt( m_scPos.x + m_iSliderOutlineWidth / 2, m_scPos.y + m_iSliderOutlineWidth, m_scSize.w - m_iSliderOutlineWidth, m_scCenterBox.h, uiInputBgColor, m_iSliderOutlineWidth );
195197
if( eFocusAnimation == QM_HIGHLIGHTIFFOCUS && this == m_pParent->ItemAtCursor())
196-
UI_DrawPic( sliderX, m_scPos.y, m_scCenterBox.w, m_scSize.h, uiColorHelp, UI_SLIDER_MAIN );
198+
UI_DrawPic( sliderX, m_scPos.y, m_scCenterBox.w, m_scSize.h, uiColorHelp, imgSlider );
197199
else
198-
UI_DrawPic( sliderX, m_scPos.y, m_scCenterBox.w, m_scSize.h, uiColorWhite, UI_SLIDER_MAIN );
200+
UI_DrawPic( sliderX, m_scPos.y, m_scCenterBox.w, m_scSize.h, uiColorWhite, imgSlider );
199201

200202

201203
textHeight = m_scPos.y - (m_scChSize * 1.5f);

controls/Slider.h

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class CMenuSlider : public CMenuEditable
5252
// void SetDrawStep( float drawStep, int numSteps );
5353

5454
void SetKeepSlider( int keepSlider ) { m_iKeepSlider = keepSlider; }
55+
56+
CImage imgSlider;
5557
private:
5658
float m_flMinValue;
5759
float m_flMaxValue;

controls/SpinControl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CMenuSpinControl::CMenuSpinControl() : BaseClass(), m_szBackground(),
2525
m_flMinValue(0), m_flMaxValue(1), m_flCurValue(0), m_flRange(0.1), m_pModel( NULL ),
2626
m_iFloatPrecision(0), m_szDisplay()
2727
{
28-
m_szBackground = NULL;
28+
m_szBackground = 0;
2929
m_szLeftArrow = UI_LEFTARROW;
3030
m_szLeftArrowFocus = UI_LEFTARROWFOCUS;
3131
m_szRightArrow = UI_RIGHTARROW;

controls/SpinControl.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class CMenuSpinControl : public CMenuEditable
5151
const char *MoveRight();
5252
void Display();
5353

54-
const char *m_szBackground;
55-
const char *m_szLeftArrow;
56-
const char *m_szRightArrow;
57-
const char *m_szLeftArrowFocus;
58-
const char *m_szRightArrowFocus;
59-
float m_flMinValue;
60-
float m_flMaxValue;
61-
float m_flCurValue;
62-
float m_flRange;
54+
CImage m_szBackground;
55+
CImage m_szLeftArrow;
56+
CImage m_szRightArrow;
57+
CImage m_szLeftArrowFocus;
58+
CImage m_szRightArrowFocus;
59+
float m_flMinValue;
60+
float m_flMaxValue;
61+
float m_flCurValue;
62+
float m_flRange;
6363

6464
CMenuBaseArrayModel *m_pModel;
6565
short m_iFloatPrecision;

controls/Table.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ class CMenuTable : public CMenuBaseItem
149149

150150
float flFixedSumm, flDynamicSumm;
151151

152-
const char *szBackground;
153-
const char *szUpArrow;
154-
const char *szUpArrowFocus;
155-
const char *szUpArrowPressed;
156-
const char *szDownArrow;
157-
const char *szDownArrowFocus;
158-
const char *szDownArrowPressed;
152+
CImage szBackground;
153+
CImage szUpArrow;
154+
CImage szUpArrowFocus;
155+
CImage szUpArrowPressed;
156+
CImage szDownArrow;
157+
CImage szDownArrowFocus;
158+
CImage szDownArrowPressed;
159159

160160
int iTopItem;
161161
int iNumRows;

menus/LoadGame.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ class CMenuLoadGame;
4141
class CMenuSavePreview : public CMenuBaseItem
4242
{
4343
public:
44-
CMenuSavePreview() : CMenuBaseItem()
44+
CMenuSavePreview() : CMenuBaseItem(), fallback( "{GRAF001" )
4545
{
4646
iFlags = QMF_INACTIVE;
4747
}
4848

4949
void Draw() override;
50+
51+
CImage fallback;
5052
};
5153

5254
class CMenuSavesListModel : public CMenuBaseModel
@@ -123,8 +125,6 @@ class CMenuLoadGame : public CMenuFramework
123125

124126
void CMenuSavePreview::Draw()
125127
{
126-
const char *fallback = "{GRAF001";
127-
128128
if( szName && *szName )
129129
{
130130
char saveshot[128];

0 commit comments

Comments
 (0)