Author Topic: Progress wheel  (Read 2388 times)

MrTAToad

  • Guest
Progress wheel
« on: 2011-Jun-16 »
This code creates a progress wheel.  In addition, to the standard updating function, you can pass it a percentage value, which will be displayed inside it.

Call Initialise first, and then Update every time something is loaded or read or saved.

Code: (glbasic) [Select]

// --------------------------------- //
// Project: Spots_TheBoardGame
// Start: Friday, June 10, 2011
// IDE Version: 10.013

TYPE TProgress
spriteID% = -1
sprX%;sprY%
textX%;textY%;textFont%
angle

perc$="000"

FUNCTION Initialise%:useFont%=-1
LOCAL array%[]
LOCAL loop%,text$,dupSize%=4,hexSize%=8
LOCAL screenWidth%,screenHeight%,index%,sprWidth%,sprHeight%
LOCAL fW%,fH%

self.spriteID%=GENSPRITE()
IF self.spriteID%>=0
GETSCREENSIZE screenWidth%,screenHeight%

self.angle=0.0

RESTORE progress_1
READ sprWidth%,sprHeight%
IF sprWidth%*sprHeight%<=0 THEN RETURN FALSE

DIM array%[sprWidth%*sprHeight%]
index%=0

READ text$
WHILE text$<>"--------"
    IF LEN(text$)<8 THEN RETURN FALSE

    loop%=0
    WHILE loop%<LEN(text$)
        IF MID$(text$,loop%,1)="*"
          LOCAL value%,amount%

// Duplicate data
amount%=self.hexToDec(MID$(text$,loop%+1,dupSize%))
value%=self.hexToDec(MID$(text$,loop%+1+dupSize%,hexSize%))
WHILE amount%>0
array%[index%]=value%
INC index%
DEC amount%
WEND

          INC loop%,hexSize%+dupSize%+1
        ELSE
                   array%[index%]=self.hexToDec(MID$(text$,loop%,hexSize%))
                   INC loop%,hexSize%
                   INC index%
                ENDIF
  WEND
  READ text$
WEND

IF MEM2SPRITE(array%[],self.spriteID%,sprWidth%,sprHeight%)=FALSE THEN RETURN FALSE

self.sprX%=(screenWidth%-sprWidth%)/2
self.sprY%=(screenHeight%-sprHeight%)/2

IF useFont%>=0
SETFONT useFont%
ENDIF

GETFONTSIZE fW%,fH%
self.textX%=self.sprX%+((sprWidth%-(LEN(self.perc$)*fW%))/2)
self.textY%=self.sprY%+((sprHeight%-fH%)/2)
self.textFont%=useFont%
RETURN TRUE
ENDIF

RETURN FALSE
ENDFUNCTION

FUNCTION Destroy%:
IF self.spriteID%>=0 THEN LOADSPRITE "",self.spriteID%
ENDFUNCTION

FUNCTION Update%:percentage%=-1
ALPHAMODE 0.0
SMOOTHSHADING FALSE

ROTOZOOMSPRITE self.spriteID%,self.sprX%,self.sprY%,self.angle,1.0

IF self.textFont%>=0 THEN SETFONT self.textFont%
IF percentage>=0 AND percentage%<=100 THEN PRINT RIGHT$(self.perc$+percentage%,LEN(self.perc$)),self.textX%,self.textY%

SHOWSCREEN

INC self.angle,0.5
IF self.angle>=360.0 THEN self.angle=0.0
ENDFUNCTION

//! Convert a hexadecimal number of an integer
//param hex$ - Hexidecimal string
//\return The decimal value of the passed string
FUNCTION hexToDec%:hex$
LOCAL i%
LOCAL j%
LOCAL loop%

    i%=0
    j%=0
    FOR loop%=0 TO LEN(hex$)-1
        i%=ASC(MID$(hex$,loop%,1))-48
        IF 9<i% THEN DEC i%,7
        j%=bOR(j%*16,bAND(i,15))
    NEXT

    RETURN j%
ENDFUNCTION
ENDTYPE

