From 5beea06cfecfa77538e18b83a8f7b4872dc81f4f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 13 Sep 2014 23:19:24 +0000 Subject: add some basic stuff --- Sgraph.c | 113 +++++++++++++++++++++----------------------------------------- Sgraph.h | 2 ++ SgraphP.h | 5 +-- 3 files changed, 43 insertions(+), 77 deletions(-) diff --git a/Sgraph.c b/Sgraph.c index 9b13264..3b3532c 100644 --- a/Sgraph.c +++ b/Sgraph.c @@ -20,40 +20,46 @@ #include #include "SgraphP.h" -/* Class Methods */ -static void Initialize(Widget, Widget, ArgList, Cardinal *); +static void Initialize(Widget request, Widget w, ArgList args, Cardinal *nargs); +static void Realize(Widget w, XtValueMask *valueMask, XSetWindowAttributes *attrs); +static void Action(Widget w, XEvent *event, String *params, Cardinal *num_params); +static void Resize(Widget w); -/* Prototypes */ -static Bool Function(SgraphWidget, int, int, Bool); +#define BORDER 2 +#define SGRAPH_WIDTH 1024 +#define SGRAPH_HEIGHT 768 -/* Actions */ -static void Action(Widget, XEvent *, String *, Cardinal *); +static Dimension winwidth = SGRAPH_WIDTH; +static Dimension winheight = SGRAPH_HEIGHT; /* Initialization */ #define offset(field) XtOffsetOf(SgraphRec, sgraph.field) static XtResource resources[] = { - { - XtNsgraphResource, /* name */ - XtCSgraphResource, /* class */ - XtRSgraphResource, /* type */ - sizeof(char *), /* size */ - offset(resource), /* offset */ - XtRString, /* default_type */ - (XtPointer) "default" /* default_addr */ - }, + { XtNwidth, XtCWidth, XtRDimension, + sizeof(Dimension), XtOffset(Widget, core.width), + XtRDimension, &winwidth }, + { XtNheight, XtCHeight, XtRDimension, + sizeof(Dimension), XtOffset(Widget, core.height), + XtRDimension, &winheight }, + { XtNforeground, XtCForeground, XtRPixel, + sizeof(Pixel), XtOffset(SgraphWidget, sgraph.foreground), + XtRString, "white" }, + { XtNbackground, XtCBackground, XtRPixel, + sizeof(Pixel), XtOffset(SgraphWidget, sgraph.background), + XtRString, "black" }, + { XtNmirror, XtCBoolean, XtRBoolean, + sizeof(Boolean), XtOffset(SgraphWidget, sgraph.mirror), + XtRBoolean, False }, }; #undef offset -static XtActionsRec actions[] = -{ - { - "sgraph", /* name */ - Action /* procedure */ - }, +static XtActionsRec actions[] = { + { "sgraph", Action }, }; static char translations[] = ":" "sgraph()\n"; + #define Superclass (&widgetClassRec) SgraphClassRec sgraphClassRec = { /* core */ @@ -66,7 +72,7 @@ SgraphClassRec sgraphClassRec = { False, /* class_inited */ Initialize, /* initialize */ NULL, /* initialize_hook */ - XtInheritRealize, /* realize */ + Realize, /* realize */ actions, /* actions */ XtNumber(actions), /* num_actions */ resources, /* resources */ @@ -77,7 +83,7 @@ SgraphClassRec sgraphClassRec = { True, /* compress_enterleave */ False, /* visible_interest */ NULL, /* destroy */ - NULL, /* resize */ + Resize, /* resize */ NULL, /* expose */ NULL, /* set_values */ NULL, /* set_values_hook */ @@ -96,70 +102,27 @@ SgraphClassRec sgraphClassRec = { NULL, /* extension */ } }; - WidgetClass sgraphWidgetClass = (WidgetClass)&sgraphClassRec; /* Implementation */ -/* - * Function: - * Initialize - * - * Parameters: - * request - requested widget - * w - the widget - * args - arguments - * num_args - number of arguments - * - * Description: - * Initializes widget instance. - */ -/* ARGSUSED */ static void -Initialize(Widget request, Widget w, ArgList args, Cardinal *num_args) +Initialize(Widget request, Widget w, ArgList args, Cardinal *nargs) { - SgraphWidget sw = (SgraphWidget)w; +// Display *dpy = XtDisplay(w); +} - sw->sgraph.private = NULL; +static void +Realize(Widget w, XtValueMask *valueMask, XSetWindowAttributes *attrs) +{ + XtCreateWindow(w, InputOutput, CopyFromParent, *valueMask, attrs); } -/* - * Function: - * Function - * - * Parameters: - * sw - sgraph widget - * x - x coordinate - * y - y coordinate - * force - force action - * - * Description: - * This function does nothing. - * - * Return: - * Parameter force - */ -/* ARGSUSED */ -static Bool -Function(SgraphWidget sw, int x, int y, Bool force) +static void +Resize(Widget w) { - return (force); } -/* - * Function: - * Action - * - * Parameters: - * w - sgraph widget - * event - event that caused this action - * params - parameters - * num_params - number of parameters - * - * Description: - * This function does nothing. - */ -/* ARGSUSED */ static void Action(Widget w, XEvent *event, String *params, Cardinal *num_params) { diff --git a/Sgraph.h b/Sgraph.h index c2366eb..093971e 100644 --- a/Sgraph.h +++ b/Sgraph.h @@ -44,6 +44,8 @@ */ /* define any special resource names here that are not in */ +#define XtNmirror "mirror" + #define XtNsgraphResource "sgraphResource" #define XtCSgraphResource "SgraphResource" diff --git a/SgraphP.h b/SgraphP.h index 8213bb9..d6ca5a0 100644 --- a/SgraphP.h +++ b/SgraphP.h @@ -38,8 +38,9 @@ typedef struct _SgraphClassRec { extern SgraphClassRec sgraphClassRec; typedef struct { - char *resource; - char *private; + Pixel foreground; + Pixel background; + Boolean mirror; } SgraphPart; typedef struct _SgraphRec { -- cgit v1.2.3