1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

New namespaces: GL2D (low-level OpenGL functions), Gfx (images and animation objects cooperating with the interface GL2D)

This commit is contained in:
paracelsus
2013-03-03 19:03:45 +00:00
parent 51d0af5060
commit 1e0f473761
57 changed files with 2245 additions and 907 deletions

View File

@ -26,8 +26,9 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <cstdint>
#include <cstdio>
#include <stdio.h>
#ifdef _WIN32
#include <tchar.h>
#else
@ -68,7 +69,6 @@
#include <boost/assert.hpp>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
#include <boost/cstdint.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
@ -91,20 +91,20 @@
#endif
// Integral data types
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
typedef boost::int8_t si8; //signed int 8 bits (1 byte)
typedef uint64_t ui64; //unsigned int 64 bits (8 bytes)
typedef uint32_t ui32; //unsigned int 32 bits (4 bytes)
typedef uint16_t ui16; //unsigned int 16 bits (2 bytes)
typedef uint8_t ui8; //unsigned int 8 bits (1 byte)
typedef int64_t si64; //signed int 64 bits (8 bytes)
typedef int32_t si32; //signed int 32 bits (4 bytes)
typedef int16_t si16; //signed int 16 bits (2 bytes)
typedef int8_t si8; //signed int 8 bits (1 byte)
// Fixed width bool data type is important for serialization
static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#if defined _M_X64 && defined _WIN32 //Win64 -> cannot load 32-bit DLLs for video handling
#define DISABLE_VIDEO
#define DISABLE_VIDEO 1
#endif
#ifdef __GNUC__
@ -150,6 +150,22 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#define DLL_LINKAGE DLL_IMPORT
#endif
// Unaligned pointers
#if defined(__GNUC__) && (defined(__arm__) || defined(__MIPS__) || defined(__sparc__))
# define UNALIGNED_PTR(T) struct __attribute__((__packed__)) { \
T val; \
inline operator T() { return val; }; \
inline T operator=(T v) { return val = v; }; \
} *
#elif defined(_MSC_VER) && defined(_M_IA64)
# define UNALIGNED_PTR(T) T __unaligned *
#else
# define UNALIGNED_PTR(T) T *
#endif
typedef UNALIGNED_PTR(uint32_t) ua_ui32_ptr;
//defining available c++11 features
//initialization lists - only gcc-4.4 or later

View File

@ -80,16 +80,16 @@ Global
{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.RD|x64.Build.0 = RD|x64
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.Debug|Win32.ActiveCfg = Debug|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.Debug|Win32.Build.0 = Debug|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.Debug|x64.ActiveCfg = Debug|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.Debug|x64.ActiveCfg = Debug|x64
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.RD|Win32.ActiveCfg = RD|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.RD|Win32.Build.0 = RD|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.RD|x64.ActiveCfg = RD|Win32
{276C3DB0-7A6B-4417-8E5C-322B08633AAC}.RD|x64.ActiveCfg = RD|x64
{D15B34EC-A32C-4968-9B0B-66998B579364}.Debug|Win32.ActiveCfg = Debug|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.Debug|Win32.Build.0 = Debug|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.Debug|x64.ActiveCfg = Debug|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.Debug|x64.ActiveCfg = Debug|x64
{D15B34EC-A32C-4968-9B0B-66998B579364}.RD|Win32.ActiveCfg = RD|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.RD|Win32.Build.0 = RD|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.RD|x64.ActiveCfg = RD|Win32
{D15B34EC-A32C-4968-9B0B-66998B579364}.RD|x64.ActiveCfg = RD|x64
{C0300513-E845-43B4-9A4F-E8817EAEF57C}.Debug|Win32.ActiveCfg = Debug|Win32
{C0300513-E845-43B4-9A4F-E8817EAEF57C}.Debug|Win32.Build.0 = Debug|Win32
{C0300513-E845-43B4-9A4F-E8817EAEF57C}.Debug|x64.ActiveCfg = Debug|x64

View File

@ -572,9 +572,9 @@ void CMinimap::mouseMoved(const SDL_MouseMotionEvent & sEvent)
moveAdvMapSelection();
}
void CMinimap::showAll(SDL_Surface * to)
void CMinimap::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
if (minimap)
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
@ -589,10 +589,10 @@ void CMinimap::showAll(SDL_Surface * to)
ui16(adventureInt->terrain.tilesh * pos.h / mapSizes.y)
};
SDL_GetClipRect(to, &oldClip);
SDL_SetClipRect(to, &pos);
CSDL_Ext::drawDashedBorder(to, radar, int3(255,75,125));
SDL_SetClipRect(to, &oldClip);
//* SDL_GetClipRect(to, &oldClip);
//* SDL_SetClipRect(to, &pos);
//* CSDL_Ext::drawDashedBorder(to, radar, int3(255,75,125));
//* SDL_SetClipRect(to, &oldClip);
}
}
@ -648,11 +648,11 @@ CInfoBar::CVisibleInfo::CVisibleInfo(Point position):
}
void CInfoBar::CVisibleInfo::show(SDL_Surface *to)
void CInfoBar::CVisibleInfo::show()
{
CIntObject::show(to);
CIntObject::show();
BOOST_FOREACH(auto object, forceRefresh)
object->showAll(to);
object->showAll();
}
void CInfoBar::CVisibleInfo::loadHero(const CGHeroInstance * hero)

View File

@ -231,7 +231,7 @@ public:
void setLevel(int level);
void setAIRadar(bool on);
void showAll(SDL_Surface * to);
void showAll();
void hideTile(const int3 &pos); //puts FoW
void showTile(const int3 &pos); //removes FoW
@ -255,7 +255,7 @@ class CInfoBar : public CIntObject
public:
CVisibleInfo(Point position);
void show(SDL_Surface *to);
void show();
//functions that must be called only once
void loadHero(const CGHeroInstance * hero);

View File

@ -252,24 +252,24 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
} //for (int i=0;i<currentPath->nodes.size()-1;i++)
}
void CTerrainRect::show(SDL_Surface * to)
void CTerrainRect::show()
{
if(ADVOPT.smoothMove)
CGI->mh->terrainRect
(adventureInt->position, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &pos, moveX, moveY, false, int3());
nullptr, &pos, moveX, moveY, false, int3());
else
CGI->mh->terrainRect
(adventureInt->position, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &pos, 0, 0, false, int3());
nullptr, &pos, 0, 0, false, int3());
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
//SDL_FreeSurface(teren);
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
{
showPath(&pos, to);
//* showPath(&pos, to);
}
}
@ -350,14 +350,14 @@ void CResDataBar::draw(SDL_Surface * to)
graphics->fonts[FONT_SMALL]->renderTextLeft(to, processStr(datetext,temp), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
}
void CResDataBar::show(SDL_Surface * to)
void CResDataBar::show()
{
}
void CResDataBar::showAll(SDL_Surface * to)
void CResDataBar::showAll()
{
draw(to);
draw(nullptr);
}
CAdvMapInt::CAdvMapInt():
@ -445,13 +445,13 @@ void CAdvMapInt::fswitchLevel()
{
position.z--;
underground.setIndex(0,true);
underground.showAll(screenBuf);
underground.showAll();
}
else
{
underground.setIndex(1,true);
position.z++;
underground.showAll(screenBuf);
underground.showAll();
}
updateScreen = true;
minimap.setLevel(position.z);
@ -652,36 +652,36 @@ void CAdvMapInt::deactivate()
LOCPLINT->cingconsole->deactivate();
}
}
void CAdvMapInt::showAll(SDL_Surface * to)
void CAdvMapInt::showAll()
{
blitAt(bg,0,0,to);
//* blitAt(bg,0,0,to);
if(state != INGAME)
return;
kingOverview.showAll(to);
underground.showAll(to);
questlog.showAll(to);
sleepWake.showAll(to);
moveHero.showAll(to);
spellbook.showAll(to);
advOptions.showAll(to);
sysOptions.showAll(to);
nextHero.showAll(to);
endTurn.showAll(to);
kingOverview.showAll();
underground.showAll();
questlog.showAll();
sleepWake.showAll();
moveHero.showAll();
spellbook.showAll();
advOptions.showAll();
sysOptions.showAll();
nextHero.showAll();
endTurn.showAll();
minimap.showAll(to);
heroList.showAll(to);
townList.showAll(to);
minimap.showAll();
heroList.showAll();
townList.showAll();
updateScreen = true;
show(to);
show();
resdatabar.draw(to);
//* resdatabar.draw(to);
statusbar.show(to);
statusbar.show();
infoBar.showAll(to);
LOCPLINT->cingconsole->showAll(to);
infoBar.showAll();
LOCPLINT->cingconsole->showAll();
}
bool CAdvMapInt::isHeroSleeping(const CGHeroInstance *hero)
@ -701,7 +701,7 @@ void CAdvMapInt::setHeroSleeping(const CGHeroInstance *hero, bool sleep)
updateNextHero(NULL);
}
void CAdvMapInt::show(SDL_Surface * to)
void CAdvMapInt::show()
{
if(state != INGAME)
return;
@ -746,14 +746,14 @@ void CAdvMapInt::show(SDL_Surface * to)
}
if(updateScreen)
{
terrain.show(to);
for(int i=0;i<4;i++)
blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
terrain.show();
//* for(int i=0;i<4;i++)
//* blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
updateScreen=false;
LOCPLINT->cingconsole->showAll(to);
LOCPLINT->cingconsole->showAll();
}
infoBar.show(to);
statusbar.showAll(to);
infoBar.show();
statusbar.showAll();
}
void CAdvMapInt::selectionChanged()
@ -1490,7 +1490,7 @@ void CAdvMapInt::aiTurnStarted()
CCS->musich->playMusicFromSet("enemy-turn", true);
adventureInt->minimap.setAIRadar(true);
adventureInt->infoBar.startEnemyTurn(LOCPLINT->cb->getCurrentPlayer());
adventureInt->infoBar.showAll(screen);//force refresh on inactive object
adventureInt->infoBar.showAll(); //force refresh on inactive object
}
void CAdvMapInt::adjustActiveness(bool aiTurnStart)

View File

@ -55,7 +55,7 @@ public:
void clickRight(tribool down, bool previousState);
void hover(bool on);
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void show(SDL_Surface * to);
void show();
void showPath(const SDL_Rect * extRect, SDL_Surface * to);
int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
@ -76,8 +76,8 @@ public:
~CResDataBar();
void draw(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
};
/// That's a huge class which handles general adventure map actions and
@ -147,8 +147,8 @@ public:
void activate();
void deactivate();
void show(SDL_Surface * to); //redraws terrain
void showAll(SDL_Surface * to); //shows and activates adv. map interface
void show(); //redraws terrain
void showAll(); //shows and activates adv. map interface
void select(const CArmedInstance *sel, bool centerView = true);
void selectionChanged();

View File

@ -1218,9 +1218,9 @@ CAnimImage::~CAnimImage()
delete anim;
}
void CAnimImage::showAll(SDL_Surface * to)
void CAnimImage::showAll()
{
IImage *img;
/* IImage *img;
if ( flags & CShowableAnim::BASE && frame != 0)
if ((img = anim->getImage(0, group)))
@ -1228,6 +1228,7 @@ void CAnimImage::showAll(SDL_Surface * to)
if ((img = anim->getImage(frame, group)))
img->draw(to, pos.x, pos.y);
*/
}
void CAnimImage::setFrame(size_t Frame, size_t Group)
@ -1345,11 +1346,11 @@ void CShowableAnim::clipRect(int posX, int posY, int width, int height)
pos.h = height;
}
void CShowableAnim::show(SDL_Surface * to)
void CShowableAnim::show()
{
if ( flags & BASE && frame != first)
blitImage(first, group, to);
blitImage(frame, group, to);
//* if ( flags & BASE && frame != first)
//* blitImage(first, group, to);
//* blitImage(frame, group, to);
if ((flags & PLAY_ONCE) && frame + 1 == last)
return;
@ -1362,11 +1363,11 @@ void CShowableAnim::show(SDL_Surface * to)
}
}
void CShowableAnim::showAll(SDL_Surface * to)
void CShowableAnim::showAll()
{
if ( flags & BASE && frame != first)
blitImage(first, group, to);
blitImage(frame, group, to);
//* if ( flags & BASE && frame != first)
//* blitImage(first, group, to);
//* blitImage(frame, group, to);
}
void CShowableAnim::blitImage(size_t frame, size_t group, SDL_Surface *to)

View File

@ -247,7 +247,7 @@ public:
//makes image player-colored
void playerColored(PlayerColor player);
void showAll(SDL_Surface * to);
void showAll();
};
/// Base class for displaying animation, used as superclass for different animations
@ -308,8 +308,8 @@ public:
virtual void reset();
//show current frame and increase counter
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
};
/// Creature-dependend animations like attacking, moving,...

View File

@ -1,7 +1,5 @@
#pragma once
struct SDL_Surface;
/*
@ -14,11 +12,6 @@ struct SDL_Surface;
*
*/
/// Struct which stands for a simple rgba palette
struct BMPPalette
{
ui8 R,G,B,F;
};
namespace BitmapHandler
{

View File

@ -129,7 +129,7 @@ SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, double f)
return ret;
}
void CBuildingRect::show(SDL_Surface * to)
void CBuildingRect::show()
{
const ui32 stageDelay = 16;
@ -141,20 +141,20 @@ void CBuildingRect::show(SDL_Surface * to)
if (stateCounter < S1_TRANSP)
{
setAlpha(255*stateCounter/stageDelay);
CShowableAnim::show(to);
CShowableAnim::show();
}
else
{
setAlpha(255);
CShowableAnim::show(to);
CShowableAnim::show();
}
if (border && stateCounter > S1_TRANSP)
{
if (stateCounter == BUILDED)
{
if (parent->selectedBuilding == this)
blitAtLoc(border,0,0,to);
//* if (parent->selectedBuilding == this)
//* blitAtLoc(border,0,0,to);
return;
}
// key colors in glowing border
@ -175,7 +175,7 @@ void CBuildingRect::show(SDL_Surface * to)
newColor = oldColor;
SDL_SetColors(border, &newColor, colorID, 1);
blitAtLoc(border,0,0,to);
//* blitAtLoc(border,0,0,to);
SDL_SetColors(border, &oldColor, colorID, 1);
}
@ -183,14 +183,14 @@ void CBuildingRect::show(SDL_Surface * to)
stateCounter++;
}
void CBuildingRect::showAll(SDL_Surface * to)
void CBuildingRect::showAll()
{
if (stateCounter == 0)
return;
CShowableAnim::showAll(to);
if(!active && parent->selectedBuilding == this && border)
blitAtLoc(border,0,0,to);
CShowableAnim::showAll();
//* if(!active && parent->selectedBuilding == this && border)
//* blitAtLoc(border,0,0,to);
}
std::string getBuildingSubtitle(const CStructure * structure)//hover text for building
@ -370,7 +370,7 @@ void CHeroGSlot::clickLeft(tribool down, bool previousState)
{
setHighlight(true);
owner->garr->selectSlot(nullptr);
showAll(screen2);
showAll();
}
hover(false);hover(true); //refresh statusbar
}
@ -545,18 +545,18 @@ void CCastleBuildings::removeBuilding(BuildingID building)
recreate();
}
void CCastleBuildings::show(SDL_Surface * to)
void CCastleBuildings::show()
{
CIntObject::show(to);
CIntObject::show();
BOOST_FOREACH(CBuildingRect * str, buildings)
str->show(to);
str->show();
}
void CCastleBuildings::showAll(SDL_Surface * to)
void CCastleBuildings::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
BOOST_FOREACH(CBuildingRect * str, buildings)
str->showAll(to);
str->showAll();
}
const CGHeroInstance* CCastleBuildings::getHero()
@ -749,9 +749,9 @@ void CCastleBuildings::enterCastleGate()
availableTowns.push_back(t->id.getNum());//add to the list
}
}
CPicture *titlePic = new CPicture (LOCPLINT->castleInt->bicons->ourImages[BuildingID::CASTLE_GATE].bitmap, 0,0, false);//will be deleted by selection window
GH.pushInt (new CObjectListWindow(availableTowns, titlePic, CGI->generaltexth->jktexts[40],
CGI->generaltexth->jktexts[41], boost::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)));
//* CPicture *titlePic = new CPicture (LOCPLINT->castleInt->bicons->ourImages[BuildingID::CASTLE_GATE].bitmap, 0,0, false);//will be deleted by selection window
//* GH.pushInt (new CObjectListWindow(availableTowns, titlePic, CGI->generaltexth->jktexts[40],
//* CGI->generaltexth->jktexts[41], boost::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)));
}
void CCastleBuildings::enterDwelling(int level)
@ -858,7 +858,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
center();
updateShadow();
garr = new CGarrisonInt(305, 387, 4, Point(0,96), panel->bg, Point(62,374), town->getUpperArmy(), town->visitingHero);
garr = new CGarrisonInt(305, 387, 4, Point(0,96), NULL /*panel->bg*/, Point(62,374), town->getUpperArmy(), town->visitingHero);
heroes = new HeroSlots(town, Point(241, 387), Point(241, 483), garr, true);
title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, Colors::WHITE, town->name);
income = new CLabel(195, 443, FONT_SMALL, CENTER);
@ -873,7 +873,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
garr->addSplitBtn(split);
Rect barRect(9, 182, 732, 18);
statusbar = new CGStatusBar(new CPicture(*panel, barRect, 9, 555, false));
statusbar = new CGStatusBar(new CPicture(panel->getImage(), barRect, 9, 555, false));
resdatabar = new CResDataBar("ZRESBAR", 3, 575, 32, 2, 85, 85);
townlist = new CTownList(3, Point(744, 414), "IAM014", "IAM015");
@ -1283,7 +1283,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
resdatabar->pos.x += pos.x;
resdatabar->pos.y += pos.y;
Rect barRect(5, 556, 740, 18);
statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false));
statusBar = new CGStatusBar(new CPicture(background->getImage(), barRect, 5, 556, false));
title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings[BuildingID(town->hallLevel()+BuildingID::VILLAGE_HALL)]->Name());
exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "",
@ -1357,7 +1357,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
OBJ_CONSTRUCTION_CAPTURING_ALL;
new CAnimImage(town->town->clientInfo.buildingsIcons, building->bid, 0, 125, 50);
new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
new CGStatusBar(new CPicture(background->getImage(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
new CLabel(197, 30, FONT_MEDIUM, CENTER, Colors::WHITE,
boost::str(boost::format(CGI->generaltexth->hcommands[7]) % building->Name()));
@ -1450,7 +1450,7 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
resdatabar->pos.y += pos.y;
Rect barRect(4, 554, 740, 18);
statusBar = new CGStatusBar(new CPicture(*background, barRect, 4, 554, false));
statusBar = new CGStatusBar(new CPicture(background->getImage(), barRect, 4, 554, false));
}
void CFortScreen::creaturesChanged()
@ -1595,7 +1595,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner):
resdatabar->pos.x += pos.x;
resdatabar->pos.y += pos.y;
Rect barRect(7, 556, 737, 18);
statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false));
//* statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false));
exit = new CAdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE);
@ -1658,7 +1658,7 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, Art
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
animBG = new CPicture("TPSMITBK", 64, 50);
animBG->needRefresh = true;

View File

@ -52,8 +52,8 @@ public:
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
};
/// Dwelling info box - right-click screen for dwellings
@ -146,8 +146,8 @@ public:
void addBuilding(BuildingID building);
void removeBuilding(BuildingID building);//FIXME: not tested!!!
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
};
/// Creature info window

View File

@ -443,7 +443,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
else //slider automatically places bonus Items
recreateSkillList (0);
showAll(screen2);
showAll();
//AUIDAT.DEF
}
@ -505,11 +505,11 @@ void CCreatureWindow::recreateSkillList(int Pos)
}
}
void CCreatureWindow::showAll(SDL_Surface * to)
void CCreatureWindow::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::YELLOW, to); //creature name
//* printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::YELLOW, to); //creature name
printLine(0, CGI->generaltexth->primarySkillNames[0], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->Attack());
printLine(1, CGI->generaltexth->primarySkillNames[1], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->Defense());
@ -523,13 +523,13 @@ void CCreatureWindow::showAll(SDL_Surface * to)
}
if (stackNode->valOfBonuses(Bonus::CASTS))
{
printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::WHITE, to);
std::string casts;
if (type == BATTLE)
casts = boost::lexical_cast<std::string>((ui16)dynamic_cast<const CStack*>(stackNode)->casts); //ui8 is converted to char :(
else
casts = boost::lexical_cast<std::string>(stackNode->valOfBonuses(Bonus::CASTS));
printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::WHITE, to);
}
//TODO
@ -542,29 +542,29 @@ void CCreatureWindow::showAll(SDL_Surface * to)
printLine(6, CGI->generaltexth->zelp[441].first, c->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED));
BOOST_FOREACH(CBonusItem* b, bonusItems)
b->showAll (to);
b->showAll();
BOOST_FOREACH(auto s, selectableSkills)
s->showAll (to);
s->showAll();
for (int i = 0; i < skillPictures.size(); i++)
{
skillPictures[i]->bg = BitmapHandler::loadBitmap (skillToFile(i));
skillPictures[i]->showAll (to);
//* skillPictures[i]->bg = BitmapHandler::loadBitmap (skillToFile(i));
//* skillPictures[i]->showAll (to);
}
if (upgradeOptions.size() && (type == COMMANDER_LEVEL_UP && upgradeOptions[selectedOption] >= 100)) //add frame to selected skill
{
int index = selectedOption - selectableSkills.size(); //this is screwed
CSDL_Ext::drawBorder(to, Rect::around(selectableBonuses[index]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
//* CSDL_Ext::drawBorder(to, Rect::around(selectableBonuses[index]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
}
}
void CCreatureWindow::show(SDL_Surface * to)
void CCreatureWindow::show()
{
CIntObject::show(to);
if (!count.empty()) //army stack
graphics->fonts[FONT_TIMES]->renderTextRight(to, count, Colors::WHITE, Point(pos.x + 114, pos.y + 174));
CIntObject::show();
//* if (!count.empty()) //army stack
//* graphics->fonts[FONT_TIMES]->renderTextRight(to, count, Colors::WHITE, Point(pos.x + 114, pos.y + 174));
}
@ -709,14 +709,14 @@ CBonusItem::CBonusItem(const Rect &Pos, const std::string &Name, const std::stri
removeUsedEvents(ALL); //no actions atm
}
void CBonusItem::showAll (SDL_Surface * to)
void CBonusItem::showAll()
{
if (visible)
{
graphics->fonts[FONT_SMALL]->renderTextLeft(to, name, Colors::YELLOW, Point(pos.x + 72, pos.y + 6));
graphics->fonts[FONT_SMALL]->renderTextLeft(to, description, Colors::WHITE, Point(pos.x + 72, pos.y + 30));
if (bonusGraphics && bonusGraphics->bg)
blitAtLoc(bonusGraphics->bg, 12, 2, to);
//* graphics->fonts[FONT_SMALL]->renderTextLeft(to, name, Colors::YELLOW, Point(pos.x + 72, pos.y + 6));
//* graphics->fonts[FONT_SMALL]->renderTextLeft(to, description, Colors::WHITE, Point(pos.x + 72, pos.y + 30));
//* if (bonusGraphics && bonusGraphics->bg)
//* blitAtLoc(bonusGraphics->bg, 12, 2, to);
}
}
@ -731,10 +731,10 @@ void CSelectableSkill::clickLeft(tribool down, bool previousState)
callback();
}
void CCreInfoWindow::show(SDL_Surface * to)
void CCreInfoWindow::show()
{
CIntObject::show(to);
creatureCount->showAll(to);
CIntObject::show();
creatureCount->showAll();
}
CCreInfoWindow::CCreInfoWindow(const CStackInstance &stack, bool LClicked, boost::function<void()> upgradeFunc, boost::function<void()> dismissFunc, UpgradeInfo *upgradeInfo):

View File

@ -94,8 +94,8 @@ public:
CCreatureWindow(CreatureID Cid, CreWinType Type, int creatureCount); //c-tor
void init(const CStackInstance *stack, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner);
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll();
void show();
void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
void sliderMoved(int newpos);
void close();
@ -118,7 +118,7 @@ public:
~CBonusItem();
void setBonus(const Bonus &bonus);
void showAll (SDL_Surface * to);
void showAll();
};
class CSelectableSkill : public LRClickableAreaWText
@ -155,7 +155,7 @@ public:
void init(const CCreature * cre, const CBonusSystemNode * stackNode, const CGHeroInstance * heroOwner, int creatureCount, bool LClicked);
void printLine(int nr, const std::string & text, int baseVal, int val = -1, bool range = false);
void show(SDL_Surface * to);
void show();
};
CIntObject *createCreWindow(const CStack *s, bool lclick = false);

View File

@ -4,7 +4,6 @@
#include "../lib/Filesystem/CResourceLoader.h"
#include "../lib/VCMI_Lib.h"
#include "CBitmapHandler.h"
/*
* CDefHandler.cpp, part of VCMI engine
@ -52,7 +51,6 @@ CDefEssential::~CDefEssential()
void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
{
BMPPalette palette[256];
SDefEntry &de = * reinterpret_cast<SDefEntry *>(table);
ui8 *p;
@ -62,13 +60,7 @@ void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
height = read_le_u32(&de.height);
ui32 totalBlocks = read_le_u32(&de.totalBlocks);
for (ui32 it=0;it<256;it++)
{
palette[it].R = de.palette[it].R;
palette[it].G = de.palette[it].G;
palette[it].B = de.palette[it].B;
palette[it].F = 255;
}
//CPaletteRGBA palette(de);
// The SDefEntryBlock starts just after the SDefEntry
p = reinterpret_cast<ui8 *>(&de);
@ -115,7 +107,7 @@ void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
for(ui32 i=0; i < SEntries.size(); ++i)
{
Cimage nimg;
nimg.bitmap = getSprite(i, table, palette);
nimg.bitmap = getSprite(i, table);
nimg.imName = SEntries[i].name;
nimg.groupNumber = SEntries[i].group;
ourImages.push_back(nimg);
@ -128,7 +120,7 @@ void CDefHandler::expand(ui8 N,ui8 & BL, ui8 & BR)
BR = N & 0x1F;
}
SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const
SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef) const
{
SDL_Surface * ret=NULL;
@ -175,12 +167,12 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPal
for(int i=0; i<256; ++i)
{
SDL_Color pr;
pr.r = palette[i].R;
pr.g = palette[i].G;
pr.b = palette[i].B;
pr.unused = palette[i].F;
(*(ret->format->palette->colors+i))=pr;
// SDL_Color pr;
// pr.r = palette[i].R;
// pr.g = palette[i].G;
// pr.b = palette[i].B;
// pr.unused = palette[i].F;
// (*(ret->format->palette->colors+i))=pr;
}
int ftcp=0;
@ -371,6 +363,7 @@ CDefHandler * CDefHandler::giveDef(const std::string & defName)
delete [] data;
return nh;
}
CDefEssential * CDefHandler::giveDefEss(const std::string & defName)
{
CDefEssential * ret;

View File

@ -1,9 +1,7 @@
#pragma once
#include "../lib/vcmi_endian.h"
struct SDL_Surface;
struct BMPPalette;
/*
* CDefHandler.h, part of VCMI engine
@ -94,7 +92,7 @@ public:
CDefHandler(); //c-tor
~CDefHandler(); //d-tor
SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp"
SDL_Surface * getSprite (int SIndex, const ui8 * FDef) const; //saves picture with given number to "testtt.bmp"
static void expand(ui8 N,ui8 & BL, ui8 & BR);
void openFromMemory(ui8 * table, const std::string & name);
CDefEssential * essentialize();

View File

@ -191,7 +191,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals
OBJ_CONSTRUCTION_CAPTURING_ALL;
if(!garr)
{
garr = new CGarrisonInt(15, 485, 8, Point(), background->bg, Point(15,485), curHero);
garr = new CGarrisonInt(15, 485, 8, Point(), NULL /*background->bg*/, Point(15,485), curHero);
split = new CAdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32],
boost::bind(&CGarrisonInt::splitClick,garr), 539, 519, "hsbtns9.def", false, NULL, false); //deleted by garrison destructor
boost::algorithm::replace_first(split->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
@ -319,55 +319,55 @@ void CHeroWindow::commanderWindow()
}
void CHeroWindow::showAll(SDL_Surface * to)
void CHeroWindow::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
//printing hero's name
printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, Colors::YELLOW, to);
//* printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, Colors::YELLOW, to);
//printing hero's level
std::string secondLine= CGI->generaltexth->allTexts[342];
boost::algorithm::replace_first(secondLine,"%d",boost::lexical_cast<std::string>(curHero->level));
boost::algorithm::replace_first(secondLine,"%s",curHero->type->heroClass->name);
printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::WHITE, to);
//* printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::WHITE, to);
//primary skills names
printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::YELLOW, to);
printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::YELLOW, to);
printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::YELLOW, to);
printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::YELLOW, to);
//* printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::YELLOW, to);
//* printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::YELLOW, to);
//* printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::YELLOW, to);
//* printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::YELLOW, to);
//dismiss / quest log
printAtMiddleWBLoc(CGI->generaltexth->jktexts[8], 388, 455, FONT_SMALL, 50, Colors::WHITE, to);
printAtMiddleWBLoc(CGI->generaltexth->jktexts[9], 534, 455, FONT_SMALL, 50, Colors::WHITE, to);
//* printAtMiddleWBLoc(CGI->generaltexth->jktexts[8], 388, 455, FONT_SMALL, 50, Colors::WHITE, to);
//* printAtMiddleWBLoc(CGI->generaltexth->jktexts[9], 534, 455, FONT_SMALL, 50, Colors::WHITE, to);
//printing primary skills' amounts
for(int m=0; m<4; ++m)
{
std::ostringstream primarySkill;
primarySkill << primSkillAreas[m]->bonusValue;
printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, Colors::WHITE, to);
}
//secondary skills
for(size_t v=0; v<std::min(secSkillAreas.size(), curHero->secSkills.size()); ++v)
{
printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
}
//printing special ability
printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::YELLOW, to);
printAtLoc(curHero->type->specName, 69, 205, FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::YELLOW, to);
//* printAtLoc(curHero->type->specName, 69, 205, FONT_SMALL, Colors::WHITE, to);
//printing necessery texts
printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::YELLOW, to);
//* printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::YELLOW, to);
std::ostringstream expstr;
expstr << curHero->exp;
printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::WHITE, to);
printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::YELLOW, to);
//* printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::YELLOW, to);
std::ostringstream manastr;
manastr << curHero->mana << '/' << heroWArt.manaLimit();
printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::WHITE, to);
}

View File

@ -83,7 +83,7 @@ public:
CHeroWindow(const CGHeroInstance *hero); //c-tor
void update(const CGHeroInstance * hero, bool redrawNeeded = false); //sets main displayed hero
void showAll(SDL_Surface * to);
void showAll();
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
void questlog(); //show quest log in hero window

View File

@ -3,6 +3,7 @@
#include "StdInc.h"
#include <boost/filesystem/operations.hpp>
#include <SDL_mixer.h>
#include "UIFramework/GL2D.h"
#include "UIFramework/SDL_Extensions.h"
#include "CGameInfo.h"
#include "mapHandler.h"
@ -40,17 +41,15 @@
#include "../lib/GameConstants.h"
#include "UIFramework/CGuiHandler.h"
#ifdef _WIN32
#include "SDL_syswm.h"
#endif
#include "../lib/CDefObjInfoHandler.h"
#include "../lib/UnlockGuard.h"
#if __MINGW32__
#if __MINGW32__ || defined(_WIN32)
#undef main
#endif
namespace po = boost::program_options;
namespace fs = boost::filesystem;
/*
* CMT.cpp, part of VCMI engine
@ -62,8 +61,7 @@ namespace po = boost::program_options;
*
*/
std::string NAME_AFFIX = "client";
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (client)"); //application name
CGuiHandler GH;
static CClient *client=NULL;
SDL_Surface *screen = NULL, //main screen surface
@ -136,8 +134,7 @@ void init()
tlog0<<"Initializing VCMI_Lib: "<<tmh.getDiff()<<std::endl;
pomtime.getDiff();
CCS->curh = new CCursorHandler;
CCS->curh->initCursor();
CCS->curh = new CCursorHandler();
CCS->curh->show();
tlog0<<"Screen handler: "<<pomtime.getDiff()<<std::endl;
pomtime.getDiff();
@ -177,20 +174,34 @@ static void prog_help(const po::options_description &opts)
void OSX_checkForUpdates();
#endif
static void initScreen(int w, int h, bool fullscreen)
{
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
GL2D::initVideo(w, h, fullscreen);
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
}
#ifdef _WIN32
int _tmain(int argc, _TCHAR* argv[])
#elif defined(__APPLE__)
int SDL_main(int argc, char *argv[])
#else
int main(int argc, char** argv)
int main(int argc, char* argv[])
#endif
{
#ifdef __APPLE__
// Correct working dir executable folder (not bundle folder) so we can use executable relative pathes
std::string executablePath = argv[0];
std::string workDir = executablePath.substr(0, executablePath.rfind('/'));
chdir(workDir.c_str());
tlog0 << "Starting... " << std::endl;
#if defined(__APPLE__) || defined(_WIN32)
//Set working directory to parent directory of executable
//so we can use executable relative pathes
fs::current_path(fs::path(argv[0]).parent_path());
#endif
#ifdef __APPLE__
// Check for updates
OSX_checkForUpdates();
@ -203,7 +214,6 @@ int main(int argc, char** argv)
fclose(check);
#endif
tlog0 << "Starting... " << std::endl;
po::options_description opts("Allowed options");
opts.add_options()
("help,h", "display help and exit")
@ -242,8 +252,8 @@ int main(int argc, char** argv)
}
//Set environment vars to make window centered. Sometimes work, sometimes not. :/
putenv((char*)"SDL_VIDEO_WINDOW_POS");
putenv((char*)"SDL_VIDEO_CENTERED=1");
putenv("SDL_VIDEO_CENTERED=center");
//putenv("SDL_VIDEO_WINDOW_POS");
// Have effect on X11 system only (Linux).
// For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension
@ -293,7 +303,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["fullscreen"].Bool());
initScreen(res["width"].Float(), res["height"].Float(), video["fullscreen"].Bool());
tlog0 <<"\tInitializing screen: "<<pomtime.getDiff() << std::endl;
@ -315,8 +325,6 @@ int main(int argc, char** argv)
if(!vm.count("battle") && !vm.count("nointro"))
playIntro();
SDL_FillRect(screen,NULL,0);
CSDL_Ext::update(screen);
loading.join();
tlog0<<"Initialization of VCMI (together): "<<total.getDiff()<<std::endl;
@ -654,9 +662,9 @@ void processCommand(const std::string &message)
//plays intro, ends when intro is over or button has been pressed (handles events)
void playIntro()
{
if(CCS->videoh->openAndPlayVideo("3DOLOGO.SMK", 60, 40, screen, true))
if (CCS->videoh->openAndPlayVideo("3DOLOGO.SMK", 60, 40, true))
{
CCS->videoh->openAndPlayVideo("AZVS.SMK", 60, 80, screen, true);
CCS->videoh->openAndPlayVideo("AZVS.SMK", 60, 80, true);
}
}
@ -667,79 +675,6 @@ void dispose()
delete logfile;
}
//used only once during initialization
static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo)
{
// VCMI will only work with 2, 3 or 4 bytes per pixel
vstd::amax(bpp, 16);
vstd::amin(bpp, 32);
// Try to use the best screen depth for the display
int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
if(suggestedBpp == 0)
{
tlog1 << "Error: SDL says that " << w << "x" << h << " resolution is not available!\n";
return;
}
bool bufOnScreen = (screenBuf == screen);
if(suggestedBpp != bpp)
{
tlog2 << "Note: SDL suggests to use " << suggestedBpp << " bpp instead of" << bpp << " bpp " << std::endl;
}
//For some reason changing fullscreen via config window checkbox result in SDL_Quit event
if (resetVideo)
{
if(screen) //screen has been already initialized
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
}
if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL)
{
tlog1 << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)\n";
throw std::runtime_error("Requested screen resolution is not available\n");
}
tlog0 << "New screen flags: " << screen->flags << std::endl;
if(screen2)
SDL_FreeSurface(screen2);
screen2 = CSDL_Ext::copySurface(screen);
SDL_EnableUNICODE(1);
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#ifdef _WIN32
SDL_SysWMinfo wm;
SDL_VERSION(&wm.version);
int getwm = SDL_GetWMInfo(&wm);
if(getwm == 1)
{
int sw = GetSystemMetrics(SM_CXSCREEN),
sh = GetSystemMetrics(SM_CYSCREEN);
RECT curpos;
GetWindowRect(wm.window,&curpos);
int ourw = curpos.right - curpos.left,
ourh = curpos.bottom - curpos.top;
SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
}
else
{
tlog3 << "Something went wrong, getwm=" << getwm << std::endl;
tlog3 << "SDL says: " << SDL_GetError() << std::endl;
tlog3 << "Window won't be centered.\n";
}
#endif
//TODO: centering game window on other platforms (or does the environment do their job correctly there?)
screenBuf = bufOnScreen ? screen : screen2;
//setResolution = true;
}
static void fullScreenChanged()
{
boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);

View File

@ -5,6 +5,7 @@
#include "CDefHandler.h"
#include "CAnimation.h"
#include "CGameInfo.h"
#include "UIFramework/GL2D.h"
#include "UIFramework/SDL_Extensions.h"
#include "../lib/CGeneralTextHandler.h"
#include "Graphics.h"
@ -46,7 +47,7 @@ public:
CComponent *comp;
//blit component with image centered at this position
void showAll(SDL_Surface * to);
void showAll();
//ComponentResolved(); //c-tor
ComponentResolved(CComponent *Comp); //c-tor
@ -117,18 +118,18 @@ void CMessage::dispose()
SDL_Surface * CMessage::drawDialogBox(int w, int h, PlayerColor playerColor)
{
//prepare surface
SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
//* SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
for (int i=0; i<w; i+=background->w)//background
{
for (int j=0; j<h; j+=background->h)
{
Rect srcR(0,0,background->w, background->h);
Rect dstR(i,j,w,h);
CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
//* CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
}
}
drawBorder(playerColor, ret, w, h);
return ret;
//* drawBorder(playerColor, ret, w, h);
return nullptr; //* ret;
}
std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineSize, EFonts font )
@ -229,8 +230,8 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
for(int i = 0;
i < ARRAY_COUNT(sizes)
&& sizes[i][0] < screen->w - 150
&& sizes[i][1] < screen->h - 150
&& sizes[i][0] < GL2D::getScreenWidth() - 150
&& sizes[i][1] < GL2D::getScreenHeight() - 150
&& ret->text->slider;
i++)
{
@ -263,20 +264,20 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
vstd::amax(winSize.first, comps.w);
vstd::amax(winSize.first, bw);
vstd::amin(winSize.first, screen->w - 150);
vstd::amin(winSize.first, GL2D::getScreenWidth() - 150);
ret->bitmap = drawDialogBox (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player);
ret->pos.h=ret->bitmap->h;
ret->pos.w=ret->bitmap->w;
ret->center();
//* ret->bitmap = drawDialogBox (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player);
//* ret->pos.h=ret->bitmap->h;
//* ret->pos.w=ret->bitmap->w;
//* ret->center();
int curh = SIDE_MARGIN;
int xOffset = (ret->pos.w - ret->text->pos.w)/2;
if(!ret->buttons.size() && !ret->components.size()) //improvement for very small text only popups -> center text vertically
{
if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN)
curh = (ret->bitmap->h - ret->text->pos.h)/2;
//* if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN)
//* curh = (ret->bitmap->h - ret->text->pos.h)/2;
}
ret->text->moveBy(Point(xOffset, curh));
@ -291,8 +292,8 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
if(ret->buttons.size())
{
// Position the buttons at the bottom of the window
bw = (ret->bitmap->w/2) - (bw/2);
curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h;
//* bw = (ret->bitmap->w/2) - (bw/2);
//* curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h;
for(size_t i=0; i<ret->buttons.size(); i++)
{
@ -395,10 +396,10 @@ ComponentResolved::~ComponentResolved()
}
}
void ComponentResolved::showAll(SDL_Surface *to)
void ComponentResolved::showAll()
{
CIntObject::showAll(to);
comp->showAll(to);
CIntObject::showAll();
comp->showAll();
}
ComponentsToBlit::~ComponentsToBlit()
@ -481,7 +482,7 @@ void ComponentsToBlit::blitCompsOnSur( bool blitOr, int inter, int &curh, SDL_Su
cur->moveTo(Point(curw, curh));
//blit component
cur->showAll(ret);
cur->showAll();
curw += cur->pos.w;
//if there is subsequent component blit "or"

View File

@ -318,8 +318,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
{
movementPxStep(details, i, hp, ho);
adventureInt->updateScreen = true;
adventureInt->show(screen);
CSDL_Ext::update(screen);
adventureInt->show();
GH.mainFPSmng->framerateDelay(); //for animation purposes
} //for(int i=1; i<32; i+=4)
//main moving done
@ -2185,7 +2184,7 @@ void CPlayerInterface::acceptTurn()
adventureInt->infoBar.showDate();
adventureInt->updateNextHero(NULL);
adventureInt->showAll(screen);
adventureInt->showAll();
if(settings["session"]["autoSkip"].Bool() && !LOCPLINT->shiftPressed())
{

View File

@ -39,6 +39,7 @@
#include "../lib/CThreadHelper.h"
#include "../lib/CConfigHandler.h"
#include "../lib/GameConstants.h"
#include "UIFramework/GL2D.h"
#include "UIFramework/CGuiHandler.h"
#include "UIFramework/CIntObjectClasses.h"
#include "../lib/Mapping/CMapService.h"
@ -237,8 +238,8 @@ CMenuScreen::CMenuScreen(const JsonNode& configNode):
background = new CPicture(config["background"].String());
if (config["scalable"].Bool())
{
if (background->bg->format->palette)
background->convertToScreenBPP();
//* if (background->bg->format->palette)
//* background->convertToScreenBPP();
background->scaleTo(Point(screen->w, screen->h));
}
@ -265,20 +266,20 @@ CIntObject * CMenuScreen::createTab(size_t index)
return new CMenuEntry(this, config["items"].Vector()[index]);
}
void CMenuScreen::showAll(SDL_Surface * to)
void CMenuScreen::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
if (pos.h != to->h || pos.w != to->w)
CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
if (pos.w != GL2D::getScreenWidth() || pos.h != GL2D::getScreenHeight())
CMessage::drawBorder(PlayerColor(1), nullptr, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
}
void CMenuScreen::show(SDL_Surface * to)
void CMenuScreen::show()
{
if (!config["video"].isNull())
CCS->videoh->update(config["video"]["x"].Float() + pos.x, config["video"]["y"].Float() + pos.y, to, true, false);
CIntObject::show(to);
CCS->videoh->update(config["video"]["x"].Float() + pos.x, config["video"]["y"].Float() + pos.y, true, false);
CIntObject::show();
}
void CMenuScreen::activate()
@ -418,12 +419,12 @@ CreditsScreen::CreditsScreen()
credits->pos.h = credits->maxH;
}
void CreditsScreen::showAll(SDL_Surface * to)
void CreditsScreen::showAll()
{
//Do not draw anything
}
void CreditsScreen::show(SDL_Surface * to)
void CreditsScreen::show()
{
static int count = 0;
count++;
@ -436,7 +437,7 @@ void CreditsScreen::show(SDL_Surface * to)
SDL_SetClipRect(screenBuf, &creditsArea);
SDL_SetClipRect(screen, &creditsArea);
redraw();
CIntObject::showAll(to);
CIntObject::showAll();
SDL_SetClipRect(screen, NULL);
SDL_SetClipRect(screenBuf, NULL);
@ -460,8 +461,8 @@ void CreditsScreen::clickRight(tribool down, bool previousState)
CGPreGame::CGPreGame():
pregameConfig(new JsonNode(ResourceID("config/mainmenu.json")))
{
pos.w = screen->w;
pos.h = screen->h;
pos.w = GL2D::getScreenWidth();
pos.h = GL2D::getScreenHeight();
GH.defActionsDef = 63;
CGP = this;
@ -502,7 +503,6 @@ void CGPreGame::disposeGraphics()
void CGPreGame::update()
{
boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
if(CGP != this) //don't update if you are not a main interface
return;
@ -513,25 +513,7 @@ void CGPreGame::update()
menu->switchToTab(0);
}
if(SEL)
SEL->update();
// Handles mouse and key input
GH.updateTime();
GH.handleEvents();
//if (GH.curInt == NULL) // no redraw, when a new game was created
//return;
GH.topInt()->show(screen);
if (settings["general"]["showfps"].Bool())
GH.drawFPSCounter();
// draw the mouse cursor and update the screen
CCS->curh->drawWithScreenRestore();
CSDL_Ext::update(screen);
CCS->curh->drawRestored();
if (SEL) SEL->update();
}
void CGPreGame::openCampaignScreen(std::string name)
@ -1035,11 +1017,11 @@ void CSelectionScreen::propagateNames()
*serv << &pn;
}
void CSelectionScreen::showAll(SDL_Surface *to)
void CSelectionScreen::showAll()
{
CIntObject::showAll(to);
if (bordered && (pos.h != to->h || pos.w != to->w))
CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
CIntObject::showAll();
//* if (bordered && (pos.h != to->h || pos.w != to->w))
//* CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
}
// A new size filter (Small, Medium, ...) has been selected. Populate
@ -1484,10 +1466,10 @@ void SelectionTab::printMaps(SDL_Surface *to)
}
}
void SelectionTab::showAll(SDL_Surface * to)
void SelectionTab::showAll()
{
CIntObject::showAll(to);
printMaps(to);
CIntObject::showAll();
//* printMaps(to);
std::string title;
switch(tabType) {
@ -1505,10 +1487,10 @@ void SelectionTab::showAll(SDL_Surface * to)
break;
}
printAtMiddleLoc(title, 205, 28, FONT_MEDIUM, Colors::YELLOW, to); //Select a Scenario to Play
//* printAtMiddleLoc(title, 205, 28, FONT_MEDIUM, Colors::YELLOW, to); //Select a Scenario to Play
if(tabType != CMenuScreen::campaignList)
{
printAtMiddleLoc(CGI->generaltexth->allTexts[510], 87, 62, FONT_SMALL, Colors::YELLOW, to); //Map sizes
//* printAtMiddleLoc(CGI->generaltexth->allTexts[510], 87, 62, FONT_SMALL, Colors::YELLOW, to); //Map sizes
}
}
@ -1798,10 +1780,10 @@ void RandomMapTab::validateCompOnlyPlayersCnt(int compOnlyPlayersCnt)
}
}
void RandomMapTab::showAll(SDL_Surface * to)
void RandomMapTab::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
/*
// Headline
printAtMiddleLoc(CGI->generaltexth->allTexts[738], 222, 36, FONT_BIG, Colors::YELLOW, to);
printAtMiddleLoc(CGI->generaltexth->allTexts[739], 222, 56, FONT_SMALL, Colors::WHITE, to);
@ -1826,6 +1808,7 @@ void RandomMapTab::showAll(SDL_Surface * to)
// Monster strength
printAtLoc(CGI->generaltexth->allTexts[758], 68, 465, FONT_SMALL, Colors::WHITE, to);
*/
}
void RandomMapTab::updateMapInfo()
@ -1926,7 +1909,7 @@ InfoCard::InfoCard( bool Network )
if(SEL->screenType == CMenuScreen::campaignList)
{
CSelectionScreen *ss = static_cast<CSelectionScreen*>(parent);
mapDescription->addChild(new CPicture(*ss->bg, descriptionRect + Point(-393, 0)), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
mapDescription->addChild(new CPicture(ss->bg->getImage(), descriptionRect + Point(-393, 0)), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
}
else
{
@ -1953,13 +1936,13 @@ InfoCard::InfoCard( bool Network )
difficulty->block(true);
//description needs bg
mapDescription->addChild(new CPicture(*bg, descriptionRect), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
mapDescription->addChild(new CPicture(bg->getImage(), descriptionRect), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
if(network)
{
playerListBg = new CPicture("CHATPLUG.bmp", 16, 276);
chat = new CChatBox(descriptionRect);
chat->chatHistory->addChild(new CPicture(*bg, chat->chatHistory->pos - pos), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
chat->chatHistory->addChild(new CPicture(bg->getImage(), chat->chatHistory->pos - pos), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
chatOn = true;
mapDescription->disable();
@ -1974,14 +1957,14 @@ InfoCard::~InfoCard()
delete sFlags;
}
void InfoCard::showAll(SDL_Surface * to)
void InfoCard::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
//blit texts
if(SEL->screenType != CMenuScreen::campaignList)
{
printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, Colors::WHITE, to); //Allies
/* printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, Colors::WHITE, to); //Allies
printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, Colors::WHITE, to); //Enemies
printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, Colors::YELLOW, to);//"Map Diff:"
printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, Colors::YELLOW, to); //player difficulty
@ -2013,6 +1996,7 @@ void InfoCard::showAll(SDL_Surface * to)
}
}
*/
}
if(SEL->current)
@ -2028,27 +2012,27 @@ void InfoCard::showAll(SDL_Surface * to)
if (temp>20) temp=0;
std::string sss = CGI->generaltexth->victoryConditions[temp];
if (temp && SEL->current->mapHeader->victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
printAtLoc(sss, 60, 307, FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(sss, 60, 307, FONT_SMALL, Colors::WHITE, to);
temp = SEL->current->mapHeader->victoryCondition.condition;
if (temp>12) temp=11;
blitAtLoc(CGP->victory->ourImages[temp].bitmap, 24, 302, to); //victory cond descr
//* blitAtLoc(CGP->victory->ourImages[temp].bitmap, 24, 302, to); //victory cond descr
//loss conditoins
temp = SEL->current->mapHeader->lossCondition.typeOfLossCon+1;
if (temp>20) temp=0;
sss = CGI->generaltexth->lossCondtions[temp];
printAtLoc(sss, 60, 366, FONT_SMALL, Colors::WHITE, to);
//* printAtLoc(sss, 60, 366, FONT_SMALL, Colors::WHITE, to);
temp=SEL->current->mapHeader->lossCondition.typeOfLossCon;
if (temp>12) temp=3;
blitAtLoc(CGP->loss->ourImages[temp].bitmap, 24, 359, to); //loss cond
//* blitAtLoc(CGP->loss->ourImages[temp].bitmap, 24, 359, to); //loss cond
}
//difficulty
assert(SEL->current->mapHeader->difficulty <= 4);
std::string &diff = CGI->generaltexth->arraytxt[142 + SEL->current->mapHeader->difficulty];
printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::WHITE, to);
//selecting size icon
switch (SEL->current->mapHeader->width)
@ -2069,11 +2053,11 @@ void InfoCard::showAll(SDL_Surface * to)
temp=4;
break;
}
blitAtLoc(sizes->ourImages[temp].bitmap, 318, 22, to);
//* blitAtLoc(sizes->ourImages[temp].bitmap, 318, 22, to);
if(SEL->screenType == CMenuScreen::loadGame)
printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::WHITE, to);
//* if(SEL->screenType == CMenuScreen::loadGame)
//* printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::WHITE, to);
//print flags
int fx = 34 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[390]);
@ -2089,7 +2073,7 @@ void InfoCard::showAll(SDL_Surface * to)
for (auto i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++)
{
int *myx = ((i->first == playerColor || SEL->current->mapHeader->players[i->first.getNum()].team == myT) ? &fx : &ex);
blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 399, to);
//* blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 399, to);
*myx += sFlags->ourImages[i->first.getNum()].bitmap->w;
}
@ -2112,7 +2096,7 @@ void InfoCard::showAll(SDL_Surface * to)
tob="200%";
break;
}
printAtMiddleLoc(tob, 311, 472, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(tob, 311, 472, FONT_SMALL, Colors::WHITE, to);
}
//blit description
@ -2128,10 +2112,10 @@ void InfoCard::showAll(SDL_Surface * to)
}
//name
if (name.length())
printAtLoc(name, 26, 39, FONT_BIG, Colors::YELLOW, to);
else
printAtLoc("Unnamed", 26, 39, FONT_BIG, Colors::YELLOW, to);
//* if (name.length())
//* printAtLoc(name, 26, 39, FONT_BIG, Colors::YELLOW, to);
//* else
//* printAtLoc("Unnamed", 26, 39, FONT_BIG, Colors::YELLOW, to);
}
}
@ -2234,9 +2218,10 @@ OptionsTab::~OptionsTab()
}
void OptionsTab::showAll(SDL_Surface * to)
void OptionsTab::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
/*
printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, Colors::YELLOW, to);
printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 68, FONT_SMALL, 300, Colors::WHITE, to); //Select starting options, handicap, and name for each player in the game.
printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 110, FONT_SMALL, 100, Colors::YELLOW, to); //Player Name Handicap Type
@ -2246,6 +2231,7 @@ void OptionsTab::showAll(SDL_Surface * to)
printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, Colors::YELLOW, to); // Player Turn Duration
if (turnDuration)
printAtMiddleLoc(CGI->generaltexth->turnDurations[turnDuration->value], 319,559, FONT_SMALL, Colors::WHITE, to);//Turn duration value
*/
}
void OptionsTab::nextCastle( PlayerColor player, int dir )
@ -2527,7 +2513,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet
static const char *bgs[] = {"ADOPRPNL.bmp", "ADOPBPNL.bmp", "ADOPYPNL.bmp", "ADOPGPNL.bmp",
"ADOPOPNL.bmp", "ADOPPPNL.bmp", "ADOPTPNL.bmp", "ADOPSPNL.bmp"};
bg = new CPicture(BitmapHandler::loadBitmap(bgs[s.color.getNum()]), 0, 0, true);
bg = new CPicture(Gfx::CManager::getImage(bgs[s.color.getNum()]), 0, 0, true);
if(SEL->screenType == CMenuScreen::newGame)
{
btns[0] = new CAdventureMapButton(CGI->generaltexth->zelp[132], bind(&OptionsTab::nextCastle, owner, s.color, -1), 107, 5, "ADOPLFA.DEF");
@ -2568,11 +2554,11 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet
bonus = new SelectedBox(Point(271, 2), s, BONUS);
}
void OptionsTab::PlayerOptionsEntry::showAll(SDL_Surface * to)
void OptionsTab::PlayerOptionsEntry::showAll()
{
CIntObject::showAll(to);
printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, Colors::WHITE, to);
printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 39, FONT_TINY, 50, Colors::WHITE, to);
CIntObject::showAll();
//* printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 39, FONT_TINY, 50, Colors::WHITE, to);
}
void OptionsTab::PlayerOptionsEntry::update()
@ -3031,11 +3017,11 @@ CMultiMode::CMultiMode()
OBJ_CONSTRUCTION_CAPTURING_ALL;
bg = new CPicture("MUPOPUP.bmp");
bg->convertToScreenBPP(); //so we could draw without problems
blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img
//* blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img
pos = bg->center(); //center, window has size of bg graphic
bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0));//226, 472
txt = new CTextInput(Rect(19, 436, 334, 16), *bg);
//* txt = new CTextInput(Rect(19, 436, 334, 16), *bg);
txt->setTxt(settings["general"]["playerName"].String()); //Player
btns[0] = new CAdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF");
@ -3078,7 +3064,7 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
for(int i = 0; i < ARRAY_COUNT(txt); i++)
{
txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg);
//* txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg);
txt[i]->cb += boost::bind(&CHotSeatPlayers::onChange, this, _1);
}
@ -3258,14 +3244,14 @@ void CBonusSelection::goBack()
GH.popIntTotally(this);
}
void CBonusSelection::showAll(SDL_Surface * to)
void CBonusSelection::showAll()
{
blitAt(background, pos.x, pos.y, to);
CIntObject::showAll(to);
//* blitAt(background, pos.x, pos.y, to);
CIntObject::showAll();
show(to);
if (pos.h != to->h || pos.w != to->w)
CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
show();
//* if (pos.h != to->h || pos.w != to->w)
//* CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
}
void CBonusSelection::loadPositionsOfGraphics()
@ -3326,22 +3312,22 @@ void CBonusSelection::selectMap( int whichOne, bool initialSelect )
}
}
void CBonusSelection::show(SDL_Surface * to)
void CBonusSelection::show()
{
//blitAt(background, pos.x, pos.y, to);
//map name
std::string mapName = ourHeader->name;
/*
if (mapName.length())
printAtLoc(mapName, 481, 219, FONT_BIG, Colors::YELLOW, to);
else
printAtLoc("Unnamed", 481, 219, FONT_BIG, Colors::YELLOW, to);
*/
//map description
printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::YELLOW, to);
//* printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::YELLOW, to);
mapDesc->showAll(to); //showAll because CTextBox has no show()
mapDesc->showAll(); //showAll because CTextBox has no show()
//map size icon
int temp;
@ -3363,7 +3349,7 @@ void CBonusSelection::show(SDL_Surface * to)
temp=4;
break;
}
blitAtLoc(sizes->ourImages[temp].bitmap, 735, 26, to);
//* blitAtLoc(sizes->ourImages[temp].bitmap, 735, 26, to);
//flags
int fx = 496 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[390]);
@ -3373,14 +3359,14 @@ void CBonusSelection::show(SDL_Surface * to)
for (auto i = sInfo.playerInfos.cbegin(); i != sInfo.playerInfos.cend(); i++)
{
int *myx = ((i->first == playerColor || ourHeader->players[i->first.getNum()].team == myT) ? &fx : &ex);
blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, pos.x + *myx, pos.y + 405, to);
//* blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, pos.x + *myx, pos.y + 405, to);
*myx += sFlags->ourImages[i->first.getNum()].bitmap->w;
}
//difficulty
blitAtLoc(diffPics[sInfo.difficulty], 709, 455, to);
//* blitAtLoc(diffPics[sInfo.difficulty], 709, 455, to);
CIntObject::show(to);
CIntObject::show();
}
void CBonusSelection::updateBonusSelection()
@ -3566,9 +3552,7 @@ void CBonusSelection::updateBonusSelection()
if (picNumber != -1)
picName += ":" + boost::lexical_cast<std::string>(picNumber);
CAnimation * anim = new CAnimation();
anim->setCustom(picName, 0);
bonusButton->setImage(anim);
bonusButton->setImage(Gfx::CManager::getAnimation(picName));
const SDL_Color brightYellow = { 242, 226, 110, 0 };
bonusButton->borderColor = brightYellow;
bonuses->addButton(bonusButton);
@ -3704,7 +3688,7 @@ void CBonusSelection::CRegion::clickLeft( tribool down, bool previousState )
{
owner->selectMap(myNumber, false);
owner->highlightedRegion = this;
parent->showAll(screen);
parent->showAll();
}
}
@ -3718,23 +3702,23 @@ void CBonusSelection::CRegion::clickRight( tribool down, bool previousState )
}
}
void CBonusSelection::CRegion::show(SDL_Surface * to)
void CBonusSelection::CRegion::show()
{
//const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->camp->header.mapVersion].regions[myNumber];
if (!accessible)
{
//show as striped
blitAtLoc(graphics[2], 0, 0, to);
//* blitAtLoc(graphics[2], 0, 0, to);
}
else if (this == owner->highlightedRegion)
{
//show as selected
blitAtLoc(graphics[1], 0, 0, to);
//* blitAtLoc(graphics[1], 0, 0, to);
}
else
{
//show as not selected selected
blitAtLoc(graphics[0], 0, 0, to);
//* blitAtLoc(graphics[0], 0, 0, to);
}
}
@ -3989,12 +3973,12 @@ void CCampaignScreen::CCampaignButton::hover(bool on)
hoverLabel->setTxt(" ");
}
void CCampaignScreen::CCampaignButton::show(SDL_Surface * to)
void CCampaignScreen::CCampaignButton::show()
{
if (status == CCampaignScreen::DISABLED)
return;
CIntObject::show(to);
CIntObject::show();
// Play the campaign button video when the mouse cursor is placed over the button
if (hovered)
@ -4002,7 +3986,7 @@ void CCampaignScreen::CCampaignButton::show(SDL_Surface * to)
if (CCS->videoh->fname != video)
CCS->videoh->open(video);
CCS->videoh->update(pos.x, pos.y, to, true, false); // plays sequentially frame by frame, starts at the beginning when the video is over
CCS->videoh->update(pos.x, pos.y, true, false); // plays sequentially frame by frame, starts at the beginning when the video is over
}
else if (CCS->videoh->fname == video) // When you got out of the bounds of the button then close the video
{
@ -4047,11 +4031,11 @@ CCampaignScreen::CCampaignScreen(const JsonNode &config)
campButtons.push_back(new CCampaignButton(node));
}
void CCampaignScreen::showAll(SDL_Surface *to)
void CCampaignScreen::showAll()
{
CIntObject::showAll(to);
if (pos.h != to->h || pos.w != to->w)
CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
CIntObject::showAll();
//* if (pos.h != to->h || pos.w != to->w)
//* CMessage::drawBorder(PlayerColor(1), to, pos.w+28, pos.h+30, pos.x-14, pos.y-15);
}
void CGPreGame::showLoadingScreen(boost::function<void()> loader)
@ -4082,12 +4066,12 @@ CLoadingScreen::~CLoadingScreen()
loadingThread.join();
}
void CLoadingScreen::showAll(SDL_Surface *to)
void CLoadingScreen::showAll()
{
Rect rect(0,0,to->w, to->h);
SDL_FillRect(to, &rect, 0);
//* Rect rect(0,0,to->w, to->h);
//* SDL_FillRect(to, &rect, 0);
CWindowObject::showAll(to);
CWindowObject::showAll();
}
CPrologEpilogVideo::CPrologEpilogVideo( CCampaignScenario::SScenarioPrologEpilog _spe, std::function<void()> callback )
@ -4107,9 +4091,9 @@ CPrologEpilogVideo::CPrologEpilogVideo( CCampaignScenario::SScenarioPrologEpilog
//SDL_SaveBMP(txt, "txtsrfc.bmp");
}
void CPrologEpilogVideo::show( SDL_Surface * to )
void CPrologEpilogVideo::show()
{
memset(to->pixels, 0, to->h*to->pitch); //make bg black
/* memset(to->pixels, 0, to->h*to->pitch); //make bg black
CCS->videoh->update(pos.x, pos.y, to, true, false);
SDL_Rect tmp, our;
our = Rect(0, to->h-100, to->w, 100);
@ -4125,6 +4109,7 @@ void CPrologEpilogVideo::show( SDL_Surface * to )
curTxtH = std::max(curTxtH - 1, to->h - txt->h);
decrementDelayCounter = 0;
}
*/
}
void CPrologEpilogVideo::clickLeft( tribool down, bool previousState )

View File

@ -69,8 +69,8 @@ public:
};
CMenuScreen(const JsonNode& configNode);
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll();
void show();
void activate();
void deactivate();
@ -93,8 +93,8 @@ class CreditsScreen : public CIntObject
public:
CreditsScreen();
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
@ -130,7 +130,7 @@ public:
CDefHandler *sizes, *sFlags;
void changeSelection(const CMapInfo *to);
void showAll(SDL_Surface * to);
void showAll();
void clickRight(tribool down, bool previousState);
void showTeamsPopup();
void toggleChat();
@ -177,7 +177,7 @@ public:
void selectFName(std::string fname);
const CMapInfo * getSelectedMapInfo() const;
void showAll(SDL_Surface * to);
void showAll();
void clickLeft(tribool down, bool previousState);
void keyPressed(const SDL_KeyboardEvent & key);
void onDoubleClick();
@ -247,7 +247,7 @@ public:
PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
void selectButtons(); //hides unavailable buttons
void showAll(SDL_Surface * to);
void showAll();
void update();
};
@ -275,7 +275,7 @@ public:
void recreate();
OptionsTab();
~OptionsTab();
void showAll(SDL_Surface * to);
void showAll();
int nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir );
@ -298,7 +298,7 @@ public:
*
* @param to where the graphics should be inserted
*/
void showAll(SDL_Surface * to);
void showAll();
/**
* Updates the map info object and fires the associated callback method.
@ -483,7 +483,7 @@ public:
void postRequest(ui8 what, ui8 dir) override;
void postChatMessage(const std::string &txt) override;
void propagateNames();
void showAll(SDL_Surface *to);
void showAll();
};
/// Save game screen
@ -551,7 +551,7 @@ public:
CPrologEpilogVideo(CCampaignScenario::SScenarioPrologEpilog _spe, std::function<void()> callback);
void clickLeft(tribool down, bool previousState);
void show(SDL_Surface * to);
void show();
};
/// Campaign screen where you can choose one out of three starting bonuses
@ -594,7 +594,7 @@ class CBonusSelection : public CIntObject
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void show(SDL_Surface * to);
void show();
};
std::vector<CRegion *> regions;
@ -626,8 +626,8 @@ public:
CBonusSelection(shared_ptr<CCampaignState> _ourCampaign);
~CBonusSelection();
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll();
void show();
void goBack();
void startMap();
@ -659,7 +659,7 @@ private:
public:
CCampaignButton(const JsonNode &config );
void show(SDL_Surface * to);
void show();
};
CAdventureMapButton *back;
@ -672,7 +672,7 @@ public:
enum CampaignSet {ROE, AB, SOD, WOG};
CCampaignScreen(const JsonNode &config);
void showAll(SDL_Surface *to);
void showAll();
};
/// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
@ -710,7 +710,7 @@ public:
CLoadingScreen(boost::function<void()> loader);
~CLoadingScreen();
void showAll(SDL_Surface *to);
void showAll();
};
extern ISelectionScreenInfo *SEL;

View File

@ -40,10 +40,10 @@ void CQuestLabel::clickLeft(tribool down, bool previousState)
callback();
}
void CQuestLabel::showAll(SDL_Surface * to)
void CQuestLabel::showAll()
{
if (active)
CBoundedLabel::showAll (to);
CBoundedLabel::showAll ();
}
CQuestIcon::CQuestIcon (const std::string &defname, int index, int x, int y) :
@ -58,10 +58,10 @@ void CQuestIcon::clickLeft(tribool down, bool previousState)
callback();
}
void CQuestIcon::showAll(SDL_Surface * to)
void CQuestIcon::showAll()
{
CSDL_Ext::CClipRectGuard guard(to, parent->pos);
CAnimImage::showAll(to);
//* CSDL_Ext::CClipRectGuard guard(to, parent->pos);
CAnimImage::showAll();
}
CQuestMinimap::CQuestMinimap (const Rect & position) :
@ -109,11 +109,11 @@ void CQuestMinimap::iconClicked()
moveAdvMapSelection();
}
void CQuestMinimap::showAll(SDL_Surface * to)
void CQuestMinimap::showAll()
{
CIntObject::showAll(to); // blitting IntObject directly to hide radar
BOOST_FOREACH (auto pic, icons)
pic->showAll(to);
//* CIntObject::showAll(to); // blitting IntObject directly to hide radar
//* BOOST_FOREACH (auto pic, icons)
//* pic->showAll(to);
}
CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
@ -151,20 +151,20 @@ void CQuestLog::init()
recreateQuestList (0);
}
void CQuestLog::showAll(SDL_Surface * to)
void CQuestLog::showAll()
{
CIntObject::showAll (to);
CIntObject::showAll();
BOOST_FOREACH (auto label, labels)
{
label->show(to); //shows only if active
label->show(); //shows only if active
}
if (labels.size() && labels[questIndex]->active)
{
CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
//* CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
}
description->show(to);
description->show();
minimap->update();
minimap->show(to);
minimap->show();
}
void CQuestLog::recreateQuestList (int newpos)

View File

@ -41,7 +41,7 @@ public:
CQuestLabel (int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE, const std::string &Text = "")
: CBoundedLabel (x, y, FONT_SMALL, TOPLEFT, Colors::WHITE, Text){};
void clickLeft(tribool down, bool previousState);
void showAll(SDL_Surface * to);
void showAll();
};
class CQuestIcon : public CAnimImage
@ -52,7 +52,7 @@ public:
CQuestIcon (const std::string &defname, int index, int x=0, int y=0);
void clickLeft(tribool down, bool previousState);
void showAll(SDL_Surface * to);
void showAll();
};
class CQuestMinimap : public CMinimap
@ -73,7 +73,7 @@ public:
void setLevel(int level);
void addQuestMarks (const QuestInfo * q);
void showAll(SDL_Surface * to);
void showAll();
};
class CQuestLog : public CWindowObject
@ -100,5 +100,5 @@ public:
void printDescription (int which){};
void sliderMoved (int newpos);
void recreateQuestList (int pos);
void showAll (SDL_Surface * to);
void showAll();
};

View File

@ -314,43 +314,43 @@ void CSpellWindow::fRcornerb()
GH.breakEventHandling();
}
void CSpellWindow::showAll(SDL_Surface * to)
void CSpellWindow::showAll()
{
CWindowObject::showAll(to);
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
CWindowObject::showAll();
//* blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
std::ostringstream mana;
mana<<myHero->mana;
printAtMiddleLoc(mana.str(), 435, 426, FONT_SMALL, Colors::YELLOW, to);
//* printAtMiddleLoc(mana.str(), 435, 426, FONT_SMALL, Colors::YELLOW, to);
statusBar->showAll(to);
statusBar->showAll();
//printing school images
if(selectedTab!=4 && currentPage == 0)
{
blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
//* blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
}
//printing corners
if(currentPage!=0)
{
blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
//* blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
}
if((currentPage+1) < (pagesWithinCurrentTab()) )
{
blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
//* blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
}
//printing spell info
for(int b=0; b<12; ++b)
{
spellAreas[b]->showAll(to);
//* spellAreas[b]->showAll(to);
}
}
void CSpellWindow::show(SDL_Surface * to)
void CSpellWindow::show()
{
statusBar->show(to);
statusBar->show();
}
class SpellbookSpellSorter
@ -766,11 +766,11 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
}
if (availableTowns.empty())
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
else
GH.pushInt (new CObjectListWindow(availableTowns,
new CPicture(graphics->spellscr->ourImages[spell].bitmap, 0, 0, false),
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
boost::bind (&CSpellWindow::teleportTo, owner, _1, h)));
//* else
//* GH.pushInt (new CObjectListWindow(availableTowns,
//* new CPicture(graphics->spellscr->ourImages[spell].bitmap, 0, 0, false),
//* CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
//* boost::bind (&CSpellWindow::teleportTo, owner, _1, h)));
}
return;
}
@ -823,15 +823,15 @@ void CSpellWindow::SpellArea::hover(bool on)
}
}
void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
void CSpellWindow::SpellArea::showAll()
{
if(mySpell < 0)
return;
const CSpell * spell = mySpell.toSpell();
blitAt(owner->spells->ourImages[mySpell].bitmap, pos.x, pos.y, to);
blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
//* blitAt(owner->spells->ourImages[mySpell].bitmap, pos.x, pos.y, to);
//* blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
SDL_Color firstLineColor, secondLineColor;
if(spellCost > owner->myHero->mana) //hero cannot cast this spell
@ -846,13 +846,13 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
secondLineColor = Colors::WHITE;
}
//printing spell's name
printAtMiddleLoc(spell->name, 39, 70, FONT_TINY, firstLineColor, to);
//* printAtMiddleLoc(spell->name, 39, 70, FONT_TINY, firstLineColor, to);
//printing lvl
printAtMiddleLoc(CGI->generaltexth->allTexts[171 + spell->level], 39, 82, FONT_TINY, secondLineColor, to);
//* printAtMiddleLoc(CGI->generaltexth->allTexts[171 + spell->level], 39, 82, FONT_TINY, secondLineColor, to);
//printing cost
std::ostringstream ss;
ss << CGI->generaltexth->allTexts[387] << ": " << spellCost;
printAtMiddleLoc(ss.str(), 39, 94, FONT_TINY, secondLineColor, to);
//* printAtMiddleLoc(ss.str(), 39, 94, FONT_TINY, secondLineColor, to);
}
void CSpellWindow::SpellArea::setSpell(SpellID spellID)

View File

@ -58,7 +58,7 @@ private:
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void hover(bool on);
void showAll(SDL_Surface * to);
void showAll();
};
SDL_Surface * leftCorner, * rightCorner;
@ -108,8 +108,8 @@ public:
void keyPressed(const SDL_KeyboardEvent & key);
void activate();
void deactivate();
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll();
void show();
void teleportTo(int town, const CGHeroInstance * hero);
};

View File

@ -167,41 +167,16 @@ checkErrorAndClean:
throw std::runtime_error("BIK failed opening video!");
}
void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update )
void CBIKHandler::show( int x, int y, bool update )
{
const int w = hBink->width,
h = hBink->height,
Bpp = dst->format->BytesPerPixel;
int mode = -1;
//screen color depth might have changed... (eg. because F4)
if(bufferSize != w * h * Bpp)
{
freeBuffer();
allocBuffer(Bpp);
}
switch(Bpp)
{
case 2:
mode = 3; //565, mode 2 is 555 probably
break;
case 3:
mode = 0;
break;
case 4:
mode = 1;
break;
default:
return; //not supported screen depth
}
h = hBink->height;
binkDoFrame(hBink);
binkCopyToBuffer(hBink, buffer, w*Bpp, h, 0, 0, mode);
blitBuffer(buffer, x, y, w, h, dst);
if(update)
SDL_UpdateRect(dst, x, y, w, h);
binkCopyToBuffer(hBink, buffer, w*4, h, 0, 0, 1);
//blitBuffer(buffer, x, y, w, h, dst);
//if(update)
// SDL_UpdateRect(dst, x, y, w, h);
}
bool CBIKHandler::nextFrame()
@ -237,17 +212,17 @@ int CBIKHandler::frameCount() const
return hBink->frameCount;
}
void CBIKHandler::redraw( int x, int y, SDL_Surface *dst, bool update )
void CBIKHandler::redraw( int x, int y, bool update)
{
int w = hBink->width, h = hBink->height;
blitBuffer(buffer, x, y, w, h, dst);
if(update)
SDL_UpdateRect(dst, x, y, w, h);
//blitBuffer(buffer, x, y, w, h, dst);
//if(update)
// SDL_UpdateRect(dst, x, y, w, h);
}
void CBIKHandler::allocBuffer(int Bpp)
{
if(!Bpp) Bpp = screen->format->BytesPerPixel;
//* if(!Bpp) Bpp = screen->format->BytesPerPixel;
bufferSize = hBink->width * hBink->height * Bpp;
buffer = new char[bufferSize];
@ -315,7 +290,7 @@ bool CSmackPlayer::open( std::string name )
return true;
}
void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
void CSmackPlayer::show( int x, int y, bool update)
{
int w = data->width;
int stripe = (-w*2) & (~3);
@ -323,7 +298,7 @@ void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
//put frame to the buffer
ptrSmackToBuffer(data, 0, 0, stripe, w, buf, 0x80000000);
ptrSmackDoFrame(data);
redraw(x, y, dst, update);
redraw(x, y, update);
}
int CSmackPlayer::curFrame() const
@ -336,23 +311,14 @@ int CSmackPlayer::frameCount() const
return data->frameCount;
}
void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
void CSmackPlayer::redraw( int x, int y, bool update )
{
int w = std::min<int>(data->width, dst->w - x), h = std::min<int>(data->height, dst->h - y);
/* Lock the screen for direct access to the pixels */
if ( SDL_MUSTLOCK(dst) )
{
if ( SDL_LockSurface(dst) < 0 )
{
fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
return;
}
}
//int w = std::min<int>(data->width, dst->w - x), h = std::min<int>(data->height, dst->h - y);
int w = data->width, h = data->height;
// draw the frame
Uint16* addr = (Uint16*) (buffer+w*(h-1)*2-2);
if(dst->format->BytesPerPixel >= 3)
{
/*
for( int j=0; j<h-1; j++) // why -1 ?
{
for ( int i=w-1; i>=0; i--)
@ -367,32 +333,9 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
addr--;
}
}
}
else if(dst->format->BytesPerPixel == 2)
{
for( int j=0; j<h-1; j++) // why -1 ?
{
for ( int i=w-1; i>=0; i--)
{
//convert rgb 555 to 565
Uint16 pixel = *addr;
Uint16 *p = (Uint16 *)((Uint8 *)dst->pixels + (j+y) * dst->pitch + (i + x) * dst->format->BytesPerPixel);
*p = (pixel & 0x1F)
+ ((pixel & 0x3e0) << 1)
+ ((pixel & 0x7c00) << 1);
addr--;
}
}
}
if ( SDL_MUSTLOCK(dst) )
{
SDL_UnlockSurface(dst);
}
if(update)
SDL_UpdateRect(dst, x, y, w, h);
*/
//if(update)
// SDL_UpdateRect(dst, x, y, w, h);
}
CVideoPlayer::CVideoPlayer()
@ -472,10 +415,10 @@ bool CVideoPlayer::nextFrame()
return false;
}
void CVideoPlayer::show(int x, int y, SDL_Surface *dst, bool update)
void CVideoPlayer::show(int x, int y, bool update)
{
if(current)
current->show(x, y, dst, update);
current->show(x, y, update);
}
bool CVideoPlayer::wait()
@ -502,17 +445,17 @@ int CVideoPlayer::frameCount() const
return -1;
}
bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey)
bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, bool stopOnKey)
{
if(!open(name))
return false;
bool ret = playVideo(x, y, dst, stopOnKey);
bool ret = playVideo(x, y, stopOnKey);
close();
return ret;
}
void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, bool update )
void CVideoPlayer::update( int x, int y, bool forceRedraw, bool update )
{
if(!current)
return;
@ -529,25 +472,23 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
first = false;
}
if(!w)
{
show(x,y,dst,update);
show(x, y, update);
}
else if (forceRedraw)
{
redraw(x, y, dst, update);
redraw(x, y, update);
}
}
void CVideoPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
void CVideoPlayer::redraw( int x, int y, bool update)
{
if(current)
current->redraw(x, y, dst, update);
current->redraw(x, y, update);
}
bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey)
{
if(!current)
return false;
@ -560,7 +501,7 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
if(!wait())
{
show(x, y, dst);
show(x, y);
nextFrame();
frame++;
}

View File

@ -9,8 +9,8 @@ public:
virtual bool open(std::string name)=0; //true - succes
virtual void close()=0;
virtual bool nextFrame()=0;
virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
virtual void show(int x, int y, bool update = true)=0;
virtual void redraw(int x, int y, bool update = true)=0; //reblits buffer
virtual bool wait()=0;
virtual int curFrame() const =0;
virtual int frameCount() const =0;
@ -22,8 +22,8 @@ class IMainVideoPlayer : public IVideoPlayer
public:
std::string fname; //name of current video file (empty if idle)
virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true){}
virtual bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false)
virtual void update(int x, int y, bool forceRedraw, bool update = true){}
virtual bool openAndPlayVideo(std::string name, int x, int y, bool stopOnKey = false)
{
return false;
}
@ -34,8 +34,8 @@ class CEmptyVideoPlayer : public IMainVideoPlayer
public:
virtual int curFrame() const {return -1;};
virtual int frameCount() const {return -1;};
virtual void redraw( int x, int y, SDL_Surface *dst, bool update = true ) {};
virtual void show( int x, int y, SDL_Surface *dst, bool update = true ) {};
virtual void redraw( int x, int y, bool update = true ) {};
virtual void show( int x, int y, bool update = true ) {};
virtual bool nextFrame() {return false;};
virtual void close() {};
virtual bool wait() {return false;};
@ -119,8 +119,8 @@ public:
bool open(std::string name);
void close();
bool nextFrame();
void show(int x, int y, SDL_Surface *dst, bool update = true);
void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
void show(int x, int y, bool update = true);
void redraw(int x, int y, bool update = true); //reblits buffer
bool wait();
int curFrame() const;
int frameCount() const;
@ -175,8 +175,8 @@ public:
bool open(std::string name);
void close();
bool nextFrame();
void show(int x, int y, SDL_Surface *dst, bool update = true);
void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
void show(int x, int y, bool update = true);
void redraw(int x, int y, bool update = true); //reblits buffer
bool wait();
int curFrame() const;
int frameCount() const;
@ -202,15 +202,15 @@ public:
bool open(std::string name);
void close();
bool nextFrame(); //move animation to the next frame
void show(int x, int y, SDL_Surface *dst, bool update = true); //blit current frame
void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
void show(int x, int y, bool update = true); //blit current frame
void redraw(int x, int y, bool update = true); //reblits buffer
void update(int x, int y, bool forceRedraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
bool wait(); //true if we should wait before displaying next frame (for keeping FPS)
int curFrame() const; //current frame number <1, framecount>
int frameCount() const;
bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false); //opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
bool playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey = false); //plays whole opened video; returns: true when whole video has been shown, false when it has been interrupted
bool openAndPlayVideo(std::string name, int x, int y, bool stopOnKey = false); //opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
bool playVideo(int x, int y, bool stopOnKey = false); //plays whole opened video; returns: true when whole video has been shown, false when it has been interrupted
};
#else

View File

@ -701,9 +701,9 @@ void CInfoWindow::close()
LOCPLINT->showingDialog->setn(false);
}
void CInfoWindow::show(SDL_Surface * to)
void CInfoWindow::show()
{
CIntObject::show(to);
CIntObject::show();
}
CInfoWindow::~CInfoWindow()
@ -715,10 +715,10 @@ CInfoWindow::~CInfoWindow()
}
}
void CInfoWindow::showAll(SDL_Surface * to)
void CInfoWindow::showAll()
{
CSimpleWindow::show(to);
CIntObject::showAll(to);
CSimpleWindow::show();
CIntObject::showAll();
}
void CInfoWindow::showYesNoDialog(const std::string & text, const std::vector<CComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps, PlayerColor player)
@ -1056,12 +1056,12 @@ void CSelectableComponent::select(bool on)
}
}
void CSelectableComponent::showAll(SDL_Surface * to)
void CSelectableComponent::showAll()
{
CComponent::showAll(to);
CComponent::showAll();
if(selected)
{
CSDL_Ext::drawBorder(to, Rect::around(image->pos), int3(239,215,123));
//* CSDL_Ext::drawBorder(to, Rect::around(image->pos), int3(239,215,123));
}
}
@ -1364,13 +1364,13 @@ void CRecruitmentWindow::CCreatureCard::clickRight(tribool down, bool previousSt
GH.pushInt(createCreWindow(creature->idNumber, CCreatureWindow::OTHER, 0));
}
void CRecruitmentWindow::CCreatureCard::showAll(SDL_Surface * to)
void CRecruitmentWindow::CCreatureCard::showAll()
{
CIntObject::showAll(to);
if (selected)
drawBorder(to, pos, int3(248, 0, 0));
else
drawBorder(to, pos, int3(232, 212, 120));
CIntObject::showAll();
//* if (selected)
//* drawBorder(to, pos, int3(248, 0, 0));
//* else
//* drawBorder(to, pos, int3(232, 212, 120));
}
CRecruitmentWindow::CCostBox::CCostBox(Rect position, std::string title)
@ -1492,10 +1492,10 @@ void CRecruitmentWindow::buy()
close();
}
void CRecruitmentWindow::showAll(SDL_Surface * to)
void CRecruitmentWindow::showAll()
{
CWindowObject::showAll(to);
CWindowObject::showAll();
/*
// recruit\total values
drawBorder(to, pos.x + 172, pos.y + 222, 67, 42, int3(239,215,123));
drawBorder(to, pos.x + 246, pos.y + 222, 67, 42, int3(239,215,123));
@ -1508,6 +1508,7 @@ void CRecruitmentWindow::showAll(SDL_Surface * to)
drawBorder(to, pos.x + 133, pos.y + 312, 66, 34, int3(173,142,66));
drawBorder(to, pos.x + 211, pos.y + 312, 66, 34, int3(173,142,66));
drawBorder(to, pos.x + 289, pos.y + 312, 66, 34, int3(173,142,66));
*/
}
CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(CreatureID,int)> &Recruit, int y_offset):
@ -1521,7 +1522,7 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, co
moveBy(Point(0, y_offset));
OBJ_CONSTRUCTION_CAPTURING_ALL;
new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
new CGStatusBar(new CPicture(background->getImage(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
slider = new CSlider(176,279,135,0,0,0,0,true);
slider->moved = boost::bind(&CRecruitmentWindow::sliderMoved,this, _1);
@ -2028,7 +2029,7 @@ int CTradeWindow::CTradeableItem::getIndex()
}
}
void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
void CTradeWindow::CTradeableItem::showAll()
{
Point posToBitmap;
Point posToSubCenter;
@ -2062,10 +2063,10 @@ void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
if (image)
{
image->moveTo(pos.topLeft() + posToBitmap);
CIntObject::showAll(to);
CIntObject::showAll();
}
printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, Colors::WHITE, to);
}
void CTradeWindow::CTradeableItem::clickLeft(tribool down, bool previousState)
@ -2119,7 +2120,7 @@ void CTradeWindow::CTradeableItem::clickLeft(tribool down, bool previousState)
}
}
void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to)
void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::string &customSub)
{
Rect oldPos = pos;
std::string oldSub = subtitle;
@ -2127,7 +2128,7 @@ void CTradeWindow::CTradeableItem::showAllAt(const Point &dstPos, const std::str
moveTo(dstPos);
subtitle = customSub;
showAll(to);
showAll();
downSelection = false;
moveTo(oldPos.topLeft());
@ -2457,10 +2458,10 @@ void CTradeWindow::initSubs(bool Left)
}
}
void CTradeWindow::showAll(SDL_Surface * to)
void CTradeWindow::showAll()
{
CWindowObject::showAll(to);
CWindowObject::showAll();
/*
if(hRight)
CSDL_Ext::drawBorder(to,hRight->pos.x-1,hRight->pos.y-1,hRight->pos.w+2,hRight->pos.h+2,int3(255,231,148));
if(hLeft && hLeft->type != ARTIFACT_INSTANCE)
@ -2471,6 +2472,7 @@ void CTradeWindow::showAll(SDL_Surface * to)
hLeft->showAllAt(pos.topLeft() + selectionOffset(true), selectionSubtitle(true), to);
hRight->showAllAt(pos.topLeft() + selectionOffset(false), selectionSubtitle(false), to);
}
*/
}
void CTradeWindow::removeItems(const std::set<CTradeableItem *> &toRemove)
@ -2559,7 +2561,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan
madeTransaction = false;
bool sliderNeeded = true;
new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
std::string title;
@ -3050,7 +3052,7 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
//Total experience on the Altar
new CTextBox(CGI->generaltexth->allTexts[476], Rect(15, 495, 125, 40), 0, FONT_SMALL, CENTER, Colors::YELLOW);
new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
ok = new CAdventureMapButton(CGI->generaltexth->zelp[568],boost::bind(&CGuiHandler::popIntTotally,&GH,this),516,520,"IOK6432.DEF",SDLK_RETURN);
ok->assignedKeys.insert(SDLK_ESCAPE);
@ -3340,17 +3342,17 @@ void CAltarWindow::artifactPicked()
redraw();
}
void CAltarWindow::showAll(SDL_Surface * to)
void CAltarWindow::showAll()
{
CTradeWindow::showAll(to);
CTradeWindow::showAll();
if(mode == EMarketMode::ARTIFACT_EXP && arts && arts->commonInfo->src.art)
{
artIcon->setFrame(arts->commonInfo->src.art->artType->iconIndex);
artIcon->showAll(to);
artIcon->showAll();
int dmp, val;
market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, EMarketMode::ARTIFACT_EXP);
printAtMiddleLoc(boost::lexical_cast<std::string>(val), 304, 498, FONT_SMALL, Colors::WHITE, to);
//* printAtMiddleLoc(boost::lexical_cast<std::string>(val), 304, 498, FONT_SMALL, Colors::WHITE, to);
}
}
@ -3667,7 +3669,7 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj):
new CLabel(320, 328, FONT_SMALL, CENTER, Colors::WHITE, "2500");
new CTextBox(LOCPLINT->cb->getTavernGossip(tavernObj), Rect(32, 190, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE);
new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
cancel = new CAdventureMapButton(CGI->generaltexth->tavernInfo[7],"", boost::bind(&CTavernWindow::close, this), 310, 428, "ICANCEL.DEF", SDLK_ESCAPE);
recruit = new CAdventureMapButton("", "", boost::bind(&CTavernWindow::recruitb, this), 272, 355, "TPTAV01.DEF", SDLK_RETURN);
thiefGuild = new CAdventureMapButton(CGI->generaltexth->tavernInfo[5],"", boost::bind(&CTavernWindow::thievesguildb, this), 22, 428, "TPTAV02.DEF", SDLK_t);
@ -3717,9 +3719,9 @@ CTavernWindow::~CTavernWindow()
void CTavernWindow::show(SDL_Surface * to)
{
CWindowObject::show(to);
//* CWindowObject::show(to);
CCS->videoh->update(pos.x+70, pos.y+56, to, true, false);
CCS->videoh->update(pos.x+70, pos.y+56, true, false);
if(selected >= 0)
{
HeroPortrait *sel = selected ? h2 : h1;
@ -3735,7 +3737,7 @@ void CTavernWindow::show(SDL_Surface * to)
}
printAtMiddleWBLoc(sel->descr, 146, 395, FONT_SMALL, 200, Colors::WHITE, to);
CSDL_Ext::drawBorder(to,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123));
//* CSDL_Ext::drawBorder(to,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123));
}
}
@ -4010,7 +4012,7 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
garr = new CGarrisonInt(92, 127, 4, Point(0,96), background->bg, Point(93,127), up, down, removableUnits);
//* garr = new CGarrisonInt(92, 127, 4, Point(0,96), background->bg, Point(93,127), up, down, removableUnits);
{
CAdventureMapButton *split = new CAdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),88,314,"IDV6432.DEF");
removeChild(split);
@ -4332,11 +4334,11 @@ void CArtPlace::deselect ()
ourOwner->safeRedraw();
}
void CArtPlace::showAll(SDL_Surface * to)
void CArtPlace::showAll()
{
if (ourArt && !picked && ourArt == ourOwner->curHero->getArt(slotID, false)) //last condition is needed for disassembling -> artifact may be gone, but we don't know yet TODO: real, nice solution
{
CIntObject::showAll(to);
CIntObject::showAll();
}
if(marked && active)
@ -4344,15 +4346,15 @@ void CArtPlace::showAll(SDL_Surface * to)
// Draw vertical bars.
for (int i = 0; i < pos.h; ++i)
{
CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x, pos.y + i, 240, 220, 120);
CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + pos.w - 1, pos.y + i, 240, 220, 120);
//* CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x, pos.y + i, 240, 220, 120);
//* CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + pos.w - 1, pos.y + i, 240, 220, 120);
}
// Draw horizontal bars.
for (int i = 0; i < pos.w; ++i)
{
CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + i, pos.y, 240, 220, 120);
CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + i, pos.y + pos.h - 1, 240, 220, 120);
//* CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + i, pos.y, 240, 220, 120);
//* CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x + i, pos.y + pos.h - 1, 240, 220, 120);
}
}
}
@ -5162,10 +5164,10 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2)
questlogButton[1] = new CAdventureMapButton(CGI->generaltexth->heroscrn[0], "", boost::bind(&CExchangeWindow::questlog,this, 1), 740, 44, "hsbtns4.def");
Rect barRect(5, 578, 725, 18);
ourBar = new CGStatusBar(new CPicture(*background, barRect, 5, 578, false));
//* ourBar = new CGStatusBar(new CPicture(*background, barRect, 5, 578, false));
//garrison interface
garr = new CGarrisonInt(69, 131, 4, Point(418,0), *background, Point(69,131), heroInst[0],heroInst[1], true, true);
//* garr = new CGarrisonInt(69, 131, 4, Point(418,0), *background, Point(69,131), heroInst[0],heroInst[1], true, true);
garr->addSplitBtn(new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick, garr), 10, 132, "TSBTNS.DEF"));
garr->addSplitBtn(new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick, garr), 740, 132, "TSBTNS.DEF"));
}
@ -5213,7 +5215,7 @@ CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int b
}
}
statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
title = new CLabel(164, 27, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[13]);
costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->jktexts[14]);
@ -5256,20 +5258,20 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
}
}
void CPuzzleWindow::showAll(SDL_Surface * to)
void CPuzzleWindow::showAll()
{
int3 moveInt = int3(8, 9, 0);
Rect mapRect = genRect(544, 591, pos.x + 8, pos.y + 7);
/*
CGI->mh->terrainRect
(grailPos - moveInt, adventureInt->anim,
&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
to, &mapRect, 0, 0, true, moveInt);
CWindowObject::showAll(to);
*/
CWindowObject::showAll();
}
void CPuzzleWindow::show(SDL_Surface * to)
void CPuzzleWindow::show()
{
static int animSpeed = 2;
@ -5287,7 +5289,7 @@ void CPuzzleWindow::show(SDL_Surface * to)
piece->setAlpha(currentAlpha);
currentAlpha -= animSpeed;
}
CWindowObject::show(to);
CWindowObject::show();
}
void CTransformerWindow::CItem::move()
@ -5304,7 +5306,7 @@ void CTransformerWindow::CItem::clickLeft(tribool down, bool previousState)
if(previousState && (!down))
{
move();
parent->showAll(screen2);
parent->showAll();
}
}
@ -5340,7 +5342,7 @@ void CTransformerWindow::addAll()
for (int i=0; i<items.size(); i++)
if (items[i]->left)
items[i]->move();
showAll(screen2);
showAll();
}
void CTransformerWindow::updateGarrisons()
@ -5369,7 +5371,7 @@ CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTow
all = new CAdventureMapButton(CGI->generaltexth->zelp[590],boost::bind(&CTransformerWindow::addAll,this), 146,416,"ALTARMY.DEF",SDLK_a);
convert= new CAdventureMapButton(CGI->generaltexth->zelp[591],boost::bind(&CTransformerWindow::makeDeal,this), 269,416,"ALTSACR.DEF",SDLK_RETURN);
cancel = new CAdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CTransformerWindow::close, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE);
bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
new CLabel(153, 29,FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[485]);//holding area
new CLabel(153+295, 29, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[486]);//transformer
@ -5417,7 +5419,7 @@ int CUniversityWindow::CItem::state()
return 2;
}
void CUniversityWindow::CItem::showAll(SDL_Surface * to)
void CUniversityWindow::CItem::showAll()
{
CPicture * bar;
switch (state())
@ -5433,12 +5435,12 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to)
}
assert(bar);
blitAtLoc(bar->bg, -28, -22, to);
blitAtLoc(bar->bg, -28, 48, to);
printAtMiddleLoc (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, Colors::WHITE,to);//Name
printAtMiddleLoc (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, Colors::WHITE,to);//Level(always basic)
//* blitAtLoc(bar->bg, -28, -22, to);
//* blitAtLoc(bar->bg, -28, 48, to);
//* printAtMiddleLoc (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, Colors::WHITE,to);//Name
//* printAtMiddleLoc (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, Colors::WHITE,to);//Level(always basic)
CAnimImage::showAll(to);
CAnimImage::showAll();
}
CUniversityWindow::CItem::CItem(CUniversityWindow * _parent, int _ID, int X, int Y):
@ -5489,7 +5491,7 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket
cancel = new CAdventureMapButton(CGI->generaltexth->zelp[632],
boost::bind(&CUniversityWindow::close, this),200,313,"IOKAY.DEF",SDLK_RETURN);
bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
}
CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available ):
@ -5526,7 +5528,7 @@ CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bo
cancel = new CAdventureMapButton(CGI->generaltexth->zelp[631],boost::bind(&CUnivConfirmWindow::close, this),
252,299,"ICANCEL.DEF",SDLK_ESCAPE);
bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
}
void CUnivConfirmWindow::makeDeal(int skill)
@ -5567,9 +5569,9 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn
upgradeAll = new CAdventureMapButton(CGI->generaltexth->allTexts[432],"",boost::bind(&CHillFortWindow::makeDeal, this, SlotID(slotsCount)),
30, 231, "", SDLK_0, &files);
quit = new CAdventureMapButton("","",boost::bind(&CHillFortWindow::close, this), 294, 275, "IOKAY.DEF", SDLK_RETURN);
bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
//* bar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
garr = new CGarrisonInt(108, 60, 18, Point(),background->bg,Point(108,60),hero,NULL);
//* garr = new CGarrisonInt(108, 60, 18, Point(),background->bg,Point(108,60),hero,NULL);
updateGarrisons();
}
@ -5632,9 +5634,9 @@ void CHillFortWindow::makeDeal(SlotID slot)
}
}
void CHillFortWindow::showAll (SDL_Surface *to)
void CHillFortWindow::showAll()
{
CWindowObject::showAll(to);
CWindowObject::showAll();
for ( int i=0; i<slotsCount; i++)
{
@ -5648,15 +5650,15 @@ void CHillFortWindow::showAll (SDL_Surface *to)
int val = costs[i][j];
if(!val) continue;
blitAtLoc(resources->ourImages[j].bitmap, 104+76*i, curY, to);
printToLoc(boost::lexical_cast<std::string>(val), 168+76*i, curY+16, FONT_SMALL, Colors::WHITE, to);
//* blitAtLoc(resources->ourImages[j].bitmap, 104+76*i, curY, to);
//* printToLoc(boost::lexical_cast<std::string>(val), 168+76*i, curY+16, FONT_SMALL, Colors::WHITE, to);
curY += 20;
}
}
else//free upgrade - print gold image and "Free" text
{
blitAtLoc(resources->ourImages[6].bitmap, 104+76*i, 128, to);
printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, Colors::WHITE, to);
//* blitAtLoc(resources->ourImages[6].bitmap, 104+76*i, 128, to);
//* printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, Colors::WHITE, to);
}
}
}
@ -5664,8 +5666,8 @@ void CHillFortWindow::showAll (SDL_Surface *to)
{
if (totalSumm[i])//this resource is used - display it
{
blitAtLoc(resources->ourImages[i].bitmap, 104+76*i, 237, to);
printToLoc(boost::lexical_cast<std::string>(totalSumm[i]), 166+76*i, 253, FONT_SMALL, Colors::WHITE, to);
//* blitAtLoc(resources->ourImages[i].bitmap, 104+76*i, 237, to);
//* printToLoc(boost::lexical_cast<std::string>(totalSumm[i]), 166+76*i, 253, FONT_SMALL, Colors::WHITE, to);
}
}
}
@ -6099,9 +6101,9 @@ CRClickPopup::~CRClickPopup()
{
}
void CRClickPopupInt::show(SDL_Surface * to)
void CRClickPopupInt::show()
{
inner->show(to);
inner->show();
}
CRClickPopupInt::CRClickPopupInt( IShowActivatable *our, bool deleteInt )
@ -6124,7 +6126,7 @@ CRClickPopupInt::~CRClickPopupInt()
CCS->curh->show();
}
void CRClickPopupInt::showAll(SDL_Surface * to)
void CRClickPopupInt::showAll()
{
inner->showAll(to);
inner->showAll();
}

