home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / brush.cxx < prev    next >
C/C++ Source or Header  |  1995-04-09  |  4KB  |  187 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /*
  7.  *
  8.  *          Copyright (C) 1994, M. A. Sridhar
  9.  *  
  10.  *
  11.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  12.  *     to copy, modify or distribute this software  as you see fit,
  13.  *     and to use  it  for  any  purpose, provided   this copyright
  14.  *     notice and the following   disclaimer are included  with all
  15.  *     copies.
  16.  *
  17.  *                        DISCLAIMER
  18.  *
  19.  *     The author makes no warranties, either expressed or implied,
  20.  *     with respect  to  this  software, its  quality, performance,
  21.  *     merchantability, or fitness for any particular purpose. This
  22.  *     software is distributed  AS IS.  The  user of this  software
  23.  *     assumes all risks  as to its quality  and performance. In no
  24.  *     event shall the author be liable for any direct, indirect or
  25.  *     consequential damages, even if the  author has been  advised
  26.  *     as to the possibility of such damages.
  27.  *
  28.  */
  29.  
  30.  
  31.  
  32. #if defined(__GNUC__)
  33. #pragma implementation
  34. #endif
  35.  
  36.  
  37.  
  38.  
  39. #include "ui/brush.h"
  40. #include "ui/dsplsurf.h"
  41. #include "ui/applic.h"
  42.  
  43. #if defined(__MS_WINDOWS__)
  44. #include <windows.h>
  45. static short getPatternFromMS(UI_BrushPattern );
  46.  
  47. #elif defined(__X_MOTIF__)
  48. #include <X11/Intrinsic.h>
  49. static long getPatternFromX (const UI_BrushPattern &); 
  50.  
  51.  
  52. #endif
  53.  
  54. UI_Brush::UI_Brush (UI_DrawingSurface* ctxt, const UI_Color& color,
  55.                     UI_BrushPattern ptrn)
  56. : UI_DisplayResource (ctxt)
  57. {
  58.     _color = color;
  59.     _pattern = ptrn;
  60.     _handle = 0;
  61.     _Setup ();
  62. }
  63.  
  64. UI_Brush::UI_Brush(const UI_Brush& b)
  65. : UI_DisplayResource (b._clientCtxt)
  66. {
  67.     _pattern = b._pattern;
  68.     _handle = 0;
  69.     _Setup ();
  70. }
  71.  
  72.  
  73.  
  74. UI_Brush::~UI_Brush()
  75. {
  76. #if defined(__MS_WINDOWS__)
  77.     if (_handle) {
  78.         SelectObject (_clientCtxt->Handle(), GetStockObject (NULL_BRUSH));
  79.         DeleteObject ((HANDLE) _handle);
  80.     }
  81. #endif
  82. }
  83.  
  84.  
  85. void UI_Brush::Pattern (UI_BrushPattern p)
  86. {
  87.     _pattern = p;
  88.     _Setup();
  89. }
  90.  
  91. void UI_Brush::Color (const UI_Color& newC)
  92. {
  93.     _color = newC;
  94.     _Setup ();
  95. }
  96.  
  97. UI_Color UI_Brush::Color ()
  98. {
  99.     return _color;
  100. }
  101.  
  102. UI_BrushPattern UI_Brush::Pattern()
  103. {
  104.     return _pattern;
  105. }
  106.  
  107.  
  108. void UI_Brush::_Setup()
  109. {
  110. #if defined(__MS_WINDOWS__)
  111.     if (_handle) {
  112.         SelectObject (_clientCtxt->Handle(), GetStockObject (NULL_BRUSH));
  113.         DeleteObject ((HANDLE) _handle);
  114.     }
  115.     LOGBRUSH logBrush;
  116.     logBrush.lbStyle = getPatternFromMS (_pattern);
  117.     logBrush.lbColor = _color.NativeForm();
  118.     logBrush.lbHatch = HS_BDIAGONAL;
  119.     _handle = (UI_ResourceHandle) CreateBrushIndirect (&logBrush);
  120.     SelectObject (_clientCtxt->Handle(), _handle);
  121. #elif defined(__OS2__)
  122.     if (!_clientCtxt)
  123.         return;
  124.     HPS hps = (HPS) _clientCtxt->Handle();
  125.     GpiSetBackColor (hps, _color.NativeForm());
  126.     LONG backMode = BM_LEAVEALONE;
  127.     switch (_pattern) {
  128.     case UIBrush_Hatched:
  129.     case UIBrush_Solid:
  130.         backMode  = BM_OVERPAINT;
  131.         break;
  132.         
  133.     case UIBrush_Hollow:
  134.     default:
  135.         backMode  = BM_LEAVEALONE;
  136.         break;
  137.     };
  138.     GpiSetBackMix (hps, backMode);
  139. #elif defined(__X_MOTIF__)
  140.     if (!_clientCtxt)
  141.         return;
  142.     Display* dpy = XtDisplay (_TheApplication->MainWindow()->ViewHandle());
  143.     XSetFillStyle  (dpy, _clientCtxt->Handle (), 
  144.                     getPatternFromX (Pattern ()));
  145. #endif
  146. }
  147.  
  148.  
  149. #if defined(__MS_WINDOWS__)
  150.  
  151. short getPatternFromMS(UI_BrushPattern p)
  152. {
  153.     switch (p) {
  154.     case UIBrush_Hatched:
  155.         return BS_HATCHED;
  156.  
  157.     case UIBrush_Hollow:
  158.         return BS_HOLLOW;
  159.  
  160.     case UIBrush_Solid:
  161.         return BS_SOLID;
  162.  
  163.     default:
  164.         return BS_SOLID;
  165.    } 
  166. }
  167.  
  168. #elif defined(__X_MOTIF__)
  169.  
  170. long getPatternFromX (const UI_BrushPattern& p)
  171. {
  172.     switch (p){
  173.         case UIBrush_Hatched:
  174.             return FillTiled;
  175.  
  176.         case UIBrush_Solid:
  177.             return FillSolid;
  178.  
  179.         case UIBrush_Hollow:
  180.         default:
  181.             return FillSolid;
  182.     }
  183. }
  184.  
  185. #endif
  186.  
  187.