1. getting the canvas of iupplot and print it

hi,

it driving me nuts. i can't get the canvas or image if iupplot and print it.

my application plots just fine, but i need to print the plot. so i took from pete's samples

function item_print_action_cb(Ihandle /*item_print*/) 
--Ihandle canvas = IupGetDialogChild(item_print, "CANVAS") 
imImage image 
--string title = IupGetAttribute(IupGetDialog(item_print), "TITLE") 
string title = IupGetAttribute(dlg, "TITLE") 
cdCanvan print_canvas = cdCreateCanvas(CD_PRINTER, "%s -d", {title}) 
    if print_canvas=NULL then 
        return IUP_DEFAULT 
    end if 
 
    -- do NOT draw the background, use the paper color 
 
    -- draw the image at the center of the canvas 
    image = IupGetInt(canvas, "IMAGE") 
    if image!=NULL then 
        integer x, y, canvas_width, canvas_height, view_width, view_height 
        atom canvas_width_mm, canvas_height_mm 
--      Ihandle config = IupGetInt(canvas, "CONFIG") 
        integer margin_width = IupConfigGetVariableInt(config, "Print", "MarginWidth", 20) 
        integer margin_height = IupConfigGetVariableInt(config, "Print", "MarginHeight", 20) 
 
        {canvas_width, canvas_height, canvas_width_mm, canvas_height_mm} = cdCanvasGetSize(print_canvas) 
 
        -- convert to pixels 
        margin_width = floor((margin_width*canvas_width)/canvas_width_mm) 
        margin_height = floor((margin_height*canvas_height)/canvas_height_mm) 
 
        {view_width, view_height} = view_fit_rect(canvas_width-2*margin_width, 
                                                  canvas_height-2*margin_height, 
                                                  im_width(image), im_height(image)) 
 
        x = (canvas_width-view_width)/2 
        y = (canvas_height-view_height)/2 
 
        cdCanvasPutImImage(print_canvas, image, x, y, view_width, view_height) 
    end if 
 
    cdKillCanvas(print_canvas) 
    return IUP_DEFAULT 
end function 

and tried to use it on iupplot. if tried

IupPlotPaintTo(plot, print_canvas)

or

image = IupGetInt(plot, "CANVAS")

but nothing works. is there anyone who knows how to do that? yes, i searched the iup c samples.

thanks

richard

new topic     » topic index » view message » categorize

2. Re: getting the canvas of iupplot and print it

begin said...

I can't get the canvas or image if iupplot and print it.

my application plots just fine, but i need to print the plot. so i took from pete's samples

I haven't done much of this, but you should be on the right track with IupPlotPaintTo().

You don't have an imImage with IupPlot, so let's rip all that out. Try this (untested):

function item_print_action_cb(Ihandle /*item_print*/) 
cdCanvan print_canvas = cdCreateCanvas(CD_PRINTER, "myplot -d") 
    if print_canvas!=NULL then 
        IupPlotPaintTo(plot, print_canvas) 
        IupSetAttribute(plot,"REDRAW",NULL) 
        cdKillCanvas(print_canvas) 
    end if 
    return IUP_DEFAULT 
end function 

If it does not work, and I find time tomorrow, I'll have a bash at adding this to the plot demo.

Pete

new topic     » goto parent     » topic index » view message » categorize

3. Re: getting the canvas of iupplot and print it

this works great. thanks pete.

do you know how to get it to print landscape by any chance?

i was thinking, that i would probably great to plot to canvas every time, since one can have scrolling etc.. just a thought.

richard

new topic     » goto parent     » topic index » view message » categorize

4. Re: getting the canvas of iupplot and print it

pete let pick your brain one more time please.

i try to create a scrollable canvas of, lets say, 3000x1000 and put a plot of the same size in it. i then would like to scroll the whole plot from left to right. is this possible?

richard

new topic     » goto parent     » topic index » view message » categorize

5. Re: getting the canvas of iupplot and print it

IupPlot has builtin scrolling.

Hold down Ctrl and select an area with the mouse:
Move the mouse to any intended corner position,
press and hold the left mouse button,
move the mouse to the diagonally opposite corner,
as the rectangle grows, release the mouse button.

You can then drag the canvas with the mouse.

Not sure how any of that is achievable programmatically though, perhaps a few IupGetAllAttributes might show you how.

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu