Jump to content
shadowrecon

Forms Objects + SMART ?

Recommended Posts

So i got the bright idea last night to try to paint the win 32 progress bar from the forms onto smart, with about 2 hours of messing around i finnally figured out how to paint it onto smart, but when i went to step it or do anything to the progress-bar and repaint it, scar just crashed. Any one have any ideas on ways to change the progress bar?

 

[scar] program New;

{$DEFINE RS2}

{$DEFINE OSI_Color_Anti_Randoms}

{$DEFINE SMART}

{$I OSI\OSI.scar}

 

var

Form1: TForm;

ProgressBar1: TProgressBar;

 

Procedure IncimentBar;

begin

if ProgressBar1.Position < 110 then

ProgressBar1.StepIt;

end;

 

procedure Form1_Init;

begin

Form1 := CreateForm;

ProgressBar1 := TProgressBar.Create(Form1);

with ProgressBar1 do

begin

Parent := Form1;

Step := 10;

Min := 0;

Max := 110;

end;

end;

 

procedure Form1_SafeInit;

var

v: TVariantArray;

begin

SetLength(v, 0);

ThreadSafeCall('Form1_Init', v);

end;

 

function Form1_ShowModal: Boolean;

begin

Result := Form1.ShowModal = mrOk;

end;

 

function Form1_SafeShowModal: Boolean;

var

v: TVariantArray;

begin

SetLength(v, 0);

Result := ThreadSafeCall('Form1_ShowModal', v);

end;

 

Procedure PaintProgressBar(X,Y,T:Integer);

VAr

Z: Integer;

begin

Try

Form1_SafeInit;

Z := GetsystemTime + T;

repeat

ProgressBar1.PaintTo(SmartGetDebugDC,X,Y);

IncimentBar;

Wait(1000);

until Z < GetSystemTime;

SmartSetTarget;

Form1_SafeShowModal;

FreeForm(Form1);

except end;

end;

 

begin

SetUpOSI;

PaintProgressBar(20,20,7000);

end.[/scar]

Edited by shadowrecon
Link to comment
Share on other sites

Wouldn't it be easier to just draw your own progress bar?

I have made my own progress bar, but the way i did it was with 15 bit maps, so u can precisely control the bar, and the tprogress bar is a already made progress bar that doesnt use as much memory and processing power as bitmaps and setting pixels. plus its completely controllable.

 

---------- Post added at 04:24 AM ---------- Previous post was at 04:23 AM ----------

 

I like and agree with freddy :P That may be alot easier actually

 

its not about easiness, =p its about efficiency! Until i try both i wont know which is more efficient =)

 

---------- Post added at 05:02 AM ---------- Previous post was at 04:24 AM ----------

 

So after some more messing around with it, im no longer crashing smart, but its not painting the position of the progress bar i set it to, heres what im using now

[scar]program New;

{$DEFINE RS2}

{$DEFINE OSI_Color_Anti_Randoms}

{$DEFINE SMART}

{$I OSI\OSI.scar}

 

procedure ScriptTerminate;

begin

FreeOSI;

end;

 

var

Prog: TForm;

ProgressBar: TProgressBar;

 

Procedure intPaintProgressBar;

begin

Prog := CreateForm;

ProgressBar := TProgressBar.Create(Prog);

ProgressBar.Parent := Prog;

ProgressBar.Width := 169;

ProgressBar.Height := 16;

ProgressBar.Min := 0;

ProgressBar.Max := 60;

end;

 

Var

SmartDebugDC: Integer;

 

begin

SetUpOSI;

SmartDebugDC := SmartGetDebugDC;

 

intPaintProgressBar;

ProgressBar.Position := 60;

ProgressBar.Invalidate; // more effective way to paint

ProgressBar.PaintTo(SmartDebugDC,20,20);

 

SmartSetTarget;

FreeForm(Prog);

end. [/scar]

 

[ATTACH=CONFIG]297[/ATTACH]

Edited by shadowrecon
Link to comment
Share on other sites

It does what the name suggests, it makes a call to another thread in a safe manner. http://forums.scar-divi.com/showthread.php?19-Debugging-Common-Issues

 

If you use the form designer you can see how you use it.

what does the V do?

 

[scar]procedure UnitedBots_SafeInit;

var

v: TVariantArray;

begin

SetLength(v, 0);

ThreadSafeCall('UnitedBots_Init', v);

end; [/scar]

Link to comment
Share on other sites

The argument(s) stored in v get passed to the function you are calling. Never played with it to see it actually works.

Alrighty, im gonna mess around with it, im guessing with this whole idea of changing the progress bar i had to call the forum change it to where i want it, then close forum then paint the progressbar. then call forum again move to different pos then close and repaint.. im starting to think this could be pretty memory intensive..

Link to comment
Share on other sites

As Bixby said, the variantarray passes the parameters to the function:

 

[scar]procedure UnitedBots_SetPos(const Pos: Integer);

begin

ProgressBar.Position := Pos;

ProgressBar.Invalidate;

end;

 

procedure UnitedBots_SetPos(const Pos: Integer);

var

v: TVariantArray;

begin

SetLength(v, 1);

v[0] := Pos;

ThreadSafeCall('UnitedBots_SetPos', v);

end;[/scar]

 

On a note, Invalidate isn't a more efficient way to paint... It simply tells the progressbar to repaint.

Link to comment
Share on other sites

As Bixby said, the variantarray passes the parameters to the function:

 

[scar]procedure UnitedBots_SetPos(const Pos: Integer);

begin

ProgressBar.Position := Pos;

ProgressBar.Invalidate;

end;

 

procedure UnitedBots_SetPos(const Pos: Integer);

var

v: TVariantArray;

begin

SetLength(v, 1);

v[0] := Pos;

ThreadSafeCall('UnitedBots_SetPos', v);

end;[/scar]

 

On a note, Invalidate isn't a more efficient way to paint... It simply tells the progressbar to repaint.

 

Oh alright i understand it a bit better. And as for the invalidate being a more efficient way, I think i was mistaken because when i was reading about different methods for painting objects to canvas that was one i ran across that repaints everything where some other methods used system cache to determine if the object had changed enough to repaint or just leave it alone. And at the time i wanted it to paint every-time because i couldnt get it to change so i figured it could of been something with the cache or something silly.

 

---------- Post added 02-21-2012 at 07:14 AM ---------- Previous post was 02-20-2012 at 12:12 PM ----------

 

After some messing around with TProgressBars Ive came to the conclusion making my own would be so much easier. I guess young dogs dont ever listen and the old dogs are always right. Anyways here is what i came up with pretty simple i tried rounding edges but could accomplish it.

 

[scar]procedure ProgressBar(Pos: Integer);

Var

I,II,BMP: Integer;

begin

DisplayDebugImgWindow(200,200);

BMP := BitmapFromString(200,200,'');

FastDrawClear(BMP,clBlack);

SafeDrawBitmap(BMP,GetDebugCanvas,0,0);

For I := 0 to Pos do

For II := 0 to 15 do

FastSetPixel(BMP, I, II, clGreen);

SafeDrawBitmap(BMP,GetDebugCanvas,10,10);

FreeBitmap(BMP);

end; [/scar]

 

Heres Function Example:

[scar]program ProgressExample;

{$DEFINE RS2}

{.include OSI\OSI.scar}

 

Procedure ProgressBar(Pos, X, Y : Integer);

Var

I,II,H,BMP,BMP1: Integer;

TPA: TPointArray;

begin

if Pos > 100 then

Pos := 100;

BMP1 := BitmapFromString(164,18,'');

FastDrawClear(BMP,clSilver);

 

BMP := BitmapFromString(160,16,'');

FastDrawClear(BMP,clGray);

For I := 0 to Round((Pos*2)/1.25) do // Makes Bar bigger than just 100 pixels long.

For II := 0 to 15 do

FastSetPixel(BMP, I, II, clLime);

 

TPA := LoadTextTPA(IntToStr(Pos)+'%', OptionChars); // Prints Precentage

H := High(TPA);

for I := 0 to H do

FastSetPixel(BMP, TPA.X, TPA.Y, 2302226);

 

SmartDebugBitmap(BMP1,X-1,Y-1);

SmartDebugBitmap(BMP,X,Y);

 

FreeBitmap(BMP);

FreeBitmap(BMP1);

end;

 

Var

I: Integer;

begin

SetupOSI;

For I := o to 100 do

ProgressBar(I,20,20);

end.[/scar]

Heres a pic of my archaic progress bar.. lol

[ATTACH=CONFIG]314[/ATTACH]

Edited by shadowrecon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...