home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / ZINC.ZIP / D_PIANO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-23  |  5.7 KB  |  190 lines

  1. //    Program name..    Zinc Interface Library
  2. //    Filename......    D_APPS.CPP
  3. //    
  4. //    COPYRIGHT (C) 1990.  All Rights Reserved.
  5. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  6.  
  7. #include <dos.h>
  8. #include <graphics.h>
  9. #include <ui_win.hpp>
  10. #include "d_demo.hpp"
  11. #include "d_help.hlh"
  12.  
  13. const int IVORY = 0;
  14. const int EBONY = 1;
  15.  
  16. // Color palette definitions for piano keys.
  17. static UI_PALETTE ebonyPalette = { ' ', attrib(BLACK, BLACK), attrib(MONO_BLACK, MONO_BLACK),
  18.         SOLID_FILL, attrib(BLACK, BLACK), attrib(BW_BLACK, BW_BLACK),
  19.         attrib(GS_BLACK, GS_BLACK) };
  20.  
  21. static UI_PALETTE ivoryPalette = { ' ', attrib(WHITE, WHITE), attrib(MONO_NORMAL, MONO_NORMAL),
  22.         SOLID_FILL, attrib(WHITE, WHITE), attrib(BW_WHITE, BW_WHITE),
  23.         attrib(GS_WHITE, GS_WHITE) };
  24.  
  25. class PIANO_KEY : public UIW_BUTTON
  26. {
  27. public:
  28.     PIANO_KEY(int left, int a_ebony, char a_key, char a_note, int a_freq);
  29.  
  30.     virtual int Event(const UI_EVENT &event);
  31.  
  32. private:
  33.     int ebony;
  34.     char note;
  35.     int freq;
  36.     int oldScreenID;
  37. };
  38.  
  39. PIANO_KEY::PIANO_KEY(int left, int a_ebony, char a_key, char a_note, int a_freq) :
  40.     UIW_BUTTON(left, 2, 3 - a_ebony, "", BTF_NO_TOGGLE, WOF_JUSTIFY_CENTER, 0)
  41. {
  42.     ebony = a_ebony;
  43.     hotKey = a_key;
  44.     note = a_note;
  45.     freq = a_freq;
  46.  
  47.     // Lengthen buttons to look like piano keys.
  48.     true.bottom = relative.bottom = 6 - 2 * ebony;
  49.     woAdvancedFlags |= WOAF_HOT_REGION;
  50. }
  51.  
  52. int PIANO_KEY::Event(const UI_EVENT &event)
  53. {
  54.     // Switch on the event type.
  55.     UI_REGION region = true;
  56.     UI_PALETTE *palette;
  57.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_BUTTON);
  58.     switch (ccode)
  59.     {
  60.     case S_CREATE:
  61.         oldScreenID = screenID;
  62.     case S_MOVE:
  63.     case S_SIZE:
  64.         ccode = UI_WINDOW_OBJECT::Event(event);
  65.          nosound();
  66.         break;
  67.  
  68.     case S_NON_CURRENT:
  69.         btStatus &= ~BTS_DEPRESSED;
  70.         palette = (ebony) ? &ebonyPalette : &ivoryPalette;
  71.         UI_WINDOW_OBJECT::Text(string, depth, ccode, palette);
  72.          nosound();
  73.         break;
  74.  
  75.     case S_DISPLAY_ACTIVE:
  76.     case S_CURRENT:
  77.     case S_DISPLAY_INACTIVE:
  78.         if (ebony && ccode != S_DISPLAY_INACTIVE)
  79.         {
  80.             screenID = -2;
  81.             UI_WINDOW_OBJECT::display->RegionDefine(screenID, region);
  82.         }
  83.         else
  84.             screenID = oldScreenID;
  85.         palette = (ebony) ? &ebonyPalette : &ivoryPalette;
  86.         if (ccode == S_CURRENT || UI_WINDOW_OBJECT::NeedsUpdate(event, ccode))
  87.             UI_WINDOW_OBJECT::Text(string, depth, ccode, palette);
  88.         break;
  89.  
  90.     case L_BEGIN_SELECT:
  91.     case L_CONTINUE_SELECT:
  92.     case L_END_SELECT:
  93.         woStatus |= WOS_CURRENT;
  94.         if (!FlagSet(btStatus, BTS_DEPRESSED) && 
  95.             UI_WINDOW_OBJECT::Overlap(event.position))
  96.         {
  97.             UI_WINDOW_OBJECT::Shadow(region, -depth);
  98.             btStatus |= BTS_DEPRESSED;
  99.             sound(freq);
  100.         }
  101.         else if (ccode == L_END_SELECT || (FlagSet(btStatus, BTS_DEPRESSED) &&
  102.             !UI_WINDOW_OBJECT::Overlap(event.position)))
  103.         {
  104.             UI_WINDOW_OBJECT::Shadow(region, depth);
  105.             btStatus &= ~BTS_DEPRESSED;
  106.             nosound();
  107.         }
  108.         break;
  109.  
  110.     case L_SELECT:
  111.         UI_WINDOW_OBJECT::Shadow(region, -depth);
  112.         sound(freq);
  113.         delay(100);
  114.         region = true;
  115.         UI_WINDOW_OBJECT::Shadow(region, depth);
  116.         nosound();
  117.         break;
  118.  
  119.     default:
  120.         ccode = UI_WINDOW_OBJECT::Event(event);
  121.         break;
  122.     }
  123.     return (ccode);
  124. }
  125.  
  126. #pragma argsused
  127. void Piano(void *item, UI_EVENT &event)
  128. {
  129.     extern void ExitButton(void *object, UI_EVENT &event);
  130.  
  131.     // Create a window in the screen center.
  132.     int centerX = _display->columns / _display->cellWidth / 2;
  133.     if (centerX < 25)
  134.         centerX = 25;
  135.     int centerY = _display->lines / _display->cellHeight / 2;
  136.     UIW_WINDOW *window = new UIW_WINDOW(centerX - 25, centerY - 6, 49, 13, WOF_NO_FLAGS, WOAF_MODAL, INFO_PIANO);
  137.  
  138.     // Allow normal keys to be hot keys for piano. (normally <Alt key>)
  139.     window->woAdvancedFlags |= WOAF_NORMAL_HOT_KEYS;
  140.  
  141.     // Add border, buttons, keys, etc. to window.
  142.     *window
  143.         + new UIW_BORDER
  144.         + new UIW_MINIMIZE_BUTTON
  145.         + &(*new UIW_SYSTEM_BUTTON
  146.             + new UIW_POP_UP_ITEM("~Move", MNIF_MOVE, BTF_NO_TOGGLE, WOF_NO_FLAGS, 0)
  147.             + new UIW_POP_UP_ITEM("Mi~nimize", MNIF_MINIMIZE, BTF_NO_TOGGLE, WOF_NO_FLAGS, 0)
  148.             + new UIW_POP_UP_ITEM
  149.             + new UIW_POP_UP_ITEM("~Close", MNIF_CLOSE, BTF_NO_TOGGLE, WOF_NO_FLAGS, 0)
  150.             + new HELP_PULL_DOWN_ITEM(" ~About the piano ", MNF_NO_FLAGS, INFO_PIANO))
  151.         + new UIW_TITLE("Beethoven (Modal Window)", WOF_JUSTIFY_CENTER)
  152.         + new UIW_PROMPT(2, 1, "  1  2     4  5  6     8  9     -  =  ", WOF_NO_FLAGS)
  153.         + new UIW_PROMPT(2, 7, "a  q  w  e  r  t  y  u  i  o  p  [  ]  ;  '", WOF_NO_FLAGS)
  154.         + new UIW_BUTTON(19, 9, 10, "Esc=Exit", BTF_NO_FLAGS, WOF_JUSTIFY_CENTER, ExitButton);
  155.     *window
  156.         + new PIANO_KEY(1, IVORY, 'A', 'C', 131)
  157.         + new PIANO_KEY(4, IVORY, 'Q', 'D', 147)
  158.         + new PIANO_KEY(7, IVORY, 'W', 'E', 165)
  159.         + new PIANO_KEY(10, IVORY, 'E', 'F', 175)
  160.         + new PIANO_KEY(13, IVORY, 'R', 'G', 196);
  161.     *window
  162.         + new PIANO_KEY(16, IVORY, 'T', 'A', 220)
  163.         + new PIANO_KEY(19, IVORY, 'Y', 'B', 247)
  164.         + new PIANO_KEY(22, IVORY, 'U', 'C', 262)
  165.         + new PIANO_KEY(25, IVORY, 'I', 'D', 294)
  166.         + new PIANO_KEY(28, IVORY, 'O', 'E', 329);
  167.     *window
  168.         + new PIANO_KEY(31, IVORY, 'P', 'F', 349)
  169.         + new PIANO_KEY(34, IVORY, '[', 'G', 392)
  170.         + new PIANO_KEY(37, IVORY, ']', 'A', 440)
  171.         + new PIANO_KEY(40, IVORY, ';', 'B', 494)
  172.         + new PIANO_KEY(43, IVORY, '\'', 'C', 523);
  173.     *window
  174.         + new PIANO_KEY(3, EBONY, '1', 'C', 139)
  175.         + new PIANO_KEY(6, EBONY, '2', 'D', 156)
  176.         + new PIANO_KEY(12, EBONY, '4', 'F', 185)
  177.         + new PIANO_KEY(15, EBONY, '5', 'G', 208)
  178.         + new PIANO_KEY(18, EBONY, '6', 'A', 233);
  179.     *window
  180.         + new PIANO_KEY(24, EBONY, '8', 'C', 277)
  181.         + new PIANO_KEY(27, EBONY, '9', 'D', 311)
  182.         + new PIANO_KEY(33, EBONY, '-', 'F', 370)
  183.         + new PIANO_KEY(36, EBONY, '=', 'G', 415)
  184.         + new PIANO_KEY(39, EBONY, BACKSPACE, 'A', 466);
  185.  
  186.     // Add the window to the window manager.
  187.     *_windowManager + window;
  188. }
  189.  
  190.