Heron Posted April 15, 2009 Share Posted April 15, 2009 I have some questions for the advanced users of AutoIT. I'm trying to write a kind of Graph function. My questions: - is it possible to write text vertical AND bottom up (so bow head left to read)? - when I focus my window (after minimize or something) my text is gone, why? (do I have to repaint each time?) Thanks already Link to comment Share on other sites More sharing options...
ResNullius Posted April 15, 2009 Share Posted April 15, 2009 I have some questions for the advanced users of AutoIT. I'm trying to write a kind of Graph function.My questions:- is it possible to write text vertical AND bottom up (so bow head left to read)?- when I focus my window (after minimize or something) my text is gone, why? (do I have to repaint each time?)Thanks alreadyVertical text solution here: http://www.autoitscript.com/forum/index.ph...st&p=649044 Link to comment Share on other sites More sharing options...
Heron Posted April 16, 2009 Author Share Posted April 16, 2009 Vertical text solution here: http://www.autoitscript.com/forum/index.ph...st&p=649044Thanks! I didn't find it myself, it's kind of hidden. Link to comment Share on other sites More sharing options...
Heron Posted April 16, 2009 Author Share Posted April 16, 2009 Thanks! I didn't find it myself, it's kind of hidden. I took the example and simplified it to the following. It works ok but only for vertical text bottom up (as I was looking for). I had to wrap the actual drawing in a function for as the x, y coordinates are rotated as well. Strange thing I noticed however: it works but the exclamation mark is printed before the text??? Any idea? #include <GDIPlus.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> $GUI = GUICreate("GDI+",400,400) GUISetState() $graph = GUICtrlCreateGraphic(0, 0, 400, 400) ;point GDI graphic to GUICtrlCreateGraphic with 270 DEG rotation _GDIPlus_Startup() $hGraph = ControlGetHandle($GUI, "", $graph) $GDI = _GDIPlus_GraphicsCreateFromHWND($hGraph) $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, 270, False) _GDIPlus_GraphicsSetTransform($GDI, $hMatrix) Vstring("Hello world!", 100, 150, 12) While 1 $MSG = GUIGetMsg() If $MSG = -3 Then Exit Sleep(20) WEnd Func VString($txt, $x, $y, $size) ;draw string with x,y = upper left corner _GDIPlus_GraphicsDrawString($GDI, $txt, -$y, $x, "Arial", $size, 0x0001) EndFunc Link to comment Share on other sites More sharing options...
Malkey Posted April 17, 2009 Share Posted April 17, 2009 I took the example and simplified it to the following. It works ok but only for vertical text bottom up (as I was looking for). I had to wrap the actual drawing in a function for as the x, y coordinates are rotated as well. Strange thing I noticed however: it works but the exclamation mark (!) is printed before the text??? Any idea? #include <GDIPlus.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> $GUI = GUICreate("GDI+",400,400) GUISetState() $graph = GUICtrlCreateGraphic(0, 0, 400, 400) ;point GDI graphic to GUICtrlCreateGraphic with 270 DEG rotation _GDIPlus_Startup() $hGraph = ControlGetHandle($GUI, "", $graph) $GDI = _GDIPlus_GraphicsCreateFromHWND($hGraph) $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, 270, False) _GDIPlus_GraphicsSetTransform($GDI, $hMatrix) Vstring("Hello world!", 100, 150, 12) While 1 $MSG = GUIGetMsg() If $MSG = -3 Then Exit Sleep(20) WEnd Func VString($txt, $x, $y, $size) ;draw string with x,y = upper left corner _GDIPlus_GraphicsDrawString($GDI, $txt, -$y, $x, "Arial", $size, 0x0001) EndFuncAdded formulas to calculate the initial position of the text before rotation. Now, any angle entered works. And, changed the $iFormat parameter of _GDIPlus_GraphicsDrawString to 0x0002. expandcollapse popup; #include <GDIPlus.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> Local $nAngle = 180 Local $nPI = 4 * ATan(1) $GUI = GUICreate("GDI+", 400, 400) GUISetState() $graph = GUICtrlCreateGraphic(0, 0, 400, 400) ;point GDI graphic to GUICtrlCreateGraphic with 270 DEG rotation _GDIPlus_Startup() $hGraph = ControlGetHandle($GUI, "", $graph) $GDI = _GDIPlus_GraphicsCreateFromHWND($hGraph) $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $nAngle, False) _GDIPlus_GraphicsSetTransform($GDI, $hMatrix) Vstring("Hello world!", 100, 150, 12, $nAngle) While 1 $MSG = GUIGetMsg() If $MSG = -3 Then Exit Sleep(20) WEnd Func VString($txt, $nx, $ny, $size, $nAngle) ;draw string with x,y = upper left corner ;Rotation of Coordinate Axes formulae $nXt = $nx * Cos($nAngle * $nPI / 180) + $ny * Sin($nAngle * $nPI / 180) ; $nXt - X coordinate before translation $nYt = -$nx * Sin($nAngle * $nPI / 180) + $ny * Cos($nAngle * $nPI / 180) ; $nYt - Y coordinate before translation _GDIPlus_GraphicsDrawString($GDI, $txt, $nXt, $nYt, "Arial", $size, 0x0002) EndFunc ;==>VString ; Link to comment Share on other sites More sharing options...
Heron Posted April 17, 2009 Author Share Posted April 17, 2009 Added formulas to calculate the initial position of the text before rotation. Now, any angle entered works. And, changed the $iFormat parameter of _GDIPlus_GraphicsDrawString to 0x0002. expandcollapse popup; #include <GDIPlus.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> Local $nAngle = 180 Local $nPI = 4 * ATan(1) $GUI = GUICreate("GDI+", 400, 400) GUISetState() $graph = GUICtrlCreateGraphic(0, 0, 400, 400) ;point GDI graphic to GUICtrlCreateGraphic with 270 DEG rotation _GDIPlus_Startup() $hGraph = ControlGetHandle($GUI, "", $graph) $GDI = _GDIPlus_GraphicsCreateFromHWND($hGraph) $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $nAngle, False) _GDIPlus_GraphicsSetTransform($GDI, $hMatrix) Vstring("Hello world!", 100, 150, 12, $nAngle) While 1 $MSG = GUIGetMsg() If $MSG = -3 Then Exit Sleep(20) WEnd Func VString($txt, $nx, $ny, $size, $nAngle) ;draw string with x,y = upper left corner ;Rotation of Coordinate Axes formulae $nXt = $nx * Cos($nAngle * $nPI / 180) + $ny * Sin($nAngle * $nPI / 180) ; $nXt - X coordinate before translation $nYt = -$nx * Sin($nAngle * $nPI / 180) + $ny * Cos($nAngle * $nPI / 180) ; $nYt - Y coordinate before translation _GDIPlus_GraphicsDrawString($GDI, $txt, $nXt, $nYt, "Arial", $size, 0x0002) EndFunc ;==>VString ; Great addition! Think I gonna use it. Matrix math is long ago for me, give's me headache ;-) Did you notice the strange '!' issue too? (same for @,#,$,% etc) And can you tell somethng about the dissapearing of the text after a focuschange? I'm sorry, but I've none expierience with graphics and I'm puzzled. Graphics drawn with GUICtrlSetGraphic don't have this problem and stay until a clear or exit. Link to comment Share on other sites More sharing options...
Malkey Posted April 19, 2009 Share Posted April 19, 2009 Great addition! Think I gonna use it. Matrix math is long ago for me, give's me headache ;-) Did you notice the strange '!' issue too? (same for @,#,$,% etc) And can you tell somethng about the dissapearing of the text after a focuschange? I'm sorry, but I've none expierience with graphics and I'm puzzled. Graphics drawn with GUICtrlSetGraphic don't have this problem and stay until a clear or exit.This example is possibly the easiest way to have the graphics of the GUI window, re-drawn, by actually re-drawing to the graphics object, $GDI in each loop of the While-Wend loop. There are pitfalls in using this method, which this example avoids. The other common method used to repaint the GUI when using GDI+, is by double buffering and registering a user defined function for a Windows paint Message, GUIRegisterMsg (). Examples abound on these forums. http://msdn.microsoft.com/en-us/library/ms533798(VS.85).aspx has alot of information about GDI+. The wrappers for use with AutoIt's DllCall are under the heading "GDI+ Flat API". On my xp, with the last parameter of _GDIPlus_GraphicsDrawString set to 0x002, the exclamation mark appears at the end where it is supposed to be. I hope you find this helpful. expandcollapse popup; #include <GDIPlus.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> ; http://www.autoitscript.com/forum/index.php?s=&showtopic=93289&view=findpost&p=670844 Local $nAngle = 180 Local $nPI = 4 * ATan(1) Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled $GUI = GUICreate("GDI+", 400, 400) GUISetOnEvent(-3, "_Quit") GUISetState() ;$graph = GUICtrlCreateGraphic(0, 0, 400, 400) ;point GDI graphic to GUICtrlCreateGraphic with 270 DEG rotation _GDIPlus_Startup() ;$hGraph = ControlGetHandle($GUI, "", $graph) $GDI = _GDIPlus_GraphicsCreateFromHWND($GUI) $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($hMatrix, $nAngle, False) _GDIPlus_GraphicsSetTransform($GDI, $hMatrix) While 1 Vstring("Hello world!", 100, 150, 12, $nAngle) Sleep(250) WEnd Func VString($txt, $nx, $ny, $size, $nAngle) ;draw string with x,y = upper left corner ;Rotation of Coordinate Axes formulae $nXt = $nx * Cos($nAngle * $nPI / 180) + $ny * Sin($nAngle * $nPI / 180) ; $nXt - X coordinate before translation $nYt = -$nx * Sin($nAngle * $nPI / 180) + $ny * Cos($nAngle * $nPI / 180) ; $nYt - Y coordinate before translation _GDIPlus_GraphicsDrawString($GDI, $txt, $nXt, $nYt, "Arial", $size, 0x0002) EndFunc ;==>VString Func _Quit() _GDIPlus_GraphicsDispose($GDI) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_Shutdown() Exit EndFunc ;==>_Quit ; Link to comment Share on other sites More sharing options...
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