|
I really liked this. Good article.
|
|
|
|
|
You may defines ASCII char with table as:
const int Sa = 0x01; // ....Sa....
const int Sb = 0x02; // Sf......Sb
const int Sc = 0x04; // ....Sg....
const int Sd = 0x08; // Se......Sc
const int Se = 0x10; // ....Sd......Sh
const int Sf = 0x20;
const int Sg = 0x40;
const int Sh = 0x80;
static char[] Tcar =
{
'1' , '2' , '3' ,
'4' , '5' , '6' ,
'7' , '8' , '9' ,
'0' , 'A' , 'B' ,
'C' , 'D' , 'E' ,
'F' , '.' , ' ' ,
'H' , 'I' , 'L' ,
'O' , 'P' , 'R' ,
'U' , '-' , '=' ,
'a' , 'b' , 'c' ,
'd' , 'e' , 'f' ,
'h' , 'i' , 'n' ,
'o' , 'r' , 't' ,
'u'
};
static int[] Tval =
{
Sb+Sc, Sa+Sb+Sd+Se+Sg, Sa+Sb+Sc+Sd+Sg,
Sb+Sc+Sf+Sg, Sa+Sc+Sd+Sf+Sg, Sa+Sc+Sd+Se+Sf+Sg,
Sa+Sb+Sc, Sa+Sb+Sc+Sd+Se+Sf+Sg, Sa+Sb+Sc+Sd+Sf+Sg,
Sa+Sb+Sc+Sd+Se+Sf, Sa+Sb+Sc+Se+Sf+Sg, Sc+Sd+Se+Sf+Sg,
Sa+Sd+Se+Sf, Sb+Sc+Sd+Se+Sg, Sa+Sd+Se+Sf+Sg,
Sa+Se+Sf+Sg, Sh, 0x00,
Sb+Sc+Se+Sf+Sg, Se+Sf, Sd+Se+Sf,
Sc+Sd+Se+Sg, Sa+Sb+Se+Sf+Sg, Se+Sg,
Sc+Sd+Se, Sg, Sd+Sg,
Sa+Sb+Sc+Se+Sf+Sg, Sc+Sd+Se+Sf+Sg, Sa+Sd+Se+Sf,
Sb+Sc+Sd+Se+Sg, Sa+Sd+Se+Sf+Sg, Sa+Se+Sf+Sg,
Sc+Se+Sf+Sg, Se, Sc+Se+Sg,
Sc+Sd+Se+Sg, Se+Sg, Sd+Se+Sf+Sg,
Sc+Sd+Se
};
So, your DrawSingleChar() Procedure becomes:
private void DrawSingleChar(Graphics g, Rectangle rectBound, Color colCharacter, char car, float bevelRate, float segmentWidth, float segmentInterval)
{
int emme = Tcar.Length;
int i;
for (i = 0; i < emme; i++)
{
if (Tcar[i] == car)
{
int segm = Tval[i];
for (int k = 0; k < 8; k++)
{
if ((segm & (1 << k)) != 0)
{
DrawSegment(g, rectBound, colCharacter, k+1, bevelRate, segmentWidth, segmentInterval);
}
}
break;
}
}
}
And DrawSingleCharWithFadedBk() becomes:
private void DrawSingleCharWithFadedBk(Graphics g, Rectangle rectBound, Color colCharacter,
Color colFaded, char car, float bevelRate, float segmentWidth, float segmentInterval)
{
int emme = Tcar.Length;
int i;
for (i = 0; i < emme; i++)
{
if (Tcar[i] == car)
{
int segm = Tval[i];
for (int k = 0; k < 8; k++)
{
if ((segm & (1 << k)) != 0)
{
DrawSegment(g, rectBound, colCharacter, k + 1, bevelRate, segmentWidth, segmentInterval);
}
else
{
DrawSegment(g, rectBound, colFaded, k + 1, bevelRate, segmentWidth, segmentInterval);
}
}
break;
}
}
}
Ciao
Nicola
|
|
|
|
|
Hey, just saw this.
I believe that I learnt this 7-segment led display when I was doing some native C programming for DIP micro processor back to my college time.
Nice binary manipulation, inspiring.
Someone was born greatness;
Someone achieved greatness;
Someone have the greatness thrust upon him;
|
|
|
|
|
yeah, i quite agree with your habit of coding. i will prefer "Array.IndexOf()" to instead of the linear searching loop .
|
|
|
|
|
Hi guys,
i am new at programming so please bear with me.
i downloaded the demo project and i am trying to the run the project using VS 2005,
when doing so i get prompted for a password.
Please Help
|
|
|
|
|
Sorry for the late reply!
Well, it is strange~~ and I can't reproduce your problem. However, you can download the source code and re-compile the project to see if it can be used.
|
|
|
|
|
Thanks for the good work and also for sharing!
Good work also on the presentation (Article).
Keep it up and optimizations are welcome
CodeMadness - Code before you go mad!
|
|
|
|
|
Nice control. I liked it. Thanks
|
|
|
|
|
Say: why don't you hardcode all coordinates for a standard (unit) size (1,1) (or (1,2)), then just resize each point to the new size (w, h)?!
You may do beter by harcoding the corners of just 3 segments, then flip (two of) them on a simetry line! (it works even with 2: one you flip and/or rotate (90 degrees), the other one - fixed in the center.)
To avoid even those calculation during redraw - do the drawing in a bitmap and paste that bitmap in an image control.
Alternalively, why don't harcode three bitmaps for those three (two) segments and just play with flipping, rotating and combining bitmaps?! - and let the image support to resize it!
On another hand: can you do italic?
Horia Tudosie
|
|
|
|
|
Thanks for your suggestion, Horia! Yes, I think hardcoding all coordinates for a standard size is a good idea, and I will try it.
Also, may be we can use affine transformation to get the italic effect.
I am very sorry for the late replying, but it is really a busy time for me now~~
|
|
|
|
|
I've sent the update to the editor .
Many thanks to Ed. Poore!
|
|
|
|
|
Nicely done control. Enjoyed the article and good job.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Thank you , I am very glad that you like it.
|
|
|
|
|
First thanks for writing a decent article (in the recent spate of rubbish ones) and creating what looks like a decent control.
Secondly I just thought I'd point out a technique which I picked up from Tim Dawson years ago, why not override the OnResize protected method to perform the calculations the graphics paths etc used for drawing. The reasoning behind this is that the control is drawn far more frequently than it is resized so by moving the calculations out of the drawing code you can speed up the drawing of the control.
Hope that made some sense, it also makes it slightly easier to maintain.
|
|
|
|
|
Thank you for your suggestion. Yes, you' re right! I will have a try and fix it as soon as possible ! Thank you !
Best Wishes!
|
|
|
|
|
infact, if you are using gdi+, the work can get done with fewer than 100 lines with the help of triangle linecap and flag attributed enum as bitmask.
|
|
|
|
|