Widget
2007-06-03 04:23:09
Well, here goes: My first tutorial.
Why get rid of the title bar?
It looks cooler :P. Also, it can mess up the coordinates of your objects with different skins on their computers.
So here we go!
First, we start out with a basic form:
(The with operator makes it so you don't have to type in the name of the object for cleaner code)
Now we need a close button, because once you have no taskbar, you have no way to close it without closing the SCAR window too.
So We'll make a Close:TButton;
Great, the form closes. Now under the main form, we add:
Now all we need is some way to move the form around. After quite a bit of experimentation I came up with this, which responds to the OnMouseDown event:
And stick it on to the main form:
Yay, we have a working borderless form!
But it looks oh, so ugly!
The first thing I think we should do is hide SCAR while the form is up so it doesn't leave behind an imprint of itself until you let go of the mouse.
In the main loop we can do:
But we need it to look pretty! Let's make a canvas to play on. We create:
Now we need a 1x500 bitmap. I used:
Then in the InitForm procedure, we stick in:
This strechtes the 1x500 bitmap onto the 250x500 canvas, keeping it 250 times smaller than it could be.
But why not make a border? I say a white two pixel border around it should be fine. We make a 1x1 bitmap:
And voila! We're done! Your script is now ten times more leet than it was before :D
Here's the finished script:
I hope this made sense :P
- Widget
Why get rid of the title bar?
It looks cooler :P. Also, it can mess up the coordinates of your objects with different skins on their computers.
So here we go!
First, we start out with a basic form:
(The with operator makes it so you don't have to type in the name of the object for cleaner code)
program FormTemplate;
var WidgetForm:TForm;
procedure MakeForm;
begin
WidgetForm := CreateForm;
with WidgetForm do
begin
Caption := 'Captions won''t even be visible with this';
Position := poScreenCenter;
Width := 250;
Height := 500;
Color := clBlack;
Font.Color := clRed;
end;
end;
procedure SafeShowWF;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('MakeForm', tva);
end;
procedure ShowFormModal;
begin
WidgetForm.ShowModal
end;
procedure SafeShowFormModal;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('ShowFormModal', tva);
end;
procedure Form;
begin
SafeShowWF;
SafeShowFormModal;
end;
begin
Form;
end.Now we need a close button, because once you have no taskbar, you have no way to close it without closing the SCAR window too.
So We'll make a Close:TButton;
Close := TButton.Create(WidgetForm);
with Close do
begin
Parent := WidgetForm;
Top := 225;
Left := 100;
Width := 50;
Height := 25;
Caption := 'Close';
ModalResult := mrOk;
end;Great, the form closes. Now under the main form, we add:
BorderStyle := bsNone;which eliminates the border. Now all we need is some way to move the form around. After quite a bit of experimentation I came up with this, which responds to the OnMouseDown event:
procedure DragForm(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var sx,sy,tx,ty:integer;
begin
getmousepos(tx,ty);
repeat
getmousepos(sx,sy);
WidgetForm.Top := WidgetForm.Top - (ty-sy);
WidgetForm.Left := WidgetForm.Left - (tx-sx);
sleep(1);
tx := sx;
ty := sy;
until (not IsMouseButtonDown(True));
end;And stick it on to the main form:
OnMouseDown := @DragForm;Yay, we have a working borderless form!
program FormTemplate;
var WidgetForm:TForm;
Close:TButton;
procedure DragForm(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var sx,sy,tx,ty:integer;
begin
getmousepos(tx,ty);
repeat
getmousepos(sx,sy);
WidgetForm.Top := WidgetForm.Top - (ty-sy);
WidgetForm.Left := WidgetForm.Left - (tx-sx);
sleep(1);
tx := sx;
ty := sy;
until (not IsMouseButtonDown(True));
end;
procedure MakeForm;
begin
WidgetForm := CreateForm;
with WidgetForm do
begin
Caption := 'Captions won''t even be visible with this';
Position := poScreenCenter;
Width := 250;
Height := 500;
Color := clBlack;
Font.Color := clRed;
BorderStyle := bsNone;
OnMouseDown := @DragForm;
end;
Close := TButton.Create(WidgetForm);
with Close do
begin
Parent := WidgetForm;
Top := 225;
Left := 100;
Width := 50;
Height := 25;
Caption := 'Close';
ModalResult := mrOk;
end;
end;
procedure SafeShowWF;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('MakeForm', tva);
end;
procedure ShowFormModal;
begin
WidgetForm.ShowModal
end;
procedure SafeShowFormModal;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('ShowFormModal', tva);
end;
procedure Form;
begin
SafeShowWF;
SafeShowFormModal;
end;
begin
Form;
end.But it looks oh, so ugly!
The first thing I think we should do is hide SCAR while the form is up so it doesn't leave behind an imprint of itself until you let go of the mouse.
In the main loop we can do:
begin
GetSelf.Visible := False;
Form;
GetSelf.Visible := True;
end.And if you want, you can Disguise() to the title of your choice in the explorer bar.But we need it to look pretty! Let's make a canvas to play on. We create:
Background := TImage.Create(WidgetForm)
with Background do
begin
Parent := WidgetForm;
Top := 0;
Left := 0;
Height := 500;
Width := 250;
OnMouseDown := @DragForm;
end;Now we need a 1x500 bitmap. I used:
b := BitmapFromString(1, 500, 'z78DAA596496EDD301044AF448A43' +
'37971ABEEE7FA420AF15A81042C24FECC533608BD5644FA894FEF' +
'CE4039EBFB9F097855F4B810D76E870C00DEEF003512819A2502A' +
'44A118E46C5921670BD10B67F93C55CE56A257CE56A257A257142' +
'AD12B0A95E815053E4F0D858642E34F0D85C61D1A0A8D3B34741A' +
'3A0D9D860E9FA7CE5B3A6A1DB5CE153B9A1DB5CEAD3A6A1D9D8E0' +
'EFF4CC659E394216A7C6F7C6F44373260C475223AA79C53CE2947' +
'CEB9B973D639EB9C75223A0A7C92063A833B8F2AE4E603CD61421' +
'78E7FA44FB4895DA2B7E95671CF4598EFB7C4BBAE37C67B77E126' +
'3989FCB8642CB2D7249F45321CD94E77FEED2315D984ABD42E685' +
'2D326552E52F77C77423FEFDEB87848CF0437E9A5E010BAD026F6' +
'1FD31EE80FD4BBAD1337A1BEF1106A364E999A24D9CB92CF22AC9' +
'2F926B53061546A0875EE76E121D53F651E93F489CE66918EAAD2' +
'637D9A5997CE9CE777934E3EA6899EE75AA73B4F53535EA75E67B' +
'F3FEC017B98E8FFDB0FBA0D9ADC2DC94B87646F915AAC52D34526' +
'68971EF387FED7EE1D5FECE7366DE643AA5FA4A63EEDDE53F2AFD' +
'9B61F6CD4F14515DE37EDCCA7DD5BA7CE99F770FEBB03AF9D7C4E' +
'BD7A4C5B7A7BD8D2F3AE9E37F6D3DE7EDADEF30ED719D74D3EA64' +
'DFECD3E7FDFEAEFFB7CBC766C137751C56F2CC27C3B93702917C3' +
'B71CE26476F136AB781E179AF8A2F048555C5338A82C9E2ADD2EE' +
'B725C8778B0F063AB38B4706B26FE2DBC5C1577174E2FDFDE2F7C' +
'60F908C3256EE21B87D0844D58C58506D3CD70AA976B3DC4C786A' +
'75DC5E586E335F1C0E187AB38E470CBF9F6CFE1A5F347DCF52E24' +
'4A264A264A264A264A264A6E42626562E5E517E1A851E0');Then in the InitForm procedure, we stick in:
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,500,0,0,250,500)This strechtes the 1x500 bitmap onto the 250x500 canvas, keeping it 250 times smaller than it could be.
But why not make a border? I say a white two pixel border around it should be fine. We make a 1x1 bitmap:
b := BitmapFromString(1, 1, 'FFFFFF');FFFFF is the hex color, in RGB (SCAR usually uses BGR). Now we copy it onto the edges of the canvas: SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,0,2,500)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,248,0,250,500)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,0,250,2)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,498,250,500)And voila! We're done! Your script is now ten times more leet than it was before :D
Here's the finished script:
program FormTemplate;
var WidgetForm:TForm;
Close:TButton;
Background:TImage;
b:integer;
procedure DragForm(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var sx,sy,tx,ty:integer;
begin
getmousepos(tx,ty);
repeat
getmousepos(sx,sy);
WidgetForm.Top := WidgetForm.Top - (ty-sy);
WidgetForm.Left := WidgetForm.Left - (tx-sx);
sleep(1);
tx := sx;
ty := sy;
until (not IsMouseButtonDown(True));
end;
procedure MakeForm;
begin
WidgetForm := CreateForm;
with WidgetForm do
begin
Caption := 'Captions won''t even be visible with this';
Position := poScreenCenter;
Width := 250;
Height := 500;
Color := clBlack;
Font.Color := clRed;
BorderStyle := bsNone;
OnMouseDown := @DragForm;
end;
Close := TButton.Create(WidgetForm);
with Close do
begin
Parent := WidgetForm;
Top := 225;
Left := 100;
Width := 50;
Height := 25;
Caption := 'Close';
ModalResult := mrOk;
end;
Background := TImage.Create(WidgetForm)
with Background do
begin
Parent := WidgetForm;
Top := 0;
Left := 0;
Height := 500;
Width := 250;
OnMouseDown := @DragForm;
end;
b := BitmapFromString(1, 500, 'z78DAA596496EDD301044AF448A43' +
'37971ABEEE7FA420AF15A81042C24FECC533608BD5644FA894FEF' +
'CE4039EBFB9F097855F4B810D76E870C00DEEF003512819A2502A' +
'44A118E46C5921670BD10B67F93C55CE56A257CE56A257A257142' +
'AD12B0A95E815053E4F0D858642E34F0D85C61D1A0A8D3B34741A' +
'3A0D9D860E9FA7CE5B3A6A1DB5CE153B9A1DB5CEAD3A6A1D9D8E0' +
'EFF4CC659E394216A7C6F7C6F44373260C475223AA79C53CE2947' +
'CEB9B973D639EB9C75223A0A7C92063A833B8F2AE4E603CD61421' +
'78E7FA44FB4895DA2B7E95671CF4598EFB7C4BBAE37C67B77E126' +
'3989FCB8642CB2D7249F45321CD94E77FEED2315D984ABD42E685' +
'2D326552E52F77C77423FEFDEB87848CF0437E9A5E010BAD026F6' +
'1FD31EE80FD4BBAD1337A1BEF1106A364E999A24D9CB92CF22AC9' +
'2F926B53061546A0875EE76E121D53F651E93F489CE66918EAAD2' +
'637D9A5997CE9CE777934E3EA6899EE75AA73B4F53535EA75E67B' +
'F3FEC017B98E8FFDB0FBA0D9ADC2DC94B87646F915AAC52D34526' +
'68971EF387FED7EE1D5FECE7366DE643AA5FA4A63EEDDE53F2AFD' +
'9B61F6CD4F14515DE37EDCCA7DD5BA7CE99F770FEBB03AF9D7C4E' +
'BD7A4C5B7A7BD8D2F3AE9E37F6D3DE7EDADEF30ED719D74D3EA64' +
'DFECD3E7FDFEAEFFB7CBC766C137751C56F2CC27C3B93702917C3' +
'B71CE26476F136AB781E179AF8A2F048555C5338A82C9E2ADD2EE' +
'B725C8778B0F063AB38B4706B26FE2DBC5C1577174E2FDFDE2F7C' +
'60F908C3256EE21B87D0844D58C58506D3CD70AA976B3DC4C786A' +
'75DC5E586E335F1C0E187AB38E470CBF9F6CFE1A5F347DCF52E24' +
'4A264A264A264A264A264A6E42626562E5E517E1A851E0');
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,500,0,0,250,500)
b := BitmapFromString(1, 1, 'FFFFFF');
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,0,2,500)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,248,0,250,500)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,0,250,2)
SafeCopyCanvas(GetBitmapCanvas(b),Background.Canvas,0,0,1,1,0,498,250,500)
end;
procedure SafeShowWF;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('MakeForm', tva);
end;
procedure ShowFormModal;
begin
WidgetForm.ShowModal
end;
procedure SafeShowFormModal;
var
tva: TVariantArray;
begin
setarraylength(tva, 0);
ThreadSafeCall('ShowFormModal', tva);
end;
procedure Form;
begin
SafeShowWF;
SafeShowFormModal;
end;
begin
GetSelf.Visible := False;
Form;
GetSelf.Visible := True;
end.I hope this made sense :P
- Widget
The whole thing is self coloring so it'll look pretty no matter what bitmap you stick on it :D