View File

@ -96,8 +96,8 @@ public:
void setDelComps(bool DelComps);
virtual void close();
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
void sliderMoved(int to);
CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo &comps = TCompsInfo(), const TButtonsInfo &Buttons = TButtonsInfo(), bool delComps = true); //c-tor
@ -145,8 +145,8 @@ public:
IShowActivatable *inner;
bool delInner;
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
CRClickPopupInt(IShowActivatable *our, bool deleteInt); //c-tor
virtual ~CRClickPopupInt(); //d-tor
};
@ -229,7 +229,7 @@ public:
bool selected; //if true, this component is selected
boost::function<void()> onSelect; //function called on selection change
void showAll(SDL_Surface * to);
void showAll();
void select(bool on);
void clickLeft(tribool down, bool previousState); //call-in
@ -408,7 +408,7 @@ class CRecruitmentWindow : public CWindowObject
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void showAll(SDL_Surface *to);
void showAll();
public:
const CCreature * creature;
si32 amount;
@ -451,7 +451,7 @@ class CRecruitmentWindow : public CWindowObject
void buy();
void sliderMoved(int to);
void showAll(SDL_Surface *to);
void showAll();
public:
const CGDwelling * const dwelling;
CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(CreatureID,int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
@ -609,11 +609,11 @@ public:
CFunctionList<void()> callback;
bool downSelection;
void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
void showAllAt(const Point &dstPos, const std::string &customSub);
void clickRight(tribool down, bool previousState);
void hover (bool on);
void showAll(SDL_Surface * to);
void showAll();
void clickLeft(tribool down, bool previousState);
std::string getName(int number = -1) const;
CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
@ -635,7 +635,7 @@ public:
CTradeWindow(std::string bgName, const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c
void showAll(SDL_Surface * to);
void showAll();
void initSubs(bool Left);
void initTypes();
@ -709,7 +709,7 @@ public:
void putOnAltar(int backpackIndex);
bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
void makeDeal();
void showAll(SDL_Surface * to);
void showAll();
void blockTrade();
void sliderMoved(int to);
@ -912,7 +912,7 @@ public:
void clickRight(tribool down, bool previousState);
void select();
void deselect();
void showAll(SDL_Surface * to);
void showAll();
bool fitsHere(const CArtifactInstance * art) const; //returns true if given artifact can be placed here
void setMeAsDest(bool backpackAsVoid = true);
@ -1071,8 +1071,8 @@ private:
ui8 currentAlpha;
public:
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void showAll();
void show();
CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
};
@ -1117,7 +1117,7 @@ class CUniversityWindow : public CWindowObject
int ID;//id of selected skill
CUniversityWindow * parent;
void showAll(SDL_Surface * to);
void showAll();
void clickLeft(tribool down, bool previousState);
void clickRight(tribool down, bool previousState);
void hover(bool on);
@ -1171,7 +1171,7 @@ public:
CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
void showAll (SDL_Surface *to);
void showAll();
std::string getDefForSlot(SlotID slot);//return def name for this slot
std::string getTextForSlot(SlotID slot);//return hover text for this slot
void makeDeal(SlotID slot);//-1 for upgrading all creatures

93
client/Gfx/Animations.cpp Normal file
View File

@ -0,0 +1,93 @@
#include "StdInc.h"
#include "Animations.h"
#include "Images.h"
#include "FilesHeaders.h"
namespace Gfx
{
#define LE(x) SDL_SwapLE32(x)
/*********** CAnimation ***********/
CAnimation* CAnimation::makeFromDEF(const SH3DefFile& def, size_t fileSize)
{
if (def.totalBlocks == 0 || def.width == 0 || def.height == 0) return nullptr;
if (def.fbEntrCount() == LE(1))
{
CImage* img = CImage::makeFromDEF(def, fileSize);
if (img == nullptr) return nullptr;
return new COneFrameAnimation(*img);
}
return new (LE(def.fbEntrCount())) CPalettedAnimation(def, fileSize);
}
CAnimation::~CAnimation() {}
/*********** COneFrameAnimation ***********/
COneFrameAnimation::COneFrameAnimation(CImage& img) :
CAnimation(1, img.getWidth(), img.getHeight()),
frame(img)
{
}
COneFrameAnimation::~COneFrameAnimation()
{
delete &frame;
}
CImage* COneFrameAnimation::getFrame(ui32 fnr)
{
if (fnr == 0) return &frame;
return nullptr;
}
/*********** CPalettedAnimation ***********/
CPalettedAnimation::CPalettedAnimation(const SH3DefFile& def, size_t fileSize) :
CAnimation(LE(def.fbEntrCount()), LE(def.width), LE(def.height)),
palette(def.palette, def.type == LE(71) ? 1 : 10, true)
//type == 71 - Buttons/buildings don't have shadows\semi-transparency
{
ua_ui32_ptr offsets = def.firstBlock.offsets();
for (ui32 j=0; j<framesCount; ++j)
{
CPalettedBitmap* fr = CImage::makeFromDEFSprite(def.getSprite(offsets[j]), palette);
if (fr == nullptr)
{
framesCount = j;
break;
}
frames[j] = fr;
}
}
CPalettedAnimation::~CPalettedAnimation()
{
for (ui32 j=0; j<framesCount; ++j)
{
delete frames[j];
}
}
CImage* CPalettedAnimation::getFrame(ui32 fnr)
{
if (fnr >= framesCount) return nullptr;
return frames[fnr];
}
}

70
client/Gfx/Animations.h Normal file
View File

@ -0,0 +1,70 @@
#pragma once
#include "CPaletteRGBA.h"
namespace Gfx
{
struct SH3DefFile;
class CImage;
class CAnimation
{
protected:
ui32 framesCount;
ui32 width;
ui32 height;
inline CAnimation(ui32 fc, ui32 w, ui32 h) : framesCount(fc), width(w), height(h) {};
public:
static CAnimation* makeFromDEF(const SH3DefFile& def, size_t fileSize);
virtual ~CAnimation();
virtual CImage* getFrame(ui32 fnr) = 0;
inline ui32 getFramesCount() { return framesCount; };
inline ui32 getWidth() { return width; };
inline ui32 getHeight() { return height; };
};
class COneFrameAnimation : CAnimation
{
friend class CAnimation;
CImage& frame;
protected:
COneFrameAnimation(CImage& img);
public:
virtual ~COneFrameAnimation();
virtual CImage* getFrame(ui32 fnr);
};
#pragma warning(disable : 4200)
class CPalettedAnimation : CAnimation
{
friend class CAnimation;
CPaletteRGBA palette;
CImage* frames[];
protected:
inline void* operator new(size_t size, ui32 frCount) {
return ::operator new(size + frCount * sizeof(void*));
}
inline void operator delete(void* ptr, ui32 frCount) {
::operator delete(ptr);
}
CPalettedAnimation(const SH3DefFile& def, size_t fileSize);
public:
virtual ~CPalettedAnimation();
virtual CImage* getFrame(ui32 fnr);
};
#pragma warning(default : 4200)
}

View File

@ -0,0 +1,63 @@
#include "StdInc.h"
#include <SDL_opengl.h>
#include "CPaletteRGBA.h"
namespace Gfx
{
CPaletteRGBA::CPaletteRGBA(const ColorRGBA palBuff[]) : texHandle(0), shared(false)
{
memcpy(buffer, palBuff, 256);
}
CPaletteRGBA::CPaletteRGBA(const ui8 palBuff[][3], int alphaMode, bool shr) : texHandle(0), shared(shr)
{
static const ui8 defPalette[10][4] = {{0,0,0,0}, {0,0,0,32}, {0,0,0,64}, {0,0,0,128}, {0,0,0,128},
{255,255,255,0}, {255,255,255,0}, {255,255,255,0}, {0,0,0,192}, {0,0,0,192}};
if (alphaMode > 0)
{
if (alphaMode > 10) alphaMode = 10;
memcpy(buffer, defPalette, alphaMode*sizeof(ColorRGBA));
}
for (ui32 it = alphaMode; it<256; ++it)
{
memcpy(&buffer[it], palBuff[it], 3);
buffer[it].comp.A = 255;
}
}
CPaletteRGBA::~CPaletteRGBA()
{
unloadFromVideoRAM();
}
void CPaletteRGBA::Unlink()
{
if (!shared) delete this;
}
void CPaletteRGBA::loadToVideoRAM()
{
if (texHandle > 0) return;
glGenTextures(1, &texHandle);
glBindTexture(GL_TEXTURE_1D, texHandle);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
}
void CPaletteRGBA::unloadFromVideoRAM()
{
glDeleteTextures(1, &texHandle);
texHandle = 0;
}
}

46
client/Gfx/CPaletteRGBA.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
namespace Gfx
{
#pragma pack(1)
typedef ui8 ColorRGB[3]; // 24bit RGB color
union ColorRGBA // 32bit RGBA color
{
ui32 color32;
ui8 arr[4];
struct {
ui8 R,G,B,A;
} comp;
inline ColorRGBA() {};
inline ColorRGBA(ui32 c) : color32(c) {};
};
#pragma pack()
class CPaletteRGBA
{
friend class CPalettedAnimation;
ui32 texHandle; // OpenGL texture handle
bool shared;
ColorRGBA buffer[256];
~CPaletteRGBA();
public:
CPaletteRGBA(const ColorRGBA palBuff[]); // 32bit RGBA source
CPaletteRGBA(const ColorRGB palBuff[], int alphaMode, bool shr=false); // 24-bit RGB source
void Unlink();
inline ui32 getTexHandle() { return texHandle; };
void loadToVideoRAM();
void unloadFromVideoRAM();
};
}

81
client/Gfx/FilesHeaders.h Normal file
View File

@ -0,0 +1,81 @@
#pragma once
#include <SDL_endian.h>
#include "CPaletteRGBA.h"
namespace Gfx
{
#define RGB_PALETTE_SIZE 0x300
#define H3PCX_HEADER_SIZE sizeof(SH3PcxFile)
#define H3DEF_HEADER_SIZE sizeof(SH3DefFile)
#define SELF_ADDR reinterpret_cast<const ui8*>(this)
#pragma pack(1)
#pragma warning(disable : 4200)
struct SH3PcxFile
{
ui32 size;
ui32 width;
ui32 height;
ui8 data[];
// palette = last 256*3 bytes of PCX
inline const ColorRGB* palette(size_t sizeOfPcx) const {
return (ColorRGB*) (SELF_ADDR + sizeOfPcx - RGB_PALETTE_SIZE);
}
};
struct SH3DefSprite
{
ui32 size;
ui32 format; /// format in which pixel data is stored
ui32 fullWidth; /// full width and height of frame, including borders
ui32 fullHeight;
ui32 width; /// width and height of pixel data, borders excluded
ui32 height;
si32 leftMargin;
si32 topMargin;
ui8 data[];
};
struct SH3DefBlock {
ui32 id;
ui32 entriesCount;
ui32 unknown1;
ui32 unknown2;
char names[][13]; // [entriesCount][13] - array of frames names
inline const ua_ui32_ptr offsets() const {
return (ua_ui32_ptr)(names + SDL_SwapLE32(entriesCount));
} // array of offsets of frames
};
struct SH3DefFile {
ui32 type;
ui32 width;
ui32 height;
ui32 totalBlocks;
ColorRGB palette[256];
// SDefHeader is followed by a series of SH3DefBlock
SH3DefBlock firstBlock;
// Number of entries (sprites) in first block
inline ui32 fbEntrCount() const { return firstBlock.entriesCount; };
inline SH3DefSprite& getSprite(ui32 offset) const {
return *(SH3DefSprite*) (SELF_ADDR + offset);
}
};
#pragma warning(default : 4200)
#pragma pack()
#undef SELF_ADDR
}

440
client/Gfx/Images.cpp Normal file
View File

@ -0,0 +1,440 @@
#include "StdInc.h"
#include <SDL_opengl.h>
#include <SDL_endian.h>
#include "Images.h"
namespace Gfx
{
/*********** CImage ***********/
CImage::~CImage()
{
unloadFromVideoRAM();
}
void CImage::loadToVideoRAM()
{
if (texHandle > 0) return;
glGenTextures(1, &texHandle);
glBindTexture(GL_TEXTURE_RECTANGLE, texHandle);
textureTransfer();
}
void CImage::unloadFromVideoRAM()
{
glDeleteTextures(1, &texHandle);
texHandle = 0;
}
void CImage::bindTexture()
{
if (texHandle > 0)
{
glBindTexture(GL_TEXTURE_RECTANGLE, texHandle);
return;
}
glGenTextures(1, &texHandle);
glBindTexture(GL_TEXTURE_RECTANGLE, texHandle);
textureTransfer();
}
/*********** CBitmap32::QuadInstance ***********/
CBitmap32::QuadInstance::QuadInstance(Point p) : coords()
{
for (int i=0; i<4; ++i) coords[i].vertex = p;
}
void CBitmap32::QuadInstance::setOffset(TransformFlags flags, si32 x, si32 y)
{
if (flags & ROTATE_90_DEG)
{
}
else
{
}
}
void CBitmap32::QuadInstance::transform(TransformFlags flags, ui32 w0, ui32 h0, ui32 w, ui32 h)
{
if (flags & MIRROR_HORIZ)
{
coords[0].vertex.x += w;
coords[3].vertex.x += w;
}
else
{
coords[1].vertex.x += w;
coords[2].vertex.x += w;
}
if (flags & MIRROR_VERTIC)
{
coords[0].vertex.y += h;
coords[1].vertex.y += h;
}
else
{
coords[2].vertex.y += h;
coords[3].vertex.y += h;
}
if (flags & ROTATE_90_DEG)
{
coords[0].texture.x = w0;
coords[1].texture.x = w0;
coords[1].texture.y = h0;
coords[2].texture.y = h0;
}
else
{
coords[1].texture.x = w0;
coords[2].texture.x = w0;
coords[2].texture.y = h0;
coords[3].texture.y = h0;
}
}
void CBitmap32::QuadInstance::putToGL() const
{
glBegin(GL_QUADS);
for (int i=0; i<4; ++i)
{
const CoordBind& row = coords[i];
glTexCoord2i(row.texture.x, row.texture.y);
glVertex2i(row.vertex.x, row.vertex.y);
}
glEnd();
}
/*********** CBitmap32 ***********/
CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[]) : CImage(w, h)
{
const ui32 size = w * h;
buffer = new ColorRGBA[size];
for (ui32 it=0; it<size; ++it)
{
memcpy(&buffer[it], &pixBuff[it], 3);
buffer[it].comp.A = 255;
}
}
CBitmap32::~CBitmap32()
{
delete buffer;
}
void CBitmap32::textureTransfer()
{
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
}
void CBitmap32::putAt(Point p)
{
GL2D::useNoShader();
bindTexture();
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(p.x, p.y);
glTexCoord2i(width, 0);
glVertex2i(p.x + width, p.y);
glTexCoord2i(width, height);
glVertex2i(p.x + width, p.y + height);
glTexCoord2i(0, height);
glVertex2i(p.x, p.y + height);
glEnd();
}
void CBitmap32::putAt(Point p, TransformFlags flags)
{
QuadInstance qi(p);
qi.transform(flags, width, height, width, height);
GL2D::useNoShader();
bindTexture();
qi.putToGL();
}
void CBitmap32::putAt(Point p, TransformFlags flags, float scale)
{
QuadInstance qi(p);
qi.transform(flags, width, height, width*scale, height*scale);
GL2D::useNoShader();
bindTexture();
qi.putToGL();
}
void CBitmap32::putAt(Point p, TransformFlags flags, Rect clipRect)
{
QuadInstance qi(p);
qi.setOffset(flags, clipRect.lt.x, clipRect.lt.y);
qi.transform(flags, clipRect.rb.x - p.x, clipRect.rb.y - p.y, clipRect.width(), clipRect.height());
GL2D::useNoShader();
bindTexture();
qi.putToGL();
}
void CBitmap32::putAt(Point p, TransformFlags flags, const ColorMatrix cm)
{
QuadInstance qi(p);
qi.transform(flags, width, height, width, height);
GL2D::useColorizeShader(cm);
bindTexture();
qi.putToGL();
}
void CBitmap32::putWithPlrColor(Point p, ColorRGBA c)
{
putAt(p);
}
void CBitmap32::putWithPlrColor(Point p, ColorRGBA c, float scale)
{
putAt(p, NONE, scale);
}
/*********** CPalettedBitmap ***********/
CPalettedBitmap::CPalettedBitmap(ui32 w, ui32 h, CPaletteRGBA& pal, const ui8 pixBuff[]) :
CImage(w, h),
palette(pal)
{
const ui32 rowStride = (w + 3) & ~3;
const ui32 size = rowStride * h;
buffer = new ui8[size];
if (rowStride == w)
{
memcpy(buffer, pixBuff, size);
return;
}
for (ui32 y=0; y<h; ++y)
{
memset(&buffer[rowStride*(y+1)-4], 0, 4);
memcpy(&buffer[rowStride*y], &pixBuff[w*y], w);
}
width = rowStride;
}
CPalettedBitmap::CPalettedBitmap(ui32 w, ui32 h, CPaletteRGBA& pal, const ui8 pixBuff[], ui32 format) :
CImage(w, h),
palette(pal)
{
const ui32 rowStride = (w + 3) & ~3;
buffer = new ui8[rowStride * h];
switch (format)
{
case 1:
{
const ua_ui32_ptr rowsOffsets = (ua_ui32_ptr)pixBuff;
for (ui32 y=0; y<h; ++y)
{
const ui8* srcRowPtr = pixBuff + SDL_SwapLE32(rowsOffsets[y]);
ui8* dstRowPtr = buffer + (y * rowStride);
ui32 rowLength = 0;
do {
ui8 segmentType = *(srcRowPtr++);
size_t segmentLength = *(srcRowPtr++) + 1;
if (segmentType == 0xFF)
{
memcpy(dstRowPtr, srcRowPtr, segmentLength);
srcRowPtr += segmentLength;
}
else
{
memset(dstRowPtr, segmentType, segmentLength);
}
dstRowPtr += segmentLength;
rowLength += segmentLength;
}
while (rowLength < w);
}
return;
}
default:
return;
}
}
CPalettedBitmap::~CPalettedBitmap()
{
delete buffer;
palette.Unlink();
}
void CPalettedBitmap::textureTransfer()
{
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_R8UI, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, buffer);
palette.loadToVideoRAM();
}
void CPalettedBitmap::putAt(Point p)
{
loadToVideoRAM();
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
GL2D::usePaletteBitmapShader(p.x, p.y);
glRecti(p.x, p.y, p.x + width, p.y + height);
}
void CPalettedBitmap::putAt(Point p, TransformFlags flags)
{
putAt(p);
}
void CPalettedBitmap::putAt(Point p, TransformFlags flags, float scale)
{
loadToVideoRAM();
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
GL2D::usePaletteBitmapShader(p.x, p.y);
glRecti(p.x, p.y, p.x + width*scale, p.y + height*scale);
}
void CPalettedBitmap::putAt(Point p, TransformFlags flags, Rect clipRect)
{
putAt(p);
}
void CPalettedBitmap::putAt(Point p, TransformFlags flags, const ColorMatrix cm)
{
loadToVideoRAM();
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
GL2D::usePaletteBitmapShader(p.x, p.y, cm);
glRecti(p.x, p.y, p.x + width, p.y + height);
}
void CPalettedBitmap::putWithPlrColor(Point p, ColorRGBA c)
{
putAt(p);
}
void CPalettedBitmap::putWithPlrColor(Point p, ColorRGBA c, float scale)
{
putAt(p, NONE, scale);
}
/*********** CPalBitmapWithMargin ***********/
CPalBitmapWithMargin::CPalBitmapWithMargin(ui32 fw, ui32 fh, ui32 lm, ui32 tm, ui32 iw, ui32 ih,
CPaletteRGBA& pal, const ui8 pixBuff[]) :
CPalettedBitmap(iw, ih, pal, pixBuff),
leftMargin(lm), topMargin(tm),
intWidth(iw), intHeight(ih)
{
width = fw;
height = fh;
}
void CPalBitmapWithMargin::textureTransfer()
{
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_R8UI, intWidth, intHeight, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, buffer);
palette.loadToVideoRAM();
}
CPalBitmapWithMargin::CPalBitmapWithMargin(ui32 fw, ui32 fh, ui32 lm, ui32 tm, ui32 iw, ui32 ih,
CPaletteRGBA& pal, const ui8 pixBuff[], ui32 format) :
CPalettedBitmap(iw, ih, pal, pixBuff, format),
leftMargin(lm), topMargin(tm),
intWidth(iw), intHeight(ih)
{
width = fw;
height = fh;
}
void CPalBitmapWithMargin::putAt(Point p)
{
loadToVideoRAM();
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
GL2D::usePaletteBitmapShader(p.x, p.y);
glRecti(p.x, p.y, p.x + intWidth, p.y + intHeight);
}
void CPalBitmapWithMargin::putAt(Point p, TransformFlags flags)
{
putAt(p);
}
void CPalBitmapWithMargin::putAt(Point p, TransformFlags flags, float scale)
{
putAt(p);
}
void CPalBitmapWithMargin::putAt(Point p, TransformFlags flags, Rect clipRect)
{
putAt(p);
}
void CPalBitmapWithMargin::putAt(Point p, TransformFlags flags, const ColorMatrix cm)
{
loadToVideoRAM();
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
GL2D::usePaletteBitmapShader(p.x, p.y, cm);
glRecti(p.x, p.y, p.x + width, p.y + height);
}
void CPalBitmapWithMargin::putWithPlrColor(Point p, ColorRGBA c)
{
putAt(p);
}
void CPalBitmapWithMargin::putWithPlrColor(Point p, ColorRGBA c, float scale)
{
putAt(p, NONE, scale);
}
}

