File: curve_rectangle.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (53 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#/* a custom shape, that could be wrapped in a function */
x0         = 0.1   #/*< parameters like cairo_rectangle */
y0         = 0.1
rect_width  = 0.8
rect_height = 0.8
radius = 0.4   #/*< and an approximate curvature radius */

snippet_normalize (cr, width, height)

x1=x0+rect_width
y1=y0+rect_height
#if (!rect_width || !rect_height)
#    return
if rect_width/2<radius:
    if rect_height/2<radius:
        cr.move_to  (x0, (y0 + y1)/2)
        cr.curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0)
        cr.curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2)
        cr.curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1)
        cr.curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2)
    else:
        cr.move_to  (x0, y0 + radius)
        cr.curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0)
        cr.curve_to (x1, y0, x1, y0, x1, y0 + radius)
        cr.line_to (x1 , y1 - radius)
        cr.curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1)
        cr.curve_to (x0, y1, x0, y1, x0, y1- radius)

else:
    if rect_height/2<radius:
        cr.move_to  (x0, (y0 + y1)/2)
        cr.curve_to (x0 , y0, x0 , y0, x0 + radius, y0)
        cr.line_to (x1 - radius, y0)
        cr.curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2)
        cr.curve_to (x1, y1, x1, y1, x1 - radius, y1)
        cr.line_to (x0 + radius, y1)
        cr.curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2)
    else:
        cr.move_to  (x0, y0 + radius)
        cr.curve_to (x0 , y0, x0 , y0, x0 + radius, y0)
        cr.line_to (x1 - radius, y0)
        cr.curve_to (x1, y0, x1, y0, x1, y0 + radius)
        cr.line_to (x1 , y1 - radius)
        cr.curve_to (x1, y1, x1, y1, x1 - radius, y1)
        cr.line_to (x0 + radius, y1)
        cr.curve_to (x0, y1, x0, y1, x0, y1- radius)

cr.close_path ()

cr.set_source_rgb (0.5,0.5,1)
cr.fill_preserve ()
cr.set_source_rgba (0.5,0,0,0.5)
cr.stroke ()