aboutsummaryrefslogtreecommitdiff
path: root/render/button.c
blob: 8896f364510cfc361c2c3ae11a812b3a8bcb687a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib.h>
#include <stdio.h>
#include "button.h"

#include "../umath/intersect.h"

int mouse_in_button (float pt[], txtd *t, button *b) {
    int width = get_text_width(b->txt, t);
    float size[2] = { width+b->pad*2, 10+b->pad*2 };
    if (pt_rect(pt, b->pos, size)) return 1;
    return 0;
}

void render_button (SDL_Renderer* rend, txtd *t, button *b) {
    int width = get_text_width(b->txt, t);
    SDL_Rect rect = { b->pos[0], b->pos[1], width+b->pad*2, 10+b->pad*2 };
    SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
    SDL_RenderDrawRect(rend, &rect);
    float offpad[2] = { b->pos[0]+b->pad, b->pos[1]+b->pad };
    render_text(rend, b->txt, offpad, t);
}