home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / pen.cxx < prev    next >
C/C++ Source or Header  |  1995-04-06  |  4KB  |  197 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. #if defined(__GNUC__)
  32. #pragma implementation
  33. #endif
  34.  
  35.  
  36. #include "ui/pen.h"
  37. #include "ui/color.h"
  38. #include "ui/visualob.h"
  39. #include "ui/dsplsurf.h"
  40. #include "ui/cntroler.h"
  41.  
  42. #if defined(__MS_WINDOWS__)
  43.  
  44. #include <windows.h>
  45. static short getPatternFromMS (UI_PenPattern );
  46. #elif defined(__X_MOTIF__)
  47.  
  48. #include <X11/Intrinsic.h>
  49.  
  50. static long getPatternFromX (UI_PenPattern);
  51. #endif
  52.  
  53. UI_Pen::UI_Pen (UI_DrawingSurface* ct, short sz, UI_Color cl,
  54.                 UI_PenPattern pt)
  55. : UI_DisplayResource (ct)
  56. {
  57.     _size = sz;
  58.     _color = cl;
  59.     _pattern = pt;
  60.     _handle = 0;
  61.     _Setup ();
  62. }
  63.  
  64. void UI_Pen::_Setup ()
  65. {
  66. #if defined(__MS_WINDOWS__)
  67.     if(_handle) {
  68.         SelectObject (_clientCtxt->Handle(), GetStockObject (BLACK_PEN));
  69.         DeleteObject (_handle);
  70.     }
  71.     short msp = getPatternFromMS (_pattern);
  72.     _handle = (UI_ResourceHandle) CreatePen (msp, _size, _color.NativeForm());
  73.     SelectObject (_clientCtxt->Handle(), _handle);
  74.     SetTextColor (_clientCtxt->Handle(), _color.NativeForm());
  75. #elif defined(__OS2__)
  76.     HPS hps = (HPS) _clientCtxt->Handle();
  77.     GpiSetLineType (hps, OS2Pattern ());
  78. //     if (!GpiSetColor (hps, _color.NativeForm()))
  79. //         UI_Application::PMError();
  80.     GpiSetLineWidth (hps, MAKEFIXED (_size, 0));
  81. #elif defined(__X_MOTIF__)
  82.     Display* dpy = XtDisplay (_TheApplication->Controller().ShellWidget());
  83.     XSetLineAttributes (dpy, _clientCtxt->Handle(), _size,
  84.                         getPatternFromX (Pattern ()),
  85.                         CapButt, JoinMiter);
  86.     
  87.     if (_pattern == UIPen_Dot || _pattern == UIPen_Dash) {
  88.         XGCValues val;
  89.         val.dashes = _pattern == UIPen_Dot ? 2 : 4;
  90.         XChangeGC (dpy, _clientCtxt->Handle(), GCDashList, &val);
  91.     }
  92. #endif
  93. }
  94.  
  95.  
  96.  
  97. UI_Pen::~UI_Pen()
  98. {
  99. #if defined(__MS_WINDOWS__)
  100.     if(_handle)
  101.         DeleteObject (_handle); 
  102.  
  103. #elif defined(__X_MOTIF__)
  104.  
  105. #endif
  106. }
  107.  
  108. void UI_Pen::Thickness (short sz)
  109. {
  110.     _size = sz;
  111.     _Setup ();
  112. }
  113.  
  114.  
  115. void UI_Pen::Pattern (UI_PenPattern ptrn)
  116. {
  117.     _pattern = ptrn;
  118.     _Setup ();
  119. }
  120.  
  121. void UI_Pen::Color(UI_Color newColor)
  122. {
  123.     _color = newColor;
  124.     _Setup();
  125. }
  126.  
  127.  
  128.  
  129.  
  130. #if defined(__MS_WINDOWS__)
  131.  
  132. short getPatternFromMS(UI_PenPattern p)
  133. {
  134.  
  135.     switch(p){
  136.  
  137.     case UIPen_None:
  138.         return PS_NULL;
  139.         
  140.     case UIPen_Solid:
  141.         return PS_SOLID;
  142.     
  143.     case UIPen_Dash:
  144.         return PS_DASH;
  145.     
  146.     case UIPen_Dot:
  147.         return PS_DOT;
  148.         
  149.     default:
  150.         return PS_SOLID;
  151.     }
  152.  
  153. }
  154.  
  155. #elif defined(__OS2__)
  156.  
  157. long UI_Pen::OS2Pattern () const
  158. {
  159.     switch (_pattern) {
  160.     case UIPen_None:
  161.         return LINETYPE_INVISIBLE;
  162.  
  163.     case UIPen_Dash:
  164.         return LINETYPE_SHORTDASH;
  165.     
  166.     case UIPen_Dot:
  167.         return LINETYPE_SHORTDASH;
  168.         
  169.     case UIPen_Solid:
  170.     default:
  171.         return LINETYPE_SOLID;
  172.     }
  173.  
  174. }
  175.  
  176. #elif defined(__X_MOTIF__)
  177. long getPatternFromX (UI_PenPattern p)
  178. {
  179.     switch (p){
  180.     case UIPen_Solid:
  181.         return LineSolid;
  182.  
  183.     case UIPen_Dash:
  184.         return LineOnOffDash;
  185.  
  186.     case UIPen_Dot:
  187.         return LineOnOffDash;
  188.  
  189.     default:
  190.         return LineSolid;
  191.     }
  192.  
  193. }
  194.  
  195. #endif
  196.  
  197.