TLauncher.bmx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. Strict
  2. Import MaxGui.Drivers
  3. Import "PNGHeader.bmx"
  4. Incbin "bmxlogo.png"
  5. Type TAR
  6. Field width:Int
  7. Field height:Int
  8. Function Create:TAR( width:Int , height:Int )
  9. Local temp:TAR = New TAR
  10. temp.width = width
  11. temp.height = height
  12. Return temp
  13. EndFunction
  14. Method ToString:String()
  15. Return width + ":" + height
  16. EndMethod
  17. EndType
  18. Type TLauncher
  19. Field angle = 0
  20. Field sync:TTimer
  21. Field myWindow:TGadget
  22. Field myCanvas:TGadget
  23. Field myLogo:TImage
  24. Field myLB:TGadget
  25. Field resMap:TMap
  26. Field btnLaunch:TGadget
  27. Field btnAbort:TGadget
  28. Field terminate = False
  29. Field selected:TGraphicsMode
  30. Field isDisposed = True
  31. Field aspectRatios:TList
  32. Field pngInfo:PNGHeader
  33. Method initGUI()
  34. myWindow = CreateWindow("Arise GUI Launcher - BETA", Desktop().width/2 - 100, Desktop().height/2 - 100, 200, 200, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS | WINDOW_HIDDEN)
  35. myCanvas:TGadget = CreateCanvas ( 0 , 0 , 200 , 87 , myWindow)
  36. pngInfo:PNGHeader = PNGHeader.fromPtr(IncbinPtr( "bmxlogo.png" ))
  37. If pngInfo.isPNG()
  38. myLogo:TImage = LoadAnimImage( "incbin::bmxlogo.png",pngInfo.width,1,0,pngInfo.height )
  39. EndIf
  40. myLB:TGadget = CreateListBox(0,88,200,93,myWindow)
  41. For Local i:String = EachIn resMap.Keys()
  42. AddGadgetItem myLB , i
  43. Next
  44. 'SelectGadgetItem myLB , CountGadgetItems(myLB) -1
  45. sync = CreateTimer(100)
  46. btnLaunch = CreateButton ("LAUNCH!" , 0,181,100,20,myWindow)
  47. btnAbort = CreateButton ("ABORT!" , 100,181,100,20,myWindow)
  48. isDisposed = False
  49. EndMethod
  50. Function Create:TLauncher()
  51. Local temp:TLauncher = New TLauncher
  52. temp.addAspectRatio( 4 , 3 )
  53. temp.populateModes
  54. Return temp
  55. End Function
  56. Method populateModes()
  57. If aspectRatios = Null
  58. addAspectRatio( 4 , 3 )
  59. EndIf
  60. resMap = New TMap
  61. For Local i:TGraphicsMode = EachIn GraphicsModes()
  62. For Local j:TAR = EachIn aspectRatios
  63. If i.width / j.width = i.height / j.height And i.depth > 8
  64. Local res:String = i.width + " x " + i.height + " - " + i.depth + " bits @ " + i.hertz + "Hz"
  65. resMap.insert res , i
  66. Exit
  67. EndIf
  68. Next
  69. Next
  70. EndMethod
  71. Method addAspectRatio( width:Int , height:Int )
  72. If aspectRatios = Null
  73. aspectRatios = New TList
  74. EndIf
  75. aspectRatios.addLast( TAR.Create( width , height ))
  76. EndMethod
  77. Method show()
  78. If Not isDisposed
  79. ShowGadget myWindow
  80. EndIf
  81. EndMethod
  82. Method hide()
  83. If Not isDisposed
  84. HideGadget myWindow
  85. EndIf
  86. EndMethod
  87. Method dispose()
  88. FreeGadget myWindow
  89. FreeGadget myCanvas
  90. FreeGadget btnLaunch
  91. FreeGadget btnAbort
  92. FreeGadget myLB
  93. myLogo = Null
  94. resMap = Null
  95. myWindow = Null
  96. myCanvas = Null
  97. btnLaunch = Null
  98. btnAbort = Null
  99. myLB = Null
  100. isDisposed = True
  101. EndMethod
  102. Method getSelectedMode:TGraphicsMode()
  103. Return selected
  104. EndMethod
  105. Method main()
  106. If Not isDisposed
  107. WaitEvent
  108. If CurrentEvent.id = EVENT_TIMERTICK
  109. angle = TimerTicks(sync) Mod 360
  110. SetGraphics CanvasGraphics( myCanvas )
  111. SetClsColor 255 , 255 , 255
  112. Cls
  113. For Local i:Int = 0 Until pngInfo.height
  114. DrawImage myLogo,24 + Sin(angle+i*2) * 48,i,i
  115. Next
  116. Flip
  117. ElseIf CurrentEvent.id = EVENT_APPTERMINATE Or CurrentEvent.id = EVENT_WINDOWCLOSE Or..
  118. ( CurrentEvent.id = EVENT_GADGETACTION And EventSource() = btnAbort )
  119. terminate = True
  120. ElseIf ( CurrentEvent.id = EVENT_GADGETACTION And EventSource() = btnLaunch )
  121. terminate = True
  122. If SelectedGadgetItem(myLB)<>-1
  123. selected = TGraphicsMode(resMap.ValueForKey(GadgetItemText(myLB,SelectedGadgetItem(myLB))))
  124. EndIf
  125. EndIf
  126. EndIf
  127. EndMethod
  128. EndType