Repaint static / bitmap

This forum is for eXpress++ general support.
Message
Author
User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Repaint static / bitmap

#21 Post by Auge_Ohr »

Victorio wrote:Have some solution to run this example?
do you mean Express++ Sample ... exclude EVAL( Codeblock ) from that line
Victorio wrote:I need some examples where is used redraw function for my map viewer based on vector graphics.
In example is some like I want.
I am comment line with error then program run and show main window with menu, but it is all what I can do.
i guess you want to load a Picture and have Repaint Problem ?

normal Way

Code: Select all

oDrawStatic:Caption := oImage
   or after o:Create()
oDrawStatic:Setcaption(oImage)
here Windows OS() will do default rePAINT when WM_PAINT is fired.

Enhance Way

Code: Select all

oDrawStatic:Paint := {|aRect,uNIL,oSelf| RepaintScreen(oBMP,aRect,oSelf) }

FUNCTION RepaintScreen(oBMP,aRect,oSelf)
LOCAL oLockPS
   oLockPS := oSelf:LockPS()
   oBMP:draw( oLockPS                        , ;
              aRect                          , ;
             { 0, 0, oBMP:xSize, oBMP:ySize }, ;
                                             , ;
              GRA_BLT_BBO_IGNORE )
   oSelf:UnlockPS()
RETURN .T.
here you fill o:Paint Codeblock (of XbpStatic() / XbpWindow() ) with your Function "to paint" ( oBMP:draw() ) , which will override Windows OS() default, when WM_PAINT is fired.

if you want to "paint" into your Image you have to use the Presspace of Image !!!

Code: Select all

   ::oPS := XBpPresSpace():New()
   ::oPS:Create( ::oStat:WinDevice() )

   ::oFont    := XbpFont():new(::oPS)
   ::oFont:create(FONT_DEFFIXED_MEDIUM+FONT_STYLE_BOLD)
   GraSetFont( ::oPS, ::oFont )

   ::oBMP := XbpBitmap():new():create(::oPS)
   ::oBMP:Load("DXEPLAY2.EXE",2002)

   nBGClr                :=::oBMP:getDefaultBgColor()
   ::oBMP:transparentClr := nBGClr

   aTmp   :=::oStat:CurrentSize()
   ::oStat:SetCaption( BMP2BMP(::oBMP,{aTmp[1],aTmp[2]}) ) // resize and set as Caption
greetings by OHR
Jimmy

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Repaint static / bitmap

#22 Post by Auge_Ohr »

Victorio wrote:Jimmy: I examine PEN_DRAW, thanks it is other nice example. I will study it :)
as i say this is the "original" what Jack Duijf used for his Sample which make Problem with repaint after add a Image to paint "on it".
greetings by OHR
Jimmy

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Repaint static / bitmap

#23 Post by Victorio »

Hi Jimmy,

I want examine lockPS, unlockPS, but I do not understand, what this function/procedure do ?

I want speedy drawing because drawing about 200000-400000 lines is too slow.
Has using lockPS, unlockPS some effect to speed drawing ?
I examine using array to read coordinates of lines from database and then drawing, but no effect.

Here is little example, I do not know, why kresliciary() drawing lines, but kresliciary3() NO !.

Can I use lockPS, unlockPS for drawing vector elements ( like GraLine..-...) ?

In my example, I have main window (application window), with menu, and in it some other graphic window oPS.
I want draw to this window, but controlling with menu and some buttons, like in PENDRAW example.

EXAMPLE :
**************************
* KRESLIMAPU.PRG
**************************
#include "Appevent.ch"
#include "Common.ch"
#include "Font.ch"
#include "Gra.CH"
#include "XBP.CH"

PROCEDURE AppSys

PUBLIC oDlg, oDialog, oPS,oMF,oDevice,oMenu
PUBLIC aPos[2], aSize[2],aPosu[2],aSizeu[2],farba:=1,zoomfaktor:=0
* toto iba pomocnß premennß, ak zmenÝm farbu, mierku,... pokyn na prekreslenie
PUBLIC zmena:=.F.
* zistenie rozmerov aktußlnej obrazovky podża rozlÝÜenia v pixeloch, tj. max.rozmery
aSize := SetAppWindow():currentSize()
* toto je pozÝcia, kde sa umiestni okno, teda lavy dolny roh
* teda vypoŔÝtanÚ ako 0.01 z aSize ktorÚ je zase zistenÚ cez currentSize
aPos[1] := 0.05 * aSize[1]
aPos[2] := 0.05 * aSize[2]
* toto je rozmer hlavnÚho okna aplikßcie, ktorÚ sa otvorÝ pri spustenÝ programu
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 )

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()

* tu pekne vykreslÝ Ŕiary,ale pri posune okna z nich ore×e
oMenu:addItem( { "Kresliciary ", {|| kresliciary()} } )

oMenu:addItem( { "Kresliciary3 + lockPS/unlockPS ", {|| kresliciary3()} } )

