SRL Archive - OSR Advanced Scripting Tutorials

How to Make a Form Without a Title Bar


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)
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

Santa_Clause

2007-06-03 04:25:17

Very Sexy…But Most People Use Form Editor So It Might Confuse Them A Tiny Bit…

Edit:
Robot…I know that you can understand it but not everyone that uses forms has been doing it for a while now…some *new* form makers will get confused…

R0b0t1

2007-06-03 19:50:50

Eh? I use form editor and I can understand this.

I really don't think its quite useful though, with not title bar.

stylen

2007-06-04 17:28:22

That's pretty cool man.
Not that I would use it but its pretty cool.

BTW you should post a picture of the form.
Great find though.

Smartzkid

2007-06-04 19:57:16

<3 Borderless Forms

Maybe some more people will start using them now?

I hope so…Other forms are just so ugly

~alex~

2007-06-04 20:05:46

Boarderless forms are sexy, and not overly difficult. <3 You for spreading the word :)

SKy Scripter

2007-06-04 20:06:28

The Form Editer is a Waste of time really :p

very nice widget..

yah instead of bitmaps i usually draw them using CANVASES

Santa_Clause

2007-06-05 19:56:22

That's you SKy, not us…:p…We might be advanced in forms but haven't practiced as much…;)

tim46

2007-06-06 07:00:39

Sweet tutorial. Form looks sexy :)

Widget

2007-06-06 23:18:34

From: stylen
BTW you should post a picture of the form.

Well here's what I'm working on: (SCAR's first real GUI)

The whole thing is self coloring so it'll look pretty no matter what bitmap you stick on it :D

Santa_Clause

2007-06-08 07:27:29

Widget's obsessed with the prospect of making a script run while the form is open…:p

x13om13e12x

2007-06-27 21:41:50

The whole graphic User Interface idea looks awsome, I'm new to forms and i understood this, so its actually pretty easy to understand, one thing im having trouble with is declare multiple players with forms, someone should make a tuturial on how to set up players.

Haxor

2007-06-28 04:12:58

nice pic of form. looks leet also guide is cool.


haxor

jhildy

2007-07-06 02:25:30

question for those buttons do you just make those pictures or do you find them somewhere or what. if you make them picktures you dont have to explain because i know what to do from them, but i'm curious as to what you do.

Santa_Clause

2007-07-06 06:38:04

It's a bitmap…

jhildy

2007-07-06 19:56:53

ok thanks thats all i need to know

IEatJ00erBaybees

2007-07-06 21:29:25

Good and cool tut, but there's more things I'd like to know. I'd like to know how to incorporate a player form into your script. And other button functions, like if I want another form to pop up when you click something or to create a new player type thing.

procedure DeclarePlayers;
begin

//All this junk

Players[0].Name := Players[0].NameCaption

It's something like that. I'd like to know more about implementing it so that you can interact in the form, instead of just seeing it.

Santa_Clause

2007-07-06 22:02:52

Ahh lmao…I'll add you on MSN and teach you.

itSchRis917

2007-07-17 19:35:52

very sexy. ill be using this. Nice tut also!