Skip to content

Commit

Permalink
Image: new class for to store texture path and handle to it. Apparent…
Browse files Browse the repository at this point in the history
…ly fixes not found texture spam in console :)
  • Loading branch information
a1batross committed Nov 25, 2019
1 parent 2ca8d16 commit 9d288ff
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 52 deletions.
4 changes: 2 additions & 2 deletions BaseMenu.cpp
Expand Up @@ -180,9 +180,9 @@ void UI_DisableAlphaFactor()
UI_DrawPic
=================
*/
void UI_DrawPic( int x, int y, int width, int height, const unsigned int color, const char *pic, const ERenderMode eRenderMode )
void UI_DrawPic( int x, int y, int width, int height, const unsigned int color, CImage &pic, const ERenderMode eRenderMode )
{
HIMAGE hPic = EngFuncs::PIC_Load( pic );
HIMAGE hPic = pic.Handle();

if( !hPic )
return;
Expand Down
15 changes: 13 additions & 2 deletions BaseMenu.h
Expand Up @@ -26,6 +26,7 @@ GNU General Public License for more details.
#include "FontManager.h"
#include "BtnsBMPTable.h"
#include "WindowSystem.h"
#include "Image.h"

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

void UI_DrawPic(int x, int y, int w, int h, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL );
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
void UI_DrawPic( int x, int y, int w, int h, const unsigned int color, CImage &pic, const ERenderMode eRenderMode = QM_DRAWNORMAL );
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, CImage &pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
{
UI_DrawPic( pos.x, pos.y, size.w, size.h, color, pic, eRenderMode );
}
inline void UI_DrawPic( int x, int y, int w, int h, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
{
CImage img = pic;
UI_DrawPic( x, y, w, h, color, img, eRenderMode );
}
inline void UI_DrawPic( Point pos, Size size, const unsigned int color, const char *pic, const ERenderMode eRenderMode = QM_DRAWNORMAL )
{
CImage img = pic;
UI_DrawPic( pos, size, color, img, eRenderMode );
}
void UI_FillRect( int x, int y, int w, int h, const unsigned int color );
inline void UI_FillRect( Point pos, Size size, const unsigned int color )
{
Expand Down
2 changes: 1 addition & 1 deletion EngineCallback.cpp
Expand Up @@ -17,7 +17,7 @@ GNU General Public License for more details.
#include "BaseMenu.h"
#include "Utils.h"

void EngFuncs::PIC_Set(HIMAGE hPic, int r, int g, int b, int a)
void EngFuncs::PIC_Set( HIMAGE hPic, int r, int g, int b, int a)
{
if( uiStatic.enableAlphaFactor )
a *= uiStatic.alphaFactor;
Expand Down
94 changes: 94 additions & 0 deletions Image.h
@@ -0,0 +1,94 @@
/*
Image.h -- image class
Copyright (C) 2019 a1batross
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef IMAGE_H
#define IMAGE_H

#include "enginecallback_menu.h"

class CImage
{
public:
CImage() : m_szPath( NULL ), m_hPic( 0 ) { }
CImage( HIMAGE hPic ) : m_szPath( NULL ), m_hPic( hPic ) { }
CImage( const char *szPath, int flags = 0 )
{
Load( szPath, flags );
}
CImage( const char *szPath, const byte *rgbdata, int size, int flags = 0 )
{
Load( szPath, rgbdata, size, flags );
}

void Set( HIMAGE handle )
{
m_hPic = handle;
m_szPath = NULL;
}

void Load( const char *szPath, int flags = 0 )
{
Set( EngFuncs::PIC_Load( szPath, flags ) );
m_szPath = szPath;
}

void Load( const char *szPath, const byte *rgbdata, int size, int flags = 0 )
{
Set( EngFuncs::PIC_Load( szPath, rgbdata, size, flags ));
m_szPath = szPath;
}

// a1ba: why there is no destructor?
// Engine doesn't track the reference count of texture
// so unloading texture may behave not as you may expect
// Moreover, you can't unload texture by it's handle, only by name
// If you still want to unload image, there is a function for you
void ForceUnload()
{
if( m_szPath )
EngFuncs::PIC_Free( m_szPath );
m_hPic = 0;
}

const char * operator =( const char *path )
{
Load( path );
return path;
}

HIMAGE operator = ( HIMAGE handle )
{
Set( handle );
return handle;
}

operator HIMAGE()
{
return m_hPic;
}

friend inline bool operator == ( CImage &a, CImage &b )
{
return a.m_hPic == b.m_hPic;
}

bool IsValid() { return m_hPic != 0; }
const char *Path() { return m_szPath; }
HIMAGE Handle() { return m_hPic; }
private:
const char *m_szPath;
HIMAGE m_hPic;
};

#endif // IMAGE_H
9 changes: 4 additions & 5 deletions controls/Action.cpp
Expand Up @@ -21,7 +21,7 @@ GNU General Public License for more details.

CMenuAction::CMenuAction() : BaseClass()
{
m_szBackground = NULL;
m_szBackground = 0;
m_bfillBackground = false;
forceCalcW = forceCalcY = false;
}
Expand All @@ -45,9 +45,8 @@ void CMenuAction::VidInit( )
{
if( m_szBackground )
{
HIMAGE handle = EngFuncs::PIC_Load( m_szBackground );
size.w = EngFuncs::PIC_Width( handle );
size.h = EngFuncs::PIC_Height( handle );
size.w = EngFuncs::PIC_Width( m_szBackground );
size.h = EngFuncs::PIC_Height( m_szBackground );
}
else
{
Expand Down Expand Up @@ -186,7 +185,7 @@ void CMenuAction::SetBackground(const char *path, unsigned int color)
void CMenuAction::SetBackground(unsigned int color, unsigned int focused )
{
m_bfillBackground = true;
m_szBackground = NULL;
m_szBackground = 0;
m_iBackcolor = color;
m_iBackColorFocused = focused;
}
2 changes: 1 addition & 1 deletion controls/Action.h
Expand Up @@ -39,7 +39,7 @@ class CMenuAction : public CMenuBaseItem
private:
CColor m_iBackcolor;
CColor m_iBackColorFocused;
const char *m_szBackground;
CImage m_szBackground;
bool m_bfillBackground;
bool forceCalcW, forceCalcY;
};
Expand Down
9 changes: 2 additions & 7 deletions controls/Bitmap.cpp
Expand Up @@ -166,19 +166,14 @@ void CMenuBannerBitmap::VidInit()
if( !szPic )
return;

HIMAGE hPic = EngFuncs::PIC_Load( szPic );

if( !hPic )
return;

Size sz = EngFuncs::PIC_Size( hPic );
Size sz = EngFuncs::PIC_Size( szPic );
float factor = (float)m_scSize.h / (float)sz.h;
m_scSize.w = sz.w * factor;

// CMenuPicButton::SetTitleAnim( CMenuPicButton::AS_TO_TITLE );
CMenuPicButton::SetupTitleQuadForLast( uiStatic.xOffset + pos.x, uiStatic.yOffset + pos.y, m_scSize.w, m_scSize.h );
#if defined(TA_ALT_MODE2) && !defined(TA_ALT_MODE)
CMenuPicButton::SetTransPicForLast( EngFuncs::PIC_Load( szPic ) );
CMenuPicButton::SetTransPicForLast( szPic );
#endif
#endif // CS16CLIENT
}
7 changes: 4 additions & 3 deletions controls/Bitmap.h
Expand Up @@ -44,13 +44,14 @@ class CMenuBitmap : public CMenuBaseItem
ePressRenderMode = pressRenderMode;
}

const char *szPic;
protected:
CImage szPic;
ERenderMode eRenderMode;

const char *szFocusPic;
CImage szFocusPic;
ERenderMode eFocusRenderMode;

const char *szPressPic;
CImage szPressPic;
ERenderMode ePressRenderMode;
};

Expand Down
10 changes: 5 additions & 5 deletions controls/CheckBox.h
Expand Up @@ -54,11 +54,11 @@ class CMenuCheckBox : public CMenuEditable
bool bInvertMask;
bool bChangeOnPressed;

const char *szEmptyPic;
const char *szFocusPic;
const char *szPressPic;
const char *szCheckPic;
const char *szGrayedPic; // when QMF_GRAYED is set
CImage szEmptyPic;
CImage szFocusPic;
CImage szPressPic;
CImage szCheckPic;
CImage szGrayedPic; // when QMF_GRAYED is set

unsigned int iMask; // used only for BitMaskCb
static void BitMaskCb( CMenuBaseItem *pSelf, void *pExtra )
Expand Down
2 changes: 1 addition & 1 deletion controls/Field.cpp
Expand Up @@ -35,7 +35,7 @@ CMenuField::CMenuField() : BaseClass(), szBuffer()
iCursor = 0;
iScroll = 0;
iRealWidth = 0;
szBackground = NULL;
szBackground = 0;
}

void CMenuField::Init()
Expand Down
4 changes: 2 additions & 2 deletions controls/Field.h
Expand Up @@ -58,8 +58,8 @@ class CMenuField : public CMenuEditable
bool bAllowColorstrings;
bool bHideInput;
bool bNumbersOnly;
const char *szBackground;
int iMaxLength; // can't be more than UI_MAX_FIELD_LINE
CImage szBackground;
int iMaxLength; // can't be more than UI_MAX_FIELD_LINE

protected:
void _Event( int ev ) override;
Expand Down
2 changes: 1 addition & 1 deletion controls/ItemsHolder.cpp
Expand Up @@ -23,7 +23,7 @@ GNU General Public License for more details.
CMenuItemsHolder::CMenuItemsHolder() :
BaseClass(), m_iCursor( 0 ), m_iCursorPrev( 0 ), m_pItems( ),
m_events(), m_bInit( false ),
m_bWrapCursor( true ), m_szResFile( 0 )
m_bWrapCursor( true ), m_szResFile( 0 ), m_pItemAtCursorOnDown( 0 )
{
;
}
Expand Down
6 changes: 4 additions & 2 deletions controls/Slider.cpp
Expand Up @@ -33,6 +33,8 @@ CMenuSlider::CMenuSlider() : BaseClass(), m_flMinValue(), m_flMaxValue(), m_flCu

SetCharSize( QM_DEFAULTFONT );

imgSlider = UI_SLIDER_MAIN;

iFlags |= QMF_DROPSHADOW;
}

Expand Down Expand Up @@ -193,9 +195,9 @@ void CMenuSlider::Draw( void )

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


textHeight = m_scPos.y - (m_scChSize * 1.5f);
Expand Down
2 changes: 2 additions & 0 deletions controls/Slider.h
Expand Up @@ -52,6 +52,8 @@ class CMenuSlider : public CMenuEditable
// void SetDrawStep( float drawStep, int numSteps );

void SetKeepSlider( int keepSlider ) { m_iKeepSlider = keepSlider; }

CImage imgSlider;
private:
float m_flMinValue;
float m_flMaxValue;
Expand Down
2 changes: 1 addition & 1 deletion controls/SpinControl.cpp
Expand Up @@ -25,7 +25,7 @@ CMenuSpinControl::CMenuSpinControl() : BaseClass(), m_szBackground(),
m_flMinValue(0), m_flMaxValue(1), m_flCurValue(0), m_flRange(0.1), m_pModel( NULL ),
m_iFloatPrecision(0), m_szDisplay()
{
m_szBackground = NULL;
m_szBackground = 0;
m_szLeftArrow = UI_LEFTARROW;
m_szLeftArrowFocus = UI_LEFTARROWFOCUS;
m_szRightArrow = UI_RIGHTARROW;
Expand Down
18 changes: 9 additions & 9 deletions controls/SpinControl.h
Expand Up @@ -51,15 +51,15 @@ class CMenuSpinControl : public CMenuEditable
const char *MoveRight();
void Display();

const char *m_szBackground;
const char *m_szLeftArrow;
const char *m_szRightArrow;
const char *m_szLeftArrowFocus;
const char *m_szRightArrowFocus;
float m_flMinValue;
float m_flMaxValue;
float m_flCurValue;
float m_flRange;
CImage m_szBackground;
CImage m_szLeftArrow;
CImage m_szRightArrow;
CImage m_szLeftArrowFocus;
CImage m_szRightArrowFocus;
float m_flMinValue;
float m_flMaxValue;
float m_flCurValue;
float m_flRange;

CMenuBaseArrayModel *m_pModel;
short m_iFloatPrecision;
Expand Down
14 changes: 7 additions & 7 deletions controls/Table.h
Expand Up @@ -149,13 +149,13 @@ class CMenuTable : public CMenuBaseItem

float flFixedSumm, flDynamicSumm;

const char *szBackground;
const char *szUpArrow;
const char *szUpArrowFocus;
const char *szUpArrowPressed;
const char *szDownArrow;
const char *szDownArrowFocus;
const char *szDownArrowPressed;
CImage szBackground;
CImage szUpArrow;
CImage szUpArrowFocus;
CImage szUpArrowPressed;
CImage szDownArrow;
CImage szDownArrowFocus;
CImage szDownArrowPressed;

int iTopItem;
int iNumRows;
Expand Down
6 changes: 3 additions & 3 deletions menus/LoadGame.cpp
Expand Up @@ -41,12 +41,14 @@ class CMenuLoadGame;
class CMenuSavePreview : public CMenuBaseItem
{
public:
CMenuSavePreview() : CMenuBaseItem()
CMenuSavePreview() : CMenuBaseItem(), fallback( "{GRAF001" )
{
iFlags = QMF_INACTIVE;
}

void Draw() override;

CImage fallback;
};

class CMenuSavesListModel : public CMenuBaseModel
Expand Down Expand Up @@ -123,8 +125,6 @@ class CMenuLoadGame : public CMenuFramework

void CMenuSavePreview::Draw()
{
const char *fallback = "{GRAF001";

if( szName && *szName )
{
char saveshot[128];
Expand Down

0 comments on commit 9d288ff

Please sign in to comment.