[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scaling arrow heads
From: |
Christof Ecker |
Subject: |
scaling arrow heads |
Date: |
Mon, 21 Oct 2002 11:32:06 +0200 (CEST) |
The following patch changes the line dialog to allow scaling of arrow
heads.
As sketch is representing arrow heads as paths, it is not possible, to
introduce a separete scaling factor without changing the whole concept
(e.g. the fileformat).
My solution is to introduce a "standart size" for arrow heads, which
corresponds to the arrow drawn in a certain thickness and scaling. The
scaling factor is then defined as the ratio of the height of the arrow
head and its standart height.
Cheers,
Christof
diff -r sketch-0.6.14/Sketch/UI/linedlg.py
sketch-0.6.14_hack/Sketch/UI/linedlg.py
30,34c30,31
< StandardDashes, StandardArrows, StandardColors
<
<
< from Tkinter import Frame, Label, IntVar, LEFT, X, E, W, GROOVE
< from tkext import ColorButton, UpdatedCheckbutton, MyOptionMenu2
---
> StandardDashes, StandardArrows, StandardColors, Scale, Point, \
> Arrow
35a33,37
> from Tkinter import Frame, Label, IntVar, LEFT, RIGHT, TOP, X, Y, E, \
> W, GROOVE, DoubleVar
> from tkext import ColorButton, UpdatedCheckbutton, MyOptionMenu2, \
> MyEntry
> from miniscroll import MiniScroller
41a44,64
> class RoundedFloat:
> def __init__(self, var, precision=2):
> self.var = var
> self.precision = precision
> def get(self):
> return self.var.get()
> def set(self, value):
> self.var.set(round(value, self.precision))
>
> def create_scale_entry(top, master, command, args = (), scroll_pad = 2):
> var = DoubleVar(top)
> var.set(100.0)
> rounded_var = RoundedFloat(var, precision=2)
> entry = MyEntry(master, textvariable = var, justify = RIGHT,
> width = 6, command = command, args = args)
> scroll = MiniScroller(master, variable = var, min = 0, max = None,
> step = 10)
> entry.pack(side = LEFT, expand = 1, fill = X, anchor = E)
> scroll.pack(side = LEFT, fill = Y, pady = scroll_pad)
> return rounded_var
>
83c106,107
< _arrow_height = 25
---
> _arrow_height = 20
> _scalefactor = 20.
121a146,162
> def set_scalefactor(arrow, scale):
> ascale = get_scalefactor(arrow)
> if ascale == 0:
> return arrow
> path = arrow.path.Duplicate()
> path.Transform(Scale(scale/ascale))
> arrow = Arrow(path)
> return arrow
>
> def get_scalefactor(arrow):
> if arrow is None:
> return 0
> p = Point(1,0)
> x1, y1, x2, y2 = arrow.BoundingRect(p, p, _thickness)
> return (y2-y1)/_scalefactor *100
>
>
134c175
< button_frame.grid(row = 5, columnspan = 2, sticky = 'ew')
---
> button_frame.grid(row = 6, columnspan = 2, sticky = 'ew')
171c212
< self.opt_arrow1 = MyOptionMenu2(top, arrow1, command = self.set_arrow,
---
> self.opt_arrow1 = MyOptionMenu2(top, arrow1, command =
> self.set_arrowshape,
175c216
< self.opt_arrow2 = MyOptionMenu2(top, arrow2, command = self.set_arrow,
---
> self.opt_arrow2 = MyOptionMenu2(top, arrow2, command =
> self.set_arrowshape,
181a223,238
> scale_frame = Frame(top, relief = GROOVE, bd = 2)
> scale_frame.grid(row = 4, columnspan = 2, sticky = 'ew')
>
> label = Label(scale_frame, text = "Arrow Scale")
> label.pack(side = TOP, expand = 1, fill=X, anchor = W)
>
> self.var_scale1 = create_scale_entry(top, scale_frame,
> self.set_arrowscale,
> args = 1,
> scroll_pad = 0)
>
> self.var_scale2 = create_scale_entry(top, scale_frame,
> self.set_arrowscale,
> args = 2,
> scroll_pad = 0)
>
188c245
< self.opt_join.grid(row = 4, column = 0, sticky = 'ew')
---
> self.opt_join.grid(row = 5, column = 0, sticky = 'ew')
197c254
< self.opt_cap.grid(row = 4, column = 1, sticky = 'ew')
---
> self.opt_cap.grid(row = 5, column = 1, sticky = 'ew')
224c281,291
<
---
>
> def _get_arrow(self, which):
> if which == 1:
> scale = self.var_scale1.get()
> arrow = self.opt_arrow1.GetValue()
> else:
> scale = self.var_scale2.get()
> arrow = self.opt_arrow2.GetValue()
>
> return set_scalefactor(arrow, scale)
>
234,235c301,302
< kw["line_arrow1"] = self.opt_arrow1.GetValue()
< kw["line_arrow2"] = self.opt_arrow2.GetValue()
---
> kw["line_arrow1"] = self._get_arrow(1)
> kw["line_arrow2"] = self._get_arrow(2)
266c333
< def set_arrow(self, arrow, which):
---
> def set_arrow(self, arrow=None, scale=None, which=1):
267a335,339
> if scale is None:
> scale = self.var_scale1.get()
> if arrow is None:
> arrow = self.opt_arrow1.GetValue()
> arrow = set_scalefactor(arrow, scale)
270a343,347
> if scale is None:
> scale = self.var_scale2.get()
> if arrow is None:
> arrow = self.opt_arrow2.GetValue()
> arrow = set_scalefactor(arrow, scale)
273c350,356
<
---
>
> def set_arrowshape(self, arrow, which):
> self.set_arrow(arrow = arrow, which = which)
>
> def set_arrowscale(self, scale, which):
> self.set_arrow(scale = scale, which = which)
>
275a359,361
> scale = get_scalefactor(arrow)
> arrow = set_scalefactor(arrow, 100.)
>
279a366,367
> if arrow is not None:
> self.var_scale1.set(scale)
281a370,372
> scale = get_scalefactor(arrow)
> arrow = set_scalefactor(arrow, 100.)
>
286c377,379
<
---
> if arrow is not None:
> self.var_scale2.set(scale)
>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- scaling arrow heads,
Christof Ecker <=