rwg
New Member
Posts: 49
|
Post by rwg on Sept 23, 2019 19:38:01 GMT -5
i've given up trying to both view and print a graphics window !
it would appear that if i "flush" during my plot creation, then i can't print without distortions.
conversely, if i don't flush during the creation, then i can't view those parts of the plot outside the graphics window.
having read plenty of Alyce's great contributions, i'm now a master of the following ....
fixing the glitch when scrolling outside the graphics window.
creating scrollbars and setting scrollbars limits. using api's to set and get scroll positions. using the "SIZE" command when printing. creating bitmaps. using the "FLUSH" command. etc, etc ...
despite this, i can't achieve what i thought would be simple at the beginning of my programming mission.
|
|
|
Post by tsh73 on Sept 24, 2019 1:22:38 GMT -5
Do flush, enjoy "viewing those parts of the plot outside the graphics window" Then trying to print, CLS and redraw from scratch, so it'll be single flushed segment. Just an idea.
|
|
|
Post by Rod on Sept 24, 2019 4:31:19 GMT -5
OK, just to help me understand the problem. Here is code that creates a large chart that you can scroll around and print. Are you trying to print only sections of the chart?, the section in view?
Nomainwin WindowWidth = 800 WindowHeight = 800
UpperLeftX = Int((DisplayWidth - WindowWidth)/2) UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Graphicbox #1.graph, 20, 20, 690, 700 button #1.print, "Print", [print], UL, 720, 10 Open "Graphicbox and Scrollbars" for Window_nf as #1 #1 "Trapclose [quit]"
#1.graph "Horizscrollbar On 0 1000" #1.graph "Vertscrollbar On 0 1000" #1.graph "Down ; Color Darkblue"
'the graphics will distort without the next line #1.graph "Place -20, -20; Boxfilled 1690 1700"
'draw some graduations and circles to check for dsitortion. For x = 0 to 1670 Step 10 '1000 (max) + 690 (graphicbox width) - 20 = 1670 #1.graph "Place ";x;" 10" #1.graph "North; Turn 180; Go 10" If x / 100 = Int( x / 100 ) Then #1.graph "Go 10" #1.graph "Place ";x - 10;" 40" #1.graph "\";x End If Next x For y = 0 to 1680 Step 10 '1000 (max) + 700 (graphicbox height) - 20 = 1680 #1.graph "Place 10 ";y #1.graph "North; Turn 90; Go 10" If y / 100 = Int( y / 100 ) Then #1.graph "Go 10" #1.graph "Place 30 ";y + 5 #1.graph "\";y End If Next y #1.graph "place 845 850 ; circle 820 ; circle 815" #1.graph "Flush" Wait
[print] #1.graph "print 1690" wait
[quit] close #1 end
I also posted code a while back that scaled chart data to fit any chart size. Would that help? The underlying problem is that you can only have one flush command if you want to print. But Liberty can redraw the chart so quickly that it is relatively straight forwards to draw and print what you want then redraw and view what you want. The graphic box you use for printing does not even have to be in view so two graphicboxes might help but I need to understand the problem a little better.
|
|
|
Post by Rod on Sept 24, 2019 5:57:42 GMT -5
Just thinking, you are using API code to set and get scrollbar positions? If I recall I had trouble getting those to work when testing code to answer your query about scrollbars. In the above code I stay within the Liberty BASIC drawing system. By stepping outside and introducing API drawing/scrolling you are perhaps spoiling the Liberty BASIC segment. Can you add code to my example that shows the problem? I don't understand why you might need to get and set the scroll position, so code would help, a working extract of your own code?
|
|
|
Post by tenochtitlanuk on Sept 24, 2019 14:39:25 GMT -5
Francesco showed an example several years back that may be relevant and suggests an alternative. Example below generates a 1800x1800 BMP. If you open it in a browser rather than a LB graphics window you can see it either reduced to fit the browser page, or click on it for the full scale representation and scroll it. 'JB Spirograph v0.02 pre-alfa :) By Francesco 'Main purpose is to demonstrate the use of the function SaveGraphicBox. 'See below to read more about that function. 'The pic will be saved to the current dir with name "Spirograph.bmp"
'Here you can initialize bmp file settings ImageWidth=1800:ImageHeight=1800:xdpi=300:ydpi=300:FileName$="Spirograph.bmp"
'Open 600x600 window and (ImageWidth)x(ImageHeight) graphicbox nomainwin WindowWidth=600:WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2:UpperLeftY=(DisplayHeight-WindowHeight)/2 graphicbox #w.g,0,0,ImageWidth,ImageHeight open "JB Spirograph v0.01 by Francesco" for window_nf as #w #w "trapclose [quit]"
'Initialize random values for the epicycloid x0=ImageWidth/2:y0=ImageHeight/2:r1=0:r2=0:p=0:da=1:i=x0:if x0>y0 then i=y0 t=int(i/50):if t<5 then t=5 while (r1+r2+p)<int(i/2) while r1=r2 r1=int(t+(i-2*t)*rnd(1)) while r2=0:r2=int(t+(i-r1-2*t)*rnd(1))-r1:wend wend p=int(t+(i-r1-r2-t)*rnd(1)) wend if abs(r1)<=abs(r2) then t=abs(r1) if abs(r1)>abs(r2) then t=abs(r2) for i=t to 1 step -1 if ((abs(r1) mod i)=0)and((abs(r2) mod i)=0) then if i>1 then n=int(360*abs(r2)/i):i=0 if i=1 then n=int(360*abs(r2)/3) end if next
'Here you can re-initialize the values of the spirograph. 'Uncomment next lines and set your values 'or they will be (reasonably) random.
'r1 = 60 '(pixels) radius of main circle 'r2 = 60 '(pixels) radius of second circle 'p = 60 '(pixels) offset of drawing point relative to 2nd circle 'da = 1 '(degrees) increment of the angle (resolution) 'n = 34560 '(decimal) number of points to calculate
'Draw epicycloid print #w.g,"down;place 0 0;color white;backcolor white" print #w.g,"boxfilled ";ImageWidth;" ";ImageHeight print #w.g,"flush;color black" a=0 print #w.g,"place ";x0+r1+r2+p;" ";y0 for i = 1 to n ar=asn(1)/90*a x=int((r1+r2)*cos(ar)+p*cos((r1+r2)*ar/r2)) y=int((r1+r2)*sin(ar)+p*sin((r1+r2)*ar/r2)) print #w.g,"goto ";x0+x;" ";y0+y a=a+da next print #w.g,"flush"
'Call SaveGraphicBox function, show result and exit t=SaveGraphicBox(FileName$,"#w.g",0,0,ImageWidth,ImageHeight,xdpi,ydpi) run "rundll32.exe C:\Windows\system32\shimgvw.dll,ImageView_Fullscreen "+DefaultDir$+"\"+FileName$ close #w end
'**************************************************************************************************** '* SaveGraphicBox saves part of a graphicbox to a bmp file to the default dir path. '* This function can grab and save the bitmap of very large graphicboxes while getbmp+bmpsave '* can grab and save only visible parts of them, thus being limited by the size of the desktop. '* This function moves the graphicbox and grabs it divided in many small bmp files and then '* merges them to single large bmp file. The graphicbox must be opened in a "window" type window. '* '* Parameters: '* FileName$: name of the bmp file '* boxHandle$: handle of the graphicbox '* xStart: x of upper left corner of the portion to grab '* yStart: y of upper left corner of the portion to grab '* xSize: horizontal size in pixels of the portion to grab '* ySize: vertical size in pixels of the portion to grab '* xdpi: horizontal dpi that will be stored in bmp file header '* ydpi: vertical dpi that will be stored in bmp file header '**************************************************************************************************** function SaveGraphicBox(FileName$,boxHandle$,xStart,yStart,xSize,ySize,xdpi,ydpi) SaveGraphicBox=0:winHandle$=left$(boxHandle$,instr(boxHandle$,".")-1) nx=1+int((xSize-1)/500):ny=1+int((ySize-1)/500) ly=-1*yStart:nt=1:yS=ySize for i=1 to ny lx=-1*xStart:xS=xSize for j=1 to nx dx=500:if xS<500 then dx=xS dy=500:if yS<500 then dy=yS print #boxHandle$,"locate ";lx;" ";ly;" ";500-1*lx+2;" ";500-1*ly+2 print #winHandle$,"refresh":print #boxHandle$,"flush" print #boxHandle$,"getbmp bmp ";-1*lx;" ";-1*ly;" ";dx;" ";dy bmpsave "bmp","SGBtemp"+right$("00"+str$(nt),3)+".bmp" lx=lx-500:xS=xS-500:nt=nt+1 next ly=ly-500:yS=yS-500 next print #boxHandle$,"locate 0 0 ";WindowWidth;" ";WindowHeight print #winHandle$,"refresh":print #boxHandle$,"flush" open "SGBtemp001.bmp" for input as #1:h$=input$(#1,14) hlen=asc(mid$(h$,11,1))+256*asc(mid$(h$,12,1))+256*256*asc(mid$(h$,13,1))+256*256*256*asc(mid$(h$,14,1)) h$=h$+input$(#1,hlen-14):close #1 nt=1:bmlen=0 for i=1 to ny for j=1 to nx open "SGBtemp"+right$("00"+str$(nt),3)+".bmp" for input as #1:t$=input$(#1,6):close #1 l=asc(mid$(t$,3,1))+256*asc(mid$(t$,4,1))+256*256*asc(mid$(t$,5,1))+256*256*256*asc(mid$(t$,6,1)) bmlen=bmlen+l-hlen:nt=nt+1 next next pixlen=int(bmlen/(xSize*ySize)) open FileName$ for output as #1:n=int(bmlen/1000) print #1,h$; for i=1 to n:print #1,space$(1000);:next:print #1,space$(bmlen-n*1000); close #1 open FileName$ for binary as #1:actualseek=hlen t=lof(#1):seek #1,2:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next t=xSize:seek #1,18:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next t=ySize:seek #1,22:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next t=bmlen:seek #1,34:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next t=int(xdpi*(100/2.54)):seek #1,38:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next t=int(ydpi*(100/2.54)):seek #1,42:for i=1 to 4:print #1,chr$(t and 255);:t=t/256:next for i=ny to 1 step -1 t=0 for j=1 to nx nt=(i-1)*nx+j:open "SGBtemp"+right$("00"+str$(nt),3)+".bmp" for input as #2 t$=input$(#2,hlen) w=asc(mid$(t$,19,1))+256*asc(mid$(t$,20,1))+256*256*asc(mid$(t$,21,1))+256*256*256*asc(mid$(t$,22,1)) h=asc(mid$(t$,23,1))+256*asc(mid$(t$,24,1))+256*256*asc(mid$(t$,25,1))+256*256*256*asc(mid$(t$,26,1)) for k=1 to h:seek #1,actualseek+t+(k-1)*xSize*pixlen:print #1,input$(#2,w*pixlen):next close #2 t=t+w*pixlen next actualseek=loc(#1) next close #1 nt=1:for i=1 to ny:for j=1 to nx:kill "SGBtemp"+right$("00"+str$(nt),3)+".bmp":nt=nt+1:next:next end function
[quit] close #w end
|
|
|
Post by Carl Gundel on Sept 24, 2019 15:16:41 GMT -5
Francesco showed an example several years back that may be relevant and suggests an alternative. Example below generates a 1800x1800 BMP. If you open it in a browser rather than a LB graphics window you can see it either reduced to fit the browser page, or click on it for the full scale representation and scroll it. Clever.
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Sept 25, 2019 19:56:50 GMT -5
thanks all for your responses. i'm working on them regards rwg
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Sept 25, 2019 22:19:02 GMT -5
thanks Rod for your help. i've taken the API settings for getting and setting scrollbars out of my program. they work well, but maybe they do have unwanted effects. my aim was to plot coordinated lines starting from a position way off the graphics window. instead of manually scrolling and searching for the plotted start point, the API would scroll to the central point automatically. my only problem now is successfully printing the graphics window. i know it's got something to do with "flushing". below is a simplistic bit of code which hopefully highlights the problem. throughout my program i need to be able to "flush" so as to allow for, amongst other things, "undoing" bits and pieces of graphics. if i dont use the "flush" command midway through the following code, the print is correct. but the print is a mess if i do "flush". as you can see, i don't use a graphicbox, just a graphics window. too late now - i don't want to change the software.
'place mainwin at top left of screen 'i use mainwin as a log calldll #user32,"GetActiveWindow",_ mainwinhandle as short calldll #user32,"MoveWindow", _ mainwinhandle as word, _ 0 as short, _ 0 as short, _ 600 as short, _ 750 as short, _ 1 as word, _ result as void
'open a graphics window WindowWidth = 740:WindowHeight = 750 UpperLeftX=610:UpperLeftY=1 OPEN "lines test" for graphics_nsb as #5 #5,"trapclose [quitclose]" #5 "Place -20, -20; Boxfilled 1740 1750" 'to stop distortion ? #5 "Horizscrollbar On 0 1000" #5 "Vertscrollbar On 0 1000" 'print 2 lines, one 350 pixels long 'the other 400 pixels long 'line 2 will go past the graphics window" 'no problem to view - just scroll across. #5,"place 50 375" #5,"down" #5,"circlefilled 10" #5,"line 50 375 400 375" #5,"flush" 'if i dont flush now, all would be ok #5,"circlefilled 10" #5,"line 400 375 800 375" #5,"circlefilled 10" #5,"flush" #5,"redraw" 'suggested by tsh73 'print to default printer wait #5,"print 1000" wait [quitclose] end
|
|
|
Post by Rod on Sept 26, 2019 2:51:00 GMT -5
Well if you want to print graphics in Liberty BASIC v4.x you must create your drawn image within one segment. A segment is a collection of drawing and text placement commands that create an image that is captured and stored with the FLUSH command. Use more than one FLUSH and you create more than one segment.
The command is mostly used to "fix" graphics. If you don't flush and the window is moved off screen or covered by another window the graphics will be lost. By creating a segment with FLUSH these segments are remembered and redrawn when the window moves on screen or is uncovered.
So most often folks issue FLUSH after FLUSH without thinking about it. When it comes to printed output it is different, PRINT cannot access everything in previous segments so you have to be sure there is only one.
This is fairly easy to do and can happen in the blink of an eye. The solution is to have a sub that redraws your chart completely from scratch. So CLS, Draw, FLUSH, PRINT. The CLS wipes out all previous segments, you draw a new single segment and print that.
The scale and text code will probably not change, the chart itself just needs redrawn from a data array. Doing that you could probably reintroduce your API scroll code as it will have no impact on the print image. You could also draw the chart to a hidden graphicbox and print from that graphicbox, just create it off screen so it cannot be seen, it need not be very large. Your current window can then be left as is.
|
|
|
Post by Rod on Sept 26, 2019 3:03:57 GMT -5
'place mainwin at top left of screen 'i use mainwin as a log calldll #user32,"GetActiveWindow",_ mainwinhandle as short calldll #user32,"MoveWindow", _ mainwinhandle as word, _ 0 as short, _ 0 as short, _ 600 as short, _ 750 as short, _ 1 as word, _ result as void
'open a graphics window WindowWidth = 740:WindowHeight = 750 UpperLeftX=610:UpperLeftY=1 graphicbox #5.hidden,-10,-10,0,0 OPEN "lines test" for graphics_nsb as #5 #5,"trapclose [quitclose]" #5 "Place -20, -20; Boxfilled 1740 1750" 'to stop distortion ? #5 "Horizscrollbar On 0 1000" #5 "Vertscrollbar On 0 1000" 'print 2 lines, one 350 pixels long 'the other 400 pixels long 'line 2 will go past the graphics window" 'no problem to view - just scroll across. #5,"place 50 375" #5,"down" #5,"circlefilled 10" #5,"line 50 375 400 375" #5,"flush" 'if i dont flush now, all would be ok #5,"circlefilled 10" #5,"line 400 375 800 375" #5,"circlefilled 10" #5,"flush" gosub [printit] wait
[printit] #5.hidden "down ; cls" #5.hidden "place 50 375" #5.hidden "circlefilled 10" #5.hidden "line 50 375 400 375" #5.hidden "circlefilled 10" #5.hidden "line 400 375 800 375" #5.hidden "circlefilled 10" #5.hidden "flush" #5.hidden "print 1000" return
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Sept 26, 2019 20:14:48 GMT -5
thanks again Rod. i can follow that.
|
|