home *** CD-ROM | disk | FTP | other *** search
/ ANews 3 / AnewsCD3.iso / DP / Programmation / PureBasic_Demo / Examples / Sources / WildManager.pb < prev    next >
Encoding:
Text File  |  1999-10-10  |  12.7 KB  |  633 lines

  1. ;
  2. ;
  3. ; ---------->        <------
  4. ; Wild Manager      V1.01
  5. ; ------------>    <--------
  6. ;
  7. ; © 1999 - Fantaisie Software - Coded by AlphaSND
  8. ;
  9. ;
  10. ; Description: Preference front-end for the WILD 3D package from 'Pyper'
  11. ;
  12. ;
  13. ; NOTE:
  14. ; -----
  15. ;
  16. ; A String in a linked list must not be to NULL for the listview, else
  17. ; we got an enforcer hit (AmigaOS 'bug') !
  18. ;
  19. ;
  20.  
  21. WBStartup()
  22.  
  23. InitScreen(0)
  24. InitWindow(0)
  25. InitGadget(0)
  26. InitFile  (0)
  27.  
  28. If InitRequester() = 0
  29.   End
  30. EndIf
  31.  
  32. *TagList = InitTagList(10)  ; Note you can use TagListID() but using a variable is smaller/faster
  33.  
  34. Mode.s
  35.  
  36. Structure PBScreenInfo
  37.   DisplayID.l     ; Display mode ID
  38.   Width.l         ; Width of display in pixels
  39.   Height.l        ; Height of display in pixels
  40.   Depth.w         ; Number of bit-planes of display
  41.   OverscanType.w  ; Type of overscan of display
  42.   AutoScroll.b
  43. EndStructure
  44.  
  45.  
  46. Structure NLVList
  47.   Pad.w
  48.   Item.s
  49.   Command.s
  50.   Processors.b
  51.   Rendering.b
  52.   Warp3D.b
  53.   Width.w
  54.   Height.w
  55.   ScreenID.l
  56.   Changed.b
  57.   AGA.b
  58. EndStructure
  59.  
  60. NewList PL.NLVList()
  61.  
  62. ;
  63. ; Read pref file..
  64. ;
  65. ;LoadPref
  66.  
  67. If ReadFile(0, "PROGDIR:WildManager.pref")
  68.  
  69.   a$ = ReadString()
  70.   If a$ = "WildManagerPref1"
  71.     NbProg = ReadWord()
  72.  
  73.     For k=0 To NbProg-1
  74.       If AddElement(PL())
  75.         PL()\Item       = ReadString()
  76.         PL()\Command    = ReadString()
  77.         PL()\Processors = ReadByte()
  78.         PL()\Rendering  = ReadByte()
  79.         PL()\Warp3D     = ReadByte()
  80.         PL()\Width      = ReadWord()
  81.         PL()\Height     = ReadWord()
  82.         PL()\ScreenID   = ReadLong()
  83.         PL()\AGA        = ReadByte()
  84.       EndIf
  85.  
  86.       a$ = ReadString() ; "WAM_End_WAM"
  87.     Next
  88.  
  89.   EndIf
  90.  
  91.   CloseFile(0)
  92. Else
  93.   NoPref = 1
  94. EndIf
  95.  
  96. If NbProg<1 OR NoPref
  97.   AddElement(PL())
  98.   PL()\Item = "Program 1"
  99.   NbProg = 1
  100. EndIf
  101.  
  102. FirstElement(PL())
  103.  
  104. Dim Language.s(8)
  105.  
  106. *MyScreen = FindScreen(0,"Workbench")
  107.  
  108. ;
  109. ; Now, create all the windows gadgets
  110. ;
  111.  
  112. If CreateGadgetList(0, ScreenID())
  113.  
  114.   HG     = 20
  115.   HFont  = ScreenFontHeight()
  116.   HFont3 = HFont+3
  117.   HFont6 = HFont+6
  118.  
  119.   Top = HG
  120.  
  121.   ResetTagList(#GTST_MaxChars,100)
  122.         AddTag(#GA_Immediate, 1)
  123.         AddTag(#GTST_String, PL()\Item)
  124.   StringGadget(1, 210, HG, 200, HFont6, "Name:", *TagList) : HG=HG+HFont6+2
  125.  
  126.  
  127.   a$ = "Fountain.exe"
  128.   ResetTagList(#GTST_MaxChars,1000)
  129.         AddTag(#GTST_String, PL()\Command)
  130.         AddTag(#GA_Immediate, 1)
  131.   StringGadget(2, 210, HG, 180, HFont6, "Program:", *TagList)
  132.  
  133.   ButtonGadget(16,  390, HG, 20, HFont6, "?"   , 0) : HG=HG+HFont6+10
  134.                                                                                                                               
  135.   Dim WildProcessor.s(2)
  136.   WildProcessor(0) = "680x0"
  137.   WildProcessor(1) = "PowerPC"
  138.  
  139.   ResetTagList(#GTCY_Labels, WildProcessor())
  140.         AddTag(#GTCY_Active, PL()\Processors)
  141.   SetGadgetFlags(#PLACETEXT_LEFT)
  142.   CycleGadget (7, 210, HG, 100, HFont6, "Amiga:", *TagList) : HG=HG+HFont6+2
  143.  
  144.   Dim WildRender.s(4)
  145.   WildRender(0) = "WireFrame"
  146.   WildRender(1) = "Flat"
  147.   WildRender(2) = "Gouraud"
  148.   WildRender(3) = "Textured"
  149.  
  150.   ResetTagList(#GTCY_Labels, WildRender())
  151.         AddTag(#GTCY_Active, PL()\Rendering)
  152.   SetGadgetFlags(#PLACETEXT_LEFT)
  153.   CycleGadget(8, 210, HG, 100, HFont6, "Rendering:", *TagList) : HG=HG+HFont6+2
  154.                                                                                                                               
  155.   ResetTagList(#GTCB_Scaled, 1)
  156.         AddTag(#GTCB_Checked, PL()\Warp3D)
  157.   SetGadgetFlags(#PLACETEXT_LEFT)
  158.   CheckBoxGadget(13, 210, HG, HFont6, HFont6, "Warp3D:", *TagList) : HG=HG+HFont6+2
  159.  
  160.   TextGadget(11,  210, HG,  0, HFont6, "Screen:" , 0)
  161.   SetGadgetFlags(#PLACETEXT_IN)
  162.  
  163.   TextGadget(20,  330, HG,  80, HFont6, "" , 0)
  164.  
  165.   Dim WildScreen.s(2)
  166.   WildScreen(0) = "CGFX"
  167.   WildScreen(1) = "AGA"
  168.  
  169.   ResetTagList (#GTCY_Labels, WildScreen())
  170.         AddTag (#GTCY_Active, PL()\AGA)
  171.   CycleGadget  (21,  210, HG, 60, HFont6, "", *TagList)
  172.   ButtonGadget (10,  272, HG, 50, HFont6, "Set", 0) : HG=HG+HFont6+HFont
  173.  
  174.   If PL()\Command = ""
  175.     a=1
  176.   Else
  177.     a=0
  178.   Endif
  179.  
  180.   ResetTagList (#GA_Disabled, a)
  181.   ButtonGadget (17,  210, HG, 200, HFont6, "-> Launch IT ! <-"   , *TagList)
  182.  
  183.   *RealList = ListBase(PL())
  184.  
  185.   ResetTagList (#GTLV_Labels, *RealList)
  186.         AddTag (#GTLV_ShowSelected, 0)
  187.         AddTag (#GTLV_Selected, 0)
  188.   SetGadgetFlags (#PLACETEXT_ABOVE)
  189.   *a.Gadget = ListViewGadget(9, 12, Top+HFont+7, 100, HG-Top-(HFont+7), "Programs:", *TagList)
  190.   ListViewGadget(9, 12, Top+HFont+7, 100, HG-Top-(HFont+7), "Programs:", *TagList)
  191.  
  192.   real = Top+HFont+9+*a\Height
  193.  
  194.   SetGadgetFlags (#PLACETEXT_IN)
  195.   ButtonGadget   (14,  12, real, 49, HFont6, "Add", 0)
  196.   ButtonGadget   (15,  63, real, 49, HFont6, "Del", 0) : HG=HG+HFont6+16
  197.  
  198.   SetGadgetFlags (#PLACETEXT_IN)
  199.   ButtonGadget   (4,  12, HG, 125, HFont6+2, "Save"   , 0)
  200.   ButtonGadget   (5, 148, HG, 125, HFont6+2, "Use"    , 0)
  201.   ButtonGadget   (6, 285, HG, 125, HFont6+2, "Cancel" , 0)
  202.  
  203. EndIf
  204.  
  205. ;
  206. ; Open our window and attach gadgets & menus..
  207. ;
  208.  
  209. WinTitle$    = "Wild Manager V1.00"
  210. ScreenTitle$ = "Wild Manager - © 1999 Fantaisie Software"
  211.  
  212. ResetTagList (#WA_Title, @WinTitle$)
  213.       AddTag (#WA_CustomScreen, ScreenID())
  214.       AddTag (#WA_ScreenTitle, @ScreenTitle$)
  215.  
  216. WHeight = HG+HFont+2
  217. If OpenWindow(0, ScreenWidth()/2-210, HFont+20, 416, WHeight, #WFLG_CLOSEGADGET | #WFLG_DRAGBAR | #WFLG_DEPTHGADGET | #WFLG_ACTIVATE | #WFLG_RMBTRAP, *TagList)
  218.  
  219.   BevelBox(WindowBorderLeft(),WindowBorderTop(),WindowInnerWidth(),WindowInnerHeight(),0)
  220.  
  221.   BevelBox(WindowBorderLeft()-1,HG-7,WindowInnerWidth()+2,2,1)
  222.  
  223.   AttachGadgetList(0, WindowID())
  224.  
  225.   Gosub DisableWarp3D
  226.   Gosub DisableDel
  227.  
  228.   Gosub RefreshScreenMode
  229.  
  230. MainLoop:
  231.   Repeat
  232.  
  233.     Repeat
  234.       VWait()
  235.       IDCMP.l = WindowEvent()
  236.     Until IDCMP
  237.  
  238.     ; Special for mouseclick when editing a String !
  239.     ;
  240.     ;
  241.     If MustBeRefreshed
  242.       If MustBeRefreshed = 1
  243.         Gosub String1
  244.       Else
  245.         Gosub String2
  246.       EndIf
  247.  
  248.       MustBeRefreshed = 0
  249.     EndIf
  250.  
  251.  
  252.     Gadget = EventGadget()
  253.     Code   = EventCode()
  254.  
  255.     If IDCMP = #IDCMP_GADGETUP OR IDCMP = #IDCMP_GADGETDOWN ; A gadget has been pushed
  256.  
  257.       Select Gadget
  258.         Case 1
  259.           Gosub String1
  260.           MustBeRefreshed = 1
  261.  
  262.  
  263.         Case 2
  264.           Gosub String2
  265.           MustBeRefreshed = 2
  266.  
  267.  
  268.         Case 4 ; 'Save'
  269.           Gosub SavePrefs
  270.           IDCMP = #IDCMP_CLOSEWINDOW
  271.  
  272.  
  273.         Case 5 ; 'Use'
  274.           IDCMP = #IDCMP_CLOSEWINDOW
  275.  
  276.  
  277.         Case 6 ; 'Cancel'
  278.           IDCMP = #IDCMP_CLOSEWINDOW
  279.  
  280.  
  281.         Case 7
  282.           PL()\Processors = Code
  283.           PL()\Changed = 1
  284.  
  285.  
  286.         Case 8
  287.           PL()\Rendering = Code
  288.           PL()\Changed = 1
  289.  
  290.           Gosub DisableWarp3D
  291.  
  292.  
  293.         Case 9
  294.           ResetList(PL())
  295.  
  296.           For k=0 To Code
  297.             NextElement(PL())
  298.           Next
  299.  
  300.           Gosub RefreshWindow
  301.  
  302.  
  303.         Case 10
  304.  
  305.           ResetTagList (#ASLSM_DoWidth          , 1)
  306.                 AddTag (#ASLSM_DoHeight         , 1)
  307.                 AddTag (#ASLSM_DoOverscanType   , 1)
  308.                 AddTag (#ASLSM_InitialDisplayID , PL()\ScreenID)
  309.                 If PL()\Width
  310.                   AddTag (#ASLSM_InitialDisplayWidth  , PL()\Width)
  311.                   AddTag (#ASLSM_InitialDisplayHeight , PL()\Height)
  312.                 EndIf
  313.  
  314.           *sm.PBScreenInfo = ScreenRequester(*TagList)
  315.           If *sm
  316.             PL()\Width    = *sm\Width
  317.             PL()\Height   = *sm\Height
  318.             PL()\ScreenID = *sm\DisplayID
  319.           EndIf
  320.  
  321.           Gosub RefreshScreenMode
  322.  
  323.           PL()\Changed = 1
  324.  
  325.  
  326.         Case 13 ; 'Warp3D - On/Off'
  327.           PL()\Warp3D = Code
  328.           PL()\Changed = 1
  329.  
  330.  
  331.         Case 14 ; 'Add'
  332.  
  333.           NbProg = NbProg+1
  334.           AddElement(PL())
  335.           PL()\Item = ""
  336.  
  337.           GadgetAttrs(9, #GTLV_Labels, *RealList)
  338.           GadgetAttrs(9, #GTLV_Selected, ListIndex(PL()))
  339.  
  340.           RefreshGadget(9)
  341.           Gosub RefreshWindow
  342.  
  343.           ActivateGadget(1)
  344.  
  345.  
  346.         Case 15 ; 'Del'
  347.           KillElement(PL())
  348.  
  349.           NbProg = NbProg-1
  350.  
  351.           GadgetAttrs(9, #GTLV_Labels, *RealList)
  352.           RefreshGadget(9)
  353.           NextElement(PL())
  354.           Gosub RefreshWindow
  355.  
  356.  
  357.         Case 16
  358.  
  359.           b$ = PL()\Command
  360.  
  361.           file$ = GetFilePart(b$)
  362.           path$ = GetPathPart(b$)
  363.  
  364.           ResetTagList (#ASLFR_InitialTopEdge , WindowY()+WindowBorderTop())
  365.                 AddTag (#ASLFR_InitialLeftEdge, WindowX())
  366.                 AddTag (#ASLFR_InitialHeight  , ScreenHeight()/2)
  367.                 AddTag (#ASLFR_InitialWidth   , 200)
  368.                 AddTag (#ASLFR_InitialFile    , file$)
  369.                 AddTag (#ASLFR_InitialDrawer  , path$)
  370.  
  371.           STOP
  372.  
  373.           FileRequester(*TagList)
  374.  
  375.           If a$ <> ""
  376.             SetStringText(2, a$)
  377.             RefreshGadget(2)
  378.             Gosub String2
  379.           EndIf
  380.  
  381.  
  382.         Case 17 ; 'Launch IT !'
  383.           Gosub SetPref
  384.           PL()\Changed = 0
  385.  
  386.           b$ = GetPathPart(PL()\Command)
  387.  
  388.           RunProgram(b$, Chr(34)+PL()\Command+Chr(34), 1, 8192)
  389.  
  390.         Case 21 ; 'AGA - CGFX'
  391.           PL()\AGA = Code
  392.           PL()\Changed = 1
  393.  
  394.  
  395.       EndSelect
  396.     EndIf
  397.  
  398.   Until IDCMP = #IDCMP_CLOSEWINDOW
  399.  
  400. EndIf
  401.  
  402. End
  403.  
  404.  
  405. RefreshWindow:
  406.  
  407.   Gosub DisableDel
  408.  
  409.   Gosub DisableWarp3D
  410.  
  411.   Gosub RefreshScreenMode
  412.  
  413.   SetStringText(1, PL()\Item)
  414.   SetStringText(2, PL()\Command)
  415.  
  416.   If PL()\Command<>""
  417.     DisableGadget(17, 0)
  418.   Else
  419.     DisableGadget(17, 1)
  420.   Endif
  421.  
  422.   GadgetAttrs (7, #GTCY_Active, PL()\Processors)
  423.   GadgetAttrs (8, #GTCY_Active, PL()\Rendering)
  424.   GadgetAttrs (21,#GTCY_Active, PL()\AGA)
  425.  
  426.   GadgetAttrs (13,#GTCB_Checked, PL()\Warp3D)
  427.  
  428.   RefreshGadget(1)
  429.   RefreshGadget(2)
  430.   RefreshGadget(7)
  431.   RefreshGadget(8)
  432.  
  433. Return
  434.  
  435.  
  436. SavePrefs:
  437.   If CreateFile(0,"PROGDIR:WildManager.pref")
  438.  
  439.     WriteString("WildManagerPref1")
  440.     WriteWord(NbProg)
  441.  
  442.     ResetList(PL())
  443.  
  444.     For k=0 To NbProg-1
  445.       If NextElement(PL())
  446.         WriteString(PL()\Item)
  447.         WriteString(PL()\Command)
  448.  
  449.         WriteByte(PL()\Processors)
  450.         WriteByte(PL()\Rendering)
  451.         WriteByte(PL()\Warp3D)
  452.  
  453.         WriteWord(PL()\Width)
  454.         WriteWord(PL()\Height)
  455.         WriteLong(PL()\ScreenID)
  456.         WriteByte(PL()\AGA)
  457.       EndIf
  458.  
  459.       WriteString("WAM_End_WAM")
  460.     Next
  461.  
  462.     CloseFile(0)
  463.   EndIf
  464.  
  465.   ResetList(PL())
  466.  
  467.   For k=0 To NbProg-1
  468.     If NextElement(PL())
  469.       If PL()\Changed
  470.         Gosub SetPref
  471.       EndIf
  472.     EndIf
  473.   Next
  474.  
  475. Return
  476.  
  477.  
  478. DisableDel:
  479.  
  480.   If CountList(PL()) = 1
  481.     DisableGadget(15, 1)
  482.   Else
  483.     DisableGadget(15, 0)
  484.   EndIf
  485.  
  486. Return
  487.  
  488.  
  489. DisableWarp3D:
  490.  
  491.   If PL()\Rendering<>3
  492.     DisableGadget(13, 1)
  493.   Else
  494.     DisableGadget(13, 0)
  495.   EndIf
  496.  
  497. Return
  498.                                                                                                                               
  499.  
  500.  
  501. String1:
  502.   PL()\Item = GetStringText(1)
  503.   GadgetAttrs(9, #GTLV_Labels, *RealList)
  504.   RefreshGadget(9)
  505. Return
  506.  
  507.  
  508. String2:
  509.   PL()\Command = GetStringText(2)
  510.  
  511.   If PL()\Command<>""
  512.     DisableGadget(17, 0)
  513.   Else
  514.     DisableGadget(17, 1)
  515.   EndIf
  516.  
  517.   RefreshGadget(17)
  518.  
  519.   PL()\Changed = 1
  520.  
  521. Return
  522.  
  523.  
  524. SetPref:
  525.  
  526.   If PL()\Processors = 0
  527.  
  528.     Param$ = "TD Monkey"
  529.  
  530.     If PL()\Rendering = 0 ; Special case for WireFrame
  531.       Param$ = Param$ + " DI TryZkren"
  532.     Else
  533.  
  534.       If PL()\AGA
  535.         Param$ = Param$ + " DI TryPeJam+"
  536.       Else
  537.         Param$ = Param$ + " DI Cyborg"
  538.       EndIf
  539.  
  540.     EndIf
  541.  
  542.  
  543.     Select PL()\Rendering
  544.  
  545.       Case 0 ; 'Wire'
  546.         Param$ = Param$ + " DW Wire BK no LI no"
  547.  
  548.       Case 1 ; 'Flat'
  549.         Param$ = Param$ + " DW Flat BK NiX+ LI Flash"
  550.  
  551.       Case 2 ; 'Gouraud'
  552.         Param$ = Param$ + " DW Fluff BK ShiX LI Torch"
  553.  
  554.       Case 3 ; 'Textured'
  555.         Param$ = Param$ + " DW Candy+ BK TiX+ LI Torch"
  556.  
  557.     EndSelect
  558.  
  559.   Else
  560.  
  561.     Param$ = "TD Evolution"
  562.  
  563.     If PL()\Rendering = 0 ; Special case for WireFrame
  564.       Param$ = Param$ + " DI TryZkren"
  565.     Else
  566.  
  567.       If PL()\AGA
  568.         Param$ = Param$ + " DI TryNoe8"
  569.       Else
  570.         Param$ = Param$ + " DI Cyborg"
  571.       EndIf
  572.  
  573.     EndIf
  574.  
  575.  
  576.     Select PL()\Rendering
  577.  
  578.       Case 0 ; 'Wire'
  579.         Param$ = Param$ + " DW Wire BK no LI no"
  580.  
  581.       Case 1 ; 'Flat'
  582.         Param$ = Param$ + " DW Flat BK NiX+ LI Flash"
  583.  
  584.       Case 2 ; 'Gouraud'
  585.         Param$ = Param$ + " DW Fluff BK ShiX LI WTorch"
  586.  
  587.       Case 3 ; 'Textured'
  588.         Param$ = Param$ + " DW PowerDragon BK WTiX LI WTorch"
  589.  
  590.     EndSelect
  591.  
  592.   EndIf
  593.  
  594.  
  595.   If PL()\Warp3D
  596.     If PL()\Processors = 0
  597.       Param$ = "TD Monkey LI Torch"
  598.     Else
  599.       Param$ = "TD Evolution LI WTorch"
  600.     EndIf
  601.  
  602.     Param$ = Param$ + " DW DrScott DI CyborgHi BK no"
  603.   EndIf
  604.  
  605.  
  606.   If PL()\Width
  607.     Param$ = Param$+" WID "+Str(PL()\Width)+" HEI "+Str(PL()\Height);+" MODEID $";+Hex$(\ScreenID)
  608.   EndIf
  609.  
  610.   c$ = GetFilePart(PL()\Command)
  611.  
  612.   If c$ <> ""
  613.     RunProgram("WildPJ:Tools", "CloseWild", 0, 4096)
  614.     RunProgram("WildPJ:Tools", "SetWildAppPrefs "+c$+" save "+Param$, 0, 4096)
  615.   EndIf
  616.  
  617. Return
  618.  
  619.  
  620. RefreshScreenMode:
  621.  
  622.   If PL()\Width
  623.     Mode = Str(PL()\Width)+"x"+Str(PL()\Height)
  624.   Else
  625.     Mode = "Default"
  626.   EndIf
  627.  
  628.   GadgetAttrs(20, #GTTX_Text, Mode)
  629.   RefreshGadget(20)
  630.  
  631. Return
  632.  
  633.