SRL Archive - OSR Advanced Scripting Tutorials

Make a form with a special shape! Circle etc..


mastaraymond

2007-07-24 14:23:31

Ok, yesterday i learned Forms. I've read some tutorials, did some testing. And i found out something cool! You are able to load a form in a special shape for example: Circle!
For this tutorial you need:
1) Canvas knowledge.
2) Form knowledge
3) Little bit math, for making the shapes ;).

2 Examples before starting ;).
Lets start!

First we load a simple form without a bar. If we do this, we need a way of closing it. Thats why we add a simple button that closes the form, here we go:

program New;

var
OurForm : TForm;
Button : TButton;

procedure InitAndLoadForm;
begin

OurForm := CreateForm;
OurForm.SetBounds(0, 0, 300, 300);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.Color := clBlack;
OurForm.BORDERSTYLE:= bsnone;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(0,0,40,20);
Button.Top := 140;
Button.Left := 130;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
SafeLoadForm;
FreeForm(Ourform);
end.
Cool, it loads a black screen with a button in the middle. Click it and the form will close! Ok, lets go on. When a form gets loaded, it uses the brush to fill in the canvas of the form ( I think:rolleyes:). So basicly if we change the brush style, the way of filling it in, we can change how it looks!
A side note, [YourForm].color changes the color, but [YourForm].Brush.Color does also change it ;).
Brush styles change the way huh, what styles do we got?
Here you go:
bsSolid, bsClear, bsHorizontal, bsVertical, bsFDiagonal, bsBDiagonal, bsCross, bsDiagCross. O we see 1 special one! 'bsClear', yeah this one is the one we need! bsClear draws something a canvas transparent! So if we add 'OurForm.Brush.Style := bsClear;' we cannot see the window anymore, because its transparent! The coolest thing is now, we can still see the button. Notice: OurForm.Brush.Style := bsClear; must come AFTER the .color chooses! Otherwise, our form will not be transparent!

Cool, we got a button with a transparent form! Now, comes the coolest part, we can change the way our form is supposed to look! How? Quite simple, because we can still enter the Form canvas! So if we edit the canvas, the form canvas will be edited to! I made a simple example for you guys:

procedure PaintCircle(Sender: TObject);
begin
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
Ourform.Canvas.Ellipse(0,0,300,300);
SafeCopyCanvas(Ourform.Canvas, Ourform.Canvas, 0, 0, 280, 280, 0, 0, 280,280);
end;
You see? First we edit the colors of the brush & pen, then we make a circle on the canvas and then we load it onto the original!
But, wait, you putted a Sender : TObject in it, why? Because we need to load this procedure, we are going to load this procedure when the form is going to paint his canvas. In our case it would be: OurForm.OnPaint := @PaintCircle;
Try it, add that line and run it! You should see a form in the shape of a circle right now!
I hope you got how it works :p. Otherwise just post ;).
Here below i posted my Form shape script with a few form shapes:Triangle,Box,Pacman or Circle.
See below!

EDIT: Small note: once its loaded, the transparent part, will not change:p. For example i got a black background, i load the form, it will have a black transparent part. Then somehow my background changes to white, the transparent part will stay black! :(. Unless you load the form again ;). So, if you want to prevent this, add a TTimer that makes the form invisible & visible every sec?

UPDATE: Dragging the form!
Ok, if you know how the shaped forms work, we need to add something: Dragging it! All credits for finding out how you can load a new 'transparent' background goes to Widget!

Lets start, first we are going to declare 2 variables:

StartX,StartY : Integer;
This are integers of the mouse position at the start ;). Then we add 3 events!

OurForm.OnMouseDown := @Start;
OurForm.OnMouseMove := @DragTheForm;
OurForm.OnMouseUp := @Stop;
.

Let me explain it! If we click at the form, it will activate procedure start:

