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

📄 sskinprovider.pas

📁 AlphaControls是一个Delphi标准控件的集合
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    Result := False;
    if Assigned(Form.ActiveMDIChild) and Assigned(Form.ActiveMDIChild.Menu) then begin
      for i := ItemProcessed to Form.ActiveMDIChild.Menu.Items.Count - 1 do begin
        LocalItem := Form.ActiveMDIChild.Menu.Items[i];

        // If MDI form and included other
        if (LocalItem.GroupIndex > ChangedIndex) and (LocalItem.GroupIndex <= CurrentIndex) then begin

          if not Assigned(LocalItem.OnMeasureItem) or
               not Assigned(LocalItem.OnAdvancedDrawItem) or
                 not LocalItem.Visible then Break;

          Result := (LocalItem.GroupIndex >= CurrentIndex);
          ChangedIndex := LocalItem.GroupIndex;

          j := i;
          while (j <= Form.ActiveMDIChild.Menu.Items.Count - 1) do begin
            LocalItem := Form.ActiveMDIChild.Menu.Items[j];
            if (LocalItem.GroupIndex > ChangedIndex) and (Index <= Form.Menu.Items.Count - 1) then Exit;
            w := 0;
            h := 0;
            LocalItem.OnMeasureItem(LocalItem, FsStyle.FCacheBmp.Canvas, w, h);
            ChangedIndex := LocalItem.GroupIndex;

            if x + w + Offs - SymbolWidth> Form.Width - 2 * BorderWidth - 6 - 2 * TForm(Form).BorderWidth then begin
              x := BorderWidth;
              inc(y, MenuHeight);
            end;

            r := Rect(x, y, x + w + Offs - SymbolWidth, y + MenuHeight);
            LocalItem.OnAdvancedDrawItem(LocalItem,
                                 FsStyle.FCacheBmp.Canvas, R, []);
            x := r.Right;
            ItemProcessed := i + 1;
            inc(j);
          end;
        end;
      end;
    end;
  end;
begin
  Offs := GetSystemMetrics(SM_CXMENUSIZE);
  Iconic := IsIconic(Form.Handle);
  CY := BorderHeight;
  h := 2 * CY + CaptionHeight;
  ItemProcessed := 0;
  SymbolWidth := 6;
  if Iconic then begin
    rForm := Rect(0, 0, IconicWidth, h - CY + 1);//IconicHeight);
  end
  else begin
    rForm := Rect(0, 0, Form.Width, Form.Height)
  end;
  if BGChanged then begin //and (FsStyle.FCacheBmp.Width <> Form.Width) and (FsStyle.FCacheBmp.Height <> Form.Height) then begin
    RgnChanged := True;
    ci.Ready := False;
    FsStyle.FCacheBmp.Width := Form.Width;
    FsStyle.FCacheBmp.Height := Form.Height;

    if IsValidSkinIndex(sStyle.SkinIndex) then begin
      // Paint body
      if (Form.BorderStyle <> bsNone) then begin
        PaintItem(sStyle.SkinIndex, sStyle.SkinSection, EmptyCI, False, integer(FormActive), rForm, Point(0, 0), FsStyle.FCacheBmp);
      end
      else begin
        PaintItemBG(sStyle.SkinIndex, sStyle.SkinSection, EmptyCI, integer(FormActive), rForm, Point(0, 0), FsStyle.FCacheBmp);
      end;

      // Prepare cache info
      ci.Bmp := FsStyle.FCacheBmp;
      ci.X := OffsetX; ci.Y := OffsetY;
      ci.Ready := True;

      if (Form.BorderStyle <> bsNone) then begin
        // Paint title
        i := GetSkinIndex(FormTitle);
        if Iconic and IsValidSkinIndex(i) then begin
          PaintItem(i, FormTitle, ci, True, integer(FormActive),
            Rect(0, 0, rForm.Right, rForm.Bottom),
            Point(0, 0), FsStyle.FCacheBmp);
        end
        else begin
          if IsValidSkinIndex(i) then
            PaintItem(i, FormTitle, ci, True, integer(FormActive),
              Rect(0, 0, rForm.Right, h - CY),
              Point(0, 0), FsStyle.FCacheBmp);
        end;
      end;

      if not Iconic then begin
        if (Form.BorderStyle <> bsNone) then begin
          // Paint title toolbar if exists
          i := sStyle.GetMaskIndex(NormalTitleBar);
          if IsValidImgIndex(i) then begin
            DrawMaskRect(FsStyle.FCacheBmp, ma[i].Bmp,
                   integer(FormActive),
                   Rect(Form.Width - BarWidth(i), 0, FsStyle.FCacheBmp.Width, h - CY),
                   ma[i].TransparentColor, True, EmptyCI);
          end;
        end;

        if (Form.Menu <> nil) and MenuPresent and (MenuHeight > 0) then begin
          LinesCount := GetLinesCount;

          // Paint menu bar
          i := GetSkinIndex(MenuLine);
          if IsValidSkinIndex(i) then
            PaintItem(i, MenuLine, ci, True, integer(FormActive),
              Rect(0, CaptionHeight + BorderHeight, FsStyle.FCacheBmp.Width, CaptionHeight + BorderHeight + LinesCount * MenuHeight + 1),
              Point(0, CaptionHeight + BorderHeight),
              FsStyle.FCacheBmp);

          // Store bg for Menu line
          MenuLineBmp.Width := Form.Width;
          MenuLineBmp.Height := LinesCount * MenuHeight + 1;
          BitBlt(MenuLineBmp.Canvas.Handle, 0, 0, MenuLineBmp.Width, MenuLineBmp.Height,
               FsStyle.FCacheBmp.Canvas.Handle, 0, BorderHeight + CaptionHeight, SRCCOPY);