164
client/Gfx/Images.h Normal file
View File

@ -0,0 +1,164 @@
#pragma once
#include "CPaletteRGBA.h"
#include "../UIFramework/GL2D.h"
namespace Gfx
{
struct Point
{
si32 x;
si32 y;
inline Point() {};
inline Point(si32 _x, si32 _y) : x(_x), y(_y) {};
};
struct Rect
{
Point lt;
Point rb;
inline ui32 width() { return rb.x - lt.x; };
inline ui32 height() { return rb.y - lt.y; };
};
enum TransformFlags
{
NONE = 0,
MIRROR_HORIZ = 1,
MIRROR_VERTIC = 2,
ROTATE_90_DEG = 4
};
/* Color transform matrix for: grayscale, clone, bloodlust, etc */
typedef float ColorMatrix[4][4];
class CImage
{
protected:
ui32 texHandle;
ui32 width;
ui32 height;
inline CImage(ui32 w, ui32 h) : texHandle(0), width(w), height(h) {};
virtual void textureTransfer() = 0;
public:
static CImage* makeFromPCX(const struct SH3PcxFile& pcx, size_t fileSize);
static CImage* makeFromDEF(const struct SH3DefFile& def, size_t fileSize);
static class CPalettedBitmap* makeFromDEFSprite(
const struct SH3DefSprite& spr, CPaletteRGBA& pal);
virtual ~CImage();
inline ui32 getWidth() { return width; };
inline ui32 getHeight() { return height; };
void loadToVideoRAM();
void unloadFromVideoRAM();
void bindTexture();
virtual void putAt(Point p) = 0;
virtual void putAt(Point p, TransformFlags flags) = 0;
virtual void putAt(Point p, TransformFlags flags, float scale) = 0;
virtual void putAt(Point p, TransformFlags flags, Rect clipRect) = 0;
virtual void putAt(Point p, TransformFlags flags, const ColorMatrix cm) = 0;
virtual void putWithPlrColor(Point p, ColorRGBA c) = 0;
virtual void putWithPlrColor(Point p, ColorRGBA c, float scale) = 0;
};
class CBitmap32 : public CImage
{
friend class CImage;
ColorRGBA* buffer;
struct CoordBind {
Point texture, vertex;
inline CoordBind() : texture(0, 0) {};
};
class QuadInstance {
CoordBind coords[4];
public:
QuadInstance(Point p);
QuadInstance(const CoordBind c[4]);
void setOffset(TransformFlags flags, si32 x, si32 y);
void transform(TransformFlags flags, ui32 w0, ui32 h0, ui32 w, ui32 h);
void putToGL() const;
};
protected:
CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[]); // 24bit RGB source
virtual void textureTransfer();
public:
virtual ~CBitmap32();
virtual void putAt(Point p);
virtual void putAt(Point p, TransformFlags flags);
virtual void putAt(Point p, TransformFlags flags, float scale);
virtual void putAt(Point p, TransformFlags flags, Rect clipRect);
virtual void putAt(Point p, TransformFlags flags, const ColorMatrix cm);
virtual void putWithPlrColor(Point p, ColorRGBA c);
virtual void putWithPlrColor(Point p, ColorRGBA c, float scale);
};
class CPalettedBitmap : public CImage
{
friend class CImage;
protected:
CPaletteRGBA& palette;
ui8* buffer;
CPalettedBitmap(ui32 w, ui32 h, CPaletteRGBA& pal, const ui8 pixBuff[]);
CPalettedBitmap(ui32 w, ui32 h, CPaletteRGBA& pal, const ui8 pixBuff[], ui32 format);
virtual void textureTransfer();
public:
virtual ~CPalettedBitmap();
virtual void putAt(Point p);
virtual void putAt(Point p, TransformFlags flags);
virtual void putAt(Point p, TransformFlags flags, float scale);
virtual void putAt(Point p, TransformFlags flags, Rect clipRect);
virtual void putAt(Point p, TransformFlags flags, const ColorMatrix cm);
virtual void putWithPlrColor(Point p, ColorRGBA c);
virtual void putWithPlrColor(Point p, ColorRGBA c, float scale);
};
class CPalBitmapWithMargin : public CPalettedBitmap
{
friend class CImage;
ui32 leftMargin;
ui32 topMargin;
ui32 intWidth;
ui32 intHeight;
protected:
CPalBitmapWithMargin(ui32 fw, ui32 fh, ui32 lm, ui32 tm, ui32 iw, ui32 ih,
CPaletteRGBA& pal, const ui8 pixBuff[]);
CPalBitmapWithMargin(ui32 fw, ui32 fh, ui32 lm, ui32 tm, ui32 iw, ui32 ih,
CPaletteRGBA& pal, const ui8 pixBuff[], ui32 format);
virtual void textureTransfer();
public:
virtual void putAt(Point p);
virtual void putAt(Point p, TransformFlags flags);
virtual void putAt(Point p, TransformFlags flags, float scale);
virtual void putAt(Point p, TransformFlags flags, Rect clipRect);
virtual void putAt(Point p, TransformFlags flags, const ColorMatrix cm);
virtual void putWithPlrColor(Point p, ColorRGBA c);
virtual void putWithPlrColor(Point p, ColorRGBA c, float scale);
};
}

82
client/Gfx/ImgMakers.cpp Normal file
View File

@ -0,0 +1,82 @@
#include "StdInc.h"
#include "Images.h"
#include "FilesHeaders.h"
namespace Gfx
{
#define LE(x) SDL_SwapLE32(x)
/*********** H3 PCX image format ***********/
CImage * CImage::makeFromPCX(const SH3PcxFile& pcx, size_t fileSize)
{
ui32 imgSize = LE(pcx.size);
ui32 width = LE(pcx.width);
ui32 height = LE(pcx.height);
if (imgSize == width*height)
{
if (H3PCX_HEADER_SIZE + RGB_PALETTE_SIZE + imgSize > fileSize) return nullptr;
CPaletteRGBA* ppal = new CPaletteRGBA(pcx.palette(fileSize), 0);
return new CPalettedBitmap(width, height, *ppal, pcx.data);
}
if (imgSize == width*height*3)
{
if (H3PCX_HEADER_SIZE + imgSize > fileSize) return nullptr;
return new CBitmap32(width, height, (ColorRGB*)pcx.data);
}
return nullptr;
}
/*********** DEF animation frame ***********/
CImage* CImage::makeFromDEF(const struct SH3DefFile& def, size_t fileSize)
{
CPaletteRGBA* ppal = new CPaletteRGBA(def.palette, def.type == LE(71) ? 1 : 10);
CPalettedBitmap* img = makeFromDEFSprite(def.getSprite(def.firstBlock.offsets()[0]), *ppal);
if (img == nullptr) ppal->Unlink();
return img;
}
CPalettedBitmap* CImage::makeFromDEFSprite(const SH3DefSprite& spr, CPaletteRGBA& pal)
{
ui32 format = LE(spr.format);
if (format > 3) return nullptr;
ui32 fullWidth = LE(spr.fullWidth);
ui32 fullHeight = LE(spr.fullHeight);
ui32 intWidth = LE(spr.width);
ui32 intHeight = LE(spr.height);
ui32 leftMargin = LE(spr.leftMargin);
ui32 topMargin = LE(spr.topMargin);
bool noMargins = (leftMargin == 0 && topMargin == 0 && fullWidth == intWidth && fullHeight == intHeight);
if (format == 0)
{
if (noMargins)
{
return new CPalettedBitmap(fullWidth, fullHeight, pal, spr.data);
}
return new CPalBitmapWithMargin(fullWidth, fullHeight, leftMargin, topMargin, intWidth, intHeight, pal, spr.data);
}
if (noMargins)
{
return new CPalettedBitmap(fullWidth, fullHeight, pal, spr.data, format);
}
return new CPalBitmapWithMargin(fullWidth, fullHeight, leftMargin, topMargin, intWidth, intHeight, pal, spr.data, format);
}
}

76
client/Gfx/Manager.cpp Normal file
View File

@ -0,0 +1,76 @@
#include "StdInc.h"
#include <map>
#include "Manager.h"
#include "Animations.h"
#include "Images.h"
#include "FilesHeaders.h"
#include "../../lib/Filesystem/CResourceLoader.h"
namespace Gfx
{
class Resources
{
friend class CManager;
static std::map<std::string, PImage> images;
static std::map<std::string, PAnimation> anims;
};
std::map<std::string, PImage> Resources::images;
std::map<std::string, PAnimation> Resources::anims;
PImage CManager::getImage(const std::string& fname)
{
PImage& img_ptr = Resources::images[fname];
if (img_ptr) return img_ptr;
ResourceID resImageId("DATA/" + fname, EResType::IMAGE);
auto stream = CResourceHandler::get()->load(resImageId);
auto streamSize = stream->getSize();
if (streamSize < H3PCX_HEADER_SIZE) return nullptr;
if (streamSize > 0x10000000) streamSize = 0x10000000;
std::unique_ptr<ui8[]> data(new ui8[(size_t)streamSize]);
auto readSize = stream->read(data.get(), streamSize);
assert(readSize == stream->getSize());
CImage* img_tmp = CImage::makeFromPCX(*(SH3PcxFile*)data.get(), (size_t)readSize);
if (img_tmp == nullptr) return nullptr;
return img_ptr = PImage(img_tmp);
}
PAnimation CManager::getAnimation(const std::string& fname)
{
PAnimation& anim_ptr = Resources::anims[fname];
if (anim_ptr) return anim_ptr;
ResourceID resAnimId("SPRITES/" + fname, EResType::ANIMATION);
auto stream = CResourceHandler::get()->load(resAnimId);
auto streamSize = stream->getSize();
if (streamSize < H3DEF_HEADER_SIZE) return nullptr;
if (streamSize > 0x7FFFFFF0) streamSize = 0x7FFFFFF0;
std::unique_ptr<ui8[]> data(new ui8[(size_t)streamSize]);
auto readSize = stream->read(data.get(), streamSize);
assert(readSize == stream->getSize());
CAnimation* anim_tmp = CAnimation::makeFromDEF(*(SH3DefFile*)data.get(), (size_t)readSize);
if (anim_tmp == nullptr) return nullptr;
return anim_ptr = PAnimation(anim_tmp);
}
}

21
client/Gfx/Manager.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <memory>
#include <string>
namespace Gfx
{
class CImage;
class CAnimation;
typedef std::shared_ptr<CImage> PImage;
typedef std::shared_ptr<CAnimation> PAnimation;
class CManager
{
public:
static PImage getImage(const std::string& fname);
static PAnimation getAnimation(const std::string& fname);
};
}

View File

