home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / cube3d / cube3D.exe / cube3D / src / help.c < prev    next >
C/C++ Source or Header  |  2000-12-26  |  6KB  |  234 lines

  1. /*
  2.  * @(#)help.c
  3.  *
  4.  * Copyright 1999-2000, Aaron Ardiri (mailto:aaron@ardiri.com)
  5.  * All rights reserved.
  6.  *
  7.  * The  source code  outlines a number of basic Palm Computing Programming
  8.  * principles and you  should be able to take the core structure and write 
  9.  * a large complex program. It is distributed WITHOUT ANY WARRANTY; use it
  10.  * "AS IS" and at your own risk.
  11.  *
  12.  * The code presented is Copyright 1999-2000 by Aaron Ardiri. It should be
  13.  * used for  educational purposes only.  You  shall not modify  the Cube3D 
  14.  * source code in any way and  re-distribute it as your  own,  however you
  15.  * are free to use  the code as  a guide for  developing  programs  on the 
  16.  * Palm Computing Platform.
  17.  */
  18.  
  19. #include "palm.h"
  20.  
  21. typedef struct 
  22. {
  23.   UInt32    keyMask;
  24.   WinHandle helpWindow;
  25. } HelpGlobals;
  26.  
  27. /**
  28.  * Initialize the instructions screen.
  29.  * 
  30.  * @return the height in pixels of the instructions data area.
  31.  */
  32. UInt16
  33. InitInstructions()
  34. {
  35.   const RectangleType     rect  = {{0,0},{142,234}};
  36.   const CustomPatternType erase = {0,0,0,0,0,0,0,0};
  37.   HelpGlobals *globals;
  38.   UInt16      err;
  39.  
  40.   // create the globals object, and register it
  41.   globals = (HelpGlobals *)MemPtrNew(sizeof(HelpGlobals));
  42.   MemSet(globals, sizeof(HelpGlobals), 0);
  43.   FtrSet(appCreator, ftrHelpGlobals, (UInt32)globals);
  44.  
  45.   // setup the valid keys available at this point in time
  46.   globals->keyMask = KeySetMask(~(keyBitsAll ^ 
  47.                                  (keyBitPower    | keyBitCradle   |
  48.                                   keyBitPageUp   | keyBitPageDown |
  49.                                   keyBitContrast)));
  50.  
  51.   // initialize windows
  52.   globals->helpWindow = 
  53.     WinCreateOffscreenWindow(rect.extent.x,rect.extent.y,screenFormat,&err);
  54.   err |= (globals->helpWindow == NULL);
  55.  
  56.   // draw the help
  57.   if (err == errNone) {
  58.   
  59.     FontID    font;
  60.     WinHandle currWindow;
  61.  
  62.     currWindow = WinGetDrawWindow();
  63.     font       = FntGetFont();
  64.  
  65.     // draw to help window
  66.     WinSetDrawWindow(globals->helpWindow);
  67.     WinSetPattern(&erase);
  68.     WinFillRectangle(&rect,0);
  69.  
  70.     {
  71.       Char  *str, *ptrStr;
  72.       Coord x, y;
  73.  
  74.       // initialize
  75.       y   = 2;
  76.       str = (Char *)MemPtrNew(256 * sizeof(Char));
  77.  
  78.       // draw title
  79.       StrCopy(str, "WIREFRAME CUBE");
  80.       x = (rect.extent.x - FntCharsWidth(str, StrLen(str))) >> 1;
  81.  
  82.       WinSetUnderlineMode(grayUnderline);
  83.       WinDrawChars(str, StrLen(str), x, y); y += FntLineHeight();
  84.       WinSetUnderlineMode(noUnderline);
  85.  
  86.       // add space (little)
  87.       y += FntLineHeight() >> 1;
  88.  
  89.       // general text 
  90.       x = 4;
  91.       StrCopy(str,
  92. "Cube3D is a simple wireframe cube demonstration that uses perspective \
  93. geometry for the Palm Computing Platform.");
  94.       ptrStr = str;
  95.       while (StrLen(ptrStr) != 0) {
  96.         UInt8 count = FntWordWrap(ptrStr, rect.extent.x-x);
  97.  
  98.         x = (rect.extent.x - FntCharsWidth(ptrStr, count)) >> 1;
  99.         WinDrawChars(ptrStr, count, x, y); y += FntLineHeight(); x = 4;
  100.  
  101.         ptrStr += count;
  102.       }
  103.  
  104.       // add space (little)
  105.       y += FntLineHeight() >> 1;
  106.   
  107.       // show the screen teaser
  108.       x = 8;
  109.       {
  110.         MemHandle bitmapHandle = DmGet1Resource('Tbmp', bitmapHelpAnimation);
  111.         WinDrawBitmap((BitmapType *)MemHandleLock(bitmapHandle), x, y);
  112.         MemHandleUnlock(bitmapHandle);
  113.         DmReleaseResource(bitmapHandle);
  114.       }
  115.  
  116.       // add space (little)
  117.       y += 48 + (FntLineHeight() >> 1);
  118.  
  119.       // general text
  120.       x = 4;
  121.       StrCopy(str,
  122. "The source code is available for educational purposes only and \
  123. shall not be redistributed or modified without the consent of \
  124. the original author.");
  125.       ptrStr = str;
  126.       while (StrLen(ptrStr) != 0) {
  127.         UInt8 count = FntWordWrap(ptrStr, rect.extent.x-x);
  128.  
  129.         x = (rect.extent.x - FntCharsWidth(ptrStr, count)) >> 1;
  130.         WinDrawChars(ptrStr, count, x, y); y += FntLineHeight(); x = 4;
  131.  
  132.         ptrStr += count;
  133.       }
  134.  
  135.       // add space (little)
  136.       y += FntLineHeight() >> 1;
  137.  
  138.       x = 4;
  139.       StrCopy(str,
  140. "Interested in developing for the Palm Computing Platform?");
  141.       ptrStr = str;
  142.       while (StrLen(ptrStr) != 0) {
  143.         UInt8 count = FntWordWrap(ptrStr, rect.extent.x-x);
  144.  
  145.         x = (rect.extent.x - FntCharsWidth(ptrStr, count)) >> 1;
  146.         WinDrawChars(ptrStr, count, x, y); y += FntLineHeight(); x = 4;
  147.  
  148.         ptrStr += count;
  149.       }
  150.  
  151.       // add space (little)
  152.       y += FntLineHeight() >> 1;
  153.  
  154.       StrCopy(str, "http://www.palmos.com/");
  155.       FntSetFont(boldFont);
  156.       x = (rect.extent.x - FntCharsWidth(str, StrLen(str))) >> 1;
  157.       WinDrawChars(str, StrLen(str), x, y); y += FntLineHeight();
  158.  
  159.       // add space (little)
  160.       y += FntLineHeight() >> 1;
  161.  
  162.       StrCopy(str, "Happy Hacking!");
  163.       FntSetFont(font);
  164.       x = (rect.extent.x - FntCharsWidth(str, StrLen(str))) >> 1;
  165.       WinDrawChars(str, StrLen(str), x, y); y += FntLineHeight();
  166.  
  167.       // clean up
  168.       MemPtrFree(str);
  169.     }
  170.  
  171.     FntSetFont(font);
  172.     WinSetDrawWindow(currWindow);
  173.   }
  174.   else
  175.  
  176.   // something went wrong
  177.   {
  178.     ApplicationDisplayDialog(xmemForm);
  179.  
  180.     // close the form
  181.     {
  182.       EventType event;
  183.  
  184.       MemSet(&event, sizeof(EventType), 0);
  185.       event.eType = frmCloseEvent;
  186.       event.data.frmClose.formID = FrmGetActiveFormID();
  187.       EvtAddEventToQueue(&event);
  188.     }
  189.   }
  190.  
  191.   return rect.extent.y;
  192. }
  193.  
  194. /**
  195.  * Draw the instructions on the screen.
  196.  * 
  197.  * @param offset the offset height of the window to start copying from.
  198.  */
  199. void 
  200. DrawInstructions(UInt16 offset)
  201. {
  202.   const RectangleType helpArea = {{0,offset},{142,116}};
  203.   HelpGlobals *globals;
  204.  
  205.   // get globals reference
  206.   FtrGet(appCreator, ftrHelpGlobals, (UInt32 *)&globals);
  207.  
  208.   // blit the required area
  209.   WinCopyRectangle(globals->helpWindow, 
  210.                    WinGetDrawWindow(), &helpArea, 3, 16, winPaint);
  211. }
  212.  
  213. /**
  214.  * Terminate the instructions screen.
  215.  */
  216. void
  217. QuitInstructions()
  218. {
  219.   HelpGlobals *globals;
  220.  
  221.   // get globals reference
  222.   FtrGet(appCreator, ftrHelpGlobals, (UInt32 *)&globals);
  223.  
  224.   // return the state of the key processing
  225.   KeySetMask(globals->keyMask);
  226.  
  227.   // clean up memory
  228.   WinDeleteWindow(globals->helpWindow, false);
  229.   MemPtrFree(globals);
  230.  
  231.   // unregister global data
  232.   FtrUnregister(appCreator, ftrHelpGlobals);
  233. }
  234.