AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GDI+ standard library 1.45 by tic
Goto page Previous  1, 2, 3 ... 22, 23, 24 ... 60, 61, 62  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Smurth



Joined: 13 Dec 2006
Posts: 117

PostPosted: Thu Mar 04, 2010 11:10 am    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
Smurth



Joined: 13 Dec 2006
Posts: 117

PostPosted: Thu Mar 04, 2010 11:32 am    Post subject: Reply with quote

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
}
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Thu Mar 04, 2010 9:39 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
Smurth



Joined: 13 Dec 2006
Posts: 117

PostPosted: Fri Mar 05, 2010 4:08 am    Post subject: Reply with quote

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".
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Fri Mar 05, 2010 10:41 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
ConfusedByGdip
Guest





PostPosted: Sat Mar 06, 2010 2:18 am    Post subject: Reply with quote

Could somebody show a demonstration on how to paste an image onto a normal gui window (with text & buttons) using Gdip?
Back to top
Zaelia



Joined: 31 Oct 2008
Posts: 604
Location: France

PostPosted: Mon Mar 08, 2010 4:23 pm    Post subject: Reply with quote

check example #9, first page of this thread, you can use bitblt or setimage (you need to create an handle)
Back to top
View user's profile Send private message Send e-mail
Razer



Joined: 15 Feb 2010
Posts: 10

PostPosted: Thu Mar 11, 2010 8:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Learning one



Joined: 04 Apr 2009
Posts: 1001
Location: Croatia

PostPosted: Thu Mar 11, 2010 11:07 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Thu Mar 11, 2010 11:23 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Smurth



Joined: 13 Dec 2006
Posts: 117

PostPosted: Thu Mar 11, 2010 11:33 am    Post subject: Reply with quote

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)
}



Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Thu Mar 11, 2010 12:14 pm    Post subject: Reply with quote

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 Embarassed

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)
Back to top
View user's profile Send private message
Razer



Joined: 15 Feb 2010
Posts: 10

PostPosted: Thu Mar 11, 2010 1:59 pm    Post subject: Reply with quote

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. Crying or Very sad

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

Razer.
Back to top
View user's profile Send private message
Smurth



Joined: 13 Dec 2006
Posts: 117

PostPosted: Thu Mar 11, 2010 9:50 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Mar 11, 2010 11:19 pm    Post subject: Reply with quote

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)
}


Smile
_________________
Scripts - License
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 22, 23, 24 ... 60, 61, 62  Next
Page 23 of 62

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group