home *** CD-ROM | disk | FTP | other *** search
- #include "rb_plugin.h"
-
- static int add5func(int v)
- {
- return v + 5;
- }
-
- static REALstring plugchrfunc(int ch)
- {
- char cch = ch;
- return REALBuildString(&cch, 1);
- }
-
- static int plugascfunc(REALstring str)
- {
- return REALCString(str)[0];
- }
-
- extern struct REALcontrol boxControl;
-
- REALevent boxEvents[] = {
- { "Action(X As Integer,Y As Integer)" }
- };
-
- Pattern black = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-
- struct boxData
- {
- int fillColor;
- REALpicture backdrop;
- REALstring caption;
- };
-
- static void boxDevDraw(REALcontrolInstance instance)
- {
- ControlData(boxControl, instance, boxData, data);
- RGBColor oldCol, fillCol;
- Rect r;
-
- REALGetControlBounds(instance, &r);
-
- GetForeColor(&oldCol);
- fillCol.red = (data->fillColor >> 16) * 257;
- fillCol.green = ((data->fillColor >> 8) & 0xff) * 257;
- fillCol.blue = ((data->fillColor & 0xff) * 257);
- RGBForeColor(&fillCol);
- FillRect(&r, &black);
- RGBForeColor(&oldCol);
-
- MoveTo(r.left, r.top);
- LineTo(r.right - 1, r.top);
- LineTo(r.right - 1, r.bottom - 1);
- LineTo(r.left, r.bottom - 1);
- LineTo(r.left, r.top);
- LineTo(r.right - 1, r.bottom - 1);
- }
-
- static Boolean boxDevClick(REALcontrolInstance instance, int x, int y, int modifiers)
- {
- MoveTo(x - 3, y - 3);
- LineTo(x + 3, y + 3);
- MoveTo(x - 3, y + 3);
- LineTo(x + 3, y - 3);
- return true;
- }
-
- static void boxDevDrag(REALcontrolInstance instance, int x, int y)
- {
- MoveTo(x - 3, y - 3);
- LineTo(x + 3, y + 3);
- MoveTo(x - 3, y + 3);
- LineTo(x + 3, y - 3);
- }
-
- static void boxDevMouseUp(REALcontrolInstance instance, int x, int y)
- {
- void (*fp)(REALcontrolInstance instance, int ,int);
-
- fp = (void (*)(REALcontrolInstance instance, int, int)) REALGetEventInstance(instance, &boxEvents[0]);
- if (fp)
- fp(instance, x, y);
- }
-
- static void boxMakeRed(REALcontrolInstance instance)
- {
- ControlData(boxControl, instance, boxData, data);
-
- data->fillColor = 0xFF0000;
- }
-
- static int boxColorComponent(REALcontrolInstance instance, int bit)
- {
- ControlData(boxControl, instance, boxData, data);
-
- if (bit == 0)
- return data->fillColor >> 16;
- else if (bit == 1)
- return (data->fillColor >> 8) & 0xff;
- else
- return (data->fillColor) & 0xff;
- }
-
- static void boxColorComponentSet(REALcontrolInstance instance, int bit, int value)
- {
- ControlData(boxControl, instance, boxData, data);
-
- if (value < 0)
- value = 0;
- else if (value > 255)
- value = 255;
- if (bit == 0)
- data->fillColor = (data->fillColor & 0x00FFFF) | (value << 16);
- else if (bit == 1)
- data->fillColor = (data->fillColor & 0xFF00FF) | (value << 8);
- else
- data->fillColor = (data->fillColor & 0xFFFF00) | (value);
- REALInvalidateControl(instance);
- }
-
- REALproperty boxProperties[] = {
- { "Appearance", "BackColor", "Color", REALpropInvalidate, REALstandardGetter, REALstandardSetter, FieldOffset(boxData, fillColor) },
- { "Appearance", "Backdrop", "Picture", REALpropInvalidate, REALstandardGetter, REALstandardSetter, FieldOffset(boxData, backdrop) },
- { "Appearance", "Caption", "string", REALpropInvalidate, REALstandardGetter, REALstandardSetter, FieldOffset(boxData, caption) },
- };
-
- REALmethodDefinition add5defn = {
- (REALproc) add5func,
- REALnoImplementation,
- "add5(v as integer) as integer"
- };
-
- REALmethodDefinition plugascdefn = {
- (REALproc) plugascfunc,
- REALnoImplementation,
- "plugasc(v as string) as integer"
- };
-
- REALmethodDefinition plugchrdefn = {
- (REALproc) plugchrfunc,
- REALnoImplementation,
- "plugchr(v as integer) as string"
- };
-
- REALmethodDefinition boxMethods[] = {
- { (REALproc) boxMakeRed, REALnoImplementation, "makered" },
- { (REALproc) boxColorComponent, (REALproc) boxColorComponentSet, "colorComponent(v as integer) as integer" },
- };
-
- REALcontrolBehaviour boxBehaviour = {
- nil,
- nil,
- boxDevDraw,
- boxDevClick,
- boxDevDrag,
- boxDevMouseUp,
- };
-
- REALcontrol boxControl = {
- kCurrentREALControlVersion,
- "box",
- sizeof(boxData),
- REALcontrolAcceptFocus | REALcontrolFocusRing,
- 169,
- 170,
- 64, 32,
- boxProperties,
- sizeof(boxProperties) / sizeof(REALproperty),
- boxMethods,
- sizeof(boxMethods) / sizeof(REALmethodDefinition),
- boxEvents,
- sizeof(boxEvents) / sizeof(REALevent),
- &boxBehaviour
- };
-
- void PluginEntry(void)
- {
- REALRegisterMethod(&add5defn);
- REALRegisterMethod(&plugascdefn);
- REALRegisterMethod(&plugchrdefn);
- REALRegisterControl(&boxControl);
- }
-