/*
* Place i so i->r.min = log, i->layer->screenr.min == scr.
*/
int
memlorigin(Memimage *i, Point log, Point scr)
{
Memlayer *l;
Memscreen *s;
Memimage *t, *shad, *nsave;
Rectangle x, newr, oldr;
Point delta;
int overlap, eqlog, eqscr, wasclear;
/*
* To clean up old position, make a shadow window there, don't paint it,
* push it behind this one, and (later) delete it. Because the refresh function
* for this fake window is a no-op, this will cause no graphics action except
* to restore the background and expose the windows previously hidden.
*/
shad = memlalloc(s, oldr, memlnorefresh, nil, DNofill);
if(shad == nil)
return -1;
s->frontmost = i;
if(s->rearmost == i)
s->rearmost = shad;
else
l->rear->layer->front = shad;
shad->layer->front = i;
shad->layer->rear = l->rear;
l->rear = shad;
l->front = nil;
shad->layer->clear = 0;
/*
* Shadow is now holding down the fort at the old position.
* Move the window and hide things obscured by new position.
*/
for(t=l->rear->layer->rear; t!=nil; t=t->layer->rear){
x = newr;
overlap = rectclip(&x, t->layer->screenr);
if(overlap){
memlhide(t, x);
t->layer->clear = 0;
}
}
l->screenr = newr;
l->delta = subpt(scr, i->r.min);
l->clear = rectinrect(newr, l->screen->image->clipr);
/*
* Everything's covered. Copy to new position and delete shadow window.
*/
if(wasclear)
memdraw(s->image, newr, s->image, oldr.min, nil, Pt(0,0), S);
else
memlexpose(i, newr);
memldelete(shad);