/* TUIpeer works in conjunction with an implementation of java.awt.Toolkit to provide a Text User Interface for programs using the Java AWT. Copyright (C) 1997-2000 Stuart D. Gathman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #pragma implementation #include #include "windraw.h" WindowContext::WindowContext(): DrawingContext(Rect(0,0,-1,-1)) { setframe(new Frame("","")); panx = pany = 0; active = false; } WindowContext::~WindowContext() { } void WindowContext::setActive(bool f) { if (f != active) { active = f; frame->settype(f ? frame->DOUBLE : frame->SINGLE); } } void WindowContext::setCaption(const char *s) { frame->set(frame->title,s); } void WindowContext::setTitle(const char *s) { frame->set(s,frame->desc); } void WindowContext::setphys(const Rect &r) { FrameWin::setphys(r); cliprect = Rect(0,0,loc.height() - 1,loc.width() - 1); } void WindowContext::draw(const Rect &r) { IndirectContext gc(this); gc.clipRect(r.moverel(pany - translatey,panx - translatex)); //gc.translate(-panx,-pany); paint(&gc); } void WindowContext::writeAttr(int x,int y,int n,const CHTYPE *a) { write(y - pany + translatey,x - panx + translatex,n,a); } void WindowContext::copyArea(const Rect &r,int dx,int dy) { if (dy) slide(r.moverel(translatey-pany,translatex-panx),DIR_DOWN,dy); if (dx) slide(r.moverel(translatey-pany,translatex-panx),DIR_RIGHT,dx); } void WindowContext::fillRect(const Rect &r,CHTYPE attr) { fill(r.moverel(translatey-pany,translatex-panx),attr); } void WindowContext::setCursor(int x,int y) { //fprintf(stderr,"curpos(%d,%d)\n",y,x); x += translatex; y += translatey; int dx = panx, dy = pany; if (x < panx && x >= 0) panx = x; if (y < pany && y >= 0) pany = y; int w = loc.width(); if (x >= panx + w) panx = x - w + 1; int h = loc.height(); if (y >= pany + h) pany = y - h + 1; dx -= panx; dy -= pany; if (dx || dy) { Rect clip(0,0,h-1,w-1); fprintf(stderr,"setCursor: dx=%d dy=%d\n",dx,dy); if (dx) redraw(); else slide(clip,DIR_DOWN,dy); } Window::curpos(y - pany,x - panx); } int WindowContext::getX() const { return col + panx - translatex; } int WindowContext::getY() const { return row + pany - translatey; }