Jump to content

Control flickering while moving GDIplus Image (SOLVED)


Recommended Posts

Hello all!

I have this problem which i cannot seem to figure out. I have a GDIplus image on my GUI, which also has a control over the top of it, in this case its just a simple graphic. Whenever i move the image, the control disappears, so ive had to add guictrlsetstate($drone, $GUI_SHOW), which causes the control to flicker when moving.

here is the full code:

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <Array.au3>

#include <GDIPlus.au3>

Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)

HotKeySet("{esc}", "esc")



HotKeySet("{a}", "dummy")
HotKeySet("{s}", "dummy")
HotKeySet("{d}", "dummy")
HotKeySet("{w}", "dummy")

Func dummy()
    ;msgbox(0, "", "")
EndFunc   ;==>dummy


$gui = GUICreate("map", 1600, 1000)
GUICtrlCreateGraphic(800, 400) ;creates the area where the map will be drawn...somehow
;$s = guictrlcreatebutton("s", 1200, 600)


GUISetState()



_GDIPlus_Startup()
$image = _GDIPlus_ImageLoadFromFile("C:\users\phill\desktop\survivor\map.jpg")

$gfx = _GDIPlus_GraphicsCreateFromHWND($gui)
$bmp_buffer = _GDIPlus_BitmapCreateFromGraphics(800, 600, $gfx)
$gfx_buffer = _GDIPlus_ImageGetGraphicsContext($bmp_buffer)



_GDIPlus_GraphicsScaleTransform($gfx_buffer, 3.1, 3.1, True)
_GDIPlus_GraphicsTranslateTransform($gfx_buffer, -300, -300, True)


$drone = GUICtrlCreateGraphic(1200, 700, 10, 10)
GUICtrlSetBkColor(-1, $COLOR_RED)

_Draw()

Func _Draw()
    ;_GDIPlus_GraphicsClear($gfx_buffer, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($gfx_buffer, 0xFFE8FFE8)
    _GDIPlus_GraphicsDrawImage($gfx_buffer, $image, 1, 1) ;draws the image and sets the pos of it
    _GDIPlus_GraphicsDrawImage($gfx, $bmp_buffer, 0, 0)


    _GDIPlus_GraphicsDrawImage($gfx, $bmp_buffer, 0, 0); Draw bitmap, $hBMPBuff, to the GUI's graphics, $hGraphicGUI.


guictrlsetstate($drone, $GUI_SHOW)

EndFunc   ;==>_Draw









While 1
    If WinActive("map") Then

        Select
            Case _IsPressed(53) And _IsPressed(44) ;down and right
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, -0.2, -0.2, True) ;moves the image
                _Draw()


            Case _IsPressed(53) And _IsPressed(41) ;down and left
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, 0.2, -0.2, True) ;moves the image
                _Draw()

            Case _IsPressed(57) And _IsPressed(44) ;up and right
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, -0.2, 0.2, True) ;moves the image
                _Draw()



            Case _IsPressed(57) And _IsPressed(41) ;up and left
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, 0.2, 0.2, True) ;moves the image
                _Draw()



            Case _IsPressed(41) ;left
                sleep(50)
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, 1, 0, True) ;moves the image
                _Draw()


            Case _IsPressed(44) ;right
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, -0.2, 0, True) ;moves the image
                _Draw()


            Case _IsPressed(57) ;up
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, 0, 0.2, True) ;moves the image
                _Draw()


            Case _IsPressed(53) ;down
                _GDIPlus_GraphicsTranslateTransform($gfx_buffer, 0, -0.2, True) ;moves the image
                _Draw()


        EndSelect
    EndIf


WEnd



Func esc()
    _GDIPlus_ImageDispose($image)
    _GDIPlus_GraphicsDispose($gfx_buffer)
    _GDIPlus_BitmapDispose($bmp_buffer)
    _GDIPlus_GraphicsDispose($gfx)
    _GDIPlus_Shutdown()
    GUIDelete($gui)
    Exit
EndFunc   ;==>esc

Any help would be much appreciated!

Thank you.

 

EDIT: SOLVED IT.

Edited by Phillip
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...