@ -193,7 +193,7 @@ CDefEssential * Graphics::loadHeroAnim( const std::string &name, const std::vect
}
for(size_t ff=0; ff<anim->ourImages.size(); ++ff)
{
CSDL_Ext::alphaTransform(anim->ourImages[ff].bitmap);
if (anim->ourImages[ff].bitmap != nullptr) CSDL_Ext::alphaTransform(anim->ourImages[ff].bitmap);
}
return anim;
}
@ -245,6 +245,7 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefEssential *> Graphics::*,
}
for(size_t ff=0; ff<curImgs.size(); ++ff)
{
if (curImgs[ff].bitmap != nullptr)
SDL_SetColorKey(curImgs[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(curImgs[ff].bitmap->format, 0, 255, 255)
);

View File

@ -1,8 +1,10 @@
#include "StdInc.h"
#include "CCursorHandler.h"
#include <SDL.h>
#include "SDL_Extensions.h"
#include "CCursorHandler.h"
#include "GL2D.h"
#include "../Gfx/Animations.h"
#include "../Gfx/Images.h"
#include "../CAnimation.h"
#include "CGuiHandler.h"
@ -16,24 +18,23 @@
*
*/
extern SDL_Surface * screen;
void CCursorHandler::initCursor()
CCursorHandler::CCursorHandler()
{
xpos = ypos = 0;
type = ECursor::DEFAULT;
dndObject = nullptr;
currentCursor = nullptr;
help = CSDL_Ext::newSurface(40,40);
//* help = CSDL_Ext::newSurface(40,40);
SDL_ShowCursor(SDL_DISABLE);
changeGraphic(ECursor::ADVENTURE, 0);
}
void CCursorHandler::changeGraphic(ECursor::ECursorTypes type, int index)
{
std::string cursorDefs[4] = { "CRADVNTR.DEF", "CRCOMBAT.DEF", "CRDEFLT.DEF", "CRSPELL.DEF" };
const std::string cursorDefs[4] = { "CRADVNTR", "CRCOMBAT", "CRDEFLT", "CRSPELL" };
if (type != this->type)
{
@ -42,26 +43,20 @@ void CCursorHandler::changeGraphic(ECursor::ECursorTypes type, int index)
this->type = type;
this->frame = index;
delete currentCursor;
currentCursor = new CAnimImage(cursorDefs[int(type)], index);
currentCursor = Gfx::CManager::getAnimation(cursorDefs[type]);
}
frame = index;
}
if (frame != index)
{
frame = index;
currentCursor->setFrame(index);
}
}
void CCursorHandler::dragAndDropCursor(CAnimImage * object)
{
if (dndObject)
delete dndObject;
if (dndObject) delete dndObject;
dndObject = object;
}
void CCursorHandler::cursorMove(const int & x, const int & y)
void CCursorHandler::cursorMove(int x, int y)
{
xpos = x;
ypos = y;
@ -73,19 +68,14 @@ void CCursorHandler::drawWithScreenRestore()
int x = xpos, y = ypos;
shiftPos(x, y);
SDL_Rect temp_rect1 = genRect(40,40,x,y);
SDL_Rect temp_rect2 = genRect(40,40,0,0);
SDL_BlitSurface(screen, &temp_rect1, help, &temp_rect2);
if (dndObject)
{
dndObject->moveTo(Point(x - dndObject->pos.w/2, y - dndObject->pos.h/2));
dndObject->showAll(screen);
dndObject->showAll();
}
else
{
currentCursor->moveTo(Point(x,y));
currentCursor->showAll(screen);
currentCursor->getFrame(frame)->putAt(Gfx::Point(x, y));
}
}
@ -96,18 +86,14 @@ void CCursorHandler::drawRestored()
int x = xpos, y = ypos;
shiftPos(x, y);
SDL_Rect temp_rect = genRect(40, 40, x, y);
SDL_BlitSurface(help, NULL, screen, &temp_rect);
//blitAt(help,x,y);
}
void CCursorHandler::draw(SDL_Surface *to)
void CCursorHandler::draw()
{
currentCursor->moveTo(Point(xpos, ypos));
currentCursor->showAll(screen);
currentCursor->getFrame(frame)->putAt(Gfx::Point(xpos, ypos));
}
void CCursorHandler::shiftPos( int &x, int &y )
{
if(( type == ECursor::COMBAT && frame != ECursor::COMBAT_POINTER) || type == ECursor::SPELLBOOK)
@ -215,10 +201,11 @@ void CCursorHandler::shiftPos( int &x, int &y )
}
}
void CCursorHandler::centerCursor()
{
this->xpos = (screen->w / 2.) - (currentCursor->pos.w / 2.);
this->ypos = (screen->h / 2.) - (currentCursor->pos.h / 2.);
this->xpos = (GL2D::getScreenWidth() - currentCursor->getWidth()) / 2;
this->ypos = (GL2D::getScreenHeight() - currentCursor->getHeight()) / 2;
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_WarpMouse(this->xpos, this->ypos);
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
@ -226,9 +213,5 @@ void CCursorHandler::centerCursor()
CCursorHandler::~CCursorHandler()
{
if(help)
SDL_FreeSurface(help);
delete currentCursor;
delete dndObject;
}

View File

@ -1,7 +1,8 @@
#pragma once
#include "../Gfx/Manager.h"
class CAnimImage;
struct SDL_Surface;
/*
* CCursorhandler.h, part of VCMI engine
@ -27,8 +28,8 @@ namespace ECursor
/// handles mouse cursor
class CCursorHandler
{
SDL_Surface * help;
CAnimImage * currentCursor;
Gfx::PImage help;
Gfx::PAnimation currentCursor;
CAnimImage* dndObject; // if set, overrides currentCursor
bool showing;
@ -41,7 +42,7 @@ public:
size_t frame;
/// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
void initCursor();
CCursorHandler();
/// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
void changeGraphic(ECursor::ECursorTypes type, int index);
@ -59,14 +60,14 @@ public:
/// Restore original image below cursor
void drawRestored();
/// Simple draw cursor
void draw(SDL_Surface *to);
void draw();
void shiftPos( int &x, int &y );
void hide() { showing=0; };
void show() { showing=1; };
/// change cursor's positions to (x, y)
void cursorMove(const int & x, const int & y);
void cursorMove(int x, int y);
/// Move cursor to screen center
void centerCursor();

View File

@ -1,9 +1,11 @@
#include "StdInc.h"
#include "CGuiHandler.h"
#include "GL2D.h"
#include "SDL_Extensions.h"
#include "CIntObject.h"
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "CCursorHandler.h"
#include "../../lib/CThreadHelper.h"
#include "../../lib/CConfigHandler.h"
@ -141,13 +143,22 @@ IShowActivatable * CGuiHandler::topInt()
return listInt.front();
}
void CGuiHandler::totalRedraw()
{
for(int i=0;i<objsToBlit.size();i++)
objsToBlit[i]->showAll(screen2);
blitAt(screen2,0,0,screen);
for (size_t i=0; i<objsToBlit.size(); ++i)
objsToBlit[i]->showAll();
if (settings["general"]["showfps"].Bool()) drawFPSCounter();
// draw the mouse cursor and update the screen
CCS->curh->drawWithScreenRestore();
CCS->curh->drawRestored();
SDL_GL_SwapBuffers();
}
void CGuiHandler::updateTime()
{
int ms = mainFPSmng->getElapsedMilliseconds();
@ -336,9 +347,9 @@ void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
void CGuiHandler::simpleRedraw()
{
//update only top interface and draw background
if(objsToBlit.size() > 1)
blitAt(screen2,0,0,screen); //blit background
objsToBlit.back()->show(screen); //blit active interface/window
//* if(objsToBlit.size() > 1)
//* blitAt(screen2,0,0,screen); //blit background
objsToBlit.back()->show(); //blit active interface/window
}
void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion )
@ -375,14 +386,23 @@ void CGuiHandler::run()
inGuiThread.reset(new bool(true));
try
{
GL2D::attachToCurrentThread();
if (settings["video"]["fullscreen"].Bool())
CCS->curh->centerCursor();
mainFPSmng->init(); // resets internal clock, needed for FPS manager
while(!terminate)
{
if(curInt)
curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment
boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
if (curInt) curInt->update();
// Handles mouse and key input
updateTime();
handleEvents();
totalRedraw();
mainFPSmng->framerateDelay(); // holds a constant FPS
}
@ -500,7 +520,7 @@ void CGuiHandler::pushSDLEvent(int type, int usercode)
CFramerateManager::CFramerateManager(int rate)
{
this->rate = rate;
this->rateticks = (1000.0 / rate);
this->rateticks = (ui32)ceil(1000.0 / rate);
this->fps = 0;
}
@ -517,7 +537,7 @@ void CFramerateManager::framerateDelay()
// FPS is higher than it should be, then wait some time
if (timeElapsed < rateticks)
{
SDL_Delay(ceil(this->rateticks) - timeElapsed);
SDL_Delay(rateticks - timeElapsed);
}
currentTicks = SDL_GetTicks();

View File

@ -24,7 +24,7 @@ class IShowable;
class CFramerateManager
{
private:
double rateticks;
ui32 rateticks;
ui32 lastticks, timeElapsed;
int rate;

View File

@ -1,4 +1,5 @@
#include "StdInc.h"
#include "GL2D.h"
#include "CIntObject.h"
#include "CGuiHandler.h"
#include "SDL_Extensions.h"
@ -43,21 +44,21 @@ void CIntObject::onTimer(int timePassed)
}
}
void CIntObject::show(SDL_Surface * to)
void CIntObject::show()
{
if(defActions & UPDATE)
for(size_t i = 0; i < children.size(); i++)
if(children[i]->recActions & UPDATE)
children[i]->show(to);
children[i]->show();
}
void CIntObject::showAll(SDL_Surface * to)
void CIntObject::showAll()
{
if(defActions & SHOWALL)
{
for(size_t i = 0; i < children.size(); i++)
if(children[i]->recActions & SHOWALL)
children[i]->showAll(to);
children[i]->showAll();
}
}
@ -208,8 +209,8 @@ void CIntObject::fitToScreen(int borderWidth, bool propagate)
Point newPos = pos.topLeft();
vstd::amax(newPos.x, borderWidth);
vstd::amax(newPos.y, borderWidth);
vstd::amin(newPos.x, screen->w - borderWidth - pos.w);
vstd::amin(newPos.y, screen->h - borderWidth - pos.h);
vstd::amin(newPos.x, GL2D::getScreenWidth() - borderWidth - pos.w);
vstd::amin(newPos.y, GL2D::getScreenHeight() - borderWidth - pos.h);
if (newPos != pos.topLeft())
moveTo(newPos, propagate);
}
@ -281,9 +282,7 @@ void CIntObject::redraw()
}
else
{
showAll(screenBuf);
if(screenBuf != screen)
showAll(screen);
showAll();
}
}
}
@ -292,7 +291,7 @@ const Rect & CIntObject::center( const Rect &r, bool propagate )
{
pos.w = r.w;
pos.h = r.h;
return center(Point(screen->w/2, screen->h/2), propagate);
return center(Point(GL2D::getScreenWidth()/2, GL2D::getScreenHeight()/2), propagate);
}
const Rect & CIntObject::center( bool propagate )

View File

@ -41,10 +41,10 @@ class IShowable
{
public:
virtual void redraw()=0;
virtual void show(SDL_Surface * to) = 0;
virtual void showAll(SDL_Surface * to)
virtual void show() = 0;
virtual void showAll()
{
show(to);
show();
}
virtual ~IShowable(){}; //d-tor
};
@ -156,9 +156,9 @@ public:
void deactivate();
//called each frame to update screen
void show(SDL_Surface * to);
void show();
//called on complete redraw only
void showAll(SDL_Surface * to);
void showAll();
//request complete redraw of this object
void redraw();

View File

@ -1,5 +1,6 @@
#include "StdInc.h"
#include "CIntObjectClasses.h"
#include "GL2D.h"
#include "../CBitmapHandler.h"
#include "SDL_Pixels.h"
@ -18,29 +19,31 @@
#include "../GUIClasses.h"
#include "CGuiHandler.h"
#include "../CAdvmapInterface.h"
#include "../Gfx/Animations.h"
#include "../Gfx/Images.h"
CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
CPicture::CPicture(Gfx::PImage BG, int x, int y, bool Free )
{
init();
bg = BG;
freeSurf = Free;
pos.x += x;
pos.y += y;
pos.w = BG->w;
pos.h = BG->h;
pos.w = BG->getWidth();
pos.h = BG->getHeight();
}
CPicture::CPicture( const std::string &bmpname, int x, int y )
{
init();
bg = BitmapHandler::loadBitmap(bmpname);
bg = Gfx::CManager::getImage(bmpname);
freeSurf = true;;
pos.x += x;
pos.y += y;
if(bg)
{
pos.w = bg->w;
pos.h = bg->h;
pos.w = bg->getWidth();
pos.h = bg->getHeight();
}
else
{
@ -51,7 +54,7 @@ CPicture::CPicture( const std::string &bmpname, int x, int y )
CPicture::CPicture(const Rect &r, const SDL_Color &color, bool screenFormat /*= false*/)
{
init();
createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b));
//createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b));
}
CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/)
@ -60,7 +63,7 @@ CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/)
createSimpleRect(r, screenFormat, color);
}
CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/)
CPicture::CPicture(Gfx::PImage BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/)
{
needRefresh = false;
srcRect = new Rect(SrcRect);
@ -74,7 +77,7 @@ CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*
void CPicture::setSurface(SDL_Surface *to)
{
bg = to;
//* bg = to;
if (srcRect)
{
pos.w = srcRect->w;
@ -82,15 +85,13 @@ void CPicture::setSurface(SDL_Surface *to)
}
else
{
pos.w = bg->w;
pos.h = bg->h;
pos.w = bg->getWidth();
pos.h = bg->getHeight();
}
}
CPicture::~CPicture()
{
if(freeSurf)
SDL_FreeSurface(bg);
delete srcRect;
}
@ -100,14 +101,15 @@ void CPicture::init()
srcRect = NULL;
}
void CPicture::show(SDL_Surface * to)
void CPicture::show()
{
if (needRefresh)
showAll(to);
if (bg) bg->putAt(Gfx::Point(pos.x, pos.y));
}
void CPicture::showAll(SDL_Surface * to)
void CPicture::showAll()
{
if (bg) bg->putAt(Gfx::Point(pos.x, pos.y));
/*
if(bg)
{
if(srcRect)
@ -122,30 +124,32 @@ void CPicture::showAll(SDL_Surface * to)
else
blitAt(bg, pos, to);
}
*/
}
void CPicture::convertToScreenBPP()
{
SDL_Surface *hlp = bg;
/* SDL_Surface *hlp = bg;
bg = SDL_ConvertSurface(hlp,screen->format,0);
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
SDL_FreeSurface(hlp);
SDL_FreeSurface(hlp); */
}
void CPicture::setAlpha(int value)
{
SDL_SetAlpha(bg, SDL_SRCALPHA, value);
//* SDL_SetAlpha(bg, SDL_SRCALPHA, value);
}
void CPicture::scaleTo(Point size)
{
SDL_Surface * scaled = CSDL_Ext::scaleSurface(bg, size.x, size.y);
/* SDL_Surface * scaled = CSDL_Ext::scaleSurface(bg, size.x, size.y);
if(freeSurf)
SDL_FreeSurface(bg);
setSurface(scaled);
freeSurf = false;
*/
}
void CPicture::createSimpleRect(const Rect &r, bool screenFormat, ui32 color)
@ -153,12 +157,12 @@ void CPicture::createSimpleRect(const Rect &r, bool screenFormat, ui32 color)
pos += r;
pos.w = r.w;
pos.h = r.h;
if(screenFormat)
/* if(screenFormat)
bg = CSDL_Ext::newSurface(r.w, r.h);
else
bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0);
SDL_FillRect(bg, NULL, color);
SDL_FillRect(bg, NULL, color); */
freeSurf = true;
}
@ -172,8 +176,8 @@ void CPicture::colorizeAndConvert(PlayerColor player)
void CPicture::colorize(PlayerColor player)
{
assert(bg);
assert(bg->format->BitsPerPixel == 8);
graphics->blueToPlayersAdv(bg, player);
//* assert(bg->format->BitsPerPixel == 8);
//* graphics->blueToPlayersAdv(bg, player);
}
CFilledTexture::CFilledTexture(std::string imageName, Rect position):
@ -189,10 +193,10 @@ CFilledTexture::~CFilledTexture()
SDL_FreeSurface(texture);
}
void CFilledTexture::showAll(SDL_Surface *to)
void CFilledTexture::showAll()
{
CSDL_Ext::CClipRectGuard guard(to, pos);
CSDL_Ext::fillTexture(to, texture);
//* CSDL_Ext::CClipRectGuard guard(to, pos);
//* CSDL_Ext::fillTexture(to, texture);
}
CButtonBase::CButtonBase()
@ -223,8 +227,8 @@ void CButtonBase::update()
if (newPos < 0)
newPos = 0;
if (state == HIGHLIGHTED && image->size() < 4)
newPos = image->size()-1;
if (state == HIGHLIGHTED && image->getFramesCount() < 4)
newPos = image->getFramesCount()-1;
if (swappedImages)
{
@ -232,8 +236,8 @@ void CButtonBase::update()
else if (newPos == 1) newPos = 0;
}
if (!keepFrame)
image->setFrame(newPos);
//* if (!keepFrame)
//* image->setFrame(newPos);
if (active)
redraw();
@ -310,6 +314,7 @@ CAdventureMapButton::CAdventureMapButton( const std::pair<std::string, std::stri
pom[0] = help.first;
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
}
void CAdventureMapButton::clickLeft(tribool down, bool previousState)
{
if(isBlocked())
@ -412,34 +417,36 @@ void CAdventureMapButton::setIndex(size_t index, bool playerColoredButton)
if (index == currentImage || index>=imageNames.size())
return;
currentImage = index;
setImage(new CAnimation(imageNames[index]), playerColoredButton);
setImage(Gfx::CManager::getAnimation(imageNames[index]));
}
void CAdventureMapButton::setImage(CAnimation* anim, bool playerColoredButton, int animFlags)
void CAdventureMapButton::setImage(Gfx::PAnimation anim, bool playerColoredButton, int animFlags)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
delete image;
image = new CAnimImage(anim, getState(), 0, 0, 0, animFlags);
if (playerColoredButton)
image->playerColored(LOCPLINT->playerID);
image = anim; //new CAnimImage(anim, getState(), 0, 0, 0, animFlags);
//* if (playerColoredButton)
//* image->playerColored(LOCPLINT->playerID);
pos.w = image->getWidth();
pos.h = image->getHeight();
pos.w = image->pos.w;
pos.h = image->pos.h;
}
void CAdventureMapButton::setPlayerColor(PlayerColor player)
{
if (image)
image->playerColored(player);
// if (image)
// image->playerColored(player);
}
void CAdventureMapButton::showAll(SDL_Surface * to)
void CAdventureMapButton::showAll()
{
CIntObject::showAll(to);
image->getFrame(0)->putAt(Gfx::Point(pos.x, pos.y));
if (borderEnabled && borderColor.unused == 0)
CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b));
CIntObject::showAll();
//* if (borderEnabled && borderColor.unused == 0)
//* CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b));
}
void CHighlightableButton::select(bool on)
@ -571,28 +578,28 @@ void CHighlightableButtonsGroup::selectionChanged(int to)
parent->redraw();
}
void CHighlightableButtonsGroup::show(SDL_Surface * to)
void CHighlightableButtonsGroup::show()
{
if (musicLike)
{
for(size_t i=0;i<buttons.size(); ++i)
if(buttons[i]->isHighlighted())
buttons[i]->show(to);
buttons[i]->show();
}
else
CIntObject::show(to);
CIntObject::show();
}
void CHighlightableButtonsGroup::showAll(SDL_Surface * to)
void CHighlightableButtonsGroup::showAll()
{
if (musicLike)
{
for(size_t i=0;i<buttons.size(); ++i)
if(buttons[i]->isHighlighted())
buttons[i]->showAll(to);
buttons[i]->showAll();
}
else
CIntObject::showAll(to);
CIntObject::showAll();
}
void CHighlightableButtonsGroup::block( ui8 on )
@ -770,11 +777,11 @@ CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int
if(style == 0)
{
std::string name = horizontal?"IGPCRDIV.DEF":"OVBUTN2.DEF";
std::string name = horizontal ? "IGPCRDIV":"OVBUTN2";
//NOTE: this images do not have "blocked" frames. They should be implemented somehow (e.g. palette transform or something...)
//use source def to create custom animations. Format "name.def:123" will load this frame from def file
CAnimation *animLeft = new CAnimation();
/* CAnimation *animLeft = new CAnimation();
animLeft->setCustom(name + ":0", 0);
animLeft->setCustom(name + ":1", 1);
left->setImage(animLeft);
@ -787,12 +794,13 @@ CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int
CAnimation *animSlider = new CAnimation();
animSlider->setCustom(name + ":4", 0);
slider->setImage(animSlider);
*/
}
else
{
left->setImage(new CAnimation(horizontal ? "SCNRBLF.DEF" : "SCNRBUP.DEF"));
right->setImage(new CAnimation(horizontal ? "SCNRBRT.DEF" : "SCNRBDN.DEF"));
slider->setImage(new CAnimation("SCNRBSL.DEF"));
left->setImage(Gfx::CManager::getAnimation(horizontal ? "SCNRBLF" : "SCNRBUP"));
right->setImage(Gfx::CManager::getAnimation(horizontal ? "SCNRBRT" : "SCNRBDN"));
slider->setImage(Gfx::CManager::getAnimation("SCNRBSL"));
}
slider->actOnDown = true;
slider->soundDisabled = true;
@ -817,10 +825,10 @@ void CSlider::setAmount( int to )
vstd::amax(positions, 0);
}
void CSlider::showAll(SDL_Surface * to)
void CSlider::showAll()
{
CSDL_Ext::fillRect(to, &pos, 0);
CIntObject::showAll(to);
//* CSDL_Ext::fillRect(to, &pos, 0);
CIntObject::showAll();
}
void CSlider::wheelScrolled(bool down, bool in)
@ -1085,11 +1093,12 @@ const std::list<CIntObject *> &CListBox::getItems()
return items;
}
void CSimpleWindow::show(SDL_Surface * to)
void CSimpleWindow::show()
{
if(bitmap)
blitAt(bitmap,pos.x,pos.y,to);
//* if(bitmap)
//* blitAt(bitmap,pos.x,pos.y,to);
}
CSimpleWindow::~CSimpleWindow()
{
if (bitmap)
@ -1150,16 +1159,16 @@ void LRClickableAreaWText::init()
addUsedEvents(LCLICK | RCLICK | HOVER);
}
void CLabel::showAll(SDL_Surface * to)
void CLabel::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
std::string toPrint = visibleText();
if(!toPrint.length())
return;
//blitLine(to, pos.topLeft()/2 + pos.bottomRight()/2, toPrint);
blitLine(to, pos.topLeft() + textOffset, toPrint);
//* blitLine(to, pos.topLeft() + textOffset, toPrint);
}
@ -1260,9 +1269,9 @@ CTextContainer::CTextContainer(EAlignment alignment, EFonts font, SDL_Color colo
color(color)
{}
void CBoundedLabel::showAll(SDL_Surface * to)
void CBoundedLabel::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
const IFont * f = graphics->fonts[font];
int lineHeight = f->getLineHeight();
@ -1285,7 +1294,7 @@ void CBoundedLabel::showAll(SDL_Surface * to)
x += pos.w - f->getStringWidth(line.c_str()) / 2;
}
blitLine(to, Point(x, base_y + i * dy), line);
//* blitLine(to, Point(x, base_y + i * dy), line);
}
}
@ -1352,9 +1361,9 @@ void CTextBox::recalculateLines(const std::string &Txt)
vstd::amax(maxW, f->getStringWidth(line));
}
void CTextBox::showAll(SDL_Surface * to)
void CTextBox::showAll()
{
CIntObject::showAll(to);
CIntObject::showAll();
const IFont * f = graphics->fonts[font];
int dy = f->getLineHeight(); //line height
@ -1374,7 +1383,7 @@ void CTextBox::showAll(SDL_Surface * to)
int width = pos.w + (slider ? (slider->pos.w) : 0);
int x = pos.x + int(alignment) * width / 2;
blitLine(to, Point(x, base_y + i * dy), line);
//* blitLine(to, Point(x, base_y + i * dy), line);
}
}
@ -1444,9 +1453,9 @@ CGStatusBar::~CGStatusBar()
GH.statusbar = oldStatusBar;
}
void CGStatusBar::show(SDL_Surface * to)
void CGStatusBar::show()
{
showAll(to);
showAll();
}
void CGStatusBar::init()
@ -1511,10 +1520,10 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
OBJ_CONSTRUCTION;
bg = new CPicture(Pos, 0, true);
Rect hlp = Pos;
if(srf)
/* if(srf)
CSDL_Ext::blitSurface(srf, &hlp, *bg, NULL);
else
SDL_FillRect(*bg, NULL, 0);
SDL_FillRect(*bg, NULL, 0); */
pos.w = bg->pos.w;
pos.h = bg->pos.h;
bg->pos = pos;
@ -1847,26 +1856,26 @@ void CWindowObject::setShadow(bool on)
fullsize = Point(pos.w, pos.h);
//create base 8x8 piece of shadow
SDL_Surface * shadowCorner = CSDL_Ext::copySurface(shadowCornerTempl);
SDL_Surface * shadowBottom = CSDL_Ext::scaleSurfaceFast(shadowBottomTempl, fullsize.x - size, size);
SDL_Surface * shadowRight = CSDL_Ext::scaleSurfaceFast(shadowRightTempl, size, fullsize.y - size);
//* SDL_Surface * shadowCorner = CSDL_Ext::copySurface(shadowCornerTempl);
//* SDL_Surface * shadowBottom = CSDL_Ext::scaleSurfaceFast(shadowBottomTempl, fullsize.x - size, size);
//* SDL_Surface * shadowRight = CSDL_Ext::scaleSurfaceFast(shadowRightTempl, size, fullsize.y - size);
blitAlphaCol(shadowBottom, 0);
blitAlphaRow(shadowRight, 0);
//* blitAlphaCol(shadowBottom, 0);
//* blitAlphaRow(shadowRight, 0);
//generate "shadow" object with these 3 pieces in it
shadow = new CIntObject;
shadow->addChild(new CPicture(shadowCorner, shadowPos.x, shadowPos.y));
shadow->addChild(new CPicture(shadowRight, shadowPos.x, shadowStart.y));
shadow->addChild(new CPicture(shadowBottom, shadowStart.x, shadowPos.y));
//* shadow->addChild(new CPicture(shadowCorner, shadowPos.x, shadowPos.y));
//* shadow->addChild(new CPicture(shadowRight, shadowPos.x, shadowStart.y));
//* shadow->addChild(new CPicture(shadowBottom, shadowStart.x, shadowPos.y));
}
}
void CWindowObject::showAll(SDL_Surface *to)
void CWindowObject::showAll()
{
CIntObject::showAll(to);
if ((options & BORDERED) && (pos.h != to->h || pos.w != to->w))
CMessage::drawBorder(LOCPLINT ? LOCPLINT->playerID : PlayerColor(1), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
CIntObject::showAll();
if ((options & BORDERED) && (pos.w != GL2D::getScreenWidth() || pos.h != GL2D::getScreenHeight()))
CMessage::drawBorder(LOCPLINT ? LOCPLINT->playerID : PlayerColor(1), nullptr, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
}
void CWindowObject::close()

View File

@ -3,6 +3,7 @@
#include "CIntObject.h"
#include "SDL_Extensions.h"
#include "../FunctionList.h"
#include "../Gfx/Manager.h"
struct SDL_Surface;
struct Rect;
@ -26,7 +27,7 @@ class CSimpleWindow : public CIntObject
{
public:
SDL_Surface * bitmap; //background
virtual void show(SDL_Surface * to);
virtual void show();
CSimpleWindow():bitmap(NULL){}; //c-tor
virtual ~CSimpleWindow(); //d-tor
};
@ -35,22 +36,20 @@ public:
class CPicture : public CIntObject
{
void setSurface(SDL_Surface *to);
Gfx::PImage bg;
public:
SDL_Surface * bg;
Rect * srcRect; //if NULL then whole surface will be used
bool freeSurf; //whether surface will be freed upon CPicture destruction
bool needRefresh;//Surface needs to be displayed each frame
operator SDL_Surface*()
{
return bg;
}
inline Gfx::PImage getImage() { return bg; };
CPicture(const Rect & r, const SDL_Color & color, bool screenFormat = false); //rect filled with given color
CPicture(const Rect & r, ui32 color, bool screenFormat = false); //rect filled with given color
CPicture(SDL_Surface * BG, int x = 0, int y=0, bool Free = true); //wrap existing SDL_Surface
CPicture(Gfx::PImage BG, int x = 0, int y=0, bool Free = true); //wrap existing SDL_Surface
CPicture(const std::string &bmpname, int x=0, int y=0);
CPicture(SDL_Surface *BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface
CPicture(Gfx::PImage BG, const Rect &SrcRext, int x = 0, int y = 0, bool free = false); //wrap subrect of given surface
~CPicture();
void init();
@ -60,8 +59,8 @@ public:
void scaleTo(Point size);
void createSimpleRect(const Rect &r, bool screenFormat, ui32 color);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
void convertToScreenBPP();
void colorizeAndConvert(PlayerColor player);
void colorize(PlayerColor player);
@ -75,7 +74,7 @@ class CFilledTexture : CIntObject
public:
CFilledTexture(std::string imageName, Rect position);
~CFilledTexture();
void showAll(SDL_Surface *to);
void showAll();
};
namespace config{struct ButtonInfo;}
@ -111,7 +110,7 @@ public:
bool isBlocked();
bool isHighlighted();
CAnimImage * image; //image for this button
Gfx::PAnimation image; //image for this button
CLabel * text;//text overlay
CButtonBase(); //c-tor
@ -146,9 +145,9 @@ public:
void init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key );
void setIndex(size_t index, bool playerColoredButton=false);
void setImage(CAnimation* anim, bool playerColoredButton=false, int animFlags=0);
void setImage(Gfx::PAnimation anim, bool playerColoredButton=false, int animFlags=0);
void setPlayerColor(PlayerColor player);
void showAll(SDL_Surface * to);
void showAll();
};
/// A button which can be selected/deselected
@ -182,8 +181,8 @@ public:
~CHighlightableButtonsGroup();
void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id
void selectionChanged(int to);
void show(SDL_Surface * to);
void showAll(SDL_Surface * to);
void show();
void showAll();
void block(ui8 on);
};
@ -214,7 +213,7 @@ public:
void wheelScrolled(bool down, bool in);
void clickLeft(tribool down, bool previousState);
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void showAll(SDL_Surface * to);
void showAll();
CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount,
int Value=0, bool Horizontal=true, int style = 0); //style 0 - brown, 1 - blue
@ -340,7 +339,7 @@ public:
bool ignoreLeadingWhitespace;
virtual void setTxt(const std::string &Txt);
void showAll(SDL_Surface * to); //shows statusbar (with current text)
void showAll(); //shows statusbar (with current text)
CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE, const std::string &Text = "");
};
@ -358,7 +357,7 @@ public:
void setTxt(const std::string &Txt);
void setBounds(int limitW, int limitH);
virtual void recalculateLines(const std::string &Txt);
void showAll(SDL_Surface * to);
void showAll();
};
//Small helper class to manage group of similar labels
@ -385,7 +384,7 @@ public:
//CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE);
CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE);
void showAll(SDL_Surface * to); //shows statusbar (with current text)
void showAll(); //shows statusbar (with current text)
void recalculateLines(const std::string &Txt);
void sliderMoved(int to);
@ -403,7 +402,7 @@ public:
void print(const std::string & Text); //prints text and refreshes statusbar
void clear();//clears statusbar and refreshes
std::string getCurrent(); //returns currently displayed text
void show(SDL_Surface * to); //shows statusbar (with current text)
void show(); //shows statusbar (with current text)
//CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::WHITE, const std::string &Text = "");
CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::WHITE); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
@ -504,7 +503,7 @@ protected:
//Used only if RCLICK_POPUP was set
void clickRight(tribool down, bool previousState);
//To display border
void showAll(SDL_Surface *to);
void showAll();
//change or set background image
void setBackground(std::string filename);
void updateShadow();

