AutoHotkey Community

It is currently May 26th, 2012, 1:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 67  Next
Author Message
 Post subject:
PostPosted: January 7th, 2009, 4:03 pm 
Hey tic, I have a radial menu I made that pops up from XButton1 from the mouse that works fine, but it flickers. Ive copied the code and converted it to the GDI library hoping to fix the problem, but as you can see from the script below, it still flickers, you can slow it down but it still flickers, wondering if you've ever come across this and/or have any suggestions?

Monitors refresh rate max is 75hz, changing it doesn't seem to impact this though.

Thanks in advance!

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include, Gdip.ahk

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

Gui, 1: Add, Picture, x10 y20 w400 h200 0xE vProgressBar
Gui, 1: Show, Example 9 - gdi+ progress bar

OnMessage(0x200, "WM_MOUSEMOVE")
Return


Gdip_SetProgress(ByRef Variable)
{
  global
   GuiControlGet, Pos, Pos, Variable
   GuiControlGet, hwnd, hwnd, Variable

   pBrushFront := Gdip_BrushCreateSolid(0xff00AAFF)
   pBrushBack := Gdip_BrushCreateSolid(0xFF000000)

   pBitmap := Gdip_CreateBitmap(Posw, Posh)
  G := Gdip_GraphicsFromImage(pBitmap)
  Gdip_SetSmoothingMode(G, 4)
 
  Gdip_FillPolygon(G, pBrushBack, "53,0|159,0|212,90|159,180|53,180|0,90")

  if (One = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|159,0|53,0|106,90")
  if (Two = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|159,0|212,90")
  if (Three = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|159,180|212,90")
  if (Four = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|159,180|53,180")
  if (Five = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|53,180|0,90")
  if (Six = 1)
    Gdip_FillPolygon(G, pBrushFront, "106,90|53,0|0,90")
 
   hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
;   SetImage(hwnd1, hBitmap)
   SetImage(hwnd, hBitmap)
   Gdip_DeleteBrush(pBrushFront)
   Gdip_DeleteBrush(pBrushBack)
   Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
   Return, 0
}

;#######################################################################

GuiClose:
Exit:
; gdi+ may now be shutdown
Gdip_Shutdown(pToken)
ExitApp
Return



WM_MOUSEMOVE(wParam, lParam)
{
  global
    x := lParam & 0xFFFF
    y := lParam >> 16

    cenx := 116
    ceny := 110
    x := x - cenx
   
    if (y < ceny)
      y := abs(y - ceny)
     
    if (y > ceny)
    {
      tmp := mod(y,ceny)
      y := tmp - (tmp * 2)
    }
   
    One = 0
    Two = 0
    Three = 0
    Four = 0
    Five = 0
    Six = 0
 
    if (triangle(-53,90,53,90,0,0,x,y) = 1)
      One = 1
    if (triangle(53,90,105,0,0,0,x,y) = 1)
      Two = 1
    if (triangle(105,0,53,-90,0,0,x,y) = 1)
      Three = 1
    if (triangle(53,-90,-53,-90,0,0,x,y) = 1)
      Four = 1
    if (triangle(-53,-90,-105,0,0,0,x,y) = 1)
      Five = 1
    if (triangle(-105,0,-53,90,0,0,x,y) = 1)
      Six = 1
     
  Gdip_SetProgress(ProgressBar)
  Sleep 20
  Return
}

triangle(x1,y1,x2,y2,x3,y3,xx,yy)
{
a0 := abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))
a1 := abs((x1-xx)*(y2-yy)-(x2-xx)*(y1-yy))
a2 := abs((x2-xx)*(y3-yy)-(x3-xx)*(y2-yy))
a3 := abs((x3-xx)*(y1-yy)-(x1-xx)*(y3-yy))

return (abs(a1+a2+a3-a0) <= 1/256)
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 5:53 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
@throgorss
I hope you get the help you need;
Your code snippet brings the words ''great potential'' to mind.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 6:58 pm 
I have the working one that I use, you can see where to change the Run commands to open whatever you want after clicking.

[url]
http://www.dev-x.org/scripts/RadialMenu.zip
[/url]

Its really friggen bloated with junk as I tried everything possible to keep the flicker as non existant as possible. It used to work flawlessly =\

Change XButton1 to whatever you want to show to pop up the menu on top of the mouse. You could even use guestures to bring it up =)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 7:04 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
This is throgorss

Couldnt figure out my username that went with my email lol, so i made a new one.

The file to launch is radial.ahk in the zip above


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 7:27 am 
Tic & Everyone -- wonderful examples here. Thanks for this forum.

Please let me ask, ... I want to draw a 25 pixel thick straight line with rounded ends. I am not shure how to do this. Could someone pls show me an example of how to? :D Have wonderful day.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 4:28 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
Ed3C wrote:
Tic & Everyone -- wonderful examples here. Thanks for this forum.

Please let me ask, ... I want to draw a 25 pixel thick straight line with rounded ends. I am not shure how to do this. Could someone pls show me an example of how to? :D Have wonderful day.


Altered from tutorial 1

Code:
; gdi+ ahk tutorial 1 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to draw a single ellipse and rectangle to the screen

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 600, Height := 400

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a slightly transparent (66) blue brush (ARGB = Transparency, red, green, blue) to draw a rectangle
pBrush := Gdip_BrushCreateSolid(0xFF0000ff)

; Fill the graphics of the bitmap with a rectangle using the brush created
; Filling from coordinates (250,80) a rectangle of 300x200
Gdip_FillRoundedRectangle(G, pBrush, 250, 80, 25, 200, 5)

Gdip_FillRoundedRectangle(G, pBrush, 300, 80, 200, 25, 5)

pBrush := Gdip_BrushCreateSolid(0xFFff00ff)

Gdip_FillRoundedRectangle(G, pBrush, 400, 80, 25, 200, 5)

; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(pBrush)


; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)


; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)
Return

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 6:37 pm 
DevX, very good looking, and nice rounded corners you made!~

... :( :( :(

The reason for sad faces, is because, what I needed, is to be able to draw lines in any direction like x1 x2 y1 x2, ... not just only 90 and 180 degrees :)

I suppose the _DrawLine function is my only hope... but I am not good enough at math to make the ends rounded. Can Gdip_DrawLine be adapted to do this? I appreciate your effort, it looked good, but isn't versatile to rounded-ended lines drawn in xy degrees :|


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2009, 10:37 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
You made me do Trigonometry =(

It can only go so small while looking ok (maybe 10 LineWidth)

But it can go really big =D

Code:
; gdi+ ahk tutorial 1 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to draw a single ellipse and rectangle to the screen

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 600, Height := 400

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()


; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a slightly transparent (66) blue brush (ARGB = Transparency, red, green, blue) to draw a rectangle


; //////////////////////////////////////////////////////////////////////
; Change variables here                                         ////////
LineWidth = 25
LineColor := "0xFF0000FF"
x1 = 130
y1 = 240
x2 = 200
y2 = 300

; Call function here
Gdip_DrawRoundedLine(G, x1, y1, x2, y2, LineWidth, LineColor)
;                                                               ////////
; //////////////////////////////////////////////////////////////////////

; Or just do it like this
Gdip_DrawRoundedLine(G, 100, 200, 95, 100, LineWidth, 0xFFFF00FF)

Gdip_DrawRoundedLine(G, 300, 200, 250, 100, LineWidth, 0xFF00FFFF)

Gdip_DrawRoundedLine(G, 500, 200, 350, 100, LineWidth, 0xFFFFFFFF)

Gdip_DrawRoundedLine(G, 200, 200, 150, 200, LineWidth, 0xFFFF0000)

Gdip_DrawRoundedLine(G, 250, 200, 250, 170, LineWidth, 0xFFFFFF00)


; The function
Gdip_DrawRoundedLine(G, x1, y1, x2, y2, LineWidth, LineColor)
{
 
  ;EndLoc
  pBrush := Gdip_BrushCreateSolid(LineColor)
  pPen := Gdip_CreatePen(LineColor, LineWidth)
 
  ; Calculations
  Slope := (y2 -y1) / (x2 -x1)
  Angle := ((ATan(Slope)) * 180/3.14159265)
 
  DiffX := (x1 - x2) / 100
  DiffY := (y1 - y2) / 100
 
  if (x1=x2)
  {
    if (y2<y1)
    {
      tmp := y1
      y1 := y2
      y2 := tmp
    }
    Pie1Angle := Angle + 180
    Pie2Angle := Angle
    PieX1 := x1 - (LineWidth / 2)
    PieY1 := y1 - (LineWidth / 2) + 1
    PieX2 := x2 - (LineWidth / 2)
    PieY2 := y2 - (LineWidth / 2) - 1
    GoTo, ContinueHere
  }
  if (y1=y2)
  {
    if (x2<x1)
    {
      tmp := x1
      x1 := x2
      x2 := tmp
    }
    Pie1Angle := Angle + 90
    Pie2Angle := Angle + 270
    PieX1 := x1 - (LineWidth / 2) + 1
    PieY1 := y1 - (LineWidth / 2)
    PieX2 := x2 - (LineWidth / 2) - 1
    PieY2 := y2 - (LineWidth / 2)
    GoTo, ContinueHere
  }
  if ((x1 > x2) && (y1 > y2))
  {
    Pie1Angle := Angle + 270
    Pie2Angle := Angle + 90
    PieX1 := x1 - (LineWidth / 2) - DiffX
    PieY1 := y1 - (LineWidth / 2) - DiffY
    PieX2 := x2 - (LineWidth / 2) + DiffX
    PieY2 := y2 - (LineWidth / 2) + DiffY
    GoTo, ContinueHere
  }
  if ((x1 > x2) && (y1 < y2))
  {
    Pie1Angle := Angle + 270
    Pie2Angle := Angle + 90
    PieX1 := x1 - (LineWidth / 2) - DiffX
    PieY1 := y1 - (LineWidth / 2) - DiffY
    PieX2 := x2 - (LineWidth / 2) + DiffX
    PieY2 := y2 - (LineWidth / 2) + DiffY
    GoTo, ContinueHere
  }
  if ((x1 < x2) && (y1 > y2))
  {
    Pie1Angle := Angle + 90
    Pie2Angle := Angle + 270
    PieX1 := x1 - (LineWidth / 2) - DiffX
    PieY1 := y1 - (LineWidth / 2) - DiffY
    PieX2 := x2 - (LineWidth / 2) + DiffX
    PieY2 := y2 - (LineWidth / 2) + DiffY
    GoTo, ContinueHere
  }
  if ((x1 < x2) && (y1 < y2))
  {
    Pie1Angle := Angle + 90
    Pie2Angle := Angle + 270
    PieX1 := x1 - (LineWidth / 2) - DiffX
    PieY1 := y1 - (LineWidth / 2) - DiffY
    PieX2 := x2 - (LineWidth / 2) + DiffX
    PieY2 := y2 - (LineWidth / 2) + DiffY
    GoTo, ContinueHere
  }
 
  ContinueHere:
  Gdip_DrawLine(G, pPen, x1, y1, x2, y2)
 
  Gdip_FillPie(G, pBrush, PieX1, PieY1, LineWidth, LineWidth, Pie1Angle, 180)
  Gdip_FillPie(G, pBrush, PieX2, PieY2, LineWidth, LineWidth, Pie2Angle, 180)
 
  Gdip_DeletePen(pPen)
  Gdip_DeleteBrush(pBrush)
}




; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)


; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)
Return

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

#End::Reload


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2009, 11:03 am 
YOU ARE SUCH A GENIUS ;)

Very good, and it works greeat! :) Have wonderful day and thank you for your trig mind! ~ED


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2009, 3:31 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
The function can be shortened if we use Gdip_DrawEllipse:
Code:
; The function
Gdip_DrawRoundedLine(G, x1, y1, x2, y2, LineWidth, LineColor)
{
  pPen := Gdip_CreatePen(LineColor, LineWidth)
  Gdip_DrawLine(G, pPen, x1, y1, x2, y2)
  Gdip_DeletePen(pPen)

  pPen := Gdip_CreatePen(LineColor, LineWidth/2)
  Gdip_DrawEllipse(G, pPen, x1-LineWidth/4, y1-LineWidth/4, LineWidth/2, LineWidth/2)
  Gdip_DrawEllipse(G, pPen, x2-LineWidth/4, y2-LineWidth/4, LineWidth/2, LineWidth/2)
  Gdip_DeletePen(pPen)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2009, 5:23 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
Yea I knew that *walks away*

Was more of "I bet I could get this to work" type of thing =\


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 7:17 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
I bet nobody's gonna make it work in Win9x...

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2009, 3:15 pm 
Offline

Joined: January 7th, 2009, 7:03 pm
Posts: 43
Not likely, no testing environment at the moment =\


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2009, 3:32 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Drugwash wrote:
I bet nobody's gonna make it work in Win9x...


Nope....

MSDN wrote:
UpdateLayeredWindow

.......

Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 2000


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2009, 4:02 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
I know, but it doesn't have to use layers.

Dunno what the reason is yet but no GDI+ code presented in this topic would run (correctly) in my 98SE, not even the progressbar example - that one works once in two-three dozen tries and often it displays random pieces of graphics from other applications as if some function were using a bad memory pointer.

Can't focus on these issues right now since I have private (family-related) matters to attend to.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: c0ntinuity, Klark92 and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group