summaryrefslogtreecommitdiff
path: root/ycurses/src/curses/attributes.cpp
blob: b859da028b2ea59da4fe9642a63f11a0b90a7fae (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef ATTRIBUTES_CPP
#define ATTRIBUTES_CPP

#include "attributes.h"

attributes::attributes()
{
  init();
}

attributes::attributes(int i_attr)
{
  init();
  set(true, i_attr);
}

attributes::attributes(color& r_color)
{
  init();
  set_color(r_color);
}

void
attributes::init()
{
  p_color = 0;
}

void
attributes::use_wattron(WINDOW* p_window)
{
  std::set<int>::iterator iter;
  for (iter = set_attr.begin(); iter != set_attr.end(); ++iter)
    wattron(p_window, *iter);

  if (p_color)
    wattron(p_window, COLOR_PAIR(p_color->get_num()));
}

void
attributes::use_wattroff(WINDOW* p_window)
{
  std::set<int>::iterator iter;
  for (iter = set_attr.begin(); iter != set_attr.end(); ++iter)
    wattroff(p_window, *iter);

  if (p_color)
    wattroff(p_window, COLOR_PAIR(p_color->get_num()));
}


void
attributes::unset_all()
{
  set_attr.clear();
  p_color = 0;
}

bool
attributes::get(int i_attr)
{
  return set_attr.find(i_attr) != set_attr.end();   
}

void
attributes::set(bool b, int i_attr)
{
  if ((set_attr.find(i_attr) != set_attr.end() ) == b)
    return;

  set_attr.insert(i_attr);
}

void
attributes::set_color(color& r_color)
{
  this->p_color = &r_color;
}

#endif