; Imagemap - imagemaps ; ; Purpose: creation of client-side image maps ; Category: web graphics ; Use: imagemap,filename[,outfilename] ; Inputs: ; filename - *gif* filename to open and create the map for ; outfilename - file to write the imagemap text to [defaults to imagemap.txt] ; Use: ; An html client-side imagemap looks like: ; ; ; ; ; ; ; This widget produces the text that goes inside the "map" element. ; It should be run (this is obvious) on the GIF that will be used as the image source ; ; Author: WMConnolley wmc@bas.ac.uk www.nbs.ac.uk/public/icd/wmc/ ; Guarantee: none ; --- Event handler: does all the work --- pro imagemap_event,event ; All needed data is stored in the top uvalue widget_control,event.top,get_uvalue=goat nx=goat.nx ; ; Select action based on event id ; case event.id of ; ; writ: write out the imagemap text ; goat.writ: begin widget_control,get_value=texto,goat.text openw,lun,goat.outfilename,/get printf,lun,texto free_lun,lun end ; ; relo: reload the image ; goat.relo: begin goat.img=goat.img0 tv,goat.img end ; ; stop - hmm, wonder what this does? ; goat.stop: begin widget_control,/destroy,event.top end ; ; draw - mouse has moved in the draw window. What we do ; depends on what shape is selected ; goat.draw: begin case goat.mode of ; ; Polygon (click on points) ; 'poly': begin ; press 1 (LH button) - add new node to polygon if (event.press eq 1) then begin goat.x(nx)=event.x & goat.y(nx)=event.y if (goat.nx ne 0) then plots,goat.x(nx-1:nx),goat.y(nx-1:nx),/dev plots,psym=3,symsize=2,[event.x],[event.y],/dev goat.nx=goat.nx+1 ; press 4 (RH button) - end polygon; write nodes as text to the text screen endif else if (event.press eq 4) then begin widget_control,goat.url,get_value=url text='' widget_control,set_value=text,goat.text,/append plots,goat.x([0,nx-1]),goat.y([0,nx-1]),/dev goat.nx=0 endif end ; ; Circle (center point and then drag out) ; 'circle': begin ; Press 1 - start new circle if (event.press eq 1) then begin plots,psym=3,symsize=2,[event.x],[event.y],/dev goat.x(0)=event.x & goat.y(0)=event.y a=tvrd() & goat.img=a goat.nx=1 endif else if (event.release eq 1) then begin ; Release 1 - end circle and write text goat.nx=0 r=sqrt((goat.x(0)-event.x)^2+(goat.y(0)-event.y)^2) plots,goat.x(0)+sind(indgen(361))*r,goat.y(0)+cosd(indgen(361))*r,/dev widget_control,goat.url,get_value=url text='' widget_control,set_value=text,goat.text,/append endif else if (nx gt 0 and event.type eq 2) then begin ; Otherwise, its a drag - rewrite image to remove previous drawn circle (cf rubberband) tv,goat.img r=sqrt((goat.x(0)-event.x)^2+(goat.y(0)-event.y)^2) plots,goat.x(0)+sind(indgen(361))*r,goat.y(0)+cosd(indgen(361))*r,/dev endif end ; ; Square (oh, OK then, rectangle) ; 'square': begin ; Press 1 - first corner if (event.press eq 1) then begin plots,psym=3,symsize=2,[event.x],[event.y],/dev goat.x(0)=event.x & goat.y(0)=event.y a=tvrd() & goat.img=a goat.nx=1 endif else if (event.release eq 1) then begin ; Release 1 - end rectangle goat.nx=0 plots,([goat.x(0),event.x])([0,1,1,0,0]),([goat.y(0),event.y])([0,0,1,1,0]),/dev widget_control,goat.url,get_value=url text='' widget_control,set_value=text,goat.text,/append endif else if (nx gt 0 and event.type eq 2) then begin ; Otherwise drag, as for circle tv,goat.img plots,([goat.x(0),event.x])([0,1,1,0,0]),([goat.y(0),event.y])([0,0,1,1,0]),/dev endif end else: begin print,'Sorry: unrecognised mode: '+goat.mode end endcase widget_control,event.top,set_uvalue=goat end ; ; End of events in draw window ; ; Press on "poly" button ; goat.poly: begin goat.mode='poly' goat.nx=0 widget_control,event.top,set_uvalue=goat end ; ; Press on "square" button ; goat.squa: begin goat.mode='square' goat.nx=0 widget_control,event.top,set_uvalue=goat end ; ; Press on "circle" button ; goat.circ: begin goat.mode='circle' goat.nx=0 widget_control,event.top,set_uvalue=goat end else: begin ; print,'Sorry: unrecognised event id: ',event.id end endcase end ; ; --- Main pro: reads in image, creates widget, calls xmanager ; pro imagemap,filename,outfilename ; Input verify if (n_elements(outfilename) eq 0) then begin outfilename='imagemap.txt' message,'Note: no imagemap filename supplied; using default: '+outfilename,/cont endif if (n_elements(filename) eq 0) then message,'Please supply input GIF file' ; Read in the GIF into "a" read_gif,filename,a,r,g,b s=size(a) xs=s(1) ys=s(2) ; Make the widget base=widget_base(/col) ; Draw widget at the top draw=widget_draw(base,xsize=xs,ysize=ys,/button_events,/motion_events) ; Row of buttons bbase=widget_base(base,/align_bottom,/row) stop=widget_button(bbase,value='End') relo=widget_button(bbase,value='Reload') writ=widget_button(bbase,value='Write imagemap') junk=widget_label(bbase,value='Select:') poly=widget_button(bbase,value='Polygon') squa=widget_button(bbase,value='Square') circ=widget_button(bbase,value='Circle') ; Url (for the hrefs) ubase=widget_base(base,/align_bottom,/row) junk=widget_label(ubase,value='URL for hrefs') url =widget_text(ubase,value='http://',xsize=40,ysize=1,/editable) ; Text that we generate text=widget_text(base,/editable,ysize=10,/scroll) ; Realise the widget widget_control,base,/real xmanager,'imagemap',/no_bl,base ; Stuff everything we need to remember into the uvalue of the base widget_control,base,set_uvalue={stop:stop,draw:draw,poly:poly,squa:squa,mode:'poly',x:fltarr(1000),y:fltarr(1000),nx:0,img:a,img0:a,relo:relo,ys:ys,text:text,writ:writ,circ:circ,url:url,outfilename:outfilename} ; Put the image into the draw widget widget_control,draw,get_value=index wset,index tvlct,r,g,b tv,a end