242
client/UIFramework/GL2D.cpp Normal file
View File

@ -0,0 +1,242 @@
#include "StdInc.h"
#include <SDL.h>
#include <SDL_video.h>
#include "SDL_syswm.h"
#include <SDL_opengl.h>
#include "GL2D.h"
namespace GL2D
{
// Variables initialized by initVideo, updated by setScreenRes:
static SDL_SysWMinfo wmInfo;
ui32 screenWidth = 0, screenHeight = 0; // Screen/Window size
// OpenGL 1.3 functions pointers
PFNGLACTIVETEXTUREPROC glActiveTexture;
// OpenGL 2.0 functions pointers
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLUNIFORM2IPROC glUniform2i;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
// Shaders' sources
static const char frag_palette_bitmap[] = (
"uniform usampler2DRect bitmap;"
"uniform sampler1D palette;"
"uniform ivec2 coordOffs;"
"layout (origin_upper_left) in vec4 gl_FragCoord;"
"void main(){"
"gl_FragColor = texelFetch(palette, int(texelFetch(bitmap, ivec2(gl_FragCoord.xy) - coordOffs).r), 0);"
"}"
);
// Programs' handlers
static GLuint currentProgram = 0;
static GLuint colorizeProgram = 0;
static GLuint paletteBitmapProgram = 0;
// Uniforms handlers
static GLint coord_uniform = -1;
// Print out the information log for a shader object
void printInfoLog(PFNGLGETPROGRAMINFOLOGPROC logFunc, GLuint object)
{
if (logFunc != nullptr)
{
GLsizei infoLogLength = 0;
GLchar infoLog[1024];
logFunc(object, sizeof(infoLog)-1, &infoLogLength, infoLog);
if (infoLogLength > 0) tlog1 << infoLog;
}
}
GLuint makeShaderProgram(const char * frg_src)
{
// Creating a fragment shader object
GLuint shader_object = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader_object, 1, &frg_src, nullptr); // assigning the shader source
// Compiling the shader
glCompileShader(shader_object);
printInfoLog(glGetShaderInfoLog, shader_object);
// Creating a program object
GLuint program_object = glCreateProgram();
// Attaching the shader into program
glAttachShader(program_object, shader_object);
// Link the shaders into a complete GLSL program.
glLinkProgram(program_object);
printInfoLog(glGetProgramInfoLog, program_object);
return program_object;
}
void initVideo(ui32 w, ui32 h, bool fullscreen)
{
SDL_VERSION(&wmInfo.version);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (!setScreenRes(w, h, fullscreen))
{
throw std::runtime_error("Video mode setting failed\n");
}
glClearColor(0, 0, 0, 0); // Black Background
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapBuffers();
// Dynamic-linked OpenGL 1.3 and 2.0 functions - required to 2D rendeing
if ( (glActiveTexture = (PFNGLACTIVETEXTUREPROC) SDL_GL_GetProcAddress("glActiveTexture")) == nullptr
|| (glCreateProgram = (PFNGLCREATEPROGRAMPROC) SDL_GL_GetProcAddress("glCreateProgram")) == nullptr
|| (glCreateShader = (PFNGLCREATESHADERPROC) SDL_GL_GetProcAddress("glCreateShader")) == nullptr
|| (glShaderSource = (PFNGLSHADERSOURCEPROC) SDL_GL_GetProcAddress("glShaderSource")) == nullptr
|| (glCompileShader = (PFNGLCOMPILESHADERPROC) SDL_GL_GetProcAddress("glCompileShader")) == nullptr
|| (glAttachShader = (PFNGLATTACHSHADERPROC) SDL_GL_GetProcAddress("glAttachShader")) == nullptr
|| (glLinkProgram = (PFNGLLINKPROGRAMPROC) SDL_GL_GetProcAddress("glLinkProgram")) == nullptr
|| (glUseProgram = (PFNGLUSEPROGRAMPROC) SDL_GL_GetProcAddress("glUseProgram")) == nullptr
|| (glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) SDL_GL_GetProcAddress("glGetUniformLocation")) == nullptr
|| (glUniform1i = (PFNGLUNIFORM1IPROC) SDL_GL_GetProcAddress("glUniform1i")) == nullptr
|| (glUniform2i = (PFNGLUNIFORM2IPROC) SDL_GL_GetProcAddress("glUniform2i")) == nullptr
)
{
tlog1 << "Error: OpenGL2 Extenstions are not available\n";
tlog1 << "SDL says: " << SDL_GetError() << std::endl;
throw std::runtime_error("OpenGL2 Extenstions are not available\n");
}
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) SDL_GL_GetProcAddress("glGetProgramInfoLog"); // not required
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) SDL_GL_GetProcAddress("glGetShaderInfoLog"); // not required
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_DITHER);
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
paletteBitmapProgram = makeShaderProgram(frag_palette_bitmap);
GLint bitmap_uniform = glGetUniformLocation(paletteBitmapProgram, "bitmap");
GLint palette_uniform = glGetUniformLocation(paletteBitmapProgram, "palette");
coord_uniform = glGetUniformLocation(paletteBitmapProgram, "coordOffs");
glUseProgram(currentProgram = paletteBitmapProgram);
glUniform1i(bitmap_uniform, 0);
glUniform1i(palette_uniform, 1);
#ifdef _WIN32
wglMakeCurrent(NULL, NULL);
#endif
}
void attachToCurrentThread()
{
#ifdef _WIN32
HDC hdc = GetDC(wmInfo.window);
wglMakeCurrent(hdc, wmInfo.hglrc);
#endif
}
bool setScreenRes(ui32 w, ui32 h, bool fullscreen)
{
// Try to use the best screen depth for the display
int suggestedBpp = SDL_VideoModeOK(w, h, 32, SDL_OPENGL | SDL_ANYFORMAT | (fullscreen?SDL_FULLSCREEN:0));
if(suggestedBpp == 0)
{
tlog1 << "Error: SDL says that " << w << "x" << h << " resolution is not available!\n";
return false;
}
if(suggestedBpp != 32)
{
tlog2 << "Note: SDL suggests to use " << suggestedBpp << " bpp instead of 32 bpp\n";
}
if(SDL_SetVideoMode(w, h, suggestedBpp, SDL_OPENGL | SDL_ANYFORMAT | (fullscreen?SDL_FULLSCREEN:0)) == NULL)
{
tlog1 << "Error: Video mode setting failed (" << w << "x" << h << "x" << suggestedBpp << "bpp)\n";
return false;
}
screenWidth = w; screenHeight = h;
int getwm = SDL_GetWMInfo(&wmInfo);
if(getwm != 1)
{
tlog2 << "Something went wrong, getwm=" << getwm << std::endl;
tlog2 << "SDL says: " << SDL_GetError() << std::endl;
return false;
}
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glOrtho(0, w, h, 0, 0, 1);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glTranslatef(0.375, 0.375, 0); // Displacement trick for exact pixelization
return true;
}
void assignTexture(ui32 slot, ui32 type, ui32 handle)
{
glActiveTexture(slot);
glBindTexture(type, handle);
}
void useNoShader()
{
if (currentProgram != 0) {
glUseProgram(currentProgram = 0);
}
}
void useColorizeShader(const float cm[4][4])
{
if (currentProgram != colorizeProgram) {
glUseProgram(currentProgram = colorizeProgram);
}
}
void usePaletteBitmapShader(si32 x, si32 y)
{
if (currentProgram != paletteBitmapProgram) {
glUseProgram(currentProgram = paletteBitmapProgram);
}
glUniform2i(coord_uniform, x, y);
}
void usePaletteBitmapShader(si32 x, si32 y, const float cm[4][4])
{
if (currentProgram != paletteBitmapProgram) {
glUseProgram(currentProgram = paletteBitmapProgram);
}
glUniform2i(coord_uniform, x, y);
}
}

17
client/UIFramework/GL2D.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
namespace GL2D
{
void initVideo(ui32 w, ui32 h, bool fullscreen);
void attachToCurrentThread();
bool setScreenRes(ui32 w, ui32 h, bool fullscreen);
inline ui32 getScreenWidth() { extern ui32 screenWidth; return screenWidth; };
inline ui32 getScreenHeight() { extern ui32 screenHeight; return screenHeight; };
void assignTexture(ui32 slot, ui32 type, ui32 handle);
void useNoShader();
void useColorizeShader(const float cm[4][4]);
void usePaletteBitmapShader(si32 x, si32 y);
void usePaletteBitmapShader(si32 x, si32 y, const float cm[4][4]);
}

View File

@ -51,9 +51,9 @@ bool isItIn(const SDL_Rect * rect, int x, int y)
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst)
{
if(!dst) dst = screen;
SDL_Rect pom = genRect(src->h,src->w,x,y);
CSDL_Ext::blitSurface(src,NULL,dst,&pom);
//if(!dst) dst = screen;
//SDL_Rect pom = genRect(src->h,src->w,x,y);
//CSDL_Ext::blitSurface(src,NULL,dst,&pom);
}
void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst)
@ -81,6 +81,8 @@ void updateRect (SDL_Rect * rect, SDL_Surface * scr)
SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
{
SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
if (ret == nullptr) return nullptr;
const int bpl = ret->pitch;
const int bpp = ret->format->BytesPerPixel;

View File

@ -33,12 +33,12 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_xp</PlatformToolset>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v110_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
@ -103,7 +103,7 @@
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalDependencies>SDL.lib;zlib.lib;SDL_image.lib;SDL_ttf.lib;SDL_mixer.lib;VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL.lib;zlib.lib;opengl32.lib;SDL_image.lib;SDL_ttf.lib;SDL_mixer.lib;VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<OptimizeReferences>false</OptimizeReferences>
<Profile>true</Profile>
@ -184,6 +184,11 @@
<ClCompile Include="CQuestLog.cpp" />
<ClCompile Include="CSpellWindow.cpp" />
<ClCompile Include="CVideoHandler.cpp" />
<ClCompile Include="Gfx\Animations.cpp" />
<ClCompile Include="Gfx\CPaletteRGBA.cpp" />
<ClCompile Include="Gfx\Images.cpp" />
<ClCompile Include="Gfx\ImgMakers.cpp" />
<ClCompile Include="Gfx\Manager.cpp" />
<ClCompile Include="Graphics.cpp" />
<ClCompile Include="GUIClasses.cpp" />
<ClCompile Include="mapHandler.cpp" />
@ -201,6 +206,7 @@
<ClCompile Include="UIFramework\CIntObjectClasses.cpp" />
<ClCompile Include="UIFramework\Fonts.cpp" />
<ClCompile Include="UIFramework\Geometries.cpp" />
<ClCompile Include="UIFramework\GL2D.cpp" />
<ClCompile Include="UIFramework\SDL_Extensions.cpp" />
</ItemGroup>
<ItemGroup>
@ -231,6 +237,11 @@
<ClInclude Include="CVideoHandler.h" />
<ClInclude Include="FontBase.h" />
<ClInclude Include="FunctionList.h" />
<ClInclude Include="Gfx\Animations.h" />
<ClInclude Include="Gfx\CPaletteRGBA.h" />
<ClInclude Include="Gfx\Images.h" />
<ClInclude Include="Gfx\FilesHeaders.h" />
<ClInclude Include="Gfx\Manager.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="GUIClasses.h" />
<ClInclude Include="mapHandler.h" />
@ -242,6 +253,7 @@
<ClInclude Include="UIFramework\CIntObjectClasses.h" />
<ClInclude Include="UIFramework\Fonts.h" />
<ClInclude Include="UIFramework\Geometries.h" />
<ClInclude Include="UIFramework\GL2D.h" />
<ClInclude Include="UIFramework\SDL_Extensions.h" />
<ClInclude Include="UIFramework\SDL_Pixels.h" />
</ItemGroup>

View File

@ -30,13 +30,37 @@
<ClCompile Include="NetPacksClient.cpp" />
<ClCompile Include="StdInc.cpp" />
<ClCompile Include="UIFramework\CCursorHandler.cpp" />
<ClCompile Include="UIFramework\CGuiHandler.cpp" />
<ClCompile Include="UIFramework\CIntObject.cpp" />
<ClCompile Include="UIFramework\CIntObjectClasses.cpp" />
<ClCompile Include="UIFramework\Geometries.cpp" />
<ClCompile Include="UIFramework\SDL_Extensions.cpp" />
<ClCompile Include="CQuestLog.cpp" />
<ClCompile Include="UIFramework\Fonts.cpp" />
<ClCompile Include="Gfx\Animations.cpp">
<Filter>Gfx</Filter>
</ClCompile>
<ClCompile Include="Gfx\Images.cpp">
<Filter>Gfx</Filter>
</ClCompile>
<ClCompile Include="Gfx\ImgMakers.cpp">
<Filter>Gfx</Filter>
</ClCompile>
<ClCompile Include="Gfx\CPaletteRGBA.cpp">
<Filter>Gfx</Filter>
</ClCompile>
<ClCompile Include="Gfx\Manager.cpp">
<Filter>Gfx</Filter>
</ClCompile>
<ClCompile Include="UIFramework\CIntObjectClasses.cpp">
<Filter>UIFramework</Filter>
</ClCompile>
<ClCompile Include="UIFramework\CIntObject.cpp">
<Filter>UIFramework</Filter>
</ClCompile>
<ClCompile Include="UIFramework\GL2D.cpp">
<Filter>UIFramework</Filter>
</ClCompile>
<ClCompile Include="UIFramework\CGuiHandler.cpp">
<Filter>UIFramework</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Global.h" />
@ -70,8 +94,6 @@
<ClInclude Include="resource.h" />
<ClInclude Include="StdInc.h" />
<ClInclude Include="UIFramework\CCursorHandler.h" />
<ClInclude Include="UIFramework\CGuiHandler.h" />
<ClInclude Include="UIFramework\CIntObject.h" />
<ClInclude Include="UIFramework\CIntObjectClasses.h" />
<ClInclude Include="UIFramework\Geometries.h" />
<ClInclude Include="UIFramework\SDL_Extensions.h" />
@ -82,6 +104,30 @@
</ClCompile>
<ClInclude Include="mapHandler.h" />
<ClInclude Include="UIFramework\Fonts.h" />
<ClInclude Include="Gfx\Animations.h">
<Filter>Gfx</Filter>
</ClInclude>
<ClInclude Include="Gfx\Images.h">
<Filter>Gfx</Filter>
</ClInclude>
<ClInclude Include="Gfx\FilesHeaders.h">
<Filter>Gfx</Filter>
</ClInclude>
<ClInclude Include="Gfx\CPaletteRGBA.h">
<Filter>Gfx</Filter>
</ClInclude>
<ClInclude Include="Gfx\Manager.h">
<Filter>Gfx</Filter>
</ClInclude>
<ClInclude Include="UIFramework\CIntObject.h">
<Filter>UIFramework</Filter>
</ClInclude>
<ClInclude Include="UIFramework\GL2D.h">
<Filter>UIFramework</Filter>
</ClInclude>
<ClInclude Include="UIFramework\CGuiHandler.h">
<Filter>UIFramework</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="VCMI_client.rc" />
@ -93,4 +139,12 @@
<None Include="..\ChangeLog" />
<None Include="vcmi.ico" />
</ItemGroup>
<ItemGroup>
<Filter Include="Gfx">
<UniqueIdentifier>{215917eb-e8a3-400a-8e1a-d027a532bf3d}</UniqueIdentifier>
</Filter>
<Filter Include="UIFramework">
<UniqueIdentifier>{1ffcd26b-1f6e-4274-8245-3572b26afed5}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@ -90,7 +90,7 @@ std::unique_ptr<CInputStream> CResourceLoader::load(const ResourceID & resourceI
const ResourceLocator & locator = resource->second.back();
// load the resource and return it
return locator.getLoader()->load(locator.getResourceName());
return locator.load();
}
std::pair<std::unique_ptr<ui8[]>, ui64> CResourceLoader::loadData(const ResourceID & resourceIdent) const
@ -201,20 +201,9 @@ CResourceLoader * CResourceHandler::get()
// CResourceLoaderFactory::resourceLoader = resourceLoader;
//}
ResourceLocator::ResourceLocator(ISimpleResourceLoader * loader, const std::string & resourceName)
: loader(loader), resourceName(resourceName)
std::unique_ptr<CInputStream> ResourceLocator::load() const
{
}
ISimpleResourceLoader * ResourceLocator::getLoader() const
{
return loader;
}
std::string ResourceLocator::getResourceName() const
{
return resourceName;
return loader->load(resourceName);
}
EResType::Type EResTypeHelper::getTypeFromExtension(std::string extension)

View File

@ -409,21 +409,31 @@ public:
* @param archive A pointer to the resource archive object.
* @param resourceName Unique resource name in the space of the given resource archive.
*/
ResourceLocator(ISimpleResourceLoader * loader, const std::string & resourceName);
inline ResourceLocator(ISimpleResourceLoader * ldr, const std::string & resName)
: loader(ldr), resourceName(resName) {};
/**
* Gets a pointer to the resource loader object.
*
* @return a pointer to the resource loader object
*/
ISimpleResourceLoader * getLoader() const;
inline ISimpleResourceLoader * getLoader() const { return loader; };
/**
* Gets the resource name.
*
* @return the resource name.
*/
std::string getResourceName() const;
inline std::string getResourceName() const { return resourceName; };
/**
* Loads the resource.
*
* @return a pointer to the input stream, not null
*
* @throws std::runtime_error if the resource doesn't exists
*/
std::unique_ptr<CInputStream> load() const;
private:
/**

View File

@ -33,7 +33,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_xp</PlatformToolset>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>