- This topic has 28 replies, 2 voices, and was last updated 7 years, 7 months ago by Raccoon.
-
AuthorPosts
-
April 10, 2017 at 7:45 pm #56468SupportKeymaster
Only Imagelist used currently.
April 11, 2017 at 7:15 am #56473RaccoonParticipantThank you for the reply.
Any chance to get a Bitmap Option there?
I wanted to use the new TsFloatButton to create a Button which has a Bitmap with variable Width. On that Bitmap I'm drawing a text. The Width is depending on Textwidth, so that the Bitmap might be greater than 256px.
I tried with VirtualImageList, but without success.
Best regards
Alex
April 11, 2017 at 7:56 am #56474SupportKeymasterYou can draw in the OnPaint event directly. Do you know it?
April 11, 2017 at 7:59 am #56475RaccoonParticipantOh, no…I didnt know 🙂
I will try it and reply here.
Thank you very much!
Alex
April 11, 2017 at 8:48 am #56476RaccoonParticipantHi there,
on paint method works well :a3:
Just one more question 😕
I attached one screenshot.
You see the TsFloatButton on top of the form. The lower “Flag” is a TPaintBox with the same Bitmap. As you can see the fontstyle differs between them. Do you have any tipp, how I can make the TsFloatButton looks like the PaintBox?
Here is my code:
Code:__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Get the Bitmap and preset Width and Height of TsFloatButton (AutoSize=false) outside of the OnPaint Event
TBitmap *ABMP = new TBitmap();
DrawFlag(ABMP);btn->Items->Items[0]->Height = ABMP->Height;
btn->Items->Items[0]->Width = ABMP->Width;
delete ABMP;
}
//—————————————————————————void __fastcall TForm1::btnItems0Paint(TObject *Sender, TacCustomPaintData PaintData)
{
//paint it
DrawFlag(PaintData.DestBmp);
}
//—————————————————————————void __fastcall TForm1::DrawFlag(TBitmap *AToBitmap)
{
if(!AToBitmap)
return;static const int FLAG_TEXT_MARGIN = 56;
TBitmap *bmpFlag = new TBitmap();
TBitmap *bmpBackground = new TBitmap();
imgl->GetBitmap(0, bmpBackground);bmpFlag->Canvas->Font->Name = “Trebuchet MS”;
bmpFlag->Canvas->Font->Size = 11;
bmpFlag->Canvas->Font->Style = TFontStyles() << fsBold;
bmpFlag->Canvas->Font->Color = clWhite;
bmpFlag->Canvas->Brush->Style = bsClear;UnicodeString asText = “Hello, I'm a topic. My current date is: “;
TDateTime dtNow;
dtNow = dtNow.CurrentDate();
int iTextWidthText = bmpFlag->Canvas->TextWidth(asText);
int iTextWidthDate = bmpFlag->Canvas->TextWidth(” ” + dtNow.DateString());int iGesWidth = iTextWidthText + iTextWidthDate;
if(iGesWidth+FLAG_TEXT_MARGIN Width)
{
bmpFlag->SetSize(bmpBackground->Width, bmpBackground->Height);
}
else
{int iNewWidth = iGesWidth + FLAG_TEXT_MARGIN;
bmpFlag->SetSize(iNewWidth, bmpBackground->Height);
}bmpFlag->Canvas->CopyRect(TRect(0,0,bmpFlag->Width, bmpFlag->Height), bmpBackground->Canvas, TRect(0,0,bmpBackground->Width, bmpBackground->Height));
bmpFlag->Canvas->TextOutW((bmpFlag->Width – iGesWidth)/2, (bmpFlag->Height – bmpFlag->Canvas->TextHeight(asText))/2, asText + ” ” + dtNow.DateString());
//pb is the TPaintBox
pb->Canvas->Draw(0,0,bmpFlag);AToBitmap->Assign(bmpFlag);
delete bmpBackground;
delete bmpFlag;
}
//—————————————————————————It seems that the Bitmap in the TsFloatButton is a little bit squeezed?!
Thank you very much for your help.
Alex
April 11, 2017 at 8:55 am #56477SupportKeymasterBitmap is not squeezed, it's drawn as is.
I will try to make a test app with your code soon and I will check it.
April 11, 2017 at 8:59 am #56478RaccoonParticipantNice, thank you :a3:
April 13, 2017 at 11:26 am #56497SupportKeymasterI think, I know a reason of the problem.
Bitmap with alphachannel used for drawing of this control, but standard API functions can't draw text with alphachannel and image have wrong alpha-pixels in text.
You can try several solutions:
1. Use the WriteText32 procedure:
Code:procedure WriteText32(const Bmp: TBitmap; Text: PacChar; Enabled: boolean; var aRect: TRect; Flags: Cardinal; SkinIndex: integer; Hot: boolean; SkinManager: TObject = nil; IsAnsi: boolean = False);Example:
R := Rect(10, 10, bmpFlag.Width – 10, bmpFlag.Height – 10);
WriteText32(bmpFlag, PChar(asText), True, R, DT_CENTER, -1, True);2.Update an alphachannel in your code after painting of text by standard TextOutW procedure. Call the FillAlphaRect procedure with rectangle of text as parameter and with Value = 255.
Code:procedure FillAlphaRect(const Bmp: TBItmap; const R: TRect; Value: byte; TransparentColor: TColor = clNone);Both procedure are decalred in the sAlphaGraph unit.
April 13, 2017 at 11:41 pm #56498RaccoonParticipantNice, both methods work :a3:
Thank you very much for your help!
Best regards
Alex
-
AuthorPosts
- You must be logged in to reply to this topic.