procedure Start(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin;
GetMousePos(StartX,Starty);
end;
We need to get the start position of the mouse ofcourse! So we clicked the form, now we want the form to move if we hold the left mouse button, thats why i made a procedure DragTheForm, on the event : OnMoveMouse!

Then if procedure DragTheForm(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
Tempx,Tempy : Integer;
begin;
GetMousePos(Tempx,Tempy);
if (ssleft in shift) and not (Starty=Tempy) and not (Startx = Tempx) then
begin;
OurForm.Visible := False;
OurForm.Top := OurForm.Top - (starty-tempy);
OurForm.Left := OurForm.Left - (startx-tempx);
Startx := Tempx;
Starty := Tempy;
OurForm.Visible := True;
end;
end;
It gets the current position of the mouse, then it checks if the left button is down and the start coords aren't the same as the coords we have now. Then it hides the form, changes the position of the form and shows it again! With Visible := false & true, you can make the background 'transparent' again ;). Ok, cool, now we need only 1 more procedure. A procedure that is called if the stop holding the mouse!

procedure Stop(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin;
OurForm.Visible := False;
Sleep(50);
OurForm.Visible := True;
end;
This procedure will make sure, you don't see any trails!

1 Note, you need to hide scar, before calling the form, otherwise you will see trails. I have no idea why, it just is… *cough* Costed me 1 hour to find out ^^ *cough*

The updated script with dragging enabled!

program New;

var
OurForm : TForm;
Button : TButton;
StartX,StartY : Integer;
const
Shape = 'pacman'; //What shape you want our form to be? Triangle,Box,Pacman or Circle?



procedure DragTheForm(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
Tempx,Tempy : Integer;
begin;
GetMousePos(Tempx,Tempy);
if (ssleft in shift) and not (Starty=Tempy) and not (Startx = Tempx) then
begin;
OurForm.Visible := False;
OurForm.Top := OurForm.Top - (starty-tempy);
OurForm.Left := OurForm.Left - (startx-tempx);
Startx := Tempx;
Starty := Tempy;
OurForm.Visible := True;
end;
end;


procedure Start(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin;
GetMousePos(StartX,Starty);
end;


procedure Stop(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin;
OurForm.Visible := False;
Sleep(50);
OurForm.Visible := True;
end;

Procedure PaintTriangle(Sendet : TObject);
var
TempCanvas : TCanvas;
I,II : INteger;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Pen.Color := clBtnFace;
Ourform.Canvas.Pen.Width := 1;
For I:= 0 to 150 do
begin;
TempCanvas.Moveto(I,150-I);
TempCanvas.LineTo(I,150+I);
II := 300-I;
TempCanvas.Moveto(II,150-I);
TempCanvas.LineTo(II,150+I);
end;
Ourform.Canvas.Pen.Color := clActiveBorder;
Ourform.Canvas.Pen.Width := 1;
TempCanvas.MoveTo(150,0);
TempCanvas.LineTo(0,150);
TempCanvas.LineTO(150,300);
TempCanvas.Lineto(300,150);
TempCanvas.LineTo(150,0);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

Procedure PaintBox(Sender : TObject);
var
TempCanvas:Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.RoundRect(0,0,300,300,50,50);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

Procedure PaintPacman(Sender: TObject);
var
TempCanvas:TCanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.Pie (0,0,300,300,300,50,300,250);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

procedure PaintCircle(Sender: TObject);
begin
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
Ourform.Canvas.Ellipse(0,0,300,300);
SafeCopyCanvas(Ourform.Canvas, Ourform.Canvas, 0, 0, 280, 280, 0, 0, 280,280);
end;

Procedure ChooseShape(Sender : TObject);
begin;
Case LowerCase(Shape) of
'triangle': PaintTriangle(Sender);
'box' : PaintBox(Sender );
'pacman' : PaintPacman(Sender );
'circle' : PaintCircle(Sender );
end;
end;

procedure InitAndLoadForm;
begin

OurForm := CreateForm;
OurForm.SetBounds(0, 0, 300, 300);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.BORDERSTYLE:= bsnone;
OurForm.Brush.style := bsclear;
OurForm.OnMouseDown := @Start;
OurForm.OnMouseUp := @Stop;
OurForm.OnMouseMove := @DragTheForm;
OurForm.Onpaint := @ChooseShape;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(0,0,40,20);
Button.Top := 140;
if LowerCase(Shape) = 'pacman' then
Button.Left := 110
else Button.Left := 130;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
GetSelf.Hide;
SafeLoadForm;
FreeForm(Ourform);
GetSelf.Show;
end.
If you see any spelling, grammar or other mistakes, tell me! This is my first tutorial and Im not good at English ;)

~Raymond

Dan Cardin

2007-07-24 14:32:32

holy crap thats cool:D:D:D:D

and now starts a whole new age of obnoxiously shaped forms!!

Killerdou

2007-07-24 15:00:21

lol, i vote this guy becomes dev… he knows so much lol(im serious though)

mastaraymond

2007-07-24 16:11:25

From: dan cardin
holy crap thats cool:D:D:D:D

and now starts a whole new age of obnoxiously shaped forms!!


Yeah that would be pretty cool :p.

From: iloveit8
lol, i vote this guy becomes dev… he knows so much lol(im serious though)

hehe, thank you!


~Raymond

Smartzkid

2007-07-24 16:31:04

Doesn't work for me, but it sure sounds awesome!

EDIT: Nevermind; I got it to work. Amazing!

mastaraymond

2007-07-24 18:42:50

From: Smartzkid
Doesn't work for me, but it sure sounds awesome!

EDIT: Nevermind; I got it to work. Amazing!


Hehe, i hope you liked it :p. Added sample pictures!
Also guys, you know that you can actually change how the form looks, from inside the script? I mean, for example i press button PacMan, the form will look like pacman :). That is possible :D.

Bonfield

2007-07-24 21:45:53

good tut u really know alot u should be a srl dev

LordGregGreg

2007-07-24 22:02:55

meh, srl dev.. not to sure about that yall.

Dont get me wrong though, this is VERY cool, and great tutorial.
Thank you very much for sharing your knowledge.

Santa_Clause

2007-07-24 23:18:15

I was about to say the same as Lordgreggreg, no offence to Raymond though…he is very good.

I knew about this, very interesting…and as for the shape changing on the click of a button, it's exactly the same idea as skinnable forms :p

Widget

2007-07-25 00:05:07

Ooh, Sky's gonna love this!

Oh, I fixed the stealing of the background for the most part, and also made words work (I've always wanted a literal WidgetForm :p)

program New;

var
OurForm : TForm;
Button : TButton;
DragTimer:TTimer;
i,wx1,wy1,wx2,wy2:integer;

procedure DragForm(Sender: TObject);
begin
getmousepos(wx1,wy1);
OurForm.Top := OurForm.Top - (wy2-wy1);
OurForm.Left := OurForm.Left - (wx2-wx1);
wx2 := wx1;
wy2 := wy1;
end;

procedure DragDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
getmousepos(wx2,wy2);
DragTimer.Interval := 1;
end;

procedure DragUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DragTimer.Interval := 10000000;
OurForm.visible := false
sleep(100)
OurForm.visible := true
end;


Procedure PaintWidget(Sender : TObject);
var
TempCanvas:Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.Brush.Style := bsClear;
TempCanvas.Pen.Color := clBlack;
TempCanvas.Font.Size := 255;
TempCanvas.Font.Name := 'Wide Latin';
TempCanvas.Font.Color := clBlack;
TempCanvas.TextOut(0,0,'W');
TempCanvas.Font.Size := 240;
TempCanvas.Font.Color := $FFAA00;
TempCanvas.TextOut(3,3,'W');
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;


procedure InitAndLoadForm;
begin

OurForm := CreateForm;
OurForm.SetBounds(0, 0, 700, 400);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.BORDERSTYLE:= bsnone;
OurForm.Brush.style := bsclear;
OurForm.Onpaint := @PaintWidget;



OurForm.OnMouseDown := @DragDown;
OurForm.OnMouseUp := @DragUp;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(290,140,40,20);
Button.Top := 140;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
DragTimer := TTimer.Create(OurForm);
DragTimer.Interval := 10000000;
DragTimer.OnTimer := @DragForm;
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
SetFontSmoothing(True);
GetSelf.WindowState := wsMinimized;
SafeLoadForm;
FreeForm(Ourform);
GetSelf.WindowState := wsNormal;
end.

Bobarkinator

2007-07-25 00:18:35

Very nice. I mostly just go for basic forms but this is pretty cool. I think I need to learn canvases. Is their a tut?

Widget

2007-07-25 00:40:50

From: bobarkinator
Very nice. I mostly just go for basic forms but this is pretty cool. I think I need to learn canvases. Is their a tut?


Everything About Canvases

Now where'd that search button tutorial go… :p

—-

Edit: Use this script to play around with different letters lol:
program New;

var
OurForm : TForm;
Button : TButton;
DragTimer:TTimer;
NewLetter:TEdit;
wx1,wy1,wx2,wy2:integer;

procedure DragForm(Sender: TObject);
begin
getmousepos(wx1,wy1);
OurForm.Top := OurForm.Top - (wy2-wy1);
OurForm.Left := OurForm.Left - (wx2-wx1);
wx2 := wx1;
wy2 := wy1;
end;

procedure DragDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
getmousepos(wx2,wy2);
DragTimer.Interval := 1;
end;

procedure DragUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DragTimer.Interval := 10000000;
OurForm.visible := false
sleep(200)
OurForm.visible := true
end;


Procedure PaintWidget(Sender : TObject);
var
TempCanvas:Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.Brush.Style := bsClear;
TempCanvas.Pen.Color := clBlack;
TempCanvas.Font.Size := 255;
TempCanvas.Font.Name := 'Wide Latin';
TempCanvas.Font.Color := clBlack;
TempCanvas.TextOut(0,0,'W');
TempCanvas.Font.Size := 240;
TempCanvas.Font.Color := $FFAA00;
TempCanvas.TextOut(3,3,'W');
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;
Procedure RepaintWidget(Sender : TObject);
var
TempCanvas:Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.Brush.Style := bsClear;
TempCanvas.Pen.Color := clBlack;
TempCanvas.Font.Size := 255;
TempCanvas.Font.Name := 'Wide Latin';
TempCanvas.Font.Color := clBlack;
TempCanvas.TextOut(0,0,NewLetter.text);
TempCanvas.Font.Size := 240;
TempCanvas.Font.Color := $FFAA00;
TempCanvas.TextOut(3,3,NewLetter.text);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
if (Sender = NewLetter) then
begin
OurForm.visible := false
sleep(200)
OurForm.visible := true
end;
end;


procedure InitAndLoadForm;
begin

OurForm := CreateForm;
OurForm.SetBounds(0, 0, 700, 400);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.BORDERSTYLE:= bsnone;
OurForm.Brush.style := bsclear;
OurForm.Onpaint := @PaintWidget;
OurForm.OnMouseDown := @DragDown;
OurForm.OnMouseUp := @DragUp;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(290,140,40,20);
Button.Top := 140;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
DragTimer := TTimer.Create(OurForm);
DragTimer.Interval := 10000000;
DragTimer.OnTimer := @DragForm;
NewLetter := TEdit.Create(OurForm);
with NewLetter do
begin
Parent := OurForm;
NewLetter.MaxLength := 1;
SetBounds(290,160,40,20);
Color := clBlack;
Font.Color := $FFAA00;
Text := 'W';
OnChange := @RepaintWidget;
end;
OurForm.Onpaint := @RepaintWidget
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
SetFontSmoothing(True);
GetSelf.WindowState := wsMinimized;
SafeLoadForm;
FreeForm(Ourform);
GetSelf.WindowState := wsNormal;
end.

Haxor

2007-07-25 04:34:13

nice idea dude. makes forms better and cooler.

haxor

mastaraymond

2007-07-25 05:37:50

From: Widget
Ooh, Sky's gonna love this!

Oh, I fixed the stealing of the background for the most part, and also made words work (I've always wanted a literal WidgetForm :p)

Hehe, yeah. Like i said, you can fix the background by reloading it.. Or in your case Visible, false,true ;). Also, I don't see why window dragging is important :'). I was doing some tests with Repaint, but it didn't work really good :p. I think a TTimer is the best option.. :'). Let it reload the form like every 500 msec? Also, you have considered, making the form a animation? I can do it, but i don't have much time ;). Make like 3 shapes, and then make a ttimer and let them rotate between shapes :D. So we can actually make like a pacman form :D

Btw 1 question:

TempCanvas.Font.Color := $FFAA00;
explain pl0x :D, Nvm got it! Hex colors ^^.

@lordgreggreg & SantaClause, i didn't say i need to become a dev, did i? Btw, you haven't seen half of my work:rolleyes:.*cough* encryption system*cough*. I just don't release everything ;)

Widget

2007-07-25 05:45:41

Well it seems the longer you have it non-visable the more likely/effectively it will kill the old background, so an animating form might not work that well, especially if you were trying to type in it for something.

Lol you just gave me an idea for a game :D

Edit!! Here's our New! one that doesn't keep the background
program ShapelessForm; // =)

var
OurForm : TForm;
Button : TButton;
DragTimer:TTimer;
NewLetter:TEdit;
i,wx1,wy1,wx2,wy2:integer;

procedure DragForm(Sender: TObject);
begin
getmousepos(wx1,wy1);
if not ((wx2=wx1) and (wy2=wy1)) then
OurForm.visible := false;
sleep(1);
OurForm.Top := OurForm.Top - (wy2-wy1);
OurForm.Left := OurForm.Left - (wx2-wx1);
OurForm.visible := true;
wx2 := wx1;
wy2 := wy1;
end;

procedure DragDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
getmousepos(wx2,wy2);
OurForm.visible := false;
DragTimer.Interval := 5;
end;

procedure DragUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DragTimer.Interval := 10000000;
OurForm.visible := false;
sleep(50);
OurForm.visible := true;
end;

Procedure RepaintWidget(Sender : TObject);
var
TempCanvas:Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
Ourform.Canvas.Brush.Color := clBtnFace;
Ourform.Canvas.Pen.Color := clActiveBorder;
TempCanvas.Brush.Style := bsClear;
TempCanvas.Pen.Color := clBlack;
TempCanvas.Font.Name := 'Wide Latin';
TempCanvas.Font.Size := 240;
TempCanvas.Font.Color := $FFAA00;
TempCanvas.TextOut(3,3,NewLetter.text);
TempCanvas.Font.Size := 255;
TempCanvas.Font.Color := clBlack;
TempCanvas.TextOut(0,0,NewLetter.text);
OurForm.Width := TempCanvas.TextWidth(NewLetter.text);
if OurForm.Width < 100 then OurForm.Width := 100;
NewLetter.Left := TempCanvas.TextWidth(NewLetter.text)/2;
Button.Left := TempCanvas.TextWidth(NewLetter.text)/2;
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
if (Sender = NewLetter) then
for i := 1 to 7 do
begin
OurForm.visible := false;
sleep(1);
OurForm.visible := true;
sleep(1);
end;
end;


procedure InitAndLoadForm;
begin

OurForm := CreateForm;
OurForm.SetBounds(0, 0, 700, 400);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.BORDERSTYLE:= bsnone;
OurForm.Brush.style := bsclear;
OurForm.OnMouseDown := @DragDown;
OurForm.OnMouseUp := @DragUp;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(290,140,40,20);
Button.Top := 140;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
DragTimer := TTimer.Create(OurForm);
DragTimer.Interval := 10000000;
DragTimer.OnTimer := @DragForm;
NewLetter := TEdit.Create(OurForm);
with NewLetter do
begin
Parent := OurForm;
// NewLetter.MaxLength := 1;
SetBounds(290,160,40,20);
Color := clBlack;
Font.Color := $FFAA00;
Text := 'W';
OnChange := @RepaintWidget;
end;
OurForm.Onpaint := @RepaintWidget
//MakeWindowTransparent(OurForm.Handle,200);
RepaintWidget(OurForm);
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
SetFontSmoothing(True);
GetSelf.WindowState := wsMinimized;
sleep(500);
SafeLoadForm;
FreeForm(Ourform);
GetSelf.WindowState := wsNormal;
end.

Miitchyy

2007-07-25 07:21:09

Mine makes prettyful colours with the triangle =D

program New;

var
OurForm : TForm;
Button : TButton;
const
Shape = 'triangle'; //What shape you want our form to be? Triangle,Box,Pacman or Circle?
Colour = 0; //Colour of the background


Procedure PaintTriangle(Sendet : TObject);
var
TempCanvas : TCanvas;
I, II : INteger;
begin;
TempCanvas := Ourform.Canvas;
OurForm.Canvas.Pen.Color := Colour;
OurForm.Canvas.Pen.Width := 1;
For I:= 0 to 150 do
begin;
OurForm.Canvas.Pen.Color := Colour + I;
TempCanvas.Moveto(I,150-I);
TempCanvas.LineTo(I,150+I);
II := 300-I;
TempCanvas.Moveto(II,150-I);
TempCanvas.LineTo(II,150+I);
end;
OurForm.Canvas.Pen.Color := Colour;
OurForm.Canvas.Pen.Width := 1;
TempCanvas.MoveTo(150,0);
TempCanvas.LineTo(0,150);
TempCanvas.LineTO(150,300);
TempCanvas.Lineto(300,150);
TempCanvas.LineTo(150,0);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

Procedure PaintBox(Sender : TObject);
var
TempCanvas: Tcanvas;
begin;
TempCanvas := Ourform.Canvas;
OurForm.Canvas.Brush.Color := Colour;
OurForm.Canvas.Pen.Color := Colour;
TempCanvas.RoundRect(0,0,300,300,50,50);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

Procedure PaintPacman(Sender: TObject);
var
TempCanvas: TCanvas;
begin;
TempCanvas := OurForm.Canvas;
OurForm.Canvas.Brush.Color := Colour;
OurForm.Canvas.Pen.Color := Colour;
TempCanvas.Pie(0,0,300,300,300,50,300,250);
SafeCopyCanvas(TempCanvas, Ourform.Canvas, 0, 0, 300, 300, 0, 0, 300,300);
end;

procedure PaintCircle(Sender: TObject);
begin
OurForm.Canvas.Brush.Color := Colour;
OurForm.Canvas.Pen.Color := Colour;
OurForm.Canvas.Ellipse(0,0,300,300);
SafeCopyCanvas(Ourform.Canvas, Ourform.Canvas, 0, 0, 280, 280, 0, 0, 280,280);
end;

Procedure ChooseShape(Sender : TObject);
begin;
Case LowerCase(Shape) of
'triangle': PaintTriangle(Sender);
'box': PaintBox(Sender);
'pacman' : PaintPacman(Sender);
'circle' : PaintCircle(Sender);
end;
end;

procedure InitAndLoadForm;
begin
OurForm := CreateForm;
OurForm.SetBounds(0, 0, 300, 300);
OurForm.Top := 50;
OurForm.Left := 50;
OurForm.BorderStyle := bsNone;
OurForm.Brush.Style := bsClear;
OurForm.OnPaint := @ChooseShape;
Button := TButton.Create(OurForm);
Button.Parent := OurForm;
Button.SetBounds(0,0,40,20);
Button.Top := 140;
if LowerCase(Shape) = 'pacman' then
Button.Left := 110
else Button.Left := 130;
Button.Caption := 'Close';
Button.ModalResult := mrOk;
Ourform.ShowModal;
end;

procedure SafeLoadForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitAndLoadForm', v);
end;


begin
SafeLoadForm;
FreeForm(Ourform);
end.

Dan Cardin

2007-07-25 08:06:57

do u think u could not make it have a backround at all…just be buttons and stuff?

itSchRis917

2007-07-25 09:49:30

this is pretty awesome. thanks for realeasing your knowledge about this.

mastaraymond

2007-07-26 12:38:24

Update!
I added a part about dragging the form, credits to Widget for finding out ;).

~Raymond

Infantry001

2007-07-27 01:23:00

Haha awesome tut, Raymond

Santa_Clause

2007-07-27 01:54:49

From: mastaraymond
Hehe, yeah. Like i said, you can fix the background by reloading it.. Or in your case Visible, false,true ;). Also, I don't see why window dragging is important :'). I was doing some tests with Repaint, but it didn't work really good :p. I think a TTimer is the best option.. :'). Let it reload the form like every 500 msec? Also, you have considered, making the form a animation? I can do it, but i don't have much time ;). Make like 3 shapes, and then make a ttimer and let them rotate between shapes :D. So we can actually make like a pacman form :D

