📄 suiform.pas
字号:
begin
Buf := TBitmap.Create();
Bmp := TBitmap.Create();
try
Buf.Width := Width;
Buf.Height := Height;
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Bmp.LoadFromResourceName(hInstance, 'MACOS_FORM_BACKGROUND')
else
{$ENDIF}
Bmp.LoadFromResourceName(hInstance, 'PROTEIN_FORM_BACKGROUND');
Buf.Canvas.Brush.Bitmap := Bmp;
Buf.Canvas.FillRect(ClientRect);
BitBlt(Canvas.Handle, 0, 0, Width, Height, Buf.Canvas.Handle, 0, 0, SRCCOPY);
finally
Bmp.Free();
Buf.Free();
end;
end
else
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ClientRect);
end;
PaintFormBorder();
end;
procedure TsuiForm.PaintFormBorder();
var
R, R2 : TRect;
ACanvas : TCanvas;
Bmp : TBitmap;
nLeft, nRight : Integer;
Tmp : TBitmap;
H : Integer;
OutUIStyle : TsuiUIStyle;
FiveSec : Boolean;
BottomBuf : TBitmap;
begin
if m_Destroyed then
Exit;
if (m_Form = nil) or (not m_Form.HandleAllocated) then
begin
inherited;
Exit;
end;
if (m_Form.WindowState = wsMinimized) and (not (csDesigning in ComponentState)) then
Exit;
ACanvas := TCanvas.Create();
ACanvas.Handle := GetWindowDC(m_Form.Handle);
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
if TitleBarVisible and m_TitleBar.CanPaint() then
begin
m_TitleBar.GetTitleImage(-2, Tmp);
R := Rect(0, 0, Max(m_LeftBorderWidth, 4), Tmp.Height);
ACanvas.CopyRect(R, Tmp.Canvas, R);
R := Rect(0, 0, Tmp.Width, 3);
ACanvas.CopyRect(R, Tmp.Canvas, R);
R := Rect(Tmp.Width - Max(4, m_RightBorderWidth), 0, Tmp.Width, Tmp.Height);
R2 := Rect(m_Form.Width - Max(4, m_RightBorderWidth), 0, m_Form.Width, Tmp.Height);
ACanvas.CopyRect(R2, Tmp.Canvas, R);
end;
if m_TitleBar.Visible then
H := m_TitleBar.Height + 3
else
H := 0;
// left border
Tmp := m_FileTheme.GetBitmap(SKIN2_FORMLEFTBORDER);
R := Rect(0, H, Tmp.Width, m_Form.Height - m_BottomBorderWidth);
ACanvas.StretchDraw(R, Tmp);
if Tmp.Width < 4 then
begin
R := Rect(Tmp.Width, H, 4, m_Form.Height - m_BottomBorderWidth);
ACanvas.Brush.Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
ACanvas.FillRect(R);
if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
begin
R := Rect(Tmp.Width, 3 + m_TitleBar.Height, 4, 3 + m_TitleBar.Height + m_MenuBar.Height);
if MenuBarColor = MenuBarToColor then
begin
ACanvas.Brush.Color := m_MenuBar.Color;
ACanvas.FillRect(R);
end
else
begin
DrawHorizontalGradient(ACanvas, R, MenuBarColor, MenuBarToColor);
end;
end;
end;
// right border
Tmp := m_FileTheme.GetBitmap(SKIN2_FORMRIGHTBORDER);
R := Rect(m_Form.Width - Tmp.Width, H, m_Form.Width, m_Form.Height - m_BottomBorderWidth);
ACanvas.StretchDraw(R, Tmp);
if Tmp.Width < 4 then
begin
R := Rect(m_Form.Width - 4, H, m_Form.Width - Tmp.Width, m_Form.Height - m_BottomBorderWidth);
ACanvas.Brush.Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
ACanvas.FillRect(R);
if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
begin
R := Rect(m_Form.Width - 4, 3 + m_TitleBar.Height, m_Form.Width - Tmp.Width, 3 + m_TitleBar.Height + m_MenuBar.Height);
if MenuBarColor = MenuBarToColor then
begin
ACanvas.Brush.Color := m_MenuBar.Color;
ACanvas.FillRect(R);
end
else
begin
DrawHorizontalGradient(ACanvas, R, MenuBarColor, MenuBarToColor);
end;
end;
end;
// bottom border
FiveSec := m_FileTheme.GetBool(SKIN2_BOTTOMBORDERTHREESECT);
m_BottomBufRgn.Width := m_Form.Width;
Tmp := m_FileTheme.GetBitmap(SKIN2_FORMBOTTOMBORDER1);
m_BottomBufRgn.Height := Tmp.Height;
if FiveSec then
begin
m_BottomBufRgn.Canvas.Draw(0, 0, Tmp);
R.Left := Tmp.Width;
R.Top := 0;
R.Bottom := Tmp.Height;
Tmp := m_FileTheme.GetBitmap(SKIN2_FORMBOTTOMBORDER3);
m_BottomBufRgn.Canvas.Draw(m_Form.Width - Tmp.Width, 0, Tmp);
R.Right := m_Form.Width - Tmp.Width;
Tmp := m_FileTheme.GetBitmap(SKIN2_FORMBOTTOMBORDER2);
m_BottomBufRgn.Canvas.StretchDraw(R, Tmp);
end
else
begin
SpitDrawHorizontal2(Tmp, m_BottomBufRgn.Canvas, Rect(0, 0, m_Form.Width, m_BottomBufRgn.Height), false, m_TransparentColor);
end;
if m_BottomNeedRegion then
begin
BottomBuf := TBitmap.Create();
BottomBuf.PixelFormat := pf24Bit;
BottomBuf.Width := m_BottomBufRgn.Width;
BottomBuf.Height := m_BottomBufRgn.Height;
BottomBuf.Canvas.Brush.Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
R := Rect(0, 0, BottomBuf.Width, BottomBuf.Height);
BottomBuf.Canvas.FillRect(R);
BottomBuf.Canvas.Draw(0, 0, m_BottomBufRgn);
R := Rect(0, m_Form.Height - m_BottomBorderWidth, m_Form.Width, m_Form.Height);
BitBlt(ACanvas.Handle, R.Left, R.Top, BottomBuf.Width, BottomBuf.Height, BottomBuf.Canvas.Handle, 0, 0, SRCCOPY);
BottomBuf.Free();
end
else
begin
R := Rect(0, m_Form.Height - m_BottomBorderWidth, m_Form.Width, m_Form.Height);
BitBlt(ACanvas.Handle, R.Left, R.Top, m_BottomBufRgn.Width, m_BottomBufRgn.Height, m_BottomBufRgn.Canvas.Handle, 0, 0, SRCCOPY);
end;
if m_BottomBorderWidth < 4 then
begin
R := Rect(m_LeftBorderWidth, m_Form.Height - 4, m_Form.Width - m_RightBorderWidth, m_Form.Height - m_BottomBorderWidth);
ACanvas.Brush.Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
ACanvas.FillRect(R);
end;
end
else // for builtin skins
begin
if TitleBarVisible and m_TitleBar.CanPaint() then
begin
Tmp := TBitmap.Create();
m_TitleBar.GetTitleImage(0, Bmp);
Tmp.Width := 3 - m_Width;
Tmp.Height := Bmp.Height;
Tmp.Canvas.Draw(0, 0, Bmp);
ACanvas.Draw(m_Width, 0, Tmp);
m_TitleBar.GetTitleImage(1, Bmp);
if Bmp.Width < 3 then
Tmp.Canvas.StretchDraw(Rect(0, 0, Tmp.Width, Tmp.Height), Bmp)
else
Tmp.Canvas.Draw(2 - Bmp.Width, 0, Bmp);
ACanvas.Draw(m_Form.Width - 3, 0, Tmp);
Tmp.Width := m_Form.Width - 5;
Tmp.Height := 3;
m_TitleBar.GetTitleImage(0, Bmp);
Tmp.Canvas.Draw(-2, 0, Bmp);
nLeft := Bmp.Width - 2;
m_TitleBar.GetTitleImage(1, Bmp);
nRight := Tmp.Width - Bmp.Width + 3;
Tmp.Canvas.Draw(nRight, 0, Bmp);
m_TitleBar.GetTitleImage(2, Bmp);
Tmp.Canvas.StretchDraw(Rect(nLeft, 0, nRight, Bmp.Height), Bmp);
ACanvas.Draw(2, 0, Tmp);
if (m_Width = 1) and (RoundCorner = 11) and not (csDesigning in ComponentState) then
begin
ACanvas.Pen.Color := m_Color;
ACanvas.Arc(m_Form.Width - RoundCorner * 2 + 1, -1, m_Form.Width + 1, RoundCorner * 2 - 1, m_Form.Width + 1, RoundCorner - 1, m_Form.Width - RoundCorner + 1, -1);
ACanvas.Arc(-1, -1, RoundCorner * 2 - 1, RoundCorner * 2 - 1, RoundCorner - 1, -1, - 1, RoundCorner - 1);
end;
Tmp.Free();
end
else if not TitleBarVisible then
begin
ACanvas.Brush.Color := m_Color;
R := Rect(0, 0, m_Form.Width, 1);
ACanvas.FillRect(R);
ACanvas.Brush.Color := Color;
R := Rect(m_Width, 1, m_Form.Width - m_Width, 3);
ACanvas.FillRect(R);
end;
ACanvas.Brush.Color := m_Color;
R := Rect(0, 0, m_Width, m_Form.Height);
ACanvas.FillRect(R);
R := Rect(0, m_Form.Height - m_Width, m_Form.Width, m_Form.Height);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - m_Width, m_Form.Height, m_Form.Width, 0);
ACanvas.FillRect(R);
ACanvas.Brush.Color := Color;
if m_Width < 4 then
begin
R := Rect(m_Width, m_Form.Height - 2, m_Form.Width - m_Width, m_Form.Height - m_Width);
ACanvas.FillRect(R);
end;
if m_Width < 4 then
begin
R := Rect(m_Width, TitleBarHeight + MenuBarHeight, 3, m_Form.Height - m_Width);
ACanvas.FillRect(R);
R := Rect(m_Form.Width - 3, m_Form.Height - m_Width, m_Form.Width - m_Width, TitleBarHeight + MenuBarHeight);
ACanvas.FillRect(R);
if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
begin
R := Rect(m_Width, TitleBarHeight, 3, TitleBarHeight + m_MenuBar.Height);
if MenuBarColor <> MenuBarToColor then
DrawHorizontalGradient(ACanvas, R, MenuBarColor, MenuBarToColor)
else
begin
ACanvas.Brush.Color := m_MenuBar.Color;
ACanvas.FillRect(R);
end;
R := Rect(m_Form.Width - 3, TitleBarHeight, m_Form.Width - m_Width, TitleBarHeight + m_MenuBar.Height);
if MenuBarColor <> MenuBarToColor then
DrawHorizontalGradient(ACanvas, R, MenuBarColor, MenuBarToColor)
else
begin
ACanvas.FillRect(R);
end;
end;
end;
end;
ReleaseDC(m_Form.Handle, ACanvas.Handle);
ACanvas.Free();
end;
procedure TsuiForm.ProcessKeyPress(var Msg: TMessage);
begin
if m_Destroyed then
Exit;
if (not FormHasFocus(m_Form)) or (not m_Form.Active) then
Msg.Result := 0
else if not Assigned(Menu) then
Msg.Result := 0
else if m_Menu.IsShortCut(TWMKEY(Msg)) then
Msg.Result := 1
else
Msg.Result := 0;
end;
procedure TsuiForm.ReAssign;
begin
if WS_CAPTION and GetWindowLong(m_Form.Handle, GWL_STYLE) <> 0 then
begin
SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));
SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
end;
end;
procedure SetBitmapWindow(
HandleOfWnd : HWND;
const TitleBmp, BottomBmp : TBitmap;
TitleNeedRegion, BottomNeedRegion : Boolean;
TitleMin, TitleMax, BottomMin, BottomMax,
TransColor : TColor; Height, Width : Integer
);
var
i, j : Integer;
Left, Right : Integer;
PreWhite : Boolean;
TempRgn : HRgn;
Rgn : HRgn;
TitleHeight, BottomHeight, Offset : Integer;
X, Y : Integer;
begin
Rgn := CreateRectRgn(0, 0, 0, 0);
if TitleNeedRegion then
TitleHeight := TitleBmp.Height
else
TitleHeight := 0;
if BottomNeedRegion then
BottomHeight := BottomBmp.Height
else
BottomHeight := 0;
if TitleNeedRegion then
begin
if TitleMin = -1 then
X := 0
else
X := TitleMin;
if TitleMax > TitleMin then
Y := TitleMax + 1
else
Y := TitleBmp.Height;
if TitleMin > 0 then
begin
TempRgn := CreateRectRgn(0, 0, Width, TitleMin);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
DeleteObject(TempRgn);
end;
for i := X to Y - 1 do
begin
Left := 0;
Right := 0;
PreWhite := true;
for j := 0 to TitleBmp.Width - 1 do
begin
if (
(TitleBmp.Canvas.Pixels[j, i] = TransColor) or
(j = TitleBmp.Width - 1)
) then
begin
if (j = TitleBmp.Width - 1) and (TitleBmp.Canvas.Pixels[j, i] <> TransColor) then
begin
TempRgn := CreateRectRgn(Left, i, j + 1, i + 1);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
DeleteObject(TempRgn);
end
else if not PreWhite then
begin
TempRgn := CreateRectRgn(Left, i, Right + 1, i + 1);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
DeleteObject(TempRgn);
end;
PreWhite := true;
end
else
begin
if PreWhite then
begin
Left := j;
Right := j;
end
else
Inc(Right);
PreWhite := false;
end;
end;
end;
if Y < TitleBmp.Height then
begin
TempRgn := CreateRectRgn(0, Y, Width, TitleBmp.Height);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
DeleteObject(TempRgn);
end;
end;
TempRgn := CreateRectRgn(0, TitleHeight, Width, Height - BottomHeight);
CombineRgn(Rgn, Rgn, TempRgn, RGN_OR);
DeleteObject(TempRgn);
if BottomNeedRegion then
begin
Offset := Height - BottomHeight;
if BottomMin = -1 then
X := 0
else
X := BottomMin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -