pro Graff_write, pdefs, event, track_flag ;+ ; GRAFF_WRITE ; Process a draw event in text mode ; ; Usage: ; graff_write, pdefs, event ; ; Argument: ; pdefs struct in/out The plot definition structure. ; event struct input The draw event that triggered this ; track_flag byte input A flag to say if it's a tracking event. ; ; History: ; Carved from graffer: 17/8/95; SJT ; Add tracking event handling: 5/12/95; SJT ;- if (track_flag) then begin graff_msg, pdefs.ids.hlptxt, 'Left ' + $ '= add string, Middle = edit string, Right = delete string' return endif xy = convert_coord(event.x, event.y, /device, /to_data) xyn = convert_coord(event.x, event.y, /device, /to_norm) case event.type of 1: begin ; Release event handle_value, pdefs.text, text, /no_copy case event.release of 1: begin ; Left: add a line if (pdefs.Ntext eq 0) then begin text.x = xy(0) text.y = xy(1) text.norm = 0b endif else begin text = [text, {graff_text, $ Text: '', $ Colour: 1, $ Size: 1.0, $ Orient: 0., $ Align: 0., $ Font: 3, $ Thick: 1, $ X: xy(0), $ Y: xy(1), $ Norm: 0b}] endelse handle_value, pdefs.text, text, /no_copy, /set graff_text, pdefs end 2:if (pdefs.ntext ge 1) then begin ; Centre - edit a text string ddata = convert_coord(text.x, text.y, /data, $ /to_device) locs = where(text.norm, nnorm) if (nnorm ne 0) then ddata(*, locs) = $ convert_coord(text(locs).x, text(locs).y, /norm, $ /to_device) handle_value, pdefs.text, text, /no_copy, /set dist = sqrt((ddata(0, *)-event.x)^2 + $ (ddata(1, *)-event.y)^2) md = min(dist, imin) if (md lt 5) then graff_text, pdefs, edit = imin $ else graff_msg, pdefs.ids.message, $ "No text anchor point within 5 pixels" endif else handle_value, pdefs.text, text, /no_copy, /set 4: if (pdefs.ntext ne 0) then begin ; Right: delete. if (pdefs.ntext ge 1) then begin ddata = convert_coord(text.x, text.y, /data, $ /to_device) locs = where(text.norm, nnorm) if (nnorm ne 0) then ddata(*, locs) = $ convert_coord(text(locs).x, text(locs).y, /norm, $ /to_device) dist = sqrt((ddata(0, *)-event.x)^2 + $ (ddata(1, *)-event.y)^2) md = min(dist, imin) endif else md = 100. if (md lt 5) then begin if (pdefs.ntext eq 1) then begin handle_value, pdefs.text, {graff_text, $ Text: '', $ Colour: 1, $ Size: 1.0, $ Orient: 0., $ Align: 0., $ Font: 3, $ Thick: 1, $ X: 0., $ Y: 0., $ Norm: 0b}, /set pdefs.ntext = 0 endif else begin if (imin eq 0) then text = text(1:*) $ else if (imin eq pdefs.ntext-1) then $ text = text(0:Imin-1) $ else text = [text(0:Imin-1), text(Imin+1:*)] handle_value, pdefs.text, text, /no_copy, /set pdefs.ntext = pdefs.ntext-1 endelse endif else begin graff_msg, pdefs.ids.message, $ "No text anchor point within 5 pixels" handle_value, pdefs.text, text, /no_copy, /set endelse endif else handle_value, pdefs.text, text, /no_copy, /set endcase end 2: begin ; Motion events idraw_flag = 0 device, set_graph = 6 if (pdefs.transient.opflag) then begin if (pdefs.xtype) then plots, 10.^!X.crange, $ replicate(pdefs.transient.opos(1), 2), linesty = 2 $ else plots, !X.crange, $ replicate(pdefs.transient.opos(1), 2), linesty = 2 if (pdefs.ytype) then plots, linesty = 2, $ replicate(pdefs.transient.opos(0), 2), 10.^!Y.crange $ else plots, replicate(pdefs.transient.opos(0), 2), $ !Y.crange, linesty = 2 endif if (pdefs.xtype) then plots, 10.^!X.crange, $ replicate(xy(1), 2), linesty = 2 $ else plots, !X.crange, replicate(xy(1), 2), linesty = 2 if (pdefs.ytype) then plots, replicate(xy(0), 2), $ 10.^!Y.crange, linesty = 2 $ else plots, replicate(xy(0), 2), !Y.crange, linesty = 2 device, set_graph = 3 pdefs.transient.opos = xy(0:1) pdefs.transient.opflag = 1b widget_control, pdefs.ids.xcp, set_value = xy(0) widget_control, pdefs.ids.ycp, set_value = xy(1) end Else: ; Ignore press events and any other ; miscellanea endcase end