home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / examples / color.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  7.8 KB  |  328 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.02
  4. // Copyright (C) 1990, 1991
  5. // Software Dimensions
  6. //
  7. // Dialog Development System
  8. //
  9.  
  10. #include "fli.h"
  11. #include "elements.h"
  12. #include "colors.h"
  13. #include "fliwin.h"
  14. #include "dds.h"
  15.  
  16. //-------------------------------------------------------------------------
  17. //
  18. // Defines the current color for an object
  19. //
  20. //-------------------------------------------------------------------------
  21.  
  22. int *CurrentColor::TheColor=0;
  23.  
  24. //-------------------------------------------------------------------------
  25. //
  26. // Foreground color class element
  27. //
  28. //-------------------------------------------------------------------------
  29.  
  30. ForeGround::ForeGround(int X,int Y,int TestX,int TestY)
  31. {
  32.     DialogElement::X=X;
  33.     DialogElement::Y=Y;
  34.     ForeGround::TestX=TestX;
  35.     ForeGround::TestY=TestY;
  36.     Width=12;
  37.     Height=4;
  38. }
  39.  
  40. void ForeGround::Show()
  41. {
  42.     MouseHide();
  43.     for (int i=0;i<4;i++)
  44.         for (int j=0;j<4;j++)
  45.             (*Blaze)(X+(j*3),Y+i) << (int)((i*4)+j) << "\xdb\xdb\xdb";
  46.     (*Blaze)(TestX,TestY) << *TheColor << "  Current!  ";
  47.     int Color=*TheColor&15; // Masks out other colors
  48.     int Y=(Color)?(Color/4):0;
  49.     int X=(Color-(Y*4))*3;
  50.     (*Blaze)(DialogElement::X+X,DialogElement::Y+Y) << Color << "\xfe\xfe\xfe";
  51.     (*Blaze) << Colors.DiaInterior;
  52.     Blaze->CharacterRepeater(DialogElement::X,DialogElement::Y-1,12,Colors.DiaInterior,' ');
  53.     Blaze->CharacterRepeaterDown(DialogElement::X-1,DialogElement::Y,4,Colors.DiaInterior,' ');
  54.     (*Blaze) (DialogElement::X-1,DialogElement::Y+Y) << '\x7';
  55.     (*Blaze) (DialogElement::X+X+1,DialogElement::Y-1) << '\x7';
  56.     MouseShow();
  57. }
  58.  
  59. void ForeGround::HighLight()
  60. {
  61.     MouseHide();
  62.     int Color=*TheColor&15; // Masks out other colors
  63.     int Y=(Color)?(Color/4):0;
  64.     int X=(Color-(Y*4))*3;
  65.     (*Blaze)(DialogElement::X+X,DialogElement::Y+Y) << (Color|128) << "\xfe\xfe\xfe";
  66.     Blaze->WindowGotoXY(DialogElement::X+X+1,DialogElement::Y+Y);
  67.     MouseShow();
  68. }
  69.  
  70. int ForeGround::EventHandler(int Event)
  71. {
  72.     int Color=*TheColor&15; // Masks out other colors
  73.     int Y=(Color)?(Color/4):0;
  74.     int X=(Color-(Y*4));
  75.  
  76.     if (Event==kbRight)
  77.     {
  78.         if (X<3)
  79.             (*TheColor)++;
  80.         else
  81.             (*TheColor)-=3;
  82.         Show();
  83.         HighLight();
  84.         return CompleteEvent;
  85.     }
  86.  
  87.     if (Event==kbLeft)
  88.     {
  89.         if (!X)
  90.             (*TheColor)+=3;
  91.         else
  92.             (*TheColor)--;
  93.         Show();
  94.         HighLight();
  95.         return CompleteEvent;
  96.     }
  97.  
  98.     if (Event==kbDown)
  99.     {
  100.         if (Y<3)
  101.             (*TheColor)+=4;
  102.         else
  103.             (*TheColor)-=12;
  104.         Show();
  105.         HighLight();
  106.         return CompleteEvent;
  107.     }
  108.  
  109.     if (Event==kbUp)
  110.     {
  111.         if (!Y)
  112.             (*TheColor)+=12;
  113.         else
  114.             (*TheColor)-=4;
  115.         Show();
  116.         HighLight();
  117.         return CompleteEvent;
  118.     }
  119.  
  120.     if (Event==ValidatedMousedEvent &&
  121.         (MouseEvent&MouseLeftButtonRelease || MouseButtonStatus&LeftButton))
  122.     {
  123.         MouseHorizontal-=DialogElement::X;
  124.         MouseVertical-=DialogElement::Y;
  125.         int X=(MouseHorizontal)?(MouseHorizontal/3):0;
  126.         int Color=(MouseVertical*4)+X;
  127.         *TheColor=(*TheColor&240)+Color;
  128.         Show();
  129.         HighLight();
  130.         return CompleteEvent;
  131.     }
  132.  
  133.     return Event;
  134. }
  135.  
  136. //-------------------------------------------------------------------------
  137. //
  138. // Foreground color class element
  139. //
  140. //-------------------------------------------------------------------------
  141.  
  142. BackGround::BackGround(int X,int Y,int TestX,int TestY)
  143. {
  144.     DialogElement::X=X;
  145.     DialogElement::Y=Y;
  146.     BackGround::TestX=TestX;
  147.     BackGround::TestY=TestY;
  148.     Width=12;
  149.     Height=2;
  150. }
  151.  
  152. void BackGround::Show()
  153. {
  154.     MouseHide();
  155.     int Colored[] = { bBlack,bBlue,bGreen,bCyan,bRed,bMagenta,bBrown,bWhite };
  156.     for (int i=0;i<2;i++)
  157.         for (int j=0;j<4;j++)
  158.       (*Blaze)(X+(j*3),Y+i) << Colored[(i*4)+j] << "   ";
  159.   (*Blaze)(TestX,TestY) << *TheColor << "  Current!  ";
  160.   int Color=(*TheColor&112)>>4; // Masks out other colors
  161.   int Y=(Color)?(Color/4):0;
  162.   int X=(Color-(Y*4))*3;
  163.   (*Blaze)(DialogElement::X+X,DialogElement::Y+Y) << Color << "\xfe\xfe\xfe";
  164.   (*Blaze) << Colors.DiaInterior;
  165.   Blaze->CharacterRepeater(DialogElement::X,DialogElement::Y-1,12,Colors.DiaInterior,' ');
  166.   Blaze->CharacterRepeaterDown(DialogElement::X-1,DialogElement::Y,2,Colors.DiaInterior,' ');
  167.   (*Blaze) (DialogElement::X-1,DialogElement::Y+Y) << '\x7';
  168.   (*Blaze) (DialogElement::X+X+1,DialogElement::Y-1) << '\x7';
  169.   MouseShow();
  170. }
  171.  
  172. void BackGround::HighLight()
  173. {
  174.   MouseHide();
  175.   int Color=(*TheColor&112)>>4; // Masks out other colors
  176.   int Y=(Color)?(Color/4):0;
  177.   int X=(Color-(Y*4))*3;
  178.   (*Blaze)(DialogElement::X+X,DialogElement::Y+Y) << (Color|128) << "\xfe\xfe\xfe";
  179.   Blaze->WindowGotoXY(DialogElement::X+X+1,DialogElement::Y+Y);
  180.   MouseShow();
  181. }
  182.  
  183. int BackGround::EventHandler(int Event)
  184. {
  185.     int Color=(*TheColor&112)>>4; // Masks out other colors
  186.   int Y=(Color)?(Color/4):0;
  187.     int X=(Color-(Y*4));
  188.  
  189.   if (Event==kbRight)
  190.   {
  191.     if (X<3)
  192.       Color++;
  193.     else
  194.       Color=3;
  195.     *TheColor=(*TheColor&143)+(Color<<4);
  196.     Show();
  197.     HighLight();
  198.     return CompleteEvent;
  199.   }
  200.  
  201.   if (Event==kbLeft)
  202.   {
  203.     if (!X)
  204.       Color+=3;
  205.     else
  206.       Color--;
  207.     *TheColor=(*TheColor&143)+(Color<<4);
  208.     Show();
  209.     HighLight();
  210.     return CompleteEvent;
  211.   }
  212.  
  213.   if (Event==kbDown)
  214.   {
  215.     if (Y<1)
  216.       Color+=4;
  217.     else
  218.       Color-=4;
  219.         *TheColor=(*TheColor&143)+(Color<<4);
  220.     Show();
  221.         HighLight();
  222.     return CompleteEvent;
  223.   }
  224.  
  225.   if (Event==kbUp)
  226.   {
  227.     if (!Y)
  228.       Color+=4;
  229.     else
  230.       Color-=4;
  231.     *TheColor=(*TheColor&143)+(Color<<4);
  232.     Show();
  233.     HighLight();
  234.     return CompleteEvent;
  235.   }
  236.  
  237.   if (Event==ValidatedMousedEvent &&
  238.     (MouseEvent&MouseLeftButtonRelease || MouseButtonStatus&LeftButton))
  239.   {
  240.     MouseHorizontal-=DialogElement::X;
  241.     MouseVertical-=DialogElement::Y;
  242.     int X=(MouseHorizontal)?(MouseHorizontal/3):0;
  243.     int Color=(MouseVertical*4)+X;
  244.     *TheColor=(*TheColor&143)+(Color<<4);
  245.     Show();
  246.     HighLight();
  247.     return CompleteEvent;
  248.   }
  249.  
  250.   return Event;
  251. }
  252.  
  253. //-------------------------------------------------------------------------
  254. //
  255. // Color changing dialog
  256. //
  257. //-------------------------------------------------------------------------
  258.  
  259. class ChColorDialog : public DialogClass
  260. {
  261. public:
  262.  
  263.   ChColorDialog() : DialogClass(20,20,"Palette")
  264.     {  }
  265.  
  266.   int EventHandler(int Event)
  267.   {
  268.     if (Event==kbEsc ||
  269.         Event==kbCr ||
  270.         Event==CloseEvent ||
  271.         Event==OutsideEvent ||
  272.         Event==colorChange ||
  273.         Event==colorCancel)
  274.       return StopEvent;
  275.     return CompleteEvent;
  276.   }
  277. };
  278.  
  279. //-------------------------------------------------------------------------
  280. //
  281. // Change colors / display dialog
  282. //
  283. //-------------------------------------------------------------------------
  284.  
  285. void DialogWindow::ChangeColor()
  286. {
  287.     ChColorDialog &Dialog=*new ChColorDialog();
  288.  
  289.     int Color=CurrentColor;
  290.     CurrentColor::TheColor=&Color;
  291.  
  292.     Dialog.Element(new ForeGround(3,3,3,14));
  293.     Dialog.HotKey(4,1,"~Foreground",kbAltF);
  294.     Dialog.Help("Select this foreground palette color");
  295.  
  296.     Dialog.Element(new BackGround(3,10,3,14));
  297.     Dialog.HotKey(4,8,"~Background",kbAltB);
  298.     Dialog.Help("Select this background palette color");
  299.  
  300.   Dialog.Element(new DiaPushButton(1,16,"Ok",colorChange,0,1));
  301.     Dialog.Help("Change to this palette color");
  302.  
  303.     Dialog.Element(new DiaPushButton(8,16,"Cancel",colorCancel));
  304.     Dialog.Help("Do not change the color");
  305.  
  306.     Dialog.Blaze.Box(1,1,16,7,Colors.DiaInterior);
  307.     Dialog.Blaze.Box(1,8,16,5,Colors.DiaInterior);
  308.     Dialog.Blaze.UserBoxDefineQuick(2);
  309.     Dialog.Blaze.Box(1,13,16,3,Colors.DiaInterior);
  310.     Dialog.Blaze.UserBoxDefineQuick(1);
  311.     Dialog.Blaze (6,13) << Colors.DiaInterior << "Sample";
  312.  
  313.     int Remember=Dialog.UseDialog();
  314.   delete &Dialog;
  315.  
  316.     if (Remember==kbCr || Remember==colorChange)
  317.   {
  318.         CurrentColor=Color;
  319.  
  320.     BlazeClass Blaze;
  321.  
  322.     RemoveTheMenus();
  323.  
  324.     Blaze (X+2,Y+Height-1) << CurrentColor << "Color";
  325.   }
  326. }
  327.  
  328.