Jump to content

_GDIPlus_GraphicsDrawCurve not drawing with high number of arrays


Recommended Posts

Here is the Code

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
    Local $hGUI, $hGraphic, $aPoints[8][2]
    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)

    ; Draw a cardinal spline
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $aPoints=_ArrayPoints(10,10,0,0.0001)
    _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoints)
GUISetState()
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_Main
;Local $x=_ArrayPoints(10,10,0)
Func _ArrayPoints($sHeight,$iX,$iY,$__Add,$sStep=1)
Local $sArray[Number(10^(StringLen(StringMid($__Add,StringInStr($__Add,'.',2)+1))+1))+2][2],$__X=$iX,$__Y=$iY
$sArray[0][0]=0
If $iY>$sHeight Then
  $sStep=-1
Else
  $sStep=1
EndIf
While 1
  If $iY>=$sHeight+$__Add Then ExitLoop
  ConsoleWrite('Y:'&$iY)
  ConsoleWrite('   X:'&$iX&@CRLF)
  $sArray[0][0]+=1
  $sArray[$sArray[0][0]][0]=$iX
  If $iY< $sHeight/2 Then
   $iX=Round($iX+$__Add,Number(StringLen(StringMid($__Add,StringInStr($__Add,'.',2)+1))))
  Else
   $iX=Round($iX-$__Add,Number(StringLen(StringMid($__Add,StringInStr($__Add,'.',2)+1))))
  EndIf
  $sArray[$sArray[0][0]][1]=$iY
  $iY=Round($iY+$__Add,Number(StringLen(StringMid($__Add,StringInStr($__Add,'.',2)+1))))
WEnd
ConsoleWrite('Total Array:'&$sArray[0][0]&@CRLF)
Return $sArray
EndFunc

Basically i want to make a Figure like

..____

( ____)

to make the curve structure very smooth i made a Function which can make a Array of very fine X Y coordinates using Float numbers

But nothing is showing in the GUI

.................................................................. ___ ........................... ____

When i tried with Integers i got a Figure <___> rather than this ( ____) therefore i was forced to use Floats

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Hi

first of all you have to use a Pen to draw a curve: _GDIPlus_PenCreate

and you should use a backbuffer-system to keep the graphics on the GUI

GDI+ curves are cardinal splines;

You only have to define 3 Points for your curve

The original DrawCurve-function converts your float-values to integer: "GdipDrawCurveI"

use GdipDrawCurve2 instead:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $iWidth = 400
Global $iHeight = 300
_GDIPlus_Startup()
Global $hGUI = GUICreate("GDI+", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
Global $hPen_Red = _GDIPlus_PenCreate(0xFFFF0000)
Global $hPen_Green = _GDIPlus_PenCreate(0xFF00FF00)
Global $tCurve = DllStructCreate("float[6];")
DllStructSetData($tCurve, 1, 10, 1)
DllStructSetData($tCurve, 1, 10, 2)
DllStructSetData($tCurve, 1, 110, 3)
DllStructSetData($tCurve, 1, 110, 4)
DllStructSetData($tCurve, 1, 10, 5)
DllStructSetData($tCurve, 1, 210, 6)
DllCall($ghGDIPDll, "uint", "GdipDrawCurve2", "hwnd", $hGfxBuffer, "hwnd", $hPen_Red, "ptr", DllStructGetPtr($tCurve), "int", 3, "float", 0)
DllCall($ghGDIPDll, "uint", "GdipDrawCurve2", "hwnd", $hGfxBuffer, "hwnd", $hPen_Green, "ptr", DllStructGetPtr($tCurve), "int", 3, "float", 0.5)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
GUISetState()

While Sleep(100)
WEnd

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func _Exit()
_GDIPlus_PenDispose($hPen_Red)
_GDIPlus_PenDispose($hPen_Green)
_GDIPlus_GraphicsDispose($hGfxBuffer)
_GDIPlus_BitmapDispose($hBmpBuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndFunc   ;==>_Exit

E

Link to comment
Share on other sites

To complete the "keep the graphics on the GUI" part, add GUISetOnEvent($GUI_EVENT_RESTORE, "WM_PAINT") to the code.

Btw, have a look here: http://www.autoitscript.com/forum/index.php?showtopic=97362

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thnx for the link UEZ thats what I wanted

and

Thnx Eucalyptus for the Script

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...