// This is the data for the file C:/Users/Nicholas/Documents/GLBasic/Utilities/GraphicToDATA/GraphicToDATA.app/progress.png
STARTDATA progress_1:
    DATA 64,64
    DATA "*001A00000000*000C00FF00FF*00300000000000FFF8FF00FFFAFF00FFD1FF00FF7EFF00FF20FF*000AFF0000FF*000500FF00FF*00290000000000FFEDFF00FFEFFF00FFF0FF00FFF4FFFFF8F8FFFFFCFCFFFF8080FF*000FFF0000FF*000400FF00FF*00240000000000FFE5FF00FFE6FF00FFE9FFFFEDEDFFFFF1F1FFFFF3F3FFFFF7F7FFFFFBFBFFFFC9C9FF*0012FF0000FF*000300FF00FF*002000000000"
    DATA "00FFDDFF00FFDEFF00FFE1FFFFE5E5FFFFE8E8FFFFECECFFFFEFEFFFFFF2F2FFFFF6F6FFFFFAFAFFFFFEFEFF*0014FF0000FF*000300FF00FF*001C0000000000FFD5FF00FFD6FF00FFD9FFFFDDDDFFFFE0E0FFFFE4E4FFFFE7E7FFFFEAEAFFFFEEEEFFFFF1F1FFFFF5F5FFFFF9F9FFFFFDFDFF*0016FF0000FF*000300FF00FF*00190000000000FFD0FF00FFD2FFFFD5D5FF"
    DATA "FFD8D8FFFFDBDBFFFFDEDEFFFFE2E2FFFFE6E6FFFFE8E8FFFFECECFFFFF0F0FFFFF4F4FFFFF8F8FFFFFCFCFFFF4C4CFF00FF13FF*000900FF00FF*000DFF0000FF*000200FF00FF*00170000000000FFCBFF00FFCDFFFFD0D0FFFFD3D3FFFFD6D6FFFFDADAFFFFDCDCFFFFE0E0FFFFE4E4FFFFE7E7FFFFEBEBFFFFEFEFFFFFF2F2FF00FFF6FF00FFC0FF00FFA4FF"
    DATA "00FF4CFF*000800000000*000400FF00FF*000BFF0000FF*000200FF00FF*00150000000000FFC6FF00FFC8FFFFCBCBFFFFCECEFFFFD1D1FFFFD4D4FFFFD7D7FFFFDBDBFFFFDEDEFFFFE2E2FFFFE6E6FF00FFE9FF00FFEEFF00FFF0FF00FFF2FF*000E00000000*000400FF00FF*0009FF0000FF*000200FF00FF*00130000000000FFC1FF00FFC3FFFFC6C6FFFFC9C9FFFFCCCCFFFFCFCFFFFFD1D1FF"
    DATA "FFD5D5FFFFD9D9FFFFDCDCFF00FFE0FF00FFE4FF00FFE6FF*001400000000*000300FF00FF*0008FF0000FF00FF09FF00FF1BFF*00110000000000FFBBFF00FFBEFFFFC1C1FFFFC4C4FFFFC6C6FFFFC9C9FFFFCCCCFFFFD0D0FFFFD2D2FF00FFD7FF00FFDAFF00FFDCFF*001800000000*000300FF00FF*0006FF0000FFFF1B1BFF00FF4AFF00FF83FF*000F0000000000FFB7FF00FFB8FF"
    DATA "FFBBBBFFFFBEBEFFFFC1C1FFFFC4C4FFFFC6C6FFFFCACAFFFFCDCDFF00FFCFFF00FFD2FF*001C00000000*000200FF00FF*0004FF0000FFFF1919FFFF4141FFFF8383FF00FF86FF00FF89FF*000D0000000000FFB1FF00FFB4FFFFB7B7FFFFB8B8FFFFBBBBFFFFBEBEFFFFC1C1FFFFC4C4FFFFC7C7FF00FFCAFF00FFCDFF*001E00000000*000200FF00FF*0002FF0000FFFF1818FF"
    DATA "FF4040FFFF8484FFFF8686FFFF8989FF00FF8BFF00FF8EFF*000B0000000000FFACFF00FFAEFFFFB1B1FFFFB4B4FFFFB6B6FFFFB8B8FFFFBBBBFFFFBEBEFFFFC1C1FF00FFC4FF00FFC7FF*00200000000000FF00FF00FF07FFFF1515FFFF3F3FFFFF8484FFFF8787FFFF8989FFFF8C8CFFFF8E8EFF00FF91FF00FF94FF*000A0000000000FFABFFFFACACFF"
    DATA "FFAEAEFFFFB1B1FFFFB3B3FFFFB6B6FFFFB8B8FFFFBBBBFF00FFBEFF00FFC1FF*00220000000000FF15FF00FF48FFFF8484FFFF8787FFFF8A8AFFFF8D8DFFFF8F8FFFFF9292FFFF9494FF00FF95FF*00090000000000FFA4FF00FFA8FFFFAAAAFFFFACACFFFFADADFFFFB0B0FFFFB2B2FFFFB5B5FF00FFB8FF00FFBBFF*00240000000000FF84FF00FF87FF"
    DATA "FF8A8AFFFF8D8DFFFF9090FFFF9393FFFF9595FFFF9797FF00FF98FF00FF9DFF*00080000000000FFA2FFFFA4A4FFFFA6A6FFFFA8A8FFFFABABFFFFADADFFFFAFAFFF00FFB2FF00FFB5FF*00260000000000FF8AFF00FF8DFFFF9191FFFF9393FFFF9696FFFF9898FFFF9B9BFFFF9D9DFF00FF9EFF*00070000000000FF9CFF00FF9FFFFFA1A1FFFFA3A3FF"
    DATA "FFA5A5FFFFA7A7FFFFAAAAFF00FFABFF00FFAFFF*00280000000000FF91FF00FF95FFFF9797FFFF9A9AFFFF9C9CFFFF9E9EFFFFA0A0FF00FFA1FF00FFA5FF*00060000000000FF9AFFFF9C9CFFFF9E9EFFFFA0A0FFFFA2A2FFFFA3A3FFFFA6A6FF00FFA8FF*002A0000000000FF99FFFF9B9BFFFF9D9DFFFFA0A0FFFFA2A2FFFFA4A4FFFFA5A5FF00FFA7FF"
    DATA "*00050000000000FF95FF00FF98FFFF9999FFFF9B9BFFFF9C9CFFFF9E9EFFFFA1A1FF00FFA1FF00FFA6FF*002A0000000000FF9BFF00FF9FFFFFA1A1FFFFA3A3FFFFA5A5FFFFA7A7FFFFA9A9FF00FFAAFF00FFAEFF*00040000000000FF93FFFF9595FFFF9696FFFF9797FFFF9999FFFF9B9BFFFF9D9DFF00FF9FFF*002C0000000000FFA3FFFFA5A5FFFFA7A7FF"
    DATA "FFA9A9FFFFABABFFFFADADFFFFAEAEFF00FFB0FF*00040000000000FF91FFFF9191FFFF9292FFFF9494FFFF9696FFFF9797FF00FF98FF00FF9DFF*002C0000000000FFA5FF00FFA9FFFFABABFFFFADADFFFFAFAFFFFFB0B0FFFFB2B2FF00FFB2FF*00030000000000FF89FF00FF8CFFFF8D8DFFFF8F8FFFFF9090FFFF9292FFFF9393FF00FF93FF*002E00000000"
    DATA "00FFAFFFFFAFAFFFFFB1B1FFFFB3B3FFFFB4B4FFFFB6B6FF00FFB7FF00FFBBFF*00020000000000FF87FFFF8989FFFF8A8AFFFF8B8BFFFF8C8CFFFF8D8DFFFF8F8FFF00FF91FF*002E0000000000FFB1FFFFB4B4FFFFB5B5FFFFB7B7FFFFB8B8FFFFB9B9FFFFBBBBFF00FFBCFF*00020000000000FF85FFFF8585FFFF8686FFFF8888FFFF8989FFFF8A8AFF"
    DATA "00FF8BFF00FF8FFF*002E0000000000FFB4FF00FFB8FFFFBABAFFFFBBBBFFFFBCBCFFFFBDBDFFFFBEBEFF00FFBEFF*00020000000000FF73FFFF8181FFFF8282FFFF8383FFFF8585FFFF8686FF00FF85FF*00300000000000FFBEFFFFBEBEFFFFBFBFFFFFC0C0FFFFC1C1FFFFC2C2FF00FFC2FF0000000000FF00FF00FF35FFFF5454FFFF7979FFFF8080FF"
    DATA "*0002FF8181FF00FF83FF*00300000000000FFC0FFFFC2C2FFFFC4C4FF*0002FFC5C5FFFFC6C6FF00FFC7FF00FFCBFF00FF00FF*0004FF0000FFFF0D0DFF00FF43FF00FF81FF*00300000000000FFC2FF00FFC6FFFFC8C8FFFFC9C9FF*0002FFCACAFFFFCBCBFF00FFCDFF00FF00FF*0005FF0000FF00FF04FF*00320000000000FFCCFFFFCCCCFFFFCDCDFF*0002FFCECEFFFFCFCFFF00FFCFFF"
    DATA "00FF00FF*0005FF0000FF00FF00FF*00320000000000FFD0FF*0002FFD1D1FF*0002FFD2D2FFFFD3D3FF00FFD3FF00FF00FF*0005FF0000FF00FF00FF*00320000000000FFD5FFFFD5D5FF*0003FFD6D6FFFFD7D7FF00FFD7FF00FF00FF*0005FF0000FF00FF00FF*00320000000000FFDAFF*0003FFDADAFF*0002FFDBDBFF00FFDBFF00FF00FF*0005FF0000FF00FF00FF*00320000000000FFDEFF*0005FFDFDFFF00FFDFFF"
    DATA "00FF00FF*0005FF0000FF00FF00FF*00320000000000FFE3FF*0005FFE3E3FF00FFE3FF00FF00FF*0005FF0000FF00FF00FF*00320000000000FFE7FFFFE8E8FF*0004FFE7E7FF00FFE7FF00FF00FF*0005FF0000FF00FF00FF*00320000000000FFECFF*0002FFECECFF*0003FFEBEBFF00FFEBFF00FF00FF*0005FF0000FF*000200FF00FF*00300000000000FFF6FF00FFF2FFFFF1F1FF*0002FFF0F0FF*0002FFEFEFFF00FFEDFF"
    DATA "*000200FF00FF*0005FF0000FF00FF00FF*00300000000000FFF8FFFFF6F6FF*0002FFF5F5FFFFF4F4FFFFF3F3FF00FFF2FF00FFEFFF0000000000FF00FF*0005FF0000FF00FF00FF*00300000000000FFC8FFFFFBFBFFFFFAFAFFFFF9F9FFFFF8F8FFFFF7F7FF00FFF7FF*00020000000000FF00FF*0005FF0000FF*000200FF00FF*002E0000000000FF00FF00FF59FFFF6976FFFFCCD0FFFFFEFEFF"
    DATA "FFFDFDFFFFFBFBFF00FFD2FF*00020000000000FF00FF*0006FF0000FF00FF00FF*002E0000000000FF00FF*0004FF0015FFFF293BFFFF848EFF00FFBFFF*000200000000*000200FF00FF*0005FF0000FF00FF00FF*002E0000000000FF00FF*0005FF0015FF00FF2BFF00FF84FF*00030000000000FF00FF*0005FF0000FF*000200FF00FF*002C00000000*000200FF00FF*0005FF0015FF00FF00FF*00040000000000FF00FF*0006FF0000FF"
    DATA "00FF00FF*002C0000000000FF00FF*0006FF0015FF00FF00FF*000400000000*000200FF00FF*0005FF0000FF*000200FF00FF*002A00000000*000200FF00FF*0005FF0015FF*000200FF00FF*00050000000000FF00FF*0006FF0000FF00FF00FF*002A0000000000FF00FF*0006FF0015FF00FF00FF*000600000000*000200FF00FF*0005FF0000FF*000200FF00FF*002800000000*000200FF00FF*0005FF0015FF*000200FF00FF*00070000000000FF00FF*0006FF0000FF*000200FF00FF"
    DATA "*002600000000*000200FF00FF*0006FF0015FF00FF00FF*000800000000*000200FF00FF*0006FF0000FF*000200FF00FF*002400000000*000200FF00FF*0006FF0015FF*000200FF00FF*00090000000000FF00FF*0007FF0000FF*000200FF00FF*002200000000*000200FF00FF*0007FF0015FF00FF00FF*000A00000000*000200FF00FF*0007FF0000FF00FFA1FF00FFFAFF*002000000000*000200FF00FF*0007FF0015FF*000200FF00FF*000B00000000*000200FF00FF*0005FF0000FFFFEBEBFF"
    DATA "FFFAFAFF00FFF6FF00FFF3FF*001E00000000*000200FF00FF*0007FF0015FF*000200FF00FF*000D00000000*000200FF00FF*0003FF0000FFFFE5E5FFFFFBFBFFFFF7F7FFFFF3F3FF00FFEFFF00FFECFF*001C00000000*000200FF00FF*0007FF0015FF*000200FF00FF*000F00000000*000200FF00FFFF0000FFFFE1E1FFFFFBFBFFFFF8F8FFFFF4F4FFFFF0F0FFFFECECFF00FFE6FF00FFE3FF00FFE1FF*001800000000"
    DATA "*000300FF00FF*0007FF0015FF*000200FF00FF*00110000000000FF00FF00FF9EFFFFFBFBFFFFF8F8FFFFF5F5FFFFF0F0FFFFEDEDFFFFE9E9FFFFE5E5FFFFE1E1FF00FFDBFF00FFD7FF00FFD5FF*001400000000*000300FF00FF*0008FF0015FF*000200FF00FF*00130000000000FFFBFF00FFF8FFFFF5F5FFFFF1F1FFFFEEEEFFFFEAEAFFFFE7E7FFFFE2E2FFFFDEDEFFFFDADAFFFFD5D5FF"
    DATA "00FFD0FF00FFC9FF00FFC7FF00FFC5FF*000E00000000*000400FF00FF*0009FF0015FF*000200FF00FF*00150000000000FFF5FF00FFF1FFFFEFEFFFFFEBEBFFFFE8E8FFFFE3E3FFFFE0E0FFFFDCDCFFFFD7D7FFFFD3D3FFFFCFCFFFFFC9C9FFFFC5C5FF00FFC0FF00FFB9FF00FFB7FF00FFB5FF*000800000000*000400FF00FF*000BFF0015FF*000200FF00FF*00170000000000FFEFFF00FFEBFF"
    DATA "FFE9E9FFFFE5E5FFFFE1E1FFFFDEDEFFFFDADAFFFFD5D5FFFFD1D1FFFFCDCDFFFFC8C8FFFFC3C3FFFFBFBFFFFFB9B9FFFFB5B5FF00FFB0FF00FFA9FF00FFA4FF00FF9FFF00FF9AFF00FF95FF00FF90FF00FF8BFF00FF86FF00FF45FF*000DFF0015FF*000200FF00FF*00190000000000FFE9FF00FFE7FF00FFE3FFFFDFDFFFFFDCDCFFFFD7D7FFFFD3D3FF"
    DATA "FFCFCFFFFFCBCBFFFFC6C6FFFFC2C2FFFFBDBDFFFFB8B8FFFFB4B4FFFFAEAEFFFFAAAAFFFFA5A5FFFF9F9FFFFF9B9BFFFF9595FFFF9090FFFF8B8BFFFF8686FFFF8181FFFF1022FF*000AFF0015FF*000300FF00FF*001C0000000000FFDFFF00FFDDFF00FFD9FFFFD5D5FFFFD1D1FFFFCECEFFFFC9C9FFFFC5C5FFFFC1C1FFFFBBBBFFFFB7B7FFFFB3B3FF"
    DATA "FFAEAEFFFFA9A9FFFFA4A4FFFF9F9FFFFF9B9BFFFF9595FFFF9191FFFF8C8CFFFF8787FFFF8282FFFF3743FF*0008FF0015FF*000300FF00FF*00200000000000FFD5FF00FFD3FF00FFCFFFFFCBCBFFFFC7C7FFFFC3C3FFFFBFBFFFFFBABAFFFFB6B6FFFFB2B2FFFFADADFFFFA9A9FFFFA4A4FFFF9F9FFFFF9B9BFFFF9595FFFF9191FFFF8C8CFFFF8787FF"
    DATA "FF8383FFFF5C62FF*0006FF0015FF*000300FF00FF*00240000000000FFCBFF00FFC9FF00FFC7FF00FFC1FFFFBDBDFFFFB9B9FFFFB5B5FFFFB1B1FFFFACACFFFFA8A8FFFFA3A3FFFF9F9FFFFF9A9AFFFF9595FFFF9191FFFF8D8DFFFF8888FFFF8484FFFF7E7EFF*0003FF0015FF*000400FF00FF*00290000000000FFBDFF00FFBBFF00FFB9FF00FFB5FF00FFAFFFFFACACFF"
    DATA "FFA8A8FFFFA3A3FFFF9E9EFFFF9A9AFFFF9595FFFF9191FFFF8D8DFFFF8888FFFF8484FF00FF61FF00FF2AFF*000300FF00FF*00300000000000FFACFF00FFAAFF00FFA7FF00FFA3FF00FF9EFF00FF99FF00FF95FF00FF91FF00FF8CFF00FF88FF00FF86FF00FF84FF*001A00000000"
    DATA "--------"
ENDDATA

[attachment deleted by admin]

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10776
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Progress wheel
« Reply #1 on: 2011-Jun-20 »
DATA -graphics!!! Awesome idea.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1790
    • View Profile
    • Homepage
Re: Progress wheel
« Reply #2 on: 2011-Jun-20 »
That's what they wanted the data-statements for in the first place :-)

MrTAToad

  • Guest
Re: Progress wheel
« Reply #3 on: 2011-Jun-20 »
Plus, it gets around DDgui_waitcursor dont being displayed correctly on some android machines :)

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Progress wheel
« Reply #4 on: 2011-Jun-21 »
Cool :) Do you mind if this or a variation of it is used for the Fuzed project? Full credit will be given of course.  8)

MrTAToad

  • Guest
Re: Progress wheel
« Reply #5 on: 2011-Jun-21 »
Go ahead!