Sign in to follow this  
Followers 0
cheatera

2d design problem

10 posts in this topic

#1 ·  Posted (edited)

ok ... im trying to make this for a looong time ... and now im finaly near. but! there's aways a BUT ... when i "dynamic" draw box on graphic its all fine ... when i draw second box - it deletes first one :mellow: tried to make it like background (GUIctrlCreatePic) and screen cap and not to define it like graphic and blaaaaaaaa .... help anyone?

CODE
;// includes

#include <misc.au3>

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include <GDIPlus.au3>

#include <ScreenCapture.au3>

;// opt's

Opt("MouseCoordMode", 0)

;// vars

;// gui

$main_gui = GUICreate("drawer", 200, 150, 10, 300)

;$graph = GUICtrlCreateGraphic(0, 0, 556, 492, BitOR($SS_NOTIFY,$SS_SUNKEN))

;GUICtrlSetBkColor(-1, 0xFFFFFF)

$line_button = GUICtrlCreateButton("line_button", 680, 40, 75, 25, 0)

$combo = GUICtrlCreateCombo("", 10, 16, 169, 25)

$box_button = GUICtrlCreateButton("box_button", 10, 40, 75, 25, 0)

$Button3 = GUICtrlCreateButton("Button3", 10, 72, 75, 25, 0)

$Button4 = GUICtrlCreateButton("Button4", 10, 72, 75, 25, 0)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()

$draw_form = GUICreate("draw_form", 633, 447, -1, -1, BitOR($WS_DLGFRAME,$WS_POPUP), -1, "draw")

$hWnd = WinGetHandle("draw_form")

$hDC = _WinAPI_GetWindowDC($hWnd)

; arrows related

$hPen = _GDIPlus_PenCreate (0xFF000000, 2)

$hEndCap = _GDIPlus_ArrowCapCreate (3, 6)

_GDIPlus_PenSetCustomEndCap ($hPen, $hEndCap)

; text related

$hBrush = _GDIPlus_BrushCreateSolid (0xFF000000)

$hFormat = _GDIPlus_StringFormatCreate ()

$hFamily = _GDIPlus_FontFamilyCreate ("Arial")

$hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)

$graph = _GDIPlus_GraphicsCreateFromHDC ($hDC)

GUISetState(@SW_SHOW)

;// main loop

Do

$msg = GUIGetMsg()

$mpos = MouseGetPos()

ToolTip($mpos[0] & "," & $mpos[1])

If _IsPressed("01") then

$mpos = MouseGetPos()

Do

$mpos2 = MouseGetPos()

ToolTip($mpos2[0] & "," & $mpos2[1])

; arrows

_GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)

_GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)

; box

_GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[0] - 21)

_WinAPI_RedrawWindow("drawer", "", $tagRECT, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))

; text

$tLayout = _GDIPlus_RectFCreate (($mpos2[0] + $mpos[0]) / 2.2, $mpos[1] - 30, 100, 20)

_GDIPlus_GraphicsDrawStringEx ($graph, $mpos2[0] - $mpos[0] & " pixels", $hFont, $tLayout, $hFormat, $hBrush)

Until Not _IsPressed("01")

_GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[1])

_GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)

_GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)

$size = WinGetPos("draw_form")

$hBMP = _ScreenCapture_CaptureWnd("", $draw_form, 0, 0, $size[2], $size[3], false)

;GUICtrlCreatePic("temp.bmp", 0, 0, 443, 320)

$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)

_GDIPlus_GraphicsDrawImage ($graph, $hBitmap, 0, 0)

EndIf

Until $msg = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose ($graph)

_WinAPI_ReleaseDC($hWnd, $hDC)

_GDIPlus_Shutdown ()

p.s.: s0z f0r m3 b4d 3ngl|sh

Edited by cheatera

Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites



cmon guys ... im stuck and REALLY need help :mellow:


Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites

ok shutting down this - cant do it alone ... is there ANY other similar project? searched all forums and didnt found nothing ... post atleast link to similar project - 2d design


Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites

ok shutting down this - cant do it alone ... is there ANY other similar project? searched all forums and didnt found nothing ... post atleast link to similar project - 2d design

You are very impatient! Opening a thread, bumping it after 92 minutes then stamping your feet after 4 hours when it is usually reconned you should not bump sooner than 24 hours.

To do what you want requires drawing using XOR so that when the rectangle has to be redrawn you first redraw it exactly as it was last drawn which will make it disappear, then draw in the new position, and you don't erase the background and so don't erase previously drawn items.

I don't think GDI+ allows you to use XOR for drawing. This means that either you make your own function for drawing lines where you calculate pixel by pixel what to draw, which would be slow I expect, or you use GDI for the lines because GDI does allow XOR and other logical mixes.

