RepublicCommando Posted February 17, 2015 Posted February 17, 2015 (edited) My code is at the bottom (didn't want to spam you initially )GDIPlus works great, with the examples, but in my code I can't seem to get my Editor graphics rendering. The idea is that you-Create a container class object (AutoItObject).-Object is put in an array of container objects.-GDI Graphics update when "Editor" gui is shown.-Graphical representation of objects are drawn based on the container objects array. The Problem is that I cannot figure out whymy graphics are not rendering on the child GUI("Editor").I suspect that it's something about my array of container class objects (I dislike how arrays work in autoit greatly..), but I wouldn't know since I stink with them. I know the code is a bit messy, I'll worry about cleaning up stuff when I get this thing rendering and create some sort of collision system on the GDI graphics so the user can select objects/containers in real time.expandcollapse popup#include <EditConstants.au3> ;Should technically be included in GUIConstantsEx #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> ;For rendering graphs/charts and stuff #include "includes/AutoItObject.au3" ;AutoIt Object package #Region GUI $GUIMain = GUICreate("xBudget", 278, 332, 192, 124) $GUIMain_Menu_Budget = GUICtrlCreateMenu("Budget") $GUIMain_Menu_Budget_New = GUICtrlCreateMenuItem("New Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Load = GUICtrlCreateMenuItem("Load Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Save = GUICtrlCreateMenuItem("Save Budget"&@TAB&"Ctrl+S", $GUIMain_Menu_Budget) $GUIMain_Menu_Edit = GUICtrlCreateMenu("Edit") $GUIMain_Menu_Editor = GUICtrlCreateMenuItem("Editor", $GUIMain_Menu_Edit) $GUIMain_Menu_Data = GUICtrlCreateMenu("Data") $GUIMain_Menu_Data_Excel = GUICtrlCreateMenuItem("Excel", $GUIMain_Menu_Data) GUICtrlSetState(-1, $GUI_DISABLE) $GUIMain_Menu_Data_Txt = GUICtrlCreateMenuItem("Text", $GUIMain_Menu_Data) $GUIMain_BudgetSummary = GUICtrlCreateGroup("Budget Summary", 8, 8, 265, 257) $GUIMain_BudgetSum_Edit = GUICtrlCreateEdit("", 16, 24, 249, 209, BitOR($ES_WANTRETURN,$WS_VSCROLL), 0) GUICtrlSetData(-1, StringFormat("Name: No solution loaded...\r\nTotal Funds: N/A\r\n--\r\nTotal Input Funds: 0.0$\r\nTotal Input Members: 0\r\n--\r\nTotal Take-Away: 0.0$\r\nTotal Take-Away Members: 0\r\n--\r\nTotal Containers: 0\r\nContainers Intrest Input: 0.0$\r\nContainers Intrest Take-Away: 0.0$\r\nExtra Funds: 0.0$")) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlSetCursor (-1, 0) $GUIMain_SumCopy = GUICtrlCreateButton("Copy To Clipboard", 16, 240, 99, 17) $GUIMain_Calc = GUICtrlCreateButton("Recalculate", 120, 240, 75, 17) $GUIMain_Rprt = GUICtrlCreateButton("Report", 200, 240, 59, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $GUIMain_Editors = GUICtrlCreateButton("Editor", 8, 272, 123, 25) Dim $GUIMain_AccelTable[1][2] = [["^s", $GUIMain_Menu_Budget_Save]] GUISetAccelerators($GUIMain_AccelTable) GUISetState(@SW_SHOW, $GUIMain) #EndRegion End GUI #Region Editor GUI $GUI_Editor = GUICreate("Editor", 278, 332, 192, 124) $GUI_Editor_IsShown = False $GUI_Editor_Menu_New = GUICtrlCreateMenu("New") $GUI_Editor_Menu_New_Container = GUICtrlCreateMenuItem("Container",$GUI_Editor_Menu_New) $GUI_Editor_Menu_New_Pipe = GUICtrlCreateMenuItem("Pipe",$GUI_Editor_Menu_New) GUISetState(@SW_HIDE, $GUI_Editor) #EndRegion _AutoItObject_Startup() _GDIPlus_Startup() Global $aContainers[1] Local $gEditor = _GDIPlus_GraphicsCreateFromHWND($GUI_Editor) _GDIPlus_GraphicsSetSmoothingMode($gEditor, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $gPen = _GDIPlus_PenCreate(0xFFA08080, 2) Func _Budget_New() ;Create a new Budget EndFunc Func _Budget_Load() ;Load a Budget $fName = FileOpenDialog("Load", @ScriptDir, "All (*.*)|xBudget (*.xBdgt)") EndFunc Func _Budget_Save() ;Save a Budget EndFunc Func App_Exit() ;Free up resources _GDIPlus_GraphicsDispose($gEditor) _GDIPlus_PenDispose($gPen) _GDIPlus_Shutdown() _GDIPlus_GraphicsClear($gEditor) GUIDelete($GUI_Editor) GUIDelete($GUIMain) Exit EndFunc Func Container() Local $oClass = _AutoItObject_Class() With $oClass .AddMethod("AddPipe", "New_Pipe") .AddMethod("Simulate", "Simulate") .AddMethod("MoveXY", "Move_Container") .AddProperty("PositionX", $ELSCOPE_PUBLIC, 20) ;Position X on the Editor GUI .AddProperty("PositionY", $ELSCOPE_PUBLIC, 20) ;Position Y on the Editor GUI .AddProperty("Label", $ELSCOPE_PUBLIC, "Label") ;User defined label (e.x.: "My Wallet", "Bank Of America Account 1", "Employment Income", "Rent", etc) .AddProperty("InfiniteFunds", $ELSCOPE_PUBLIC, 0) ;0=N/A, 1=InfiniteOutput, 2=InfiniteInput (Employment would be 1, rent would be 2) .AddProperty("Funds", $ELSCOPE_PUBLIC, 0) ;Funds that this container contains (can be negative) .AddProperty("IntrestIn", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest to gain per simulation (like a mutual fund) .AddProperty("IntrestOut", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest take-away per simulation (like a loan) EndWith Return $oClass.Object ;Global $oContainer = Container() creates a new object EndFunc Func Move_Container($oSelf, $x, $y) With $oSelf .PositionX = $x .PositionY = $y EndWith EndFunc Func _New_Container() Local $oContainer = Container() $aLen = UBound($aContainers) Dim $aContainers[$aLen+1] = [$oContainer] ;I suspect the problem is here, since I don't know how arrays work very well in autoit MsgBox(0,"New Container", String($aContainers[$aLen+1]) & "was created") EndFunc Func New_Pipe() EndFunc Func Simulate() ;Simulates a turn of container flow EndFunc Func EditorUpdate() ;Updates editor graphics based on object data ;_GDIPlus_GraphicsClear($gEditor, 0xFFFFFF) For $i=1 To $i > UBound($aContainers) Step 1 _GDIPlus_GraphicsDrawRect($gEditor,$aContainers[$i].PositionX,$aContainers[$i].PositionY,$aContainers[$i].X + 40,$aContainers[$i].X + 12) Next EndFunc While 1 $nMsg = GUIGetMsg() If $GUI_Editor_IsShown Then EditorUpdate() EndIf Switch $nMsg Case $GUI_EVENT_CLOSE App_Exit() Case $GUIMain_Menu_Budget_Load _Budget_Load() Case $GUIMain_Menu_Editor If $GUI_Editor_IsShown Then GUISetState(@SW_HIDE, $GUI_Editor) $GUI_Editor_IsShown = False Else GUISetState(@SW_SHOW, $GUI_Editor) $GUI_Editor_IsShown = True EndIf Case $GUI_Editor_Menu_New_Container _New_Container() EndSwitch WEndEdit- There are no syntax errors btw, just no desired results. Edited February 17, 2015 by RepublicCommando
aRandomDude Posted February 18, 2015 Posted February 18, 2015 Your problem is you are declaring your handles to the GDI+ Graphics locally, Local $gEditor = _GDIPlus_GraphicsCreateFromHWND($GUI_Editor) _GDIPlus_GraphicsSetSmoothingMode($gEditor, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $gPen = _GDIPlus_PenCreate(0xFFA08080, 2) should be changed to: Global $gEditor = _GDIPlus_GraphicsCreateFromHWND($GUI_Editor) _GDIPlus_GraphicsSetSmoothingMode($gEditor, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Global $gPen = _GDIPlus_PenCreate(0xFFA08080, 2) If you want to use a previously declared variable in a function the variable needs to be declared globally unless you pass it in as a parameter.
RepublicCommando Posted February 18, 2015 Author Posted February 18, 2015 (edited) Thanks for the reply. I did that and still problems with the array: ==> Subscript used on non-accessible variable.: _GDIPlus_GraphicsDrawRect($gEditor,$aContainers[$i].PositionX,$aContainers[$i].PositionY,$aContainers[$i].PositionX + 40,$aContainers[$i].PositionY + 12) _GDIPlus_GraphicsDrawRect($gEditor,$aContainers^ ERROR I wish there were another way to handle all of the objects without arrays, they are such a pain in the rear.. expandcollapse popup#include <EditConstants.au3> ;Should technically be included in GUIConstantsEx #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> ;For rendering graphs/charts and stuff #include "includes/AutoItObject.au3" ;AutoIt Object package #Region GUI $GUIMain = GUICreate("xBudget", 278, 332, 192, 124) $GUIMain_Menu_Budget = GUICtrlCreateMenu("Budget") $GUIMain_Menu_Budget_New = GUICtrlCreateMenuItem("New Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Load = GUICtrlCreateMenuItem("Load Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Save = GUICtrlCreateMenuItem("Save Budget"&@TAB&"Ctrl+S", $GUIMain_Menu_Budget) $GUIMain_Menu_Edit = GUICtrlCreateMenu("Edit") $GUIMain_Menu_Editor = GUICtrlCreateMenuItem("Editor", $GUIMain_Menu_Edit) $GUIMain_Menu_Data = GUICtrlCreateMenu("Data") $GUIMain_Menu_Data_Excel = GUICtrlCreateMenuItem("Excel", $GUIMain_Menu_Data) GUICtrlSetState(-1, $GUI_DISABLE) $GUIMain_Menu_Data_Txt = GUICtrlCreateMenuItem("Text", $GUIMain_Menu_Data) $GUIMain_BudgetSummary = GUICtrlCreateGroup("Budget Summary", 8, 8, 265, 257) $GUIMain_BudgetSum_Edit = GUICtrlCreateEdit("", 16, 24, 249, 209, BitOR($ES_WANTRETURN,$WS_VSCROLL), 0) GUICtrlSetData(-1, StringFormat("Name: No solution loaded...\r\nTotal Funds: N/A\r\n--\r\nTotal Input Funds: 0.0$\r\nTotal Input Members: 0\r\n--\r\nTotal Take-Away: 0.0$\r\nTotal Take-Away Members: 0\r\n--\r\nTotal Containers: 0\r\nContainers Intrest Input: 0.0$\r\nContainers Intrest Take-Away: 0.0$\r\nExtra Funds: 0.0$")) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlSetCursor (-1, 0) $GUIMain_SumCopy = GUICtrlCreateButton("Copy To Clipboard", 16, 240, 99, 17) $GUIMain_Calc = GUICtrlCreateButton("Recalculate", 120, 240, 75, 17) $GUIMain_Rprt = GUICtrlCreateButton("Report", 200, 240, 59, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $GUIMain_Editors = GUICtrlCreateButton("Editor", 8, 272, 123, 25) Dim $GUIMain_AccelTable[1][2] = [["^s", $GUIMain_Menu_Budget_Save]] GUISetAccelerators($GUIMain_AccelTable) GUISetState(@SW_SHOW, $GUIMain) #EndRegion End GUI #Region Editor GUI $GUI_Editor = GUICreate("Editor", 278, 332, 192, 124) $GUI_Editor_IsShown = False $GUI_Editor_Menu_New = GUICtrlCreateMenu("New") $GUI_Editor_Menu_New_Container = GUICtrlCreateMenuItem("Container",$GUI_Editor_Menu_New) $GUI_Editor_Menu_New_Pipe = GUICtrlCreateMenuItem("Pipe",$GUI_Editor_Menu_New) GUISetState(@SW_HIDE, $GUI_Editor) #EndRegion _AutoItObject_Startup() _GDIPlus_Startup() Global $aContainers Global $gEditor = _GDIPlus_GraphicsCreateFromHWND($GUI_Editor) _GDIPlus_GraphicsSetSmoothingMode($gEditor, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Global $gPen = _GDIPlus_PenCreate(0xFFA08080, 2) Func _Budget_New() ;Create a new Budget EndFunc Func _Budget_Load() ;Load a Budget $fName = FileOpenDialog("Load", @ScriptDir, "All (*.*)|xBudget (*.xBdgt)") EndFunc Func _Budget_Save() ;Save a Budget EndFunc Func App_Exit() ;Free up resources _GDIPlus_GraphicsDispose($gEditor) _GDIPlus_PenDispose($gPen) _GDIPlus_Shutdown() _GDIPlus_GraphicsClear($gEditor) GUIDelete($GUI_Editor) GUIDelete($GUIMain) Exit EndFunc Func Container() Local $oClass = _AutoItObject_Class() With $oClass .AddMethod("AddPipe", "New_Pipe") .AddMethod("Simulate", "Simulate") .AddMethod("MoveXY", "Move_Container") .AddProperty("PositionX", $ELSCOPE_PUBLIC, 20) ;Position X on the Editor GUI .AddProperty("PositionY", $ELSCOPE_PUBLIC, 20) ;Position Y on the Editor GUI .AddProperty("Label", $ELSCOPE_PUBLIC, "Label") ;User defined label (e.x.: "My Wallet", "Bank Of America Account 1", "Employment Income", "Rent", etc) .AddProperty("InfiniteFunds", $ELSCOPE_PUBLIC, 0) ;0=N/A, 1=InfiniteOutput, 2=InfiniteInput (Employment would be 1, rent would be 2) .AddProperty("Funds", $ELSCOPE_PUBLIC, 0) ;Funds that this container contains (can be negative) .AddProperty("IntrestIn", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest to gain per simulation (like a mutual fund) .AddProperty("IntrestOut", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest take-away per simulation (like a loan) EndWith Return $oClass.Object ;Global $oContainer = Container() creates a new object EndFunc Func Move_Container($oSelf, $x, $y) With $oSelf .PositionX = $x .PositionY = $y EndWith EndFunc Func _New_Container() Local $oContainer = Container() Dim $aContainers[UBound($aContainers)+1] = [$oContainer] Return $oContainer EndFunc Func New_Pipe() EndFunc Func Simulate() ;Simulates a turn of container flow EndFunc Func EditorUpdate() ;Updates editor graphics based on object data ;_GDIPlus_GraphicsClear($gEditor, 0xFFFFFF) For $i = 0 To $i > UBound($aContainers) Step 1 _GDIPlus_GraphicsDrawRect($gEditor,$aContainers[$i].PositionX,$aContainers[$i].PositionY,$aContainers[$i].PositionX + 40,$aContainers[$i].PositionY + 12) Next EndFunc While 1 $nMsg = GUIGetMsg() If $GUI_Editor_IsShown Then EditorUpdate() EndIf Switch $nMsg Case $GUI_EVENT_CLOSE App_Exit() Case $GUIMain_Menu_Budget_Load _Budget_Load() Case $GUIMain_Menu_Editor If $GUI_Editor_IsShown Then GUISetState(@SW_HIDE, $GUI_Editor) $GUI_Editor_IsShown = False Else GUISetState(@SW_SHOW, $GUI_Editor) $GUI_Editor_IsShown = True EndIf Case $GUI_Editor_Menu_New_Container _New_Container() EndSwitch WEnd Maybe if someone could tell me how to add to the column size and add it's value (I've tried everything I can find). So far I'm not a huge fan of how little information is produced for me to debug my code.. It sounds like autoit is just saying "Uhh It doesn't work.." Edited February 18, 2015 by RepublicCommando
RepublicCommando Posted February 18, 2015 Author Posted February 18, 2015 Aha, I found a solution: http://stackoverflow.com/questions/23816816/autoit-how-to-build-dynamic-array-and-loop-through-it This seems to solve the array issues, but I still can't get the boxes to render.. Any GDI geniuses out there? expandcollapse popup#include <EditConstants.au3> ;Should technically be included in GUIConstantsEx #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> ;For rendering graphs/charts and stuff #include "includes/AutoItObject.au3" ;AutoIt Object package #Region GUI $GUIMain = GUICreate("xBudget", 278, 332, 192, 124) $GUIMain_Menu_Budget = GUICtrlCreateMenu("Budget") $GUIMain_Menu_Budget_New = GUICtrlCreateMenuItem("New Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Load = GUICtrlCreateMenuItem("Load Budget", $GUIMain_Menu_Budget) $GUIMain_Menu_Budget_Save = GUICtrlCreateMenuItem("Save Budget"&@TAB&"Ctrl+S", $GUIMain_Menu_Budget) $GUIMain_Menu_Edit = GUICtrlCreateMenu("Edit") $GUIMain_Menu_Editor = GUICtrlCreateMenuItem("Editor", $GUIMain_Menu_Edit) $GUIMain_Menu_Data = GUICtrlCreateMenu("Data") $GUIMain_Menu_Data_Excel = GUICtrlCreateMenuItem("Excel", $GUIMain_Menu_Data) GUICtrlSetState(-1, $GUI_DISABLE) $GUIMain_Menu_Data_Txt = GUICtrlCreateMenuItem("Text", $GUIMain_Menu_Data) $GUIMain_BudgetSummary = GUICtrlCreateGroup("Budget Summary", 8, 8, 265, 257) $GUIMain_BudgetSum_Edit = GUICtrlCreateEdit("", 16, 24, 249, 209, BitOR($ES_WANTRETURN,$WS_VSCROLL), 0) GUICtrlSetData(-1, StringFormat("Name: No solution loaded...\r\nTotal Funds: N/A\r\n--\r\nTotal Input Funds: 0.0$\r\nTotal Input Members: 0\r\n--\r\nTotal Take-Away: 0.0$\r\nTotal Take-Away Members: 0\r\n--\r\nTotal Containers: 0\r\nContainers Intrest Input: 0.0$\r\nContainers Intrest Take-Away: 0.0$\r\nExtra Funds: 0.0$")) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlSetCursor (-1, 0) $GUIMain_SumCopy = GUICtrlCreateButton("Copy To Clipboard", 16, 240, 99, 17) $GUIMain_Calc = GUICtrlCreateButton("Recalculate", 120, 240, 75, 17) $GUIMain_Rprt = GUICtrlCreateButton("Report", 200, 240, 59, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $GUIMain_Editors = GUICtrlCreateButton("Editor", 8, 272, 123, 25) Dim $GUIMain_AccelTable[1][2] = [["^s", $GUIMain_Menu_Budget_Save]] GUISetAccelerators($GUIMain_AccelTable) GUISetState(@SW_SHOW, $GUIMain) #EndRegion End GUI #Region Editor GUI $GUI_Editor = GUICreate("Editor", 278, 332, 192, 124) $GUI_Editor_IsShown = False $GUI_Editor_Menu_New = GUICtrlCreateMenu("New") $GUI_Editor_Menu_New_Container = GUICtrlCreateMenuItem("Container",$GUI_Editor_Menu_New) $GUI_Editor_Menu_New_Pipe = GUICtrlCreateMenuItem("Pipe",$GUI_Editor_Menu_New) GUISetState(@SW_HIDE, $GUI_Editor) #EndRegion _AutoItObject_Startup() _GDIPlus_Startup() Global $aContainers = "" Global $gEditor = _GDIPlus_GraphicsCreateFromHWND($GUI_Editor) _GDIPlus_GraphicsSetSmoothingMode($gEditor, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Global $gPen = _GDIPlus_PenCreate(0xFFA08080, 2) Func App_Exit() ;Free up resources _GDIPlus_GraphicsDispose($gEditor) _GDIPlus_PenDispose($gPen) _GDIPlus_Shutdown() _GDIPlus_GraphicsClear($gEditor) GUIDelete($GUI_Editor) GUIDelete($GUIMain) Exit EndFunc Func Container() Local $oClass = _AutoItObject_Class() With $oClass .AddMethod("AddPipe", "New_Pipe") .AddMethod("Simulate", "Simulate") .AddMethod("MoveXY", "Move_Container") .AddProperty("PositionX", $ELSCOPE_PUBLIC, 20) ;Position X on the Editor GUI .AddProperty("PositionY", $ELSCOPE_PUBLIC, 20) ;Position Y on the Editor GUI .AddProperty("Label", $ELSCOPE_PUBLIC, "Label") ;User defined label (e.x.: "My Wallet", "Bank Of America Account 1", "Employment Income", "Rent", etc) .AddProperty("InfiniteFunds", $ELSCOPE_PUBLIC, 0) ;0=N/A, 1=InfiniteOutput, 2=InfiniteInput (Employment would be 1, rent would be 2) .AddProperty("Funds", $ELSCOPE_PUBLIC, 0) ;Funds that this container contains (can be negative) .AddProperty("IntrestIn", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest to gain per simulation (like a mutual fund) .AddProperty("IntrestOut", $ELSCOPE_PUBLIC, 0) ;Amnt of intrest take-away per simulation (like a loan) EndWith Return $oClass.Object ;Global $oContainer = Container() creates a new object EndFunc Func Move_Container($oSelf, $x, $y) With $oSelf .PositionX = $x .PositionY = $y EndWith EndFunc Func _New_Container() Local $oContainer = Container() If IsObj($oContainer) Then $aContainers = $aContainers & "|" & $oContainer ;Adds container to global array Return $oContainer Else Return 0 EndIf EndFunc Func New_Pipe() EndFunc Func Simulate() ;Simulates a turn of container flow EndFunc Func EditorUpdate() ;Updates editor graphics based on object data $aC = StringSplit($aContainers,"|") If IsArray($aC) Then $iMax = UBound($aC) For $i = 0 To $iMax - 1 If IsObj($aC[$i]) Then _GDIPlus_GraphicsDrawRect($gEditor,$aC[$i].PositionX,$aC[$i].PositionY,$aC[$i].PositionX + 40,$aC[$i].PositionY + 12) EndIf Next EndIf EndFunc While 1 $nMsg = GUIGetMsg() If $GUI_Editor_IsShown Then EditorUpdate() EndIf Switch $nMsg Case $GUI_EVENT_CLOSE App_Exit() Case $GUIMain_Menu_Editor If $GUI_Editor_IsShown Then GUISetState(@SW_HIDE, $GUI_Editor) $GUI_Editor_IsShown = False Else GUISetState(@SW_SHOW, $GUI_Editor) $GUI_Editor_IsShown = True EndIf Case $GUI_Editor_Menu_New_Container _New_Container() EndSwitch WEnd I wouldn't still be doing this if I didn't feel like I was really close to finishing successful. Technically, I should be doing this sort of thing in C#
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now