Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Advanced Curved Rectangle and Pill Functions

The use of it should be pretty self-explanatory, here is a preview:

[Image: 5SfDE.png]

I'm guessing a lot of you don't know why you would need this..

Well, to make curved buttons like this:
[Image: 5SfGo.png]

You need to use arcs (well, it's the easiest and only way I know).

However, say you didn't want ALL of the corners to be rounded? This function lets you do just that.

Source:
Code
Class CornerStyle
  Public TopLeft As Boolean
  Public TopRight As Boolean
  Public BottomLeft As Boolean
  Public BottomRight As Boolean
    End Class

    Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  Dim P As GraphicsPath = New GraphicsPath()
  Dim ArcRectangleWidth As Integer = Curve * 2

  If CornerStyle.TopLeft Then
    P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  Else
    P.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  End If

  If CornerStyle.TopRight Then
    P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  Else
    P.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  End If

  If CornerStyle.BottomRight Then
    P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  Else
    P.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  End If

  If CornerStyle.BottomLeft Then
    P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  Else
    P.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  End If

  P.CloseAllFigures()
  Return P
    End Function

Yes, I know I don't need to use a class, but it's a whole lot more easy for me to understand it when I can say ".TopLeft = False", than just using AdvRectangle(New Rectangle(1,2,3,4), 5, False, False, True, False, 5)... So deal with it, or change it yourself.




EDIT:
Here is a new function called "Pill". It's used to create a "Pill" shape, which means a half-circle on the side of the button (as opposed to just a rounded edge).

[Image: 5Tejf.png]

Code:
Code
Class PillStyle
  Public Left As Boolean
  Public Right As Boolean
    End Class

    Public Function Pill(ByVal Rectangle As Rectangle, ByVal PillStyle As PillStyle) As GraphicsPath
  Pill = New GraphicsPath()

  If PillStyle.Left Then
    Pill.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Height, Rectangle.Height), -270, 180)
  Else
    Pill.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y)
  End If

  If PillStyle.Right Then
    Pill.AddArc(New Rectangle(Rectangle.X + Rectangle.Width - Rectangle.Height, Rectangle.Y, Rectangle.Height, Rectangle.Height), -90, 180)
  Else
    Pill.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height)
  End If

  Pill.CloseAllFigures()

  Return Pill
    End Function

    Public Function Pill(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal PillStyle As PillStyle)
  Return Pill(New Rectangle(X, Y, Width, Height), PillStyle)
    End Function




If you want my complete Design Functions module (which makes GDI a hell of a lot easier) you can get it here:
http://pastebin.com/JXFrCdMU
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
"Yes, I know I don't need to use a class,"

what do you mean by that?
(Dec 19, 2013 05:56 PM)ident Wrote:  "Yes, I know I don't need to use a class,"

what do you mean by that?

Instead of requiring the use of the class CornerStyle, I could have just made the function take four boolean variables. The class just seemed a lot easier to understand, at least to me anyway.
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
(Dec 19, 2013 05:56 PM)ident Wrote:  "Yes, I know I don't need to use a class,"

what do you mean by that?

It isn't necessary to encapsulate the function into a class. You can use the function as is.
Thanks for this!

Hopefully I won't depend on Aeonhack's themebase forever.
Looks neat ^^

(Dec 19, 2013 09:24 PM)Hawk HF Wrote:  Thanks for this!

Hopefully I won't depend on Aeonhack's themebase forever.
It's pretty to switch over actually.
[Image: IQE6i8G.png]

BlackCap Wrote:You're even more verbose than Java.
About using GoTo's in VB/C#:
Only3 Wrote:asm use it why u shouldnt
(Dec 19, 2013 09:24 PM)Hawk HF Wrote:  Thanks for this!

Hopefully I won't depend on Aeonhack's themebase forever.

His themebase isn't bad, but using pure GDI and custom made controls just adds a little bit more flexibility.

(Dec 20, 2013 02:30 AM)Temploit Wrote:  Looks neat ^^

It's pretty to switch over actually.

Yea and it's actually really easy to switch over if you already know the basics of GDI
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
(Dec 19, 2013 05:46 PM)Tedd Wrote:  The use of it should be pretty self-explanatory, here is a preview:

[Image: 5SfDE.png]

I'm guessing a lot of you don't know why you would need this..

Well, to make curved buttons like this:
[Image: 5SfGo.png]

You need to use arcs (well, it's the easiest and only way I know).

However, say you didn't want ALL of the corners to be rounded? This function lets you do just that.

Source:
Code
Class CornerStyle
  Public TopLeft As Boolean
  Public TopRight As Boolean
  Public BottomLeft As Boolean
  Public BottomRight As Boolean
    End Class

    Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  Dim P As GraphicsPath = New GraphicsPath()
  Dim ArcRectangleWidth As Integer = Curve * 2

  If CornerStyle.TopLeft Then
    P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  Else
    P.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  End If

  If CornerStyle.TopRight Then
    P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  Else
    P.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  End If

  If CornerStyle.BottomRight Then
    P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  Else
    P.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  End If

  If CornerStyle.BottomLeft Then
    P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  Else
    P.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  End If

  P.CloseAllFigures()
  Return P
    End Function

Yes, I know I don't need to use a class, but it's a whole lot more easy for me to understand it when I can say ".TopLeft = False", than just using AdvRectangle(New Rectangle(1,2,3,4), 5, False, False, True, False, 5)... So deal with it, or change it yourself.

If you want my complete Design Functions module (which makes GDI a hell of a lot easier) you can get it here:
http://pastebin.com/Fq3FjZQR

Good share matey, bookmarked for future reference. You should come to the GDI side and have loads of fun. Easy if you have previous experience.
(Dec 20, 2013 10:44 AM)Nextrum Wrote:  Good share matey, bookmarked for future reference. You should come to the GDI side and have loads of fun. Easy if you have previous experience.

Oh I have, I just don't release a lot. I am about to start pushing out some new themes though. I've been working more on perfecting custom controls than making new themes though.
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
(Dec 19, 2013 09:24 PM)Hawk HF Wrote:  Thanks for this!

Hopefully I won't depend on Aeonhack's themebase forever.

Try playing around with it, start by creating something simple like a button, but instead of inheriting the 'ThemeControl' class use 'Control' instead. Then look at how the 'ThemeControl' handles everything, follow every step it takes, and attempt to mimic that in your control. Soon you will have figured out which steps to take without using the 'ThemeBase'. AS for its VERY useful functions, well just because you don't wanna use the 'ThemeBase' doesn't mean you cant use the functions. Create a static class for every function you find useful inside the 'ThemeBase', and port them over, you will just have to add an extra 'Graphics' parameter to each function though. All-in-all you can't be the best 'Theme Creator' without having the tools/creativity to do so.
(Dec 20, 2013 10:52 AM)AgedPeanuts Wrote:  Try playing around with it, start by creating something simple like a button, but instead of inheriting the 'ThemeControl' class use 'Control' instead. Then look at how the 'ThemeControl' handles everything, follow every step it takes, and attempt to mimic that in your control. Soon you will have figured out which steps to take without using the 'ThemeBase'. AS for its VERY useful functions, well just because you don't wanna use the 'ThemeBase' doesn't mean you cant use the functions. Create a static class for every function you find useful inside the 'ThemeBase', and port them over, you will just have to add an extra 'Graphics' parameter to each function though. All-in-all you can't be the best 'Theme Creator' without having the tools/creativity to do so.

I know how to do it, I just never took the time to dig into it.
My next theme, whenever I decide to make it, is going to be 100% GDI.
(Dec 19, 2013 05:58 PM)Tedd Wrote:  Instead of requiring the use of the class CornerStyle, I could have just made the function take four boolean variables. The class just seemed a lot easier to understand, at least to me anyway.

This is exactly why you should use OOP.
Four booleans is hard to read on first glance - you'd have to look at the method definition to find out exactly what each boolean was for.
This approach is much simpler, easier to understand, and just overall better. You should be using a class in cases such as this.
Great share, thanks. HQ User and work! 😉
Don't forget to dispose your graphics once you're done with them.
[Image: Syr3DlV.png]
(Dec 20, 2013 03:36 PM)gigajew Wrote:  Don't forget to dispose your graphics once you're done with them.

How come?
Does it improve performance or speed?

serious question.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Emre_Sep 6, 2019 11:17 PM 0 177 Sep 6, 2019 11:17 PM
Last Post: Emre_
[.NET] by 4h35i13n46u7Sep 18, 2016 03:06 PM 2 103 Sep 18, 2016 03:06 PM
Last Post: Ninja
[C#] by DannyTMAug 10, 2016 10:17 PM 6 241 Aug 10, 2016 10:17 PM
Last Post: 0xBB