|
-
Jan 18th, 2012, 12:32 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] When and where to create brushes(and there graphics tools)
EDIT: My title was meant to say other* instead of there.
Well my question here is simple. All I'm looking for is some advice from someone with much experience with performance and efficiency of ones code and the methods they use.
For me I'm big into creating my own controls. For some reason I could never get over the look of my application, and the Microsoft controls together. Just never looked right. Nor were the controls exactly what I needed. By creating controls I can pretty much custom fit them for my application, and I love it.
My question is with drawing these controls. I have 12 of them now in my current project, so I would like to make them all as efficient as possible. The biggest set back to most of them is the drawing can be a little extensive, or at least to a point where they could be more efficient. At the moment, under each paint event I have the brushes created by using blocks and then the drawing happens within them(I create all brushes first, then do the drawing, vice versa with disposing them). My question however came up when I was creating my most recent control, a SimpleList. I experimented to see(though I'm not sure how exactly to track performance) but instead of recreating the brushes and pens etc in the paint event, I put them at the top so they're only made once, and destroyed once, rather being made and destroyed every time my control paints. My common sense tells me this is a better way of going about this but my experience can't back that up. I'm wondering if anyone out there can shed some light and back me up here, or tell me otherwise. I'm always willing to learn more.
So what I am wondering is, is this the way I should be going about user drawn controls?, is there any limitations to this?(like would it be okay if I only had a limited number of brushes etc) and is the performance even that greatly impacted by making these changes that it's worth my while?
Thanks in advanced
Last edited by DavesChillaxin; Jan 18th, 2012 at 12:36 PM.
-
Jan 18th, 2012, 02:33 PM
#2
Re: When and where to create brushes(and there graphics tools)
I too author my own controls for my projects and I've used GDI and GDI+ extensively and personally have not found that creating and destroying pens and brushes inside of drawing procedures impacts performance in any way that can be felt.
While your approach would certainly improve performance even if to a slight degree, I wouldn't use that approach because of my coding style. I tend to write a lot of functions, especially to deal with drawing and having module level variables that these functions use make it much harder to improve the flexibility of these functions.
For example if I have a function that helps render the surface of some fancy control and later down the line I want this function to run inside a loop and for some reason I may want different color brushes. I can make my function take a color parameter and create and destroy the brush within the function. It could cause a lot of grief if the brush were at the class level because it may encourage me to reference it and even change it in other functions and thats where a whole lot of mess could start.
Short of it is, in this case, its better for me to rely as little as I possibly could on class/module level variables because the performance impact is negligible.
-
Jan 18th, 2012, 05:37 PM
#3
Thread Starter
Hyperactive Member
Re: When and where to create brushes(and there graphics tools)
Actually yes, I've done this before too, more so for my analog clock than any other. It was pretty long, so I split it up as fallowed; DrawHands, DrawBase, DrawNumbers, DrawOverlay, ... Shortly after though I made my my appointment grid control, which unfortunately forced me to have everything under the paint method(probably not such a good idea though at the time I had to. It had to do some thinking as to where the mouse clicks occur and how appointments should be drawn, IE selected, checked it etc etc. But awesome, thanks. I'll keep doing what I'm doing by keep objects created for drawing inside of the procedures, but split up in sub routines for larger, more complex designs.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|