Debian Codegraph @

garglk/winpair.cpp

raw symbols SCIP
1 // Copyright (C) 2006-2009 by Tor Andersson.
2 //
3 // This file is part of Gargoyle.
4 //
5 // Gargoyle is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // Gargoyle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Gargoyle; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #include "glk.h"
20 #include "garglk.h"
21
22 void win_pair_rearrange(window_t *win, const rect_t *box)
23 {
24 window_pair_t *dwin = win->winpair();
25 rect_t box1, box2;
26 int min, diff, split, splitwid, max;
27 window_t *key;
28 window_t *ch1, *ch2;
29
30 win->bbox = *box;
31
32 if (dwin->vertical) {
33 min = win->bbox.x0;
34 max = win->bbox.x1;
35 } else {
36 min = win->bbox.y0;
37 max = win->bbox.y1;
38 }
39 diff = max - min;
40
41 // We now figure split.
42 if (dwin->vertical) {
43 splitwid = gli_wpaddingx; // want border?
44 } else {
45 splitwid = gli_wpaddingy; // want border?
46 }
47
48 switch (dwin->division) {
49 case winmethod_Proportional:
50 split = (diff * dwin->size) / 100;
51 break;
52
53 case winmethod_Fixed:
54 key = dwin->key;
55 if (key == nullptr) {
56 split = 0;
57 } else {
58 switch (key->type) {
59 case wintype_TextBuffer:
60 if (dwin->vertical) {
61 split = dwin->size * gli_cellw + gli_tmarginx * 2;
62 } else {
63 split = dwin->size * gli_cellh + gli_tmarginy * 2;
64 }
65 break;
66 case wintype_TextGrid:
67 if (dwin->vertical) {
68 split = dwin->size * gli_cellw;
69 } else {
70 split = dwin->size * gli_cellh;
71 }
72 break;
73 case wintype_Graphics:
74 split = gli_zoom_int(dwin->size);
75 break;
76 default:
77 split = 0;
78 break;
79 }
80 }
81 break;
82
83 default:
84 split = diff / 2;
85 break;
86 }
87
88 if (!dwin->backward) {
89 split = max - split - splitwid;
90 } else {
91 split = min + split;
92 }
93
94 if (min >= max) {
95 split = min;
96 } else {
97 if (split < min) {
98 split = min;
99 } else if (split > max - splitwid) {
100 split = max - splitwid;
101 }
102 }
103
104 // TODO: constrain bboxes by wintype
105
106 if (dwin->vertical) {
107 box1.x0 = win->bbox.x0;
108 box1.x1 = split;
109 box2.x0 = split + splitwid;
110 box2.x1 = win->bbox.x1;
111 box1.y0 = win->bbox.y0;
112 box1.y1 = win->bbox.y1;
113 box2.y0 = win->bbox.y0;
114 box2.y1 = win->bbox.y1;
115 } else {
116 box1.y0 = win->bbox.y0;
117 box1.y1 = split;
118 box2.y0 = split + splitwid;
119 box2.y1 = win->bbox.y1;
120 box1.x0 = win->bbox.x0;
121 box1.x1 = win->bbox.x1;
122 box2.x0 = win->bbox.x0;
123 box2.x1 = win->bbox.x1;
124 }
125
126 if (!dwin->backward) {
127 ch1 = dwin->child1;
128 ch2 = dwin->child2;
129 } else {
130 ch1 = dwin->child2;
131 ch2 = dwin->child1;
132 }
133
134 gli_window_rearrange(ch1, &box1);
135 gli_window_rearrange(ch2, &box2);
136 }
137
138 void win_pair_redraw(window_t *win)
139 {
140 window_pair_t *dwin;
141 window_t *child;
142 int x0, y0, x1, y1;
143
144 if (win == nullptr) {
145 return;
146 }
147
148 dwin = win->winpair();
149
150 gli_window_redraw(dwin->child1);
151 gli_window_redraw(dwin->child2);
152
153 if (!dwin->backward) {
154 child = dwin->child1;
155 } else {
156 child = dwin->child2;
157 }
158
159 x0 = child->bbox.x0;
160 y0 = child->yadj != 0 ? child->bbox.y0 - child->yadj : child->bbox.y0;
161 x1 = child->bbox.x1;
162 y1 = child->bbox.y1;
163
164 if (dwin->vertical) {
165 int xbord = dwin->wborder ? gli_wborderx : 0;
166 int xpad = (gli_wpaddingx - xbord) / 2;
167 gli_draw_rect(x1 + xpad, y0, xbord, y1 - y0, gli_border_color);
168 } else {
169 int ybord = dwin->wborder ? gli_wbordery : 0;
170 int ypad = (gli_wpaddingy - ybord) / 2;
171 gli_draw_rect(x0, y1 + ypad, x1 - x0, ybord, gli_border_color);
172 }
173 }
174
175 void win_pair_click(window_pair_t *dwin, int x, int y)
176 {
177 int x0, y0, x1, y1;
178
179 if (dwin == nullptr) {
180 return;
181 }
182
183 x0 = dwin->child1->bbox.x0;
184 y0 = dwin->child1->bbox.y0;
185 x1 = dwin->child1->bbox.x1;
186 y1 = dwin->child1->bbox.y1;
187 if (x >= x0 && x <= x1 && y >= y0 && y <= y1) {
188 gli_window_click(dwin->child1, x, y);
189 }
190
191 x0 = dwin->child2->bbox.x0;
192 y0 = dwin->child2->bbox.y0;
193 x1 = dwin->child2->bbox.x1;
194 y1 = dwin->child2->bbox.y1;
195 if (x >= x0 && x <= x1 && y >= y0 && y <= y1) {
196 gli_window_click(dwin->child2, x, y);
197 }
198 }