oMenuBar:addItem( { oMenu, } )

RETURN

PROCEDURE Main()

LOCAL i,j,k
LOCAL nEvent := NIL, mp1 := NIL, mp2 := NIL, oXbp := NIL, drawingArea
LOCAL nSegId:=0
PUBLIC pocetbodov
PUBLIC a_x_sur[1000000],a_y_sur[1000000],a_t_spoj[1000000]
aSizeu[1]=aSize[1]*0.8
aSizeu[2]=aSize[2]*0.8

oDialog:=XbpDialog():new( ,, aPos, aSizeu )
oDlg:taskList:=.T.
oDlg:sizeRedraw:=.T.
oDlg:title:="Presentation Space Demo"
oDialog : create( , , {0,0},aSizeu)
oPS:= XbpPresSpace():new({1024,768})

oPS:create(oDialog:drawingArea:winDevice())


* HERE DRAWING 4 lines, OK, GOOD !
****************************************************
* tu kreslÝ automaticky Ŕiary na obrazovku, ok, aj pri posune sa uchovß kresba
*oDialog:drawingArea:paint:={||kresliciary(oPS,@nSegId)}

* HERE DRAWING 4 lines, but ??? NOTHING ON SCREEN ??? WHY ?
*************************************************************************************
oDialog:drawingArea:paint:={||kresliciary3(oPS,@nSegId)}

* toto sk˙siŁ vyhodiŁ ???
oDialog:show()

SetAppFocus(oDialog)

* 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 )
* oDlg:handleEvent( nEvent, mp1, mp2 )
* oDialog:handleEvent( nEvent, mp1, mp2 )


ENDDO

RETURN

FUNCTION kresliciary(oPS,nSegId)

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

FUNCTION kresliciary3(oPS,nSegId)

oPS:=oDialog:lockPS()

GraSetColor( oPS, GRA_CLR_RED )
GraLine(oPS,{10,50},{600,50})
*sleep(100)
GraSetColor( oPS, GRA_CLR_GREEN)
GraLine(oPS,{10,100},{600,100})
*sleep(100)
GraSetColor( oPS, GRA_CLR_BLUE)
GraLine(oPS,{10,150},{600,150})
*sleep(100)
GraSetColor( oPS, GRA_CLR_BLACK)
GraLine(oPS,{10,200},{600,200})
*sleep(100)

oDialog:unlockPS(oPS)


return
Attachments
KresliMapuAlaska.zip
(1.92 KiB) Downloaded 614 times

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Repaint static / bitmap

#24 Post by Auge_Ohr »

Victorio wrote:I want examine lockPS, unlockPS, but I do not understand, what this function/procedure do ?
you need oPS to "paint". you can use

Code: Select all

   oPS:= XbpPresSpace() 
OR 
   oPS:= XbpWindow():lockPS()
! Note : every XbPart have XbpWindow() as SuperClass
Victorio wrote:I want speedy drawing because drawing about 200000-400000 lines is too slow.
you have to "paint" it once ... than "save" it to a Bitmap for "repaint".
painting is much faster when o:hide() Parent an later o:Show()
Victorio wrote:Here is little example, I do not know, why kresliciary() drawing lines, but kresliciary3() NO !.

Code: Select all

   oPS:= XbpPresSpace():new() // NO Size
   oPS:create(oDialog:drawingArea:winDevice())
you are using o:drawingArea "to paint" ... i use o:drawingArea only as Parent for XbParts as Child
i use a XbpStatic, on o:drawingArea, to "paint on"
Victorio wrote:

Code: Select all

*oDialog:drawingArea:paint:={||kresliciary(oPS,@nSegId)}
oDialog:drawingArea:paint:={||kresliciary3(oDialog,@nSegId)}
1st Line pass oPS so you can "paint" into it.
2nd Line want to use XbpWindow():lockPS() so you have to pass the XbPart Object
Victorio wrote:

Code: Select all

FUNCTION kresliciary(oPS,nSegId)
   GraSetColor( oPS, GRA_CLR_RED )
   ...
return 

FUNCTION kresliciary3(oDialog,nSegId)
// if you don´t have pass oPS you have to create it
LOCAL oPS:=oDialog:drawingArea:lockPS()

   GraSetColor( oPS, GRA_CLR_RED )
   ...
   oDialog:drawingArea:unlockPS(oPS)
return
! Note : all Xbparts Callback Slots have self = oSelf as Parameter between | here Parameter | ...

Code: Select all

o:paint := {| aRect, uNIL, oSelf | Doit(aRect, oSelf) }

PROCEDURE Doit(aRect, oSelf)
LOCAL oPS := oSelf:lockPS()
   ...
   oSelf:unlockPS(oPS)
here a fulll Sample what i have change
MDI_GRA.ZIP
(2.49 KiB) Downloaded 642 times
greetings by OHR
Jimmy

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Repaint static / bitmap

#25 Post by Victorio »

Thank you very much ! I will try it.

Post Reply