I could be wrong of course but that's how I see it.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

sry, maybe i rushed it a little ... but i got little mad when i saw 30-40 views, and abs no response :\ ok will try with XOR didnt think of it :mellow: thx for the replay will post if i have success


Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites

update: ok stuck again ... same problem ... cant i just embed mspaint window? like object? i just need the coords "drawed" by the mouse but i must see where to put the lines, i need somekind of "background" ... searched all forum again ... nothing ... cant find it with olveviewer. cmon obj/com masters, where are you?


Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


Link to post
Share on other sites

sry, maybe i rushed it a little ... but i got little mad when i saw 30-40 views, and abs no response :\ ok will try with XOR didnt think of it :mellow: thx for the replay will post if i have success

I am not sure about others but speaking for myself, the number of responses could easily reflect those who have an interest in the topic, but have nothing valuable to add to the topic conversation.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You should use double buffer and WM_PAINT. Hope, this will help you :mellow:

//Edit: using third buffer to save old rects

;// includes
#include <misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

;// opt's
Opt("MouseCoordMode", 0)


;// vars



;// gui

$main_gui = GUICreate("drawer", 200, 150, 10, 300)

;$graph = GUICtrlCreateGraphic(0, 0, 556, 492, BitOR($SS_NOTIFY,$SS_SUNKEN))
;GUICtrlSetBkColor(-1, 0xFFFFFF)
$line_button = GUICtrlCreateButton("line_button", 680, 40, 75, 25, 0)
$combo = GUICtrlCreateCombo("", 10, 16, 169, 25)
$box_button = GUICtrlCreateButton("box_button", 10, 40, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Button3", 10, 72, 75, 25, 0)
$Button4 = GUICtrlCreateButton("Button4", 10, 72, 75, 25, 0)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()
$drawGUI = GUICreate("drawer2",633,447)

; arrows related
$hPen = _GDIPlus_PenCreate (0xFF000000, 2)
$hEndCap = _GDIPlus_ArrowCapCreate (3, 6)
_GDIPlus_PenSetCustomEndCap ($hPen, $hEndCap)
; text related
$hBrush = _GDIPlus_BrushCreateSolid (0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)


$graph1 = _GDIPlus_GraphicsCreateFromHWND($drawGUI)
$IMG = _GDIPlus_BitmapCreateFromGraphics(633,447,$graph1)
$graph = _GDIPlus_ImageGetGraphicsContext($IMG)

$SaveBuff = _GDIPlus_BitmapCreateFromGraphics(633,447,$graph1)
$Savegraph = _GDIPlus_ImageGetGraphicsContext($SaveBuff)
_GDIPlus_GraphicsClear($Savegraph,0xFFFFFFFF)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_PAINT,"REPAINT")
Func REPAINT($hWnd,$Msg,$wParam,$lParam)
    If $hWnd = $drawGUI Then
        _GDIPlus_GraphicsDrawImage ($graph1, $IMG, 0, 0)
    EndIf
EndFunc
;// main loop
Do
$msg = GUIGetMsg()
$mpos = MouseGetPos()
ToolTip($mpos[0] & "," & $mpos[1])
If _IsPressed("01") then

$mpos = MouseGetPos()
Do
$mpos2 = MouseGetPos()
ToolTip($mpos2[0] & "," & $mpos2[1])
; arrows
;~ _GDIPlus_GraphicsClear($graph,0xFFFFFFFF)
_GDIPlus_GraphicsDrawImage($graph,$SaveBuff,0,0)
_GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)
_GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)
; box
_GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[0] - 21)
;~ _WinAPI_RedrawWindow("drawer", "", $tagRECT, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))
; text
$tLayout = _GDIPlus_RectFCreate (($mpos2[0] + $mpos[0]) / 2.2, $mpos[1] - 30, 100, 20)
_GDIPlus_GraphicsDrawStringEx ($graph, $mpos2[0] - $mpos[0] & " pixels", $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_GraphicsDrawImage ($graph1, $IMG, 0, 0)
Until Not _IsPressed("01")
_GDIPlus_GraphicsDrawImage ($Savegraph, $IMG, 0, 0)
;~ _GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[1])
;~ _GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)
;~ _GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)


EndIf
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose ($graph1)
_GDIPlus_GraphicsDispose ($graph)
_GDIPlus_BitmapDispose($IMG)
_GDIPlus_GraphicsDispose ($Savegraph)
_GDIPlus_BitmapDispose($SaveBuff)
_GDIPlus_Shutdown ()
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

You should use double buffer and WM_PAINT. Hope, this will help you :mellow:

//Edit: using third buffer to save old rects

;// includes
#include <misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

;// opt's
Opt("MouseCoordMode", 0)


;// vars



;// gui

