Advertisement
TLama

Untitled

Feb 9th, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.74 KB | None | 0 0
  1. uses
  2.   JvTabBar;
  3.  
  4. type
  5.   TJvModernTabBarPainter = class(JvTabBar.TJvModernTabBarPainter)
  6.   protected
  7.     procedure DrawTab(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect); override;
  8.     function GetCloseRect(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect): TRect; override;
  9.   end;
  10.  
  11. implementation
  12.  
  13. { TJvModernTabBarPainter }
  14.  
  15. procedure TJvModernTabBarPainter.DrawTab(Canvas: TCanvas; Tab: TJvTabBarItem; R: TRect);
  16. var
  17.   CloseR: TRect;
  18. begin
  19.   with Canvas do
  20.   begin
  21.     Brush.Style := bsSolid;
  22.     Brush.Color := Color;
  23.     Pen.Mode := pmCopy;
  24.     Pen.Style := psSolid;
  25.     Pen.Width := 1;
  26.  
  27.     if Tab.Selected then
  28.     begin
  29.       Brush.Style := bsSolid;
  30.       Brush.Color := TabColor;
  31.       FillRect(R);
  32.  
  33.       Pen.Color := ControlDivideColor;
  34.       if Tab.TabBar.Orientation = toBottom then
  35.       begin
  36.         MoveTo(R.Left, R.Top);
  37.         LineTo(R.Left, R.Bottom - 1);
  38.         LineTo(R.Right - 1, R.Bottom - 1);
  39.         LineTo(R.Right - 1, R.Top - 1{end});
  40.       end
  41.       else // toTop
  42.       begin
  43.         MoveTo(R.Left, R.Bottom - 1);
  44.         LineTo(R.Left, R.Top);
  45.         LineTo(R.Right - 1, R.Top);
  46.         LineTo(R.Right - 1, R.Bottom - 1 + 1{end});
  47.       end;
  48.     end;
  49.  
  50.     if Tab.Enabled and not Tab.Selected and Tab.Hot then
  51.     begin
  52.       // hot
  53.       Pen.Color := DividerColor;
  54.       MoveTo(R.Left, R.Top);
  55.       LineTo(R.Right - 1 - 1, R.Top);
  56.     end;
  57.  
  58.     if Tab.TabBar.CloseButton then
  59.     begin
  60.       // close button color
  61.       if Tab.Selected then
  62.         Brush.Color := CloseColorSelected
  63.       else
  64.         Brush.Color := CloseColor;
  65.  
  66.       CloseR := GetCloseRect(Canvas, Tab, R);
  67.       Pen.Color := CloseRectColor;
  68.       if not Tab.Enabled then
  69.         Pen.Color := CloseRectColorDisabled;
  70.  
  71.       if Tab.Closing then
  72.         // shrink
  73.         Rectangle(CloseR.Left + 1, CloseR.Top + 1, CloseR.Right - 1, CloseR.Bottom - 1)
  74.       else
  75.         Rectangle(CloseR);
  76.  
  77.       if Tab.Modified then
  78.         Pen.Color := ModifiedCrossColor
  79.       else
  80.       if Tab.Selected and not Tab.Closing then
  81.         Pen.Color := CloseCrossColorSelected
  82.       else
  83.       if Tab.Enabled then
  84.         Pen.Color := CloseCrossColor
  85.       else
  86.         Pen.Color := CloseCrossColorDisabled;
  87.  
  88.       // close cross
  89.       MoveTo(CloseR.Left + 3, CloseR.Top + 3);
  90.       LineTo(CloseR.Right - 3, CloseR.Bottom - 3);
  91.       MoveTo(CloseR.Left + 4, CloseR.Top + 3);
  92.       LineTo(CloseR.Right - 4, CloseR.Bottom - 3);
  93.  
  94.       MoveTo(CloseR.Right - 4, CloseR.Top + 3);
  95.       LineTo(CloseR.Left + 2, CloseR.Bottom - 3);
  96.       MoveTo(CloseR.Right - 5, CloseR.Top + 3);
  97.       LineTo(CloseR.Left + 3, CloseR.Bottom - 3);
  98.  
  99.       // remove intersection
  100.       if Tab.Modified then
  101.         FillRect(Rect(CloseR.Left + 5, CloseR.Top + 4, CloseR.Right - 5, CloseR.Bottom - 4));
  102.  
  103.       R.Right := CloseR.Left;
  104.     end;
  105.  
  106.     InflateRect(R, -1, -1);
  107.  
  108.     if not Tab.TabBar.CloseButton then
  109.       Inc(R.Left, 2);
  110.  
  111.     if (Tab.ImageIndex <> -1) and (Tab.GetImages <> nil) then
  112.     begin
  113.       Tab.GetImages.Draw(Canvas, R.Left, R.Top + (R.Bottom - R.Top - Tab.GetImages.Height) div 2,
  114.         Tab.ImageIndex, Tab.Enabled);
  115.       Inc(R.Left, Tab.GetImages.Width + 2);
  116.     end;
  117.  
  118.     if Tab.Enabled then
  119.     begin
  120.       if Tab.Selected then
  121.         Font.Assign(Self.SelectedFont)
  122.       else
  123.         Font.Assign(Self.Font);
  124.     end
  125.     else
  126.       Font.Assign(Self.DisabledFont);
  127.  
  128.     Brush.Style := bsClear;
  129.     TextRect(R, R.Left + 3, R.Top + 3, Tab.Caption);
  130.   end;
  131. end;
  132.  
  133. function TJvModernTabBarPainter.GetCloseRect(Canvas: TCanvas; Tab: TJvTabBarItem;
  134.   R: TRect): TRect;
  135. begin
  136.   Result.Left := R.Right - 17;
  137.   Result.Top :=  R.Top + 5;
  138.   Result.Right := Result.Left + 12;
  139.   Result.Bottom := Result.Top + 11;
  140. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement