MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Color.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 
6 #ifndef _MGColor_HH_
7 #define _MGColor_HH_
8 
9 #include "mgGL/GLAttrib.h"
10 #include "mgGL/Pixel.h"
11 
12 class MGOfstream;
13 class MGIfstream;
14 class MGColors;
15 class mgVBO;
16 
17 //
18 //Define MGColor Class.
25 class MG_DLL_DECLR MGColor:public MGGLAttrib{
27 
28 public:
29 
30 enum MODE{
33  ENABLED=1,
34 };
35 
38 
40 enum ColorID{
41  dummy = 0,
42  Black = 1,
43  Red = 2,
44  Green = 3,
45  Blue = 4,
46  Yellow = 5,
47  Magenta = 6,
48  Cyan = 7,
49  White = 8,
52  Aqua ,
95  Gold ,
97  Gray ,
173  Tan ,
183  endID
184 };
185 
186 MGColor(MODE m=UNDEFINED):MGGLAttrib(static_cast<int>(m)){;};
187 
189 MGColor(float red, float green, float blue, float alpha=1.);
190 MGColor(const MGPixel& pixel);
191 
194 explicit MGColor(unsigned int argb);
195 
197 MGColor& operator=(const MGGel& gel2);
198 MGColor& operator=(const MGColor& gel2);
199 
203 MGColor& operator*=(float scale);
204 
208 MGColor& operator+=(float value);
209 
211 bool operator<(const MGColor& gel2)const;
212 bool operator<(const MGGel& gel2)const;
213 
215 
217 void argb_to_float(unsigned int argb, float out[4]) const;
218 
220 MGColor* clone()const;
221 
223 void exec()const;
224 
226 void exec(mgVBO& vbo)const;
227 
228 float* color(){return m_color;};
229 const float* color()const{return m_color;};
230 
234 int get_ColorID(int maxID)const;
235 
237 static const MGColor& get_instance(ColorID id);
238 
240 bool is_highlight_attrib()const{return true;};
241 
244 static int get_ARGBinstance(MGColor::ColorID id);
245 
248 unsigned int get_colorAsUInt();
249 
250 void set_color(const float color[4]);
251 void set_color(float red, float green, float blue, float alpha=1.);
252 void get_color(float color[4])const;
253 void get_color(float& red, float& green, float& blue, float& alpha)const;
254 
256 void drawAttrib(
257  mgVBO& vbo,
258  bool no_color=false
259 )const;
260 
262 void render(mgVBO& vbo)const{exec(vbo);};
263 
265 void set_draw_attrib_mask(unsigned int& mask)const{set_Amask(mask,CURRENT_BIT);};
266 
268 void reset_draw_attrib_mask(unsigned int& mask)const{reset_Amask(mask,CURRENT_BIT);};
269 
273 void set_enabled(){m_flag=ENABLED;};
274 
276 void set_render_attrib_mask(unsigned int& mask)const{set_Amask(mask,CURRENT_BIT);};
277 
279 void reset_render_attrib_mask(unsigned int& mask)const{reset_Amask(mask,CURRENT_BIT);};
280 
282 long identify_type() const{return MGCOLOR_TID;};
283 
284 std::string whoami()const{return "Color";};
285 
287 void ReadMembers(MGIfstream& buf);
289 void WriteMembers(MGOfstream& buf)const;
290 
292 std::ostream& out(std::ostream&) const;
293 
296 int out_to_IGES(
297  MGIgesOfstream& igesfile,
298  int SubordinateEntitySwitch=0
299 )const;
300 
301 private:
302 
303  float m_color[4];
304  static MGColors m_colors;
305 
306  friend class MGColors;
307 
308 };
309 
311 
313 class MG_DLL_DECLR MGColors{
314 public:
315  const MGColor& color(int i){return *(m_colors[i]);};
316  ~MGColors();
317 private:
318  MGColor** m_colors;
319  MGColors();
320  friend class MGColor;
321 };
322 
324 
325 
326 namespace{
328  return MGColor(
329  GetRValue(color)/255.f,
330  GetGValue(color)/255.f,
331  GetBValue(color)/255.f);
332  }
333 
334 }
335 
336 inline COLORREF ARGBtoCOLORREF(DWORD dwColor){
337  BYTE r = (BYTE)((dwColor & 0x00FF0000) >> 16);
338  BYTE g = (BYTE)((dwColor & 0x0000FF00) >> 8);
339  BYTE b = (BYTE)(dwColor & 0x000000FF);
340  return RGB(r, g, b);
341 }
342 
343 inline DWORD COLORREFtoARGB(COLORREF cl){
344  BYTE r = GetRValue(cl);
345  BYTE g = GetGValue(cl);
346  BYTE b = GetBValue(cl);
347  return (r << 16) | (g << 8) | b;
348 }
349  // end of GLAttrib group
351 
352 #endif //#ifndef _MGColor_HH_
Definition: Color.h:146
Definition: Color.h:100
Definition: Color.h:68
Definition: Color.h:116
Definition: Color.h:104
Definition: Color.h:166
Definition: Color.h:82
Definition: Color.h:118
Definition: Color.h:92
Definition: Color.h:101
void reset_Amask(unsigned int &mask, MGGLAttrib::ATTRIB_MASK bit)
float * color()
Definition: Color.h:228
std::string whoami() const
Definition: Color.h:284
Definition: Color.h:155
Definition: Color.h:132
Definition: Color.h:138
Definition: Color.h:90
MGGLAttrib is an abstract class which defines the enum of undefined or disabled.
Definition: GLAttrib.h:35
Definition: Color.h:111
void set_Amask(unsigned int &mask, MGGLAttrib::ATTRIB_MASK bit)
Set or reset the bit of mask.
virtual int out_to_IGES(MGIgesOfstream &igesfile, int SubordinateEntitySwitch=0) const
Definition: Gel.h:93
Definition: GLAttrib.h:41
Definition: Color.h:144
ColorID
The color id from 1 to 8(black to white) is the id of IGES.
Definition: Color.h:40
virtual bool operator<(const MGGel &gel2) const
Definition: Color.h:51
Definition: Color.h:63
Definition: Color.h:131
Definition: Color.h:127
Definition: Color.h:85
Definition: Color.h:164
virtual MGGLAttrib * clone() const =0
Generate a newed clone object.
virtual void WriteMembers(MGOfstream &buf) const
Write all member data.
Definition: Color.h:89
Definition: Color.h:66
void set_draw_attrib_mask(unsigned int &mask) const
Turn on the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Color.h:265
Definition: Color.h:165
Definition: Color.h:150
Definition: Color.h:136
Definition: Color.h:74
Definition: Color.h:84
Definition: Color.h:55
virtual void ReadMembers(MGIfstream &buf)
Read all member data.
Definition: Color.h:170
Definition: Color.h:176
Definition: Color.h:117
Definition: Color.h:59
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
Definition: Color.h:158
virtual MGGLAttrib & operator=(const MGGLAttrib &gel2)
Definition: GLAttrib.h:70
Definition: Color.h:107
Definition: Color.h:57
Definition: Color.h:110
Definition: Color.h:173
Definition: Color.h:56
Definition: GLAttrib.h:40
Definition: Color.h:139
COLORREF ARGBtoCOLORREF(DWORD dwColor)
Definition: Color.h:336
Definition: Color.h:159
MG_DLL_DECLR MGVector & operator*=(MGVector &v, const MGMatrix &m)
Definition: Color.h:78
Definition: Color.h:119
virtual void drawAttrib(mgVBO &vbo, bool no_color=false) const =0
draw GLAttribute process.
Definition: Color.h:109
Definition: Color.h:175
const float * color() const
Definition: Color.h:229
Definition: Color.h:128
Definition: Color.h:83
MGColor defines the OpenGL color (R,G,B,A).
Definition: Color.h:26
Definition: Color.h:113
Definition: Color.h:163
Definition: Color.h:140
Definition: Color.h:80
Definition: Color.h:95
Definition: Color.h:174
MGGel is an abstract class which represents a group element.
Definition: Gel.h:53
Definition: Color.h:162
Definition: Color.h:62
Definition: Color.h:168
Definition: Color.h:135
Definition: Color.h:153
Definition: Color.h:114
Definition: Color.h:105
Definition: Color.h:143
Definition: Color.h:81
Definition: Color.h:69
Definition: Color.h:177
Definition: Color.h:94
DWORD COLORREFtoARGB(COLORREF cl)
Definition: Color.h:343
Definition: Color.h:161
Definition: Color.h:60
Definition: Color.h:108
Definition: Color.h:86
Definition: Color.h:70
bool is_highlight_attrib() const
Test if this is highlight attrib or not.
Definition: Color.h:240
Definition: Color.h:65
Definition: Color.h:91
Definition: Color.h:160
Definition: Color.h:167
Definition: Color.h:141
Definition: Color.h:102
Definition: Color.h:96
Definition: Color.h:54
Definition: Color.h:124
Definition: Color.h:106
Definition: Color.h:152
Definition: Color.h:171
Definition: Color.h:130
void reset_draw_attrib_mask(unsigned int &mask) const
Turn off the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Color.h:268
Definition: Color.h:180
virtual std::ostream & out(std::ostream &) const
Output virtual function.
Definition: Color.h:148
Definition: Color.h:172
Definition: Color.h:103
Definition: Color.h:125
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
Definition: Color.h:93
Definition: Color.h:182
MGColor FromCOLORREF(COLORREF color)
Definition: Color.h:327
Definition: Color.h:64
Definition: Color.h:169
MGColor(MODE m=UNDEFINED)
Definition: Color.h:186
Definition: Color.h:157
Definition: Color.h:151
Definition: Color.h:58
Definition: Color.h:149
Definition: Color.h:115
MGOgesIfstream write out to *.iges file, transforming MGCL objects to IGES objects.
Definition: IgesOfstream.h:26
Definition: Color.h:129
Definition: Color.h:72
Definition: Color.h:75
Definition: Color.h:120
Definition: Color.h:154
Definition: Color.h:53
Definition: Color.h:121
Definition: Color.h:98
Definition: Color.h:99
Definition: Color.h:137
MODE
Definition: Color.h:30
long identify_type() const
Return This object's typeID.
Definition: Color.h:282
Definition: Color.h:97
Definition: Color.h:50
Definition: Color.h:52
Definition: Color.h:181
void render(mgVBO &vbo) const
render GLAttribute process.
Definition: Color.h:262
Definition: Color.h:122
Definition: Color.h:126
Definition: Color.h:142
Definition: Color.h:147
Definition: Color.h:71
Definition: Color.h:77
Definition: Color.h:79
OpenGL 4 用描画のためのクラス, in other words, display list.
Definition: VBO.h:76
Definition: Color.h:112
Definition: Color.h:61
void set_render_attrib_mask(unsigned int &mask) const
Turn on the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Color.h:276
Definition: Color.h:73
Definition: Color.h:67
void set_enabled()
Definition: Color.h:273
Definition: Color.h:133
Definition: Color.h:123
Definition: Color.h:178
Definition: Color.h:179
Definition: Color.h:156
Definition: Color.h:87
Definition: Color.h:88
Define MGPixel Class of (R,G,B,A) pixel data.
Definition: Pixel.h:18
void reset_render_attrib_mask(unsigned int &mask) const
Turn off the appropriate mask bit for this attribute. See glPushAttrib().
Definition: Color.h:279
Definition: Color.h:145
Definition: Color.h:134
Definition: Color.h:76