⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxskinlabel.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit SXSkinLabel;

////////////////////////////////////////////////////////////////////////////////
// SXSkinComponents: Skinnable Visual Controls for Delphi and C++Builder      //
//----------------------------------------------------------------------------//
// Version: 1.2.1                                                             //
// Author: Alexey Sadovnikov                                                  //
// Web Site: http://www.saarixx.info/sxskincomponents/                        //
// E-Mail: sxskincomponents@saarixx.info                                      //
//----------------------------------------------------------------------------//
// LICENSE:                                                                   //
// 1. You may freely distribute this file.                                    //
// 2. You may not make any changes to this file.                              //
// 3. The only person who may change this file is Alexey Sadovnikov.          //
// 4. You may use this file in your freeware projects.                        //
// 5. If you want to use this file in your shareware or commercial project,   //
//    you should purchase a project license or a personal license of          //
//    SXSkinComponents: http://saarixx.info/sxskincomponents/en/purchase.htm  //
// 6. You may freely use, distribute and modify skins for SXSkinComponents.   //
// 7. You may create skins for SXSkinComponents.                              //
//----------------------------------------------------------------------------//
// Copyright (C) 2006-2007, Alexey Sadovnikov. All Rights Reserved.           //
////////////////////////////////////////////////////////////////////////////////

interface

{$I Compilers.inc}

uses Windows, Classes, SXSkinControl, GR32, StdCtrls, Dialogs, SysUtils,
     Messages, Controls, GR32_Blend, SXSkinLibrary, Types, Graphics;

type

 TSXSkinCustomLabel=class(TSXSkinCustomControl)
  private
   FAutoSizeWidth:Boolean;
   FAutoSizeHeight:Boolean;
   FWordWrap:Boolean;
   FTextLeftOffset:Integer;
   FTextTopOffset:Integer;
   FTextRightOffset:Integer;
   FTextBottomOffset:Integer;
   FAlignment:TAlignment;
   FVerticalAlignment:TVerticalAlignment;
   FUseCustomFont:Boolean;
   FUseCustomFontColor:Boolean;
   FOnMouseEnter:TNotifyEvent;
   FOnMouseLeave:TNotifyEvent;
   //
   FMouseOver:Boolean;
   FTextRect:TRect;
   FTextBitmap:TBitmap32;
   FLastFontData:TSXFontData;
   procedure SetCaption(const Value:TCaption);
   procedure SetAlignment(Value:TAlignment);
   procedure SetVerticalAlignment(Value:TVerticalAlignment);
   procedure SetAutoSizeWidth(Value:Boolean);
   procedure SetAutoSizeHeight(Value:Boolean);
   procedure SetWordWrap(Value:Boolean);
   procedure SetTextLeftOffset(Value:Integer);
   procedure SetTextTopOffset(Value:Integer);
   procedure SetTextRightOffset(Value:Integer);
   procedure SetTextBottomOffset(Value:Integer);
   procedure SetUseCustomFont(Value:Boolean);
   procedure SetUseCustomFontColor(Value:Boolean);   
   function HasUnusualSkinStyle:Boolean;
   procedure GetCurrentLState(var LState:TSXSkinLabelStateParam);
   procedure ResetTextParams;
   procedure CMFontChanged(var Message:TMessage); message CM_FONTCHANGED;
   procedure CMEnabledChanged(var Message:TMessage); message CM_ENABLEDCHANGED;
  protected
   function NeedRepaintOnStateChange:Boolean;
   procedure Loaded; override;
   procedure InternalSetBounds(ALeft,ATop,AWidth,AHeight:Integer);
   function GetCaption:TCaption;
   procedure CMMouseEnter(var Msg:TMessage); message CM_MOUSEENTER;
   procedure CMMouseLeave(var Msg:TMessage); message CM_MOUSELEAVE;
   property Caption:TCaption read GetCaption write SetCaption;
   property TextLeftOffset:Integer read FTextLeftOffset write SetTextLeftOffset default 0;
   property TextTopOffset:Integer read FTextTopOffset write SetTextTopOffset default 0;
   property TextRightOffset:Integer read FTextRightOffset write SetTextRightOffset default 0;
   property TextBottomOffset:Integer read FTextBottomOffset write SetTextBottomOffset default 0;
   property WordWrap:Boolean read FWordWrap write SetWordWrap default False;
   property AutoSizeWidth:Boolean read FAutoSizeWidth write SetAutoSizeWidth default True;
   property AutoSizeHeight:Boolean read FAutoSizeHeight write SetAutoSizeHeight default True;
   property Alignment:TAlignment read FAlignment write SetAlignment default taLeftJustify;
   property VerticalAlignment:TVerticalAlignment read FVerticalAlignment write SetVerticalAlignment default taAlignTop;
   property SkinStyle stored HasUnusualSkinStyle;
   property UseCustomFont:Boolean read FUseCustomFont write SetUseCustomFont default False;
   property UseCustomFontColor:Boolean read FUseCustomFontColor write SetUseCustomFontColor default False;
  public
   procedure PaintRectToBitmap(DestCanvasHandle:HDC;DestCanvasRect:TRect;
              Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
              WithSubItems:Boolean); override;  
   procedure InvalidateText;
   procedure SetBounds(ALeft,ATop,AWidth,AHeight:Integer); override;
   procedure SkinChanged; override;
   constructor Create(AOwner:TComponent); override;
   destructor Destroy; override;
  published
   property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
   property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
 end;

 TSXSkinLabel=class(TSXSkinCustomLabel)
  published
   property Align;
   property Alignment;
   property Anchors;
   property AutoSizeWidth;
   property AutoSizeHeight;
   property Caption;
   property Color;
   property Constraints;
   property Cursor;
   property DragCursor;
   property Enabled;
   property Font;
   //property HintData;
   property ParentColor;
   property ParentFont;
   property ParentShowHint;
   property PopupMenu;
   property ShowHint;
   property SkinLibrary;
   property SkinStyle;
   property TextLeftOffset;
   property TextTopOffset;
   property TextRightOffset;
   property TextBottomOffset;
   property UseCustomFont;
   property UseCustomFontColor;
   property VerticalAlignment;
   property Visible;
   property WordWrap;
   property OnCanResize;
   property OnClick;
   property OnDblClick;
   property OnDragDrop;
   property OnDragOver;
   property OnEndDrag;
   property OnKeyDown;
   property OnKeyPress;
   property OnKeyUp;
   property OnMouseDown;
   property OnMouseEnter;
   property OnMouseLeave;
   property OnMouseMove;
   property OnMouseUp;
   property OnMouseWheel;
   property OnMouseWheelDown;
   property OnMouseWheelUp;
   property OnResize;
   property OnStartDrag;
 end;

