Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/eXene/graph-util/rounded-rect.sml
ViewVC logotype

Annotation of /sml/trunk/src/eXene/graph-util/rounded-rect.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 (* rounded-rect.sml
2 :     *
3 :     * COPYRIGHT (c) 1992 by AT&T Bell Laboratories
4 :     *
5 :     * Copyright 1988 by the Massachusetts Institute of Technology
6 :     *
7 :     * Routines to draw/fill rectangles with rounded corners. The implementation
8 :     * is lifted from the MIT X11 distribution.
9 :     *)
10 :    
11 :     structure RoundedRect : ROUNDED_RECT =
12 :     struct
13 :     structure G = Geometry
14 :    
15 :     open Geometry
16 :    
17 :     fun drawRoundedRect drawable pen {rect, c_wid, c_ht} = let
18 :     val RECT{x, y, wid=w, ht=h} = rect
19 :     val w2 = c_wid+c_wid
20 :     val h2 = c_ht+c_ht
21 :     val (ew, ew2) = if (w2 > w) then (0, 0) else (c_wid, w2)
22 :     val (eh, eh2) = if (h2 > h) then (0, 0) else (c_ht, h2)
23 :     in
24 :     Drawing.drawArcs drawable pen [
25 :     ARC{x= x, y= y, wid= ew2, ht= eh2, angle1= 180*64, angle2= ~90*64},
26 :     ARC{x= x+ew, y= y, wid= w - ew2, ht= 0, angle1= 180*64, angle2= ~180*64},
27 :     ARC{x= x+w - ew2, y= y, wid= ew2, ht= eh2, angle1= 90*64, angle2= ~90*64},
28 :     ARC{x= x+w, y= y+eh, wid= 0, ht= h - eh2, angle1= 90*64, angle2= ~180*64},
29 :     ARC{x= x+w - ew2, y= y+h - eh2, wid= ew2, ht= eh2, angle1= 0, angle2= ~90*64},
30 :     ARC{x= x+ew, y= y+h, wid= w - ew2, ht= 0, angle1= 0, angle2= ~180*64},
31 :     ARC{x= x, y= y+h - eh2, wid= ew2, ht= eh2, angle1= 270*64, angle2= ~90*64},
32 :     ARC{x= x, y= y+eh, wid= 0, ht= h - eh2, angle1= 270*64, angle2= ~180*64}
33 :     ]
34 :     end
35 :    
36 :     fun fillRoundedRect drawable pen {rect, c_wid, c_ht} = let
37 :     val pen = Drawing.updatePen (pen, [Drawing.PV_ArcMode_PieSlice])
38 :     val RECT{x, y, wid=w, ht=h} = rect
39 :     val w2 = c_wid+c_wid
40 :     val h2 = c_ht+c_ht
41 :     val (ew, ew2) = if (w2 > w) then (0, 0) else (c_wid, w2)
42 :     val (eh, eh2) = if (h2 > h) then (0, 0) else (c_ht, h2)
43 :     in
44 :     Drawing.fillArcs drawable pen [
45 :     ARC{x= x, y= y, wid= ew2, ht= eh2, angle1= 180*64, angle2= ~90*64},
46 :     ARC{x= x+w - ew2, y= y, wid= ew2, ht= eh2, angle1= 90*64, angle2= ~90*64},
47 :     ARC{x= x+w - ew2, y= y+h - eh2, wid= ew2, ht= eh2, angle1= 0, angle2= ~90*64},
48 :     ARC{x= x, y= y+h - eh2, wid= ew2, ht= eh2, angle1= 270*64, angle2= ~90*64}
49 :     ];
50 :     Drawing.fillRects drawable pen [
51 :     RECT{x= x + ew, y= y, wid= w - ew*2, ht= h},
52 :     RECT{x= x, y= y + eh, wid= ew, ht= h - eh2},
53 :     RECT{x= x + w - ew, y= y + eh, wid= ew, ht= h - eh2}
54 :     ]
55 :     end
56 :    
57 :     end (* RoundedRect *)
58 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0