home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gpacks / vib / vibline.icn < prev    next >
Text File  |  2000-07-29  |  6KB  |  198 lines

  1. ############################################################################
  2. #
  3. #  vibline.icn -- procedures for defining a line object
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vibdefn.icn"
  12.  
  13. ##########################################################################
  14. # line_obj:
  15. #    proc    : name of user callback procedure
  16. #    v       : vidget used for drawing line
  17. #    id      : unique means of identifying instance
  18. #    x,y,w,h : bounding box
  19. #    x1,y1   : one endpoint
  20. #    y1,y2   : other endpoint
  21. #    focus   : should focus lines be drawn around this object?
  22. ##########################################################################
  23. record line_obj(v, proc, id, x, y, w, h, x1, y1, x2, y2, focus)
  24.  
  25. ##########################################################################
  26. # create_line() creates a line instance and draws the line if
  27. #               it is a first class object.
  28. ##########################################################################
  29. procedure create_line(x1, y1, x2, y2)
  30.    local r, id
  31.  
  32.    id := next_id("line")
  33.    r := line_obj(, "", "line" || id, , , , , x1, y1, x2, y2, 0)
  34.    r.v := Vline(APPWIN, x1, y1, x2, y2)
  35.    VInsert(ROOT, r.v, x1, y1)
  36.    VRemove(ROOT, r.v, 1)
  37.    update_line_bb(r)
  38.    return r
  39. end
  40.  
  41. ##########################################################################
  42. # update_line_bb() updates various attributes of the line that
  43. #                  change when the button is resized, etc.
  44. ##########################################################################
  45. procedure update_line_bb(object)
  46.    if object.x1 < 0 then {
  47.       object.x2 -:= object.x1
  48.       object.x1 := 0
  49.       }
  50.    if object.x2 < 0 then {
  51.       object.x1 -:= object.x2
  52.       object.x2 := 0
  53.       }
  54.    if object.y1 < CANVASY then {
  55.       object.y2 -:= (object.y1 - CANVASY)
  56.       object.y1 := CANVASY
  57.       }
  58.    if object.y2 < CANVASY then {
  59.       object.y1 -:= (object.y2 - CANVASY)
  60.       object.y2 := CANVASY
  61.       }
  62.    object.x := minimum(object.x1, object.x2) - 2
  63.    object.y := minimum(object.y1, object.y2) - 2
  64.    object.w := abs(object.x1 - object.x2) + 4
  65.    object.h := abs(object.y1 - object.y2) + 4
  66. end
  67.  
  68. ##########################################################################
  69. # draw_line() draws the given line object.
  70. ##########################################################################
  71. procedure draw_line(r)
  72.    r.v.ax1 := r.x1
  73.    r.v.ay1 := r.y1
  74.    r.v.ax2 := r.x2
  75.    r.v.ay2 := r.y2
  76.    VDraw(r.v)
  77.    return r
  78. end
  79.  
  80. ##########################################################################
  81. # outline_line() draws an outline for the given line.  Outlines are
  82. #                used when the object is moved or resized.
  83. ##########################################################################
  84. procedure outline_line(r)
  85.    DrawLine(XORWIN, r.x1, r.y1, r.x2, r.y2)
  86. end
  87.  
  88. ##########################################################################
  89. # drag_line() is a special procedure for dragging line objects.
  90. ##########################################################################
  91. procedure drag_line(r)
  92.    local xoff, yoff, x1, y1, dx, dy
  93.  
  94.    x1 := r.x1
  95.    y1 := r.y1
  96.    dx := r.x2 - x1
  97.    dy := r.y2 - y1
  98.    xoff := x1 - &x
  99.    yoff := y1 - &y
  100.    DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
  101.    until Event(XORWIN) === (&lrelease | &mrelease | &rrelease) do {
  102.       DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
  103.       x1 := &x + xoff
  104.       y1 := &y + yoff
  105.       DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
  106.       }
  107.    DrawLine(XORWIN, x1, y1, x1 + dx, y1 + dy)
  108.    &x := r.x + x1 - r.x1
  109.    &y := r.y + y1 - r.y1
  110. end
  111.  
  112. ##########################################################################
  113. # load_line() restores a line object from session code.
  114. ##########################################################################
  115. procedure load_line(r, o)
  116.    r.x1 := o.x
  117.    r.y1 := o.y + CANVASY
  118.    r.x2 := o.w
  119.    r.y2 := o.h + CANVASY
  120.    r.v := Vline(APPWIN, r.x1, r.y1, r.x2, r.y2)
  121.    VInsert(ROOT, r.v, r.x1, r.y1)
  122.    VRemove(ROOT, r.v, 1)
  123. end
  124.  
  125. ##########################################################################
  126. # save_line() augments the record for saving a line object.
  127. ##########################################################################
  128. procedure save_line(r, o)
  129.    r.typ := "Line"
  130.    r.x := o.x1
  131.    r.y := o.y1 - CANVASY
  132.    r.w := o.x2
  133.    r.h := o.y2 - CANVASY
  134.    r.proc := &null
  135.    return
  136. end
  137.  
  138. ##########################################################################
  139. # display_line_atts() displays the attribute sheet with the current
  140. #                     attributes for the given line instance.
  141. ##########################################################################
  142. procedure display_line_atts(object)
  143.    local t, dx, dy
  144.  
  145.    t := table()
  146.    t["a_id"]        := object.id
  147.    t["c_x1"]        := object.x1
  148.    t["d_y1"]        := object.y1 - CANVASY
  149.    t["e_x2"]        := object.x2
  150.    t["f_y2"]        := object.y2 - CANVASY
  151.  
  152.    repeat {
  153.       if line_dialog(t) == "Cancel" then
  154.          fail
  155.  
  156.       if illegal(t["a_id"], "ID", "s") |
  157.          illegal(t["c_x1"], "X1", "i") |
  158.          illegal(t["d_y1"], "Y1", "i") |
  159.          illegal(t["e_x2"], "X2", "i") |
  160.          illegal(t["f_y2"], "Y2", "i")
  161.       then
  162.          next
  163.    
  164.       unfocus_object(object)
  165.       erase_object(object)
  166.  
  167.       object.id := t["a_id"]
  168.       object.x1 := t["c_x1"]
  169.       object.y1 := t["d_y1"] + CANVASY
  170.       object.x2 := t["e_x2"]
  171.       object.y2 := t["f_y2"] + CANVASY
  172.  
  173.       # can't just do a move_object() here: doesn't work for line changes
  174.       update_line_bb(object)
  175.       draw_canvas()
  176.       focus_object(object)
  177.       DIRTY := 1
  178.       break
  179.    }
  180. end
  181.  
  182. #===<<vib:begin>>===    modify using vib; do not remove this marker line
  183. procedure line_dialog(win, deftbl)
  184. static dstate
  185. initial dstate := dsetup(win,
  186.    ["line_dialog:Sizer::1:0,0,350,138:",],
  187.    ["_cancel:Button:regular::192,87,50,30:Cancel",],
  188.    ["_okay:Button:regular:-1:127,86,50,30:Okay",],
  189.    ["a_id:Text::40:13,14,318,19:ID: \\=",],
  190.    ["c_x1:Text::3:13,42,59,19:x1: \\=",],
  191.    ["d_y1:Text::3:81,42,59,19:y1: \\=",],
  192.    ["e_x2:Text::3:204,42,59,19:x2: \\=",],
  193.    ["f_y2:Text::3:272,42,59,19:y2: \\=",],
  194.    )
  195. return dpopup(win, deftbl, dstate)
  196. end
  197. #===<<vib:end>>===    end of section maintained by vib
  198.