Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: MIDLet Pascal: Stop Watch

  1. #1
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    MIDLet Pascal: Stop Watch

    Not really game related so I put it in Off-Topic

    A friend of mine heard I was playing with CellPhone development and asked me to write them a simple stop watch application.

    I would appreciate any comments of performance imprevements and on which phones this application has problems (or works).

    [pascal]
    program StopWatch;
    // ************************************************** **
    // Stop Watch application for phones that do not have a
    // Stop Watch installed.
    // Two modes:
    // Off: Allows an exit or a start stop watch command
    // On: Allows stop or create split
    // Only 9 splits allowed. When limit of 9 is reached,
    // split option is removed.
    //
    // Date: 2006/01/27
    // Author: William Cairns
    // ************************************************** **

    Var
    StartTime : Integer;
    LastSplit : Integer;
    Splits : Array[0..9] of Integer;
    SplitDisplay : Array[0..9] of String;
    Start, Exit, Stop, Split : Command;

    // Convert a Millisecond Time value to a MMSSS string Value.
    Function MakeTimeStr(InTime : Integer): String;
    Var
    MS, S, M : Integer;
    SMS, SS, SM : String;
    Begin
    MS := InTime mod 1000;
    S := InTime div 1000;
    M := S div 60;
    S := S mod 60;
    SMS := IntegerToString(MS);
    SS := IntegerToString(S);
    If Length(SS) = 1 then
    SS := '0'+SS;
    SM := IntegerToString(M);
    If Length(SM) = 1 then
    SM := '0'+SM;
    MakeTimeStr := SM+':'+SS+':'+SMS;
    End;

    // Display current splits one under each other
    Procedure DisplaySplits;
    Var
    I,Y : Integer;
    Begin
    Y := 20;
    For I := 0 to LastSplit do
    Begin
    DrawText(SplitDisplay[I],0,Y);
    Y := Y + GetStringHeight(SplitDisplay[I]);
    End;
    End;

    // Clear the Split Arrays
    Procedure ClearSplits;
    Var
    I : Integer;
    Begin
    For I := 0 to 9 do
    Begin
    Splits[I] := 0;
    SplitDisplay[I] := '';
    End;
    End;

    // This procedure is used when the stop watch is running.
    // After 9 splits the plsit option is removed and it can only be stopped
    Procedure ModeOn;
    Var
    C : Command;
    Begin
    Stop := CreateCommand('Stop',CM_OK,1);
    Split := CreateCommand('Split',CM_EXIT,1);
    Addcommand(Split);
    AddCommand(Stop);
    Repeat
    setColor(0, 0, 0);
    fillRect(0, 0, getWidth, getHeight);
    setColor(255,255,255);
    DrawText(MakeTimeStr(GetRelativeTimeMs - StartTime),40,0);
    DisplaySplits;
    Repaint;
    C := getClickedCommand;
    If (C = Split) or (C = Stop) then
    Begin
    Splits[LastSplit] := GetRelativeTimeMs - StartTime;
    SplitDisplay[LastSplit] := MakeTimeStr(Splits[LastSplit]);
    LastSplit := LastSplit + 1;
    End;
    If LastSplit = 9 then
    RemoveCommand(Split);
    Until C = Stop;
    RemoveCommand(Stop);
    RemoveCommand(Split);
    End;

    // Displays Title Screen - only used when there are no splits in Off Mode
    Procedure ShowTitle;
    var
    textToDisplay : string;
    textXPos : integer;
    textYPos : integer;
    begin
    setColor(255, 255, 255);
    fillRect(0, 0, getWidth, getHeight);

    setColor(0, 0, 255);
    setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_BOLD, FONT_SIZE_LARGE);

    textToDisplay := 'Stop Watch';
    textXPos := (getWidth - getStringWidth(textToDisplay)) div 2;
    textYPos := (getHeight - getStringHeight(textToDisplay)) / 2;
    drawText(textToDisplay, textXPos, textYPos);
    textYPos := textYPos + getStringHeight(textToDisplay);

    setColor(0, 0, 0);

    setFont(FONT_FACE_PROPORTIONAL, FONT_STYLE_PLAIN, FONT_SIZE_SMALL);

    textToDisplay := 'Created with MIDletPascal';
    textXPos := (getWidth - getStringWidth(textToDisplay)) div 2;
    drawText(textToDisplay, textXPos, textYPos);
    textYPos := textYPos + getStringHeight(textToDisplay);
    textYPos := textYPos + getStringHeight(textToDisplay);

    textToDisplay := 'by William Cairns ';
    textXPos := (getWidth - getStringWidth(textToDisplay)) div 2;
    drawText(textToDisplay, textXPos, textYPos);
    repaint;
    End;

    // Used when Stop Watch is not running.
    Procedure ModeOff;
    Var
    C : Command;
    Begin
    Start := CreateCommand('Start',CM_OK,1);
    Exit := CreateCommand('Exit',CM_EXIT,1);
    Addcommand(Start);
    AddCommand(Exit);
    ShowTitle;
    Repeat
    C := getClickedCommand;
    If C = Start then
    Begin
    RemoveCommand(Start);
    RemoveCommand(Exit);
    ClearSplits;
    StartTime := GetRelativeTimeMs;
    LastSplit := 0;
    ModeOn;
    AddCommand(Start);
    AddCommand(Exit);
    If LastSplit > 0 then
    Begin
    setColor(0, 0, 0);
    fillRect(0, 0, getWidth, getHeight);
    setColor(255,255,255);
    DisplaySplits;
    End;
    Repaint;
    End;
    Until C = Exit;
    RemoveCommand(Start);
    RemoveCommand(Exit);
    End;

    begin
    ModeOff;
    end.
    [/pascal]

    Bug Report: The Midlet does not restart properly once the splits are full - still working on it.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  2. #2

    MIDLet Pascal: Stop Watch

    Not related to your question, but I have a Motorola V525 phone that has a few Java games on it, how do I upload your midlet to it? The only option I see is to download them from Vodaphone live, which I don't really fancy doing.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    MIDLet Pascal: Stop Watch

    I'll load it to my web site a bit later tonight and let you know the address.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    MIDLet Pascal: Stop Watch

    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #5

    MIDLet Pascal: Stop Watch

    Works Great! Does not seem to have any restart issues.

    My only problem is that only 7 splits fit on my screen, with the counter going at the top ( so eight lines in all ), so if I go for the full 9 splits I can't see the 8th 9th and the final stop time as I can't scroll to them.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  6. #6

    MIDLet Pascal: Stop Watch

    A couple of work around solutions :
    1. Implement a scroll feature, which may be too much hassle ( depending on how much you are being paid for this ),
    2. Alternatively move the stop watch counter part to the bottom of the display so that the latest split and counter are always visible, and scroll appropriately based on the height of the screen.
    3. It looks like 2 columns of information would fit, so you could implement 5 splits per column with the stop watch counter at the bottom centered.

    I would also add the number 1. 2. etc infront of each split just for clarity.

    I hope this helps.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  7. #7

    MIDLet Pascal: Stop Watch

    Sorry a couple more things... No icon is associated with the application and when I look at Details it says "MIDletPascal", it would be nice if it said "Cairns Games" instead , but I don't know if you need the licenced version to fix that.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  8. #8
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    MIDLet Pascal: Stop Watch

    Thanks Savage!!!

    Version 1.0.1 added
    - Smaller gap between Lines
    - Smaller Text Size
    - Adds Number infront of each line
    - CairnsGames added as Midlet Vendor
    - Funny Green Icon added.

    Same web link as above.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  9. #9

    MIDLet Pascal: Stop Watch

    Hmm, still no icon on the phone, other games have icons, but none of the MIDletPascal ones do ( I downloaded Dave.jar from MIDlet as well ). I now see CairnsGames, yeah!

    Everything fits on the screen now, but because there is no spacing at all between each split they overlap by about 2 pixels, which makes them a hard to read.

    You might gain a slight speed improvement if you cache the height of a standard split as it is unlikely to change between splits and you would save on the function call overhead and possibly on the array lookup. Something like this...
    [pascal]
    Var
    SplitTextHeight : Integer;

    Procedure ModeOn;
    begin
    ...
    SplitTextHeight := GetStringHeight( '00:00:000' );
    ...
    end;

    Procedure DisplaySplits;
    Var
    I,Y : Integer;
    Begin
    Y := 19;
    For I := 0 to LastSplit do
    Begin
    DrawText( SplitDisplay[ I ], 0, Y );
    Y := Y + SplitTextHeight;
    End;
    End;
    [/pascal]

    I would also make Y := 19; and adjust SplitTextHeight so that there is at least 1 pixel space between each split.

    If you fix these, you can start selling your first MIDletPascal app! .
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  10. #10
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    MIDLet Pascal: Stop Watch

    Thanks Savage. The latest version has a hardcoded text size and while it works on some phones others overlap like you say. Only solution I can come up with is to use a small text size.

    I have seen the icon being diaplayed on some phones.

    The speed improvement from caching the text height is probably worth doing for this little app.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •