Jump to content
Sign in to follow this  
Heron

Vertical text

Recommended Posts

Heron

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

Share this post


Link to post
Share on other sites
ResNullius

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

Vertical text solution here: http://www.autoitscript.com/forum/index.ph...st&p=649044

Share this post


Link to post
Share on other sites
Heron

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

Share this post


Link to post
Share on other sites
Malkey

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
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.

;
#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
;

Share this post


Link to post
Share on other sites
Heron

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.

;
#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.

Share this post


Link to post
Share on other sites
Malkey

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.

;
#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
;

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  

×