Historique des modifications - Message

Message #6510

Sujet: Nouvlle GUI Irrlicht


Type Date Auteur Contenu
Dernière modification 16-08-2009 08:45:52 Magun
bon alors perso j'ai juste modifier de IGUISkin, pas vraiment dans ton optique si j'ai bien comprit m'enfin j'aime bien se que sa rend wink

le headler :

Code c++ :

#ifndef GameSkin_H_
#define GameSkin_H_

#include <irrlicht/irrlicht.h>
#include "../../externe/file/ReadConfig.h"
#include "../../externe/file/ReadColor.h"
#include "../../externe/file/ReadFont.h"

namespace irr
{
    namespace video
    {
        class IVideoDriver;
        class ITexture;
    }
    namespace gui
    {
        struct SImageGUIElementStyle
        {
            struct SBorder
            {
                s32 Top, Left, Bottom, Right;
                SBorder() : Top(0), Left(0), Bottom(0), Right(0) {}
            };
            SBorder SrcBorder;
            SBorder DstBorder;
            irr::video::ITexture* Texture;
            irr::video::SColor Color;

            SImageGUIElementStyle() : Texture(0), Color(255,255,255,255) {}
        };
        struct SImageGUISkinConfig
        {
            SImageGUIElementStyle SunkenPane, Window, Button, ButtonPressed, ProgressBar, ProgressBarFilled;
        };
        class GameSkin : public IGUISkin
        {
        public:
            GameSkin( irr::video::IVideoDriver* videoDriver, IGUISkin* fallbackSkin );
            virtual ~GameSkin();

            void loadConfig(externe::file::ReadColor*,externe::file::ReadFont*);

            virtual void setColor(EGUI_DEFAULT_COLOR which, irr::video::SColor newColor);
            virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText);
            virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
            virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT defaultFont);
            virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
            virtual void setSpriteBank(IGUISpriteBank* bank);

            virtual irr::video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
            virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const;
            virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
            virtual IGUIFont* getFont(EGUI_DEFAULT_FONT defaultFont) const;
            virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
            virtual IGUISpriteBank* getSpriteBank() const;

