From 0631f6560354be38d1b10b6f1c61026ff2a8df52 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 29 Sep 2014 17:13:08 +0000 Subject: mess up with accelerators --- Sgraph.c | 32 ++++++++++++++++++++++++++------ spectrogram.c | 21 +++++++++++++++------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Sgraph.c b/Sgraph.c index cf08fac..bbe717a 100644 --- a/Sgraph.c +++ b/Sgraph.c @@ -34,6 +34,7 @@ static void Realize(Widget w, XtValueMask *mask, XSetWindowAttributes *attr); static void Resize(Widget w); static void Redisplay(Widget w, XEvent *event, Region r); static Boolean SetValues(Widget old, Widget reference, Widget new, ArgList args, Cardinal *num_args); +static void mirror(Widget, XEvent *, String *, Cardinal *); /* Initialization */ #define Offset(field) XtOffsetOf(SgraphRec, sgraph.field) @@ -53,6 +54,14 @@ static XtResource resources[] = { }; #undef Offset +static XtActionsRec actions[] = { + { "mirror", mirror }, +}; + +static char translations[] = { + "m: mirror()\n", +}; + SgraphClassRec sgraphClassRec = { .core_class = { .superclass = (WidgetClass)&widgetClassRec, @@ -64,8 +73,8 @@ SgraphClassRec sgraphClassRec = { .initialize = Initialize, .initialize_hook = NULL, .realize = Realize, - .actions = NULL, - .num_actions = 0, + .actions = actions, + .num_actions = XtNumber(actions), .resources = resources, .num_resources = XtNumber(resources), .xrm_class = NULLQUARK, @@ -83,7 +92,7 @@ SgraphClassRec sgraphClassRec = { .accept_focus = NULL, .version = XtVersion, .callback_private = NULL, - .tm_table = XtInheritTranslations, + .tm_table = translations, .query_geometry = XtInheritQueryGeometry, .display_accelerator = XtInheritDisplayAccelerator, .extension = NULL, @@ -194,7 +203,7 @@ static void Redisplay(Widget w, XEvent *event, Region r) { SgraphWidget sw = (SgraphWidget)w; - Dimension x, y; + Dimension i, x, y; XdbeSwapInfo swap; //Trace(w); @@ -202,8 +211,12 @@ Redisplay(Widget w, XEvent *event, Region r) if (!XtIsRealized(w)) return; - for (x = 0; x < sw->sgraph.size - 1; x++) { - y = sw->sgraph.data[x]; + for (i = 0; i < sw->sgraph.size - 1; i++) { + y = sw->sgraph.data[i]; + if (sw->sgraph.mirror) + x = sw->core.width - i; + else + x = i; XDrawLine(XtDisplay(sw), sw->sgraph.backBuf, sw->sgraph.foreGC, @@ -216,3 +229,10 @@ Redisplay(Widget w, XEvent *event, Region r) XdbeSwapBuffers(XtDisplay(sw), &swap, 1); } + +static void +mirror(Widget w, XEvent *event, String *param, Cardinal *n) +{ + SgraphWidget sw = (SgraphWidget)w; + sw->sgraph.mirror ^= 1; +} diff --git a/spectrogram.c b/spectrogram.c index ec95a0d..d9ec780 100644 --- a/spectrogram.c +++ b/spectrogram.c @@ -107,14 +107,14 @@ int main(int argc, char **argv) { XtAppContext app; - Widget toplevel, display; + Widget toplevel, display, sgraph; int n, samples; Arg args[10]; + XtAccelerators acs; toplevel = XtAppInitialize(&app, "Spectrograph", options, XtNumber(options), &argc, argv, fallback, NULL, 0); - XtAppAddActions(app, actionsList, XtNumber(actionsList)); if (argc != 1) usage(); @@ -123,20 +123,29 @@ main(int argc, char **argv) init_fft(samples); warnx("samples: %d", samples); + XtAppAddActions(app, actionsList, XtNumber(actionsList)); + acs = XtParseAcceleratorTable("q: quit()"); + n = 0; XtSetArg(args[n], XtNorientation, "horizontal"); n++; + XtSetArg(args[n], XtNaccelerators, acs); n++; display = XtCreateManagedWidget("Display", displayWidgetClass, toplevel, args, n); n = 0; XtSetArg(args[n], XtNsamples, samples); n++; - XtCreateManagedWidget("SGraph", sgraphWidgetClass, + XtSetArg(args[n], XtNmirror, True); n++; + sgraph = XtCreateManagedWidget("SGraph", sgraphWidgetClass, display, args, n); - XtCreateManagedWidget("SGraph", sgraphWidgetClass, + XtInstallAccelerators(sgraph, display); + + n = 0; + XtSetArg(args[n], XtNsamples, samples); n++; + XtSetArg(args[n], XtNmirror, False); n++; + sgraph = XtCreateManagedWidget("SGraph", sgraphWidgetClass, display, args, n); + XtInstallAccelerators(sgraph, display); - XtOverrideTranslations(display, - XtParseTranslationTable("q: quit()")); XtAppAddWorkProc(app, worker, display); XtRealizeWidget(toplevel); -- cgit v1.2.3