//          Exit;
          //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

          // Draw maximized child form icon
          if ChildIconPresent and (MDISkinProvider = Self) then begin
            if Form.ActiveMDIChild.Icon.Handle <> 0 then begin
              DrawIconEx(sStyle.FCacheBmp.Canvas.Handle, BorderWidth + 1, CaptionHeight + BorderHeight + 1, Form.ActiveMDIChild.Icon.Handle, MenuHeight - 2, MenuHeight - 2, 0, 0, di_Normal);
            end
            else begin
              if Application.Icon.Handle <> 0 then begin
                DrawIconEx(sStyle.FCacheBmp.Canvas.Handle, BorderWidth + 1, CaptionHeight + BorderHeight + 1, Application.Icon.Handle, MenuHeight - 2, MenuHeight - 2, 0, 0, di_Normal);
              end
              else begin
                DrawIconEx(sStyle.FCacheBmp.Canvas.Handle, BorderWidth + 1, CaptionHeight + BorderHeight + 1, LoadIcon(0, IDI_APPLICATION), MenuHeight - 2, MenuHeight - 2, 0, 0, di_Normal);
              end;
            end;
          end;

          // Paint menu items
          x := BorderWidth;
          y := BorderHeight + CaptionHeight;// - 1;

          ChangedIndex := -1;
          Index := 0;
          while Index <= Form.Menu.Items.Count - 1 do begin
            w := 0;
            h := 0;
            CurrentItem := Form.Menu.Items[Index];
            if (CurrentItem.GroupIndex = ChangedIndex) or ProcessMerged(CurrentItem.GroupIndex) then begin
              inc(Index);
              continue;
            end
            else begin
              if not Assigned(CurrentItem.OnMeasureItem) or not Assigned(CurrentItem.OnAdvancedDrawItem) or
                                      not CurrentItem.Visible then Break;

              w := 0;
              h := 0;
              CurrentItem.OnMeasureItem(CurrentItem, FsStyle.FCacheBmp.Canvas, w, h);

              if x + w + Offs - SymbolWidth > Form.Width - 2 * BorderWidth - 6 - 2 * TForm(Form).BorderWidth then begin
                x := BorderWidth;
                inc(y, MenuHeight);
              end;

              r := Rect(x, y, x + w + Offs - SymbolWidth, y + MenuHeight);
              CurrentItem.OnAdvancedDrawItem(CurrentItem, FsStyle.FCacheBmp.Canvas, R, []);
              inc(x, w + Offs - SymbolWidth);
              inc(Index);
            end;
          end;
          ProcessMerged(99999);

          //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
          //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        end;

        if (Form.BorderStyle <> bsNone) then begin
          // Draw app icon
          if IconVisible then begin
            if TForm(Form).Icon.Handle <> 0 then begin
              DrawIconEx(FsStyle.FCacheBmp.Canvas.Handle, IconRect.Left, IconRect.Top, TForm(Form).Icon.Handle, WidthOf(IconRect), HeightOf(IconRect), 0, 0, di_Normal);
            end
            else begin
              if Application.Icon.Handle <> 0 then begin
                DrawIconEx(FsStyle.FCacheBmp.Canvas.Handle, IconRect.Left, IconRect.Top, Application.Icon.Handle, WidthOf(IconRect), HeightOf(IconRect), 0, 0, di_Normal);
              end
              else begin
                DrawIconEx(FsStyle.FCacheBmp.Canvas.Handle, IconRect.Left, IconRect.Top, LoadIcon(0, IDI_APPLICATION), WidthOf(IconRect), HeightOf(IconRect), 0, 0, di_Normal);
              end;
            end;
          end;

          if not Iconic then begin
            // Store bg for buttons
            TempBmp.Width := ButtonsCount * (ButtonWidth + 1) + BorderWidth;
            TempBmp.Height := HeaderHeight;//CaptionHeight + 2 * CY + 6;
            BitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height,
                   FsStyle.FCacheBmp.Canvas.Handle, Form.Width - TempBmp.Width - 1, 0, SRCCOPY);

            // Paint buttons
            PaintBorderIcons;
          end;

          // Out title text
          FsStyle.FCacheBmp.Canvas.Font.Assign(Form.Font);
          FsStyle.FCacheBmp.Canvas.Font.Style := FsStyle.FCacheBmp.Canvas.Font.Style + [fsBold];
          i := GetSkinIndex(FormTitle);
          if Iconic then begin
            s := CutText(FsStyle.FCacheBmp.Canvas, Form.Caption, rForm.right - IconRect.Right - 8);
          end
          else begin
            s := CutText(FsStyle.FCacheBmp.Canvas, Form.Caption, rForm.right - IconRect.Right - ButtonsCount * ButtonWidth - 16);
          end;
          r := Rect(BorderWidth + integer(IconVisible) * WidthOf(IconRect) + 4, CY, FsStyle.FCacheBmp.Canvas.TextWidth(s), CaptionHeight);
          WriteTextEx(FsStyle.FCacheBmp.Canvas, PChar(s), Form.Enabled, r, 0, i, FormActive);
        end;
      end;
      // Paint MDIArea
      if (Form.FormStyle = fsMDIForm) then begin
        if (Assigned(Form.ActiveMDIChild) and (Form.ActiveMDIChild.WindowState = wsMaximized)) then Exit;
        w := TsMDIForm(MDIForm).Width;
        h := TsMDIForm(MDIForm).Height;
        x := TsMDIForm(MDIForm).Left;
        y := TsMDIForm(MDIForm).Top;

        CI.Bmp := sStyle.FCacheBmp;
        CI.Ready := True;
        CI.X := 0;
        CI.Y := 0;
        i := GetSkinIndex(MDIArea);
        PaintItem(i, MDIArea, CI, False, 0, Rect(x, y, x + w, y + h), Point(x, y), sStyle.FCacheBmp.Canvas.Handle);
      end;
    end;
    // Paint shadows (currently n/a)
{    for i := 0 to Form.ControlCount - 1 do begin
      sc := GetsStyle(Form.Controls[i]);
//      if (csDestroying in Form.Controls[i].ComponentState) then Continue;
      if Assigned(sc) and (sc.SkinIndex > -1) and Form.Controls[i].Visible then begin
        sc.PaintShadow(sStyle.FCacheBmp.Canvas, OffsetX, OffsetY);
      end
      else
      if Assigned(sc) and (sc.COC > 0) and sc.Effects.Shadow.Enabled and Form.Controls[i].Visible then begin
        sc.PaintShadow(sStyle.FCacheBmp.Canvas, OffsetX, OffsetY);
      end;
    end;  }
  end;
