aboutsummaryrefslogtreecommitdiff
path: root/ui_ani.c
blob: 2ba395bbb416ffd85d063dad0cab7718ba5b5e9d (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
47
48
49
50
51
52
53
54
55
56
#include <stdlib.h>

#include "ui.h"
#include "ui_ani.h"

#define ANIC_INITSTATE '|'


struct anic *
init_anic(unsigned int x, unsigned int y, chtype attrs)
{
  struct anic *a = calloc(1, sizeof(struct anic));

  a->x = x;
  a->y = y;
  a->state = ANIC_INITSTATE;
  a->attrs = attrs;
  return (a);
}

void
free_anic(struct anic *a)
{
  free(a);
}

int
anic_cb(WINDOW *win, void *data, bool timed_out)
{
  struct anic *a = (struct anic *) data;

  if (a == NULL) return (UICB_ERR_UNDEF);
  if (timed_out == true) {
    switch (a->state) {
      default:
      case '|': a->state = '/'; break;
      case '/': a->state = '-'; break;
      case '-': a->state = '\\'; break;
      case '\\': a->state = '|'; break;
    }
  }
  attron(a->attrs);
  if (win != NULL) {
    mvwaddch(win, a->y, a->x, a->state);
  } else {
    mvaddch(a->y, a->x, a->state);
  }
  attroff(a->attrs);
  return (UICB_OK);
}

void
register_anic(struct anic *a)
{
  register_ui_elt(anic_cb, (void *) a, NULL);
}