#1 

26-03-2016 19:23:47

Magun
Administrateurs
Avatar de Magun
Date d'inscription:
Messages: 910
IP: 37.59.116.104
Courriel  Site web

YO!
j'en avais parler il y a un certain temps et je n'avais pas eu le temps de le poster ici depuis
du coup voila !







CGUIPieChart.hCGUIPieChart.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#ifndef __C_GUI_ROUND_PROGRESS_HEADER__
#define __C_GUI_ROUND_PROGRESS_HEADER__

#include <irrlicht/IGUIElement.h>
#include <irrlicht/ITexture.h>
#include <irrlicht/IVideoDriver.h>
#include <irrlicht/SMaterial.h>
#include <irrlicht/S3DVertex.h>
#include <irrlicht/irrList.h>

/**
 * Copyright (C) <2014>
 * Ovan/Magun contact on irrlicht-fr.org or ovan@sleek-think.ovh
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
**/

namespace irr
{
    namespace gui
    {
        struct CGUIPieChartElement
        {
            public:
                CGUIPieChartElement(float from = 0.f, float to = 1.f, const video::SColor &c = {255, 255, 255, 255}, float depth = 0.f);

                void set(float from, float to);
                void setDepth(float depth = 0.f);
                void setColor(const video::SColor&);
            public:
                video::SColor clr;
                float from, to, depth;
                core::array<core::triangle3df> pos;
            private:
                void calc(float from, float to);
                core::vector3df calc(float);
            private:
                friend class CGUIPieChart;
        };
        class CGUIPieChart : public IGUIElement
        {
            public:
                CGUIPieChart(IGUIEnvironment *environment, IGUIElement *parent, const core::recti &size, s32 id = 0) noexcept;
                ~CGUIPieChart() noexcept;

                virtual void add(const CGUIPieChartElement&);
                virtual CGUIPieChartElement& get(int);
                virtual bool erase(int);
                virtual int count() const;

                virtual void setBackgroundColor(const video::SColor&);
                virtual void setBackgroundTexture(video::ITexture*);
                virtual void setForegroundTexture(video::ITexture*);

                virtual video::ITexture* getBackgroundTexture() const;
                virtual video::ITexture* getForegroundTexture() const;
                virtual video::SColor    getBackgroundColor() const;

                virtual void updateAbsolutePosition();

                virtual void draw();
            protected:
                video::IVideoDriver *driver;
                core::list<CGUIPieChartElement> item;
            private:
                video::SColor clr;
                core::array<u16> idx;
                core::array<video::S3DVertex> vtx;
                video::ITexture *bg, *fg;
                video::SMaterial mat;
        };
    }
}

#endif

utilisation:

Code c++ :



#include <irrlicht.h>
#include "CGUIPieChart.h"
#include "driverChoice.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

int main()
{
        SIrrlichtCreationParameters cp;
    cp.AntiAlias = 4;
    cp.Bits = 32;
    cp.DriverType = video::EDT_OPENGL;
    cp.Vsync = true;
    cp.WindowSize = core::dimension2d<u32>(128, 128);

        IrrlichtDevice * device = createDeviceEx(cp);

        device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
        device->setResizable(true);

        video::IVideoDriver* driver = device->getVideoDriver();
        IGUIEnvironment* env = device->getGUIEnvironment();

        /**********************************************/

        CGUIPieChart *test = new CGUIPieChart(env, env->getRootGUIElement(), {0,0,0,0});
        test->setBackgroundTexture(driver->getTexture("bg.png"));
        test->setForegroundTexture(driver->getTexture("bg.png"));
//      test->add({0.000f, 0.458f, {128, 255,   0,   0}});
        test->add({0.458f, 0.541f, {255, 255, 128,   0}});
        test->add({0.541f, 0.624f, {255, 255, 255,   0}});
        test->add({0.624f, 0.707f, {255,   0,   0, 255}});
        test->add({0.707f, 1.000f, {255, 255,   0, 255}});

        /**********************************************/

        while(device->run())
        {
        if(device->isWindowActive())
        {
            driver->beginScene(true, true, SColor(0,0,50,50));
            env->drawAll();
            test->setRelativePosition({
                5, 5,
                (s32)driver->getScreenSize().Width - 5,
                (s32)driver->getScreenSize().Height - 5
            });
            driver->endScene();
        }
        }

        device->drop();

        return 0;
}


les coordonnées sont non uniforme, il faut utilise un cosinus pour avoir des coodonée polaire,
sinon les % peuvent avoir un rendue différents

Hors ligne


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
161 invités en ligne
membre en ligne: -
RSS Feed