3 * a class for saving and restoring screen areas
4 * $Id: screenarea.cc,v 1.1 2001/06/27 13:42:07 konst Exp $
6 * Copyright (C) 1999-2001 by Konstantin Klyagin <k@thekonst.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include "screenarea.h"
27 screenarea::screenarea() {
30 screenarea::screenarea(int fx1
, int fy1
, int fx2
, int fy2
) {
31 save(fx1
, fy1
, fx2
, fy2
);
34 screenarea::~screenarea() {
38 void screenarea::save() {
39 save(0, 0, COLS
, LINES
);
42 void screenarea::save(int fx1
, int fy1
, int fx2
, int fy2
) {
51 for(i
= 0; i
<= fy2
-fy1
; i
++) {
52 line
= new chtype
[fx2
-fx1
+2];
54 line2
= new wchar_t[fx2
-fx1
+2];
56 mvinchnstr(fy1
+i
, fx1
, line
, fx2
-fx1
+1);
58 mvinnwstr(fy1
+i
, fx1
, line2
, fx2
-fx1
+1);
60 buffer
.push_back(line
);
62 buffer2
.push_back(line2
);
72 void screenarea::restore() {
73 restore(x1
, y1
, x2
, y2
);
76 void screenarea::restore(int fx1
, int fy1
, int fx2
, int fy2
) {
77 vector
<chtype
*>::iterator i
;
79 vector
<wchar_t *>::iterator j
;
89 for(i
= buffer
.begin(), j
= buffer2
.begin(); i
!= buffer
.end(); i
++, j
++) {
91 for(i
= buffer
.begin(); i
!= buffer
.end(); i
++) {
96 const chtype
*line_ptr
= line
;
97 const wchar_t *line2_ptr
= line2
;
98 for(l
= 0; l
< fx2
-fx1
+1; l
++, line_ptr
++, line2_ptr
++ )
100 attrset( (*line_ptr
& A_COLOR
) | (*line_ptr
& A_ATTRIBUTES
) );
101 mvaddnwstr(k
, fx1
+l
, line2_ptr
, 1);
105 mvaddchnstr(k
++, fx1
, line
, fx2
-fx1
+1);
116 void screenarea::freebuffer() {
117 while(!buffer
.empty()) {
118 delete[] buffer
.front();
119 buffer
.erase(buffer
.begin());
122 while(!buffer2
.empty()) {
123 delete[] buffer2
.front();
124 buffer2
.erase(buffer2
.begin());
129 bool screenarea::empty() {
130 return buffer
.empty();