end;

procedure TsSkinProvider.PaintBG;
var
  aRect: TRect;
  bmp : TBitmap;
  TransColor : TsColor;
  iDrawed : boolean;

  procedure FillCanvas(bmp : TBitmap); begin
    BMP.Canvas.Pen.Style := psClear;
    BMP.Canvas.Brush.Style := bsSolid;
    BMP.Canvas.Brush.Color := ColorToRGB(Form.Color);
    BMP.Canvas.Rectangle(aRect.Left, aRect.Top, aRect.Right + 1, aRect.Bottom + 1);
  end;
  procedure PaintAddons; var i : integer; begin
    iDrawed := False;
    // BGImage painting
    if (gd[sStyle.SkinIndex].ImagePercent > 0) then begin
      i := sStyle.GetMaskIndex(PatternFile);
      if (i > -1) and (ma[i].Bmp <> nil)
           and (ma[i].Bmp.Width <> 0)
           and (ma[i].Bmp.Height <> 0) then begin
        TileBitmap(sStyle.FCacheBmp.Canvas, aRect, ma[i].Bmp);
        iDrawed := True;
      end
      else begin
        FillCanvas(sStyle.FCacheBmp);
      end;
    end;
    // BGGradient painting
    if (gd[sStyle.SkinIndex].GradientPercent > 0) then begin
      if iDrawed then begin
        bmp := TBitmap.Create;
        bmp.PixelFormat := pf24bit;
        bmp.Width := Form.Width;
        bmp.Height := Form.Height;
        try

          if Length(gd[sStyle.SkinIndex].GradientData) > 0 then begin
            PaintGrad(Bmp, aRect, gd[sStyle.SkinIndex].GradientArray);
          end
          else begin
            FillCanvas(Bmp);
          end;

          TransColor.A := 0;
          TransColor.R := gd[sStyle.SkinIndex].ImagePercent * 256 div 100;
          TransColor.G := TransColor.R;
          TransColor.B := TransColor.R;

          SumBitmaps(sStyle.FCacheBmp, Bmp, TransColor);
        finally
          FreeAndNil(Bmp);
        end;
      end
      else begin
        if Length(gd[sStyle.SkinIndex].GradientData) > 0 then begin
          PaintGrad(sStyle.FCacheBmp, aRect, gd[sStyle.SkinIndex].GradientArray);
        end
        else begin
          FillCanvas(sStyle.FCacheBmp);
        end;
      end;
    end;
    if gd[sStyle.SkinIndex].GradientPercent + gd[sStyle.SkinIndex].ImagePercent in [1..100] then begin
      BlendColorRect(sStyle.FCacheBmp,
                                 Rect(0,
                                      0,
                                      sStyle.FCacheBmp.Width,
                                      sStyle.FCacheBmp.Height),
                         (gd[sStyle.SkinIndex].GradientPercent + gd[sStyle.SkinIndex].ImagePercent),
                 ColorToRGB(Form.Color));
    end
    else begin
      sStyle.FCacheBmp.Canvas.Pen.Style := psClear;
      sStyle.FCacheBmp.Canvas.Brush.Style := bsSolid;
      sStyle.FCacheBmp.Canvas.Brush.Color := ColorToRGB(Form.Color);
      sStyle.FCacheBmp.Canvas.Rectangle(aRect.Left, aRect.Top, aRect.Right + 1, aRect.Bottom + 1);
    end;
  end;
begin
  aRect := Rect(0, 0, Form.Width, Form.Height);
  PaintAddons;

{
  wc := Form;//TWinControl(FOwner);
  for i := 0 to wc.ControlCount - 1 do begin
    sc := GetsStyle(wc.Controls[i]);
    if (csDestroying in wc.Controls[i].ComponentState) then break;

    if Assigned(sc) and (sc.SkinIndex > -1) and wc.Controls[i].Visible then begin
      sc.PaintShadow(sStyle.FCacheBmp.Canvas, OffsetX, OffsetY);
    end
    els

⌨️ 快捷键说明

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