home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / iconed / viedcnv.h < prev    next >
C/C++ Source or Header  |  1998-07-03  |  8KB  |  222 lines

  1. //========================= viedcnv.h ===================================
  2. // This is the header file for the icon editor picture class definition,
  3. // the color palette class definition, and the myCanvasPane class definition.
  4. //
  5. // Copyright (C) 1996 Philip Eckenroth, Mike Tipping, Marilee Padilla,
  6. //                    John Fredric Jr. Masciantoni, and Bruce E. Wampler.
  7. //
  8. // This file is part of the V Icon Editor, and is covered
  9. // under the terms of the GNU General Public License,
  10. // Version 2. This program has NO WARRANTY. See the source file
  11. // viedapp.cpp for more complete information about license terms.
  12. //=======================================================================
  13.  
  14. #ifndef VIEDCANVAS_H
  15. #define VIEDCANVAS_H
  16.  
  17. #include <v/vcanvas.h>  // derive from vCanvas
  18. #include <v/vpen.h>     // contain a vPen 
  19. #include <v/vcolor.h>
  20. #include <math.h>
  21.  
  22. #include <fstream.h>            // to save/restore drawings
  23.  
  24. #define DRAW  0
  25. #define ERASE 1
  26.  
  27.     class vApp;
  28.     class vWindow;
  29.     class myCmdWindow;
  30.  
  31.     const int defsize = 16;     // default icon size is 16x16
  32.     const int deflayers = 3;    // default number of layers is 3
  33.  
  34.     const int ImageLayer = 0;
  35.     const int TransLayer = 1;
  36.     const int BrushLayer = 2;
  37.  
  38.     class myCmdWindow;
  39.  
  40.     class Picture       // simple class for our icon
  41.       {
  42.       public:           //--------------------------------- public
  43.         Picture(int width = defsize, int height = defsize); // Constructor given size
  44.         ~Picture();             // Destructor
  45.  
  46.         int _width, _height;    // size of icon
  47.         int _x;                 // x coordinate for grid
  48.         int _y;                 // y coordinate for grid
  49.         int _index;             // index from color table
  50.     int *pixels[deflayers];            // pointer to 3-D pixel arrays
  51.  
  52.         // New methods for this class
  53.         int  GetIndex(int x, int y, int layer);            // get index from color table
  54.         void SetIndex(int x, int y, int layer, int index);    // set index to pixel
  55.         void Flatten();                         // collapse layers into picture
  56.         void Clear(int layer, int thecolor = 0);        // clear given layer
  57.         int  GetPicWidth();                    // get defined picture width
  58.         int  GetPicHeight();                    // get defined picture height
  59.  
  60.       protected:        //------------------------------ protected
  61.  
  62.       private:          //-------------------------------- private
  63.     int geti(int x,int y,int z) { return (pixels[z][(y*_width)+x]); }
  64.         void seti(int x,int y, int z, int val) { pixels[z][(y*_width)+x] = val;}
  65.       };
  66.  
  67.       class Color_Pal    // color palette class
  68.       {
  69.         public:
  70.           Color_Pal();                  // Constructor
  71.           ~Color_Pal();                 // Destructor
  72.       void init_Palette();        // init palette
  73.  
  74.           void makefg(int index);    // make index as the foreground color
  75.           void makebg(int index);    // make index as the background color
  76.           int  getfg();            // get the current foreground color
  77.           int  getbg();            // get current background color
  78.           
  79.           vColor getColor(int index);    // get color by given index number from the color palette
  80.           void setColor(int index, vColor value);    //  set color to index array location
  81.           void setRed(int index, int value);    //  set red color value
  82.           void setGreen(int index, int value);    //  set green color value
  83.           void setBlue(int index, int value);    //  set blue color value
  84.       void SetColorsUsed(int c) { _colorsUsed = c; }
  85.       int ColorsUsed() { return _colorsUsed; }
  86.  
  87.  
  88.           int _fg, _bg;
  89.           vColor _Palette[256];
  90.  
  91.         private:
  92.       int _colorsUsed;
  93.         };
  94.  
  95.     class myCanvasPane : public vCanvasPane
  96.       {
  97.       public:           //--------------------------------- public
  98.         myCanvasPane(myCmdWindow* cw);    // Constructor
  99.         virtual ~myCanvasPane();    // Destructor
  100.         void NewCanvas(int width = defsize, int height = defsize);    // create a new canvas
  101.  
  102.         // Methods we will override.
  103.  
  104.         virtual void MouseDown(int X, int Y, int button);
  105.         virtual void MouseUp(int X, int Y, int button);
  106.         virtual void MouseMove(int x, int y, int button);
  107.         virtual void MouseMotion(int x, int y);
  108.         virtual void Redraw(int x, int y, int w, int h);
  109.         virtual void Undo();
  110.         virtual void Resize(int w, int h);
  111.         virtual void HPage(int shown, int top);
  112.         virtual void HScroll(int step);
  113.         virtual void VPage(int shown, int top);
  114.         virtual void VScroll(int step);
  115.     void ResetScroll();
  116.  
  117.     void ResizeCanvas( int width, int height);
  118.  
  119.         // New methods for this class
  120.     void SetFGColor(vColor& color);
  121.     void SetBGColor(vColor& color);
  122.  
  123.         void ClearShapes();            // clears the drawing canvas
  124.         int Read(char* name);        
  125.  
  126.         int ReadIcon(char* name); 
  127.  
  128.         int Save(char* name);
  129.  
  130.     // General iconIO save
  131.         int SaveIcon(char* filename, char* iconname, char* ext);
  132.  
  133.         void SetDrawShape(int dm);
  134.  
  135.     // Draw grid to canvas
  136.         void DrawGrid();
  137.  
  138.         void DrawPixel(int x, int y, int layer);
  139.     void DrawDot(int x, int y);
  140.         void DrawImage();
  141.         int Changed() { return _changed; }
  142.         void SetChanged(int chg) { _changed = chg; }
  143.  
  144.         // Functions to draw shapes
  145.         void IconLine(int begx, int begy, int curx, int cury);
  146.         void IconRect(int begx, int begy, int curx, int cury, int mode);
  147.         void IconRdRect(int begx, int begy, int curx, int cury, int mode);
  148.         void IconEllipse(int begx, int begy, int curx, int cury, int mode);
  149.         void FillGrid(int x, int y);
  150.         void DrawBrush(int x, int y, int mode);
  151.         void FillTool(int x, int y, int the_index, int button);
  152.         Color_Pal *_myColorPal;
  153.         vColor *myPalette;
  154.  
  155.     // Functions to set the foreground and background colors
  156.         int  getCurPenInd();
  157.         void setCurPenCol(int index);
  158.         void setfg(int index);
  159.         void setbg(int index);
  160.         myCmdWindow* _cwin;
  161.  
  162.         int  _curPen;
  163.         vPen _PixelPen;
  164.         vBrush _PixelBrush;
  165.         int _snap;
  166.         int _PixSize;
  167.     int _drawGrid;
  168.         Picture* _myPicture; 
  169.  
  170.         int _PrevDrawWhat;
  171.         int _PrevDrawShape;
  172.  
  173.         int   _BrushWidth;
  174.         int   _BrushHeight;                
  175.         int   _BrushOffX;
  176.         int   _BrushOffY;
  177.         int   _BrushX;
  178.         int   _BrushY;
  179.         int   _BrushPrevX;
  180.         int   _BrushPrevY;
  181.         
  182.       protected:        //------------------------------ protected
  183.  
  184.       private:          //-------------------------------- private
  185.         void pixelwrite(int x, int y, int val);
  186.     int pixelread(int x, int y);
  187.     void fill(int x, int y, int width, int height, 
  188.         int ov, int fillcolor);
  189.         int getBaseAndExt(char* name, char* base, char* ext);
  190.         void SetScrollBarPositions();
  191.         int _DrawShape;
  192.         int _changed;
  193.         int _maxx, _maxy;
  194.         int _begx;  int _begy;  int _curx;  int _cury;  // coords
  195.         int _prex; int _prey;
  196.         int _dx, _dy;
  197.         int  Round(float num);
  198.         int  MyAbs(int value);
  199.  
  200.         int   _x;               // temp x;
  201.         int   _y;               // temp y;
  202.         int   _startval;        // start value for for loop
  203.         int   _endval;          // end value for for loop
  204.  
  205.         float _m;               // slope
  206.         float _b;               // y intercept for line and y rad for ellipse
  207.         float _a;               // x rad for ellipse
  208.        
  209.     int _rdh, _rdw;  // for smarter redraw
  210.     
  211.         int   _drawmode;
  212.         int   _prevind;
  213.  
  214.         int   _SelectbegX;
  215.         int   _SelectbegY;
  216.         int   _SelectendX;
  217.         int   _SelectendY;
  218.         
  219.       };
  220.  
  221. #endif
  222.