not having SDL, ... this works:
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
|
const int LONGBUTTON_HEIGHT = 128;
const int LONGBUTTON_WIDTH = 256;
struct Graphic
{
enum state {DEFAULT, HOVER, INACTIVE, PRESSED, TOTAL};
int use_clip;
int x;
int y;
int h;
int w;
};
int main()
{
Graphic clips[Graphic::TOTAL];
for (int i = 0; i < Graphic::TOTAL; i++)
{
clips[i].x = i * LONGBUTTON_WIDTH;
clips[i].y = 0;
clips[i].w = LONGBUTTON_WIDTH;
clips[i].h = LONGBUTTON_HEIGHT;
}
clips[0].use_clip = Graphic::DEFAULT;
}
|
this works too, if you have multiple enums in one:
Graphic clips[Graphic::state::TOTAL]; //yikes, maybe consider a case-style and stick to it?
I do not know if this answered your question? I think you have a syntax error, the .state is wrong, state is not a variable, its a type...
if you want it to be a variable:
enum {DEFAULT, HOVER, INACTIVE, PRESSED, TOTAL} state; //eww, C code!
or better:
enum state_t {DEFAULT, HOVER, INACTIVE, PRESSED, TOTAL}; //whatever style you want.
state_t State;
then you could have this gem:
clips[0].State = Graphic::state_t::PRESSED;
disclaimer -- the language wants you to use the new enum class, but it is a giant hassle because you can't directly to/from int with it, which is half the point of enums in most practical code.