PDA

View Full Version : Forms Using only TImages (No Buttons, etc.)



Widget
01-28-2008, 04:06 AM
Well this isn't so much a tutorial as a form for a script my friend is working on. It's an auto-staker so this form is basically a representation of the options menu whilst you try to make the other person use your rules ;)

To avoid the use of an insanely long bitmap string or the use of another file to be placed somewhere specificish I just have it download the picture off my site =)

The pictures more or less act as buttons in the sense that you click on them, but they don't really have real labels :)

The title thing drags the form, and accept and decline are the Ok/Cancel equivalents :)

All this in about 215 lines:

program SadlyDuelist;
const ProgramName = 'SadlyDuelist, Though It Needs a Better Name';
type CoordsAndStuff = record
x1,y1,x2,y2:integer;
Checked:boolean;
end;
var TheForm:TForm;
TheBackground,Accept,Decline,Titlebar:TImage;
TheBoolButtons:array[1..10] of TImage;
TheEquipments:array[1..11] of TImage;
CoordsAndStuff:array[1..23] of CoordsAndStuff;
i,i2:integer;
s:string;
DefaultChecked,DefaultNoArmor: array of integer;
procedure DragForm(Sender:TObject;Button:TMouseButton;Shift: TShiftState;x,y:Integer);
var x1,y1,x2,y2:integer;
begin
GetMousePos(x1,y1);
repeat
sleep(15);
GetMousePos(x2,y2);
TheForm.Left := TheForm.left - x1 + x2;
TheForm.Top := TheForm.Top - y1 + y2;
x1 := x2;
y1 := y2;
until not IsMouseButtonDown(True);
end;
function StuffToCoordsAndStuff(x1,y1,x2,y2:integer):CoordsA ndStuff;
begin
Result.x1 := x1;
Result.y1 := y1;
Result.x2 := x2;
Result.y2 := y2;
Result.Checked := False;
end;
procedure OkOrCancel(Sender:TObject);
begin
if (Sender=Accept) then
TheForm.ModalResult := mrOk
else
TheForm.ModalResult := mrCancel;
end;
procedure EquipClick(Sender:TObject);
var Image:TImage;
ii:integer;
begin
for ii := 1 to 11 do
if Sender=TheEquipments[ii] then
Break;
Image := TheEquipments[ii];
if CoordsAndStuff[ii].Checked then
SafeCopyCanvas(GetBitmapCanvas(i),TheEquipments[ii].Canvas,CoordsAndStuff[ii].x1,
CoordsAndStuff[ii].y1,CoordsAndStuff[ii].x2,CoordsAndStuff[ii].y2,0,0,35,35)
else
begin
Image.Canvas.Pen.Color := $0000FF;
Image.Canvas.MoveTo(3,3);
Image.Canvas.LineTo(33,33);
Image.Canvas.MoveTo(33,3);
Image.Canvas.LineTo(3,33);
end;
CoordsAndStuff[ii].Checked := not CoordsAndStuff[ii].Checked;
end;
procedure BoolButtonClick(Sender:TObject);
var Image:TImage;
ii:integer;
begin
for ii := 1 to 10 do
if Sender=TheBoolButtons[ii] then
Break;
Image := TheBoolButtons[ii]
if CoordsAndStuff[ii+12].Checked then
SafeCopyCanvas(GetBitmapCanvas(i),TheBoolButtons[ii].Canvas,220,39+18*(ii-1),234,53+18*(ii-1),0,0,14,14)
else
begin
Image.Canvas.Pen.Color := $0000FF;
Image.Canvas.MoveTo(4,4);
Image.Canvas.LineTo(10,10);
Image.Canvas.MoveTo(10,4);
Image.Canvas.LineTo(4,10);
end;
CoordsAndStuff[ii+12].Checked := not CoordsAndStuff[ii+12].Checked;
end;
procedure SetUpCoordsAndStuff;
begin
// Armor things, from top to bottom.
CoordsAndStuff[1] := StuffToCoordsAndStuff(85,39,120,74); // Helm
CoordsAndStuff[2] := StuffToCoordsAndStuff(44,78,79,113); // Cape
CoordsAndStuff[3] := StuffToCoordsAndStuff(85,78,120,113); // Ammy
CoordsAndStuff[4] := StuffToCoordsAndStuff(126,78,161,113); // Arrows
CoordsAndStuff[5] := StuffToCoordsAndStuff(29,117,64,152); // Weapon
CoordsAndStuff[6] := StuffToCoordsAndStuff(85,117,120,152); // Body
CoordsAndStuff[7] := StuffToCoordsAndStuff(141,117,176,152); // Shield
CoordsAndStuff[8] := StuffToCoordsAndStuff(85,157,120,192); // Pants
CoordsAndStuff[9] := StuffToCoordsAndStuff(29,197,64,232); // Gloves
CoordsAndStuff[10] := StuffToCoordsAndStuff(85,197,120,232); // Boots
CoordsAndStuff[11] := StuffToCoordsAndStuff(141,197,176,232); // Ring
end;
function TheFormAndStuff:boolean;
begin
SetUpCoordsAndStuff;
i := LoadBitmap(AppPath+'Scripts\stake.bmp');
TheForm := CreateForm;
with TheForm do
begin
SetBounds(0,0,401,306);
Position := poScreenCenter;
BorderStyle := bsNone;
end;
TheBackground := TImage.Create(TheForm);
TheBackground.Parent := TheForm;
TheBackground.SetBounds(0,0,401,306);
SafeCopyCanvas(GetBitmapCanvas(i),TheBackground.Ca nvas,0,0,401,306,0,0,401,306);
Accept := TImage.Create(TheForm);
Accept.Parent := TheForm;
Accept.SetBounds(78,246,79,23);
SafeCopyCanvas(GetBitmapCanvas(i),Accept.Canvas,78 ,246,157,269,0,0,79,23);
Accept.OnClick := @OkOrCancel;
Decline := TImage.Create(TheForm);
Decline.Parent := TheForm;
Decline.SetBounds(249,246,79,23);
SafeCopyCanvas(GetBitmapCanvas(i),Decline.Canvas,2 49,246,249+79,269,0,0,79,23);
Decline.OnClick := @OkOrCancel;
TitleBar := TImage.Create(TheForm);
TitleBar.Parent := TheForm;
TitleBar.SetBounds(7,7,386,21);
SafeCopyCanvas(GetBitmapCanvas(i),TitleBar.Canvas, 7,7,393,28,0,0,386,21);
TitleBar.OnMouseDown := @DragForm;
with TitleBar.Canvas do
begin
Font.Name := 'Fixedsys';
Font.Color := 0;
Brush.Style := psClear;
TextOut(181-TitleBar.Canvas.TextWidth('Widget''s Staker Form Thingy')/2,3,'Widget''s Staker Form Thingy');
Font.Color := 56558;
TextOut(180-TitleBar.Canvas.TextWidth('Widget''s Staker Form Thingy')/2,2,'Widget''s Staker Form Thingy');
end;
DefaultChecked := [1,3,6,7,8,9];
DefaultNoArmor := [1,2,3,4,6,7,8,9,10,11];
for i2 := 1 to 11 do
begin
TheEquipments[i2] := TImage.Create(TheForm);
with TheEquipments[i2] do
begin
Parent := TheForm;
Left := CoordsAndStuff[i2].x1;
Top := CoordsAndStuff[i2].y1;
Width := 35;
Height := 35;
OnClick := @EquipClick;
end;
SafeCopyCanvas(GetBitmapCanvas(i),TheEquipments[i2].Canvas,CoordsAndStuff[i2].x1,
CoordsAndStuff[i2].y1,CoordsAndStuff[i2].x2,CoordsAndStuff[i2].y2,0,0,35,35);
end;
for i2 := 1 to 10 do
begin
TheBoolButtons[i2] := TImage.Create(TheForm);
with TheBoolButtons[i2] do
begin
Parent := TheForm;
Left := 220;
Top := 39+18*(i2-1)
Width := 16;
Height := 16;
OnClick := @BoolButtonClick;
end;
SafeCopyCanvas(GetBitmapCanvas(i),TheBoolButtons[i2].Canvas,220,39+18*(i2-1),234+2,53+18*(i2-1)+2,0,0,16,16)
end;
for i2 := 0 to (GetArrayLength(DefaultNoArmor)-1) do
EquipClick(TheEquipments[DefaultNoArmor[i2]]);
for i2 := 0 to (GetArrayLength(DefaultChecked)-1) do
BoolButtonClick(TheBoolButtons[DefaultChecked[i2]]);
Result := TheForm.ShowModal = mrOk;
end;
function ShowTheFrigginForm:boolean;
var something:TVariantArray;
begin
SetArrayLength(something,0);
Result := ThreadSafeCall('TheFormAndStuff',something);
end;
begin
if FileExists(AppPath+'Scripts\stake.bmp') then
begin
i := OpenFile(AppPath+'Scripts\stake.bmp',False);
i2 := FileSize(i)
CloseFile(i);
end;
if not FileExists(AppPath+'Scripts\stake.bmp') or (i2<100) then
begin
CloseFile(RewriteFile(AppPath+'Scripts\stake.bmp', False));
if FileExists(AppPath+'Scripts\stake.bmp') then // If user gave filewall permissions
begin
GetApplication.MessageBox('Background not found, the script will now '+
'try to download the background for the'+#13+'form off the internet, please give '+
'it access to the page and file which it is'+#13+'downloading it to.','Hello',0);
s := GetPage('http://rs-widgets.com/REAL/stake.bmp');
i := RewriteFile(AppPath+'Scripts\stake.bmp',False);
if WriteFileString(i,s) and (length(s) > 50) then
Writeln('File written successfully')
else begin
Writeln('Background not written properly, please rerun the script');
TerminateScript;
end;
CloseFile(i);
end;
end;
GetSelf.WindowState := wsMinimized;
if not ShowTheFrigginForm then
begin
Writeln('Dude, you friggin'' cancelled it! =(');
GetSelf.WindowState := wsNormal;
TerminateScript;
end;
FreeForm(TheForm);
GetSelf.WindowState := wsNormal;
Writeln('Going on normally =)');
FreeBitmap(i);
end.

Negaal
01-28-2008, 02:57 PM
The form is nice, it needs some time to read though , I'm going to look it, but later, meanwhile, I see you're form master, How about simple tutorial script of making progress report on canvas/form...

Nice tutorial by the way, hope you find some time to progressreport form :)


