AutoHotkey Community

It is currently May 27th, 2012, 4:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 20, 21, 22, 23, 24, 25, 26 ... 67  Next
Author Message
 Post subject:
PostPosted: March 4th, 2010, 12:10 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
tic wrote:
If there is a problem with the rounded rectangle function, then Im not sure that just subtracting one is the solution. the reason youd see any offset of pixels will be due to the smoothing mode.


I really guess you're wrong, sorry.

Demonstration:
Code:
Width := 600, Height := 400
Gui, 1: -Caption +E0x80000 +LastFound +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to hi-speed
Gdip_SetSmoothingMode(G, 1)
; fill the window with red color
Gdip_GraphicsClear(G, 0xffff0000)
; create a blue pen, one pixel wide
pPen := Gdip_CreatePen(0xff0000ff,1)
; draw a rounded rectangle, without r
Gdip_DrawRoundedRectangle(G, pPen, 0, 0, width, height, 0)

Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc, 100, 100, Width, Height)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)


As you can see, the border is only drawn on the left and top border; not the right and bottom ones ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 12:32 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Razer wrote:
Can you also update the function Gdip_DrawRoundedRectangle with the same solution?


Here it is:
Code:
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
{
   Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
   Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
   Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
   Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
   E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w-1, h-1)
   Gdip_ResetClip(pGraphics)
   Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
   Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
   Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
   Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r)-1, y, 2*r, 2*r)
   Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r)-1, 2*r, 2*r)
   Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r)-1, y+h-(2*r)-1, 2*r, 2*r)
   Gdip_ResetClip(pGraphics)
   Return, E
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 10:39 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
I wrote a whole long explanation, but decided to delete it....basically you are putting in the incorrect x,y,w,h values. you dont need to create a whole new function to correct this. Just put in the correct values. Coordinates are measured from the upper left corner of each pixel (as is quite obvious). I will not be changing the function...it is drawing at the correct x,y,w,h currently

If you had really wanted to alter the coordinate point system, then it should be:

Code:
E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w-penwidth, h-penwidth)


and not:

Code:
E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w-1, h-1)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 5:08 am 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Yes, you're right about the pen width (I'm only using brushes or one pixel pens). I need to put GdipGetPenWidth somewhere into the modified DrawRoundedRectangle...
But, talking about the correct values, is just a matter of point of view.
I - and at least Razer - are mainly using rounded rectangle to paint the whole surface of the window. So, in our cases, having modified gdip functions make sense.
I'm talking about Razer and I, but I guess many other people are thinking "outer edge" as "width" and "height".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 11:41 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
You do bring up an interesting point Smurth...obviously you could use:

Code:
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w-PenWidth, h-PenWidth, r)


But perhaps that isnt as user friendly for some users. I personally am more comfortable passing the values as they are, but as you say perhaps many others arent. If we were to change the function, then we would either need a separate parameter passed that gives us the pen width, or have another function that works out the width. I think the best thing would be to leave it as it is, but mention it in all the tutorials. Please if anyone has any strong views on this then speak up as I do appreciate comments and suggestions for improvements as you can see by my 30 releases of it so far :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 3:18 am 
Could somebody show a demonstration on how to paste an image onto a normal gui window (with text & buttons) using Gdip?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 5:23 pm 
Offline
User avatar

Joined: October 31st, 2008, 9:39 am
Posts: 641
Location: France
check example #9, first page of this thread, you can use bitblt or setimage (you need to create an handle)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 9:30 am 
Offline

Joined: February 15th, 2010, 5:45 pm
Posts: 10
Hi Tic and Smurth, thx for your help.

I'm a little confused right now, I think I'm missing something when I try to work with a rounded rectangle with a border.
With the Smurth's version of Gdip_FillRoundedRectangle, I can now create nice rounded rectangle with gradient. But, as Tic says it's only a matter of parameters passed to its original function, I would like to have more info about the right way to create a nice rounded rectangle.

Anyway, with Smurth's or Tic's version of Gdip_DrawRoundedRectangle, I can't find a way to have a nice rounded border.

Here are my settings :

Code:
x = 100
y = 100
width = 800
height = 40
radius = 6

fill_color1 = FFFFFFFF
fill_color2 = FFD3D3D3

border_width = 1
border_color = FFC4C4C4

; ---------------------------------------
; Add the rounded rectangle with gradient
; ---------------------------------------
p_pen := Gdip_CreateLineBrush( 0, 0, 0, height, "0x" . fill_color1, "0x" . fill_color2 )
Gdip_FillRoundedRectangle( p_graphic, p_pen, x + border_width//2, y + border_width//2, width - border_width, height - border_width, radius )

; ---------------------------------------
; Add the border of the rounded rectangle
; ---------------------------------------
if ( border_width > 0 )
{
   p_pen := Gdip_CreatePen( "0x" . border_color, border_width )
   Gdip_DrawRoundedRectangle( p_graphic, p_pen, x + border_width//2, y + border_width//2, width-border_width, height-border_width, radius )
}

; ------------------------
; Delete of the p_pen tool
; ------------------------
Gdip_DeleteBrush(p_pen)



Any idea what I'm doing wrong?

Razer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 12:07 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Tic wrote:
This library can be distributed for commercial and non-commercial use and I actively encourage both. I would appreciate it if people give acknowledgement for my work and would be nice to have pasted once at the top of your script something similar to:
Thanks to tic (Tariq Porter) for his GDI+ Library
http://www.autohotkey.com/forum/viewtopic.php?t=32238
I think that saying thanks is minimum that Tic deserves, so:
Tic, thank you for your generosity and great work! And thanks to Lexikos too!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 12:23 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Thanks very much Learning one Radial Menu has come a long way!

Razer please could you post code so that it is similar to example 2 so that I can see exactly what you mean by just running the code? Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 12:33 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Hi Razer, I don't know if that would made the desired esthetic changes but here are some clues (assuming you're using the Tic version):
Code:
x = 100
y = 100
width = 800
height = 40
radius = 6

fill_color1 = FFFFFFFF
fill_color2 = FFD3D3D3

border_width = 1
border_color = FFC4C4C4

; ---------------------------------------
; Add the rounded rectangle with gradient
; ---------------------------------------
p_pen := Gdip_CreateLineBrush( 0, 0, 0, height, "0x" . fill_color1, "0x" . fill_color2 )
Gdip_FillRoundedRectangle( p_graphic, p_pen, x, y, width-border_width, height-border_width, radius )
; always free resources
Gdip_DeleteBrush(p_pen)


; ---------------------------------------
; Add the border of the rounded rectangle
; ---------------------------------------
if ( border_width > 0 )
{
   p_pen := Gdip_CreatePen( "0x" . border_color, border_width )
   Gdip_DrawRoundedRectangle( p_graphic, p_pen, x, y, width-border_width, height-border_width, radius )
Gdip_DeleteBrush(p_pen)
}





Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 1:14 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Cheers Smurth...

btw....I just thought I'd note that I made a few quick changes in all of the tutorials

Guis are created with:

Code:
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner


now, as Toolwindow has always had bugs in xp, so Im getting rid of it

Also I forgot to delete a resource :oops:

Code:
If !hFamily := Gdip_FontFamilyCreate(Font)
{
   MsgBox, 48, Font error!, The font you have specified does not exist on the system
   ExitApp
}
; Delete font family as we now know the font does exist
Gdip_DeleteFontFamily(hFamily)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 2:59 pm 
Offline

Joined: February 15th, 2010, 5:45 pm
Posts: 10
Tic, here is my code :

Code:

#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
gui_width := 1000, gui_height := 200

; 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 +OwnDialogs +Owner +AlwaysOnTop

; 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(gui_width, gui_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
p_graphic := Gdip_GraphicsFromHDC(hdc)

; --------------------------------------------------------------------------------------------------
; ##################################################################################################
; --------------------------------------------------------------------------------------------------

x := 100
y := 100
width := 800
height := 40
radius := 6

fill_color1 := "FFFFFFFF"
fill_color2 := "FFD3D3D3"

border_width := 1
border_color := "FFC4C4C4"

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

; ---------------------------------------
; Add the rounded rectangle with gradient
; ---------------------------------------
p_pen := Gdip_CreateLineBrush( 0, 0, 0, height, "0x" . fill_color1, "0x" . fill_color2 )
Gdip_FillRoundedRectangle( p_graphic, p_pen, x + border_width//2, y + border_width//2, width - border_width, height - border_width, radius )

; ------------------------
; Delete of the p_pen tool
; ------------------------
Gdip_DeleteBrush(p_pen)

; ---------------------------------------
; Add the border of the rounded rectangle
; ---------------------------------------
if ( border_width > 0 )
{
   p_pen := Gdip_CreatePen( "0x" . border_color, border_width )
   Gdip_DrawRoundedRectangle( p_graphic, p_pen, x + border_width//2, y + border_width//2, width-border_width, height-border_width, radius )
}

; ------------------------
; Delete of the p_pen tool
; ------------------------
Gdip_DeleteBrush(p_pen)

; --------------------------------------------------------------------------------------------------
; ##################################################################################################
; --------------------------------------------------------------------------------------------------

; 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, gui_width, gui_height)

; ------------------------------------------------------
; When the left mouse button is down drag the gui window
; ------------------------------------------------------
OnMessage(0x201, "gui_drag")

; 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(p_graphic)
Return

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

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


; -----------------------------
; Function used to drag the GUI
; -----------------------------
gui_drag()
{
   postmessage 0xA1, 2,,, A
}




Smurth, I've tested your code and unfortunately I have the same result. The rounded border is not quite rounded. :cry:

It's weird, because when I set a radius of 7 or higher or a radius of 4 or less it's OK. :o
But when I use a radius of 5 or 6 it's not rounded. :?

Razer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 10:50 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Razer: try to test with Gdip_SetSmoothingMode(G, 4). The not really rounded thing might have something to do with gdip, itselft...

On a last note, I recommend you to include the Gdip_DeleteBrush(p_pen) inside the last if { } to avoid trying to delete an unexisting p_pen; it might have nasty effects on a bigger project.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 12:19 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
tic, could you include the CreateCompatibleBitmap function with the other mfc wrapper functions? This would be nice not to have to include manually.

Code:
CreateCompatibleBitmap(hdc, w, h) {
   return DllCall("CreateCompatibleBitmap", "UInt", hdc, "Int", w, "Int", h)
}


:)

_________________
Scripts - License


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 ... 20, 21, 22, 23, 24, 25, 26 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 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