home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 18 / amigaformatcd18.iso / mui / mui_developer / c / examples / virtual.c < prev    next >
C/C++ Source or Header  |  1997-03-10  |  14KB  |  423 lines

  1. #include "demo.h"
  2.  
  3.  
  4. static const char *Pages[] =
  5. {
  6.     "Big Text Field",
  7.     "Different Objects",
  8.     "Input Accepting Objects",
  9.     "Completly Crazy",
  10.     NULL,
  11. };
  12.  
  13.  
  14. static const char text1[] = "\
  15. \33iHello User !\33n\n\
  16. \n\
  17. This could be a very long text and you are looking\n\
  18. at it through a \33uvirtual group\33n. Please use the\n\
  19. scrollbars at the right and bottom of the group to\n\
  20. move the visible area either vertically or\n\
  21. horizontally. While holding down the small arrow\n\
  22. button between both scrollbars, the display will\n\
  23. follow your mouse moves.\n\
  24. \n\
  25. If you click somewhere into a \33uvirtual group\33n and\n\
  26. move the mouse across one of its borders, the group will\n\
  27. start scrolling. If you are lucky and own a middle mouse\n\
  28. button, you may also want to press it and try moving.\n\
  29. \n\
  30. When the surrounding window is big enough for the\n\
  31. complete virtual group to fit, the scrollers and\n\
  32. the move button get disabled.\n\
  33. \n\
  34. Since this \33uvirtual group\33n does only contain a\n\
  35. single text object, it's a rather simple example.\n\
  36. In fact, virtual groups are a lot more powerful,\n\
  37. they can contain any objects you like.\n\
  38. \n\
  39. Note to 7MHz/68000 users: Sorry if you find this\n\
  40. thingy a bit slow. Clipping in virtual groups can\n\
  41. get quite complicated. Please don't blame me,\n\
  42. blame your 'out of date' machine! :-)\n\
  43. \n\
  44. \33i\33cHave fun, Stefan.\33n\
  45. ";
  46.  
  47.  
  48. APTR MakePage1(VOID)
  49. {
  50.     return
  51.     (
  52.     ScrollgroupObject,
  53. MUIA_Scrollgroup_UseWinBorder, TRUE,
  54.         MUIA_Scrollgroup_Contents, VirtgroupObject,
  55.             VirtualFrame,
  56.             Child, TextObject,
  57.                 MUIA_Background, MUII_TextBack,
  58.                 MUIA_Text_Contents, text1,
  59.                 End,
  60.             End,
  61.         End
  62.     );
  63. }
  64.  
  65.  
  66. static const char text2[] = "\33c\
  67. As you can see, this virtual group contains a\n\
  68. lot of different objects. The (virtual) width\n\
  69. and height of the virtual group are automatically\n\
  70. calculated from the default width and height of\n\
  71. the virtual groups contents.\
  72. ";
  73.  
  74.  
  75. APTR MakePage2(VOID)
  76. {
  77.     #define img(nr)  ImageObject, MUIA_Image_Spec, nr, End
  78.  
  79.     APTR obj = ScrollgroupObject,
  80.         MUIA_UserData, 42,
  81.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame,
  82.             MUIA_UserData, 42,
  83.             Child, TextObject,
  84.                 TextFrame,
  85.                 MUIA_Background, MUII_TextBack,
  86.                 MUIA_Text_Contents, text2,
  87.                 End,
  88.             Child, HGroup,
  89.                 Child, ColGroup(2), GroupFrameT("Standard Images"),
  90.                     Child, Label("ArrowUp:"    ), Child, img(MUII_ArrowUp    ),
  91.                     Child, Label("ArrowDown:"  ), Child, img(MUII_ArrowDown  ),
  92.                     Child, Label("ArrowLeft:"  ), Child, img(MUII_ArrowLeft  ),
  93.                     Child, Label("ArrowRight:" ), Child, img(MUII_ArrowRight ),
  94.                     Child, Label("RadioButton:"), Child, img(MUII_RadioButton),
  95.                     Child, Label("File:"       ), Child, img(MUII_PopFile    ),
  96.                     Child, Label("HardDisk:"   ), Child, img(MUII_HardDisk   ),
  97.                     Child, Label("Disk:"       ), Child, img(MUII_Disk       ),
  98.                     Child, Label("Chip:"       ), Child, img(MUII_Chip       ),
  99.                     Child, Label("Drawer:"     ), Child, img(MUII_Drawer     ),
  100.                     End,
  101.                 Child, VGroup, GroupFrameT("Some Backgrounds"),
  102.                     Child, HGroup,
  103.                         Child, RectangleObject, TextFrame, MUIA_Background, MUII_BACKGROUND , MUIA_FixWidth, 30, End,
  104.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILL       , MUIA_FixWidth, 30, End,
  105.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOW     , MUIA_FixWidth, 30, End,
  106.                         End,
  107.                     Child, HGroup,
  108.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWBACK , MUIA_FixWidth, 30, End,
  109.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWFILL , MUIA_FixWidth, 30, End,
  110.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWSHINE, MUIA_FixWidth, 30, End,
  111.                         End,
  112.                     Child, HGroup,
  113.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLBACK   , MUIA_FixWidth, 30, End,
  114.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHINEBACK  , MUIA_FixWidth, 30, End,
  115.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLSHINE  , MUIA_FixWidth, 30, End,
  116.                         End,
  117.                     End,
  118.                 End,
  119.             Child, ColGroup(2), GroupFrame,
  120.                 Child, Label1("Gauge:"), Child, GaugeObject, GaugeFrame, MUIA_Gauge_Current, 66, MUIA_Gauge_Horiz, TRUE, End,
  121.                 Child, VSpace(0)       , Child, ScaleObject, End,
  122.                 End,
  123.             End,
  124.         End;
  125.  
  126.     return(obj);
  127. }
  128.  
  129.  
  130. static const char text3[] = "\
  131. \33cThe above pages only showed 'read only' groups,\n\
  132. no user actions within them were possible. Of course,\n\
  133. handling user actions in a virtual group is not a\n\
  134. problem for MUI. As I promised on the first page,\n\
  135. you can use virtual groups with whatever objects\n\
  136. you want. Here's a small example...\n\
  137. \n\
  138. Note: Due to some limitations of the operating system,\n\
  139. it is not possible to clip gadgets depending on\n\
  140. intuition.library correctly. This affects the appearence\n\
  141. of string and proportional objects in virtual groups.\n\
  142. You will only be able to use these gadgets when they\n\
  143. are completely visible.\n\
  144. \n\
  145. PS: Also try TAB cycling here!\
  146. ";
  147.  
  148. static const char *CYA_Computer[] = { "Amiga 500","Amiga 600","Amiga 1000 :)","Amiga 1200","Amiga 2000","Amiga 3000","Amiga 4000", "Amiga 4000T", "Atari ST :(", NULL };
  149. static const char *CYA_Printer[]  = { "HP Deskjet","NEC P6","Okimate 20",NULL };
  150. static const char *CYA_Display[]  = { "A1081","NEC 3D","A2024","Eizo T660i",NULL };
  151.  
  152. static APTR CY_Computer,CY_Printer,CY_Display;
  153. static APTR MT_Computer,MT_Printer,MT_Display;
  154. static APTR LV_Computer;
  155. static APTR BT_Button[12];
  156.  
  157. APTR MakePage3(VOID)
  158. {
  159.     APTR obj;
  160.  
  161.     obj = ScrollgroupObject,
  162.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, 
  163.             Child, TextObject,
  164.                 TextFrame,
  165.                 MUIA_Background, MUII_TextBack,
  166.                 MUIA_Text_Contents, text3,
  167.                 End,
  168.             Child, VGroup,
  169.                 Child, HGroup,
  170.                     Child, MT_Computer = Radio("Computer:",CYA_Computer),
  171.                     Child, VGroup,
  172.                         Child, MT_Printer = Radio("Printer:",CYA_Printer),
  173.                         Child, VSpace(0),
  174.                         Child, MT_Display = Radio("Display:",CYA_Display),
  175.                         End,
  176.                     Child, VGroup,
  177.                         Child, ColGroup(2), GroupFrameT("Cycle Gadgets"),
  178.                             Child, KeyLabel1("Computer:",'c'), Child, CY_Computer = KeyCycle(CYA_Computer,'c'),
  179.                             Child, KeyLabel1("Printer:" ,'p'), Child, CY_Printer  = KeyCycle(CYA_Printer ,'p'),
  180.                             Child, KeyLabel1("Display:" ,'d'), Child, CY_Display  = KeyCycle(CYA_Display ,'d'),
  181.                             End,
  182.                         Child, LV_Computer =    ListviewObject,
  183.                             MUIA_Listview_ScrollerPos, MUIV_Listview_ScrollerPos_Left,
  184.                             MUIA_Listview_Input, TRUE,
  185.                             MUIA_Listview_List, ListObject, InputListFrame, End,
  186.                             End,
  187.                         End,
  188.                     End,
  189.                 Child, ColGroup(4), GroupFrameT("Button Field"),
  190.                     Child, BT_Button[ 0] = SimpleButton("Button"),
  191.                     Child, BT_Button[ 1] = SimpleButton("Button"),
  192.                     Child, BT_Button[ 2] = SimpleButton("Button"),
  193.                     Child, BT_Button[ 3] = SimpleButton("Button"),
  194.                     Child, BT_Button[ 4] = SimpleButton("Button"),
  195.                     Child, BT_Button[ 5] = SimpleButton("Button"),
  196.                     Child, BT_Button[ 6] = SimpleButton("Button"),
  197.                     Child, BT_Button[ 7] = SimpleButton("Button"),
  198.                     Child, BT_Button[ 8] = SimpleButton("Button"),
  199.                     Child, BT_Button[ 9] = SimpleButton("Button"),
  200.                     Child, BT_Button[10] = SimpleButton("Button"),
  201.                     Child, BT_Button[11] = SimpleButton("Button"),
  202.                     End,
  203.                 End,
  204.             End,
  205.         End;
  206.  
  207.     if (LV_Computer)
  208.         DoMethod(LV_Computer,MUIM_List_Insert,CYA_Computer,-1,MUIV_List_Insert_Bottom);
  209.  
  210.     return(obj);
  211. }
  212.  
  213.  
  214. #define mytxt(txt)\
  215.     TextObject,\
  216.         MUIA_Text_Contents, "\33c"txt,\
  217.         MUIA_Text_SetMax, TRUE,\
  218.         End
  219.  
  220. #define ibt(i)\
  221.     ImageObject,\
  222.         ImageButtonFrame,\
  223.         MUIA_Background, MUII_ButtonBack,\
  224.         MUIA_InputMode , MUIV_InputMode_RelVerify,\
  225.         MUIA_Image_Spec, i,\
  226.         End
  227.  
  228. static char *x4Sex[]     = { "male","female",NULL };
  229. static char *x4Pages[]   = { "Race","Class","Armors","Weapons","Levels",NULL };
  230. static char *x4Races[]   = { "Human","Elf","Dwarf","Hobbit","Gnome",NULL };
  231. static char *x4Classes[] = { "Warrior","Rogue","Bard","Monk","Magician","Archmage",NULL };
  232. static char *x4Weapons[] = { "Staff","Dagger","Sword","Axe","Grenade",NULL };
  233.  
  234. APTR MakePage4(VOID)
  235. {
  236.     APTR bt1,bt2,bt3,bt4,gr,obj,pcy,pgr;
  237.  
  238.     obj = ScrollgroupObject,
  239.         MUIA_Scrollgroup_Contents, ColGroupV(3), VirtualFrame, 
  240.             MUIA_Group_Spacing, 10,
  241.             Child, VGroup, GroupFrame,
  242.                 Child, HGroup,
  243.                     Child, HSpace(0),
  244.                     Child, bt1 = ibt(MUII_ArrowUp),
  245.                     Child, HSpace(0),
  246.                     End,
  247.                 Child, HGroup,
  248.                     Child, bt2 = ibt(MUII_ArrowLeft),
  249.                     Child, bt3 = ibt(MUII_ArrowRight),
  250.                     End,
  251.                 Child, HGroup,
  252.                     Child, HSpace(0),
  253.                     Child, bt4 = ibt(MUII_ArrowDown),
  254.                     Child, HSpace(0),
  255.                     End,
  256.                 End,
  257.             Child, mytxt("Ever wanted to see\na virtual group in\na virtual group?"),
  258.             Child, HVSpace,
  259.             Child, mytxt("Here it is!"),
  260.  
  261.             Child, ScrollgroupObject,
  262.                 MUIA_Scrollgroup_Contents, gr = VGroupV, VirtualFrame,
  263.                     Child, ColGroup(6), MUIA_Group_SameSize, TRUE,
  264.                         Child, SimpleButton("One"),
  265.                         Child, SimpleButton("Two"),
  266.                         Child, SimpleButton("Three"),
  267.                         Child, SimpleButton("Four"),
  268.                         Child, SimpleButton("Five"),
  269.                         Child, SimpleButton("Six"),
  270.                         Child, SimpleButton("Eighteen"),
  271.                         Child, mytxt("The"),
  272.                         Child, mytxt("red"),
  273.                         Child, mytxt("brown"),
  274.                         Child, mytxt("fox"),
  275.                         Child, SimpleButton("Seven"),
  276.                         Child, SimpleButton("Seventeen"),
  277.                         Child, mytxt("dog."),
  278.                         Child, SimpleButton("Nineteen"),
  279.                         Child, SimpleButton("Twenty"),
  280.                         Child, mytxt("jumps"),
  281.                         Child, SimpleButton("Eight"),
  282.                         Child, SimpleButton("Sixteen"),
  283.                         Child, mytxt("lazy"),
  284.                         Child, mytxt("the"),
  285.                         Child, mytxt("over"),
  286.                         Child, mytxt("quickly"),
  287.                         Child, SimpleButton("Nine"),
  288.                         Child, SimpleButton("Fifteen"),
  289.                         Child, SimpleButton("Fourteen"),
  290.                         Child, SimpleButton("Thirteen"),
  291.                         Child, SimpleButton("Twelve"),
  292.                         Child, SimpleButton("Eleven"),
  293.                         Child, SimpleButton("Ten"),
  294.                         End,
  295.                     End,
  296.                 End,
  297.  
  298.             Child, mytxt("Do you like it? I hope..."),
  299.             Child, HVSpace,
  300.             Child, mytxt("I admit, it's a\n bit crazy... :-)\nBut it demonstrates\nthe power of\n\33bobject oriented\33n\nGUI design."),
  301.  
  302.             Child, ScrollgroupObject,
  303.                 MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, InnerSpacing(4,4), 
  304.                     Child, VGroup,
  305.                         Child, pcy = Cycle(x4Pages),
  306.                         Child, pgr = PageGroup,
  307.                             Child, HCenter(Radio(NULL,x4Races)),
  308.                             Child, HCenter(Radio(NULL,x4Classes)),
  309.                             Child, HGroup,
  310.                                 Child, HSpace(0),
  311.                                 Child, ColGroup(2),
  312.                                     Child, Label1("Cloak:" ), Child, CheckMark(TRUE),
  313.                                     Child, Label1("Shield:"), Child, CheckMark(TRUE),
  314.                                     Child, Label1("Gloves:"), Child, CheckMark(TRUE),
  315.                                     Child, Label1("Helm:"  ), Child, CheckMark(TRUE),
  316.                                     End,
  317.                                 Child, HSpace(0),
  318.                                 End,
  319.                             Child, HCenter(Radio(NULL,x4Weapons)),
  320.                             Child, ColGroup(2),
  321.                                 Child, Label("Experience:"  ), Child, Slider(0,100, 3),
  322.                                 Child, Label("Strength:"    ), Child, Slider(0,100,42),
  323.                                 Child, Label("Dexterity:"   ), Child, Slider(0,100,24),
  324.                                 Child, Label("Condition:"   ), Child, Slider(0,100,39),
  325.                                 Child, Label("Intelligence:"), Child, Slider(0,100,74),
  326.                                 End,
  327.                             End,
  328.                         End,
  329.                     End,
  330.                 End,
  331.  
  332.  
  333.             End,
  334.         End;
  335.  
  336.     if (obj)
  337.     {
  338.         DoMethod(bt1,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,0);
  339.         DoMethod(bt2,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,0);
  340.         DoMethod(bt3,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,9999);
  341.         DoMethod(bt4,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,9999);
  342.  
  343.         DoMethod(pcy,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  344.             pgr,3,MUIM_Set,MUIA_Group_ActivePage,MUIV_TriggerValue);
  345.     }
  346.  
  347.     return(obj);
  348. }
  349.  
  350.  
  351. int main(int argc,char *argv[])
  352. {
  353.     static APTR app,window;
  354.  
  355.     init();
  356.  
  357.     app = ApplicationObject,
  358.         MUIA_Application_Title      , "VirtualDemo",
  359.         MUIA_Application_Version    , "$VER: VirtualDemo 19.5 (12.02.97)",
  360.         MUIA_Application_Copyright  , "©1993, Stefan Stuntz",
  361.         MUIA_Application_Author     , "Stefan Stuntz",
  362.         MUIA_Application_Description, "Show virtual groups.",
  363.         MUIA_Application_Base       , "VIRTUALDEMO",
  364.  
  365.         SubWindow, window = WindowObject,
  366.             MUIA_Window_Title, "Virtual Groups",
  367.             MUIA_Window_ID   , MAKE_ID('V','I','R','T'),
  368.             MUIA_Window_UseRightBorderScroller, TRUE,
  369.             MUIA_Window_UseBottomBorderScroller, TRUE,
  370.             WindowContents, ColGroup(2), GroupSpacing(8),
  371.                 Child, MakePage1(),
  372.                 Child, MakePage2(),
  373.                 Child, MakePage3(),
  374.                 Child, MakePage4(),
  375.                 End,
  376.             End,
  377.         End;
  378.  
  379.  
  380.     if (!app)
  381.         fail(app,"Failed to create Application.");
  382.  
  383.  
  384.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  385.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  386.  
  387.     DoMethod(window,MUIM_Window_SetCycleChain,
  388.         MT_Computer,MT_Printer,MT_Display,
  389.         CY_Computer,CY_Printer,CY_Display,
  390.         LV_Computer,
  391.         BT_Button[ 0],BT_Button[ 1],BT_Button[ 2],BT_Button[ 3],
  392.         BT_Button[ 4],BT_Button[ 5],BT_Button[ 6],BT_Button[ 7],
  393.         BT_Button[ 8],BT_Button[ 9],BT_Button[10],BT_Button[11],
  394.         NULL);
  395.  
  396. /*
  397. ** This is the ideal input loop for an object oriented MUI application.
  398. ** Everything is encapsulated in classes, no return ids need to be used,
  399. ** we just check if the program shall terminate.
  400. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  401. ** from Wait() (or 0). This makes the input loop significantly faster.
  402. */
  403.  
  404.     set(window,MUIA_Window_Open,TRUE);
  405.  
  406.     {
  407.         ULONG sigs = 0;
  408.  
  409.         while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  410.         {
  411.             if (sigs)
  412.             {
  413.                 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  414.                 if (sigs & SIGBREAKF_CTRL_C) break;
  415.             }
  416.         }
  417.     }
  418.  
  419.     set(window,MUIA_Window_Open,FALSE);
  420.  
  421.     fail(app,NULL);
  422. }
  423.