diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | appl/wm/mand.b | 45 | ||||
| -rw-r--r-- | include/version.h | 2 | ||||
| -rw-r--r-- | libinterp/tk.c | 36 | ||||
| -rw-r--r-- | man/2/tk | 2 |
5 files changed, 61 insertions, 27 deletions
@@ -1,3 +1,6 @@ +20110419 + libinterp/tk.c:/^Tk_rect shouldn't return non-canonical rectangles + /appl/wm/mand.b handle reshape to empty rectangles 20110408 appl/lib/json.b - have writeval produce same (correct) form as .text for Real [issue 230] 20110407 diff --git a/appl/wm/mand.b b/appl/wm/mand.b index 7e060722..e3084fc2 100644 --- a/appl/wm/mand.b +++ b/appl/wm/mand.b @@ -94,6 +94,8 @@ Fracpoint: adt { Fracrect: adt { min, max: Fracpoint; + dx: fn(r: self Fracrect): real; + dy: fn(r: self Fracrect): real; }; Params: adt { @@ -189,9 +191,10 @@ init(ctxt: ref Context, argv : list of string) colours[i] = ctxt.display.rgb(col(i/(G*B), R), col(i/(1*B), G), col(i/(1*1), B)); + canvr := canvposn(win); specr := Fracrect((-2.0, -1.5), (1.0, 1.5)); p := Params( - correctratio(specr, win), + correctratio(specr, canvr), (0.0, 0.0), 1, # m 1, # kdivisor @@ -200,7 +203,6 @@ init(ctxt: ref Context, argv : list of string) pid := -1; sync := chan of int; imgch := chan of (ref Image, Rect); - canvr := canvposn(win); spawn docalculate(sync, p, imgch); pid = <-sync; imgch <-= (win.image, canvr); @@ -290,11 +292,14 @@ init(ctxt: ref Context, argv : list of string) if (pid != -1) kill(pid); win.image.flush(Draw->Flushoff); - p.r = correctratio(specr, win); - sync = chan of int; - spawn docalculate(sync, p, imgch); - pid = <-sync; - imgch <-= (win.image, canvposn(win)); + wr := canvposn(win); + if(!isempty(wr)){ + p.r = correctratio(specr, wr); + sync = chan of int; + spawn docalculate(sync, p, imgch); + pid = <-sync; + imgch <-= (win.image, wr); + } } } } @@ -318,21 +323,22 @@ winreq(win: ref Tk->Toplevel, c: string, imgch: chan of (ref Image, Rect), termi return 0; } -correctratio(r: Fracrect, win: ref Tk->Toplevel): Fracrect +correctratio(r: Fracrect, wr: Rect): Fracrect { # make sure calculation rectangle is in # the same ratio as bitmap (also make sure that # calculated area always includes desired area) - wr := canvposn(win); - (btall, atall) := (real wr.dy() / real wr.dx(), (r.max.y - r.min.y) / (r.max.x - r.min.x)); + if(isempty(wr)) + return ((0.0,0.0), (0.0,0.0)); + (btall, atall) := (real wr.dy() / real wr.dx(), r.dy() / r.dx()); if (btall > atall) { # bitmap is taller than area, so expand area vertically - excess := (r.max.x - r.min.x) * btall - (r.max.y - r.min.y); + excess := r.dx()*btall - r.dy(); r.min.y -= excess / 2.0; r.max.y += excess / 2.0; } else { # area is taller than bitmap, so expand area horizontally - excess := (r.max.y - r.min.y) / btall - (r.max.x - r.min.x); + excess := r.dy()/btall - r.dx(); r.min.x -= excess / 2.0; r.max.x += excess / 2.0; } @@ -423,6 +429,11 @@ canvposn(win: ref Tk->Toplevel): Rect return tk->rect(win, ".c", Tk->Local); } +isempty(r: Rect): int +{ + return r.dx() <= 0 || r.dy() <= 0; +} + calculate(p: Params, imgch: chan of (ref Image, Rect)) { calc := ref Calc; @@ -779,6 +790,16 @@ horizline(calc: ref Calc, d: ref Image, x0, x1, y: int, col: int) # r.max = r.max.add((1, 1)); } +Fracrect.dx(r: self Fracrect): real +{ + return r.max.x - r.min.x; +} + +Fracrect.dy(r: self Fracrect): real +{ + return r.max.y - r.min.y; +} + real2fix(x: real): FIX { return big (x * real SCALE); diff --git a/include/version.h b/include/version.h index b50a775e..ee827d4a 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20110408)" +#define VERSION "Fourth Edition (20110419)" diff --git a/libinterp/tk.c b/libinterp/tk.c index 2556a224..b3206b80 100644 --- a/libinterp/tk.c +++ b/libinterp/tk.c @@ -198,19 +198,18 @@ Tk_rect(void *fp) Tk *tk; TkTop *t; Rectangle r; - TkGeom *g; Point o; - int bd, flags; + int bd, flags, w, h; t = (TkTop*)f->t; if(t == H || D2H(t)->t != fakeTkTop){ - *(Rectangle *)f->ret = ZR; + *(Rectangle*)f->ret = ZR; return; } lockctxt(t->ctxt); tk = tklook(t, string2c(f->name), 0); if(tk == nil){ - *(Rectangle *)f->ret = ZR; + *(Rectangle*)f->ret = ZR; unlockctxt(t->ctxt); return; } @@ -218,20 +217,32 @@ Tk_rect(void *fp) flags = f->flags; if(flags & Tk_Local) o = subpt(o, tkposn(tk->env->top->root)); + if(flags & Tk_Required){ + h = tk->req.height; + w = tk->req.width; + }else{ + h = tk->act.height; + w = tk->act.width; + } + unlockctxt(t->ctxt); + if(w < 0) + w = 0; + if(h < 0) + h = 0; bd = tk->borderwidth; - g = (flags & Tk_Required) ? &tk->req : &tk->act; + if(bd < 0) + bd = 0; if(flags & Tk_Border){ r.min = o; - r.max.x = r.min.x + g->width + bd + bd; - r.max.y = r.min.y + g->height + bd + bd; - } else { + r.max.x = r.min.x + w + bd + bd; + r.max.y = r.min.y + h + bd + bd; + }else{ r.min.x = o.x + bd; r.min.y = o.y + bd; - r.max.x = r.min.x + g->width; - r.max.y = r.min.y + g->height; + r.max.x = r.min.x + w; + r.max.y = r.min.y + h; } - *(Rectangle *)f->ret = r; - unlockctxt(t->ctxt); + *(Rectangle*)f->ret = r; } int @@ -580,7 +591,6 @@ Tk_namechan(void *a) h = D2H(v->value); h->ref++; Setmark(h); - // poolimmutable((void *)h); retstr("", f->ret); } @@ -1,6 +1,6 @@ .TH TK 2 .SH NAME -Tk: toplevel, namechan, cmd, pointer, keyboard, imageget, imageput, quote \- graphics toolkit +Tk: toplevel, namechan, cmd, pointer, keyboard, imageget, imageput, quote, rect \- graphics toolkit .SH SYNOPSIS .EX include "draw.m"; |
