75 lines
2.3 KiB
Text
75 lines
2.3 KiB
Text
--
|
|
-- demo\rosetta\Plot_coordinate_pairs.exw
|
|
--
|
|
include pGUI.e
|
|
|
|
Ihandle dlg, canvas
|
|
cdCanvas cddbuffer, cdcanvas
|
|
|
|
constant x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
|
|
y = {2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}
|
|
|
|
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
|
|
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
|
|
atom cx,cy,nx,ny
|
|
atom {w,h} = {(width-60)/9,(height-60)/180}
|
|
cdCanvasActivate(cddbuffer)
|
|
cx = 30+x[1]*w
|
|
cy = 30+y[1]*h
|
|
for i=2 to length(x) do
|
|
cdCanvasSetForeground(cddbuffer, CD_BLACK)
|
|
nx = 30+(i-1)*w
|
|
ny = 30+(i-1)*20*h
|
|
{} = cdCanvasTextAlignment(cddbuffer, CD_NORTH)
|
|
cdCanvasText(cddbuffer, nx, 25, sprintf("%d",(i-1)))
|
|
{} = cdCanvasTextAlignment(cddbuffer, CD_EAST)
|
|
cdCanvasText(cddbuffer, 25, ny, sprintf("%3d",(i-1)*20))
|
|
cdCanvasSetForeground(cddbuffer, CD_GRAY)
|
|
cdCanvasLine(cddbuffer,30,ny,width-30,ny)
|
|
cdCanvasLine(cddbuffer,nx,30,nx,height-30)
|
|
cdCanvasSetForeground(cddbuffer, CD_BLUE)
|
|
nx = 30+floor(x[i]*w)
|
|
ny = 30+floor(y[i]*h)
|
|
cdCanvasLine(cddbuffer,cx,cy,nx,ny)
|
|
cx = nx
|
|
cy = ny
|
|
end for
|
|
cdCanvasSetForeground(cddbuffer, CD_BLACK)
|
|
cdCanvasLine(cddbuffer,30,30,width-30,30)
|
|
cdCanvasLine(cddbuffer,30,30,30,height-30)
|
|
cdCanvasFlush(cddbuffer)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function map_cb(Ihandle ih)
|
|
cdcanvas = cdCreateCanvas(CD_IUP, ih)
|
|
cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
|
|
cdCanvasSetBackground(cddbuffer, CD_WHITE)
|
|
return IUP_DEFAULT
|
|
end function
|
|
|
|
function esc_close(Ihandle /*ih*/, atom c)
|
|
if c=K_ESC then return IUP_CLOSE end if
|
|
return IUP_CONTINUE
|
|
end function
|
|
|
|
procedure main()
|
|
IupOpen()
|
|
|
|
canvas = IupCanvas(NULL)
|
|
IupSetAttribute(canvas, "RASTERSIZE", "340x340") -- initial size
|
|
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
|
|
|
|
dlg = IupDialog(canvas)
|
|
IupSetAttribute(dlg, "TITLE", "Plot coordinate pairs")
|
|
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
|
|
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
|
|
|
|
IupMap(dlg)
|
|
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
|
|
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
|
|
IupMainLoop()
|
|
IupClose()
|
|
end procedure
|
|
|
|
main()
|