CheckBox Glyph in TsDBGrid

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #35131
    alweis
    Participant

    Serge,

    I am having difficulty drawing the checked and unchecked glyphs to the TsDbGrid, The transparent color (clFuchsia) is not being honored. This is true only for some skins. For example Office10 and Neutral3 are OK. Acryl and DarkGlass are painted incorrectly. See examples below:

    [attachment=5588:demo.png]

    Here is the code:

    Code:
    procedure DrawBooleanGridCell(AGrid: TsDBGrid; ARect: TRect;
    State: TGridDrawState; AChecked:Boolean);
    var
    TmpBmp : TBITMAP;
    i : integer;
    NewLeft, NewTop : integer;
    Size : TSize;
    CellState : Integer;
    begin
    if gdSelected in State then
    CellState := 2
    else
    CellState := 0;

    if DefaultManager.Active then begin
    if AChecked then
    i := DefaultManager.ConstData.CheckBoxChecked
    else
    i := DefaultManager.ConstData.CheckBoxUnChecked;

    Try
    if DefaultManager.IsValidImgIndex(i) then
    begin
    Size.cx := WidthOfImage(DefaultManager.ma);
    Size.cy := HeightOfImage(DefaultManager.ma);
    TmpBmp := CreateBmp32(Size.cx, Size.cy);
    BitBlt(TmpBmp.Canvas.Handle, 0, 0, Size.cx, Size.cy,
    DefaultManager.MasterBitmap.Canvas.Handle,
    DefaultManager.ma.r.left, DefaultManager.ma.r.Top, SRCCOPY);
    NewLeft := (WidthOf(ARect) – Size.cx) div 2;
    Newtop := (HeightOf(ARect) – Size.cy) div 2;
    DrawSkinGlyph(TmpBmp, Point(NewLeft, NewTop), CellState, 1,
    DefaultManager.ma, MakeCacheInfo(TmpBmp));
    BitBlt(AGrid.Canvas.Handle, ARect.Left + NewLeft,
    ARect.Top + NewTop, Size.cx, Size.cy, TmpBmp.Canvas.Handle,
    0, 0, SRCCOPY);
    end;
    finally
    FreeAndNil(TmpBmp);
    end;
    end;
    end;

    Other Info:

    OS: Win 7

    Delphi: XE

    AC Version: 7.62

    I assume there must be a better or correct way to do this. Any help you can offer to resolve this issue will be most appreciated.

    Best Regards,

    Al

    #48067
    Kujo
    Participant

    Hello to all,

    I'm a new user and I have the same problem (not only related to grids) with all skins: sometimes the background is fuchsia, sometimes is white but it is never transparent.

    I also tried to use different code (see below) but the result is the same

    Code:
    var
    GlyphIndex: Integer;
    TempBmp: TBitmap;
    GlyphSize: TSize;

    begin
    GlyphIndex := sSkinManager1.GetMaskIndex(sSkinManager1.ConstData.IndexGLobalInfo, s_GLobalInfo, s_RadioButtonChecked);
    if GlyphIndex > -1 then
    begin
    GlyphSize.cx := WidthOf(sSkinManager1.ma[GlyphIndex].R) div sSkinManager1.ma[GlyphIndex].ImageCount;
    GlyphSize.cy := HeightOf(sSkinManager1.ma[GlyphIndex].R) div (sSkinManager1.ma[GlyphIndex].MaskType + 1);
    TempBmp := CreateBmp32(GlyphSize.cx, GlyphSize.cy);
    DrawSkinGlyph(TempBmp, Point(0, 0), 1, 1, sSkinManager1.ma[GlyphIndex], MakeCacheInfo(TempBmp));
    BitBlt(Self.Canvas.Handle, 50, 50, GlyphSize.cx, GlyphSize.cy, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);
    FreeAndNil(TempBmp);
    end;
    end;

    Thanks for any help.

    #48079
    Kujo
    Participant
    'Kujo' wrote:

    Hello to all,

    I'm a new user and I have the same problem (not only related to grids) with all skins: sometimes the background is fuchsia, sometimes is white but it is never transparent.

    I also tried to use different code (see below) but the result is the same

    Code:
    var
    GlyphIndex: Integer;
    TempBmp: TBitmap;
    GlyphSize: TSize;

    begin
    GlyphIndex := sSkinManager1.GetMaskIndex(sSkinManager1.ConstData.IndexGLobalInfo, s_GLobalInfo, s_RadioButtonChecked);
    if GlyphIndex > -1 then
    begin
    GlyphSize.cx := WidthOf(sSkinManager1.ma[GlyphIndex].R) div sSkinManager1.ma[GlyphIndex].ImageCount;
    GlyphSize.cy := HeightOf(sSkinManager1.ma[GlyphIndex].R) div (sSkinManager1.ma[GlyphIndex].MaskType + 1);
    TempBmp := CreateBmp32(GlyphSize.cx, GlyphSize.cy);
    DrawSkinGlyph(TempBmp, Point(0, 0), 1, 1, sSkinManager1.ma[GlyphIndex], MakeCacheInfo(TempBmp));
    BitBlt(Self.Canvas.Handle, 50, 50, GlyphSize.cx, GlyphSize.cy, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);
    FreeAndNil(TempBmp);
    end;
    end;

    Thanks for any help.

    Hello,

    no one can help here ?

    #48094
    Support
    Keymaster

    Hello!

    A small demo with sources can help to help you more faster. 🙂

    I will make a test-application now with your code and I will write a result here soon.

    #48095
    Support
    Keymaster

    alweis, you can try this code :

    Code:
    procedure DrawBooleanGridCell(AGrid: TsDBGrid; ARect: TRect; State: TGridDrawState; AChecked:Boolean);
    var
    TmpBmp : TBITMAP;
    i : integer;
    NewLeft, NewTop : integer;
    Size : TSize;
    CellState : Integer;
    CI : TCacheInfo;
    begin
    if gdSelected in State then CellState := 2 else CellState := 0;
    if DefaultManager.Active then begin
    if AChecked then i := DefaultManager.ConstData.CheckBoxChecked else i := DefaultManager.ConstData.CheckBoxUnChecked;
    Try
    if DefaultManager.IsValidImgIndex(i) then begin
    Size.cx := WidthOfImage(DefaultManager.ma);
    Size.cy := HeightOfImage(DefaultManager.ma);
    TmpBmp := CreateBmp32(Size.cx, Size.cy);
    FillDC(TmpBmp.Canvas.Handle, Rect(0, 0, Size.cx, Size.cy), AGrid.Color);
    NewLeft := (WidthOf(ARect) – Size.cx) div 2;
    Newtop := (HeightOf(ARect) – Size.cy) div 2;
    CI.FillColor := AGrid.Color;
    CI.Ready := False;
    DrawSkinGlyph(TmpBmp, Point(0, 0), CellState, 1, DefaultManager.ma, CI);
    BitBlt(AGrid.Canvas.Handle, ARect.Left + NewLeft,
    ARect.Top + NewTop, Size.cx, Size.cy, TmpBmp.Canvas.Handle, 0, 0, SRCCOPY);
    end;
    finally
    FreeAndNil(TmpBmp);
    end;
    end;
    end;
    #48103
    Kujo
    Participant
    'Support' wrote:

    Hello!

    A small demo with sources can help to help you more faster. 🙂

    I will make a test-application now with your code and I will write a result here soon.

    After several checks, the following code works for me even if I don't know if this is the right way (AC is a very powerful package but there are too many undocumented units and procedures/functions).

    Code:
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
    Rect: TRect; State: TGridDrawState);
    var
    GlyphSize : TSize;
    GlyphIndex : Integer;
    GlyphState : integer;
    TempBmp : TBitmap;
    Position : TPoint;

    begin
    if sSkinManager1.Active and (Length(sSkinManager1.ma) > 0) then begin
    GlyphIndex := sSkinManager1.ConstData.RadioButtonChecked;
    if GlyphIndex > -1 then begin
    GlyphState := 0; // 0, 1, 2
    GlyphSize.cx := WidthOf(sSkinManager1.ma[GlyphIndex].R) div sSkinManager1.ma[GlyphIndex].ImageCount;
    GlyphSize.cy := HeightOf(sSkinManager1.ma[GlyphIndex].R) div (sSkinManager1.ma[GlyphIndex].MaskType + 1);
    Position := Point(Rect.Left + (WidthOf(Rect) – GlyphSize.cx) div 2,
    Rect.Top + (HeightOf(Rect) – GlyphSize.cy) div 2);

    // Fill the bitmap with the same portion of the background where the Glyph will be placed
    TempBmp := CreateBmp32(GlyphSize.cx, GlyphSize.cy);
    BitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height,
    StringGrid1.Canvas.Handle, Position.X, Position.Y, SRCCOPY);

    DrawSkinGlyph(TempBmp, Point(0, 0), GlyphState, 1, sSkinManager1.ma[GlyphIndex], MakeCacheInfo(TempBmp));

    BitBlt(StringGrid1.Canvas.Handle, Position.x, Position.y,
    TempBmp.Width, TempBmp.Height, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);

    FreeAndNil(TempBmp);
    end;
    end;
    end;

    There is a better method ?

    Best regards.

    #48105
    Support
    Keymaster
    'Kujo' wrote:
    There is a better method ?

    Yes, your code should work 🙂

    #48169
    alweis
    Participant

    Hello Serge,

    Thank you for the code corrections. my immediate problem is now solved. From my perspective, this topic can be closed.

    I would like to note that I intend to implement alternate row colors in the TsDBGrid and icons in the same cell as text. I can see already that I'm going to have some difficulty with this. However, I have not worked on it enough to clearly ask an intelligent question.

    If you happen to have some sample code, I would be most appreciative for any help you can offer. When I can ask a clear question I will post a new topic. Thank you very much for your help and your beautiful skins and controls. They're going to add a lot to my application.

    Best regards,

    Al

    #48244
    Support
    Keymaster
    'alweis' wrote:
    I would like to note that I intend to implement alternate row colors in the TsDBGrid and icons in the same cell as text. I can see already that I'm going to have some difficulty with this. However, I have not worked on it enough to clearly ask an intelligent question.

    I think, you can receive a required color for odd or even rows by mixing of Grid1.Color with Grid1Font.Color :

    Code:
    myOddColor := sGraphUtils.MixColors(Grid1.Color, Grid1.Font.Color, 0.92)

    Received color may be used in the OnDrawDataCell or OnDrawColumnCell events.

    #48255
    alweis
    Participant

    Hello Serge,

    Here is a further update.

    The code for drawing the glyphs only work properly if the cell is not selected. When the cell is selected and the 'SELECTED' skin section drawn, many skins do not properly draw the glyph with transparency all the way around. The glyphs for the skinned check boxes do not appear to be consistently created in the skin files.

    Likewise, if the skin glyphs are used with alternate row coloring I found that the canvas.brush.color must be adjusted for both odd and even rows to assure that the dark color skins will render reasonably. For example:

    Code:
    if IsRowEven then
    Brush.Color := MixColors(DefaultManager.GetGlobalColor,
    DefaultManager.GetGlobalFontColor, 0.8)
    else
    Brush.Color := MixColors(DefaultManager.GetGlobalColor,
    DefaultManager.GetGlobalFontColor, 0.6);

    The bottom line is that I cannot find a way to use the skin glyphs for checkboxes in the TsDBGrid and have all the skins render selected and unselected cells with transparent glyphs. I can get most skins to tender properly but not all.

    For a universal solution for all skins I am now drawing checkboxes on the grid using the AlphaImageList and everything works perfectly. The only down side is that the grid checkboxes are not same style of the skin. This solution is OK for me and this case may still be considered closed. If however there is something I have overlooked because of my newness to Delphi, I would appreciate any advice or sample code that you may have to offer that would improve upon my solution.

    #48269
    Support
    Keymaster
    'alweis' wrote:
    The code for drawing the glyphs only work properly if the cell is not selected. When the cell is selected and the 'SELECTED' skin section drawn, many skins do not properly draw the glyph with transparency all the way around. The glyphs for the skinned check boxes do not appear to be consistently created in the skin files.

    Hello

    Maybe you can make a small demo-application? I will check this app and I will add some improvements there.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.