Page 1 of 1

Drawing vector graphics

Posted: Wed Jun 24, 2015 2:40 am
by Victorio
Hi,
I want create viewer for vector digital maps. I examine functions for drawing Gra... it is ok, drawing is too quick, ok for my use.
But I do not understand some things about metafile, dialogs and redrawing...
In example I have program, who open application window, and then presentation space
To it I drav several lines. After it if I move window to side (left, right, .... ) out from main app window and back, lines lost, or trim. It is no good. I want moving presentation , resizing, without lost draw.
In example metafile alaska is used metafile, but i do not know how input this to my source. In metafile.prg is I move window, draw is still in window.

Other thing : to future I want select some part of draw with mouse and zoom this to full presentation window, and other things so I need to work with maps.(zoom + -, pan, select, measure etc.

#include "Appevent.ch"
#include "Common.ch"
#include "Font.ch"
#include "Gra.CH"
#include "XBP.CH"
#include "Box.ch"

****************************
PROCEDURE AppSys
*****************************
PUBLIC oDlg, aPos[2], aSize[2],aPosu[2],aSizeu[2]

aSize := SetAppWindow():currentSize()
aPos[1] := 0.05 * aSize[1]
aPos[2] := 0.05 * aSize[2]
aSize[1] := aSize[1]*0.95
aSize[2] := aSize[2]*0.95

oDlg := XbpDialog():new( ,, aPos, aSize )
oDlg:title := "KRESLIMAPU"
oDlg:taskList := .T.
oDlg:close := {|| PostAppEvent( xbeP_Quit ) }
oDlg:create()
oDlg:drawingArea:setFontCompoundName( FONT_HELV_SMALL )

AppMenu( oDlg:menuBar() )

SetAppWindow( oDlg )

SetAppFocus( oDlg )

RETURN

**********************************************
PROCEDURE AppMenu( oMenuBar )
**********************************************
LOCAL oMenu

oMenu := XbpMenu():new( oMenuBar )
oMenu:title := "Aplikacia"
oMenu:create()
oMenu:addItem( { "Koniec", {|| PostAppEvent( xbeP_Quit ) } } )
oMenuBar:addItem( { oMenu, } )

oMenu := XbpMenu():new( oMenuBar )
oMenu:title := "Funkcie"
oMenu:create()
oMenu:addItem( { "Kresliciary ", {|| kresliciary() } } )
oMenuBar:addItem( { oMenu, } )

RETURN

*************************
PROCEDURE Main()
*************************
LOCAL i,j,k
LOCAL nEvent := NIL, mp1 := NIL, mp2 := NIL, oXbp := NIL, drawingArea
PUBLIC oDialog,oPS,oDevice
PUBLIC oMF

* rozmer okna pre vykreslenie mapy
aSizeu[1]=aSize[1]*0.8
aSizeu[2]=aSize[2]*0.8

oDialog:=XbpDialog():new( ,, aPos, aSizeu )
oDialog : create( , , {0,0},aSizeu)
oPS:= XbpPresSpace():new({1024,768})
oDevice:=oDialog:drawingArea:winDevice()
oPS:create(oDevice)


* cyklus pre čakanie na Quit, náhrada Inkey(0) ktorý tu nefunguje
DO WHILE nEvent <> xbeP_Quit
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:handleEvent( nEvent, mp1, mp2 )
ENDDO
**********
RETURN
**********

****************************
FUNCTION kresliciary
****************************
GraSetColor( oPS, GRA_CLR_RED )
GraLine(oPS,{10,50},{600,50})
GraSetColor( oPS, GRA_CLR_GREEN)
GraLine(oPS,{10,100},{600,100})
GraSetColor( oPS, GRA_CLR_BLUE)
GraLine(oPS,{10,150},{600,150})
GraSetColor( oPS, GRA_CLR_BLACK)
GraLine(oPS,{10,200},{600,200})
****************************
return nil
****************************

Re: Drawing vector graphics

Posted: Thu Jun 25, 2015 7:03 pm
by Auge_Ohr
Victorio wrote:Other thing : to future I want select some part of draw with mouse and zoom this to full presentation window, and other things so I need to work with maps.(zoom + -, pan, select, measure etc.
did you have played with Alaska Sample c:\ALASKA\XPPW32\Source\samples\solution\Preview\Preview.prg ?

it show how to Zoom in a Preview ... and you can "print-out" ( or Save it in a Bitmap )
remember oPS is same for Screen and Printer ... just switch Device

Re: Drawing vector graphics

Posted: Thu Jun 25, 2015 8:57 pm
by rdonnay
Try adding this:

oDialog:paint := {||kresliciary(oPS)}

Re: Drawing vector graphics

Posted: Mon Jun 29, 2015 3:30 am
by Victorio
Roger: thanks, :paint work´s fine.
now I examine gra fnc, if it will be useable for my digital maps viewer.
for small maps in vector format it works fine, but maps with 200000 and more points (and 200000 lines objects) it will be slow, and map is draw without signs, texts and other objects.
also experienced with store coordinates in database and in array too, but speed drawing is little slower if coordinates is in array ?!.

I know, better for it is C,C++ language ;)

Jimmy: preview with zoom I saw, I am not sure, if it is useable for vector graphics ?

Re: Drawing vector graphics

Posted: Mon Jun 29, 2015 10:16 am
by Auge_Ohr
Victorio wrote:Jimmy: preview with zoom I saw, I am not sure, if it is useable for vector graphics ?
you always need oPS to "paint" ... like in Preview which show how to "zoom"