jvcleave / ofxImGui

Use ImGui in openFrameworks
296 stars 124 forks source link

Please add ofColor conversion to IM_VEC4_CLASS_EXTRA in imconfig.h #13

Closed hluisi closed 8 years ago

hluisi commented 8 years ago

This will allow for easy use of ImColor( ofColor()), etc...

Currently mine looks like this:

#define MyVec2 ofVec2f
#define MyVec4 ofVec4f
#define MyColor ofColor

#define IM_VEC2_CLASS_EXTRA                                                 \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; }                       \
operator MyVec2() const { return MyVec2(x,y); }

#define IM_VEC4_CLASS_EXTRA                                                 \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; }     \
operator MyVec4() const { return MyVec4(x,y,z,w); }   \
ImVec4(const MyColor& f) { float sc = 1.0f/255.0f; x = f.r*sc; y = f.g*sc ; z = f.b*sc; w = f.a*sc; }   \
operator MyColor() const { return MyColor((int) (x*255.0f+0.5f), (int) (y*255.0f+0.5f), (int) (z*255.0f+0.5f), (int) (w*255.0f+0.5f)); }

#define ImDrawIdx ofIndexType
jvcleave commented 8 years ago

what is the +0.5f for? an epsilon?

hluisi commented 8 years ago

the c-style cast is a truncating conversion, the +0.5 is a fast way to make it into a round.

jvcleave commented 8 years ago

Cool - if you want to do a PR, I'll accept it. It also would be nice to have a snippet in the example-demo to explain it