Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Preserve spaces in filenames

From: greggirwin::mindspring::com at: 16-Feb-2006 10:42

Hi Paavo, PN> 2) How to draw a line between two movable faces. I need it to implement PN> a simple graph editing functionality. A modified example from the RT docs: PN> I know how to draw lines using Draw dialect. Should I have it all PN> Draw based then, and draw the whole thing every time a box moves? PN> (I don't actually understand how to do that). Or is there a neat PN> way, where i can somehow make a "line object" dependable of one or PN> two other objects? How to draw a subpane face, which is a line (and PN> the rest of it transparent in this case). It is easy thing for me PN> to make a line dependent of both ends if somebody tells me how to PN> draw a line as a "face" in this framework. (I am not very familiar PN> with the visual side of Rebol...) There is no "line object" that makes this easy. When I did a whiteboard app a long time ago, I added faces as the anchors for lines, so they could be grabbed and moved, and the lines themselves were just draw commands for the main "canvas" face. I've included some old code, below, that I used for it (I think; it's been a long time). You could pass faces instead or corner coordinates of course. -- Gregg ; Larry Palmiter map: apply: func [fn blk args /local result][ result: copy [] repeat el blk [append/only result fn :el args] result ] distance: func [ {Always returns a positive value.} a [pair!] b [pair!] ][ square-root add (square first (a - b)) (square second (a - b)) ] all-corners: func [ {Returns all corners of the rectangle given the upper-left and lower-right corners.} ul [pair!] "The upper-left corner of the rectangle" lr [pair!] "The bottom-right corner of the rectangle" /local result ][ result: make block! 4 repend result [ ul to-pair compose [(first ul) (second lr)] ;ur to-pair compose [(first lr) (second ul)] ;ll lr ] return result ] ; My original version ; nearest-point: func ["Returns the point nearest the specified point." ; pt[pair!] "The reference point" ; points[any-block!] "The points you want to check" ; /local result[pair!] ref-dist[decimal!]] [ ; result: first points ; ref-dist: distance pt first points ; foreach p next points [ ; if (distance pt p) < ref-dist [ ; ref-dist: distance pt p ; result: p ; ] ; ] ; return result ; ] ; Condensed version using map function nearest-point: func [ {Returns the point nearest the specified point.} pt [pair!] "The reference point" points [any-block!] "The points you want to check" ][ pick points index? minimum-of (map :distance points pt) ] ; My original version ; farthest-point: func ["Returns the point farthest from the specified point." ; pt[pair!] "The reference point" ; points[any-block!] "The points you want to check" ; /local result[pair!] ref-dist[decimal!]] [ ; result: first points ; ref-dist: distance pt first points ; foreach p next points [ ; if (distance pt p) > ref-dist [ ; ref-dist: distance pt p ; result: p ; ] ; ] ; return result ; ] ; Condensed version using map function farthest-point: func [ {Returns the point farthest from the specified point.} pt [pair!] "The reference point" points [any-block!] "The points you want to check" ][ pick points index? maximum-of (map :distance points pt) ] nearest-corner: func [ "Returns the corner of the retangle nearest the specified point." pt [pair!] "The reference point" ul [pair!] "The upper-left corner of the rectangle" lr [pair!] "The bottom-right corner of the rectangle" ][ nearest-point pt all-corners ul lr ]