Recent

Author Topic: How to draw Controls on canvas at linux? Or other ways to draw check box on VST  (Read 1239 times)

Pixelmak

  • Newbie
  • Posts: 2
Usually at the Windows i am using UxTheme library.

Like this
Code: Pascal  [Select][+][-]
  1. procedure TxpLoginRegisterForm.GridAfterCellPaint(Sender: TBaseVirtualTree;
  2.   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   const CellRect: TRect);
  4. var
  5.   r: TRect;
  6.   size: TSize;
  7.   h: HTHEME;
  8.  
  9.   data: PGridData;
  10. const
  11.   PADDING = 4;
  12. begin
  13.   if Column = IsWebColumn then
  14.   begin
  15.     r := CellRect;
  16.  
  17.     data := Grid.GetNodeData(Node);
  18.     size.cx := GetSystemMetrics(SM_CXMENUCHECK);
  19.     size.cy := GetSystemMetrics(SM_CYMENUCHECK);
  20.  
  21.     h := OpenThemeData(Sender.Handle, 'BUTTON');
  22.  
  23.     GetThemePartSize(h, TargetCanvas.Handle, BP_CHECKBOX, CBS_CHECKEDNORMAL, nil, TS_DRAW, size);
  24.     r.Top    := CellRect.Top + (CellRect.Bottom - CellRect.Top - size.cy) div 2;
  25.     r.Bottom := r.Top + size.cy;
  26.     r.Left   := r.Left + PADDING;
  27.     r.Right  := r.Left + size.cx;
  28.  
  29.     if data^.IsWeb=1 then
  30.       DrawThemeBackground(h, TargetCanvas.Handle, BP_CHECKBOX, CBS_CHECKEDNORMAL, r, nil)
  31.     else
  32.       DrawThemeBackground(h, TargetCanvas.Handle, BP_CHECKBOX, CBS_UNCHECKEDNORMAL, r, nil);
  33.  
  34.     CloseThemeData(h);
  35.   end;
  36. end;
  37.  

Is there a way to do the same for Linux? Or other ways to draw a checkbox?

wp

  • Hero Member
  • *****
  • Posts: 7760
Checkbox theme drawing should be active in VTV by default (CheckImageKind = dkSystemDefault), AFIK there is no need to draw checkbox manually for this purpose.

In general, theme support is handled in the LCL in a cross-platform way by the unit "themes" and the ThemeServices methods.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Pixelmak

  • Newbie
  • Posts: 2
Checkbox theme drawing should be active in VTV by default (CheckImageKind = dkSystemDefault), AFIK there is no need to draw checkbox manually for this purpose.

I am using TVirtualStringTree where I have many columns, in each of which I need to draw a checkbox. But "CheckImageKind" adds a checkbox only to the root column.

In general, theme support is handled in the LCL in a cross-platform way by the unit "themes" and the ThemeServices methods.

Excellent! That's what I was looking for! Thank you so much!

Code: Pascal  [Select][+][-]
  1. procedure TxpLoginRegisterForm.GridAfterCellPaint(Sender: TBaseVirtualTree;
  2.   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   const CellRect: TRect);
  4. var
  5.   r: TRect;
  6.   size: TSize;
  7.   data: PGridData;
  8.  
  9.   Details: TThemedElementDetails;
  10. const
  11.   PADDING = 4;
  12. begin
  13.   if Column = IsWebColumn then
  14.   begin
  15.     r := CellRect;
  16.  
  17.     data := Grid.GetNodeData(Node);
  18.     size.cx := GetSystemMetrics(SM_CXMENUCHECK);
  19.     size.cy := GetSystemMetrics(SM_CYMENUCHECK);
  20.  
  21.     r.Top    := CellRect.Top + (CellRect.Bottom - CellRect.Top - size.cy) div 2;
  22.     r.Bottom := r.Top + size.cy;
  23.     r.Left   := r.Left + PADDING;
  24.     r.Right  := r.Left + size.cx;
  25.  
  26.     if data^.IsWeb=1 then
  27.       Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal)
  28.     else
  29.       Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);
  30.  
  31.     ThemeServices.DrawElement(TargetCanvas.Handle, Details, r, nil);
  32.  
  33.     CloseThemeData(h);
  34.   end;
  35. end;
  36.  

 

TinyPortal © 2005-2018