implementation

uses Math, SXBitmap32Utils;

{ TSXSkinCustomLabel }

function TSXSkinCustomLabel.HasUnusualSkinStyle:Boolean;
begin
 Result:=SkinStyle<>'_Label';
end;

procedure TSXSkinCustomLabel.SetAlignment(Value:TAlignment);
begin
 if Value<>FAlignment then
  begin
   FAlignment:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetVerticalAlignment(Value:TVerticalAlignment);
begin
 if Value<>FVerticalAlignment then
  begin
   FVerticalAlignment:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetAutoSizeWidth(Value:Boolean);
begin
 if Value<>FAutoSizeWidth then
  begin
   FAutoSizeWidth:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetAutoSizeHeight(Value:Boolean);
begin
 if Value<>FAutoSizeHeight then
  begin
   FAutoSizeHeight:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetWordWrap(Value:Boolean);
begin
 if Value<>FWordWrap then
  begin
   FWordWrap:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetTextLeftOffset(Value:Integer);
begin
 if Value<>FTextLeftOffset then
  begin
   FTextLeftOffset:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetTextTopOffset(Value:Integer);
begin
 if Value<>FTextTopOffset then
  begin
   FTextTopOffset:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetTextRightOffset(Value:Integer);
begin
 if Value<>FTextRightOffset then
  begin
   FTextRightOffset:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetTextBottomOffset(Value:Integer);
begin
 if Value<>FTextBottomOffset then
  begin
   FTextBottomOffset:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetUseCustomFont(Value:Boolean);
begin
 if Value<>FUseCustomFont then
  begin
   FUseCustomFont:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.SetUseCustomFontColor(Value:Boolean);
begin
 if Value<>FUseCustomFontColor then
  begin
   FUseCustomFontColor:=Value;
   if not (csLoading in ComponentState) then
    begin
     InvalidateText;
     ResetTextParams;
     InvalidateText;
    end;
  end;
end;

procedure TSXSkinCustomLabel.GetCurrentLState(var LState:TSXSkinLabelStateParam);
var  A:Integer;
 Style:TSXSkinLabelStyle;

 procedure SetLStateFrom(const T:TSXSkinLabelStateParam);
 begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -