Hi,
I’ve been lookin for easy way to embed font to project because I want to make LCD panel lookalike. Since that was not possible I decide to make LCD control. Well, try to make. Because I’m no professional coder, my code is propably as bad as my english. But anyway, I’m going to make it public now and show the world my skill level as coder. Please be gentle with me
In mac and linux this works fine, but in windows it flickers. If I make it use GDI+ it looks nicer, but flickers more.
Please tell me what I’m doing totally wrong and how I should do it better.
So here it is: https://dl.dropboxusercontent.com/u/43427569/lcd.zip
Sample codes open-event has pretty much every property You can change. And slider change value.
Thanks!
What I would suggest is changing Value to a computed property. Move the drawing code from paint to a new method (ie CCLcd.render). In that method, draw into a buffer picture (ie CCLcd.bufferImage) rather than the control’s graphics. At the end of that method, call me.invalidate. In the paint event just draw the buffer to g. I believe that will fix your flicker. Then you can also call the render method from anywhere the display will change BackColor.set Scale.set etc Also then you will not need to call invalidate when you change a value from outside (ie slider.ValueChanged)
Looks very nice btw.
I could see this in an audio mixing console app or the like.
Thanks.
I changed as suggested. I didn’t understand everything but anyway, it draws not to buffer, and paint use buffer. I also made methods that change properties, I don’t know if that was wise. And I don’t know what exactly is that computed property, but seemd to work
And, btw. one thing I do not understand, what is difference between self and me.
Windows still flickers… https://dl.dropboxusercontent.com/u/43427569/lcd_b.zip
if u r in a window with controls, ‘me’ referring to the current control and ‘self’ referring to windows unless u r in the event handler in the window, then me is the same as self.
I did some modification here… Moved it to a canvas and changed the digits to strings… that allowed me to add a - for negative values. You could also add decimal points for floating point numbers. I turned on doublebuffer and am seeing no flicker in win32. If you need the embedwithin functionality, you could make a container and just add the canvas to it. Otherwise you could create instances in code via control arrays. There are some minor tweaks… I didn’t comment as I made changes though :-/
just notice on the new version, resize didn’t do anything on Mac OSX Mavericks. But i do notice the white/grey canvas behind the lower right corner LCD does not show up anymore
Thanks!
Pretty much same as Jrmie Leroy told me to do
I changed also to Canvas Class since it was ContainerControl that cause flicker in windows.
but I didn’t know how to make resize with that.
here what I did: https://dl.dropboxusercontent.com/u/43427569/CLcd.zip
Thank You very much, I’ll read your code and learn by it!
Pretty cool that it extends digits!
Can You please comment this somehow, I’m totally lost here:
if RenderedImage=nil or RenderedImage.Width<>round(Digits*148*scale) or RenderedImage.Height<>me.Height then
RenderedImage=new Picture(Digits*148*scale,me.Height,32)
end if
Make sure if you use invalidate or refresh you pass false as you don’t want to erase the background each time (which can also cause flicker on Windows).
Thanks to Jim and Jrmie. I now have LCD Panel lookalike that is Flicker free in windows also.
I changed Jims code so that if I put digitcount, it’s not dynamic, otherwise it is.
I also try to add some error if value don’t fit to digits.
Learned a lot and still learning!
Thanks again and have fun with lcd panel http://purkki.net/CLcd/
[quote=49968:@Jukka Leino]retty cool that it extends digits!
Can You please comment this somehow, I’m totally lost here:
if RenderedImage=nil or RenderedImage.Width<>round(Digits148scale) or RenderedImage.Height<>me.Height then
RenderedImage=new Picture(Digits148scale,me.Height,32)
end if
Jukka[/quote]
Sure, this is just a check to make sure that the drawing buffer (RenderedImage) exists and that if it exists it is the correct size for the drawing we need. Otherwise it creates a new image at the needed dimensions.