#include "gameui.h" #define SET_RENDER_ITEM(idx,sp,px,py,f,abs,curid,mouseevt) \ do { \ gUI->renderList[idx].sprite = &(sp); \ gUI->renderList[idx].x = px; \ gUI->renderList[idx].y = py; \ gUI->renderList[idx].currframe = f; \ gUI->renderList[idx].absolute = abs; \ gUI->renderList[idx].onhovercursorid = curid; \ gUI->renderList[idx].onmousebuttonevent_proc = mouseevt; \ } while(0) void testevent(struct _renderItem_t *self, Uint8 button, Uint8 state, gameState_t *gState) { printf("BLAH !\n"); } int buildGameRenderList(gameRess_t *gRess, gameUI_t *gUI) { SET_RENDER_ITEM(RLI_terrain, gUI->terrainSprite,0,0,0,1,2,NULL); SET_RENDER_ITEM(RLI_lem0, gRess->lemmingAnims[0],700,200,0,0,5,testevent); SET_RENDER_ITEM(RLI_cursor, gRess->cursor,0,0,0,1,0,NULL); gUI->cursor = &gUI->renderList[RLI_cursor]; return 0; } renderItem_t * findActionnableItemUnderCursor(gameUI_t *gUI) { int i; for (i=MAX_RENDERLIST_SIZE-1; i>=0; i--) { if ( gUI->renderList[i].onmousebuttonevent_proc ) { SDL_Rect curhot; curhot.x=gUI->cursor->x + gUI->cursor->sprite->size.w / 2; curhot.y=gUI->cursor->y + gUI->cursor->sprite->size.h / 2; curhot.w=1; curhot.h=1; if ( SDL_HasIntersection(&curhot, &gUI->renderList[i].lastDstRect) ) { return &gUI->renderList[i]; } } } return NULL; }