frselect.c - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       frselect.c (2426B)
       ---
            1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
            2 #include <u.h>
            3 #include <libg.h>
            4 #include <frame.h>
            5 
            6 void
            7 frselect(Frame *f, Mouse *m)    /* when called, button 1 is down */
            8 {
            9     uint64_t p0, p1, q;
           10     Point mp, pt0, pt1, qt;
           11 
           12     mp = m->xy;
           13 
           14     Again:
           15     f->modified = 0;
           16     frselectp(f, F&~D);
           17     p0 = p1 = frcharofpt(f, mp);
           18     pt0 = frptofchar(f, p0);
           19     pt1 = frptofchar(f, p1);
           20     frselectf(f, pt0, pt1, F&~D);
           21     do{
           22         if(f->modified) /* special hack so 8½ can frselect in parallel */
           23             goto Again;
           24         q = frcharofpt(f, m->xy);
           25         if(p1 != q){
           26             if(p0 == p1)
           27                 frselectf(f, pt0, pt1, F&~D);
           28             qt = frptofchar(f, q);
           29             if(p1 < q)
           30                 frselectf(f, pt1, qt, F&~D);
           31             else
           32                 frselectf(f, qt, pt1, F&~D);
           33             p1 = q;
           34             pt1 = qt;
           35             if(p0 == p1)
           36                 frselectf(f, pt0, pt1, F&~D);
           37         }
           38         f->modified = 0;
           39         if(p0 < p1)
           40             f->p0 = p0, f->p1 = p1;
           41         else
           42             f->p0 = p1, f->p1 = p0;
           43         frgetmouse();
           44     }while((m->buttons & 7) == 1);
           45 }
           46 /* it is assumed p0<=p1 and both were generated by frptofchar() */
           47 void
           48 frselectf(Frame *f, Point p0, Point p1, Fcode c)
           49 {
           50     int n;
           51     Point q0, q1;
           52 
           53     if(p0.x == f->left)
           54         p0.x = f->r.min.x;
           55     if(p1.x == f->left)
           56         p1.x = f->r.min.x;
           57     q0 = p0;
           58     q1 = p1;
           59     q0.y += f->fheight;
           60     q1.y += f->fheight;
           61     n = (p1.y-p0.y)/f->fheight;
           62     if(f->b == 0)
           63         berror("frselectf b==0");
           64     if(p0.y == f->r.max.y)
           65         return;
           66     if(n == 0){
           67         if(p0.x == p1.x){
           68             if(p0.x == f->r.min.x)
           69                 q1.x++;
           70             else
           71                 p0.x--;
           72         }
           73         bitblt2(f->b, p0, f->b, Rpt(p0, q1), c, 0, f->bg);
           74     }else{
           75         if(p0.x >= f->r.max.x)
           76             p0.x = f->r.max.x-1;
           77         bitblt2(f->b, p0, f->b, Rect(p0.x, p0.y, f->r.max.x, q0.y), c, 0, f->bg);
           78         if(n > 1)
           79             bitblt2(f->b, Pt(f->r.min.x, q0.y),
           80                 f->b, Rect(f->r.min.x, q0.y, f->r.max.x, p1.y), c, 0, f->bg);
           81         bitblt2(f->b, Pt(f->r.min.x, p1.y),
           82                 f->b, Rect(f->r.min.x, p1.y, q1.x, q1.y), c, 0, f->bg);
           83     }
           84 }
           85 
           86 void
           87 frselectp(Frame *f, Fcode c)
           88 {
           89     Point pt0, pt1;
           90 
           91     pt0 = frptofchar(f, f->p0);
           92     pt1 = (f->p0==f->p1)? pt0 : frptofchar(f, f->p1);
           93     frselectf(f, pt0, pt1, c);
           94 }