summaryrefslogtreecommitdiff
path: root/ycurses/src/curses/coordinate.cpp
blob: efdf9e2ad93665718f7ad0c6a571ec77696b0d5c (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef COORDONATE_CPP
#define COORDONATE_CPP

#include "coordinate.h"

coordinate::coordinate()
{
  y = x = 0;
}

coordinate::coordinate(coordinate_type type, dummy_window& r_win)
{
  set(type, r_win);
}

coordinate::coordinate(coordinate_type type)
{
  set(type);
}

coordinate::coordinate(int y, int x)
{
  this->y = y;
  this->x = x;
}

coordinate&
coordinate::set(coordinate_type type, dummy_window& r_win)
{
  switch (type)
  {
    case Absolutecoord:
    	getyx(r_win.get_WINDOW(), y, x);
	break;

    case Relativecoord:
    	getparyx(r_win.get_WINDOW(), y, x);
	break;

    case Beginningcoord:
       	getbegyx(r_win.get_WINDOW(), y, x);
	break;

    case windowSize:
    	getmaxyx(r_win.get_WINDOW(), y, x);
	break;

    default:
	set(type);
  }

  return *this;
}

coordinate&
coordinate::set(coordinate_type type)
{
  switch (type)
  {
    case TerminalSize:
    	y = COLS;
    	x = LINES;
	break;

    case TerminalCenter:
    	y = static_cast<int>(COLS / 2);
    	x = static_cast<int>(LINES / 2);
	break;
  }

  return *this;
}

coordinate&
coordinate::left()
{
  return left(1);
}

coordinate&
coordinate::right()
{
  return right(1);
}

coordinate&
coordinate::up()
{
  return up(1);
}

coordinate&
coordinate::down()
{
  return down(1);
}

coordinate&
coordinate::left(int i)
{
  x -= i;
  return *this;
}

coordinate&
coordinate::right(int i)
{
  x += i;
  return *this;
}

coordinate&
coordinate::up(int i)
{
  y -= i;
  return *this;
}

coordinate&
coordinate::down(int i)
{
  y += i;
  return *this;
}

coordinate&
coordinate::displace(int i_y, int i_x)
{
  y += i_y;
  x += i_x;
  return *this;
}

#endif