Heh, I remember when I playd RS then I used your autotalker:D

Dan Cardin
01-28-2008, 07:13 PM
wow :) that makes me impressed :)
just the x in the corner doesnt work :(

and just because i'm not edgamacated in drawing stuff, how did you un-x the boxes? or send me to the line where you unchecked them cuz i like ur form :)

mastaraymond
01-28-2008, 07:19 PM
Nice form :p

One thing your standards are kinda weird, makes it hard to read :p

Widget
01-28-2008, 11:40 PM
wow :) that makes me impressed :)
just the x in the corner doesnt work :(

and just because i'm not edgamacated in drawing stuff, how did you un-x the boxes? or send me to the line where you unchecked them cuz i like ur form :)
if CoordsAndStuff[ii].Checked then
SafeCopyCanvas(GetBitmapCanvas(i),TheEquipments[ii].Canvas,CoordsAndStuff[ii].x1,
CoordsAndStuff[ii].y1,CoordsAndStuff[ii].x2,CoordsAndStuff[ii].y2,0,0,35,35)

I put all the coordinates of the equipment buttons in that array, as well as it's Xed or not state :). Basically what that line does is if it's currently crossed out, it will recopy the part of the canvas that it's on back over, so it's basically just giving it a new picture ;)

Oh, and I was just to lazy to make the X in the top-right corner an actual image and set it to the Decline option thing :p

Harry
01-28-2008, 11:47 PM
Hehe, nice! And you don't even have a scripters cup! :O

Santa_Clause
01-28-2008, 11:53 PM
Had a feeling you'd make one of these soon. Good job.

Widget
01-29-2008, 12:09 AM
Hehe, nice! And you don't even have a scripters cup! :O

Well considering I still haven't made an RS script and This was like the first script I've posted in about half a year... :p

Edit: Now that I think about it, I could probably make the entire form only use the TForm canvas... *evilish grin (Forms with no components, anyone? :D)*