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 !
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 | #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 [email protected] * * 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 |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | #include "CGUIPieChart.h" #include <irrlicht/IGUIEnvironment.h> #include <irrlicht/IVideoDriver.h> #include <irrlicht/S3DVertex.h> #include <irrlicht/irrMath.h> #include <irrlicht/SColor.h> #include <iostream> namespace irr { namespace gui { CGUIPieChartElement::CGUIPieChartElement(float f, float t, const video::SColor &c, float d) : clr(c), depth(d) { set(f, t); } void CGUIPieChartElement::set(float f, float t) { from = f; to = t; } void CGUIPieChartElement::setDepth(float i) { for(int j = 0; j<pos.size(); ++j) { pos[j].pointA.Z = i; pos[j].pointB.Z = i; pos[j].pointC.Z = i; } depth = i; } void CGUIPieChartElement::setColor(const video::SColor &i) { clr = i; } core::vector3df CGUIPieChartElement::calc(float i) { core::vector3df f(0, 0, depth); if(i >= 0.75f && i < 1.0f) f.X = core::clamp((1.00f-i)*4, 0.f, 1.f); if(i >= 0.50f && i < 0.75f) { f.Y = core::clamp((0.75f-i)*4, 0.f, 1.f); f.X = 1.f; } if(i >= 0.25f && i < 0.50f) { f.Y = 1.f; f.X = 1.f - core::clamp((0.50f-i)*4, 0.f, 1.f); } if(i > 0.f && i <= 0.25f) f.Y = 1.f - core::clamp((0.25f-i)*4, 0.f, 1.f); return f; } void CGUIPieChartElement::calc(float from, float to) { if(to-from <= 0.0000001f) return; if(from > to || to > 1.f) { calc(from, 1.f); calc(0.f, to-(int)to); return; } float next = to; if(from >= 0.00f) next = core::min_(to, 0.25f); if(from >= 0.25f) next = core::min_(to, 0.50f); if(from >= 0.50f) next = core::min_(to, 0.75f); if(from >= 0.75f) next = core::min_(to, 1.0f); if(next != to) { calc(from, next); calc(next, to); } else { pos.push_back({ calc(from), { 0.5f, 0.5f, depth}, calc(next) }); } } /***************************************************/ CGUIPieChart::CGUIPieChart(IGUIEnvironment *environment, IGUIElement *parent, const core::recti &size, s32 id) noexcept : IGUIElement(EGUIET_ELEMENT , environment, parent, id, size), bg(nullptr), fg(nullptr), driver(environment->getVideoDriver()), clr(255, 128, 128, 128) { mat.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; mat.BackfaceCulling = false; } CGUIPieChart::~CGUIPieChart() noexcept { if(bg) bg->drop(); if(fg) fg->drop(); } void CGUIPieChart::add(const CGUIPieChartElement& i) { item.push_back(i); } CGUIPieChartElement& CGUIPieChart::get(int i) { return *(item.begin()+i); } bool CGUIPieChart::erase(int i) { if(i >= count()) return false; auto it = item.begin(); it += i; item.erase(it); return true; } int CGUIPieChart::count() const { return item.size(); } void CGUIPieChart::setForegroundTexture(video::ITexture *f) { mat.setTexture(0, f); if(f) f->grab(); if(fg) fg->drop(); fg = f; } void CGUIPieChart::setBackgroundTexture(video::ITexture *b) { if(b) b->grab(); if(bg) bg->drop(); bg = b; } void CGUIPieChart::setBackgroundColor(const irr::video::SColor &i) { clr = i; } video::SColor CGUIPieChart::getBackgroundColor() const { return clr; } video::ITexture* CGUIPieChart::getForegroundTexture() const { return fg; } video::ITexture* CGUIPieChart::getBackgroundTexture() const { return bg; } void CGUIPieChart::updateAbsolutePosition() { auto size = AbsoluteRect.getSize(); auto &start = AbsoluteRect.UpperLeftCorner; vtx.clear(); idx.clear(); for(auto &it : item) { it.pos.clear(); it.calc(it.from, it.to); for(int i = 0; i<it.pos.size(); ++i) { idx.push_back(vtx.size()); vtx.push_back({ start.X + it.pos[i].pointA.X * size.Width, start.Y + it.pos[i].pointA.Y * size.Height, it.pos[i].pointA.Z, 0.f, 0.f, 1.f, it.clr, it.pos[i].pointA.X, it.pos[i].pointA.Y }); idx.push_back(vtx.size()); vtx.push_back({ start.X + it.pos[i].pointB.X * size.Width, start.Y + it.pos[i].pointB.Y * size.Height, it.pos[i].pointB.Z, 0.f, 0.f, 1.f, it.clr, it.pos[i].pointB.X, it.pos[i].pointB.Y }); idx.push_back(vtx.size()); vtx.push_back({ start.X + it.pos[i].pointC.X * size.Width, start.Y + it.pos[i].pointC.Y * size.Height, it.pos[i].pointC.Z, 0.f, 0.f, 1.f, it.clr, it.pos[i].pointC.X, it.pos[i].pointC.Y }); } } IGUIElement::updateAbsolutePosition(); } void CGUIPieChart::draw() { if(bg) { const video::SColor Colors[] = {clr, clr, clr, clr}; core::rect<s32> sourceRect = core::rect<s32>(core::dimension2di(bg->getOriginalSize())); driver->draw2DImage( bg, AbsoluteRect, sourceRect, &AbsoluteClippingRect, Colors, true ); } else { Environment->getSkin()->draw3DSunkenPane( this, clr, true, true, AbsoluteRect, &AbsoluteClippingRect ); } driver->setMaterial(mat); driver->draw2DVertexPrimitiveList( vtx.pointer(), vtx.size(), idx.pointer(), idx.size()/3, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT ); IGUIElement::draw(); } } } |
utilisation:
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é |
---|---|---|---|---|
Corrections |
|
xhtml 1.0 css 2.1 Propulsé par FluxBB Traduit par FluxBB.fr |
882 membres 1429 sujets 11119 messages |
Dernier membre inscrit: LiseBuisson96 60 invités en ligne Aucun membre connecté RSS Feed |