Btw 1 question:

TempCanvas.Font.Color := $FFAA00;
explain pl0x :D, Nvm got it! Hex colors ^^.

@lordgreggreg & SantaClause, i didn't say i need to become a dev, did i? Btw, you haven't seen half of my work:rolleyes:.*cough* encryption system*cough*. I just don't release everything ;)


Encryption system? I'd love to see that ;)

SKy Scripter

2007-07-27 02:07:03

From: Widget
Ooh, Sky's gonna love this!



But i already knew About it -.- i cant believe nobody knew about this…

LordGregGreg

2007-07-27 02:45:43

From: mastaraymond

@lordgreggreg & SantaClause, i didn't say i need to become a dev, did i? Btw, you haven't seen half of my work:rolleyes:.*cough* encryption system*cough*. I just don't release everything ;)


Well, you cant brag about something you dont release.

"my main is ziezma" kinda of mentality there..

I wasnt refering to you asking.. i was refering to your minions.

mastaraymond

2007-07-27 06:37:01

@lordgreggreg, you are totally right about that..

@SantaClause, i have my reasons to not release it and i need scar 3.12 to make it perfect..

Lets stop, ok? Its a pointless discussion..
~Raymond

cathering_

2007-07-28 19:03:54

When the form is dragged it can cause for some unusual things including lag and the program tabs moving on there own XD

llib

2007-08-07 20:32:32

That is…amazing lol forget boxes. Nice find. :) defintly wanna mess with this a bit…

The Element

2007-08-10 15:23:52

Okay,

So I get the TTimer part but what is the code needed to make the form become invisible then visible. I'm trying to solve that background color to transparent problem.

EDIT:

Nvm found an even easier way then Widget's fix. Just put:

   
OurForm.visible := false
sleep(100)
OurForm.visible := true

At the bottom of dragform (after the until).

ShawnjohnSJ

2008-06-01 22:03:53

Can this also be used on Objects, such as TButtons or something?

mastaraymond

2008-06-02 09:28:14

From: ShawnjohnSJ
Can this also be used on Objects, such as TButtons or something?

In theory it could, but since the form is the "Background" of a TButton it won't have much effect..

P1nky

2008-06-02 12:19:08

sw33t! only thing i dont know is Canvas :)

you can make triangles too than
?

Dan Cardin

2008-06-02 12:58:01

you can make any shape. This would be a lot easier to take advantage of if you made a function have it draw according to points given (they give you (0,3)(45,2)(63,73) and they get a weirded up triangle.) ;)