home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Plugins / Plugins SDK / faceless.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-25  |  2.4 KB  |  108 lines  |  [TEXT/CWIE]

  1. #include "rb_plugin.h"
  2.  
  3. extern struct REALcontrol facelessControl;
  4.  
  5. REALevent facelessEvents[] = {
  6.     { "Action(red As Integer)" }
  7. };
  8.  
  9. Pattern black = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  10.  
  11. struct facelessData
  12. {
  13.     int fillColor;
  14. };
  15.  
  16. static void facelessInit(REALcontrolInstance instance)
  17. {
  18. }
  19.  
  20. static void facelessDraw(REALcontrolInstance instance)
  21. {
  22.     ControlData(facelessControl, instance, facelessData, data);
  23.     RGBColor oldCol, fillCol;
  24.     Rect r;
  25.  
  26.     REALGetControlBounds(instance, &r);
  27.  
  28.     GetForeColor(&oldCol);
  29.     fillCol.red = (data->fillColor >> 16) * 257;
  30.     fillCol.green = ((data->fillColor >> 8) & 0xff) * 257;
  31.     fillCol.blue = ((data->fillColor & 0xff) * 257);
  32.     RGBForeColor(&fillCol);
  33.     FillRect(&r, &black);
  34.     RGBForeColor(&oldCol);
  35.  
  36.     MoveTo(r.left, r.top);
  37.     LineTo(r.right - 1, r.top);
  38.     LineTo(r.right - 1, r.bottom - 1);
  39.     LineTo(r.left, r.bottom - 1);
  40.     LineTo(r.left, r.top);
  41.     LineTo(r.right - 1, r.bottom - 1);
  42. }
  43.  
  44. static void boxMakeRed(REALcontrolInstance instance)
  45. {
  46.     ControlData(facelessControl, instance, facelessData, data);
  47.  
  48.     void (*fp)(REALcontrolInstance instance, int);
  49.  
  50.     fp = (void (*)(REALcontrolInstance instance, int)) REALGetEventInstance(instance, &facelessEvents[0]);
  51.     if (fp)
  52.         fp(instance, data->fillColor >> 16);
  53.  
  54.     data->fillColor = 0xFF0000;
  55. }
  56.  
  57. static int boxColorComponent(REALcontrolInstance instance, int bit)
  58. {
  59.     ControlData(facelessControl, instance, facelessData, data);
  60.  
  61.     if (bit == 0)
  62.         return data->fillColor >> 16;
  63.     else if (bit == 1)
  64.         return (data->fillColor >> 8) & 0xff;
  65.     else
  66.         return (data->fillColor) & 0xff;
  67. }
  68.  
  69. REALproperty facelessProperties[] = {
  70.     { "Appearance", "BackColor", "Color", REALpropInvalidate, REALstandardGetter, REALstandardSetter, FieldOffset(facelessData, fillColor) }
  71. };
  72.  
  73. REALmethodDefinition facelessMethods[] = {
  74.     { (REALproc) boxMakeRed, REALnoImplementation, "makered" },
  75.     { (REALproc) boxColorComponent, REALnoImplementation, "colorComponent(v as integer) as integer" },
  76. };
  77.  
  78. REALcontrolBehaviour facelessBehaviour = {
  79.     facelessInit,
  80.     nil,
  81.     facelessDraw,
  82.     nil,
  83.     nil,
  84.     nil,
  85. };
  86.  
  87. REALcontrol facelessControl = {
  88.     kCurrentREALControlVersion,
  89.     "faceless",
  90.     sizeof(facelessData),
  91.     REALinvisibleControl,
  92.     128,
  93.     129,
  94.     32, 32,
  95.     facelessProperties,
  96.     sizeof(facelessProperties) / sizeof(REALproperty),
  97.     facelessMethods,
  98.     sizeof(facelessMethods) / sizeof(REALmethodDefinition),
  99.     facelessEvents,
  100.     sizeof(facelessEvents) / sizeof(REALevent),
  101.     &facelessBehaviour
  102. };
  103.  
  104. void PluginEntry(void)
  105. {
  106.     REALRegisterControl(&facelessControl);
  107. }
  108.