I’ve created a structure called panel which render in OpenGL,works fine,but I want to add this to panel:
int flags;
then I define this in header :
#define PANEL_TITLE 0x0001
#define PANEL_MOVEABLE 0x0002
#define PANEL_SHADOW 0x0003
to use the flags value like this:
panel.flags = PANEL_TITLE | PANEL_MOVEABLE;
instead of have a lot :(which looks not good)
bool panel_has_title;
bool panel_moveable;
bool panel_shadow;
then check bool value,instead I can just have single int to achieve same result.I have read a lot open source stuff,that use flags,like the code above.
however my problem is it doesn’t work,when I check the flags with:
panel.flags = PANEL_TITLE | PANEL_MOVEABLE;
if(panel.flags & PANEL_TITLE) //this one works
{
}
if(panel.flags & PANEL_MOVEABLE) //this one doesn't work
{
//not gets called
}
edit:
ok,now I’ve change it to
#define PANEL_TITLE 0x0002
#define PANEL_MOVEABLE 0x0004
#define PANEL_SHADOW 0x0008
are they intersect with each other again?
the new problem is if I set
panel.flags = PANEL_TITLE;
then every functions inside of it gets called
if(panel.flags & PANEL_TITLE)
{
//called which is normal
}
if(panel.flags & PANEL_MOVEABLE)
{
//called ..
}
if(panel.flags & PANEL_SHADOW)
{
//called ..
}
is it normal?
The problem here is that the bitmasks intersect with each other.
e.g. (simplefied for 8 bit)
What you want is this:
edit to your edit:
you don’t set them like that, you set them with:
And for the last problem, I can’t see anything wrong at first sight, try to step over it with a debugger and output the variable, that will give you a much clearer view of the problem