The full version includes
-performance compiled irrlicht.dll (dx9,dx8,openGl)
-pre-compiled example usage (Examples/05.UserInterface)
-Full source code, ready to build visual studio 05 project file.
The latest version of the code is available at:
www.g0dsoft.com/irrlicht/chatQueue/v03/full.zip
And for just the changes to the irrlicht source: (Much smaller)
www.g0dsoft.com/irrlicht/chatQueue/v03/src.zip
New, 05.UserInterface.exe example (In full.zip)
Updated for 0.3.1
-Re factored into a engine widget * Must be compiled into irrlicht.
-Word preserving word wrap
-Proper Alpha fade by default
-Draw is now automatically called
-No longer uses STL (only irr wrappers)
-getVisible renamed to isVisible
-getDebug renamed to isDebug
-Removed 3 overloaded/redundant addMessage functions
ToDo:
-Protection from errors in the following special cases
Tiny rendering box (word wrap stack overflow?)
Invalid rendering box?
Note: This is still a work in progress, Please be critical- It's my first time writing code for use inside the Irrlicht engine.
Example usage:
Code: Select all
IGUIChatQueue* chatqueue;
IGUIFont* font;
font = device->getGUIEnvironment()->getFont("Media/Fonts/haettenschweiler.bmp");
if (font)
skin->setFont(font);
chatqueue = env->addChatQueue(rect<s32>(300,120,600,400),0,-1);
chatqueue->setDefaultStyle(CQS_PLAIN); //This line isnt needed
chatqueue->setFont(font);
chatqueue->setLife(6000); //Messages stay for 6 seconds and then fade
//chatqueue->setDebug(true); //Draws render area.
chatqueue->addMessage( L"This is a test of the chatQue object," );
chatqueue->addMessage( L"for use with irrlicht.", CQS_SHADOW);
chatqueue->addMessage( L"Lots of great features including- Word wrrrrrapping! Do, do do, do the word wrap...auto matic happy! Aint life easy? word wrap" );
chatqueue->addMessage( L"Rainbow Text",CQS_RAINBOW);
chatqueue->addMessage( L"Full Background Text",CQS_BACKGROUND,SColor(255,100,100,255),SColor(255,10,255,10));
chatqueue->addMessage( L"Cropped Background Text",CQS_CROPBACKGROUND,SColor(255,100,255,100),SColor(255,225,180,0));
chatqueue->addMessage( L"Pulse Text",CQS_PULSE,SColor(255,255,255,0),SColor(0,0,0,0) );
chatqueue->addMessage( L"Shadow Text ... Also text can fade off slowly :D",CQS_SHADOW);
chatqueue->addMessage( L"Text can be any color!",CQS_USEDEFAULT,SColor(255,100,255,25));
Code: Select all
/*
ChatQueue is copyright g0dsoft 2008
Version: 0.3.1
Code by: Mark Laprairie
Contact: webmaster@g0dsoft.com
Url: www.g0dsoft.com
IGUIChatQueue.h
ChatQueue is a object for simulating half-life/starcraft style chat display
capable of colors, special effects and any custom font.
*/
#ifndef __I_GUI_CHAT_QUEUE_H_INCLUDED__
#define __I_GUI_CHAT_QUEUE_H_INCLUDED__
#include "IGUIElement.h"
namespace irr
{
namespace gui
{
enum chatQueueStyle{
CQS_USEDEFAULT = 0,
CQS_PLAIN,
CQS_SHADOW,
CQS_RAINBOW,
CQS_MULTIRAINBOW,
CQS_PULSE,
CQS_BACKGROUND,
CQS_CROPBACKGROUND,
/*!! Warning:
The following styles are for internal
use only, using them may cause your
program to crash.
!!*/ //This should some how be moved to CGUI.
CQS_INTERNALUSEONLY_PULSE,
CQS_INTERNALUSEONLY_FADE,
CQS_INTERNALUSEONLY_FADE2
};
//! GUI Check box interface.
class IGUIChatQueue : public IGUIElement
{
public:
//! constructor
IGUIChatQueue(IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32> &rectangle)
: IGUIElement(EGUIET_CHAT_QUEUE, environment, parent, id, rectangle) {}
//! destructor
virtual ~IGUIChatQueue() {}
//! Add a message to the Chat Queue
/** \param text: Irrlicht stringw, wchar_t* or const wchar_t*
refrencing the text you want displayed
\param color1: The main color for your text
\param color2: The special color, used for styles
ex. if you apply CQS_SHADOW as the style this will
be the color for the background shadow.
\param chatQueueStyle: The style the text is to be renderd
with defaults to a style set with setDefaultStyle or if
not set,CQS_PLAIN*/
virtual void addMessage(core::stringw text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 = video::SColor(255,255,255,255),video::SColor color2 = video::SColor(255,0,0,0)) = 0;
virtual void addMessage(wchar_t* text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 =video::SColor(255,255,255,255),video::SColor color2 =video::SColor(255,0,0,0)) = 0;
virtual void addMessage(const wchar_t* text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 =video::SColor(255,255,255,255),video::SColor color2 =video::SColor(255,0,0,0)) = 0;
//! Sets how long text should fade for before removing
virtual void setFadeTime(u32 fadeTime = 1000) = 0;
//! Sets the font to be used by Chat Queue
virtual void setFont(IGUIFont* font) = 0;
//! Sets a max number of lines that can be visible at a given time
virtual void setMaxLines(u16 maxLines) = 0;
//! Makes Chat Queue visible, or invisible
virtual void setVisible(bool setVisible = true) = 0;
//! Sets how long a text entry should be fully visible
virtual void setLife(u32 setLife = 1000) = 0;
//! Enables/Disables word wrapping
virtual void setWordWrap(bool setWordWrap = true) = 0;
//! Modifies the draw area
virtual void setDrawArea(const core::rect<s32> areaArea) = 0;
//! Sets a debug mode that makes the draw area visible
virtual void setDebug(bool setDebug = true) = 0;
//! Sets a default style to be used when no other style is present
virtual void setDefaultStyle(chatQueueStyle useStyle) = 0;
//! Is the current ChatQueue object in debug mode?
virtual bool isDebug() = 0;
//! Returns the current fade time
virtual u32 getFadeTime() = 0;
//! Returns the current font
virtual IGUIFont* getFont() = 0;
//! Returns the current, default style
virtual chatQueueStyle getDefaultStyle() = 0;
private:
};
} // end namespace gui
} // end namespace irr
#endif
Code: Select all
/*
ChatQueue is copyright g0dsoft 2008
Version: 0.3.1
Code by: Mark Laprairie
Contact: webmaster@g0dsoft.com
Url: www.g0dsoft.com
CGUIChatQueue.h
ChatQueue is a object for simulating half-life/starcraft style chat display
capable of colors, special effects and any custom font.
*/
#ifndef __C_GUI_CHAT_QUEUE_H_INCLUDED__
#define __C_GUI_CHAT_QUEUE_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIFont.h"
#include <ITimer.h>
#include "IGUIChatQueue.h"
#include <irrlist.h>
namespace irr
{
namespace gui
{
#define chatQueue_STRINGLENGTH 200
//! Multi-Line chat queue
class CGUIChatQueue : public virtual IGUIChatQueue {
public:
//! constructor
CGUIChatQueue(IGUIEnvironment* environment, IGUIElement* parent, s32 id,const core::rect<s32> &drawArea,IGUIFont* font = NULL,
u32 textLife = 5000, u32 fadeTime = 500.00, bool setWordWrap = true);
//! destructor
~CGUIChatQueue();
//! Add a message to the Chat Queue
/** \param text: Irrlicht stringw, wchar_t* or const wchar_t*
refrencing the text you want displayed
\param color1: The main color for your text
\param color2: The special color, used for styles
ex. if you apply CQS_SHADOW as the style this will
be the color for the background shadow.
\param chatQueueStyle: The style the text is to be renderd
with defaults to a style set with setDefaultStyle or if
not set,CQS_PLAIN*/
virtual void addMessage(core::stringw text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 =video::SColor(255,255,255,255),video::SColor color2 =video::SColor(255,0,0,0));
virtual void addMessage(wchar_t* text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 =video::SColor(255,255,255,255),video::SColor color2 =video::SColor(255,0,0,0));
virtual void addMessage(const wchar_t* text,chatQueueStyle useStyle = CQS_USEDEFAULT,video::SColor color1 =video::SColor(255,255,255,255),video::SColor color2 =video::SColor(255,0,0,0));
//! draws the element and its children
virtual void draw();
//! Sets how long text should fade for before removing
virtual void setFadeTime(u32 fadeTime = 1000);
//! Sets the font to be used by Chat Queue
virtual void setFont(IGUIFont* font);
//! Sets a max number of lines that can be visible at a given time
virtual void setMaxLines(u16 maxLines);
//! Makes Chat Queue visible, or invisible
virtual void setVisible(bool setVisible = true);
//! Sets how long a text entry should be fully visible
virtual void setLife(u32 setLife = 1000);
//! Enables/Disables word wrapping
virtual void setWordWrap(bool setWordWrap = true);
//! Modifies the draw area
virtual void setDrawArea(const core::rect<s32> areaArea);
//! Sets a debug mode that makes the draw area visible
virtual void setDebug(bool setDebug = true);
//! Sets a default style to be used when no other style is present
virtual void setDefaultStyle(chatQueueStyle useStyle);
//! Is the current ChatQueue object in debug mode?
virtual bool isDebug();
//! Returns the current fade time
virtual u32 getFadeTime();
//! Returns the current font
virtual IGUIFont* getFont();
//! Returns the current, default style
virtual chatQueueStyle getDefaultStyle();
private:
//Helper functions
void chatQueue_calculateRect(const core::rect<s32> drawArea);
void chatQueue_calculateFontDimensions(IGUIFont* font);
void chatQueue_calculateMaxLines();
//Style and Font
chatQueueStyle chatQueue_defaultStyle;
IGUIFont* chatQueue_font;
//Rect replacment
u32 m_xWidth;
u32 m_yHeight;
u32 m_y;
u32 m_x;
//Font height
u16 m_fontHeight;
//Chat Queue message container
struct chatQueueMessage{
wchar_t message[chatQueue_STRINGLENGTH];
chatQueueStyle Style;
video::SColor color1;
video::SColor color2;
video::SColor color1Fade;
video::SColor color2Fade;
u32 created;
u32 fade;
};
IGUIEnvironment* chatQueue_env;
bool chatQueue_debug;
bool chatQueue_wordWrap;
u32 chatQueue_fadeTime;
u32 chatQueue_life;
u16 chatQueue_maxLines;
core::list<chatQueueMessage> chatQueue_list;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_CHAT_QUEUE_H_INCLUDED__
Code: Select all
/*
ChatQueue is copyright g0dsoft 2008
Version: 0.3.1
Code by: Mark Laprairie
Contact: webmaster@g0dsoft.com
Url: www.g0dsoft.com
CGUIChatQueue.cpp
ChatQueue is a object for simulating half-life/starcraft style chat display
capable of colors, special effects and any custom font.
*/
#include "CGUIChatQueue.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "os.h"
namespace irr
{
namespace gui
{
CGUIChatQueue::CGUIChatQueue(IGUIEnvironment* environment, IGUIElement* parent, s32 id,const core::rect<s32> &drawArea, IGUIFont* font, u32 textLife,
u32 fadeTime, bool setWordWrap): IGUIChatQueue(environment, parent, id, drawArea)
{
#ifdef _DEBUG
setDebugName("CGUIChatQueue");
#endif
//Initialize ChatQueue
chatQueue_env = environment;
if(!font)
chatQueue_font = environment->getBuiltInFont();
else
chatQueue_font = font;
chatQueue_wordWrap = setWordWrap;
chatQueue_life = textLife;
setVisible(true);
chatQueue_debug = false;
chatQueue_fadeTime = fadeTime;
chatQueue_defaultStyle = CQS_PLAIN;
m_fontHeight = 0;
chatQueue_calculateRect(drawArea);
this->setFont(chatQueue_font);
}
CGUIChatQueue::~CGUIChatQueue()
{
chatQueue_list.empty();
}
void CGUIChatQueue::addMessage(core::stringw text,chatQueueStyle useStyle,video::SColor color1,video::SColor color2)
{
chatQueueMessage lmsg;
s32 l_cutPosition = chatQueue_font->getCharacterFromPos(text.c_str(),m_xWidth);
if(l_cutPosition != -1)
wcscpy(lmsg.message,text.subString(0,l_cutPosition).c_str());
else
wcscpy(lmsg.message,text.subString(0,text.size()).c_str());
lmsg.color1 = color1;
lmsg.color2 = color2;
lmsg.fade = 0;
//Assign Style
if(useStyle == CQS_USEDEFAULT)
useStyle = chatQueue_defaultStyle;
lmsg.Style = useStyle;
lmsg.created = os::Timer::getTime();
//Word preserving word wrapping, adapted from BlindSide's code
if(l_cutPosition != -1 && chatQueue_wordWrap)
{
s32 spacepos = text.subString(0,l_cutPosition).findLast(32);
if(spacepos != -1)
l_cutPosition = spacepos;
wcscpy(lmsg.message,text.subString(0,l_cutPosition).c_str());
chatQueue_list.push_front(lmsg);
addMessage(text.subString(l_cutPosition,text.size()),useStyle,color1,color2);
}
else
chatQueue_list.push_front(lmsg);
}
void CGUIChatQueue::addMessage(wchar_t* text,chatQueueStyle useStyle,video::SColor color1,video::SColor color2)
{
addMessage((const wchar_t*) text,useStyle,color1,color2);
}
void CGUIChatQueue::addMessage(const wchar_t* text,chatQueueStyle useStyle,video::SColor color1,video::SColor color2)
{
//I'm sure there is a better way to do this conversion, Ideas?
core::stringw text2;
text2 = "";
text2.append(text);
addMessage(text2,useStyle,color1,color2);
}
void CGUIChatQueue::draw()
{
//Debug
if(chatQueue_debug && IsVisible)
chatQueue_env->getVideoDriver()->draw2DRectangle(video::SColor(100,155,155,255),
core::rect<s32>(m_x, m_y - m_yHeight,m_x + m_xWidth,m_y));
//Main Update/Draw
core::list<chatQueueMessage>::Iterator iter;
u16 count = 0;
u32 m_y_tmp = m_y;
u32 l_time = os::Timer::getTime();
for (iter=chatQueue_list.begin(); iter != chatQueue_list.end(); iter++)
{
//Max lines means no fade, special case delete
if(count > chatQueue_maxLines)
{
//STL deprecation, I need to fix this..
//chatQueue_list.erase(iter,chatQueue_list.end());
chatQueue_list.erase(iter);
return;
}
//Update
if(chatQueue_life >= 0 && (iter->created + chatQueue_life) < l_time){
if(iter->fade == 0 && chatQueue_fadeTime > 0)
{
iter->fade = l_time;
iter->color1Fade = iter->color1;
iter->color2Fade = iter->color2;
if(iter->Style == CQS_SHADOW)
iter->Style = CQS_INTERNALUSEONLY_FADE2;
else
iter->Style = CQS_INTERNALUSEONLY_FADE;
}
//Kill text that has faded away.
if( ((l_time - iter->fade) >= chatQueue_fadeTime) || chatQueue_fadeTime <= 0 )
{
//STL deprecation, could cause problems. Needs extensive testing
//chatQueue_list.erase(iter,chatQueue_list.end());
chatQueue_list.erase(iter);
return;
}
// Old Fade code, left incase you would rather fade to a color
// Here it fades to black, w/ alpha fade.
// f32 l_alpha = ( (f32)(l_time - iter->fade)/(f32)chatQueue_fadeTime );
// iter->color1 = iter->color1Fade.getInterpolated(video::SColor(0,0,0,0),1-l_alpha);
// iter->color2 = iter->color2Fade.getInterpolated(video::SColor(0,0,0,0),1-l_alpha);
// Proposed alpha fade code, does not work with irrlicht 1.1
f32 l_alpha = ( (f32)(l_time - iter->fade)/(f32)chatQueue_fadeTime );
iter->color1.setAlpha((s32)(iter->color1Fade.getAlpha() * (1-l_alpha)));
iter->color2.setAlpha((s32)(iter->color2Fade.getAlpha() * (1-l_alpha)));
}
//Draw
if (IsVisible && chatQueue_font){
s16 l_offSetX = 0;
s16 l_offSetY = 0;
bool l_render2 = false;
//Apply style
switch (iter->Style){
case CQS_SHADOW:
l_offSetX = 1;
l_offSetY = 1;
l_render2 = true;
break;
case CQS_RAINBOW:
iter->color1 =video::SColor(255,(l_time/2)%255,(l_time/3)%255,(l_time)%255);
break;
case CQS_MULTIRAINBOW:
l_offSetX = 1;
l_offSetY = 1;
iter->color1 =video::SColor(255,(l_time/2)%255,(l_time/3)%255,(l_time)%255);
iter->color2 =video::SColor(255,(l_time)%255,(l_time/2)%255,(l_time/3)%255);
l_render2 = true;
break;
case CQS_BACKGROUND:
chatQueue_env->getVideoDriver()->draw2DRectangle(iter->color2,
core::rect<s32>(m_x,m_y_tmp - m_fontHeight,m_x+m_xWidth,m_y_tmp));
break;
case CQS_CROPBACKGROUND:{
core::dimension2d<s32> l_fontDimensions = chatQueue_font->getDimension(iter->message);
chatQueue_env->getVideoDriver()->draw2DRectangle(iter->color2,
core::rect<s32>(m_x,m_y_tmp - m_fontHeight,m_x+l_fontDimensions.Width,m_y_tmp));
break;}
case CQS_PULSE:
iter->color1Fade = iter->color1;
iter->Style = CQS_INTERNALUSEONLY_PULSE;
case CQS_INTERNALUSEONLY_PULSE:
iter->color1 = iter->color1Fade.getInterpolated(iter->color2,(l_time%1000)/(f32)999.9);
break;
case CQS_INTERNALUSEONLY_FADE2:
l_offSetX = 1;
l_offSetY = 1;
l_render2 = true;
break;
default:{break;}
}
if(l_render2)
chatQueue_font->draw(iter->message,
core::rect<s32>(m_x + l_offSetX,m_y_tmp - m_fontHeight+ l_offSetY,m_x+m_xWidth + l_offSetX,m_y_tmp + l_offSetY),
iter->color2);
chatQueue_font->draw(iter->message,
core::rect<s32>(m_x,m_y_tmp - m_fontHeight,m_x+m_xWidth,m_y_tmp),
iter->color1);
m_y_tmp -= m_fontHeight;
}
count++;
}
}
//!-- Start Helpers
void CGUIChatQueue::chatQueue_calculateRect(const core::rect<s32> drawArea)
{
m_xWidth = drawArea.getWidth();
m_yHeight = drawArea.getHeight();
core::position2d<s32> l_positionTmp = drawArea.LowerRightCorner;
m_y = l_positionTmp.Y;
l_positionTmp = drawArea.UpperLeftCorner;
m_x = l_positionTmp.X;
}
void CGUIChatQueue::chatQueue_calculateFontDimensions(irr::gui::IGUIFont* font)
{
core::dimension2d<s32> l_fontDimensions = font->getDimension(L"W");
m_fontHeight = l_fontDimensions.Height;
chatQueue_calculateMaxLines();
}
void CGUIChatQueue::chatQueue_calculateMaxLines()
{
chatQueue_maxLines = ((m_yHeight - m_fontHeight) / m_fontHeight);
}
//!-- End Helpers
//Set Functions
void CGUIChatQueue::setFadeTime(u32 fadeTime)
{
chatQueue_fadeTime = fadeTime;
}
void CGUIChatQueue::setMaxLines(u16 maxLines)
{
chatQueue_calculateMaxLines();
if(maxLines < chatQueue_maxLines)
chatQueue_maxLines = maxLines;
}
void CGUIChatQueue::setFont(IGUIFont* font)
{
chatQueue_font = font;
chatQueue_calculateFontDimensions(font);
}
void CGUIChatQueue::setLife(u32 setLife)
{
chatQueue_life = setLife;
}
void CGUIChatQueue::setVisible(bool setVisible)
{
IsVisible = setVisible;
}
void CGUIChatQueue::setWordWrap(bool setWordWrap)
{
chatQueue_wordWrap = setWordWrap;
}
void CGUIChatQueue::setDrawArea(const core::rect<s32> drawArea)
{
chatQueue_calculateRect(drawArea);
setFont(chatQueue_font);
}
void CGUIChatQueue::setDebug(bool setDebug)
{
chatQueue_debug = setDebug;
}
void CGUIChatQueue::setDefaultStyle(chatQueueStyle useStyle)
{
if(useStyle == CQS_USEDEFAULT)
useStyle = CQS_PLAIN;
chatQueue_defaultStyle = useStyle;
}
//Get Functions
chatQueueStyle CGUIChatQueue::getDefaultStyle()
{
return chatQueue_defaultStyle;
}
u32 CGUIChatQueue::getFadeTime()
{
return chatQueue_fadeTime;
}
bool CGUIChatQueue::isDebug()
{
return chatQueue_debug;
}
irr::gui::IGUIFont* CGUIChatQueue::getFont()
{
if(chatQueue_font)
return chatQueue_font;
else
return NULL;
}
} // end namespace gui
} // end namespace irr
#endif