 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nate Lockwood Guest
|
Posted: Thu Feb 16, 2006 11:03 pm Post subject: combo box with a graphic and text |
|
|
I need a component that works like a combo box that can display a simple
graphic with a very short text. The graphic would be the simplest color
(box)and the text will be the hex representation of the color. The
graphic could be in one column and the text in a second.
The object would be to let the user choose a color and be able to see
the hex value. (I would also use code to allow the user to add, delete,
and position the items.)
Can this be done with any components in the palette?
Thanks
Nate |
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Feb 17, 2006 2:03 am Post subject: Re: combo box with a graphic and text |
|
|
Nate Lockwood <RNLockwoodREMOVE (AT) attglobal (DOT) net> wrote:
| Quote: |
[...] Can this be done with any components in the palette?
|
Well you did say ComboBox and if you had searched the archives:
http://www.tamaracka.com/search.htm
You'd have found something like this:
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
ComboBox1->Style = csOwnerDrawFixed;
ComboBox1->ItemHeight = ImageList1->Height;
ComboBox1->ItemIndex = 0;
}
//-------------------------------------------------------------
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
{
TComboBox *pBox = dynamic_cast<TComboBox*>( Control );
TCanvas *pCanvas = pBox->Canvas;
if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = pBox->Color;
pCanvas->Font->Color = pBox->Font->Color;
}
pCanvas->FillRect( Rect );
ImageList1->Draw( pCanvas, Rect.left, Rect.top, Index, true );
pCanvas->TextOut( Rect.left + ImageList1->Width + 3,
Rect.top + (((Rect.bottom - Rect.top) / 2) - (pCanvas->TextHeight("Wg") / 2)),
ComboBox1->Items->Strings[Index] );
}
//-------------------------------------------------------------
Note that the above uses a TImageList which could be replaced
with a TBitmap that you fill as needed with the color that you
want at that moment.
~ JD |
|
| Back to top |
|
 |