            virtual void draw3DButtonPaneStandard(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>*clip=0);
            virtual void draw3DButtonPanePressed(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DSunkenPane(IGUIElement*,irr::video::SColor , bool, bool,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual irr::core::rect<s32> draw3DWindowBackground(IGUIElement*,bool, irr::video::SColor,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DMenuPane(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DToolBar(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DTabButton(IGUIElement*,bool,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
            virtual void draw3DTabBody(IGUIElement*,bool,bool,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
            virtual void drawIcon(IGUIElement*,EGUI_DEFAULT_ICON,const irr::core::position2di, u32 starttime=0, u32 currenttime=0,bool loop=false, const irr::core::rect<s32>* clip=0);
            virtual void drawHorizontalProgressBar( IGUIElement*,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip,f32, irr::video::SColor);
            virtual void draw2DRectangle(IGUIElement*, const irr::video::SColor&,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip = 0);
            irr::core::dimension2d<s32> titreBorder;
        private:
            void drawElementStyle( const SImageGUIElementStyle& elem, const irr::core::rect<s32>& rect, const irr::core::rect<s32>* clip, irr::video::SColor* color=0 );
            externe::file::ReadColor *color;
            externe::file::ReadFont  *XML;
            irr::video::IVideoDriver* VideoDriver;
            IGUISkin* FallbackSkin;
            SImageGUISkinConfig Config;
        };
    }
}

#endif

et la source :

Code c++ :

#include "GameSkin.h"
#include <irrlicht/IVideoDriver.h>
#include <irrlicht/ITexture.h>

using namespace irr;
using namespace core;
using namespace video;
//! murder under night

namespace irr
{
    namespace gui
    {
        GameSkin::GameSkin( IVideoDriver* driver, IGUISkin* fallbackSkin )
        {
            VideoDriver = driver;
            FallbackSkin = fallbackSkin;
            FallbackSkin->grab();
            //Type = EGST_WINDOWS_CLASSIC;
            setSize(EGDS_MESSAGE_BOX_WIDTH, 400);
            setSize(EGDS_TEXT_DISTANCE_X, 10);
            SImageGUIElementStyle* currentElement = 0;

            currentElement = &Config.Button;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/button.tga");
            currentElement->SrcBorder.Top = 4;
            currentElement->SrcBorder.Left = 4;
            currentElement->SrcBorder.Bottom = 4;
            currentElement->SrcBorder.Right = 4;
            currentElement->DstBorder.Top = 4;
            currentElement->DstBorder.Left = 4;
            currentElement->DstBorder.Bottom = 4;
            currentElement->DstBorder.Right = 4;

            currentElement = &Config.ButtonPressed;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/button.tga");
            currentElement->SrcBorder.Top = 0;
            currentElement->SrcBorder.Left = 0;
            currentElement->SrcBorder.Bottom = 0;
            currentElement->SrcBorder.Right = 0;
            currentElement->DstBorder.Top = 0;
            currentElement->DstBorder.Left = 0;
            currentElement->DstBorder.Bottom = 0;
            currentElement->DstBorder.Right = 0;

            currentElement = &Config.SunkenPane;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/sunkenpane.tga");
            currentElement->SrcBorder.Top = 32;
            currentElement->SrcBorder.Left = 32;
            currentElement->SrcBorder.Bottom = 32;
            currentElement->SrcBorder.Right = 32;
            currentElement->DstBorder.Top = 10;
            currentElement->DstBorder.Left = 10;
            currentElement->DstBorder.Bottom = 10;
            currentElement->DstBorder.Right = 10;

            currentElement = &Config.Window;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/window.tga");
            currentElement->SrcBorder.Top = 25;
            currentElement->SrcBorder.Left = 5;
            currentElement->SrcBorder.Bottom = 5;
            currentElement->SrcBorder.Right = 5;
            currentElement->DstBorder.Top = 25;
            currentElement->DstBorder.Left = 6;
            currentElement->DstBorder.Bottom = 6;
            currentElement->DstBorder.Right = 6;

            currentElement = &Config.ProgressBar;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/gaugefilled.tga");
            currentElement->SrcBorder.Top = 30;
            currentElement->SrcBorder.Left = 64;
            currentElement->SrcBorder.Bottom = 30;
            currentElement->SrcBorder.Right = 64;
            currentElement->DstBorder.Top = 30;
            currentElement->DstBorder.Left = 64;
            currentElement->DstBorder.Bottom = 30;
            currentElement->DstBorder.Right = 64;

            currentElement = &Config.ProgressBarFilled;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/gauge.tga");
            currentElement->SrcBorder.Top = 30;
            currentElement->SrcBorder.Left = 64;
            currentElement->SrcBorder.Bottom = 0;
            currentElement->SrcBorder.Right = 0;
            currentElement->DstBorder.Top = 30;
            currentElement->DstBorder.Left = 64;
            currentElement->DstBorder.Bottom = 0;
            currentElement->DstBorder.Right = 0;
        }
        GameSkin::~GameSkin()
        {
            FallbackSkin->drop();
        }
        void GameSkin::loadConfig(externe::file::ReadColor *cl,externe::file::ReadFont*xlm)
        {
            color = cl;
            XML = xlm;
        }
        SColor GameSkin::getColor(EGUI_DEFAULT_COLOR color) const
        {
            return this->color->getColor(color);
            return FallbackSkin->getColor(color);
        }
        void GameSkin::setColor( EGUI_DEFAULT_COLOR which,SColor newColor )
        {
            return color->setColor(which,newColor);
            FallbackSkin->setColor(which,newColor);
        }
        s32 GameSkin::getSize(EGUI_DEFAULT_SIZE size) const
        {
            return FallbackSkin->getSize(size);
        }
        const wchar_t* GameSkin::getDefaultText(EGUI_DEFAULT_TEXT text) const
        {
            return FallbackSkin->getDefaultText(text);
        }
        void GameSkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText)
        {
            FallbackSkin->setDefaultText(which, newText);
        }
        void GameSkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
        {
            FallbackSkin->setSize(which, size);
        }
        IGUIFont* GameSkin::getFont(EGUI_DEFAULT_FONT defaultFont) const
        {
            return FallbackSkin->getFont(defaultFont);
        }
        void GameSkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT defaultFont)
        {
            if(font) FallbackSkin->setFont(font, defaultFont);
        }
        IGUISpriteBank* GameSkin::getSpriteBank() const
        {
            return FallbackSkin->getSpriteBank();
        }
        void GameSkin::setSpriteBank( IGUISpriteBank* bank )
        {
            FallbackSkin->setSpriteBank(bank);
        }
        u32 GameSkin::getIcon( EGUI_DEFAULT_ICON icon ) const
        {
            return FallbackSkin->getIcon(icon);
        }
        void GameSkin::setIcon( EGUI_DEFAULT_ICON icon, u32 index )
        {
            FallbackSkin->setIcon(icon, index);
        }
        void GameSkin::draw3DButtonPaneStandard( IGUIElement* element, const core::rect<s32>& rect, const core::rect<s32>* clip )
        {
            if ( !Config.Button.Texture )
            {
                FallbackSkin->draw3DButtonPaneStandard( element, rect, clip );
                return;
            }
            drawElementStyle( Config.Button, rect, clip );
        }
        void GameSkin::draw3DButtonPanePressed( IGUIElement* element, const core::rect<s32>& rect, const core::rect<s32>* clip )
        {
            if ( !Config.Button.Texture )
            {
                FallbackSkin->draw3DButtonPanePressed( element, rect, clip );
                return;
            }
            drawElementStyle( Config.ButtonPressed, rect, clip );
        }
        void GameSkin::draw3DSunkenPane(IGUIElement* element,SColor bgcolor, bool flat, bool fillBackGround,const core::rect<s32>& rect,const core::rect<s32>* clip)
        {
            if ( !Config.SunkenPane.Texture )
            {
                FallbackSkin->draw3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip);
                return;
            }
            drawElementStyle( Config.SunkenPane, rect, clip );
        }
        core::rect<s32> GameSkin::draw3DWindowBackground(IGUIElement* element,bool drawTitleBar, SColor titleBarColor,const core::rect<s32>& rect,const core::rect<s32>* clip)
        {
            if ( !Config.Window.Texture )
            {
                return FallbackSkin->draw3DWindowBackground(element, drawTitleBar, titleBarColor, rect, clip );
            }
            drawElementStyle( Config.Window, rect, clip );

            return core::rect<s32>( rect.UpperLeftCorner.X+Config.Window.DstBorder.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-Config.Window.DstBorder.Right, rect.UpperLeftCorner.Y+Config.Window.DstBorder.Top );
        }
        void GameSkin::draw3DMenuPane(IGUIElement* element,
                    const core::rect<s32>& rect,
                    const core::rect<s32>* clip)
        {
            FallbackSkin->draw3DMenuPane(element,rect,clip);
        }
        void GameSkin::draw3DToolBar(IGUIElement* element,
            const core::rect<s32>& rect,
            const core::rect<s32>* clip)
        {
            FallbackSkin->draw3DToolBar(element,rect,clip);
        }
        void GameSkin::draw3DTabButton(IGUIElement* element, bool active,
                    const core::rect<s32>& rect, const core::rect<s32>* clip, EGUI_ALIGNMENT alignment)
        {
            FallbackSkin->draw3DTabButton(element, active, rect, clip, alignment);
        }
        void GameSkin::draw3DTabBody(IGUIElement* element, bool border, bool background,
                    const core::rect<s32>& rect, const core::rect<s32>* clip, s32 tabHeight, EGUI_ALIGNMENT alignment)
        {
            FallbackSkin->draw3DTabBody(element, border, background, rect, clip, tabHeight, alignment);
        }
        void GameSkin::drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
            const core::position2di position, u32 starttime, u32 currenttime,
            bool loop, const core::rect<s32>* clip)
        {
            FallbackSkin->drawIcon(element,icon,position,starttime,currenttime,loop,clip);
        }
        void GameSkin::drawHorizontalProgressBar( IGUIElement* element, const core::rect<s32>& rectangle, const core::rect<s32>* clip,
                    f32 filledRatio, SColor fillColor )
        {
            if ( !Config.ProgressBar.Texture || !Config.ProgressBarFilled.Texture )
            {
                return;
            }
            drawElementStyle( Config.ProgressBar, rectangle, clip );

                s32 filledPixels = (s32)( filledRatio * rectangle.getSize().Width );
                s32 height = rectangle.getSize().Height;

                core::rect<s32> clipRect = clip? *clip:rectangle;
                if ( filledPixels < height )
                {
                    if ( clipRect.LowerRightCorner.X > rectangle.UpperLeftCorner.X + filledPixels )
                        clipRect.LowerRightCorner.X = rectangle.UpperLeftCorner.X + filledPixels;

                    filledPixels = height;
                }

                core::rect<s32> filledRect = core::rect<s32>(
                    rectangle.UpperLeftCorner.X,
                    rectangle.UpperLeftCorner.Y,
                    rectangle.UpperLeftCorner.X + filledPixels,
                    rectangle.LowerRightCorner.Y + filledPixels);

                drawElementStyle( Config.ProgressBarFilled, filledRect, &clipRect, &fillColor );
        }
        void GameSkin::drawElementStyle( const SImageGUIElementStyle& elem, const core::rect<s32>& rect, const core::rect<s32>* clip, SColor* pcolor  )
        {
            core::rect<s32> srcRect;
            core::rect<s32> dstRect;
            core::dimension2di tsize = (core::dimension2di)elem.Texture->getSize();
            ITexture* texture = elem.Texture;

            SColor color = elem.Color;
            if ( pcolor )
                color = *pcolor;

            SColor faceColor = getColor(EGDC_APP_WORKSPACE);
            color.setRed( (u8)(color.getRed() * faceColor.getRed() / 255) );
            color.setGreen( (u8)(color.getGreen() * faceColor.getGreen() / 255 ) );
            color.setBlue( (u8)(color.getBlue() * faceColor.getBlue() / 255) );
            color.setAlpha( (u8)(color.getAlpha() * faceColor.getAlpha() / 255 ) );

            SColor colors [4] = { color, color, color, color };
            core::dimension2di dstSize = rect.getSize();

            SImageGUIElementStyle::SBorder dst = elem.DstBorder;
            f32 scale = 1.0f;
            if ( dstSize.Width < dst.Left + dst.Right )
            {
                scale = dstSize.Width / (f32)( dst.Left + dst.Right );
            }
            if ( dstSize.Height < dst.Top + dst.Bottom )
            {
                f32 x = dstSize.Height / (f32)( dst.Top + dst.Bottom );
                if ( x < scale )
                {
                    scale = x;
                }
            }
            if ( scale < 1.0f )
            {
                dst.Left = (s32)( dst.Left * scale );
                dst.Right = (s32)( dst.Right * scale );
                dst.Top = (s32)( dst.Top * scale );
                dst.Bottom = (s32)( dst.Bottom * scale );
            }

            const SImageGUIElementStyle::SBorder& src = elem.SrcBorder;

            // Draw the top left corner
            srcRect = core::rect<s32>( 0, 0, src.Left, src.Top );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y, rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the top right corner
            srcRect = core::rect<s32>( tsize.Width-src.Right, 0, tsize.Width, src.Top );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the top border
            srcRect = core::rect<s32>( src.Left, 0, tsize.Width-src.Right, src.Top );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the left border
            srcRect = core::rect<s32>( 0, src.Top, src.Left, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y+dst.Top, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the right border
            srcRect = core::rect<s32>( tsize.Width-src.Right, src.Top, tsize.Width, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the middle section
            srcRect = core::rect<s32>( src.Left, src.Top, tsize.Width-src.Right, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom left corner
            srcRect = core::rect<s32>( 0, tsize.Height-src.Bottom, src.Left, tsize.Height );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.LowerRightCorner.Y-dst.Bottom, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom right corner
            srcRect = core::rect<s32>( tsize.Width-src.Right, tsize.Height-src.Bottom, tsize.Width, tsize.Height );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom border
            srcRect = core::rect<s32>( src.Left, tsize.Height-src.Bottom, tsize.Width-src.Right, tsize.Height );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
        }
        void GameSkin::draw2DRectangle(IGUIElement* element, const SColor &color,const core::rect<s32>& pos, const core::rect<s32>* clip)
        {
//            FallbackSkin->draw2DRectangle(element, color, pos, clip);
            if(pos.UpperLeftCorner.X  >= element->getAbsolutePosition().UpperLeftCorner.X  && pos.UpperLeftCorner.Y  >= element->getAbsolutePosition().UpperLeftCorner.Y)
            if(pos.LowerRightCorner.X <= element->getAbsolutePosition().LowerRightCorner.X && pos.LowerRightCorner.Y <= element->getAbsolutePosition().LowerRightCorner.Y)
            {
                SImageGUIElementStyle tmp = *&Config.SunkenPane;
                tmp.Color = color;
                drawElementStyle(tmp,pos,clip);
            }
        }
    } // namespace gui
} // namespace irr

répétition ? fait des essaye avec le clipRect si tu utilise un driver->draw2dImage wink
en récupérent le clipRect de guienv->getRootGUIElement()->AbsoluteClippingRect sa marche je croix ... enfin ses vieux, quand je l'avais fait
seulement il est en protected ....

ta de la chance tu va être le premier du forum a voir un extré de mon projet
Création du message 12-06-2009 19:57:41 Magun
bon alors perso j'ai juste modifier de IGUISkin, pas vraiment dans ton optique si j'ai bien comprit m'enfin j'aime bien se que sa rend wink

le headler :

Code c++ :

#ifndef GameSkin_H_
#define GameSkin_H_

#include <irrlicht/irrlicht.h>
#include "../../externe/file/ReadConfig.h"
#include "../../externe/file/ReadColor.h"
#include "../../externe/file/ReadFont.h"

namespace irr
{
    namespace video
    {
        class IVideoDriver;
        class ITexture;
    }
    namespace gui
    {
        struct SImageGUIElementStyle
        {
            struct SBorder
            {
                s32 Top, Left, Bottom, Right;
                SBorder() : Top(0), Left(0), Bottom(0), Right(0) {}
            };
            SBorder SrcBorder;
            SBorder DstBorder;
            irr::video::ITexture* Texture;
            irr::video::SColor Color;

            SImageGUIElementStyle() : Texture(0), Color(255,255,255,255) {}
        };
        struct SImageGUISkinConfig
        {
            SImageGUIElementStyle SunkenPane, Window, Button, ButtonPressed, ProgressBar, ProgressBarFilled;
        };
        class GameSkin : public IGUISkin
        {
        public:
            GameSkin( irr::video::IVideoDriver* videoDriver, IGUISkin* fallbackSkin );
            virtual ~GameSkin();

            void loadConfig(externe::file::ReadColor*,externe::file::ReadFont*);

            virtual void setColor(EGUI_DEFAULT_COLOR which, irr::video::SColor newColor);
            virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText);
            virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
            virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT defaultFont);
            virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
            virtual void setSpriteBank(IGUISpriteBank* bank);

            virtual irr::video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
            virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const;
            virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
            virtual IGUIFont* getFont(EGUI_DEFAULT_FONT defaultFont) const;
            virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
            virtual IGUISpriteBank* getSpriteBank() const;

            virtual void draw3DButtonPaneStandard(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>*clip=0);
            virtual void draw3DButtonPanePressed(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DSunkenPane(IGUIElement*,irr::video::SColor , bool, bool,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual irr::core::rect<s32> draw3DWindowBackground(IGUIElement*,bool, irr::video::SColor,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DMenuPane(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DToolBar(IGUIElement*,const irr::core::rect<s32>&,const irr::core::rect<s32>* clip=0);
            virtual void draw3DTabButton(IGUIElement*,bool,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
            virtual void draw3DTabBody(IGUIElement*,bool,bool,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
            virtual void drawIcon(IGUIElement*,EGUI_DEFAULT_ICON,const irr::core::position2di, u32 starttime=0, u32 currenttime=0,bool loop=false, const irr::core::rect<s32>* clip=0);
            virtual void drawHorizontalProgressBar( IGUIElement*,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip,f32, irr::video::SColor);
            virtual void draw2DRectangle(IGUIElement*, const irr::video::SColor&,const irr::core::rect<s32>&, const irr::core::rect<s32>* clip = 0);
            irr::core::dimension2d<s32> titreBorder;
        private:
            void drawElementStyle( const SImageGUIElementStyle& elem, const irr::core::rect<s32>& rect, const irr::core::rect<s32>* clip, irr::video::SColor* color=0 );
            externe::file::ReadColor *color;
            externe::file::ReadFont  *XML;
            irr::video::IVideoDriver* VideoDriver;
            IGUISkin* FallbackSkin;
            SImageGUISkinConfig Config;
        };
    }
}

#endif

et la source :

Code c++ :

#include "GameSkin.h"
#include <irrlicht/IVideoDriver.h>
#include <irrlicht/ITexture.h>

using namespace irr;
using namespace core;
using namespace video;
//! murder under night

namespace irr
{
    namespace gui
    {
        GameSkin::GameSkin( IVideoDriver* driver, IGUISkin* fallbackSkin )
        {
            VideoDriver = driver;
            FallbackSkin = fallbackSkin;
            FallbackSkin->grab();
            //Type = EGST_WINDOWS_CLASSIC;
            setSize(EGDS_MESSAGE_BOX_WIDTH, 400);
            setSize(EGDS_TEXT_DISTANCE_X, 10);
            SImageGUIElementStyle* currentElement = 0;

            currentElement = &Config.Button;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/button.tga");
            currentElement->SrcBorder.Top = 4;
            currentElement->SrcBorder.Left = 4;
            currentElement->SrcBorder.Bottom = 4;
            currentElement->SrcBorder.Right = 4;
            currentElement->DstBorder.Top = 4;
            currentElement->DstBorder.Left = 4;
            currentElement->DstBorder.Bottom = 4;
            currentElement->DstBorder.Right = 4;

            currentElement = &Config.ButtonPressed;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/button.tga");
            currentElement->SrcBorder.Top = 0;
            currentElement->SrcBorder.Left = 0;
            currentElement->SrcBorder.Bottom = 0;
            currentElement->SrcBorder.Right = 0;
            currentElement->DstBorder.Top = 0;
            currentElement->DstBorder.Left = 0;
            currentElement->DstBorder.Bottom = 0;
            currentElement->DstBorder.Right = 0;

            currentElement = &Config.SunkenPane;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/sunkenpane.tga");
            currentElement->SrcBorder.Top = 32;
            currentElement->SrcBorder.Left = 32;
            currentElement->SrcBorder.Bottom = 32;
            currentElement->SrcBorder.Right = 32;
            currentElement->DstBorder.Top = 10;
            currentElement->DstBorder.Left = 10;
            currentElement->DstBorder.Bottom = 10;
            currentElement->DstBorder.Right = 10;

            currentElement = &Config.Window;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/window.tga");
            currentElement->SrcBorder.Top = 25;
            currentElement->SrcBorder.Left = 5;
            currentElement->SrcBorder.Bottom = 5;
            currentElement->SrcBorder.Right = 5;
            currentElement->DstBorder.Top = 25;
            currentElement->DstBorder.Left = 6;
            currentElement->DstBorder.Bottom = 6;
            currentElement->DstBorder.Right = 6;

            currentElement = &Config.ProgressBar;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/gaugefilled.tga");
            currentElement->SrcBorder.Top = 30;
            currentElement->SrcBorder.Left = 64;
            currentElement->SrcBorder.Bottom = 30;
            currentElement->SrcBorder.Right = 64;
            currentElement->DstBorder.Top = 30;
            currentElement->DstBorder.Left = 64;
            currentElement->DstBorder.Bottom = 30;
            currentElement->DstBorder.Right = 64;

            currentElement = &Config.ProgressBarFilled;
            currentElement->Texture = VideoDriver->getTexture("monde/images/skin/gauge.tga");
            currentElement->SrcBorder.Top = 30;
            currentElement->SrcBorder.Left = 64;
            currentElement->SrcBorder.Bottom = 0;
            currentElement->SrcBorder.Right = 0;
            currentElement->DstBorder.Top = 30;
            currentElement->DstBorder.Left = 64;
            currentElement->DstBorder.Bottom = 0;
            currentElement->DstBorder.Right = 0;
        }
        GameSkin::~GameSkin()
        {
            FallbackSkin->drop();
        }
        void GameSkin::loadConfig(externe::file::ReadColor *cl,externe::file::ReadFont*xlm)
        {
            color = cl;
            XML = xlm;
        }
        SColor GameSkin::getColor(EGUI_DEFAULT_COLOR color) const
        {
            return this->color->getColor(color);
            return FallbackSkin->getColor(color);
        }
        void GameSkin::setColor( EGUI_DEFAULT_COLOR which,SColor newColor )
        {
            return color->setColor(which,newColor);
            FallbackSkin->setColor(which,newColor);
        }
        s32 GameSkin::getSize(EGUI_DEFAULT_SIZE size) const
        {
            return FallbackSkin->getSize(size);
        }
        const wchar_t* GameSkin::getDefaultText(EGUI_DEFAULT_TEXT text) const
        {
            return FallbackSkin->getDefaultText(text);
        }
        void GameSkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText)
        {
            FallbackSkin->setDefaultText(which, newText);
        }
        void GameSkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
        {
            FallbackSkin->setSize(which, size);
        }
        IGUIFont* GameSkin::getFont(EGUI_DEFAULT_FONT defaultFont) const
        {
            return FallbackSkin->getFont(defaultFont);
        }
        void GameSkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT defaultFont)
        {
            if(font) FallbackSkin->setFont(font, defaultFont);
        }
        IGUISpriteBank* GameSkin::getSpriteBank() const
        {
            return FallbackSkin->getSpriteBank();
        }
        void GameSkin::setSpriteBank( IGUISpriteBank* bank )
        {
            FallbackSkin->setSpriteBank(bank);
        }
        u32 GameSkin::getIcon( EGUI_DEFAULT_ICON icon ) const
        {
            return FallbackSkin->getIcon(icon);
        }
        void GameSkin::setIcon( EGUI_DEFAULT_ICON icon, u32 index )
        {
            FallbackSkin->setIcon(icon, index);
        }
        void GameSkin::draw3DButtonPaneStandard( IGUIElement* element, const core::rect<s32>& rect, const core::rect<s32>* clip )
        {
            if ( !Config.Button.Texture )
            {
                FallbackSkin->draw3DButtonPaneStandard( element, rect, clip );
                return;
            }
            drawElementStyle( Config.Button, rect, clip );
        }
        void GameSkin::draw3DButtonPanePressed( IGUIElement* element, const core::rect<s32>& rect, const core::rect<s32>* clip )
        {
            if ( !Config.Button.Texture )
            {
                FallbackSkin->draw3DButtonPanePressed( element, rect, clip );
                return;
            }
            drawElementStyle( Config.ButtonPressed, rect, clip );
        }
        void GameSkin::draw3DSunkenPane(IGUIElement* element,SColor bgcolor, bool flat, bool fillBackGround,const core::rect<s32>& rect,const core::rect<s32>* clip)
        {
            if ( !Config.SunkenPane.Texture )
            {
                FallbackSkin->draw3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip);
                return;
            }
            drawElementStyle( Config.SunkenPane, rect, clip );
        }
        core::rect<s32> GameSkin::draw3DWindowBackground(IGUIElement* element,bool drawTitleBar, SColor titleBarColor,const core::rect<s32>& rect,const core::rect<s32>* clip)
        {
            if ( !Config.Window.Texture )
            {
                return FallbackSkin->draw3DWindowBackground(element, drawTitleBar, titleBarColor, rect, clip );
            }
            drawElementStyle( Config.Window, rect, clip );

            return core::rect<s32>( rect.UpperLeftCorner.X+Config.Window.DstBorder.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-Config.Window.DstBorder.Right, rect.UpperLeftCorner.Y+Config.Window.DstBorder.Top );
        }
        void GameSkin::draw3DMenuPane(IGUIElement* element,
                    const core::rect<s32>& rect,
                    const core::rect<s32>* clip)
        {
            FallbackSkin->draw3DMenuPane(element,rect,clip);
        }
        void GameSkin::draw3DToolBar(IGUIElement* element,
            const core::rect<s32>& rect,
            const core::rect<s32>* clip)
        {
            FallbackSkin->draw3DToolBar(element,rect,clip);
        }
        void GameSkin::draw3DTabButton(IGUIElement* element, bool active,
                    const core::rect<s32>& rect, const core::rect<s32>* clip, EGUI_ALIGNMENT alignment)
        {
            FallbackSkin->draw3DTabButton(element, active, rect, clip, alignment);
        }
        void GameSkin::draw3DTabBody(IGUIElement* element, bool border, bool background,
                    const core::rect<s32>& rect, const core::rect<s32>* clip, s32 tabHeight, EGUI_ALIGNMENT alignment)
        {
            FallbackSkin->draw3DTabBody(element, border, background, rect, clip, tabHeight, alignment);
        }
        void GameSkin::drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
            const core::position2di position, u32 starttime, u32 currenttime,
            bool loop, const core::rect<s32>* clip)
        {
            FallbackSkin->drawIcon(element,icon,position,starttime,currenttime,loop,clip);
        }
        void GameSkin::drawHorizontalProgressBar( IGUIElement* element, const core::rect<s32>& rectangle, const core::rect<s32>* clip,
                    f32 filledRatio, SColor fillColor )
        {
            if ( !Config.ProgressBar.Texture || !Config.ProgressBarFilled.Texture )
            {
                return;
            }
            drawElementStyle( Config.ProgressBar, rectangle, clip );

                s32 filledPixels = (s32)( filledRatio * rectangle.getSize().Width );
                s32 height = rectangle.getSize().Height;

                core::rect<s32> clipRect = clip? *clip:rectangle;
                if ( filledPixels < height )
                {
                    if ( clipRect.LowerRightCorner.X > rectangle.UpperLeftCorner.X + filledPixels )
                        clipRect.LowerRightCorner.X = rectangle.UpperLeftCorner.X + filledPixels;

                    filledPixels = height;
                }

                core::rect<s32> filledRect = core::rect<s32>(
                    rectangle.UpperLeftCorner.X,
                    rectangle.UpperLeftCorner.Y,
                    rectangle.UpperLeftCorner.X + filledPixels,
                    rectangle.LowerRightCorner.Y + filledPixels);

                drawElementStyle( Config.ProgressBarFilled, filledRect, &clipRect, &fillColor );
        }
        void GameSkin::drawElementStyle( const SImageGUIElementStyle& elem, const core::rect<s32>& rect, const core::rect<s32>* clip, SColor* pcolor  )
        {
            core::rect<s32> srcRect;
            core::rect<s32> dstRect;
            core::dimension2di tsize = (core::dimension2di)elem.Texture->getSize();
            ITexture* texture = elem.Texture;

            SColor color = elem.Color;
            if ( pcolor )
                color = *pcolor;

            SColor faceColor = getColor(EGDC_APP_WORKSPACE);
            color.setRed( (u8)(color.getRed() * faceColor.getRed() / 255) );
            color.setGreen( (u8)(color.getGreen() * faceColor.getGreen() / 255 ) );
            color.setBlue( (u8)(color.getBlue() * faceColor.getBlue() / 255) );
            color.setAlpha( (u8)(color.getAlpha() * faceColor.getAlpha() / 255 ) );

            SColor colors [4] = { color, color, color, color };
            core::dimension2di dstSize = rect.getSize();

            SImageGUIElementStyle::SBorder dst = elem.DstBorder;
            f32 scale = 1.0f;
            if ( dstSize.Width < dst.Left + dst.Right )
            {
                scale = dstSize.Width / (f32)( dst.Left + dst.Right );
            }
            if ( dstSize.Height < dst.Top + dst.Bottom )
            {
                f32 x = dstSize.Height / (f32)( dst.Top + dst.Bottom );
                if ( x < scale )
                {
                    scale = x;
                }
            }
            if ( scale < 1.0f )
            {
                dst.Left = (s32)( dst.Left * scale );
                dst.Right = (s32)( dst.Right * scale );
                dst.Top = (s32)( dst.Top * scale );
                dst.Bottom = (s32)( dst.Bottom * scale );
            }

            const SImageGUIElementStyle::SBorder& src = elem.SrcBorder;

            // Draw the top left corner
            srcRect = core::rect<s32>( 0, 0, src.Left, src.Top );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y, rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the top right corner
            srcRect = core::rect<s32>( tsize.Width-src.Right, 0, tsize.Width, src.Top );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the top border
            srcRect = core::rect<s32>( src.Left, 0, tsize.Width-src.Right, src.Top );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the left border
            srcRect = core::rect<s32>( 0, src.Top, src.Left, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y+dst.Top, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the right border
            srcRect = core::rect<s32>( tsize.Width-src.Right, src.Top, tsize.Width, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the middle section
            srcRect = core::rect<s32>( src.Left, src.Top, tsize.Width-src.Right, tsize.Height-src.Bottom );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom left corner
            srcRect = core::rect<s32>( 0, tsize.Height-src.Bottom, src.Left, tsize.Height );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.LowerRightCorner.Y-dst.Bottom, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom right corner
            srcRect = core::rect<s32>( tsize.Width-src.Right, tsize.Height-src.Bottom, tsize.Width, tsize.Height );
            dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );

            // Draw the bottom border
            srcRect = core::rect<s32>( src.Left, tsize.Height-src.Bottom, tsize.Width-src.Right, tsize.Height );
            dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y );
        //    if ( !clip || clipRects( dstRect, srcRect, *clip ) )
                VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
        }
        void GameSkin::draw2DRectangle(IGUIElement* element, const SColor &color,const core::rect<s32>& pos, const core::rect<s32>* clip)
        {
//            FallbackSkin->draw2DRectangle(element, color, pos, clip);
            if(pos.UpperLeftCorner.X  >= element->getAbsolutePosition().UpperLeftCorner.X  && pos.UpperLeftCorner.Y  >= element->getAbsolutePosition().UpperLeftCorner.Y)
            if(pos.LowerRightCorner.X <= element->getAbsolutePosition().LowerRightCorner.X && pos.LowerRightCorner.Y <= element->getAbsolutePosition().LowerRightCorner.Y)
            {
                SImageGUIElementStyle tmp = *&Config.SunkenPane;
                tmp.Color = color;
                drawElementStyle(tmp,pos,clip);
            }
        }
    } // namespace gui
} // namespace irr

répétition ? fait des essaye avec le clipRect si tu utilise un driver->draw2dImage wink
en récupérent le clipRect de guienv->getRootGUIElement()->AbsoluteClippingRect sa marche je croix ... enfin ses vieux, quand je l'avais fait
seulement il est en protected ....

ta de la chance tu va être le premier du forum a voir un extré de mon projet

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
138 invités en ligne
membre en ligne: -
RSS Feed