Board index » cppbuilder » Predefined TBitmap compatible bitmaps for basic colors for TMenItem entries?

Predefined TBitmap compatible bitmaps for basic colors for TMenItem entries?


2003-10-04 11:13:10 AM
cppbuilder114
Are there any bit maps in BCB v6 that are compatible with (the right
size) the VCL class TBitMap that have been premade and are somewhere
part of BCB v6?
Or, better yet, is there some way on-the-fly to make a bitmap that will
be a solid TColor color that will be the right size to use when
instantiating a TBitmap?
I want to take a list of lines that the user has drawn on a graph, loop
thru and build up a list of TMenuItem objects that have the right TColor
associated with them so I can show a list of colors and line names in a
submenu of a context pop-up menu.
 
 

Re:Predefined TBitmap compatible bitmaps for basic colors for TMenItem entries?

"Randall Parker" < XXXX@XXXXX.COM >wrote in message
Quote
I want to take a list of lines that the user has drawn on a graph,
loop thru and build up a list of TMenuItem objects that have
the right TColor associated with them so I can show a list of
colors and line names in a submenu of a context pop-up menu.
Why use a TBitmap at all? If all you want to do is draw a solid line on a
menu item, then why not use the TMenuItem::DrawItem event and draw a colored
line directly onto the menu's Canvas when needed?
Gambit
 

Re:Predefined TBitmap compatible bitmaps for basic colors for TMenItem entries?

Well, I don't want a line. I want a square box. Look at the way the
color-choosing pop-down lists show their rows. I want to do that but in
a menu item.
Also, if I used this DrawItem event how would I position the text to the
right of the color box? Normally the text is specified with the Caption
property. If I just go drawing on the TMenuItem canvas the TMenuItem
isn't going to know to shift the Caption over to make room for the
color. This will create alignment problems.
I think what I need is a method that will take a TColor and create and
return a 16x16 TBitmap that I can then assign to the TMenuItem::Bitmap.
So I need a way to specify the size of and fill in a bitmap in memory.
TMenuItem* MyMenuItem = new TMenuItem();
MyMenuItem->Caption = "Some Investment";
TBitmap* MyBitMap = new TBitmap();
TColor MyTColor = clMoneyGreen;
// Then somehow create a 16x16 area filled in with MyTColor.
// ????????????????????
// Use one of the LoadFromXXX to put that memory-created bitmap
// into the MyBitMap object.
// ????????????????????
// Then finish:
MyMenuItem->Bitmap = MyBitMap;
So how to create a bitmap memory area in memory?
Remy Lebeau (TeamB) wrote:
Quote
"Randall Parker" < XXXX@XXXXX.COM >wrote in message
news:3f7e39ff$ XXXX@XXXXX.COM ...


>I want to take a list of lines that the user has drawn on a graph,
>loop thru and build up a list of TMenuItem objects that have
>the right TColor associated with them so I can show a list of
>colors and line names in a submenu of a context pop-up menu.


Why use a TBitmap at all? If all you want to do is draw a solid line on a
menu item, then why not use the TMenuItem::DrawItem event and draw a colored
line directly onto the menu's Canvas when needed?


Gambit


 

{smallsort}

Re:Predefined TBitmap compatible bitmaps for basic colors for TMenItem entries?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news: XXXX@XXXXX.COM ...
Quote
Well, I don't want a line. I want a square box.
Either way, my earlier suggestion still stands. Just custom-draw the menu
items, then you don't need separate bitmaps at all. You can draw the items
however you want.
Quote
Also, if I used this DrawItem event how would I position
the text to the right of the color box?
For a custom-drawn item, you are responsible for drawing the text as well.
Simply use the Canvas's TextOut() or TextRect() method (I would suggest
TextRect()). Both allow you to specify the offset where you want the text
to be drawn. Simply draw the box first and then specify on offset that is
at least the width of the box, maybe a few extra pixels for spacing.
Quote
Normally the text is specified with the Caption property. If I just
go drawing on the TMenuItem canvas the TMenuItem isn't going
to know to shift the Caption over to make room for the color.
This will create alignment problems.
When you custom-drawn an item, the Menu Item no longer draws the Caption for
you, so it becomes your responsibility, not the MenuItem's to handle the
necessarily alignment. You can draw the text whereever you want. If you
want to support aligning the Caption relative to the color box, then simply
adjust the offset you use for TextOut/Rect(). The OnDrawItem event provides
the rectangle for the MenuItem, simply adjust the Left member before calling
TextOut/Rect(). The Sender parameter is a pointer to the TMenuItem so you
can grab the current Caption.
Quote
I think what I need is a method that will take a TColor and create
and return a 16x16 TBitmap that I can then assign to the
TMenuItem::Bitmap.
As you wish. I was just trying to help you streamline your code to be more
effient without needing to use extra memory. Specifying a Bitmap just
accomplished the same thing that I have suggested here, except that the
MenuItem is handling the custom-drawing for you instead of you doing it
manually, but the end effect is still the same - the MenuItem custom-draws
the bitmap, then shifts the Caption and draws it alongside the bitmap. But
then you're instilling the extra memory for every single bitmap you
allocate, whereas using the OnDrawItem event is dynamic and does not use
extra memory, especially for something is simple as a solid box of a single
color.
Quote
So I need a way to specify the size of and fill in a bitmap in memory.
See my reply to the other thread you started on that topic.
Gambit