* forgot to add files in prev. commit
* added BLP related files to vc71 project
This commit is contained in:
parent
0397d33989
commit
3f9686eaed
137
src/Client/GUI/CCursorController.cpp
Normal file
137
src/Client/GUI/CCursorController.cpp
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
#include "CCursorController.h"
|
||||||
|
|
||||||
|
CCursorController::CCursorController(ICursorControl* irrCursor, IVideoDriver* irrVideoDriver) :
|
||||||
|
m_pMouseCursor(0), used(0), irrCursorControl(irrCursor), videoDriver(irrVideoDriver)
|
||||||
|
{
|
||||||
|
updateMousePos();
|
||||||
|
|
||||||
|
setVisible(true);
|
||||||
|
setOSCursorVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCursorController::~CCursorController()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::setVisible(bool visible)
|
||||||
|
{
|
||||||
|
IsVisible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCursorController::isVisible() const
|
||||||
|
{
|
||||||
|
return IsVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::setOSCursorVisible(bool visible)
|
||||||
|
{
|
||||||
|
IsOSCursorVisible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCursorController::isOSCursorVisible() const
|
||||||
|
{
|
||||||
|
return IsOSCursorVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::render()
|
||||||
|
{
|
||||||
|
updateMousePos();
|
||||||
|
|
||||||
|
if(isVisible() && used)
|
||||||
|
{
|
||||||
|
_IRR_DEBUG_BREAK_IF(!m_pMouseCursor); // There isn't any cursor texture loaded
|
||||||
|
if(m_pMouseCursor)
|
||||||
|
{
|
||||||
|
videoDriver->draw2DImage(m_pMouseCursor,
|
||||||
|
topleft ? position2di(m_MousePos.X,m_MousePos.Y) : position2di(m_MousePos.X - m_pMouseCursor->getSize().Width/2+1,
|
||||||
|
m_MousePos.Y - m_pMouseCursor->getSize().Height/2+2),
|
||||||
|
rect<s32>(position2di(0,0),m_pMouseCursor->getSize()),
|
||||||
|
0, SColor(140,255,255,255), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isOSCursorVisible())
|
||||||
|
{
|
||||||
|
irrCursorControl->setVisible(true);
|
||||||
|
irrCursorControl->setPosition(irrCursorControl->getPosition());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
irrCursorControl->setVisible(false);
|
||||||
|
irrCursorControl->setPosition(irrCursorControl->getPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::addMouseCursorTexture(c8* Cursor_file, bool top_left)
|
||||||
|
{
|
||||||
|
m_pMouseCursor = videoDriver->getTexture(Cursor_file);
|
||||||
|
|
||||||
|
bool isAlreadyLoaded = false;
|
||||||
|
for(u32 i = 0; i < m_aMouseCursors.size() && !isAlreadyLoaded; i++)
|
||||||
|
{
|
||||||
|
if(m_aMouseCursors[i].tex->getName() == m_pMouseCursor->getName())
|
||||||
|
{
|
||||||
|
isAlreadyLoaded = !isAlreadyLoaded;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAlreadyLoaded)
|
||||||
|
{
|
||||||
|
videoDriver->makeColorKeyTexture(m_pMouseCursor, SColor(255,0,0,0));
|
||||||
|
|
||||||
|
m_aMouseCursors.push_back(TexBoolPair(m_pMouseCursor,top_left));
|
||||||
|
used++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// So the first loaded cursor will be active
|
||||||
|
if(used > 0)
|
||||||
|
setActiveCursor(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITexture* CCursorController::getCursorTexture(u32 index) const
|
||||||
|
{
|
||||||
|
_IRR_DEBUG_BREAK_IF(index>used); // access violation
|
||||||
|
|
||||||
|
return m_aMouseCursors[index].tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::removeCursor(u32 index)
|
||||||
|
{
|
||||||
|
_IRR_DEBUG_BREAK_IF(index>used); // access violation
|
||||||
|
|
||||||
|
videoDriver->removeTexture(m_aMouseCursors[index].tex);
|
||||||
|
m_aMouseCursors.erase(index);
|
||||||
|
used--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::setActiveCursor(u32 index)
|
||||||
|
{
|
||||||
|
_IRR_DEBUG_BREAK_IF(index>used); // access violation
|
||||||
|
|
||||||
|
m_pMouseCursor = m_aMouseCursors[index].tex;
|
||||||
|
topleft = m_aMouseCursors[index].topleft;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCursorController::Clear()
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < m_aMouseCursors.size(); i++)
|
||||||
|
{
|
||||||
|
removeCursor(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_aMouseCursors.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
position2di& CCursorController::getMousePos()
|
||||||
|
{
|
||||||
|
return updateMousePos();
|
||||||
|
}
|
||||||
|
|
||||||
|
position2di& CCursorController::updateMousePos()
|
||||||
|
{
|
||||||
|
m_MousePos = irrCursorControl->getPosition();
|
||||||
|
|
||||||
|
return m_MousePos;
|
||||||
|
}
|
||||||
59
src/Client/GUI/CCursorController.h
Normal file
59
src/Client/GUI/CCursorController.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Copyright (c) 2007-2008 Tomer Nosrati
|
||||||
|
// This file is part of the "NUSoftware Game Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in nge.h
|
||||||
|
|
||||||
|
#ifndef __C_CURSOR_H__
|
||||||
|
#define __C_CURSOR_H__
|
||||||
|
|
||||||
|
#include "irrlicht/irrlicht.h"
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
using namespace irr::core;
|
||||||
|
using namespace irr::gui;
|
||||||
|
using namespace irr::scene;
|
||||||
|
using namespace irr::video;
|
||||||
|
|
||||||
|
//! Cursor controller v0.2
|
||||||
|
/*! This class controls the cursor. You can choose to use the OS's cursor, a custom
|
||||||
|
cursor or both. You can also have many custom cursors and switch between them easily.
|
||||||
|
*/
|
||||||
|
class CCursorController
|
||||||
|
{
|
||||||
|
struct TexBoolPair
|
||||||
|
{
|
||||||
|
TexBoolPair(ITexture *t, bool tl) { tex = t; topleft = tl; }
|
||||||
|
ITexture *tex;
|
||||||
|
bool topleft;
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
CCursorController(ICursorControl* irrCursor, IVideoDriver* irrVideoDriver);
|
||||||
|
~CCursorController();
|
||||||
|
|
||||||
|
void setVisible(bool visible);
|
||||||
|
bool isVisible() const;
|
||||||
|
void setOSCursorVisible(bool visible);
|
||||||
|
bool isOSCursorVisible() const;
|
||||||
|
|
||||||
|
void render();
|
||||||
|
void addMouseCursorTexture(c8* Cursor_file, bool top_left = false);
|
||||||
|
ITexture* getCursorTexture(u32 index) const;
|
||||||
|
void removeCursor(u32 index);
|
||||||
|
void setActiveCursor(u32 index);
|
||||||
|
void Clear();
|
||||||
|
position2di& getMousePos();
|
||||||
|
|
||||||
|
private:
|
||||||
|
position2di& updateMousePos();
|
||||||
|
|
||||||
|
bool IsOSCursorVisible;
|
||||||
|
bool IsVisible;
|
||||||
|
bool topleft;
|
||||||
|
position2di m_MousePos;
|
||||||
|
ICursorControl* irrCursorControl;
|
||||||
|
IVideoDriver* videoDriver;
|
||||||
|
array<TexBoolPair> m_aMouseCursors;
|
||||||
|
ITexture* m_pMouseCursor;
|
||||||
|
|
||||||
|
u32 used;
|
||||||
|
};
|
||||||
|
#endif // __C_CURSOR_H__
|
||||||
@ -423,6 +423,12 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\Client\Gui\CCursorController.h">
|
RelativePath=".\Client\Gui\CCursorController.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Gui\CImageLoaderBLP.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Gui\CImageLoaderBLP.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Client\Gui\CM2MeshFileLoader.cpp">
|
RelativePath=".\Client\Gui\CM2MeshFileLoader.cpp">
|
||||||
</File>
|
</File>
|
||||||
@ -471,6 +477,12 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\Client\Gui\ShTlTerrainSceneNode.h">
|
RelativePath=".\Client\Gui\ShTlTerrainSceneNode.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Gui\SImage.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Client\Gui\SImage.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Client\Gui\TlTMesh.h">
|
RelativePath=".\Client\Gui\TlTMesh.h">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user