$main_gui = GUICreate("drawer", 200, 150, 10, 300)

;$graph = GUICtrlCreateGraphic(0, 0, 556, 492, BitOR($SS_NOTIFY,$SS_SUNKEN))
;GUICtrlSetBkColor(-1, 0xFFFFFF)
$line_button = GUICtrlCreateButton("line_button", 680, 40, 75, 25, 0)
$combo = GUICtrlCreateCombo("", 10, 16, 169, 25)
$box_button = GUICtrlCreateButton("box_button", 10, 40, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Button3", 10, 72, 75, 25, 0)
$Button4 = GUICtrlCreateButton("Button4", 10, 72, 75, 25, 0)

GUISetState(@SW_SHOW)

_GDIPlus_Startup ()
$drawGUI = GUICreate("drawer2",633,447)

; arrows related
$hPen = _GDIPlus_PenCreate (0xFF000000, 2)
$hEndCap = _GDIPlus_ArrowCapCreate (3, 6)
_GDIPlus_PenSetCustomEndCap ($hPen, $hEndCap)
; text related
$hBrush = _GDIPlus_BrushCreateSolid (0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)


$graph1 = _GDIPlus_GraphicsCreateFromHWND($drawGUI)
$IMG = _GDIPlus_BitmapCreateFromGraphics(633,447,$graph1)
$graph = _GDIPlus_ImageGetGraphicsContext($IMG)

$SaveBuff = _GDIPlus_BitmapCreateFromGraphics(633,447,$graph1)
$Savegraph = _GDIPlus_ImageGetGraphicsContext($SaveBuff)
_GDIPlus_GraphicsClear($Savegraph,0xFFFFFFFF)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_PAINT,"REPAINT")
Func REPAINT($hWnd,$Msg,$wParam,$lParam)
    If $hWnd = $drawGUI Then
        _GDIPlus_GraphicsDrawImage ($graph1, $IMG, 0, 0)
    EndIf
EndFunc
;// main loop
Do
$msg = GUIGetMsg()
$mpos = MouseGetPos()
ToolTip($mpos[0] & "," & $mpos[1])
If _IsPressed("01") then

$mpos = MouseGetPos()
Do
$mpos2 = MouseGetPos()
ToolTip($mpos2[0] & "," & $mpos2[1])
; arrows
;~ _GDIPlus_GraphicsClear($graph,0xFFFFFFFF)
_GDIPlus_GraphicsDrawImage($graph,$SaveBuff,0,0)
_GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)
_GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)
; box
_GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[0] - 21)
;~ _WinAPI_RedrawWindow("drawer", "", $tagRECT, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))
; text
$tLayout = _GDIPlus_RectFCreate (($mpos2[0] + $mpos[0]) / 2.2, $mpos[1] - 30, 100, 20)
_GDIPlus_GraphicsDrawStringEx ($graph, $mpos2[0] - $mpos[0] & " pixels", $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_GraphicsDrawImage ($graph1, $IMG, 0, 0)
Until Not _IsPressed("01")
_GDIPlus_GraphicsDrawImage ($Savegraph, $IMG, 0, 0)
;~ _GDIPlus_GraphicsDrawRect($graph, $mpos[0], $mpos[1], $mpos2[0] - $mpos[0], $mpos2[1] - $mpos[1])
;~ _GDIPlus_GraphicsDrawLine ($graph, $mpos[0] + 5, $mpos[1] - 10, $mpos2[0], $mpos[1] - 10, $hPen)
;~ _GDIPlus_GraphicsDrawLine ($graph, $mpos2[0] - 5, $mpos[1] - 10, $mpos[0], $mpos[1] - 10, $hPen)


EndIf
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose ($graph1)
_GDIPlus_GraphicsDispose ($graph)
_GDIPlus_BitmapDispose($IMG)
_GDIPlus_GraphicsDispose ($Savegraph)
_GDIPlus_BitmapDispose($SaveBuff)
_GDIPlus_Shutdown ()
Very nice Progandy, thanks for the example. XOR isn't needed!

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@progandy: I LOV U M8! :( thx! u helped me ALOT! and im not much familiar with this buffers and gdi and etc ... THX AGAIN! will metion your name if i complete what im started :mellow: /salute!


Is There A Life BEFORE Death?im stupidSaved warn logs: cheateraSmOke_N Note Added 17 January 2009 - 02:54 PM Added to warn level Posting a way to hack the registry and force sending someones desktop via TCP. Jos Note Added 25 November 2008 - 02:52 PM Added to warn level for being an impolite rookie.once a year i go bad ... what will happen in 2010??[u]Its GOOD to be BAD ... (Warlock's Succubus - World of Warcraft)[/u]

Share this post


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
Sign in to follow this  
Followers 0