summaryrefslogtreecommitdiff
path: root/src/gameui.c
blob: c099e45ed0821de5e174af9ead0eaddbd3ca18c5 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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;
}