TacTitleItem Question

Viewing 9 posts - 21 through 29 (of 29 total)
  • Author
    Posts
  • #56468
    Support
    Keymaster

    Only Imagelist used currently.

    #56473
    Raccoon
    Participant

    Thank 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

    #56474
    Support
    Keymaster

    You can draw in the OnPaint event directly. Do you know it?

    #56475
    Raccoon
    Participant

    Oh, no…I didnt know 🙂

    I will try it and reply here.

    Thank you very much!

    Alex

    #56476
    Raccoon
    Participant

    Hi 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

    #56477
    Support
    Keymaster

    Bitmap 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.

    #56478
    Raccoon
    Participant

    Nice, thank you :a3:

    #56497
    Support
    Keymaster

    I 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.

    #56498
    Raccoon
    Participant

    Nice, both methods work :a3:

    Thank you very much for your help!

    Best regards

    Alex

Viewing 9 posts - 21 through 29 (of 29 total)
  • You must be logged in to reply to this topic.