Nate Lockwood Guest
|
Posted: Fri Feb 17, 2006 7:03 am Post subject: Re: combo box with a graphic and text |
|
|
JD wrote:
Thanks, JD, I decided that a TListBox would be a better choice for what
I want to do and this time I did search, thanks. <g>
It mostly works but the color of the bitmap in the box is white, not
red, 0x0000ff. Here's some code:
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
clFillColor = (TColor) 0x0000ff; // should be red
ListBoxColor->Style = lbOwnerDrawFixed;
ListBoxColor->ItemHeight = ImageListColor->Height;
ListBoxColor->ItemIndex = 0;
Graphics::TBitmap *pBitMap = new Graphics::TBitmap();
pBitMap->Height = ImageListColor->Height;
pBitMap->Width = ImageListColor->Width;
pBitMap->Canvas->Rectangle(0, 0, ImageListColor->Width,
ImageListColor->Height);
pBitMap->Canvas->FloodFill(0, 0, clFillColor, fsSurface);
ImageListColor->Add(pBitMap, NULL);
ListBoxColor->Clear();
ListBoxColor->AddItem("Item 1", (TObject *)pBitMap);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ListBoxColorDrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{
TListBox *pBox = dynamic_cast<TListBox*>( Control );
TCanvas *pCanvas = pBox->Canvas;
if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = pBox->Color;
pCanvas->Font->Color = pBox->Font->Color;
}
pCanvas->FillRect( Rect );
ImageListColor->Draw( pCanvas, Rect.left, Rect.top, Index, true );
pCanvas->TextOut( Rect.left + Image->Width + 3,
Rect.top + (((Rect.bottom - Rect.top) / 2) -
(pCanvas->TextHeight("Wg") / 2)),
ListBoxColor->Items->Strings[Index] );
}
//--------------------------------------------------------------------------- |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Feb 17, 2006 9:03 am Post subject: Re: combo box with a graphic and text |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote in message
news:43f52107$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Note that the above uses a TImageList which could be replaced
with a TBitmap that you fill as needed with the color that you
want at that moment.
|
You don't even need that much. Since Nate said the items would be hex
values of the colors, he can convert the text to TColor and draw the color
directly onto the Canvas:
// set the ComboBox1->Style to csOwnerDrawFixed at design-time...
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control, int
Index, TRect &Rect, TOwnerDrawState State)
{
TCanvas *pCanvas = ComboBox1->Canvas;
AnsiString S = ComboBox1->Items->Strings[Index];
TColor c = (TColor) StrToIntDef("0x" + S, clNone);
int iSquareSize = (Rect.Height()-4);
int iSquareRight = (Rect.Left + 2 + iSquareSize);
if( State.Contains(odSelected) )
pCanvas->Brush->Color = clHighlight;
else
pCanvas->Brush->Color = pBox->Color;
pCanvas->FillRect(Rect);
if( c != clNone )
{
pCanvas->Pen->Color = clBlack;
pCanvas->Brush->Color = c;
pCanvas->Rectangle(Rect.Left+2, Rect.Top+2, iSquareRight,
Rect.Bottom-2);
}
if( State.Contains(odSelected) )
pCanvas->Font->Color = clHighlightText;
else
pCanvas->Font->Color = pBox->Font->Color;
pCanvas->TextRect(Rect, iSquareRight+3, Rect.Top + 2,
ComboBox1->Items->Strings[Index]);
}
Gambit |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Feb 17, 2006 9:03 am Post subject: Re: combo box with a graphic and text |
|
|
"Nate Lockwood" <RNLockwoodREMOVE (AT) attglobal (DOT) net> wrote in message
news:43f4f59f (AT) newsgroups (DOT) borland.com...
| Quote: | I need a component that works like a combo box that can display
a simple graphic with a very short text. The graphic would be the
simplest color (box)and the text will be the hex representation of the
color. The graphic could be in one column and the text in a second.
|
If you are using BCB 6+, have a look at the TColorBox component.
Gambit |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Feb 17, 2006 9:03 am Post subject: Re: combo box with a graphic and text |
|
|
"Nate Lockwood" <RNLockwoodREMOVE (AT) attglobal (DOT) net> wrote in message
news:43f565bf$1 (AT) newsgroups (DOT) borland.com...
| Quote: | It mostly works but the color of the bitmap in the
box is white, not red, 0x0000ff. Here's some code:
|
I would not recommend using TImageList and TBitmap at all for what you are
attempting. See my other reply.
Gambit |
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Feb 17, 2006 9:03 am Post subject: Re: combo box with a graphic and text |
|
|
Nate Lockwood <RNLockwoodREMOVE (AT) attglobal (DOT) net> wrote:
| Quote: |
[...] It mostly works but the color of the bitmap in the box
is white, not red, 0x0000ff. Here's some code:
|
I don't what I was thinking when I said anything about a
TBitMap. Try this:
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
ListBox1->AddItem( "clLime", reinterpret_cast<TObject*>(clLime) );
ListBox1->AddItem( "clRed", reinterpret_cast<TObject*>(clRed) );
ListBox1->AddItem( "clAqua", reinterpret_cast<TObject*>(clAqua) );
ListBox1->AddItem( "clBlue", reinterpret_cast<TObject*>(clBlue) );
}
//-------------------------------------------------------------
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
{
TListBox *pBox = static_cast<TListBox*>( Control );
TCanvas *pCanvas = pBox->Canvas;
if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = pBox->Color;
pCanvas->Font->Color = pBox->Font->Color;
}
pCanvas->FillRect( Rect );
TRect R = Rect;
int height = (R.bottom - R.top) - 4;
int width = height + 0;
R.left += width + 4;
::DrawText( pCanvas->Handle, pBox->Items->Strings[Index].c_str(), -1, &R, DT_SINGLELINE | DT_LEFT | DT_VCENTER );
R.left = Rect.left + 2;
R.top += 2;
R.right = R.left + width + 2;
R.bottom -= 2;
pCanvas->Brush->Color = reinterpret_cast<TColor>( pBox->Items->Objects[Index] );
pCanvas->FillRect( R );
}
//-------------------------------------------------------------
~ JD |
|
| Back to top |
|
 |
Nate Lockwood Guest
|
Posted: Fri Feb 17, 2006 5:03 pm Post subject: Re: combo box with a graphic and text |
|
|
Thanks, Remy and JD. I'll try your suggestions when I get to my office.
What I'm doing with this small application is generating KML (Google
Earth XML) files from a meta data file that has location, altitude, and
other data for each infrared image that we take from an aircraft. Each
meta data file describes the images taken in one pass over part of a
wildfire. In the course of the fire we would make several overlapping
passes so that what we have covered is a box. We typically have several
boxes in the course of a day. The images and data are sent by satellite
to a ground station, processed, and posted to the Internet. I'm
developing diverse tools to automate and speed the process and we are
working toward 10 to 15 minutes turnaround for each pass, that's "real
time" in this business and an improvement from the hour and a half it
took when we started.
The person who works with the images needs to get an idea of where the
aircraft is on the passes and wants the icons for different passes to
have different colors so as to easily differentiate among them. I want
the colors to be chosen by the user so I need to display them with hex
values in a list that will, in the end, be editable. I had thought of a
ComboBox as the the chosen color would display neatly and my form would
be smaller but that's harder to edit. I envision one which the user
will be able edit, that, choose a color and then insert it into the list
or modify an existing color, be able to move list items up or down, and
to delete them. I expect that the user will need to do extensive
revisions to get a "good" list. As you can see the list functions as a
custom palette. Of course I will save any values in the list and
populate the list as the application starts.
If this makes a difference in my choice of lists please let me know
So that's the kind of list I need. I only have access the browser based
groups at work. I am using CPP 6 and developing under XP-Pro.
Some of our work, kind of experimental is at www.fireimaging.com. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|