Guest User

Untitled

a guest
Jan 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Red [
  2. title: "Iterated faces in Red"
  3. file: %iterated-faces.red
  4. author: "Marco Antoniazzi"
  5. license: "Do with this code whatever you want, giving credit to me is NOT required"
  6. email: [luce80 AT alice DOT it]
  7. date: 13-01-2018
  8. version: 0.0.6
  9. Purpose: "Create iterated faces as those found in Rebol View"
  10. Needs: View
  11. ]
  12.  
  13. iter-func: func [
  14. iterated-face [object!]
  15. index [integer! pair!]
  16. ][
  17. ; RETURNS: face, index number, or none
  18. ; if index is integer! return face
  19. ; if index is pair! return iteration number
  20. ?? index
  21. either integer? index [
  22. ; Draw needs to know offset and text:
  23. iterated-face/offset/y: index - 1 * (iterated-face/size/y)
  24. if iterated-face/offset/y > iterated-face/parent/size/y [return none]
  25. iterated-face/text: form iterated-face/offset
  26. iterated-face/color: either iterated-face/extra/selected = index [blue] [red]
  27. return iterated-face
  28. ][
  29. ; Events need to know iteration number:
  30. return to-integer index/y / (iterated-face/size/y) + 1
  31. ]
  32. none
  33. ]
  34.  
  35. call_and_draw_iters: func[
  36. ;itering-func [function!] ; using functions is currently problematic
  37. itering-face [object!]
  38. image [image!]
  39. /local
  40. draw-blk index current-face
  41. ][
  42. draw-blk: [image 0 0x0 10x10]
  43.  
  44. index: 1
  45. while [current-face: iter-func itering-face index ] [
  46. index: index + 1
  47.  
  48. draw-blk/2: to-image current-face
  49. draw-blk/3: current-face/offset
  50. draw-blk/4: current-face/offset + current-face/size
  51. draw image draw-blk
  52. ]
  53. image
  54. ]
  55.  
  56. view compose [
  57. below space 4x4
  58. text "Select a line by clicking on it"
  59. panel [
  60. below
  61. canvas: image 300x190 green all-over
  62. on-over [
  63. probe iter-func line-text event/offset
  64. ]
  65. on-down [
  66. line-text/extra/selected: iter-func line-text event/offset
  67. call_and_draw_iters line-text face/image
  68. ]
  69. line-text: text "abcd" red yellow hidden extra object [selected: false]
  70. ] on-created [
  71. call_and_draw_iters line-text canvas/image
  72. ]
  73. ]
Add Comment
Please, Sign In to add comment