From 5d04bbcf9f3c0ae746f450b86ccf76ad9119a0dd Mon Sep 17 00:00:00 2001 From: Roman Belov Date: Tue, 10 Dec 2024 19:22:21 +0300 Subject: [PATCH] Updated docs, GP and Nuklear sources. --- README.md | 1 - doc/CommandLineInterface.md | 17 +- doc/{MachineTuning.md => ControlTuning.md} | 0 doc/GettingStarted.md | 8 +- doc/GraphicalUserInterface.md | 3 +- doc/HardwareDesign.md | 2 +- doc/HardwareVESC.md | 2 +- doc/IntegritySelfTest.md | 4 +- doc/MachineProbe.md | 39 +- doc/NetworkCAN.md | 19 +- pgui/gp/async.c | 98 +- pgui/gp/async.h | 10 +- pgui/gp/dirent.c | 4 +- pgui/gp/draw.c | 117 +- pgui/gp/draw.h | 8 +- pgui/gp/edit.c | 11 +- pgui/gp/edit.h | 2 +- pgui/gp/gp.c | 2070 ++++-- pgui/gp/gp.h | 36 +- pgui/gp/lang.c | 90 +- pgui/gp/lang.h | 5 + pgui/gp/lse.c | 305 +- pgui/gp/lse.h | 47 +- pgui/gp/lz4.c | 70 +- pgui/gp/lz4.h | 84 +- pgui/gp/menu.c | 2 +- pgui/gp/plot.c | 2103 ++++-- pgui/gp/plot.h | 81 +- pgui/gp/read.c | 788 ++- pgui/gp/read.h | 24 +- pgui/gp/scheme.c | 20 +- pgui/gp/scheme.h | 2 +- pgui/gp/svg.c | 2 +- pgui/nksdl.c | 1 + pgui/nuklear.h | 7289 +++++++++++--------- pgui/phobia.c | 13 +- src/app/autostart.c | 6 +- src/phobia/lse.h | 6 +- src/regfile.c | 2 +- src/shell.c | 6 +- 40 files changed, 8247 insertions(+), 5150 deletions(-) rename doc/{MachineTuning.md => ControlTuning.md} (100%) diff --git a/README.md b/README.md index 9a60845..05e0992 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ There are a few videos about PMC on [youtube](https://www.youtube.com/@romblv). - Least Squares estimate library [LSE](https://github.com/rombrew/lse). - - Phase current sampling scheme includes two or three sensors configuration with inline or low-side placement. - Self-adjustment of all onboard measurements (current and voltage) along diff --git a/doc/CommandLineInterface.md b/doc/CommandLineInterface.md index e9ad980..2dc4163 100644 --- a/doc/CommandLineInterface.md +++ b/doc/CommandLineInterface.md @@ -1,7 +1,8 @@ ## Overview -This page introduces you to the Command Line Interface (CLI). We have a regular -CLI with autocompletion function and command history. +The main control interface of PMC is Command Line Interface (CLI). We have a +regular UNIX-like CLI with autocompletion function and command history. +Depending on the hardware it is available on USART, USB and CAN interface. ## Key mapping @@ -12,10 +13,10 @@ These are the basic special keys that are used in the CLI: - `Tab` or (@) - Automplete function. - `Shift` + `Tab` - Automplete function reverse. - `Ctrl` + `C` or `Ctrl` + `D` - Drop the content of the line or abort the command. -- `Ctrl` + `P` or `Up` or `*` - History function scroll up. -- `Ctrl` + `N` or `Down` or `!` - History function scroll down. +- `Ctrl` + `P` or `Up` - History function scroll up. +- `Ctrl` + `N` or `Down` - History function scroll down. -## Register file +## Register concept A register is a scalar variable known by its name and having associated attributes. All registers together are called the register file. This is a @@ -31,7 +32,7 @@ command. - You can specify a register number instead of its name to refer the exactly one register. -Something like that. +Try something like that. (pmc) reg (pmc) reg @@ -88,7 +89,7 @@ Command to grab telemetry into RAM and flush textual dump. (pmc) tlm_grab (pmc) tlm_flush_sync -Run in endless loop of grabbing until PMC stops with error. +Run in endless loop of grabbing until PMC stops with an error. (pmc) tlm_watch @@ -162,7 +163,7 @@ Show instant analog knob input voltages. (pmc) reg ap.knob_in_ANG (pmc) reg ap.knob_in_BRK -Enable the HX711 helper task. +Enable the HX711 helper application. (pmc) reg ap.task_HX711 1 diff --git a/doc/MachineTuning.md b/doc/ControlTuning.md similarity index 100% rename from doc/MachineTuning.md rename to doc/ControlTuning.md diff --git a/doc/GettingStarted.md b/doc/GettingStarted.md index 1333b1b..8ea8685 100644 --- a/doc/GettingStarted.md +++ b/doc/GettingStarted.md @@ -49,7 +49,9 @@ erased MCU) then short BOOT pin to +3.3v before the power up. +--/ --+ ``` -**WARNING**: You also can use an USB connection if your hardware has one. +**WARNING**: You also can use an USB connection if your hardware has one. Refer +to your hardware manual or look into `src/hal/hw/...` directory to find out +available serial interfaces. ## Software @@ -94,7 +96,7 @@ files by `mkconfig` python script before build. $ ./mkconfig $ make HWREV=PHOBIA_rev5 -## Load +## MCU flash There are several ways to load the firmware into the MCU. @@ -147,7 +149,7 @@ for setting PMC up. - [Hardware VESC](HardwareVESC.md) - [Integrity Self Test](IntegritySelfTest.md) - [Machine Probe](MachineProbe.md) -- [Machine Tuning](MachineTuning.md) +- [Control Tuning](ControlTuning.md) - [High Frequency Injection](HighFrequencyInjection.md) - [Input Analog Knob](InputAnalogKnob.md) - [Input Pulse Width](InputPulseWidth.md) diff --git a/doc/GraphicalUserInterface.md b/doc/GraphicalUserInterface.md index 1a2c223..1dc6a1b 100644 --- a/doc/GraphicalUserInterface.md +++ b/doc/GraphicalUserInterface.md @@ -1,7 +1,8 @@ ## Overview This page introduces you to the Phobia Graphical User Interface (PGUI). We have -a regular GUI application. +the regular GUI front-end application that communicates with PMC via serial +interface. ## TODO diff --git a/doc/HardwareDesign.md b/doc/HardwareDesign.md index 8442a19..250d784 100644 --- a/doc/HardwareDesign.md +++ b/doc/HardwareDesign.md @@ -90,7 +90,7 @@ uncertainty in the output voltage `DTu` expressed as follows. The voltage divider (R1, R2) and filter capacitor (C1) are used to measure the terminal voltage (uA, uB, uC) and supply voltage (uS). This RC scheme forms an exponential integrator that allows us to restore the pulse width by measured -voltage. Additional resistor R3 can be used to bias the zero volatege into the +voltage. Additional resistor R3 can be used to bias the zero voltage into the linear region. You can skip the terminal voltage sensing if you do not need related features but supply voltage measuring is mandatory. diff --git a/doc/HardwareVESC.md b/doc/HardwareVESC.md index b32be00..08f15a1 100644 --- a/doc/HardwareVESC.md +++ b/doc/HardwareVESC.md @@ -23,7 +23,7 @@ You are also welcome to look into `src/hal/hw/...` directory to get a full actual information about specific hardware port. You can build the firmware binary yourself from sources or get it from the -bundle releases. +bundle [resleases](https://github.com/rombrew/phobia/releases). $ cd phobia/src $ make HWREV=MKESC_60100_v2 diff --git a/doc/IntegritySelfTest.md b/doc/IntegritySelfTest.md index 29c419e..67dae01 100644 --- a/doc/IntegritySelfTest.md +++ b/doc/IntegritySelfTest.md @@ -3,7 +3,7 @@ This page describes how to verify the electrical integrity of PMC hardware. **WARNING**: The procedures listed here are MUST DO in case of new hardware -first powerup. +first power up. ## Automated Self Test @@ -16,7 +16,7 @@ This test does the following steps in this order. - Get current sensors zero drift and check it is within the acceptable range. - Check actual bootstrap retention time and compare with configuration. -- Check the power stage responds to the control. +- Check the power stages respond to the control. - Check measurement accuracy against the distortion introduced by PWM. You can do it with or without machine connected. Ignore the appropriate error diff --git a/doc/MachineProbe.md b/doc/MachineProbe.md index b5bb00f..5575606 100644 --- a/doc/MachineProbe.md +++ b/doc/MachineProbe.md @@ -32,15 +32,13 @@ you will need to decrease probing currents for a small machine. If you use power supply that not tolerate reverse current then pay attention to the wattage limit settings. - (pmc) reg pm.watt - - `pm.watt_wA_reverse` - Maximal reverse current on DC link. - `pm.watt_uDC_maximal` - Maximal overvoltage on DC link. Also do not forget to reset the machine parameters if you have previously run another machine. - (pmc) pm_default_probe + (pmc) pm_default_machine ## Sensors adjustment @@ -101,7 +99,8 @@ to reach this condition. (pmc) pm_probe_spinup If the procedure fails to spinup the machine try to adjust forced control -parameters. Also you can specify Kv manually if you know it exactly. +parameters. Also you can specify Kv manually if you know it exactly and Zp +number is already configured correcly. (pmc) reg pm.const_lambda_kv @@ -110,6 +109,7 @@ speed and request lambda probing manually. Do not load the machine at this. (pmc) pm_fsm_startup (pmc) reg pm.s_setpoint_rpm + ... (pmc) pm_probe_const_flux_linkage ## No forced spinup @@ -124,21 +124,38 @@ PMC will wait for the machine to reach at least `pm.zone_threshold` speed. ## Speed noise threshold -After a flux linkage we estimate speed noise level to know the lower bound of -flux observer operation. As a result these threshold values are calculated. +In case of you use `pm_probe_spinup` after a flux linkage we estimate speed +noise level to know the lower bound of flux observer operation. As a result +these threshold values are calculated. (pmc) reg pm.zone_noise (pmc) reg pm.zone_threshold +If you have estimated flux linkage in detached mode or specified Kv manually +you should probe the noise threshold manually when the machine is in run. + + (pmc) pm_fsm_startup + (pmc) reg pm.s_setpoint_rpm + ... + (pmc) pm_probe_noise_threshold + ## Moment of inertia -Final estimate is a moment of inertia `pm.const_Ja`. To do this possible a -speed maneuver will be performed. Note that this may result energy regeneration -so your power supply must tolerate this. Either you should limit maximal DC -link current reverse as stated above. +In case of you use `pm_probe_spinup` the final estimate is a moment of inertia +`pm.const_Ja`. To do this possible a speed maneuver will be performed. Note +that this may result energy regeneration so your power supply must tolerate +this. Either you should limit maximal DC link current reverse as stated above. This constant is used to tune speed control loop. Also it is used in operation -to predict the speed changes from an applied current. +to predict the speed changes from an applied current and so on. + +If you have estimated flux linkage in detached mode or specified Kv manually +you should probe the moment of inertia manually. + + (pmc) pm_fsm_startup + (pmc) reg pm.s_setpoint_rpm + ... + (pmc) pm_probe_const_inertia ## See also diff --git a/doc/NetworkCAN.md b/doc/NetworkCAN.md index 31d1c9e..c6caa72 100644 --- a/doc/NetworkCAN.md +++ b/doc/NetworkCAN.md @@ -10,19 +10,22 @@ TODO conventional two wire bus uses a linear bus terminated at each end - +------------------------*-------------------- - | | - | +------------------|-----*-------------- - | | | | - +------|-----|------+ +------|-----|------+ - | CAN_H CAN_L | | CAN_H CAN_L | ... - | | | | - + +-------------------------*------------------~~~ + | | + | +------------------|------*-----------~~~ + | | | | + +------+------+------+ +------+------+------+ + | CAN_H CAN_L | | CAN_H CAN_L | ... + | | | | + | PMC (node 1) | | PMC (node 2) | ## Protocol We use base frame format with 11-bit identifier. + +---------------+-------------+------------------------+ + | ID (11-bit) | N (4-bit) | payload (64-bit) | + +---------------+-------------+------------------------+ ## Network survey diff --git a/pgui/gp/async.c b/pgui/gp/async.c index 2070400..6a2a844 100644 --- a/pgui/gp/async.c +++ b/pgui/gp/async.c @@ -29,7 +29,7 @@ static int async_READ(async_FILE *afd) { - int rp, wp, nw, r; + int rp, wp, nw, rc; wp = SDL_AtomicGet(&afd->wp); @@ -44,11 +44,11 @@ async_READ(async_FILE *afd) nw = afd->preload - wp; nw = (nw > afd->chunk) ? afd->chunk : nw; - r = fread(afd->stream + wp, 1, nw, afd->fd); + rc = (int) fread(afd->stream + wp, 1, nw, afd->fd); - if (r != 0) { + if (rc != 0) { - wp += r; + wp += rc; wp -= (wp >= afd->preload) ? afd->preload : 0; SDL_AtomicSet(&afd->wp, wp); @@ -56,7 +56,7 @@ async_READ(async_FILE *afd) afd->waiting = 0; } - if (r != nw) { + if (rc != nw) { if (feof(afd->fd) || ferror(afd->fd)) { @@ -89,7 +89,7 @@ async_FILE *async_open(FILE *fd, int preload, int chunk, int timeout) { async_FILE *afd; - afd = calloc(1, sizeof(async_FILE)); + afd = (async_FILE *) calloc(1, sizeof(async_FILE)); afd->preload = preload; afd->chunk = chunk; @@ -109,9 +109,30 @@ async_FILE *async_open(FILE *fd, int preload, int chunk, int timeout) return afd; } +async_FILE *async_stub(int preload, int chunk, int timeout) +{ + async_FILE *afd; + + afd = (async_FILE *) calloc(1, sizeof(async_FILE)); + + afd->preload = preload; + afd->chunk = chunk; + afd->timeout = timeout; + + afd->stream = (char *) malloc(afd->preload); + + if (afd->stream == NULL) { + + ERROR("No memory allocated for async preload\n"); + return NULL; + } + + return afd; +} + void async_close(async_FILE *afd) { - int t = 0; + int tN = 0; SDL_AtomicSet(&afd->flag_break, 1); SDL_DetachThread(afd->thread); @@ -123,13 +144,12 @@ void async_close(async_FILE *afd) free(afd->stream); free(afd); - break; } - t += 1; + tN += 1; - if (t >= 200) { + if (tN >= 100) { ERROR("Unable to terminate async_READ (memory leak)\n"); break; @@ -138,15 +158,51 @@ void async_close(async_FILE *afd) while (1); } -int async_read(async_FILE *afd, char *sbuf, int n) +int async_write(async_FILE *afd, const char *raw, int n) +{ + int rp, wp, nw; + + rp = SDL_AtomicGet(&afd->rp); + wp = SDL_AtomicGet(&afd->wp); + + nw = (wp < rp) ? rp - wp : rp + afd->preload - wp; + + if (nw > n) { + + if (wp + n >= afd->preload) { + + nw = afd->preload - wp; + + memcpy(afd->stream + wp, raw, nw); + memcpy(afd->stream, raw + nw, n - nw); + + wp += n - afd->preload; + } + else { + memcpy(afd->stream + wp, raw, n); + + wp += n; + } + + afd->clock = SDL_GetTicks(); + + SDL_AtomicSet(&afd->wp, wp); + + return ASYNC_OK; + } + else { + return ASYNC_NO_FREE_SPACE; + } +} + +int async_read(async_FILE *afd, char *raw, int n) { int rp, wp, nr; rp = SDL_AtomicGet(&afd->rp); wp = SDL_AtomicGet(&afd->wp); - nr = wp - rp; - nr += (nr < 0) ? afd->preload : 0; + nr = (wp < rp) ? wp + afd->preload - rp : wp - rp; if (nr >= n) { @@ -154,13 +210,13 @@ int async_read(async_FILE *afd, char *sbuf, int n) nr = afd->preload - rp; - memcpy(sbuf, afd->stream + rp, nr); - memcpy(sbuf + nr, afd->stream, n - nr); + memcpy(raw, afd->stream + rp, nr); + memcpy(raw + nr, afd->stream, n - nr); rp += n - afd->preload; } else { - memcpy(sbuf, afd->stream + rp, n); + memcpy(raw, afd->stream + rp, n); rp += n; } @@ -178,7 +234,7 @@ int async_read(async_FILE *afd, char *sbuf, int n) } } -int async_gets(async_FILE *afd, char *sbuf, int n) +int async_gets(async_FILE *afd, char *raw, int n) { int rp, wp, eol, nq; char c; @@ -207,7 +263,7 @@ int async_gets(async_FILE *afd, char *sbuf, int n) } else if (nq < n - 1) { - *sbuf++ = (char) c; + *raw++ = (char) c; nq++; } @@ -219,7 +275,7 @@ int async_gets(async_FILE *afd, char *sbuf, int n) if (eol != 0) { - *sbuf = 0; + *raw = 0; SDL_AtomicSet(&afd->rp, rp); @@ -242,7 +298,7 @@ int async_gets(async_FILE *afd, char *sbuf, int n) if (nq < n - 1) { - *sbuf++ = (char) c; + *raw++ = (char) c; nq++; } @@ -250,7 +306,7 @@ int async_gets(async_FILE *afd, char *sbuf, int n) } while (1); - *sbuf = 0; + *raw = 0; SDL_AtomicSet(&afd->rp, rp); diff --git a/pgui/gp/async.h b/pgui/gp/async.h index 142b929..ea6adb9 100644 --- a/pgui/gp/async.h +++ b/pgui/gp/async.h @@ -26,6 +26,7 @@ enum { ASYNC_OK = 0, + ASYNC_NO_FREE_SPACE, ASYNC_NO_DATA_READY, ASYNC_END_OF_FILE }; @@ -35,6 +36,8 @@ typedef struct { FILE *fd; SDL_Thread *thread; + Uint32 clock; + int preload; int chunk; int timeout; @@ -42,6 +45,7 @@ typedef struct { int waiting; char *stream; + SDL_atomic_t rp; SDL_atomic_t wp; @@ -51,10 +55,12 @@ typedef struct { async_FILE; async_FILE *async_open(FILE *fd, int preload, int chunk, int timeout); +async_FILE *async_stub(int preload, int chunk, int timeout); void async_close(async_FILE *afd); -int async_read(async_FILE *afd, char *sbuf, int n); -int async_gets(async_FILE *afd, char *sbuf, int n); +int async_write(async_FILE *afd, const char *raw, int n); +int async_read(async_FILE *afd, char *raw, int n); +int async_gets(async_FILE *afd, char *raw, int n); #endif /* _H_ASYNC_ */ diff --git a/pgui/gp/dirent.c b/pgui/gp/dirent.c index 3b5e68b..13c2e58 100644 --- a/pgui/gp/dirent.c +++ b/pgui/gp/dirent.c @@ -45,7 +45,7 @@ int dirent_open(struct dirent_stat *sb, const char *path) memset(sb->priv, 0, sizeof(struct dirent_priv)); } else { - sb->priv = calloc(1, sizeof(struct dirent_priv)); + sb->priv = (struct dirent_priv *) calloc(1, sizeof(struct dirent_priv)); } p = sb->priv; @@ -207,7 +207,7 @@ int dirent_open(struct dirent_stat *sb, const char *path) memset(sb->priv, 0, sizeof(struct dirent_priv)); } else { - sb->priv = calloc(1, sizeof(struct dirent_priv)); + sb->priv = (struct dirent_priv *) calloc(1, sizeof(struct dirent_priv)); } p = sb->priv; diff --git a/pgui/gp/draw.c b/pgui/gp/draw.c index 1d0f77a..516430a 100644 --- a/pgui/gp/draw.c +++ b/pgui/gp/draw.c @@ -73,7 +73,7 @@ void drawClearSurface(draw_t *dw, SDL_Surface *surface, Uint32 col) len = pitch * surface->h; - for (n = 0; n < len - 15UL; n += 16UL) { + for (n = 0; n < len - 15; n += 16) { *pixels++ = col; *pixels++ = col; @@ -1443,14 +1443,27 @@ void drawDashCanvas(draw_t *dw, SDL_Surface *surface, clipBox_t *cb, double fxs, l = d * h; - w1 = (ys - ye) * (lcb.min_x * 16 - xe + 8) - (xs - xe) * (lcb.min_y * 16 - ye + 8); - w2 = (xe - xs) * (lcb.min_x * 16 - xs + 8) + (ye - ys) * (lcb.min_y * 16 - ys + 8); + if (fys < fye) { - w1dx = (ys - ye) * 16; - w2dx = (xe - xs) * 16; + w1 = (ys - ye) * (lcb.min_x * 16 - xe + 8) - (xs - xe) * (lcb.min_y * 16 - ye + 8); + w2 = (xs - xe) * (lcb.min_x * 16 - xe + 8) + (ys - ye) * (lcb.min_y * 16 - ye + 8); - w1dy = - (xs - xe) * 16; - w2dy = (ye - ys) * 16; + w1dx = (ys - ye) * 16; + w2dx = (xs - xe) * 16; + + w1dy = - (xs - xe) * 16; + w2dy = (ys - ye) * 16; + } + else { + w1 = (ys - ye) * (lcb.min_x * 16 - xe + 8) - (xs - xe) * (lcb.min_y * 16 - ye + 8); + w2 = (xe - xs) * (lcb.min_x * 16 - xs + 8) + (ye - ys) * (lcb.min_y * 16 - ys + 8); + + w1dx = (ys - ye) * 16; + w2dx = (xe - xs) * 16; + + w1dy = - (xs - xe) * 16; + w2dy = (ye - ys) * 16; + } context = dw->dash_context; @@ -2266,10 +2279,10 @@ void drawText(draw_t *dw, SDL_Surface *surface, TTF_Font *font, int xs, int ys, svgDrawText(g, xs, ys, text, (svgCol_t) col, flags); } - textColor.a = 0; - textColor.r = (col & 0x00FF0000UL) >> 16; - textColor.g = (col & 0x0000FF00UL) >> 8; - textColor.b = (col & 0x000000FFUL) >> 0; + textColor.a = (Uint8) 0; + textColor.r = (Uint8) ((col & 0x00FF0000UL) >> 16); + textColor.g = (Uint8) ((col & 0x0000FF00UL) >> 8); + textColor.b = (Uint8) ((col & 0x000000FFUL) >> 0); if (dw->blendfont != 0) { @@ -3197,12 +3210,12 @@ int drawDotTrial(draw_t *dw, clipBox_t *cb, double fxs, double fys, void drawMarkCanvas(draw_t *dw, SDL_Surface *surface, clipBox_t *cb, double fxs, double fys, int rsize, int shape, int ncol, int thickness) { - double r2, r6; + double r2, r6, r3, r5, r8, r9; if (shape == SHAPE_CIRCLE) { r2 = (double) rsize * 0.5; - r6 = (double) rsize * 0.86603; + r6 = (double) rsize * 0.8660; drawLineCanvas(dw, surface, cb, fxs - rsize, fys, fxs - r6, fys - r2, ncol, thickness); drawLineCanvas(dw, surface, cb, fxs - r6, fys - r2, fxs - r2, fys - r6, ncol, thickness); @@ -3217,38 +3230,58 @@ void drawMarkCanvas(draw_t *dw, SDL_Surface *surface, clipBox_t *cb, double fxs, drawLineCanvas(dw, surface, cb, fxs - r6, fys + r2, fxs - r2, fys + r6, ncol, thickness); drawLineCanvas(dw, surface, cb, fxs - r2, fys + r6, fxs, fys + rsize, ncol, thickness); } - else if (shape == SHAPE_RECTANGLE) { + else if (shape == SHAPE_STARLET) { - drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs + rsize, fys - rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys + rsize, fxs + rsize, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs - rsize, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs + rsize, fys - rsize, fxs + rsize, fys + rsize, ncol, thickness); + r2 = (double) 0.4; + r6 = (double) rsize * 1.2; + + r3 = (double) rsize * 0.3708; + r5 = (double) rsize * 0.7054; + r8 = (double) rsize * 0.9708; + r9 = (double) rsize * 1.1413; + + drawLineCanvas(dw, surface, cb, fxs, fys + r6*r2, fxs + r5, fys + r8, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r5, fys + r8, fxs + r9*r2, fys + r3*r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r9*r2, fys + r3*r2, fxs + r9, fys - r3, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r9, fys - r3, fxs + r5*r2, fys - r8*r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r5*r2, fys - r8*r2, fxs, fys - r6, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs, fys - r6, fxs - r5*r2, fys - r8*r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r5*r2, fys - r8*r2, fxs - r9, fys - r3, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r9, fys - r3, fxs - r9*r2, fys + r3*r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r9*r2, fys + r3*r2, fxs - r5, fys + r8, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r5, fys + r8, fxs, fys + r6*r2, ncol, thickness); } - else if (shape == SHAPE_TRIANGLE) { + else if (shape == SHAPE_HUBCAP) { - drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs + rsize, fys - rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs + rsize, fys - rsize, fxs, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs, fys + rsize, fxs - rsize, fys - rsize, ncol, thickness); + r2 = (double) rsize * 0.7; + + drawLineCanvas(dw, surface, cb, fxs - r2, fys + rsize, fxs + r2, fys + rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r2, fys + rsize, fxs, fys - rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs, fys - rsize, fxs - r2, fys + rsize, ncol, thickness); } - else if (shape == SHAPE_ASTERIX) { + else if (shape == SHAPE_RECTANGLE) { + + r2 = (double) rsize * 0.9; + + drawLineCanvas(dw, surface, cb, fxs - r2, fys - r2, fxs + r2, fys - r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys + r2, fxs + r2, fys + r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys - r2, fxs - r2, fys + r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + r2, fys - r2, fxs + r2, fys + r2, ncol, thickness); + } + else if (shape == SHAPE_SNOWFLAKE) { + + r2 = (double) rsize * 0.7; drawLineCanvas(dw, surface, cb, fxs - rsize, fys, fxs + rsize, fys, ncol, thickness); drawLineCanvas(dw, surface, cb, fxs, fys - rsize, fxs, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs + rsize, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys + rsize, fxs + rsize, fys - rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys - r2, fxs + r2, fys + r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys + r2, fxs + r2, fys - r2, ncol, thickness); } - else if (shape == SHAPE_STAR) { - - r2 = (double) rsize * 0.5; + else if (shape == SHAPE_TRIANGLE) { - drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs, fys - r2, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs, fys - r2, fxs + rsize, fys - rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys + rsize, fxs, fys + r2, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs, fys + r2, fxs + rsize, fys + rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - rsize, fys + rsize, fxs - r2, fys, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs - r2, fys, fxs - rsize, fys - rsize, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs + rsize, fys + rsize, fxs + r2, fys, ncol, thickness); - drawLineCanvas(dw, surface, cb, fxs + r2, fys, fxs + rsize, fys - rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - rsize, fys - rsize, fxs + rsize, fys - rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs + rsize, fys - rsize, fxs, fys + rsize, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs, fys + rsize, fxs - rsize, fys - rsize, ncol, thickness); } else if (shape == SHAPE_SHARP) { @@ -3268,9 +3301,17 @@ void drawMarkCanvas(draw_t *dw, SDL_Surface *surface, clipBox_t *cb, double fxs, drawLineCanvas(dw, surface, cb, fxs - r2, fys - rsize, fxs - r2, fys + rsize, ncol, thickness); drawLineCanvas(dw, surface, cb, fxs + r2, fys - rsize, fxs + r2, fys + rsize, ncol, thickness); } - else if (shape == SHAPE_FILLED) { + else if (shape == SHAPE_FILLING) { + + drawDotCanvas(dw, surface, cb, fxs, fys, (int) (rsize * 1.8), ncol, 0); + } + else if (shape == SHAPE_SYMBOL) { + + r2 = (double) rsize * 0.9; - drawDotCanvas(dw, surface, cb, fxs, fys, rsize * 2.0, ncol, 0); + drawLineCanvas(dw, surface, cb, fxs, fys - r2, fxs, fys + r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys + r2, fxs + r2, fys + r2, ncol, thickness); + drawLineCanvas(dw, surface, cb, fxs - r2, fys - r2, fxs + r2, fys - r2, ncol, thickness); } } diff --git a/pgui/gp/draw.h b/pgui/gp/draw.h index e669ed6..c090bcd 100644 --- a/pgui/gp/draw.h +++ b/pgui/gp/draw.h @@ -31,13 +31,15 @@ enum { enum { SHAPE_CIRCLE = 0, + SHAPE_STARLET, + SHAPE_HUBCAP, SHAPE_RECTANGLE, + SHAPE_SNOWFLAKE, SHAPE_TRIANGLE, - SHAPE_ASTERIX, - SHAPE_STAR, SHAPE_SHARP, SHAPE_COLUMN, - SHAPE_FILLED, + SHAPE_FILLING, + SHAPE_SYMBOL, }; enum { diff --git a/pgui/gp/edit.c b/pgui/gp/edit.c index 8f37293..3eceddf 100644 --- a/pgui/gp/edit.c +++ b/pgui/gp/edit.c @@ -96,7 +96,7 @@ char *utf8_insert_prev(char *s, const char *i) q = s + strlen(s); - n = strlen(i); + n = (int) strlen(i); r = s + n; do { @@ -155,7 +155,7 @@ const char *utf8_skip(const char *s, int n) return s; } -const char *utf8_skip_b(const char *s, int n) +const char *utf8_skip_byte(const char *s, int n) { char *r; @@ -167,6 +167,7 @@ const char *utf8_skip_b(const char *s, int n) else break; r = (char *) utf8_go_next(s); + n += (int) (s - r); s = r; } @@ -225,7 +226,7 @@ edit_t *editAlloc(draw_t *dw, scheme_t *sch) { edit_t *ed; - ed = calloc(1, sizeof(edit_t)); + ed = (edit_t *) calloc(1, sizeof(edit_t)); ed->dw = dw; ed->sch = sch; @@ -264,8 +265,8 @@ void editRaise(edit_t *ed, int id, const char *title, const char *text, int sx, ed->box_Y = ed->cur_Y; strcpy(ed->text, text); - ed->text_cur = ed->text + strlen(ed->text); + ed->text_cur = ed->text + strlen(ed->text); ed->list_fmt = ""; editBuild(ed, 0); @@ -397,7 +398,7 @@ void editEvent(edit_t *ed, int evno, int ex, int ey) if (ed->list_fmt[0] != 0) { - len = strlen(ed->text); + len = (int) strlen(ed->text); if (len > 4) { diff --git a/pgui/gp/edit.h b/pgui/gp/edit.h index f32c2a2..93f1838 100644 --- a/pgui/gp/edit.h +++ b/pgui/gp/edit.h @@ -82,7 +82,7 @@ char *utf8_insert_prev(char *s, const char *i); char *utf8_backspace(char *s); int utf8_length(const char *s); const char *utf8_skip(const char *s, int n); -const char *utf8_skip_b(const char *s, int n); +const char *utf8_skip_byte(const char *s, int n); edit_t *editAlloc(draw_t *dw, scheme_t *sch); void editClean(edit_t *ed); diff --git a/pgui/gp/gp.c b/pgui/gp/gp.c index 5e88ff7..abc5db5 100644 --- a/pgui/gp/gp.c +++ b/pgui/gp/gp.c @@ -44,7 +44,10 @@ #undef main -#define GP_FILE_DIR_MAX 4000 +#define GP_FILE_ENT_MAX 4000 + +#define GP_CONFIG_VERSION 17 +#define GP_CONFIG_FILE "gprc" enum { GP_TAKE_NONE = 0, @@ -54,12 +57,15 @@ enum { }; enum { - GP_COMBINE_NONE = 0, - GP_COMBINE_AXES_REMAP, - GP_COMBINE_NO_REMAP + GP_IDLE = 0, + GP_MOVING, + GP_SELECT_RANGE, + GP_SELECT_BOX, + GP_MENU, + GP_EDIT, }; -struct gp_struct { +struct gp_context { scheme_t *sch; lang_t *la; @@ -70,36 +76,38 @@ struct gp_struct { menu_t *mu; edit_t *ed; + Uint32 window_ID; + SDL_Window *window; SDL_Surface *fb; SDL_Surface *surface; - int window_ID; - char sbuf[4][READ_FILE_PATH_MAX]; char rcfile[READ_FILE_PATH_MAX]; char tempfile[READ_FILE_PATH_MAX]; - int done; + int quit; int stat; int active; int unfinished; int drawn; - int clock; + Uint32 clock; + Uint32 updated; + int idled; - int updated; int level; int ctrl_on; int shift_on; - int i_show_fps; - int i_frames; - int i_clocked; - int i_FPS; + Uint32 fps_clock; + + int fps_show; + int fps_frame; + int fps_value; int fullscreen; int hinting; @@ -113,112 +121,117 @@ struct gp_struct { int data_N; int grp_N; int line_N; + int blank_N; int screen_take; int screen_yank; int legend_drag; int data_box_drag; - int combine_on; + int combine_remap; int hover_box; + double resample_range[2]; + int resample_locked; + int layout_page_box; int layout_page_title_offset; int layout_menu_page_margin; int layout_menu_dir_margin; int layout_menu_dataset_margin; int layout_menu_dataset_minimal; + int layout_menu_resample_crop; struct dirent_stat sb; char cwd[READ_FILE_PATH_MAX]; - int cwd_ok; + int cwd_exist; - char d_names[GP_FILE_DIR_MAX][PLOT_STRING_MAX]; - char la_menu[GP_FILE_DIR_MAX * PLOT_STRING_MAX + 1]; + char d_names[GP_FILE_ENT_MAX][PLOT_STRING_MAX]; + char la_menu[GP_FILE_ENT_MAX * PLOT_STRING_MAX + 1]; }; -enum { - GP_IDLE = 0, - GP_MOVING, - GP_RANGE_SELECT, - GP_BOX_SELECT, - GP_MENU, - GP_EDIT, -}; +static int +gpGetBlankData(gpcon_t *gp) +{ + plot_t *pl = gp->pl; + read_t *rd = gp->rd; + + int N, lN, lN_MAX = 0, dN = 0; + + for (N = 0; N < PLOT_DATASET_MAX; ++N) { + + if (rd->data[N].format == FORMAT_BLANK_DATA) { + + dN = N; + break; + } + + if ( rd->data[N].format != FORMAT_NONE + && rd->data[N].column_N != 0) { + + lN = plotDataLength(pl, N); + + if (lN > lN_MAX) { + + lN_MAX = lN; + dN = N; + } + } + } + + return dN; +} -#ifndef _EMBED_GP static void -gpMakeHello(gp_t *gp) +gpMakeBlank(gpcon_t *gp, int length) { - const fval_t omul[] = { + read_t *rd = gp->rd; - 21.180, 25.120, 20.298, 42.448, 19.203, 72.868, 18.649, - 106.511, 19.393, 133.510, 22.521, 159.491, 26.570, 178.031, - 30.850, 190.678, 34.669, 198.980, 41.013, 186.502, 45.839, - 176.055, 49.991, 165.249, 54.311, 151.696, 65.768, 151.514, - 77.225, 151.332, 88.682, 151.150, 100.140, 150.968, 101.891, - 159.968, 104.920, 169.501, 110.001, 181.771, 117.909, 198.980, - 125.652, 182.521, 130.473, 168.671, 133.481, 156.518, 135.785, - 145.149, 137.191, 112.465, 136.247, 72.753, 134.526, 39.231, - 133.602, 25.120, 105.497, 25.120, 77.391, 25.120, 49.286, - 25.120, 21.180, 25.120, FP_NAN, FP_NAN, 32.487, 120.416, 41.887, - 125.997, 50.408, 127.691, 58.540, 125.820, 66.771, 120.710, - FP_NAN, FP_NAN, 90.832, 120.397, 100.879, 126.139, 109.671, - 128.016, 117.918, 126.115, 126.329, 120.519, FP_NAN, FP_NAN, - 51.817, 91.523, 66.133, 83.048, 79.760, 81.249, 92.873, 84.769, - 105.648, 92.251, FP_NAN, FP_NAN, 36.994, 25.848, 43.501, 32.639, - 50.371, 35.609, 58.851, 33.517, 70.189, 25.120, FP_NAN, FP_NAN, - 85.189, 25.120, 92.850, 33.737, 101.987, 36.883, 111.918, - 34.147, 121.963, 25.120, FP_NAN, FP_NAN, 134.434, 40.169, - 135.268, 39.659, 139.077, 39.450, 147.824, 41.521, 163.470, - 47.850, 175.241, 59.465, 176.895, 75.080, 177.196, 93.201, - 184.908, 112.335, 189.761, 118.670, 193.306, 123.087, 195.480, - 125.673, 196.219, 126.515, 196.803, 130.617, 194.349, 133.181, - 190.339, 133.762, 186.259, 131.917, 182.574, 127.680, 177.766, - 121.809, 172.436, 114.071, 167.183, 104.232, 164.575, 91.517, - 165.070, 78.686, 164.466, 67.214, 158.560, 58.576, 151.353, - 55.039, 143.859, 52.910, 137.973, 51.867, 135.590, 51.590, - FP_NAN, FP_NAN, -55.581, 25.377 - }; + int N, dN; - const int lN = sizeof(omul) / sizeof(omul[0]) / 2; + dN = gp->blank_N; - int N, dN = 0, pN = 1; + if (rd->data[dN].format != FORMAT_BLANK_DATA) { - plotDataAlloc(gp->pl, dN, 2, lN + 1); + dN = gpGetBlankData(gp); + } + + if (rd->data[dN].format != FORMAT_BLANK_DATA) { + + dN = readGetFreeData(rd); + + if (dN < 0) { - for (N = 0; N < lN; ++N) { + ERROR("Unable to get free dataset\n"); + return ; + } + } - plotDataInsert(gp->pl, dN, omul + gp->pl->data[dN].column_N * N); + if (length < 1 || length > 262144000) { + + ERROR("Blank dataset length %i is out of range\n", length); + return ; } - gp->rd->data[dN].format = FORMAT_PLAIN_TEXT; - gp->rd->data[dN].column_N = 2; - gp->rd->data[dN].file[0] = 0; - gp->rd->files_N = 1; - gp->rd->bind_N = dN; + plotDataAlloc(gp->pl, dN, 1, length + 1); - gp->rd->page_N = pN; - gp->rd->figure_N = -1; + rd->data[dN].row[0] = (fval_t) 0.; - gp->rd->page[pN].busy = 1; + for (N = 0; N < length; ++N) { - strcpy(gp->rd->page[pN].title, "Hello, I am Omul"); - strcpy(gp->rd->page[pN].fig[0].label, "Omul"); + plotDataInsert(gp->pl, dN, rd->data[dN].row); + } + + rd->data[dN].format = FORMAT_BLANK_DATA; + rd->data[dN].column_N = 1; + rd->data[dN].length_N = length; + rd->data[dN].file[0] = 0; - gp->rd->page[pN].fig[0].busy = 1; - gp->rd->page[pN].fig[0].drawing = FIGURE_DRAWING_LINE; - gp->rd->page[pN].fig[0].width = 6; - gp->rd->page[pN].fig[0].dN = dN; - gp->rd->page[pN].fig[0].cX = 0; - gp->rd->page[pN].fig[0].cY = 1; - gp->rd->page[pN].fig[0].aX = 0; - gp->rd->page[pN].fig[0].aY = 1; + gp->blank_N = dN; } -#endif /* _EMBED_GP */ static void -gpFileGetPath(gp_t *gp) +gpFileGetPath(gpcon_t *gp) { char *home; @@ -228,7 +241,7 @@ gpFileGetPath(gp_t *gp) if (home != NULL) { legacy_ACP_to_UTF8(gp->rcfile, home, READ_FILE_PATH_MAX); - strcat(gp->rcfile, "/_gprc"); + strcat(gp->rcfile, "/_" GP_CONFIG_FILE); } #else /* _WINDOWS */ @@ -237,23 +250,23 @@ gpFileGetPath(gp_t *gp) if (home != NULL) { strcpy(gp->rcfile, home); - strcat(gp->rcfile, "/.gprc"); + strcat(gp->rcfile, "/." GP_CONFIG_FILE); } #endif } static void -gpFileGetLocal(gp_t *gp) +gpFileGetLocal(gpcon_t *gp) { #ifdef _WINDOWS - strcpy(gp->rcfile, "_gprc"); + strcpy(gp->rcfile, "_" GP_CONFIG_FILE); #else /* _WINDOWS */ - strcpy(gp->rcfile, ".gprc"); + strcpy(gp->rcfile, "." GP_CONFIG_FILE); #endif } static void -gpDefaultFile(gp_t *gp) +gpDefaultFile(gpcon_t *gp) { FILE *fd; @@ -282,6 +295,7 @@ gpDefaultFile(gp_t *gp) "density 40\n" "transparency 1\n" "precision 9\n" + "hexadecimal 1\n" "timecol -1\n" "shortfilename 1\n" "fastdraw 200\n" @@ -298,7 +312,7 @@ gpDefaultFile(gp_t *gp) } static void -gpWriteFile(gp_t *gp) +gpWriteFile(gpcon_t *gp) { draw_t *dw = gp->dw; plot_t *pl = gp->pl; @@ -324,7 +338,10 @@ gpWriteFile(gp_t *gp) fprintf(fd, "chunk %i\n", rd->chunk); fprintf(fd, "timeout %i\n", rd->timeout); - SDL_GetWindowSize(gp->window, &rd->window_size_x, &rd->window_size_y); + if (gp->window != NULL) { + + SDL_GetWindowSize(gp->window, &rd->window_size_x, &rd->window_size_y); + } fprintf(fd, "windowsize %i %i\n", rd->window_size_x, rd->window_size_y); fprintf(fd, "language %i\n", rd->language); @@ -343,6 +360,7 @@ gpWriteFile(gp_t *gp) fprintf(fd, "density %i\n", pl->mark_density); fprintf(fd, "transparency %i\n", pl->transparency); fprintf(fd, "precision %i\n", pl->fprecision); + fprintf(fd, "hexadecimal %i\n", pl->fhexadecimal); fprintf(fd, "timecol %i\n", rd->timecol); fprintf(fd, "shortfilename %i\n", rd->shortfilename); fprintf(fd, "fastdraw %i\n", rd->fastdraw); @@ -367,20 +385,19 @@ gpFileExist(const char *file) } static int -gpScreenLength(plot_t *pl) +gpFullLength(plot_t *pl) { return pl->screen.max_x / pl->layout_font_long; } static void -gpTextLeftCrop(plot_t *pl, char *sbuf, const char *text, int margin) +gpTextLeftCrop(char *sbuf, const char *text, int allowed) { - int length, allowed; + int length; - allowed = gpScreenLength(pl) - margin; length = utf8_length(text); - if (length > (allowed - 1)) { + if (length > allowed - 1) { text = utf8_skip(text, length - (allowed - 1)); @@ -393,9 +410,26 @@ gpTextLeftCrop(plot_t *pl, char *sbuf, const char *text, int margin) } static void -gpTextSepFill(char *sbuf, int len) +gpTextFull(plot_t *pl, char *sbuf, const char *text, int margin) +{ + gpTextLeftCrop(sbuf, text, gpFullLength(pl) - margin); +} + +static void +gpTextSpaceAdd(char *sbuf, int len) +{ + sbuf += strlen(sbuf); + + memset(sbuf, ' ', len); + + sbuf[len] = 0; +} + +static void +gpTextSepFull(char *sbuf, int len) { memset(sbuf, '-', len); + sbuf[len] = 0; } @@ -424,33 +458,36 @@ gpTextFloat(plot_t *pl, char *sbuf, double val) } static void -gpScreenLayout(gp_t *gp) +gpScreenLayout(gpcon_t *gp) { plot_t *pl = gp->pl; menu_t *mu = gp->mu; edit_t *ed = gp->ed; - mu->screen.min_x = 0; - mu->screen.max_x = gp->surface->w - 1; - mu->screen.min_y = 0; - mu->screen.max_y = gp->surface->h - 1; + if (gp->surface != NULL) { + + mu->screen.min_x = 0; + mu->screen.max_x = gp->surface->w - 1; + mu->screen.min_y = 0; + mu->screen.max_y = gp->surface->h - 1; - ed->screen.min_x = 0; - ed->screen.max_x = gp->surface->w - 1; - ed->screen.min_y = 0; - ed->screen.max_y = gp->surface->h - 1; + ed->screen.min_x = 0; + ed->screen.max_x = gp->surface->w - 1; + ed->screen.min_y = 0; + ed->screen.max_y = gp->surface->h - 1; - pl->screen.min_x = 0; - pl->screen.max_x = gp->surface->w - 1; - pl->screen.min_y = gp->layout_page_box; - pl->screen.max_y = gp->surface->h - 1; + pl->screen.min_x = 0; + pl->screen.max_x = gp->surface->w - 1; + pl->screen.min_y = gp->layout_page_box; + pl->screen.max_y = gp->surface->h - 1; + } menuLayout(mu); editLayout(ed); } static void -gpFontLayout(gp_t *gp) +gpFontLayout(gpcon_t *gp) { plot_t *pl = gp->pl; menu_t *mu = gp->mu; @@ -469,10 +506,11 @@ gpFontLayout(gp_t *gp) gp->layout_menu_dir_margin = 36; gp->layout_menu_dataset_margin = 16; gp->layout_menu_dataset_minimal = 42; + gp->layout_menu_resample_crop = 32; } static void -gpFontHinting(gp_t *gp) +gpFontHinting(gpcon_t *gp) { plot_t *pl = gp->pl; @@ -491,7 +529,7 @@ gpFontHinting(gp_t *gp) } static void -gpFontToggle(gp_t *gp, int toggle, int font_pt) +gpFontToggle(gpcon_t *gp, int toggle, int font_pt) { plot_t *pl = gp->pl; int style; @@ -519,7 +557,7 @@ gpFontToggle(gp_t *gp, int toggle, int font_pt) } static void -gpMakePageMenu(gp_t *gp) +gpMakePageMenu(gpcon_t *gp) { read_t *rd = gp->rd; char *la = gp->la_menu; @@ -528,7 +566,7 @@ gpMakePageMenu(gp_t *gp) do { if (rd->page[pN].busy != 0) { - gpTextLeftCrop(gp->pl, gp->sbuf[1], rd->page[pN].title, + gpTextFull(gp->pl, gp->sbuf[1], rd->page[pN].title, gp->layout_menu_page_margin); sprintf(gp->sbuf[0], "%3d %s", pN, gp->sbuf[1]); @@ -548,7 +586,7 @@ gpMakePageMenu(gp_t *gp) } static int -gpFileIsGP(gp_t *gp, const char *file) +gpFileIsGP(const char *file) { int rc = 0; @@ -564,7 +602,7 @@ gpFileIsGP(gp_t *gp, const char *file) #ifdef _LEGACY static int -legacy_FileIsBAT(gp_t *gp, const char *file) +legacy_FileIsBAT(const char *file) { int rc = 0; @@ -608,7 +646,7 @@ legacy_DirName(char *path) } static void -legacy_FileOpenBAT(gp_t *gp, const char *file, int fromUI) +legacy_FileOpenBAT(gpcon_t *gp, const char *file, int fromUI) { FILE *fd; char *s, *path, *argv[2]; @@ -627,7 +665,8 @@ legacy_FileOpenBAT(gp_t *gp, const char *file, int fromUI) s = strtok(s, " \t"); - if (s != NULL && (strcmp(s, "grm") == 0 || strcmp(s, "GRM") == 0)) { + if (s != NULL && ( strstr(s, "grm") != NULL + || strstr(s, "GRM") != NULL)) { if ((argv[0] = strtok(NULL, " \t")) != NULL) { @@ -655,24 +694,24 @@ legacy_FileOpenBAT(gp_t *gp, const char *file, int fromUI) #endif /* _LEGACY */ static void -gpUnifiedFileOpen(gp_t *gp, const char *file, int fromUI) +gpUnifiedFileOpen(gpcon_t *gp, const char *file, int fromUI) { read_t *rd = gp->rd; - if (gpFileIsGP(gp, file) != 0) { + if (gpFileIsGP(file) != 0) { readConfigGP(rd, file, fromUI); } #ifdef _LEGACY - else if (legacy_FileIsBAT(gp, file) != 0) { + else if (legacy_FileIsBAT(file) != 0) { legacy_FileOpenBAT(gp, file, fromUI); } #endif /* _LEGACY */ else { - sprintf(gp->sbuf[0], "load 0 0 text \"%s\"\n" + sprintf(gp->sbuf[0], "load 0 0 csv \"%s\"\n" "mkpages -2\n", file); readConfigIN(rd, gp->sbuf[0], fromUI); @@ -680,35 +719,35 @@ gpUnifiedFileOpen(gp_t *gp, const char *file, int fromUI) } static int -gpDirWalk(gp_t *gp, int dir_N, int revert); +gpDirWalk(gpcon_t *gp, int dir_N, int revert); static void -gpMakeDirMenu(gp_t *gp) +gpMakeDirMenu(gpcon_t *gp) { char sfmt[PLOT_STRING_MAX]; char *la = gp->la_menu; int len, pad, N, kmg; - len = gpScreenLength(gp->pl) - gp->layout_menu_dir_margin; + len = gpFullLength(gp->pl) - gp->layout_menu_dir_margin; if (dirent_open(&gp->sb, gp->cwd) == ENT_OK) { - gp->cwd_ok = 1; + gp->cwd_exist = 1; } else { gpDirWalk(gp, 2, 1); - gp->cwd_ok = (dirent_open(&gp->sb, gp->cwd) == ENT_OK) ? 1 : 0; + gp->cwd_exist = (dirent_open(&gp->sb, gp->cwd) == ENT_OK) ? 1 : 0; } - gpTextLeftCrop(gp->pl, gp->sbuf[1], gp->cwd, gp->layout_menu_dir_margin); + gpTextFull(gp->pl, gp->sbuf[1], gp->cwd, gp->layout_menu_dir_margin); sprintf(gp->sbuf[0], "[%s]", gp->sbuf[1]); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; - gpTextSepFill(gp->sbuf[0], len + 26); + gpTextSepFull(gp->sbuf[0], len + 26); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; @@ -719,7 +758,7 @@ gpMakeDirMenu(gp_t *gp) strcpy(gp->d_names[0], "/.."); N = 1; - if (gp->cwd_ok != 0) { + if (gp->cwd_exist != 0) { while (dirent_read(&gp->sb) == ENT_OK) { @@ -731,7 +770,7 @@ gpMakeDirMenu(gp_t *gp) continue; } - if (N >= GP_FILE_DIR_MAX) + if (N >= GP_FILE_ENT_MAX) break; sprintf(gp->sbuf[0], "/%s", gp->sb.name); @@ -740,7 +779,7 @@ gpMakeDirMenu(gp_t *gp) strcpy(gp->d_names[N], gp->sbuf[0]); - gpTextLeftCrop(gp->pl, gp->sbuf[1], gp->sb.name, + gpTextFull(gp->pl, gp->sbuf[1], gp->sb.name, gp->layout_menu_dir_margin); pad = len - utf8_length(gp->sbuf[1]); @@ -763,7 +802,7 @@ gpMakeDirMenu(gp_t *gp) if (gp->sb.ntype == ENT_TYPE_REGULAR) { - if (N >= GP_FILE_DIR_MAX) + if (N >= GP_FILE_ENT_MAX) break; sprintf(gp->sbuf[0], "%s", gp->sb.name); @@ -782,7 +821,7 @@ gpMakeDirMenu(gp_t *gp) ++kmg; } - gpTextLeftCrop(gp->pl, gp->sbuf[1], gp->sb.name, + gpTextFull(gp->pl, gp->sbuf[1], gp->sb.name, gp->layout_menu_dir_margin); pad = len - utf8_length(gp->sbuf[1]); @@ -807,7 +846,7 @@ gpMakeDirMenu(gp_t *gp) } static int -gpDirWalk(gp_t *gp, int dir_N, int revert) +gpDirWalk(gpcon_t *gp, int dir_N, int revert) { const char *file = gp->d_names[dir_N - 2]; char *eol; @@ -826,7 +865,7 @@ gpDirWalk(gp_t *gp, int dir_N, int revert) } else if (dir_N == 2) { - if (gp->cwd[0] != 0 && gp->cwd_ok != 0) { + if (gp->cwd[0] != 0 && gp->cwd_exist != 0) { eol = gp->cwd + strlen(gp->cwd) - 1; @@ -900,80 +939,99 @@ gpDirWalk(gp_t *gp, int dir_N, int revert) return walk; } -static void -gpInsertColumn(gp_t *gp, char **la, int dN, int cN) +static const char * +gpSymDatasetFormat(gpcon_t *gp, int dN) { read_t *rd = gp->rd; + const char *sym; - sprintf(gp->sbuf[0], "[%3i] %.75s", cN, rd->data[dN].label[cN]); + switch (rd->data[dN].format) { - if (rd->data[dN].hint[cN] == DATA_HINT_FLOAT) { + case FORMAT_NONE: + sym = "NONE "; + break; - strcat(gp->sbuf[0], " (DEC)"); - } - else if (rd->data[dN].hint[cN] == DATA_HINT_HEX) { + case FORMAT_BLANK_DATA: + sym = "BLANK "; + break; - strcat(gp->sbuf[0], " (HEX)"); - } - else if (rd->data[dN].hint[cN] == DATA_HINT_OCT) { + case FORMAT_STUB_DATA: + sym = "STUB "; + break; - strcat(gp->sbuf[0], " (OCT)"); - } - else { - strcat(gp->sbuf[0], " "); + case FORMAT_TEXT_STDIN: + sym = "STDIN "; + break; + + case FORMAT_TEXT_CSV: + sym = "CSV "; + break; + + case FORMAT_BINARY_FP_32: + sym = "FP32 "; + break; + + case FORMAT_BINARY_FP_64: + sym = "FP64 "; + break; + + default: + sym = "LEGACY"; + break; } - strcpy(*la, gp->sbuf[0]); - *la += strlen(*la) + 1; + return sym; } static void -gpInsertDataset(gp_t *gp, char **la, int dN) +gpMenuInsertColumn(gpcon_t *gp, int dN, int cN) { read_t *rd = gp->rd; - char *file, *sformat; - file = rd->data[dN].file; - file = (file[0] == '.' && file[1] == '/') - ? file + 2 : file; + sprintf(gp->sbuf[0], "[%3i] %.75s", cN, rd->data[dN].label[cN]); - gpTextLeftCrop(gp->pl, gp->sbuf[1], file, gp->layout_menu_dataset_margin); + switch (rd->data[dN].hint[cN]) { - if (rd->data[dN].format == FORMAT_NONE) { + case DATA_HINT_FLOAT: + strcat(gp->sbuf[0], " (DEC)"); + break; - sformat = "NONE "; - } - else if (rd->data[dN].format == FORMAT_PLAIN_STDIN) { + case DATA_HINT_HEX: + strcat(gp->sbuf[0], " (HEX)"); + break; - sformat = "STDIN "; - } - else if (rd->data[dN].format == FORMAT_PLAIN_TEXT) { + case DATA_HINT_OCT: + strcat(gp->sbuf[0], " (OCT)"); + break; - sformat = "TEXT "; + default: + strcat(gp->sbuf[0], " "); + break; } - else if (rd->data[dN].format == FORMAT_BINARY_FLOAT) { +} - sformat = "FLOAT "; - } - else if (rd->data[dN].format == FORMAT_BINARY_DOUBLE) { +static void +gpMenuInsertDataset(gpcon_t *gp, int dN) +{ + read_t *rd = gp->rd; + const char *file, *symtype; - sformat = "DOUBLE"; - } - else { - sformat = "LEGACY"; - } + file = rd->data[dN].file; + file = (file[0] == '.' && file[1] == '/') ? file + 2 : file; - sprintf(gp->sbuf[0], "[%2i] %6s %s", dN, sformat, gp->sbuf[1]); + gpTextFull(gp->pl, gp->sbuf[1], file, gp->layout_menu_dataset_margin); - strcpy(*la, gp->sbuf[0]); - *la += strlen(*la) + 1; + symtype = gpSymDatasetFormat(gp, dN); + + sprintf(gp->sbuf[0], "[%2i] %6s %s", dN, symtype, gp->sbuf[1]); } static void -gpMakeColumnSelectMenu(gp_t *gp, int dN) +gpMakeColumnSelectMenu(gpcon_t *gp, int dN) { read_t *rd = gp->rd; char *la = gp->la_menu; + int sN, cN = 0; sprintf(gp->sbuf[0], "[%3i] ", -1); @@ -985,37 +1043,40 @@ gpMakeColumnSelectMenu(gp_t *gp, int dN) if (cN < rd->data[dN].column_N) { - gpInsertColumn(gp, &la, dN, cN); + gpMenuInsertColumn(gp, dN, cN); + + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; } else { sN = cN - rd->data[dN].column_N; sprintf(gp->sbuf[0], "[%3i] %c ", cN, - " TFSEPRAXHDCBLM?" [gp->pl->data[dN].sub[sN].busy]); + " TFSEPRAXHDIBLM?" [gp->pl->data[dN].sub[sN].busy]); if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_TIME_MEDIAN) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i, %i)", - gp->pl->data[dN].sub[sN].op.median.column_1, + gp->pl->data[dN].sub[sN].op.median.column_X, gp->pl->data[dN].sub[sN].op.median.length, gp->pl->data[dN].sub[sN].op.median.unwrap); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_DATA_MEDIAN) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i)", - gp->pl->data[dN].sub[sN].op.median.column_1, - gp->pl->data[dN].sub[sN].op.median.column_2); + gp->pl->data[dN].sub[sN].op.median.column_X, + gp->pl->data[dN].sub[sN].op.median.column_Y); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %.2E, %.2E)", - gp->pl->data[dN].sub[sN].op.scale.column_1, + gp->pl->data[dN].sub[sN].op.scale.column_X, gp->pl->data[dN].sub[sN].op.scale.scale, gp->pl->data[dN].sub[sN].op.scale.offset); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_RESAMPLE) { - sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i) (%i, %i, %i)", + sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i, %i, %i)", gp->pl->data[dN].sub[sN].op.resample.column_X, gp->pl->data[dN].sub[sN].op.resample.in_data_N, gp->pl->data[dN].sub[sN].op.resample.in_column_X, @@ -1034,14 +1095,15 @@ gpMakeColumnSelectMenu(gp_t *gp, int dN) || gp->pl->data[dN].sub[sN].busy == SUBTRACT_BINARY_HYPOTENUSE) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i)", - gp->pl->data[dN].sub[sN].op.binary.column_1, - gp->pl->data[dN].sub[sN].op.binary.column_2); + gp->pl->data[dN].sub[sN].op.binary.column_X, + gp->pl->data[dN].sub[sN].op.binary.column_Y); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_DIFFERENCE || gp->pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_CUMULATIVE) { - sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i)", - gp->pl->data[dN].sub[sN].op.filter.column_1); + sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i)", + gp->pl->data[dN].sub[sN].op.filter.column_X, + gp->pl->data[dN].sub[sN].op.filter.column_Y); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_BITMASK) { @@ -1051,19 +1113,19 @@ gpMakeColumnSelectMenu(gp_t *gp, int dN) bf[1] = bf[1] >> 8; sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i, %i)", - gp->pl->data[dN].sub[sN].op.filter.column_1, + gp->pl->data[dN].sub[sN].op.filter.column_Y, (int) bf[0], (int) bf[1]); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_LOW_PASS) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %.2E)", - gp->pl->data[dN].sub[sN].op.filter.column_1, + gp->pl->data[dN].sub[sN].op.filter.column_Y, gp->pl->data[dN].sub[sN].op.filter.gain); } else if (gp->pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_MEDIAN) { sprintf(gp->sbuf[0] + strlen(gp->sbuf[0]), "(%i, %i)", - gp->pl->data[dN].sub[sN].op.median.column_1, + gp->pl->data[dN].sub[sN].op.median.column_Y, (int) gp->pl->data[dN].sub[sN].op.median.length); } @@ -1078,22 +1140,25 @@ gpMakeColumnSelectMenu(gp_t *gp, int dN) } static void -gpMakeDatasetSelectMenu(gp_t *gp) +gpMakeDatasetSelectMenu(gpcon_t *gp) { char *la = gp->la_menu; - int dN = 0, len, fnlen, fnlen_max; + int dN = 0, len, fspace; - len = gpScreenLength(gp->pl) - gp->layout_menu_dataset_margin; - len = (len < gp->layout_menu_dataset_minimal) - ? gp->layout_menu_dataset_minimal : len; + do { + gpMenuInsertDataset(gp, dN); - fnlen_max = 0; + len = utf8_length(gp->sbuf[0]); - do { - gpInsertDataset(gp, &la, dN); + if (len < gp->layout_menu_dataset_minimal) { + + fspace = gp->layout_menu_dataset_minimal - len; + + gpTextSpaceAdd(gp->sbuf[0], fspace); + } - fnlen = utf8_length(gp->sbuf[0]); - fnlen_max = (fnlen_max < fnlen) ? fnlen : fnlen_max; + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; dN += 1; @@ -1102,32 +1167,23 @@ gpMakeDatasetSelectMenu(gp_t *gp) } while (1); - gpTextSepFill(gp->sbuf[1], (fnlen_max > len) ? fnlen_max : len); - - strcpy(la, gp->sbuf[1]); - la += strlen(la) + 1; - *la = 0; } static void -gpMakeDatasetMenu(gp_t *gp) +gpMakeDatasetMenu(gpcon_t *gp) { plot_t *pl = gp->pl; read_t *rd = gp->rd; char *la = gp->la_menu; + int N, cN, gN, dN, len, fnlen, unwrap, opdata; int mbUSAGE, mbRAW, mbCACHE, lzPC; - len = gpScreenLength(gp->pl) - gp->layout_menu_dataset_margin; + len = gpFullLength(gp->pl) - gp->layout_menu_dataset_margin; len = (len < gp->layout_menu_dataset_minimal) ? gp->layout_menu_dataset_minimal : len; - if (len < 42) { - - len = 42; - } - dN = gp->data_N; if (rd->data[dN].format == FORMAT_NONE) { @@ -1144,11 +1200,14 @@ gpMakeDatasetMenu(gp_t *gp) gp->data_N = dN; } - gpInsertDataset(gp, &la, dN); + gpMenuInsertDataset(gp, dN); + + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; fnlen = utf8_length(gp->sbuf[0]); - gpTextSepFill(gp->sbuf[1], (fnlen > len) ? fnlen : len); + gpTextSepFull(gp->sbuf[1], (fnlen > len) ? fnlen : len); strcpy(la, gp->sbuf[1]); la += strlen(la) + 1; @@ -1194,11 +1253,14 @@ gpMakeDatasetMenu(gp_t *gp) strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; - sprintf(gp->sbuf[0], gp->la->dataset_menu[2], (unwrap != 0) ? " X " : " "); + sprintf(gp->sbuf[0], gp->la->dataset_menu[2], + (unwrap == UNWRAP_OVERFLOW) ? " X " + : (unwrap == UNWRAP_BURST) ? " S " : " "); + strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; - sprintf(gp->sbuf[0], gp->la->dataset_menu[3], (opdata != 0) ? " X " : " "); + sprintf(gp->sbuf[0], gp->la->dataset_menu[3], (opdata == 0) ? " " : " X "); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; @@ -1206,9 +1268,9 @@ gpMakeDatasetMenu(gp_t *gp) strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; - mbUSAGE = plotDataMemoryUsage(pl, dN) / 1048576UL; - mbRAW = plotDataMemoryUncompressed(pl, dN) / 1048576UL; - mbCACHE = plotDataMemoryCached(pl, dN) / 1048576UL; + mbUSAGE = (int) (plotDataMemoryUsage(pl, dN) / 1048576U); + mbRAW = (int) (plotDataMemoryUncompressed(pl, dN) / 1048576U); + mbCACHE = (int) (plotDataMemoryCached(pl, dN) / 1048576U); lzPC = (mbRAW != 0) ? 100U * mbUSAGE / mbRAW : 0; @@ -1228,7 +1290,10 @@ gpMakeDatasetMenu(gp_t *gp) while (cN < rd->data[dN].column_N) { - gpInsertColumn(gp, &la, dN, cN); + gpMenuInsertColumn(gp, dN, cN); + + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; cN += 1; } @@ -1237,7 +1302,7 @@ gpMakeDatasetMenu(gp_t *gp) } static void -gpMakeConfigurationMenu(gp_t *gp) +gpMakeConfigurationMenu(gpcon_t *gp) { read_t *rd = gp->rd; char *eol, *la = gp->la_menu; @@ -1251,14 +1316,14 @@ gpMakeConfigurationMenu(gp_t *gp) ERROR("fopen(\"%s\"): %s\n", gp->rcfile, strerror(errno)); } else { - gpTextLeftCrop(gp->pl, gp->sbuf[1], gp->rcfile, gp->layout_menu_page_margin); + gpTextFull(gp->pl, gp->sbuf[1], gp->rcfile, gp->layout_menu_page_margin); sprintf(gp->sbuf[0], "[%s]", gp->sbuf[1]); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; - gpTextSepFill(gp->sbuf[1], utf8_length(gp->sbuf[0])); + gpTextSepFull(gp->sbuf[1], utf8_length(gp->sbuf[0])); strcpy(la, gp->sbuf[1]); la += strlen(la) + 1; @@ -1286,7 +1351,7 @@ gpMakeConfigurationMenu(gp_t *gp) line_N++; - if (line_N >= GP_FILE_DIR_MAX - 2) + if (line_N >= GP_FILE_ENT_MAX - 2) break; } } @@ -1309,7 +1374,7 @@ gpMakeConfigurationMenu(gp_t *gp) } static void -gpWriteNewConfiguration(gp_t *gp) +gpWriteNewConfiguration(gpcon_t *gp) { FILE *fd; int line_N; @@ -1333,7 +1398,7 @@ gpWriteNewConfiguration(gp_t *gp) line_N++; - if (line_N >= GP_FILE_DIR_MAX) + if (line_N >= GP_FILE_ENT_MAX) break; } while (1); @@ -1343,14 +1408,89 @@ gpWriteNewConfiguration(gp_t *gp) } static void -gpMakeAboutMenu(gp_t *gp) +gpMakeResampleMenu(gpcon_t *gp) +{ + plot_t *pl = gp->pl; + read_t *rd = gp->rd; + char *la = gp->la_menu; + + const char *file, *symtype; + double tstep; + int lN, dN; + + dN = gp->blank_N; + + if (rd->data[dN].format == FORMAT_NONE) { + + dN = gpGetBlankData(gp); + + gp->blank_N = dN; + } + + file = rd->data[dN].file; + file = (file[0] == '.' && file[1] == '/') ? file + 2 : file; + + gpTextLeftCrop(gp->sbuf[0], file, gp->layout_menu_resample_crop); + + symtype = gpSymDatasetFormat(gp, dN); + + sprintf(gp->sbuf[1], "%i %6s %s", dN, symtype, gp->sbuf[0]); + + sprintf(gp->sbuf[0], gp->la->resample_menu[0], gp->sbuf[1]); + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + lN = (rd->data[dN].format == FORMAT_BLANK_DATA) + ? rd->data[dN].length_N : plotDataLength(pl, dN); + + sprintf(gp->sbuf[0], gp->la->resample_menu[1], lN); + + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + gpTextFloat(pl, gp->sbuf[2], gp->resample_range[0]); + gpTextFloat(pl, gp->sbuf[1], gp->resample_range[1]); + + strcat(gp->sbuf[2], " "); + strcat(gp->sbuf[2], gp->sbuf[1]); + + sprintf(gp->sbuf[0], gp->la->resample_menu[2], gp->sbuf[2]); + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + tstep = (gp->resample_range[1] - gp->resample_range[0]) / (double) (lN - 1); + + gpTextFloat(pl, gp->sbuf[3], tstep); + + sprintf(gp->sbuf[0], gp->la->resample_menu[3], gp->sbuf[3]); + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + sprintf(gp->sbuf[0], gp->la->resample_menu[4], + (pl->interpolation == 0) ? "NEAREST" : "LINEAR"); + + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + sprintf(gp->sbuf[0], gp->la->resample_menu[5], pl->defungap); + strcpy(la, gp->sbuf[0]); + la += strlen(la) + 1; + + strcpy(la, gp->la->resample_menu[6]); + la += strlen(la) + 1; + + *la = 0; +} + +static void +gpMakeAboutMenu(gpcon_t *gp) { char *la = gp->la_menu; strcpy(la, "Graph Plotter is a tool to analyse numerical data"); la += strlen(la) + 1; - gpTextSepFill(gp->sbuf[0], 54); + gpTextSepFull(gp->sbuf[0], 54); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; @@ -1373,7 +1513,7 @@ gpMakeAboutMenu(gp_t *gp) SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL); la += strlen(la) + 1; - gpTextSepFill(gp->sbuf[0], 54); + gpTextSepFull(gp->sbuf[0], 54); strcpy(la, gp->sbuf[0]); la += strlen(la) + 1; @@ -1388,7 +1528,7 @@ gpMakeAboutMenu(gp_t *gp) } static void -gpTakeScreen(gp_t *gp) +gpTakeScreen(gpcon_t *gp) { if (gp->screen_take == GP_TAKE_PNG) { @@ -1399,16 +1539,20 @@ gpTakeScreen(gp_t *gp) } else if (gp->screen_take == GP_TAKE_SVG) { - svgClose((svg_t *) gp->surface->userdata); - gp->surface->userdata = NULL; + if (gp->surface->userdata != NULL) { - ERROR("Figure was saved to \"%s\"\n", gp->tempfile); + svgClose((svg_t *) gp->surface->userdata); + gp->surface->userdata = NULL; + + ERROR("Figure was saved to \"%s\"\n", gp->tempfile); + } } else if (gp->screen_take == GP_TAKE_CSV) { - plotFigureExportCSV(gp->pl, gp->tempfile); + if (plotFigureExportCSV(gp->pl, gp->tempfile) == 0) { - ERROR("CSV table was saved to \"%s\"\n", gp->tempfile); + ERROR("CSV table was saved to \"%s\"\n", gp->tempfile); + } } gp->screen_take = GP_TAKE_NONE; @@ -1437,7 +1581,7 @@ legacy_SetClipboard(SDL_Surface *surface) SDL_SaveBMP_RW(surface, rwops, 0); SDL_RWseek(rwops, 0UL, RW_SEEK_END); - length = SDL_RWtell(rwops); + length = (long) SDL_RWtell(rwops); SDL_RWclose(rwops); @@ -1463,7 +1607,7 @@ legacy_SetClipboard(SDL_Surface *surface) #endif /* _WINDOWS */ static void -gpYankScreen(gp_t *gp) +gpYankScreen(gpcon_t *gp) { if (gp->screen_yank == 1) { @@ -1477,7 +1621,7 @@ gpYankScreen(gp_t *gp) static void -gpMenuHandle(gp_t *gp, int menu_N, int item_N) +gpMenuHandle(gpcon_t *gp, int menu_N, int item_N) { draw_t *dw = gp->dw; plot_t *pl = gp->pl; @@ -1485,6 +1629,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) menu_t *mu = gp->mu; edit_t *ed = gp->ed; + double fmin, fmax; int N, nAX, nAY; if (menu_N == 1) { @@ -1529,7 +1674,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 2: - sprintf(gp->sbuf[0], "%s/g%if%i.png", rd->screenpath, + sprintf(gp->sbuf[0], "%sg%if%i.png", rd->screenpath, rd->page_N, gp->pl->legend_N); N = 1; @@ -1542,7 +1687,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; } - sprintf(gp->sbuf[0], "%s/g%if%i_%i.png", rd->screenpath, + sprintf(gp->sbuf[0], "%sg%if%i_%i.png", rd->screenpath, rd->page_N, gp->pl->legend_N, N); N++; @@ -1557,14 +1702,17 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 3: - if (gp->fullscreen) { + if (gp->window != NULL) { - SDL_SetWindowFullscreen(gp->window, SDL_WINDOW_RESIZABLE); - gp->fullscreen = 0; - } - else { - SDL_SetWindowFullscreen(gp->window, SDL_WINDOW_FULLSCREEN_DESKTOP); - gp->fullscreen = 1; + if (gp->fullscreen != 0) { + + SDL_SetWindowFullscreen(gp->window, SDL_WINDOW_RESIZABLE); + gp->fullscreen = 0; + } + else { + SDL_SetWindowFullscreen(gp->window, SDL_WINDOW_FULLSCREEN_DESKTOP); + gp->fullscreen = 1; + } } break; @@ -1625,7 +1773,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) menuSelect(mu, rd->page_N); mu->hidden_N[0] = rd->page_N - 1; - gp->combine_on = GP_COMBINE_NONE; + gp->combine_remap = 0; gp->stat = GP_MENU; } @@ -1640,7 +1788,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) menuSelect(mu, rd->page_N); mu->hidden_N[0]= rd->page_N - 1; - gp->combine_on = GP_COMBINE_AXES_REMAP; + gp->combine_remap = 1; gp->stat = GP_MENU; } @@ -1655,7 +1803,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) menuSelect(mu, rd->page_N); mu->hidden_N[0] = rd->page_N - 1; - gp->combine_on = GP_COMBINE_NO_REMAP; + gp->combine_remap = 2; gp->stat = GP_MENU; } @@ -1673,6 +1821,9 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (pl->slice_on == 0) { pl->slice_on = 1; + pl->slice_mode_N = 0; + pl->pick_on = 0; + pl->slice_axis_N = pl->hover_axis; plotSliceTrack(pl, gp->cur_X, gp->cur_Y); @@ -1682,30 +1833,25 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) pl->slice_on = 0; pl->slice_mode_N = 0; + pl->pick_on = 0; } break; case 12: - if (pl->axis[PLOT_AXES_MAX - 1].compact != 0) { - - for (N = 0; N < PLOT_AXES_MAX; ++N) - pl->axis[N].compact = 0; - } - else { - for (N = 0; N < PLOT_AXES_MAX; ++N) - pl->axis[N].compact = 1; - } - break; + if (pl->pick_on == 0) { - case 13: - if (pl->axis[0].exponential != 0) { + pl->slice_on = 0; + pl->slice_mode_N = 0; + pl->pick_on = 1; - for (N = 0; N < PLOT_AXES_MAX; ++N) - pl->axis[N].exponential = 0; + plotPickTrack(pl, gp->cur_X, gp->cur_Y); } else { - for (N = 0; N < PLOT_AXES_MAX; ++N) - pl->axis[N].exponential = 1; + pl->data_box_on = DATA_BOX_FREE; + + pl->slice_on = 0; + pl->slice_mode_N = 0; + pl->pick_on = 0; } break; @@ -1727,7 +1873,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 17: - gp->done = 1; + gp->quit = 1; break; } } @@ -1758,7 +1904,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) switch (item_N) { case 0: - readDataReload(rd); + (void) readDataReload(rd); if (gp->shift_on != 0) { @@ -1770,7 +1916,8 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 1: - plotDataSubtractAlternate(rd->pl); + plotDataSubtractAlternate(pl); + plotTotalSubtractGarbage(pl); break; case 2: @@ -1786,6 +1933,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + gp->stat = GP_MENU; break; @@ -1836,7 +1984,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (item_N != -1) { - int gN, cN; + int gN, cN, unwrap; switch (item_N) { @@ -1844,6 +1992,8 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gpMakeDatasetSelectMenu(gp); menuRaise(mu, 10221, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, gp->data_N); + gp->stat = GP_MENU; break; @@ -1851,6 +2001,10 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gpMakeColumnSelectMenu(gp, gp->data_N); menuRaise(mu, 10222, gp->la_menu, mu->box_X, mu->box_Y); + + N = readGetTimeColumn(rd, gp->data_N); + menuSelect(mu, N + 1); + gp->stat = GP_MENU; break; @@ -1901,8 +2055,10 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (gN >= 0) { - pl->group[gN].op_time_unwrap = - (pl->group[gN].op_time_unwrap != 0) ? 0 : 1; + unwrap = pl->group[gN].op_time_unwrap; + unwrap = (unwrap < UNWRAP_BURST) ? unwrap + 1 : 0; + + pl->group[gN].op_time_unwrap = unwrap; } } @@ -2034,6 +2190,8 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 0); + gp->stat = GP_MENU; } } @@ -2046,6 +2204,8 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 2); + gp->stat = GP_MENU; } } @@ -2251,8 +2411,6 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (mu->clicked != 0) { - mu->mark[0].subs = (pl->axis[gp->ax_N].compact == 0) ? " " : "X"; - menuResume(mu); gp->stat = GP_MENU; } @@ -2263,8 +2421,6 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (mu->clicked != 0) { - mu->mark[1].subs = (pl->axis[gp->ax_N].exponential == 0) ? " " : "X"; - menuResume(mu); gp->stat = GP_MENU; } @@ -2280,8 +2436,6 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (mu->clicked != 0) { - mu->mark[2].subs = (pl->axis[gp->ax_N].lock_tick == 0) ? " " : "X"; - menuResume(mu); gp->stat = GP_MENU; } @@ -2376,20 +2530,12 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) N = plotFigureSelected(pl); - if (N < 2) { + if (N != 2) { - mu->hidden_N[0] = 2; + mu->hidden_N[0] = 5; mu->hidden_N[1] = 6; mu->hidden_N[2] = 7; mu->hidden_N[3] = 8; - mu->hidden_N[4] = 9; - } - else if (N != 2) { - - mu->hidden_N[0] = 6; - mu->hidden_N[1] = 7; - mu->hidden_N[2] = 8; - mu->hidden_N[3] = 9; } gp->stat = GP_MENU; @@ -2411,7 +2557,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) } else if (menu_N == 302) { - int config[3]; + int length, unwrap, opdata; switch (item_N) { @@ -2421,7 +2567,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) if (N < 0) { ERROR("Unable to get free figure to duplicate\n"); - break ; + break; } plotFigureAdd(pl, N, pl->figure[gp->fig_N].data_N, @@ -2437,9 +2583,9 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 1: - if (plotFigureSubtractGetMedianConfig(pl, gp->fig_N, config) >= 0) { + if (plotFigureSubtractGetMedianConfig(pl, gp->fig_N, &length, &unwrap, &opdata) >= 0) { - sprintf(gp->sbuf[0], "%d %d %d", config[0], config[1], config[2]); + sprintf(gp->sbuf[0], "%d %d %d", length, unwrap, opdata); } else { sprintf(gp->sbuf[0], "15 0 1"); @@ -2452,24 +2598,20 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 2: - plotFigureSubtractResample(pl, gp->fig_N); - break; - - case 3: editRaise(ed, 5, gp->la->scale_offset_edit, "1 0", mu->box_X, mu->box_Y); gp->stat = GP_EDIT; break; - case 4: + case 3: editRaise(ed, 6, gp->la->scale_offset_edit, "-1 0", mu->box_X, mu->box_Y); gp->stat = GP_EDIT; break; - case 5: + case 4: if (plotDataBoxPolyfit(pl, gp->fig_N) == 0) { editRaise(ed, 16, gp->la->polynomial_edit, @@ -2479,45 +2621,45 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) } break; - case 6: + case 5: plotFigureSubtractSwitch(pl, SUBTRACT_BINARY_SUBTRACTION); break; - case 7: + case 6: plotFigureSubtractSwitch(pl, SUBTRACT_BINARY_ADDITION); break; - case 8: + case 7: plotFigureSubtractSwitch(pl, SUBTRACT_BINARY_MULTIPLICATION); break; - case 9: + case 8: plotFigureSubtractSwitch(pl, SUBTRACT_BINARY_HYPOTENUSE); break; - case 10: + case 9: plotFigureSubtractFilter(pl, gp->fig_N, SUBTRACT_FILTER_DIFFERENCE, 0.); break; - case 11: + case 10: plotFigureSubtractFilter(pl, gp->fig_N, SUBTRACT_FILTER_CUMULATIVE, 0.); break; - case 12: + case 11: editRaise(ed, 8, gp->la->bit_number_edit, "0", mu->box_X, mu->box_Y); gp->stat = GP_EDIT; break; - case 13: + case 12: editRaise(ed, 13, gp->la->low_pass_edit, "0.1", mu->box_X, mu->box_Y); gp->stat = GP_EDIT; break; - case 14: + case 13: editRaise(ed, 19, gp->la->median_unwrap_edit, "15", mu->box_X, mu->box_Y); @@ -2639,25 +2781,49 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; case 1: - gp->fig_N = -1; + if (plotAxisRangeGet(pl, pl->on_X, &fmin, &fmax) != 0) { - editRaise(ed, 5, gp->la->scale_offset_edit, - "1 0", mu->box_X, mu->box_Y); + gp->resample_range[0] = fmin; + gp->resample_range[1] = fmax; + gp->resample_locked = 0; - gp->stat = GP_EDIT; + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + + N = gpGetBlankData(gp); + + if (rd->data[N].format == FORMAT_BLANK_DATA) { + + N = plotFigureHaveData(pl, N); + + gp->resample_locked = (N != 0) ? 1 : 0; + } + + gp->stat = GP_MENU; + } break; case 2: gp->fig_N = -1; + editRaise(ed, 5, gp->la->scale_offset_edit, + "1 0", mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 3: + gp->fig_N = -1; + editRaise(ed, 6, gp->la->scale_offset_edit, "-1 0", mu->box_X, mu->box_Y); gp->stat = GP_EDIT; break; - case 3: - sprintf(gp->sbuf[0], "%s/g%if%i.csv", rd->screenpath, + case 4: + sprintf(gp->sbuf[0], "%sg%if%i.csv", rd->screenpath, rd->page_N, gp->pl->legend_N); N = 1; @@ -2670,7 +2836,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) break; } - sprintf(gp->sbuf[0], "%s/g%if%i_%i.csv", rd->screenpath, + sprintf(gp->sbuf[0], "%sg%if%i_%i.csv", rd->screenpath, rd->page_N, gp->pl->legend_N, N); N++; @@ -2682,7 +2848,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) gp->stat = GP_EDIT; break; - case 4: + case 5: pl->transparency = pl->transparency ? 0 : 1; if (mu->clicked != 0) { @@ -2694,7 +2860,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) } break; - case 5: + case 6: pl->legend_hidden = pl->legend_hidden ? 0 : 1; if (mu->clicked != 0) { @@ -2713,7 +2879,8 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) for (N = 0; N < PLOT_FIGURE_MAX; ++N) { - if (pl->figure[N].busy != 0) { + if ( pl->figure[N].busy != 0 + && pl->figure[N].hidden == 0) { int lN; @@ -2730,27 +2897,149 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) } } } - else if (menu_N == 5) { + else if (menu_N == 402) { switch (item_N) { case 0: - pl->data_box_on = DATA_BOX_FREE; + gpMakeDatasetSelectMenu(gp); - pl->slice_on = 0; - pl->slice_mode_N = 0; + menuRaise(mu, 4021, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, gp->blank_N); + + gp->stat = GP_MENU; break; case 1: + if (gp->resample_locked != 0) { + + menuResume(mu); + menuLayout(mu); + + gp->stat = GP_MENU; + break; + } + + N = (rd->data[gp->blank_N].format == FORMAT_BLANK_DATA) + ? rd->data[gp->blank_N].length_N + : plotDataLength(pl, gp->blank_N); + + sprintf(gp->sbuf[0], "%i", N); + + editRaise(ed, 24, gp->la->length_edit, + gp->sbuf[0], mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 2: + editRaise(ed, 22, gp->la->time_range_edit, + gp->sbuf[2], mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 3: + if (gp->resample_locked != 0) { + + menuResume(mu); + menuLayout(mu); + + gp->stat = GP_MENU; + break; + } + + editRaise(ed, 25, gp->la->time_step_edit, + gp->sbuf[3], mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 4: + pl->interpolation = (pl->interpolation == 0) ? 1 : 0; + + gpMakeResampleMenu(gp); + + menuResume(mu); + menuLayout(mu); + + gp->stat = GP_MENU; + break; + + case 5: + sprintf(gp->sbuf[0], "%i", pl->defungap); + + editRaise(ed, 26, gp->la->time_threshold_edit, + gp->sbuf[0], mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 6: + plotTotalSubtractResample(pl, gp->blank_N, + gp->resample_range[0], + gp->resample_range[1]); + break; + } + } + else if (menu_N == 4021) { + + if (item_N != -1) { + + if ( item_N < PLOT_DATASET_MAX + && item_N >= 0) { + + gp->blank_N = item_N; + } + + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 0); + + gp->stat = GP_MENU; + } + } + else if (menu_N == 5) { + + switch (item_N) { + + case 0: plotDataBoxCopyClipboard(pl); break; + + case 1: + sprintf(gp->sbuf[0], "%i", pl->fprecision); + + editRaise(ed, 23, gp->la->precision_edit, + gp->sbuf[0], mu->box_X, mu->box_Y); + + gp->stat = GP_EDIT; + break; + + case 2: + pl->fhexadecimal = pl->fhexadecimal ? 0 : 1; + + mu->mark[1].subs = (pl->fhexadecimal == 0) ? " ": "X"; + + menuResume(mu); + gp->stat = GP_MENU; + break; + + case 3: + pl->data_box_on = DATA_BOX_FREE; + + pl->slice_on = 0; + pl->slice_mode_N = 0; + pl->pick_on = 0; + break; } } else if (menu_N == 9) { N = item_N + 1; - if (gp->combine_on == GP_COMBINE_AXES_REMAP) { + if (gp->combine_remap == 1) { readCombinePage(rd, N, 1); @@ -2766,7 +3055,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) menuResume(mu); gp->stat = GP_MENU; } - else if (gp->combine_on == GP_COMBINE_NO_REMAP) { + else if (gp->combine_remap == 2) { readCombinePage(rd, N, 0); @@ -2789,7 +3078,7 @@ gpMenuHandle(gp_t *gp, int menu_N, int item_N) } static void -gpEditHandle(gp_t *gp, int edit_N, const char *text) +gpEditHandle(gpcon_t *gp, int edit_N, const char *text) { scheme_t *sch = gp->sch; lang_t *la = gp->la; @@ -2799,8 +3088,8 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) menu_t *mu = gp->mu; svg_t *g; - double scale, offset, gain; - int len, n; + double scale, offset, fmin, fmax, gain; + int N, args[2], len, n; if (edit_N == 1) { @@ -2832,7 +3121,7 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) if (n != 0) { - if (n == 1) { + if (n < 2) { offset = 0.; } @@ -2859,25 +3148,23 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) } else if (edit_N == 7) { - const char *filetype; + const char *ft; + int len; strcpy(gp->tempfile, text); - filetype = gp->tempfile + strlen(gp->tempfile); - - if (strlen(gp->tempfile) > 4) { + ft = gp->tempfile; - filetype += - 4; - } + len = strlen(ft); + ft += (len > 4) ? len - 4 : 0; - if (strcmp(filetype, ".png") == 0) { + if (strcmp(ft, ".png") == 0) { gp->screen_take = GP_TAKE_PNG; } - else if (strcmp(filetype, ".svg") == 0) { + else if (strcmp(ft, ".svg") == 0) { - g = (void *) svgOpenNew(gp->tempfile, - gp->surface->w, gp->surface->h); + g = svgOpenNew(gp->tempfile, gp->surface->w, gp->surface->h); g->font_family = "monospace"; g->font_pt = pl->layout_font_pt; @@ -2885,15 +3172,13 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) gp->surface->userdata = (void *) g; gp->screen_take = GP_TAKE_SVG; } - else if (strcmp(filetype, ".csv") == 0) { + else if (strcmp(ft, ".csv") == 0) { gp->screen_take = GP_TAKE_CSV; } } else if (edit_N == 8) { - int args[2]; - n = sscanf(text, "%d %d", &args[0], &args[1]); if (n != 0) { @@ -2948,7 +3233,7 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) n = sscanf(text, "%le %le", &scale, &offset); - if (n == 2) { + if (n >= 2) { plotGroupScale(pl, gp->grp_N, 1, scale, offset); } @@ -2959,13 +3244,15 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 6); + gp->stat = GP_MENU; } else if (edit_N == 12) { n = sscanf(text, "%d", &len); - if (n == 1) { + if (n != 0) { if (len >= 0) { @@ -2981,13 +3268,15 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 7); + gp->stat = GP_MENU; } else if (edit_N == 13) { n = sscanf(text, "%le", &gain); - if (n == 1) { + if (n != 0) { plotFigureSubtractFilter(pl, gp->fig_N, SUBTRACT_FILTER_LOW_PASS, gain); @@ -2997,7 +3286,7 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) n = sscanf(text, "%i", &len); - if (n == 1) { + if (n != 0) { if (len >= 0 && len <= 16) { @@ -3009,7 +3298,7 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) n = sscanf(text, "%d", &len); - if (n == 1) { + if (n != 0) { gpFontToggle(gp, 0, len); @@ -3025,8 +3314,6 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) } else if (edit_N == 16) { - int args[2]; - n = sscanf(text, "%d %d", &args[0], &args[1]); if (n != 0) { @@ -3071,12 +3358,12 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) gpMakeDatasetMenu(gp); menuRaise(mu, 1022, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 3); + gp->stat = GP_MENU; } else if (edit_N == 18) { - int args[2]; - n = sscanf(text, "%d %d %d", &len, &args[0], &args[1]); if (n != 0) { @@ -3103,22 +3390,20 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) } else if (edit_N == 20) { - int args[2]; - n = sscanf(text, "%d %d", &args[0], &args[1]); - if (n == 2) { + if (n >= 2) { if (args[0] > 0 && args[0] < 100) { pl->mark_density = args[0]; - pl->mark_count = 0; + pl->mark_length = 0; } if (args[1] > 0 && args[1] < 100) { pl->mark_size = args[1]; - pl->mark_count = 0; + pl->mark_length = 0; } sprintf(gp->sbuf[2] + 20, "%2i %2i ", pl->mark_density, pl->mark_size); @@ -3152,12 +3437,117 @@ gpEditHandle(gp_t *gp, int edit_N, const char *text) menuResume(mu); menuLayout(mu); + gp->stat = GP_MENU; + } + else if (edit_N == 22) { + + n = sscanf(text, "%le %le", &fmin, &fmax); + + if (n >= 2) { + + gp->resample_range[0] = fmin; + gp->resample_range[1] = fmax; + } + + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 2); + + gp->stat = GP_MENU; + } + else if (edit_N == 23) { + + n = sscanf(text, "%d", &len); + + if (n != 0) { + + if (len >= 1 && len <= 16) { + + pl->fprecision = len; + } + } + + sprintf(gp->sbuf[2], "%1i", pl->fprecision); + + mu->mark[0].subs = gp->sbuf[2]; + + menuResume(mu); + + gp->stat = GP_MENU; + } + else if (edit_N == 24) { + + n = sscanf(text, "%d", &len); + + if (n != 0) { + + N = (rd->data[gp->blank_N].format == FORMAT_BLANK_DATA) + ? rd->data[gp->blank_N].length_N + : plotDataLength(pl, gp->blank_N); + + if (len > 0 && len != N) { + + gpMakeBlank(gp, len); + } + } + + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 1); + + gp->stat = GP_MENU; + } + else if (edit_N == 25) { + + n = sscanf(text, "%le", &offset); + + if (n != 0) { + + N = (rd->data[gp->blank_N].format == FORMAT_BLANK_DATA) + ? rd->data[gp->blank_N].length_N + : plotDataLength(pl, gp->blank_N); + + len = (int) ((gp->resample_range[1] + - gp->resample_range[0]) / offset + 1); + + if (len != N) { + + gpMakeBlank(gp, len); + } + } + + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 3); + + gp->stat = GP_MENU; + } + else if (edit_N == 26) { + + n = sscanf(text, "%d", &len); + + if (n == 1) { + + if (len >= 0) { + + pl->defungap = len; + } + } + + gpMakeResampleMenu(gp); + + menuRaise(mu, 402, gp->la_menu, mu->box_X, mu->box_Y); + menuSelect(mu, 5); + gp->stat = GP_MENU; } } static void -gpEventHandle(gp_t *gp, const SDL_Event *ev) +gpEventHandle(gpcon_t *gp, const SDL_Event *ev) { plot_t *pl = gp->pl; read_t *rd = gp->rd; @@ -3167,29 +3557,33 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) double fmin, fmax; int N; - if (ev->type == SDL_QUIT) - gp->done = 1; + if (ev->type == SDL_QUIT) { + gp->quit = 1; + } else if (ev->type == SDL_WINDOWEVENT) { if (ev->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - gp->fb = SDL_GetWindowSurface(gp->window); + if (gp->window != NULL) { - if ( gp->fb->w != gp->surface->w - || gp->fb->h != gp->surface->h) { + gp->fb = SDL_GetWindowSurface(gp->window); - SDL_FreeSurface(gp->surface); + if ( gp->fb->w != gp->surface->w + || gp->fb->h != gp->surface->h) { - gp->surface = SDL_CreateRGBSurfaceWithFormat(0, gp->fb->w, - gp->fb->h, 32, SDL_PIXELFORMAT_XRGB8888); - } + SDL_FreeSurface(gp->surface); + + gp->surface = SDL_CreateRGBSurfaceWithFormat(0, gp->fb->w, + gp->fb->h, 32, SDL_PIXELFORMAT_XRGB8888); + } - gpScreenLayout(gp); + gpScreenLayout(gp); + } } else if (ev->window.event == SDL_WINDOWEVENT_CLOSE) { - gp->done = 1; + gp->quit = 1; } } else if (ev->type == SDL_KEYDOWN) { @@ -3284,9 +3678,16 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) gpMenuHandle(gp, 102, 3); } + else if (ev->key.keysym.sym == SDLK_n) { + + mu->box_X = -1; + mu->box_Y = -1; + + gpMenuHandle(gp, 4, 1); + } else if (ev->key.keysym.sym == SDLK_i) { - gp->i_show_fps = gp->i_show_fps ? 0 : 1; + gp->fps_show = gp->fps_show ? 0 : 1; } else if ( ev->key.keysym.sym == SDLK_PAGEUP || ev->key.keysym.sym == SDLK_UP) { @@ -3372,29 +3773,7 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) } else if (ev->key.keysym.sym == SDLK_k) { - if (pl->hover_axis != -1) { - - mu->clicked = 0; - gp->ax_N = pl->hover_axis; - - gpMenuHandle(gp, 2, 4); - } - else { - gpMenuHandle(gp, 1, 12); - } - } - else if (ev->key.keysym.sym == SDLK_e) { - - if (pl->hover_axis != -1) { - - mu->clicked = 0; - gp->ax_N = pl->hover_axis; - - gpMenuHandle(gp, 2, 5); - } - else { - gpMenuHandle(gp, 1, 13); - } + gpMenuHandle(gp, 1, 12); } else if (ev->key.keysym.sym == SDLK_y) { @@ -3414,7 +3793,6 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) if (N >= 0) { pl->figure[N].hidden = pl->figure[N].hidden ? 0 : 1; - break; } @@ -3446,33 +3824,30 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) if (N >= 0) { - if (pl->axis[N].busy == AXIS_BUSY_X + if ( pl->axis[N].busy == AXIS_BUSY_X && pl->axis[N].slave == 0) { pl->on_X = N; gp->ax_N = N; gp->stat = GP_MOVING; - break; } - else if (pl->axis[N].busy == AXIS_BUSY_Y + else if ( pl->axis[N].busy == AXIS_BUSY_Y && pl->axis[N].slave == 0) { pl->on_Y = N; gp->ax_N = N; gp->stat = GP_MOVING; - break; } - } - else { - gp->box_X = ev->button.x; - gp->box_Y = ev->button.y; - gp->ax_N = -1; - - gp->stat = GP_MOVING; break; } + + gp->box_X = ev->button.x; + gp->box_Y = ev->button.y; + gp->ax_N = -1; + + gp->stat = GP_MOVING; } while (0); } @@ -3494,8 +3869,9 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) mu->hidden_N[0] = 9; } + mu->hidden_N[1] = 13; #ifndef _WINDOWS - mu->hidden_N[1] = 14; + mu->hidden_N[2] = 14; #endif /* _WINDOWS */ gp->stat = GP_MENU; @@ -3522,10 +3898,10 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) menuRaise(mu, 4, gp->la->legend_menu, gp->cur_X, gp->cur_Y); - mu->mark[0].N = 4; + mu->mark[0].N = 5; mu->mark[0].subs = (pl->transparency == 0) ? " " : "X"; - mu->mark[1].N = 5; + mu->mark[1].N = 6; mu->mark[1].subs = (pl->legend_hidden == 0) ? " " : "X"; gp->stat = GP_MENU; @@ -3539,6 +3915,14 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) menuRaise(mu, 5, gp->la->databox_menu, gp->cur_X, gp->cur_Y); + sprintf(gp->sbuf[2], "%1i", pl->fprecision); + + mu->mark[0].N = 1; + mu->mark[0].subs = gp->sbuf[2]; + + mu->mark[1].N = 2; + mu->mark[1].subs = (pl->fhexadecimal == 0) ? " ": "X"; + gp->stat = GP_MENU; break; } @@ -3562,7 +3946,6 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) mu->mark[2].subs = (pl->axis[N].lock_tick == 0) ? " " : "X"; gp->stat = GP_MENU; - break; } else { gp->ax_N = N; @@ -3581,19 +3964,16 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) mu->mark[2].subs = (pl->axis[N].lock_tick == 0) ? " " : "X"; gp->stat = GP_MENU; - break; } + break; } - else { - if (clipBoxTest(&pl->viewport, gp->cur_X, gp->cur_Y)) { - gp->box_X = ev->button.x; - gp->box_Y = ev->button.y; + if (clipBoxTest(&pl->viewport, gp->cur_X, gp->cur_Y)) { - gp->stat = GP_BOX_SELECT; - break; - } - break; + gp->box_X = ev->button.x; + gp->box_Y = ev->button.y; + + gp->stat = GP_SELECT_BOX; } } while (0); @@ -3643,6 +4023,10 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) plotSliceTrack(pl, gp->cur_X, gp->cur_Y); } + else if (pl->pick_on != 0) { + + plotPickTrack(pl, gp->cur_X, gp->cur_Y); + } if (pl->data_box_on != DATA_BOX_FREE) { @@ -3676,12 +4060,16 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) if (gp->box_X == ev->button.x && gp->box_Y == ev->button.y && clipBoxTest(&pl->viewport, gp->box_X, gp->box_Y)) { - if (pl->slice_on == 0) { + if (pl->slice_on != 0) { + + plotSliceSwitch(pl); + } + else if (pl->pick_on != 0) { - gp->stat = GP_RANGE_SELECT; + plotSliceSwitch(pl); } else { - plotSliceSwitch(pl); + gp->stat = GP_SELECT_RANGE; } } } @@ -3749,7 +4137,7 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) } } } - else if (gp->stat == GP_RANGE_SELECT) { + else if (gp->stat == GP_SELECT_RANGE) { if (ev->type == SDL_KEYDOWN) { @@ -3818,68 +4206,112 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) gp->cur_Y = ev->motion.y; } } - else if (gp->stat == GP_BOX_SELECT) { + else if (gp->stat == GP_SELECT_BOX) { if (ev->type == SDL_KEYDOWN) { - if (ev->key.keysym.sym == SDLK_ESCAPE) + if (ev->key.keysym.sym == SDLK_ESCAPE) { + gp->stat = GP_IDLE; + pl->brush_on = 0; + } + else if (ev->key.keysym.sym == SDLK_e) { + + pl->brush_on = (pl->brush_on == 0) ? 1 : 0; + + if (pl->brush_on != 0) { + + pl->brush_box_X = gp->box_X; + pl->brush_box_Y = gp->box_Y; + pl->brush_cur_X = gp->cur_X; + pl->brush_cur_Y = gp->cur_Y; + } + } } else if (ev->type == SDL_MOUSEBUTTONDOWN) { - if (ev->button.button == SDL_BUTTON_RIGHT) + if (ev->button.button == SDL_BUTTON_RIGHT) { + gp->stat = GP_IDLE; + pl->brush_on = 0; + } } else if (ev->type == SDL_MOUSEBUTTONUP) { if (ev->button.button == SDL_BUTTON_RIGHT) { - if (gp->box_X != gp->cur_X && gp->box_Y != gp->cur_Y) { + if ( gp->box_X != gp->cur_X + && gp->box_Y != gp->cur_Y) { - if (gp->box_X > gp->cur_X) { + if (pl->brush_on != 0) { - N = gp->box_X; - gp->box_X = gp->cur_X; - gp->cur_X = N; + pl->brush_box_X = gp->box_X; + pl->brush_box_Y = gp->box_Y; + pl->brush_cur_X = gp->cur_X; + pl->brush_cur_Y = gp->cur_Y; + + plotBrushErase(pl); } + else { + if (gp->box_X > gp->cur_X) { - if (gp->box_Y < gp->cur_Y) { + N = gp->box_X; + gp->box_X = gp->cur_X; + gp->cur_X = N; + } - N = gp->box_Y; - gp->box_Y = gp->cur_Y; - gp->cur_Y = N; - } + if (gp->box_Y < gp->cur_Y) { - fmin = plotAxisConvBackward(pl, pl->on_X, gp->box_X); - fmax = plotAxisConvBackward(pl, pl->on_X, gp->cur_X); + N = gp->box_Y; + gp->box_Y = gp->cur_Y; + gp->cur_Y = N; + } + + fmin = plotAxisConvBackward(pl, pl->on_X, gp->box_X); + fmax = plotAxisConvBackward(pl, pl->on_X, gp->cur_X); - plotAxisScaleManual(pl, pl->on_X, fmin, fmax); + plotAxisScaleManual(pl, pl->on_X, fmin, fmax); - fmin = plotAxisConvBackward(pl, pl->on_Y, gp->box_Y); - fmax = plotAxisConvBackward(pl, pl->on_Y, gp->cur_Y); + fmin = plotAxisConvBackward(pl, pl->on_Y, gp->box_Y); + fmax = plotAxisConvBackward(pl, pl->on_Y, gp->cur_Y); - plotAxisScaleManual(pl, pl->on_Y, fmin, fmax); + plotAxisScaleManual(pl, pl->on_Y, fmin, fmax); - pl->axis[pl->on_X].lock_scale = LOCK_FREE; - pl->axis[pl->on_Y].lock_scale = LOCK_FREE; + pl->axis[pl->on_X].lock_scale = LOCK_FREE; + pl->axis[pl->on_Y].lock_scale = LOCK_FREE; + } } else { gpMenuHandle(gp, 101, 0); } gp->stat = GP_IDLE; + pl->brush_on = 0; } } else if (ev->type == SDL_MOUSEMOTION) { gp->cur_X = ev->motion.x; gp->cur_Y = ev->motion.y; + + if (pl->brush_on != 0) { + + pl->brush_cur_X = gp->cur_X; + pl->brush_cur_Y = gp->cur_Y; + } } } else if (gp->stat == GP_MENU) { SDL_StartTextInput(); + if (mu->id == 2) { + + mu->mark[0].subs = (pl->axis[gp->ax_N].compact == 0) ? " " : "X"; + mu->mark[1].subs = (pl->axis[gp->ax_N].exponential == 0) ? " " : "X"; + mu->mark[2].subs = (pl->axis[gp->ax_N].lock_tick == 0) ? " " : "X"; + } + if (ev->type == SDL_KEYDOWN) { if (ev->key.keysym.sym == SDLK_ESCAPE) { @@ -4076,7 +4508,7 @@ gpEventHandle(gp_t *gp, const SDL_Event *ev) } static void -gpDrawRangeLight(SDL_Surface *surface, gp_t *gp) +gpDrawRangeLight(SDL_Surface *surface, gpcon_t *gp) { plot_t *pl = gp->pl; @@ -4110,7 +4542,7 @@ gpDrawRangeLight(SDL_Surface *surface, gp_t *gp) } static void -gpDrawRangeSelect(SDL_Surface *surface, gp_t *gp) +gpDrawRangeSelect(SDL_Surface *surface, gpcon_t *gp) { draw_t *dw = gp->dw; plot_t *pl = gp->pl; @@ -4145,7 +4577,7 @@ gpDrawRangeSelect(SDL_Surface *surface, gp_t *gp) } static void -gpDrawBoxLight(SDL_Surface *surface, gp_t *gp) +gpDrawBoxLight(SDL_Surface *surface, gpcon_t *gp) { plot_t *pl = gp->pl; int min_X, min_Y, max_X, max_Y; @@ -4179,7 +4611,7 @@ gpDrawBoxLight(SDL_Surface *surface, gp_t *gp) } static void -gpDrawBoxSelect(SDL_Surface *surface, gp_t *gp) +gpDrawBoxSelect(SDL_Surface *surface, gpcon_t *gp) { draw_t *dw = gp->dw; plot_t *pl = gp->pl; @@ -4203,21 +4635,21 @@ gpDrawBoxSelect(SDL_Surface *surface, gp_t *gp) } static void -gpFPSUpdate(gp_t *gp) +gpFPSUpdate(gpcon_t *gp) { - gp->i_frames += 1; + gp->fps_frame += 1; - if (gp->i_clocked < gp->clock) { + if (gp->fps_clock < gp->clock) { - gp->i_FPS = gp->i_frames; - gp->i_frames = 0; - gp->i_clocked = gp->clock + 1000; + gp->fps_value = gp->fps_frame; + gp->fps_frame = 0; + gp->fps_clock = gp->clock + 1000U; } } -gp_t *gp_Alloc() +gpcon_t *gp_Alloc() { - gp_t *gp; + gpcon_t *gp; scheme_t *sch; lang_t *la; draw_t *dw; @@ -4226,7 +4658,7 @@ gp_t *gp_Alloc() menu_t *mu; edit_t *ed; - gp = (gp_t *) calloc(1, sizeof(gp_t)); + gp = (gpcon_t *) calloc(1, sizeof(gpcon_t)); sch = (scheme_t *) calloc(1, sizeof(scheme_t)); gp->sch = sch; @@ -4301,7 +4733,7 @@ gp_t *gp_Alloc() return gp; } -void gp_Clean(gp_t *gp) +void gp_Clean(gpcon_t *gp) { scheme_t *sch = gp->sch; lang_t *la = gp->la; @@ -4332,30 +4764,85 @@ void gp_Clean(gp_t *gp) free(gp); } -void gp_TakeConfig(gp_t *gp, const char *config) +void gp_TakeConfig(gpcon_t *gp, const char *config) { readConfigIN(gp->rd, config, 0); } -int gp_OpenWindow(gp_t *gp) +void gp_TakeEvent(gpcon_t *gp, const SDL_Event *ev) +{ + if (ev->window.windowID == gp->window_ID) { + + gpEventHandle(gp, ev); + + gp->active = 1; + } +} + +SDL_Surface *gp_GetSurface(gpcon_t *gp) { scheme_t *sch = gp->sch; lang_t *la = gp->la; read_t *rd = gp->rd; + if (gp->surface != NULL) { + + if ( gp->surface->w != rd->window_size_x + || gp->surface->h != rd->window_size_y) { + + SDL_FreeSurface(gp->surface); + + gp->surface = SDL_CreateRGBSurfaceWithFormat(0, rd->window_size_x, + rd->window_size_y, 32, SDL_PIXELFORMAT_XRGB8888); + } + } + else { + readConfigSafe(rd); + + gp->surface = SDL_CreateRGBSurfaceWithFormat(0, rd->window_size_x, + rd->window_size_y, 32, SDL_PIXELFORMAT_XRGB8888); + + if (gp->surface == NULL) { + + ERROR("SDL_CreateRGBSurfaceWithFormat: %s\n", SDL_GetError()); + + gp->quit = 1; + } + } + + gpFontHinting(gp); + + gpFontLayout(gp); + gpScreenLayout(gp); + + langFill(la, rd->language); + schemeFill(sch, rd->colorscheme); + + drawGamma(gp->dw); + + gp->stat = GP_IDLE; + gp->active = 1; + + return gp->surface; +} + +Uint32 gp_OpenWindow(gpcon_t *gp) +{ + read_t *rd = gp->rd; + if (gp->window_ID != 0) { return gp->window_ID; } - readConfigVerify(rd); - gp->window = SDL_CreateWindow("GP", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, rd->window_size_x, rd->window_size_y, SDL_WINDOW_RESIZABLE); if (gp->window == NULL) { ERROR("SDL_CreateWindow: %s\n", SDL_GetError()); + + gp->quit = 1; } gp->window_ID = SDL_GetWindowID(gp->window); @@ -4363,6 +4850,8 @@ int gp_OpenWindow(gp_t *gp) if (gp->window_ID == 0) { ERROR("SDL_GetWindowID: %s\n", SDL_GetError()); + + gp->quit = 1; } SDL_SetWindowMinimumSize(gp->window, GP_MIN_SIZE_X, GP_MIN_SIZE_Y); @@ -4373,50 +4862,99 @@ int gp_OpenWindow(gp_t *gp) if (gp->fb == NULL) { ERROR("SDL_GetWindowSurface: %s\n", SDL_GetError()); + + gp->quit = 1; } - gp->surface = SDL_CreateRGBSurfaceWithFormat(0, gp->fb->w, - gp->fb->h, 32, SDL_PIXELFORMAT_XRGB8888); + return gp->window_ID; +} + +int gp_DataAdd(gpcon_t *gp, int dN, const double *payload) +{ + plot_t *pl = gp->pl; + read_t *rd = gp->rd; + + int rc, N = 0; - if (gp->surface == NULL) { + if ( dN >= 0 && dN < PLOT_DATASET_MAX + && rd->data[dN].format == FORMAT_STUB_DATA) { - ERROR("SDL_CreateRGBSurfaceWithFormat: %s\n", SDL_GetError()); + rc = async_write(rd->data[dN].afd, (void *) payload, + pl->data[dN].column_N * sizeof(double)); + + if (rc == ASYNC_OK) { + + N = 1; + } } - gpFontHinting(gp); + return N; +} - gpFontLayout(gp); - gpScreenLayout(gp); +void gp_FileReload(gpcon_t *gp) +{ + read_t *rd = gp->rd; - gp->stat = GP_IDLE; - gp->active = 1; + (void) readDataReload(rd); +} - langFill(la, rd->language); - schemeFill(sch, rd->colorscheme); +void gp_PageCombine(gpcon_t *gp, int pN, int remap) +{ + read_t *rd = gp->rd; - readSelectPage(rd, 1); + if (remap == GP_PAGE_SELECT) { - drawGamma(gp->dw); + readSelectPage(rd, pN); + } + else if (remap == GP_PAGE_COMBINE) { - return gp->window_ID; + readCombinePage(rd, pN, 1); + } + else if (remap == GP_PAGE_NO_REMAP) { + + readCombinePage(rd, pN, 0); + } } -void gp_TakeEvent(gp_t *gp, const SDL_Event *ev) +int gp_PageSafe(gpcon_t *gp) { - if (ev->window.windowID == gp->window_ID) { + plot_t *pl = gp->pl; + read_t *rd = gp->rd; - gpEventHandle(gp, ev); + int pN, N = 0; - gp->active = 1; + pN = rd->page_N; + + if (pN >= 1 && pN < READ_PAGE_MAX) { + + N = plotFigureSelected(pl); + } + + return N; +} + +void gp_AxisRange(gpcon_t *gp, int aN, double min, double max) +{ + plot_t *pl = gp->pl; + + if (aN < 0 || aN >= PLOT_AXES_MAX) { + + ERROR("Axis number is out of range\n"); + return ; } + + plotAxisScaleManual(pl, aN, min, max); + + pl->axis[aN].lock_scale = LOCK_FREE; + pl->axis[aN].lock_tick = 0; } -int gp_IsQuit(gp_t *gp) +int gp_IsQuit(gpcon_t *gp) { - return gp->done; + return gp->quit; } -int gp_Draw(gp_t *gp) +int gp_Draw(gpcon_t *gp) { scheme_t *sch = gp->sch; draw_t *dw = gp->dw; @@ -4428,18 +4966,17 @@ int gp_Draw(gp_t *gp) gp->clock = SDL_GetTicks(); gp->drawn = 0; - if (rd->files_N != 0) { - - if (readUpdate(rd) != 0) { + if (readDataLoad(rd) != 0) { - gp->active = 1; - } + gp->active = 1; } - else { + + if (rd->keep_N == 0) { + plotAxisScaleLock(pl, LOCK_FREE); } - if (gp->i_show_fps != 0) { + if (gp->fps_show != 0) { gp->active = 1; } @@ -4449,7 +4986,7 @@ int gp_Draw(gp_t *gp) gp->idled = 0; } - if (gp->updated + 250 < gp->clock) { + if (gp->updated + 250U < gp->clock) { gp->idled += 1; gp->active = (gp->idled < 20) ? 1 : 0; @@ -4465,7 +5002,7 @@ int gp_Draw(gp_t *gp) if (gp->unfinished != 0) { - int t0, t1; + Uint32 t0, t1; SDL_LockSurface(gp->surface); @@ -4476,14 +5013,14 @@ int gp_Draw(gp_t *gp) plotLayout(pl); plotAxisScaleDefault(pl); - if (gp->stat == GP_RANGE_SELECT) { + if (gp->stat == GP_SELECT_RANGE) { if (gp->shift_on == 0) { gpDrawRangeLight(gp->surface, gp); } } - else if (gp->stat == GP_BOX_SELECT) { + else if (gp->stat == GP_SELECT_BOX) { gpDrawBoxLight(gp->surface, gp); } @@ -4496,12 +5033,12 @@ int gp_Draw(gp_t *gp) plotDraw(pl, gp->surface); - if ( rd->fastdraw != 0 + if ( gp->window != NULL && rd->fastdraw != 0 && dw->antialiasing != DRAW_SOLID) { t1 = SDL_GetTicks(); - gp->level += (t1 - t0 > rd->fastdraw) ? 1 + gp->level += ((int) (t1 - t0) > rd->fastdraw) ? 1 : (gp->level > 0) ? - 1 : 0; if (gp->level > 4) { @@ -4511,11 +5048,11 @@ int gp_Draw(gp_t *gp) } } - if (gp->stat == GP_RANGE_SELECT) { + if (gp->stat == GP_SELECT_RANGE) { gpDrawRangeSelect(gp->surface, gp); } - else if (gp->stat == GP_BOX_SELECT) { + else if (gp->stat == GP_SELECT_BOX) { gpDrawBoxSelect(gp->surface, gp); } @@ -4528,7 +5065,7 @@ int gp_Draw(gp_t *gp) pl->sch->plot_hovered); } - gpTextLeftCrop(pl, gp->sbuf[1], rd->page[rd->page_N].title, + gpTextFull(pl, gp->sbuf[1], rd->page[rd->page_N].title, gp->layout_menu_page_margin); sprintf(gp->sbuf[0], "%3d %s", rd->page_N, gp->sbuf[1]); @@ -4540,13 +5077,14 @@ int gp_Draw(gp_t *gp) menuDraw(mu, gp->surface); editDraw(ed, gp->surface); - if (gp->i_show_fps != 0) { + if ( gp->window != NULL + && gp->fps_show != 0) { int len, jam; len = plotGetSketchLength(pl); - sprintf(gp->sbuf[0], "L %4d FPS %2d", len, gp->i_FPS); + sprintf(gp->sbuf[0], "L %4d FPS %2d", len, gp->fps_value); TTF_SizeUTF8(pl->font, gp->sbuf[0], &len, &jam); @@ -4557,11 +5095,14 @@ int gp_Draw(gp_t *gp) drawText(gp->dw, gp->surface, pl->font, pl->screen.max_x - (len + 6), pl->screen.min_y + gp->layout_page_title_offset, - gp->sbuf[0], TEXT_CENTERED_ON_Y, 0xFF2222); + gp->sbuf[0], TEXT_CENTERED_ON_Y, 0xFF0000); } - SDL_BlitSurface(gp->surface, NULL, gp->fb, NULL); - SDL_UpdateWindowSurface(gp->window); + if (gp->window != NULL) { + + SDL_BlitSurface(gp->surface, NULL, gp->fb, NULL); + SDL_UpdateWindowSurface(gp->window); + } gpFPSUpdate(gp); @@ -4579,144 +5120,434 @@ int gp_Draw(gp_t *gp) return gp->drawn; } +void gp_SavePNG(gpcon_t *gp, const char *file) +{ + plot_t *pl = gp->pl; + read_t *rd = gp->rd; + + if (file != gp->tempfile) { + + strcpy(gp->tempfile, file); + } + + do { + (void) readDataLoad(rd); + } + while (rd->keep_N != 0); + + plotAxisScaleDefault(pl); + + gp->active = 1; + + do { + (void) gp_Draw(gp); + } + while (gp->unfinished != 0); + + gp->screen_take = GP_TAKE_PNG; + + (void) gp_Draw(gp); +} + +void gp_SaveSVG(gpcon_t *gp, const char *file) +{ + plot_t *pl = gp->pl; + read_t *rd = gp->rd; + svg_t *g; + + if (file != gp->tempfile) { + + strcpy(gp->tempfile, file); + } + + do { + (void) readDataLoad(rd); + } + while (rd->keep_N != 0); + + plotAxisScaleDefault(pl); + + gp->active = 1; + + do { + (void) gp_Draw(gp); + } + while (gp->unfinished != 0); + + if (gp->surface != NULL) { + + g = svgOpenNew(gp->tempfile, gp->surface->w, gp->surface->h); + + g->font_family = "monospace"; + g->font_pt = pl->layout_font_pt; + + gp->surface->userdata = (void *) g; + + gp->screen_take = GP_TAKE_SVG; + gp->unfinished = 1; + + (void) gp_Draw(gp); + } +} + #ifndef _EMBED_GP static void -gpHelp(gp_t *gp) +gpUsageHelp() { - printf( "Usage: gp [-0kult] [filename] ...\n" - " -0 Open stdin text stream\n" - " -k# Chunk size in bytes\n" - " -u# Waiting timeout in msec\n" - " -l# Data length to allocate\n" - " -t# Time column default\n"); + printf( "Usage: gp [-ktd...] [-g file] [file] ...\n" + " - Open stdin stream as CSV dataset\n" + " -k[n] Chunk size (in bytes)\n" + " -t[n] Waiting timeout (in msec)\n" + " -d[n] Data length to allocate\n" + " -x[n] Time column default\n" + " -l[n] Color scheme number\n" + " -pcn[n] Select and combine pages\n" + " -a[n] min max Axis zoom to specified range\n" + " -g file Save to PNG/SVG file\n" + " -q Do not open window\n"); } static void -gpGetOPT(gp_t *gp, char *argv[]) +gpGetCMD(gpcon_t *gp, int argn, char *argv[]) { read_t *rd = gp->rd; char *op; - int argi; + int failed, argi; int n = 1; - while (argv[n] != NULL) { + while (n < argn && argv[n] != NULL) { if (argv[n][0] == '-') { op = &argv[n][1]; - while (*op != 0) { + failed = 1; + + if (*op == 0) { + + sprintf(gp->sbuf[0], "load 0 0 stdin\n" + "mkpages -2\n"); + + failed = 0; + + readConfigIN(rd, gp->sbuf[0], 0); + } + else if (*op == 'h') { + + op++; - if (*op == 'h') { + if (*op == 0) { - gpHelp(gp); - exit(0); + gpUsageHelp(); + + gp->quit = 1; + break; } - else if (*op == '0') { + } + else if (*op == 'k') { - sprintf(gp->sbuf[0], "load 0 0 stdin\n" - "mkpages -2\n"); + op++; + + if (*op == 0) { + + if (n + 1 >= argn) + goto gpGetCMD_END; - readConfigIN(rd, gp->sbuf[0], 0); + op = argv[++n]; } - else if (*op == 'k') { - op++; + if (stoi(&rd->mk_config, &argi, op) != NULL) { - if (*op == 0) { + if (argi > 0) { - if (argv[n + 1] == NULL) - break; + failed = 0; - n++; - op = argv[n]; + rd->chunk = argi; } + } + } + else if (*op == 't') { - if (stoi(&rd->mk_config, &argi, op) != NULL) { + op++; - if (argi > 0) { + if (*op == 0) { - rd->chunk = argi; - } + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi >= 0) { + + failed = 0; + + rd->timeout = argi; } } - else if (argv[n][1] == 'u') { + } + else if (*op == 'd') { - op++; + op++; - if (*op == 0) { + if (*op == 0) { - if (argv[n + 1] == NULL) - break; + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi >= 0) { - n++; - op = argv[n]; + failed = 0; + + rd->length_N = argi; } + } + } + else if (*op == 'x') { - if (stoi(&rd->mk_config, &argi, op) != NULL) { + op++; - if (argi >= 0) { + if (*op == 0) { - rd->timeout = argi; - } + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi >= -1 && argi < READ_COLUMN_MAX) { + + failed = 0; + + rd->timecol = argi; } } - else if (argv[n][1] == 'l') { + } + else if (*op == 'l') { - op++; + op++; - if (*op == 0) { + if (*op == 0) { - if (argv[n + 1] == NULL) - break; + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi >= 0 && argi <= 2) { - n++; - op = argv[n]; + failed = 0; + + rd->colorscheme = argi; + + schemeFill(gp->sch, rd->colorscheme); } + } + } + else if ( *op == 'p' + || *op == 'c' + || *op == 'n') { + + int remap; + + switch (*op) { + + default: + case 'p': + remap = GP_PAGE_SELECT; + break; + + case 'c': + remap = GP_PAGE_COMBINE; + break; + + case 'n': + remap = GP_PAGE_NO_REMAP; + break; + } + + op++; - if (stoi(&rd->mk_config, &argi, op) != NULL) { + if (*op == 0) { - if (argi > 0) { + if (n + 1 >= argn) + goto gpGetCMD_END; - rd->length_N = argi; + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi >= 1 && argi < READ_PAGE_MAX) { + + failed = 0; + + (void) gp_GetSurface(gp); + + if (gp_PageSafe(gp) == 0) { + + remap = GP_PAGE_SELECT; + } + + gp_PageCombine(gp, argi, remap); + + if (gp_PageSafe(gp) == 0) { + + ERROR("CMD: unable to combine \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; } } } - else if (argv[n][1] == 't') { + } + else if (*op == 'a') { - op++; + double fmin, fmax; - if (*op == 0) { + op++; - if (argv[n + 1] == NULL) - break; + if (*op == 0) { + + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + } + + if (stoi(&rd->mk_config, &argi, op) != NULL) { + + if (argi < 0 || argi >= PLOT_AXES_MAX) + goto gpGetCMD_END; + } + + if (n + 1 >= argn) + goto gpGetCMD_END; + + if (stod(&rd->mk_config, &fmin, argv[++n]) == NULL) + goto gpGetCMD_END; + + if (n + 1 >= argn) + goto gpGetCMD_END; - n++; - op = argv[n]; + if (stod(&rd->mk_config, &fmax, argv[++n]) == NULL) + goto gpGetCMD_END; + + if (fmin < fmax) { + + failed = 0; + + gp_AxisRange(gp, argi, fmin, fmax); + } + else { + ERROR("CMD: axis range not accepted \"%.16s %.16s\"\n", + argv[n - 1], argv[n]); + + goto gpGetCMD_NEXT; + } + } + else if (*op == 'g') { + + int len; + + op++; + + if (*op == 0) { + + if (n + 1 >= argn) + goto gpGetCMD_END; + + op = argv[++n]; + + len = strlen(op); + op += (len > 4) ? len - 4 : 0; + + if (strlen(argv[n]) >= READ_FILE_PATH_MAX) { + + ERROR("CMD: too long input file name \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; + } +#ifdef _WINDOWS + legacy_ACP_to_UTF8(gp->tempfile, argv[n], READ_FILE_PATH_MAX); +#else /* _WINDOWS */ + strcpy(gp->tempfile, argv[n]); +#endif + + failed = 0; + + if (strcmp(op, ".png") == 0) { + + if (gp_PageSafe(gp) != 0) { + + gp_SavePNG(gp, gp->tempfile); + } + else { + ERROR("CMD: no page selected before \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; + } } + else if (strcmp(op, ".svg") == 0) { - if (stoi(&rd->mk_config, &argi, op) != NULL) { + if (gp_PageSafe(gp) != 0) { - if (argi >= -1 && argi < READ_COLUMN_MAX) { + failed = 0; - rd->timecol = argi; + gp_SaveSVG(gp, gp->tempfile); + } + else { + ERROR("CMD: no page selected before \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; } } + else { + ERROR("CMD: unknown filetype \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; + } } - else { - ERROR("Unknown option \"%c\"\n", *op); - } + } + else if (*op == 'q') { op++; + + if (*op == 0) { + + failed = 0; + + gp->quit = 1; + } + } + +gpGetCMD_END: + if (failed != 0) { + + ERROR("CMD: unknown \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; } } else { if (strlen(argv[n]) >= READ_FILE_PATH_MAX) { - ERROR("Too long input file names\n"); - break; + ERROR("CMD: too long input file name \"%.80s\"\n", argv[n]); + + goto gpGetCMD_NEXT; } #ifdef _WINDOWS legacy_ACP_to_UTF8(gp->tempfile, argv[n], READ_FILE_PATH_MAX); @@ -4726,13 +5557,80 @@ gpGetOPT(gp_t *gp, char *argv[]) gpUnifiedFileOpen(gp, gp->tempfile, 0); } +gpGetCMD_NEXT: n++; } } +static void +gpHelloPage(gpcon_t *gp) +{ + const double payload[] = { + + 21.180, 25.120, 20.298, 42.448, 19.203, 72.868, 18.649, + 106.511, 19.393, 133.510, 22.521, 159.491, 26.570, 178.031, + 30.850, 190.678, 34.669, 198.980, 41.013, 186.502, 45.839, + 176.055, 49.991, 165.249, 54.311, 151.696, 65.768, 151.514, + 77.225, 151.332, 88.682, 151.150, 100.140, 150.968, 101.891, + 159.968, 104.920, 169.501, 110.001, 181.771, 117.909, 198.980, + 125.652, 182.521, 130.473, 168.671, 133.481, 156.518, 135.785, + 145.149, 137.191, 112.465, 136.247, 72.753, 134.526, 39.231, + 133.602, 25.120, 105.497, 25.120, 77.391, 25.120, 49.286, + 25.120, 21.180, 25.120, FP_NAN, FP_NAN, 32.487, 120.416, + 41.887, 125.997, 50.408, 127.691, 58.540, 125.820, 66.771, + 120.710, FP_NAN, FP_NAN, 90.832, 120.397, 100.879, 126.139, + 109.671, 128.016, 117.918, 126.115, 126.329, 120.519, FP_NAN, + FP_NAN, 51.817, 91.523, 66.133, 83.048, 79.760, 81.249, 92.873, + 84.769, 105.648, 92.251, FP_NAN, FP_NAN, 36.994, 25.848, + 43.501, 32.639, 50.371, 35.609, 58.851, 33.517, 70.189, 25.120, + FP_NAN, FP_NAN, 85.189, 25.120, 92.850, 33.737, 101.987, + 36.883, 111.918, 34.147, 121.963, 25.120, FP_NAN, FP_NAN, + 134.434, 40.169, 135.268, 39.659, 139.077, 39.450, 147.824, + 41.521, 163.470, 47.850, 175.241, 59.465, 176.895, 75.080, + 177.196, 93.201, 184.908, 112.335, 189.761, 118.670, 193.306, + 123.087, 195.480, 125.673, 196.219, 126.515, 196.803, 130.617, + 194.349, 133.181, 190.339, 133.762, 186.259, 131.917, 182.574, + 127.680, 177.766, 121.809, 172.436, 114.071, 167.183, 104.232, + 164.575, 91.517, 165.070, 78.686, 164.466, 67.214, 158.560, + 58.576, 151.353, 55.039, 143.859, 52.910, 137.973, 51.867, + 135.590, 51.590, FP_NAN, FP_NAN, -55.581, 25.377 + }; + + const int lN = sizeof(payload) / sizeof(payload[0]); + + int N, cN = 2; + + sprintf(gp->sbuf[0], "load 0 0 stub %d\n" + "page \"Hello, I am Omul\"\n" + "figure 0 1 \"Omul\"\n" + "drawing line 6\n", cN); + + gp_TakeConfig(gp, gp->sbuf[0]); + + for (N = 0; N < lN; N += cN) { + + (void) gp_DataAdd(gp, 0, &payload[N]); + } + + gp_PageCombine(gp, 1, GP_PAGE_SELECT); +} + +#ifdef _WINDOWS +static void +legacy_CloseConsole() +{ + DWORD pLIST[4]; + + if (GetConsoleProcessList(pLIST, 4) == 1) { + + FreeConsole(); + } +} +#endif /* _WINDOWS */ + int main(int argn, char *argv[]) { - gp_t *gp; + gpcon_t *gp; setlocale(LC_NUMERIC, "C"); @@ -4740,29 +5638,47 @@ int main(int argn, char *argv[]) ERROR("SDL_Init: %s\n", SDL_GetError()); - return 1; + return -1; } if (TTF_Init() < 0) { ERROR("TTF_Init: %s\n", SDL_GetError()); - return 1; + return -1; } IMG_Init(IMG_INIT_PNG); gp = gp_Alloc(); - if (argn >= 2) { + if (argn > 1) { - gpGetOPT(gp, argv); + gpGetCMD(gp, argn, argv); } - else { - gpMakeHello(gp); + + if (gp_IsQuit(gp) != 0) { + + goto GP_main_cleanup; } - gp_OpenWindow(gp); + (void) gp_GetSurface(gp); + + if (gp_PageSafe(gp) == 0) { + + gp_PageCombine(gp, 1, GP_PAGE_SELECT); + + if (gp_PageSafe(gp) == 0) { + + gpHelloPage(gp); + } + } + + (void) gp_OpenWindow(gp); + +#ifdef _WINDOWS + legacy_CloseConsole(); +#endif /* _WINDOWS */ while (gp_IsQuit(gp) == 0) { @@ -4779,6 +5695,8 @@ int main(int argn, char *argv[]) } } +GP_main_cleanup: + gp_Clean(gp); SDL_Quit(); diff --git a/pgui/gp/gp.h b/pgui/gp/gp.h index be065c8..40206ab 100644 --- a/pgui/gp/gp.h +++ b/pgui/gp/gp.h @@ -20,21 +20,37 @@ #define _H_GP_ #include -#include -struct gp_struct; +struct gp_context; -typedef struct gp_struct gp_t; +typedef struct gp_context gpcon_t; -gp_t *gp_Alloc(); -void gp_Clean(gp_t *gp); +enum { + GP_PAGE_SELECT = 0, + GP_PAGE_COMBINE, + GP_PAGE_NO_REMAP +}; -void gp_TakeConfig(gp_t *gp, const char *config); -int gp_OpenWindow(gp_t *gp); +gpcon_t *gp_Alloc(); +void gp_Clean(gpcon_t *gp); -void gp_TakeEvent(gp_t *gp, const SDL_Event *ev); -int gp_IsQuit(gp_t *gp); -int gp_Draw(gp_t *gp); +void gp_TakeConfig(gpcon_t *gp, const char *config); +void gp_TakeEvent(gpcon_t *gp, const SDL_Event *ev); + +SDL_Surface *gp_GetSurface(gpcon_t *gp); +Uint32 gp_OpenWindow(gpcon_t *gp); + +int gp_DataAdd(gpcon_t *gp, int dN, const double *payload); +void gp_FileReload(gpcon_t *gp); +void gp_PageCombine(gpcon_t *gp, int pN, int remap); +int gp_PageSafe(gpcon_t *gp); +void gp_AxisRange(gpcon_t *gp, int aN, double min, double max); + +int gp_IsQuit(gpcon_t *gp); +int gp_Draw(gpcon_t *gp); + +void gp_SavePNG(gpcon_t *gp, const char *file); +void gp_SaveSVG(gpcon_t *gp, const char *file); #endif /* _H_GP_ */ diff --git a/pgui/gp/lang.c b/pgui/gp/lang.c index fc7845f..dad6a4b 100644 --- a/pgui/gp/lang.c +++ b/pgui/gp/lang.c @@ -34,10 +34,10 @@ void langFill(lang_t *la, int lang) "C Combine with page ...\0" "B No remap combine ...\0" "R Create subtraction\0" - "M Place figure markers\0" - "T Data slice (on X)\0" - "K Compact axes mode\0" - "E Exponential mode\0" + "M Add figure markers\0" + "T Data slice on X\0" + "K Data pick point\0" + "E Erase selection\0" "Y Copy to clipboard\0" " Language ...\0" " About ...\0" @@ -91,7 +91,7 @@ void langFill(lang_t *la, int lang) la->dataset_menu[3] = " Data median [ %s ]"; la->dataset_menu[4] = " Time scale [ %s ]"; la->dataset_menu[5] = " Length [ %3i ] %iM (%i%%) cache %iM"; - la->dataset_menu[6] = " Close file"; + la->dataset_menu[6] = " [ Close ]"; la->axis_menu = @@ -99,8 +99,8 @@ void langFill(lang_t *la, int lang) "S Slave mode\0" "X Remove the axis\0" "T Data slice\0" - "K Compact mode [ %s ]\0" - "E Exponential mode [ %s ]\0" + " Compact layout [ %s ]\0" + " Exponential mode [ %s ]\0" " Ticks lock [ %s ]\0" " Label ...\0" @@ -156,8 +156,7 @@ void langFill(lang_t *la, int lang) la->figure_operation_menu = " Duplicate figure\0" - " Time median\0" - " Resample all\0" + " Time median ...\0" " Scale on X ...\0" " Scale on Y ...\0" " Add P polynomial ...\0" @@ -166,7 +165,7 @@ void langFill(lang_t *la, int lang) " Add B multiplication\0" " Add B hypotenuse\0" " Add F differences\0" - " Add F cumulative sum\0" + " Add F integral\0" " Add F bit field ...\0" " Add F low pass ...\0" " Add F median ...\0" @@ -176,6 +175,7 @@ void langFill(lang_t *la, int lang) la->legend_menu = " Drawing primitive ...\0" + "N Time resample ...\0" " Scale on X ...\0" " Scale on Y ...\0" " Bake figures to CSV ...\0" @@ -184,17 +184,27 @@ void langFill(lang_t *la, int lang) "\0"; + la->resample_menu[0] = " Dataset [ %s ]"; + la->resample_menu[1] = " Length [ %3i ]"; + la->resample_menu[2] = " Time range [ %s ]"; + la->resample_menu[3] = " Time step [ %s ]"; + la->resample_menu[4] = " Interpolation [ %s ]"; + la->resample_menu[5] = " Threshold [ %2i ]"; + la->resample_menu[6] = " [ OK ]"; + la->databox_menu = - " Close data window\0" " Copy to clipboard\0" + " Decimal precision [ %s ]\0" + " Format hexadecimal [ %s ]\0" + " [ Close ]\0" "\0"; la->cancel_menu = " Cancel\0" - " OK\0" + " [ OK ]\0" "\0"; @@ -209,9 +219,13 @@ void langFill(lang_t *la, int lang) la->length_edit = "Length"; la->figure_thickness_edit = "Thickness"; la->font_size_edit = "Font size"; - la->median_unwrap_edit = "Median and unwrap flags"; + la->median_unwrap_edit = "Median and Flags"; la->marker_density_edit = "Density and Size"; la->gamma_edit = "Gamma"; + la->time_range_edit = "Time range"; + la->precision_edit = "Precision"; + la->time_step_edit = "Time step"; + la->time_threshold_edit = "Time threshold"; } else if (lang == LANG_RU) { @@ -227,10 +241,10 @@ void langFill(lang_t *la, int lang) "C Комбинировать страницы ...\0" "B Без переназначения ...\0" "R Создать вычитание\0" - "M Разместить маркеры фигур\0" - "T Нарезка данных (по X)\0" - "K Режим компактных осей\0" - "E Экспонентный режим\0" + "M Добавить маркеры фигур\0" + "T Нарезка данных по X\0" + "K Выборка точки данных\0" + "E Стирание выбранного\0" "Y Копировать в буфер обмена\0" " Язык ...\0" " О программе ...\0" @@ -284,7 +298,7 @@ void langFill(lang_t *la, int lang) la->dataset_menu[3] = " Медиана данных [ %s ]"; la->dataset_menu[4] = " Масштаб времени [ %s ]"; la->dataset_menu[5] = " Длина [ %3i ] %iM (%i%%) кэш %iM"; - la->dataset_menu[6] = " Закрыть файл"; + la->dataset_menu[6] = " [ Закрыть ]"; la->axis_menu = @@ -292,9 +306,9 @@ void langFill(lang_t *la, int lang) "S Подчиненный режим\0" "X Удалить эту ось\0" "T Нарезка данных\0" - "K Компактный режим [ %s ]\0" - "E Экспонентный режим [ %s ]\0" - " Блокировка линейки [ %s ]\0" + " Компактная укладка [ %s ]\0" + " Экспоненциальный режим [ %s ]\0" + " Блокировка линейки [ %s ]\0" " Текст ...\0" "\0"; @@ -349,17 +363,16 @@ void langFill(lang_t *la, int lang) la->figure_operation_menu = " Дублировать фигуру\0" - " Медиана времени\0" - " Передискретизация\0" + " Медиана времени ...\0" " Масштаб по X ...\0" " Масштаб по Y ...\0" " Добавить P полином ...\0" "R Добавить B вычитание\0" " Добавить B сложение\0" " Добавить B умножение\0" - " Добавить B гипотенуза\0" - " Добавить F разности\0" - " Добавить F накопленная сумма\0" + " Добавить B гипотенузу\0" + " Добавить F производную\0" + " Добавить F интеграл\0" " Добавить F битовое поле ...\0" " Добавить F фильтр НЧ ...\0" " Добавить F медиану ...\0" @@ -369,6 +382,7 @@ void langFill(lang_t *la, int lang) la->legend_menu = " Примитив рисования ...\0" + "N Передискретизация ...\0" " Масштаб по X ...\0" " Масштаб по Y ...\0" " Запечь фигуры в CSV ...\0" @@ -377,17 +391,27 @@ void langFill(lang_t *la, int lang) "\0"; + la->resample_menu[0] = " Набор данных [ %s ]"; + la->resample_menu[1] = " Длина набора [ %3i ]"; + la->resample_menu[2] = " Диапазон времени [ %s ]"; + la->resample_menu[3] = " Шаг времени [ %s ]"; + la->resample_menu[4] = " Интерполяция [ %s ]"; + la->resample_menu[5] = " Пороговое [ %2i ]"; + la->resample_menu[6] = " [ OK ]"; + la->databox_menu = - " Закрыть окно данных\0" " Копировать в буфер обмена\0" + " Десятичная точность [ %s ]\0" + " Выводить шестнадцатеричные [ %s ]\0" + " [ Закрыть ]\0" "\0"; la->cancel_menu = " Отмена\0" - " OK\0" + " [ OK ]\0" "\0"; @@ -396,15 +420,19 @@ void langFill(lang_t *la, int lang) la->axis_label_edit = "Текст Оси"; la->scale_offset_edit = "Масштаб и Смещение"; la->file_name_edit = "Имя Файла"; - la->bit_number_edit = "Дипазон Разрядов"; + la->bit_number_edit = "Диапазон Разрядов"; la->low_pass_edit = "Коэффициент НЧ фильтра"; la->polynomial_edit = "Степень полинома"; la->length_edit = "Длина"; la->figure_thickness_edit = "Толщина"; la->font_size_edit = "Размер шрифта"; - la->median_unwrap_edit = "Медиана и флаги разворота"; + la->median_unwrap_edit = "Медиана и Флаги"; la->marker_density_edit = "Плотность и Размер"; la->gamma_edit = "Гамма"; + la->time_range_edit = "Диапазон времени"; + la->precision_edit = "Точность"; + la->time_step_edit = "Шаг времени"; + la->time_threshold_edit = "Порог времени"; } la->figure_edit_color_menu = @@ -417,6 +445,8 @@ void langFill(lang_t *la, int lang) " \0" " \0" " \0" + " \0" + " \0" "\0"; diff --git a/pgui/gp/lang.h b/pgui/gp/lang.h index a539837..a11ed09 100644 --- a/pgui/gp/lang.h +++ b/pgui/gp/lang.h @@ -37,6 +37,7 @@ typedef struct { const char *figure_edit_color_menu; const char *figure_operation_menu; const char *legend_menu; + const char *resample_menu[7]; const char *databox_menu; const char *cancel_menu; @@ -54,6 +55,10 @@ typedef struct { const char *median_unwrap_edit; const char *marker_density_edit; const char *gamma_edit; + const char *time_range_edit; + const char *precision_edit; + const char *time_step_edit; + const char *time_threshold_edit; } lang_t; diff --git a/pgui/gp/lse.c b/pgui/gp/lse.c index 8960510..c5680cb 100644 --- a/pgui/gp/lse.c +++ b/pgui/gp/lse.c @@ -20,42 +20,49 @@ #include "lse.h" -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 /* Define the maixmal allowed scale of the fast transformation. The input data * range is reduced by this number. Large number allows us to do scaling rarely. * */ #define LSE_DMAX ((lse_float_t) 1048576) -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ -/* Define what external math functions to use in LSE. +#define LSE_RM_TOP(ls) ((ls)->rm + (ls)->n_cascades - 1) + +/* Define built-in branch prediction functions. + * */ +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) + +/* Define which external math functions to use in LSE. * */ #define lse_fabsf(x) fabs(x) #define lse_sqrtf(x) sqrt(x) static void -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, lse_float_t d0, int nz) -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) #endif { lse_float_t *m = rm->m; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_float_t *d = rm->d; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ lse_float_t x0, xi, alpa, beta; int n, i, j; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_float_t di; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ n = (rm->len < rm->keep) ? rm->len : rm->keep; /* Do we have leading zeros? * */ - if (nz > 0) { + if (unlikely(nz > 0)) { m += nz * rm->len - nz * (nz - 1) / 2; } @@ -69,7 +76,7 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) if (x0 != (lse_float_t) 0) { -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 di = d[i]; /* We build the fast Givens transformation. @@ -121,7 +128,7 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) /* Keep diagonal is in allowed range. * */ - if (d[i] > LSE_DMAX * LSE_DMAX) { + if (unlikely(d[i] > LSE_DMAX * LSE_DMAX)) { alpa = (lse_float_t) 1 / LSE_DMAX; @@ -134,7 +141,7 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) d[i] *= (alpa * alpa); } - if (d0 > LSE_DMAX * LSE_DMAX) { + if (unlikely(d0 > LSE_DMAX * LSE_DMAX)) { alpa = (lse_float_t) 1 / LSE_DMAX; @@ -146,7 +153,7 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) d0 *= (alpa * alpa); } -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ /* WARNING: We use naive hypot implementation as it is * the fastest one and quite ulp-accurate. @@ -169,13 +176,13 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) xz[j] = x0; m[j] = xi; } -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ } m += rm->len; } - if (n < rm->len) { + if (unlikely(n < rm->len)) { m += - n; @@ -184,9 +191,9 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) /* We merge the retained row-vector into the upper * cascade matrix before copying the new content. * */ -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_qrupdate(ls, rm + 1, m, d[n], n); -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ lse_qrupdate(ls, rm + 1, m, n); #endif } @@ -196,16 +203,17 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) for (i = n; i < rm->len; ++i) m[i] = xz[i]; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 d[n] = d0; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ } rm->keep += 1; - if (rm->keep >= ls->n_threshold) { + if (unlikely( rm->keep >= ls->n_threshold + && ls->n_cascades >= 2)) { - if (rm < ls->rm + ls->n_cascades - 1) { + if (rm < LSE_RM_TOP(ls)) { /* Mark the cascade matrix content as lazily merged. * */ @@ -223,17 +231,17 @@ lse_qrupdate(lse_t *ls, lse_upper_t *rm, lse_float_t *xz, int nz) } static void -lse_qrmerge(lse_t *ls, lse_upper_t *rm) +lse_qrmerge(lse_t *ls, lse_upper_t *rm, lse_upper_t *um) { - lse_float_t *m = rm->m; -#if LSE_FAST_TRANSFORM != 0 - lse_float_t *d = rm->d; -#endif /* LSE_FAST_TRANSFORM */ + lse_float_t *m = um->m; +#if LSE_FAST_GIVENS != 0 + lse_float_t *d = um->d; +#endif /* LSE_FAST_GIVENS */ int n0, i; - n0 = (rm->lazy != 0) ? rm->len - : (rm->len < rm->keep) ? rm->len : rm->keep; + n0 = (um->lazy != 0) ? um->len + : (um->len < um->keep) ? um->len : um->keep; for (i = 0; i < n0; ++i) { @@ -242,17 +250,90 @@ lse_qrmerge(lse_t *ls, lse_upper_t *rm) /* We extract one by one the row-vectors from cascade * matrix and merge them into the upper cascade matrix. * */ -#if LSE_FAST_TRANSFORM != 0 - lse_qrupdate(ls, rm + 1, m, d[i], i); -#else /* LSE_FAST_TRANSFORM */ - lse_qrupdate(ls, rm + 1, m, i); +#if LSE_FAST_GIVENS != 0 + lse_qrupdate(ls, rm, m, d[i], i); +#else /* LSE_FAST_GIVENS */ + lse_qrupdate(ls, rm, m, i); #endif - m += rm->len; + m += um->len; } - rm->keep = 0; - rm->lazy = 0; + um->keep = 0; + um->lazy = 0; +} + +static void +lse_qrflush(lse_t *ls) +{ + lse_upper_t *rm = LSE_RM_TOP(ls); + + int i, len, nul; + + for (i = 0; i < ls->n_cascades - 1; ++i) { + + /* We merge all cascades into the top \rm matrix. + * */ + lse_qrmerge(ls, &ls->rm[i + 1], &ls->rm[i]); + } + + if (unlikely(rm->keep < rm->len)) { + + /* Zero out uninitialized tail content. + * */ + len = rm->keep * rm->len - rm->keep * (rm->keep - 1) / 2; + nul = rm->len * (rm->len + 1) / 2; + + for (i = len; i < nul; ++i) + rm->m[i] = (lse_float_t) 0; + +#if LSE_FAST_GIVENS != 0 + for (i = rm->keep; i < rm->len; ++i) + rm->d[i] = (lse_float_t) 1; +#endif /* LSE_FAST_GIVENS */ + + rm->keep = rm->len; + } +} + +static void +lse_qrstep(lse_t *ls, lse_upper_t *um, lse_upper_t *im, lse_float_t *u) +{ + lse_float_t *mq = im->m; +#if LSE_FAST_GIVENS != 0 + lse_float_t *d = um->d; +#endif /* LSE_FAST_GIVENS */ + lse_float_t *m; + + int i, j; + + um->keep = 0; + um->lazy = 0; + + /* Here we transpose the input matrix \im and bring it to the + * upper-triangular form again and store into \um. + * */ + for (i = 0; i < um->len; ++i) { + + m = mq; + + for (j = 0; j < i + 1; ++j) { + + u[j] = m[0]; + m += im->len - (j + 1); + } + + for (j = i + 1; j < um->len; ++j) + u[j] = (lse_float_t) 0; + +#if LSE_FAST_GIVENS != 0 + lse_qrupdate(ls, um, u, d[i], 0); +#else /* LSE_FAST_GIVENS */ + lse_qrupdate(ls, um, u, 0); +#endif + + mq += 1; + } } int lse_getsize(int n_cascades, int n_full) @@ -263,9 +344,9 @@ int lse_getsize(int n_cascades, int n_full) n_vm = n_cascades * n_full * (n_full + 1) / 2 -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 + n_cascades * n_full -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ + n_full * n_full / 4 + n_full / 2 + 1; @@ -284,7 +365,7 @@ void lse_construct(lse_t *ls, int n_cascades, int n_len_of_x, int n_len_of_z) n_full = n_len_of_x + n_len_of_z; - ls->n_threshold = n_full * 10; + ls->n_threshold = n_full * 4; ls->n_total = 0; for (i = 0; i < ls->n_cascades; ++i) { @@ -296,10 +377,10 @@ void lse_construct(lse_t *ls, int n_cascades, int n_len_of_x, int n_len_of_z) vm += n_full * (n_full + 1) / 2; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 ls->rm[i].d = vm; vm += n_full; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ } ls->sol.len = ls->n_len_of_x * ls->n_len_of_z; @@ -314,9 +395,9 @@ void lse_construct(lse_t *ls, int n_cascades, int n_len_of_x, int n_len_of_z) void lse_insert(lse_t *ls, lse_float_t *xz) { -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_qrupdate(ls, ls->rm, xz, (lse_float_t) 1, 0); -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ lse_qrupdate(ls, ls->rm, xz, 0); #endif @@ -338,9 +419,9 @@ void lse_ridge(lse_t *ls, lse_float_t la) for (j = i + 1; j < ls->rm[0].len; ++j) xz[j] = (lse_float_t) 0; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_qrupdate(ls, ls->rm, xz, (lse_float_t) 1, i); -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ lse_qrupdate(ls, ls->rm, xz, i); #endif } @@ -363,7 +444,7 @@ void lse_forget(lse_t *ls, lse_float_t la) len = n0 * rm->len - n0 * (n0 - 1) / 2; - /* We just scale \R matrices with factor \la. + /* We just scale \rm matrices with factor \la. * */ for (j = 0; j < len; ++j) rm->m[j] *= la; @@ -371,49 +452,49 @@ void lse_forget(lse_t *ls, lse_float_t la) } } -static void -lse_merge(lse_t *ls) +void lse_merge(lse_t *ls, lse_t *lb) { - lse_upper_t *rm = ls->rm + ls->n_cascades - 1; + lse_upper_t *um = LSE_RM_TOP(lb); - int i, len, nul; + lse_float_t *m = um->m; +#if LSE_FAST_GIVENS != 0 + lse_float_t *d = um->d; +#endif /* LSE_FAST_GIVENS */ - for (i = 0; i < ls->n_cascades - 1; ++i) { + int i; - /* We merge all cascades into the top \R matrix. - * */ - lse_qrmerge(ls, ls->rm + i); - } + lse_qrflush(lb); - if (rm->keep < rm->len) { + for (i = 0; i < um->len; ++i) { - /* Zero out uninitialized tail content. - * */ - len = rm->keep * rm->len - rm->keep * (rm->keep - 1) / 2; - nul = rm->len * (rm->len + 1) / 2; + m += - i; - for (i = len; i < nul; ++i) - rm->m[i] = (lse_float_t) 0; + /* TODO: Here you could shuffle \um columns. + * */ -#if LSE_FAST_TRANSFORM != 0 - for (i = rm->keep; i < rm->len; ++i) - rm->d[i] = (lse_float_t) 1; -#endif /* LSE_FAST_TRANSFORM */ + /* We extract one by one the row-vectors from \lb instance and + * merge them into the \ls instance. + * */ +#if LSE_FAST_GIVENS != 0 + lse_qrupdate(ls, ls->rm, m, d[i], i); +#else /* LSE_FAST_GIVENS */ + lse_qrupdate(ls, ls->rm, m, i); +#endif - rm->keep = rm->len; + m += um->len; } } void lse_solve(lse_t *ls) { - lse_upper_t *rm = ls->rm + ls->n_cascades - 1; + lse_upper_t *rm = LSE_RM_TOP(ls); lse_float_t *sol = ls->sol.m; lse_float_t *mq, *m, u; int n, i, j; - lse_merge(ls); + lse_qrflush(ls); mq = rm->m + (ls->n_len_of_x - 1) * rm->len - ls->n_len_of_x * (ls->n_len_of_x - 1) / 2; @@ -442,33 +523,33 @@ void lse_solve(lse_t *ls) void lse_std(lse_t *ls) { - lse_upper_t *rm = ls->rm + ls->n_cascades - 1; + lse_upper_t *rm = LSE_RM_TOP(ls); lse_float_t *std = ls->std.m; lse_float_t *mq, *m, u, ratio; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 lse_float_t *d = rm->d + ls->n_len_of_x; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ int i, j; - lse_merge(ls); + lse_qrflush(ls); mq = rm->m + ls->n_len_of_x * rm->len - ls->n_len_of_x * (ls->n_len_of_x - 1) / 2; ratio = (lse_float_t) 1 / (lse_float_t) (ls->n_total - 1); - /* We calculate l2 norm over \Rz columns. + /* We calculate l2 norm over \rm columns. * */ for (i = 0; i < ls->n_len_of_z; ++i) { m = mq; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 u = m[0] * m[0] / d[0]; -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ u = m[0] * m[0]; #endif @@ -476,9 +557,9 @@ void lse_std(lse_t *ls) m += rm->len - (ls->n_len_of_x + j); -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 u += m[0] * m[0] / d[j]; -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ u += m[0] * m[0]; #endif } @@ -489,66 +570,26 @@ void lse_std(lse_t *ls) } } -static void -lse_qrstep(lse_t *ls, lse_upper_t *um, lse_upper_t *im, lse_float_t *vm) -{ - lse_float_t *mq = im->m; -#if LSE_FAST_TRANSFORM != 0 - lse_float_t *ud = um->d; -#endif /* LSE_FAST_TRANSFORM */ - lse_float_t *m; - - int i, j; - - um->keep = 0; - um->lazy = 0; - - /* Here we transpose the input matrix \im and bring it to the - * upper-triangular form again and store into \um. - * */ - for (i = 0; i < um->len; ++i) { - - m = mq; - - for (j = 0; j < i + 1; ++j) { - - vm[j] = m[0]; - m += im->len - (j + 1); - } - - for (j = i + 1; j < um->len; ++j) - vm[j] = (lse_float_t) 0; - -#if LSE_FAST_TRANSFORM != 0 - lse_qrupdate(ls, um, vm, ud[i], 0); -#else /* LSE_FAST_TRANSFORM */ - lse_qrupdate(ls, um, vm, 0); -#endif - - mq += 1; - } -} - void lse_esv(lse_t *ls, int n_approx) { - lse_upper_t um, im, *rm = ls->rm + ls->n_cascades - 1; + lse_upper_t um, im, *rm = LSE_RM_TOP(ls); lse_float_t *m, u; int len, i; - lse_merge(ls); + lse_qrflush(ls); len = ls->n_len_of_x * (ls->n_len_of_x + 1) + ls->n_len_of_x * 3; if (ls->rm[0].m + len <= rm->m) { - /* We allocate temporal \Rx matrices instead of \R + /* We allocate temporal \um matrices instead of \rm * cascades that are empty after merge. * */ m = ls->rm[0].m; } else { - /* WARNING: We allocate temporal \Rx matrices in tail + /* WARNING: We allocate temporal \um matrices in tail * of LSE memory instead of \b and so on. * */ m = ls->sol.m; @@ -559,28 +600,28 @@ void lse_esv(lse_t *ls, int n_approx) m += ls->n_len_of_x * (ls->n_len_of_x + 1) / 2; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 um.d = m; m += ls->n_len_of_x; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ im.len = ls->n_len_of_x; im.m = m; m += ls->n_len_of_x * (ls->n_len_of_x + 1) / 2; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 im.d = m; m += ls->n_len_of_x; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 for (i = 0; i < ls->n_len_of_x; ++i) { um.d[i] = (lse_float_t) 1; im.d[i] = rm->d[i]; } -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ /* First step of QR algorithm. * */ @@ -601,17 +642,17 @@ void lse_esv(lse_t *ls, int n_approx) m = um.m; - /* We are looking for the largest and smallest diagonal elements of \Rx. + /* We are looking for the largest and smallest diagonal elements of \um. * */ for (i = 0; i < ls->n_len_of_x; ++i) { -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 u = lse_fabsf(m[0] / lse_sqrtf(um.d[i] * im.d[i])); -#else /* LSE_FAST_TRANSFORM */ +#else /* LSE_FAST_GIVENS */ u = lse_fabsf(m[0]); #endif - if (i != 0) { + if (likely(i != 0)) { ls->esv.max = (ls->esv.max < u) ? u : ls->esv.max; ls->esv.min = (ls->esv.min > u) ? u : ls->esv.min; diff --git a/pgui/gp/lse.h b/pgui/gp/lse.h index 1c9addd..3487301 100644 --- a/pgui/gp/lse.h +++ b/pgui/gp/lse.h @@ -32,7 +32,7 @@ /* Define whether to use fast Givens transformation in QR update. Typical this * is useful for fairly large matrix sizes. Also consumes a few of memory. * */ -#define LSE_FAST_TRANSFORM 1 +#define LSE_FAST_GIVENS 1 /* Define native floating-point type to use inside of LSE. * */ @@ -56,11 +56,11 @@ typedef struct { * */ lse_float_t *m; -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 /* Content of the scale diagonal matrix. * */ lse_float_t *d; -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ } lse_upper_t; @@ -92,17 +92,17 @@ typedef struct { int n_threshold; int n_total; - /* \R(i) is row-major upper-triangular matrix array with block + /* \rm(i) is row-major upper-triangular matrix array with block * structure as shown. We store only the upper triangular elements. * - * [0 1 2 3] - * [ 4 5 6] - * [Rx S ] [ 7 8] - * R(i) = [0 Rz], (ex.) = [ 9]. + * [0 1 2 3] + * [ 4 5 6] + * [ RX S ] [ 7 8] + * \rm(i) = [ 0 RZ ], (ex.) = [ 9]. * - * Rx - upper-triangular matrix size of \x, - * Rz - upper-triangular matrix size of \z, - * S - rectangular matrix size of \x by \z. + * \RX - upper-triangular matrix size of \x, + * \RZ - upper-triangular matrix size of \z, + * \S - rectangular matrix size of \x by \z. * * */ lse_upper_t rm[LSE_CASCADE_MAX]; @@ -115,7 +115,7 @@ typedef struct { * */ lse_row_t std; - /* Approximate extremal singular values of \Rx. + /* Approximate extremal singular values of \RX. * */ struct { @@ -128,9 +128,9 @@ typedef struct { * */ lse_float_t vm[LSE_CASCADE_MAX * LSE_FULL_MAX * (LSE_FULL_MAX + 1) / 2 -#if LSE_FAST_TRANSFORM != 0 +#if LSE_FAST_GIVENS != 0 + LSE_CASCADE_MAX * LSE_FULL_MAX -#endif /* LSE_FAST_TRANSFORM */ +#endif /* LSE_FAST_GIVENS */ + LSE_FULL_MAX * LSE_FULL_MAX / 4 + LSE_FULL_MAX / 2 + 1]; } @@ -145,9 +145,9 @@ int lse_getsize(int n_cascades, int n_full); * */ void lse_construct(lse_t *ls, int n_cascades, int n_len_of_x, int n_len_of_z); -/* The function updates \R with a new data row-vector \xz which contains \x and - * \z concatenated. We does QR update of \R by orthogonal transformation. Note - * that the contents of \xz will be destroyed. +/* The function updates \rm with a new data row-vector \xz which contains \x + * and \z concatenated. We are doing QR update of \rm by orthogonal + * transformation. Note that the contents of \xz will be destroyed. * */ void lse_insert(lse_t *ls, lse_float_t *xz); @@ -156,11 +156,16 @@ void lse_insert(lse_t *ls, lse_float_t *xz); * */ void lse_ridge(lse_t *ls, lse_float_t la); -/* The function scales all cascades of \R with forgetting factor \la. It is +/* The function scales all cascades of \rm with forgetting factor \la. It is * reasonable to use this function with only one cascade allocated. * */ void lse_forget(lse_t *ls, lse_float_t la); +/* The function updates \rm of \ls instance with data rows from \rm of \lb + * instance. This is a merge of two LSE instances. + * */ +void lse_merge(lse_t *ls, lse_t *lb); + /* The function calculates the final LS solution \b. * */ void lse_solve(lse_t *ls); @@ -170,12 +175,12 @@ void lse_solve(lse_t *ls); void lse_std(lse_t *ls); /* The function estimates the approximate largest and smallest singular values - * of \Rx in \n_approx iterations. A rather computationally heavy function if - * \n_approx is large (most reasonable is 4). You can calculate the conditional + * of \RX in \n_approx iterations. A rather computationally heavy function if + * \n_approx is large (most reasonable is 2). You can calculate the conditional * number or detect a rank deficiency based on retrieved values. * * WARNING: You need to provide enough memory to use this function. We use - * empty cascades of \R as temporal storage. + * empty cascades of \rm as temporal storage. * * */ void lse_esv(lse_t *ls, int n_approx); diff --git a/pgui/gp/lz4.c b/pgui/gp/lz4.c index 0a72759..a2f7abe 100644 --- a/pgui/gp/lz4.c +++ b/pgui/gp/lz4.c @@ -124,14 +124,17 @@ # include /* only present in VS2005+ */ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ # pragma warning(disable : 6237) /* disable: C6237: conditional expression is always 0 */ +# pragma warning(disable : 6239) /* disable: C6239: ( && ) always evaluates to the result of */ +# pragma warning(disable : 6240) /* disable: C6240: ( && ) always evaluates to the result of */ +# pragma warning(disable : 6326) /* disable: C6326: Potential comparison of a constant with another constant */ #endif /* _MSC_VER */ #ifndef LZ4_FORCE_INLINE -# ifdef _MSC_VER /* Visual Studio */ +# if defined (_MSC_VER) && !defined (__clang__) /* MSVC */ # define LZ4_FORCE_INLINE static __forceinline # else # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ -# ifdef __GNUC__ +# if defined (__GNUC__) || defined (__clang__) # define LZ4_FORCE_INLINE static inline __attribute__((always_inline)) # else # define LZ4_FORCE_INLINE static inline @@ -430,7 +433,7 @@ static U16 LZ4_readLE16(const void* memPtr) return LZ4_read16(memPtr); } else { const BYTE* p = (const BYTE*)memPtr; - return (U16)((U16)p[0] + (p[1]<<8)); + return (U16)((U16)p[0] | (p[1]<<8)); } } @@ -441,7 +444,7 @@ static U32 LZ4_readLE32(const void* memPtr) return LZ4_read32(memPtr); } else { const BYTE* p = (const BYTE*)memPtr; - return (U32)p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24); + return (U32)p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); } } #endif @@ -527,7 +530,7 @@ LZ4_wildCopy32(void* dstPtr, const void* srcPtr, void* dstEnd) /* LZ4_memcpy_using_offset() presumes : * - dstEnd >= dstPtr + MINMATCH - * - there is at least 8 bytes available to write after dstEnd */ + * - there is at least 12 bytes available to write after dstEnd */ LZ4_FORCE_INLINE void LZ4_memcpy_using_offset(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const size_t offset) { @@ -1118,7 +1121,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic_validated( goto _last_literals; } if (litLength >= RUN_MASK) { - int len = (int)(litLength - RUN_MASK); + unsigned len = litLength - RUN_MASK; *token = (RUN_MASK<= 255 ; len-=255) *op++ = 255; *op++ = (BYTE)len; @@ -1579,8 +1582,11 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_stream) #endif +typedef enum { _ld_fast, _ld_slow } LoadDict_mode_e; #define HASH_UNIT sizeof(reg_t) -int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) +int LZ4_loadDict_internal(LZ4_stream_t* LZ4_dict, + const char* dictionary, int dictSize, + LoadDict_mode_e _ld) { LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; const tableType_t tableType = byU32; @@ -1616,13 +1622,39 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) while (p <= dictEnd-HASH_UNIT) { U32 const h = LZ4_hashPosition(p, tableType); + /* Note: overwriting => favors positions end of dictionary */ LZ4_putIndexOnHash(idx32, h, dict->hashTable, tableType); p+=3; idx32+=3; } + if (_ld == _ld_slow) { + /* Fill hash table with additional references, to improve compression capability */ + p = dict->dictionary; + idx32 = dict->currentOffset - dict->dictSize; + while (p <= dictEnd-HASH_UNIT) { + U32 const h = LZ4_hashPosition(p, tableType); + U32 const limit = dict->currentOffset - 64 KB; + if (LZ4_getIndexOnHash(h, dict->hashTable, tableType) <= limit) { + /* Note: not overwriting => favors positions beginning of dictionary */ + LZ4_putIndexOnHash(idx32, h, dict->hashTable, tableType); + } + p++; idx32++; + } + } + return (int)dict->dictSize; } +int LZ4_loadDict(LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) +{ + return LZ4_loadDict_internal(LZ4_dict, dictionary, dictSize, _ld_fast); +} + +int LZ4_loadDictSlow(LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) +{ + return LZ4_loadDict_internal(LZ4_dict, dictionary, dictSize, _ld_slow); +} + void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream) { const LZ4_stream_t_internal* dictCtx = (dictionaryStream == NULL) ? NULL : @@ -2042,7 +2074,7 @@ LZ4_decompress_generic( * note : fast loop may show a regression for some client arm chips. */ #if LZ4_FAST_DEC_LOOP if ((oend - op) < FASTLOOP_SAFE_DISTANCE) { - DEBUGLOG(6, "skip fast decode loop"); + DEBUGLOG(6, "move to safe decode loop"); goto safe_decode; } @@ -2054,6 +2086,7 @@ LZ4_decompress_generic( assert(ip < iend); token = *ip++; length = token >> ML_BITS; /* literal length */ + DEBUGLOG(7, "blockPos%6u: litLength token = %u", (unsigned)(op-(BYTE*)dst), (unsigned)length); /* decode literal length */ if (length == RUN_MASK) { @@ -2083,21 +2116,23 @@ LZ4_decompress_generic( /* get offset */ offset = LZ4_readLE16(ip); ip+=2; - DEBUGLOG(6, " offset = %zu", offset); + DEBUGLOG(6, "blockPos%6u: offset = %u", (unsigned)(op-(BYTE*)dst), (unsigned)offset); match = op - offset; assert(match <= op); /* overflow check */ /* get matchlength */ length = token & ML_MASK; + DEBUGLOG(7, " match length token = %u (len==%u)", (unsigned)length, (unsigned)length+MINMATCH); if (length == ML_MASK) { size_t const addl = read_variable_length(&ip, iend - LASTLITERALS + 1, 0); if (addl == rvl_error) { - DEBUGLOG(6, "error reading long match length"); + DEBUGLOG(5, "error reading long match length"); goto _output_error; } length += addl; length += MINMATCH; + DEBUGLOG(7, " long match length == %u", (unsigned)length); if (unlikely((uptrval)(op)+length<(uptrval)op)) { goto _output_error; } /* overflow detection */ if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) { goto safe_match_copy; @@ -2105,6 +2140,7 @@ LZ4_decompress_generic( } else { length += MINMATCH; if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) { + DEBUGLOG(7, "moving to safe_match_copy (ml==%u)", (unsigned)length); goto safe_match_copy; } @@ -2123,7 +2159,7 @@ LZ4_decompress_generic( } } } if ( checkOffset && (unlikely(match + dictSize < lowPrefix)) ) { - DEBUGLOG(6, "Error : pos=%zi, offset=%zi => outside buffers", op-lowPrefix, op-match); + DEBUGLOG(5, "Error : pos=%zi, offset=%zi => outside buffers", op-lowPrefix, op-match); goto _output_error; } /* match starting within external dictionary */ @@ -2180,6 +2216,7 @@ LZ4_decompress_generic( assert(ip < iend); token = *ip++; length = token >> ML_BITS; /* literal length */ + DEBUGLOG(7, "blockPos%6u: litLength token = %u", (unsigned)(op-(BYTE*)dst), (unsigned)length); /* A two-stage shortcut for the most common case: * 1) If the literal length is 0..14, and there is enough space, @@ -2200,6 +2237,7 @@ LZ4_decompress_generic( /* The second stage: prepare for match copying, decode full info. * If it doesn't work out, the info won't be wasted. */ length = token & ML_MASK; /* match length */ + DEBUGLOG(7, "blockPos%6u: matchLength token = %u (len=%u)", (unsigned)(op-(BYTE*)dst), (unsigned)length, (unsigned)length + 4); offset = LZ4_readLE16(ip); ip += 2; match = op - offset; assert(match <= op); /* check overflow */ @@ -2272,9 +2310,10 @@ LZ4_decompress_generic( * so check that we exactly consume the input and don't overrun the output buffer. */ if ((ip+length != iend) || (cpy > oend)) { - DEBUGLOG(6, "should have been last run of literals") - DEBUGLOG(6, "ip(%p) + length(%i) = %p != iend (%p)", ip, (int)length, ip+length, iend); - DEBUGLOG(6, "or cpy(%p) > oend(%p)", cpy, oend); + DEBUGLOG(5, "should have been last run of literals") + DEBUGLOG(5, "ip(%p) + length(%i) = %p != iend (%p)", ip, (int)length, ip+length, iend); + DEBUGLOG(5, "or cpy(%p) > (oend-MFLIMIT)(%p)", cpy, oend-MFLIMIT); + DEBUGLOG(5, "after writing %u bytes / %i bytes available", (unsigned)(op-(BYTE*)dst), outputSize); goto _output_error; } } @@ -2300,6 +2339,7 @@ LZ4_decompress_generic( /* get matchlength */ length = token & ML_MASK; + DEBUGLOG(7, "blockPos%6u: matchLength token = %u", (unsigned)(op-(BYTE*)dst), (unsigned)length); _copy_match: if (length == ML_MASK) { @@ -2389,7 +2429,7 @@ LZ4_decompress_generic( while (op < cpy) { *op++ = *match++; } } else { LZ4_memcpy(op, match, 8); - if (length > 16) { LZ4_wildCopy8(op+8, match+8, cpy); } + if (length > 16) { LZ4_wildCopy8(op+8, match+8, cpy); } } op = cpy; /* wildcopy correction */ } diff --git a/pgui/gp/lz4.h b/pgui/gp/lz4.h index 7a2dbfd..80e3e5c 100644 --- a/pgui/gp/lz4.h +++ b/pgui/gp/lz4.h @@ -129,8 +129,8 @@ extern "C" { /*------ Version ------*/ #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */ -#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */ -#define LZ4_VERSION_RELEASE 5 /* for tweaks, bug-fixes, or development */ +#define LZ4_VERSION_MINOR 10 /* for new (non-breaking) interface capabilities */ +#define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) @@ -148,6 +148,7 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; **************************************/ /*! * LZ4_MEMORY_USAGE : + * Can be selected at compile time, by setting LZ4_MEMORY_USAGE. * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB) * Increasing memory usage improves compression ratio, generally at the cost of speed. * Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality. @@ -157,6 +158,7 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; # define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT #endif +/* These are absolute limits, they should not be changed by users */ #define LZ4_MEMORY_USAGE_MIN 10 #define LZ4_MEMORY_USAGE_DEFAULT 14 #define LZ4_MEMORY_USAGE_MAX 20 @@ -368,6 +370,51 @@ LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr); */ LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize); +/*! LZ4_loadDictSlow() : v1.10.0+ + * Same as LZ4_loadDict(), + * but uses a bit more cpu to reference the dictionary content more thoroughly. + * This is expected to slightly improve compression ratio. + * The extra-cpu cost is likely worth it if the dictionary is re-used across multiple sessions. + * @return : loaded dictionary size, in bytes (note: only the last 64 KB are loaded) + */ +LZ4LIB_API int LZ4_loadDictSlow(LZ4_stream_t* streamPtr, const char* dictionary, int dictSize); + +/*! LZ4_attach_dictionary() : stable since v1.10.0 + * + * This allows efficient re-use of a static dictionary multiple times. + * + * Rather than re-loading the dictionary buffer into a working context before + * each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a + * working LZ4_stream_t, this function introduces a no-copy setup mechanism, + * in which the working stream references @dictionaryStream in-place. + * + * Several assumptions are made about the state of @dictionaryStream. + * Currently, only states which have been prepared by LZ4_loadDict() or + * LZ4_loadDictSlow() should be expected to work. + * + * Alternatively, the provided @dictionaryStream may be NULL, + * in which case any existing dictionary stream is unset. + * + * If a dictionary is provided, it replaces any pre-existing stream history. + * The dictionary contents are the only history that can be referenced and + * logically immediately precede the data compressed in the first subsequent + * compression call. + * + * The dictionary will only remain attached to the working stream through the + * first compression call, at the end of which it is cleared. + * @dictionaryStream stream (and source buffer) must remain in-place / accessible / unchanged + * through the completion of the compression session. + * + * Note: there is no equivalent LZ4_attach_*() method on the decompression side + * because there is no initialization cost, hence no need to share the cost across multiple sessions. + * To decompress LZ4 blocks using dictionary, attached or not, + * just employ the regular LZ4_setStreamDecode() for streaming, + * or the stateless LZ4_decompress_safe_usingDict() for one-shot decompression. + */ +LZ4LIB_API void +LZ4_attach_dictionary(LZ4_stream_t* workingStream, + const LZ4_stream_t* dictionaryStream); + /*! LZ4_compress_fast_continue() : * Compress 'src' content using data from previously compressed blocks, for better compression ratio. * 'dst' buffer must be already allocated. @@ -563,43 +610,12 @@ LZ4_decompress_safe_partial_usingDict(const char* src, char* dst, */ LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); -/*! LZ4_compress_destSize_extState() : +/*! LZ4_compress_destSize_extState() : introduced in v1.10.0 * Same as LZ4_compress_destSize(), but using an externally allocated state. * Also: exposes @acceleration */ int LZ4_compress_destSize_extState(void* state, const char* src, char* dst, int* srcSizePtr, int targetDstSize, int acceleration); -/*! LZ4_attach_dictionary() : - * This is an experimental API that allows - * efficient use of a static dictionary many times. - * - * Rather than re-loading the dictionary buffer into a working context before - * each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a - * working LZ4_stream_t, this function introduces a no-copy setup mechanism, - * in which the working stream references the dictionary stream in-place. - * - * Several assumptions are made about the state of the dictionary stream. - * Currently, only streams which have been prepared by LZ4_loadDict() should - * be expected to work. - * - * Alternatively, the provided dictionaryStream may be NULL, - * in which case any existing dictionary stream is unset. - * - * If a dictionary is provided, it replaces any pre-existing stream history. - * The dictionary contents are the only history that can be referenced and - * logically immediately precede the data compressed in the first subsequent - * compression call. - * - * The dictionary will only remain attached to the working stream through the - * first compression call, at the end of which it is cleared. The dictionary - * stream (and source buffer) must remain in-place / accessible / unchanged - * through the completion of the first compression call on the stream. - */ -LZ4LIB_STATIC_API void -LZ4_attach_dictionary(LZ4_stream_t* workingStream, - const LZ4_stream_t* dictionaryStream); - - /*! In-place compression and decompression * * It's possible to have input and output sharing the same buffer, diff --git a/pgui/gp/menu.c b/pgui/gp/menu.c index b7934cc..1afb8b6 100644 --- a/pgui/gp/menu.c +++ b/pgui/gp/menu.c @@ -181,7 +181,7 @@ menu_t *menuAlloc(draw_t *dw, scheme_t *sch) { menu_t *mu; - mu = calloc(1, sizeof(menu_t)); + mu = (menu_t *) calloc(1, sizeof(menu_t)); mu->dw = dw; mu->sch = sch; diff --git a/pgui/gp/plot.c b/pgui/gp/plot.c index 480894b..3d97585 100644 --- a/pgui/gp/plot.c +++ b/pgui/gp/plot.c @@ -62,7 +62,7 @@ plot_t *plotAlloc(draw_t *dw, scheme_t *sch) plot_t *pl; int N; - pl = calloc(1, sizeof(plot_t)); + pl = (plot_t *) calloc(1, sizeof(plot_t)); pl->dw = dw; pl->sch = sch; @@ -103,6 +103,7 @@ plot_t *plotAlloc(draw_t *dw, scheme_t *sch) pl->transparency = 1; pl->fprecision = 9; + pl->fhexadecimal = 1; pl->lz4_compress = 1; return pl; @@ -145,12 +146,13 @@ void plotClean(plot_t *pl) static void plotFontLayout(plot_t *pl) { - TTF_SizeUTF8(pl->font, "M", &pl->layout_font_long, &pl->layout_font_height); + TTF_SizeUTF8(pl->font, "Ab", &pl->layout_font_long, &pl->layout_font_height); + pl->layout_font_long /= 2; pl->layout_font_height = TTF_FontHeight(pl->font); pl->layout_font_space = pl->layout_font_long * 14 / 10; - pl->layout_axis_box = pl->layout_tick_tooth + pl->layout_font_height; + pl->layout_ruler_box = pl->layout_tick_tooth + pl->layout_font_height; pl->layout_label_box = pl->layout_font_height; pl->layout_mark_size = pl->layout_font_height * pl->mark_size / 200; @@ -353,7 +355,7 @@ unsigned long long plotDataMemoryCached(plot_t *pl, int dN) } static int -plotDataCacheGetNode(plot_t *pl, int dN, int kN) +plotDataCacheGetNode(plot_t *pl, int dN) { int N, kNOT, xN = -1; @@ -391,7 +393,7 @@ plotDataCacheFetch(plot_t *pl, int dN, int kN) { int xN, kNZ, lzLEN; - xN = plotDataCacheGetNode(pl, dN, kN); + xN = plotDataCacheGetNode(pl, dN); if (pl->data[dN].cache[xN].raw != NULL) { @@ -413,10 +415,9 @@ plotDataCacheFetch(plot_t *pl, int dN, int kN) ERROR("Unable to allocate LZ4 memory of %i dataset\n", dN); } - lzLEN = LZ4_compress_default( - (const char *) pl->data[dN].cache[xN].raw, + lzLEN = LZ4_compress_fast((const char *) pl->data[dN].cache[xN].raw, (char *) pl->data[dN].compress[kNZ].raw, - pl->data[dN].chunk_bSIZE, lzLEN); + pl->data[dN].chunk_bSIZE, lzLEN, 1); if (lzLEN > 0) { @@ -452,10 +453,8 @@ plotDataCacheFetch(plot_t *pl, int dN, int kN) if (pl->data[dN].compress[kN].raw != NULL) { - lzLEN = LZ4_decompress_safe( - (const char *) pl->data[dN].compress[kN].raw, - (char *) pl->data[dN].raw[kN], - pl->data[dN].compress[kN].length, + lzLEN = LZ4_decompress_safe((const char *) pl->data[dN].compress[kN].raw, + (char *) pl->data[dN].raw[kN], pl->data[dN].compress[kN].length, pl->data[dN].chunk_bSIZE); if (lzLEN != pl->data[dN].chunk_bSIZE) { @@ -502,6 +501,7 @@ plotDataChunkWrite(plot_t *pl, int dN, int kN) void plotDataAlloc(plot_t *pl, int dN, int cN, int lN) { int *map; + int N, bSIZE; if (dN < 0 || dN >= PLOT_DATASET_MAX) { @@ -530,7 +530,10 @@ void plotDataAlloc(plot_t *pl, int dN, int cN, int lN) return ; } - plotSketchClean(pl); + if (plotFigureHaveData(pl, dN) != 0) { + + plotSketchClean(pl); + } plotDataRangeCacheClean(pl, dN); plotDataChunkAlloc(pl, dN, lN); @@ -545,7 +548,7 @@ void plotDataAlloc(plot_t *pl, int dN, int cN, int lN) for (N = 0; N < 30; ++N) { - bSIZE = sizeof(fval_t) * (cN + PLOT_SUBTRACT) * (1UL << N); + bSIZE = (int) sizeof(fval_t) * (cN + PLOT_SUBTRACT) * (1UL << N); if (bSIZE >= PLOT_CHUNK_SIZE) { @@ -582,7 +585,7 @@ void plotDataAlloc(plot_t *pl, int dN, int cN, int lN) pl->data[dN].map = (int *) map + 1; - for (N = -1; N < (cN + PLOT_SUBTRACT); ++N) { + for (N = -1; N < cN + PLOT_SUBTRACT; ++N) { pl->data[dN].map[N] = -1; } @@ -617,14 +620,19 @@ void plotDataResize(plot_t *pl, int dN, int lN) } } -int plotDataSpaceLeft(plot_t *pl, int dN) +int plotDataLength(plot_t *pl, int dN) { int N; N = pl->data[dN].tail_N - pl->data[dN].head_N; N += (N < 0) ? pl->data[dN].length_N : 0; - return pl->data[dN].length_N - N; + return N; +} + +int plotDataSpaceLeft(plot_t *pl, int dN) +{ + return pl->data[dN].length_N - plotDataLength(pl, dN); } void plotDataGrowUp(plot_t *pl, int dN) @@ -643,6 +651,7 @@ static const fval_t * plotDataGet(plot_t *pl, int dN, int *rN) { const fval_t *row = NULL; + int lN, kN, jN; if (*rN != pl->data[dN].tail_N) { @@ -784,7 +793,7 @@ static tuple_t plotDataMedianAdd(plot_t *pl, int dN, int sN, double fval, double fpay) { int index[PLOT_MEDIAN_MAX]; - int N, Nq, N0, N1, length, keep, tail, N_len; + int N, Nq, N0, N1, length, keep, tail, total; tuple_t mN = { -1, -1 }; @@ -801,15 +810,15 @@ plotDataMedianAdd(plot_t *pl, int dN, int sN, double fval, double fpay) pl->data[dN].sub[sN].op.median.keep = keep; pl->data[dN].sub[sN].op.median.tail = tail; - for (N = 0, N_len = 0; N < keep; ++N) { + for (N = 0, total = 0; N < keep; ++N) { fval = pl->data[dN].sub[sN].op.median.window[N].fval; if (fp_isfinite(fval)) { - index[N_len++] = N; + index[total++] = N; - for (Nq = N_len - 1; Nq > 0; --Nq) { + for (Nq = total - 1; Nq > 0; --Nq) { N0 = index[Nq - 1]; N1 = index[Nq]; @@ -826,24 +835,24 @@ plotDataMedianAdd(plot_t *pl, int dN, int sN, double fval, double fpay) } } - if (N_len > 0) { + if (total > 2 || (length < 3 && total > 0)) { - mN.X = index[N_len / 2]; + mN.X = index[total / 2]; mN.Y = mN.X; } if (pl->data[dN].sub[sN].op.median.opdata != 0) { - for (N = 0, N_len = 0; N < keep; ++N) { + for (N = 0, total = 0; N < keep; ++N) { fval = pl->data[dN].sub[sN].op.median.window[N].fval; fpay = pl->data[dN].sub[sN].op.median.window[N].fpay; if (fp_isfinite(fval) && fp_isfinite(fpay)) { - index[N_len++] = N; + index[total++] = N; - for (Nq = N_len - 1; Nq > 0; --Nq) { + for (Nq = total - 1; Nq > 0; --Nq) { N0 = index[Nq - 1]; N1 = index[Nq]; @@ -860,9 +869,9 @@ plotDataMedianAdd(plot_t *pl, int dN, int sN, double fval, double fpay) } } - if (N_len > 0) { + if (total > 2 || (length < 3 && total > 0)) { - mN.Y = index[N_len / 2]; + mN.Y = index[total / 2]; } } @@ -941,21 +950,27 @@ plotDataResample(plot_t *pl, int dN, int cNX, int cNY, int in_dN, int in_cNX, in } while (1); - if ( pl->interpolation != 0 - && X2 >= X) { + if (prev_X2 + (fval_t) pl->defungap > X2) { - if ( prev_X2 <= X - && prev_X2 < X2) { + if ( pl->interpolation != 0 + && X2 >= X) { - Qf = (X - prev_X2) / (X2 - prev_X2); - Y = prev_Y2 + (Y2 - prev_Y2) * Qf; + if ( prev_X2 <= X + && prev_X2 < X2) { + + Qf = (X - prev_X2) / (X2 - prev_X2); + Y = prev_Y2 + (Y2 - prev_Y2) * Qf; + } + else { + Y = prev_Y2; + } } else { - Y = prev_Y2; + Y = Y2; } } else { - Y = Y2; + Y = FP_NAN; } } else { @@ -975,6 +990,7 @@ plotDataPolyfit(plot_t *pl, int dN, int cNX, int cNY, double scale_Y, double offset_Y, int N0, int N1) { const fval_t *row; + double fval_X, fval_Y, fvec[LSE_FULL_MAX]; int N, xN, yN, kN, rN, id_N, job; @@ -1084,8 +1100,8 @@ plotDataFileCSV(plot_t *pl, int *list_dN, int *list_cN, int len_N, FILE *fd_csv) char numfmt[PLOT_STRING_MAX]; - fval_t fval; - int N, dN, job; + double fval; + int N, bN, dN, job; struct { @@ -1140,6 +1156,28 @@ plotDataFileCSV(plot_t *pl, int *list_dN, int *list_cN, int len_N, FILE *fd_csv) if (job == 0) break; + bN = 0; + + for (N = 0; N < len_N; ++N) { + + dN = list_dN[N]; + + if (local[dN].row != NULL) { + + fval = (list_cN[N] < 0) ? local[dN].id_N + : local[dN].row[list_cN[N]]; + + if (fp_isfinite(fval)) + bN++; + } + + if (bN >= 1) + break; + } + + if (bN < 1) + goto plotDataFileCSV_SKIP; + for (N = 0; N < len_N; ++N) { job = 0; @@ -1183,6 +1221,8 @@ plotDataFileCSV(plot_t *pl, int *list_dN, int *list_cN, int len_N, FILE *fd_csv) fprintf(fd_csv, "\n"); +plotDataFileCSV_SKIP: + for (dN = 0; dN < PLOT_DATASET_MAX; ++dN) { if (local[dN].row != NULL) @@ -1197,7 +1237,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int { fval_t *row, X1, X2, X3, X4; double scale, offset, gain; - int cN, rN, id_N, cN1, cN2, cN3, mode; + int cN, rN, id_N, cNX, cNY, cNT, mode; mode = pl->data[dN].sub[sN].busy; @@ -1227,13 +1267,13 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int pl->data[dN].sub[sN].op.median.prev[1] = FP_NAN; } - cN1 = pl->data[dN].sub[sN].op.median.column_1; - cN2 = pl->data[dN].sub[sN].op.median.column_2; - cN3 = pl->data[dN].sub[sN].op.median.column_3; + cNX = pl->data[dN].sub[sN].op.median.column_X; + cNY = pl->data[dN].sub[sN].op.median.column_Y; + cNT = pl->data[dN].sub[sN].op.median.column_T; offset = pl->data[dN].sub[sN].op.median.offset; - if (pl->data[dN].sub[sN].op.median.unwrap != 0) { + if (pl->data[dN].sub[sN].op.median.unwrap != UNWRAP_NONE) { X3 = (fval_t) pl->data[dN].sub[sN].op.median.prev[0]; X4 = (fval_t) pl->data[dN].sub[sN].op.median.prev[1]; @@ -1245,8 +1285,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; - X2 = (cN2 < 0) ? id_N : row[cN2]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; mN = plotDataMedianAdd(pl, dN, sN, X1, X2); @@ -1260,7 +1300,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int X2 = pl->data[dN].sub[sN].op.median.window[mN.Y].fpay; } - if (pl->data[dN].sub[sN].op.median.unwrap != 0) { + if (pl->data[dN].sub[sN].op.median.unwrap == UNWRAP_OVERFLOW) { if (X1 + (fval_t) pl->defungap < X3) { @@ -1278,8 +1318,23 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int X3 = X1; } } + else if (pl->data[dN].sub[sN].op.median.unwrap == UNWRAP_BURST) { + + if (X1 < X3) { + + X1 = FP_NAN; + } + else if (X1 - (fval_t) pl->defungap > X3) { + + X1 = FP_NAN; + } + else if (fp_isfinite(X1)) { + + X3 = X1; + } + } - row[cN3] = X1 + offset; + row[cNT] = X1 + offset; row[cN] = X2; id_N++; @@ -1291,7 +1346,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int pl->data[dN].sub[sN].op.median.offset = offset; - if (pl->data[dN].sub[sN].op.median.unwrap != 0) { + if (pl->data[dN].sub[sN].op.median.unwrap != UNWRAP_NONE) { pl->data[dN].sub[sN].op.median.prev[0] = (double) X3; pl->data[dN].sub[sN].op.median.prev[1] = (double) X4; @@ -1299,7 +1354,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } else if (mode == SUBTRACT_SCALE) { - cN1 = pl->data[dN].sub[sN].op.scale.column_1; + cNX = pl->data[dN].sub[sN].op.scale.column_X; + scale = pl->data[dN].sub[sN].op.scale.scale; offset = pl->data[dN].sub[sN].op.scale.offset; @@ -1309,7 +1365,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; X1 = X1 * scale + offset; row[cN] = X1; @@ -1320,6 +1376,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int break; } while (1); + + pl->data[dN].sub[sN].op.scale.modified = 0; } else if (mode == SUBTRACT_RESAMPLE) { @@ -1330,7 +1388,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int const double *coefs; int N, N0, N1; - cN1 = pl->data[dN].sub[sN].op.polyfit.column_X; + cNX = pl->data[dN].sub[sN].op.polyfit.column_X; + N0 = pl->data[dN].sub[sN].op.polyfit.poly_N0; N1 = pl->data[dN].sub[sN].op.polyfit.poly_N1; coefs = pl->data[dN].sub[sN].op.polyfit.coefs; @@ -1341,7 +1400,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; X2 = coefs[N1 - N0]; for (N = N1 - N0 - 1; N >= 0; --N) @@ -1361,8 +1420,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } else if (mode == SUBTRACT_BINARY_SUBTRACTION) { - cN1 = pl->data[dN].sub[sN].op.binary.column_1; - cN2 = pl->data[dN].sub[sN].op.binary.column_2; + cNX = pl->data[dN].sub[sN].op.binary.column_X; + cNY = pl->data[dN].sub[sN].op.binary.column_Y; do { row = plotDataWrite(pl, dN, &rN); @@ -1370,8 +1429,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; - X2 = (cN2 < 0) ? id_N : row[cN2]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; row[cN] = X1 - X2; @@ -1384,8 +1443,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } else if (mode == SUBTRACT_BINARY_ADDITION) { - cN1 = pl->data[dN].sub[sN].op.binary.column_1; - cN2 = pl->data[dN].sub[sN].op.binary.column_2; + cNX = pl->data[dN].sub[sN].op.binary.column_X; + cNY = pl->data[dN].sub[sN].op.binary.column_Y; do { row = plotDataWrite(pl, dN, &rN); @@ -1393,8 +1452,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; - X2 = (cN2 < 0) ? id_N : row[cN2]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; row[cN] = X1 + X2; @@ -1407,8 +1466,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } else if (mode == SUBTRACT_BINARY_MULTIPLICATION) { - cN1 = pl->data[dN].sub[sN].op.binary.column_1; - cN2 = pl->data[dN].sub[sN].op.binary.column_2; + cNX = pl->data[dN].sub[sN].op.binary.column_X; + cNY = pl->data[dN].sub[sN].op.binary.column_Y; do { row = plotDataWrite(pl, dN, &rN); @@ -1416,8 +1475,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; - X2 = (cN2 < 0) ? id_N : row[cN2]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; row[cN] = X1 * X2; @@ -1430,8 +1489,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } else if (mode == SUBTRACT_BINARY_HYPOTENUSE) { - cN1 = pl->data[dN].sub[sN].op.binary.column_1; - cN2 = pl->data[dN].sub[sN].op.binary.column_2; + cNX = pl->data[dN].sub[sN].op.binary.column_X; + cNY = pl->data[dN].sub[sN].op.binary.column_Y; do { row = plotDataWrite(pl, dN, &rN); @@ -1439,8 +1498,8 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; - X2 = (cN2 < 0) ? id_N : row[cN2]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; row[cN] = sqrt(X1 * X1 + X2 * X2); @@ -1455,11 +1514,15 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (rN_beg == pl->data[dN].head_N) { - pl->data[dN].sub[sN].op.filter.state = FP_NAN; + pl->data[dN].sub[sN].op.filter.state[0] = FP_NAN; + pl->data[dN].sub[sN].op.filter.state[1] = FP_NAN; } - cN1 = pl->data[dN].sub[sN].op.filter.column_1; - X2 = (fval_t) pl->data[dN].sub[sN].op.filter.state; + cNX = pl->data[dN].sub[sN].op.filter.column_X; + cNY = pl->data[dN].sub[sN].op.filter.column_Y; + + X3 = (fval_t) pl->data[dN].sub[sN].op.filter.state[0]; + X4 = (fval_t) pl->data[dN].sub[sN].op.filter.state[1]; do { row = plotDataWrite(pl, dN, &rN); @@ -1467,11 +1530,13 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; - row[cN] = X1 - X2; + row[cN] = (X2 - X4) / (X1 - X3); - X2 = X1; + X3 = X1; + X4 = X2; id_N++; @@ -1480,17 +1545,22 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } while (1); - pl->data[dN].sub[sN].op.filter.state = (double) X2; + pl->data[dN].sub[sN].op.filter.state[0] = (double) X3; + pl->data[dN].sub[sN].op.filter.state[1] = (double) X4; } else if (mode == SUBTRACT_FILTER_CUMULATIVE) { if (rN_beg == pl->data[dN].head_N) { - pl->data[dN].sub[sN].op.filter.state = 0.; + pl->data[dN].sub[sN].op.filter.state[0] = FP_NAN; + pl->data[dN].sub[sN].op.filter.state[1] = 0.; } - cN1 = pl->data[dN].sub[sN].op.filter.column_1; - X2 = (fval_t) pl->data[dN].sub[sN].op.filter.state; + cNX = pl->data[dN].sub[sN].op.filter.column_X; + cNY = pl->data[dN].sub[sN].op.filter.column_Y; + + X3 = (fval_t) pl->data[dN].sub[sN].op.filter.state[0]; + X4 = (fval_t) pl->data[dN].sub[sN].op.filter.state[1]; do { row = plotDataWrite(pl, dN, &rN); @@ -1498,14 +1568,19 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; + X2 = (cNY < 0) ? id_N : row[cNY]; - if (fp_isfinite(X1)) { + X2 *= X1 - X3; + + if (fp_isfinite(X2)) { - X2 += X1; + X4 += X2; } - row[cN] = X2; + X3 = X1; + + row[cN] = X4; id_N++; @@ -1514,13 +1589,14 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } while (1); - pl->data[dN].sub[sN].op.filter.state = (double) X2; + pl->data[dN].sub[sN].op.filter.state[0] = (double) X3; + pl->data[dN].sub[sN].op.filter.state[1] = (double) X4; } else if (mode == SUBTRACT_FILTER_BITMASK) { unsigned long shift, mask, ulval; - cN1 = pl->data[dN].sub[sN].op.filter.column_1; + cNX = pl->data[dN].sub[sN].op.filter.column_Y; ulval = (unsigned long) pl->data[dN].sub[sN].op.filter.gain; shift = ulval & 0xFFU; @@ -1534,7 +1610,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; ulval = ((unsigned long) X1 & mask) >> shift; row[cN] = (fval_t) ulval; @@ -1550,12 +1626,13 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (rN_beg == pl->data[dN].head_N) { - pl->data[dN].sub[sN].op.filter.state = FP_NAN; + pl->data[dN].sub[sN].op.filter.state[0] = FP_NAN; } - cN1 = pl->data[dN].sub[sN].op.filter.column_1; + cNX = pl->data[dN].sub[sN].op.filter.column_Y; gain = pl->data[dN].sub[sN].op.filter.gain; - X2 = (fval_t) pl->data[dN].sub[sN].op.filter.state; + + X2 = (fval_t) pl->data[dN].sub[sN].op.filter.state[0]; do { row = plotDataWrite(pl, dN, &rN); @@ -1563,7 +1640,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; if (fp_isfinite(X1)) { @@ -1585,7 +1662,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int } while (1); - pl->data[dN].sub[sN].op.filter.state = (double) X2; + pl->data[dN].sub[sN].op.filter.state[0] = (double) X2; } else if (mode == SUBTRACT_FILTER_MEDIAN) { @@ -1597,7 +1674,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int pl->data[dN].sub[sN].op.median.tail = 0; } - cN1 = pl->data[dN].sub[sN].op.median.column_1; + cNX = pl->data[dN].sub[sN].op.median.column_Y; do { row = plotDataWrite(pl, dN, &rN); @@ -1605,7 +1682,7 @@ plotDataSubtractWrite(plot_t *pl, int dN, int sN, int rN_beg, int id_N_beg, int if (row == NULL) break; - X1 = (cN1 < 0) ? id_N : row[cN1]; + X1 = (cNX < 0) ? id_N : row[cNX]; mN = plotDataMedianAdd(pl, dN, sN, X1, X1); @@ -1945,7 +2022,8 @@ void plotDataRangeCacheSubtractClean(plot_t *pl) int plotDataRangeCacheFetch(plot_t *pl, int dN, int cN) { const fval_t *row; - fval_t fval, fmin, fmax, ymin, ymax; + + double fval, fmin, fmax, ymin, ymax; int N, xN, rN, id_N, kN; int job, finite, started; @@ -1971,8 +2049,8 @@ int plotDataRangeCacheFetch(plot_t *pl, int dN, int cN) rN = pl->data[dN].head_N; id_N = pl->data[dN].id_N; - fmin = (fval_t) 0.; - fmax = (fval_t) 0.; + fmin = 0.; + fmax = 0.; started = 0; @@ -2095,6 +2173,7 @@ plotDataRangeCond(plot_t *pl, int dN, int cN, int cN_cond, int *pflag, double scale, double offset, double *pmin, double *pmax) { const fval_t *row; + double fval, fmin, fmax, fcond, vmin, vmax; int xN, yN, kN, rN, id_N, job, started; @@ -2316,9 +2395,10 @@ plotDataRangeAxis(plot_t *pl, int dN, int cN, int aN, double *pmin, double *pmax } static const fval_t * -plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) +plotDataSliceGet(plot_t *pl, int dN, int cN, double fdot, int *m_id_N) { const fval_t *row; + double fval, fbest, fmin, fmax, fneard; int xN, lN, rN, id_N, kN, kN_rep, best_N; int job, started, span; @@ -2344,12 +2424,12 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) fmin = pl->rcache[xN].chunk[kN].fmin; fmax = pl->rcache[xN].chunk[kN].fmax; - if (fsamp < fmin || fsamp > fmax) { + if (fdot < fmin || fdot > fmax) { job = 0; - fmin = fabs(fmin - fsamp); - fmax = fabs(fmax - fsamp); + fmin = fabs(fmin - fdot); + fmax = fabs(fmax - fdot); if (kN_rep >= 0) { @@ -2395,9 +2475,9 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) if (fp_isfinite(fval)) { - if (started != 0) { + fval = fabs(fdot - fval); - fval = fabs(fsamp - fval); + if (started != 0) { if (fval < fbest) { @@ -2408,7 +2488,7 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) else { started = 1; - fbest = fabs(fsamp - fval); + fbest = fval; best_N = id_N; } } @@ -2454,9 +2534,9 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) if (fp_isfinite(fval)) { - if (started != 0) { + fval = fabs(fdot - fval); - fval = fabs(fsamp - fval); + if (started != 0) { if (fval < fbest) { @@ -2467,7 +2547,7 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) else { started = 1; - fbest = fabs(fsamp - fval); + fbest = fval; best_N = id_N; } } @@ -2504,168 +2584,457 @@ plotDataSliceGet(plot_t *pl, int dN, int cN, double fsamp, int *m_id_N) return row; } -void plotAxisLabel(plot_t *pl, int aN, const char *label) +static const fval_t * +plotDataPickGet(plot_t *pl, int dN, int cNX, int cNY, + double fdot_X, double fdot_Y, + double tol_X, double tol_Y, int *m_id_N) { - if (aN < 0 || aN >= PLOT_AXES_MAX) { + const fval_t *row; - ERROR("Axis number is out of range\n"); - return ; - } + double fval_X, fval_Y, fbest, fmin, fmax; + int xNX, xNY, lN, rN, id_N, kN, best_N; + int job, started, span; - if (label[0] != 0) { + xNX = plotDataRangeCacheFetch(pl, dN, cNX); + xNY = plotDataRangeCacheFetch(pl, dN, cNY); - strcpy(pl->axis[aN].label, label); + rN = pl->data[dN].head_N; + id_N = pl->data[dN].id_N; - pl->axis[aN].compact = (strlen(pl->axis[aN].label) >= 3) ? 0 : 1; - } -} + started = 0; + span = 0; -static int -plotAxisRangeGet(plot_t *pl, int aN, double *pmin, double *pmax) -{ - double min, max, fmin, fmax, scale, offset; - int fN, dN, cN, xN, yN, started = 0; + do { + kN = plotDataChunkN(pl, dN, rN); + job = 1; - for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + if (xNX >= 0 && pl->rcache[xNX].chunk[kN].computed != 0) { - if (pl->figure[fN].busy != 0 && pl->figure[fN].hidden == 0) { + if (pl->rcache[xNX].chunk[kN].finite != 0) { - dN = pl->figure[fN].data_N; + fmin = pl->rcache[xNX].chunk[kN].fmin; + fmax = pl->rcache[xNX].chunk[kN].fmax; - do { - if (pl->figure[fN].axis_X == aN) { + if ( fdot_X < fmin - tol_X + || fdot_X > fmax + tol_X) { - cN = pl->figure[fN].column_X; + job = 0; } - else if (pl->figure[fN].axis_Y == aN) { + } + else { + job = 0; + } + } - cN = pl->figure[fN].column_Y; - } - else - break; + if (xNY >= 0 && pl->rcache[xNY].chunk[kN].computed != 0) { - plotDataRangeGet(pl, dN, cN, &min, &max); + if (pl->rcache[xNY].chunk[kN].finite != 0) { - if (started != 0) { + fmin = pl->rcache[xNY].chunk[kN].fmin; + fmax = pl->rcache[xNY].chunk[kN].fmax; - fmin = (min < fmin) ? min : fmin; - fmax = (max > fmax) ? max : fmax; - } - else { - started = 1; + if ( fdot_Y < fmin - tol_Y + || fdot_Y > fmax + tol_Y) { - fmin = min; - fmax = max; + job = 0; } } - while (0); + else { + job = 0; + } + } + + if (job != 0) { + + span++; do { - xN = pl->figure[fN].axis_X; - yN = pl->figure[fN].axis_Y; + if (kN != plotDataChunkN(pl, dN, rN)) + break; - if ( pl->axis[xN].slave != 0 - && pl->axis[xN].slave_N == aN) { + row = plotDataGet(pl, dN, &rN); - cN = pl->figure[fN].column_X; + if (row == NULL) + break; - scale = pl->axis[xN].scale; - offset = pl->axis[xN].offset; - } - else if ( pl->axis[yN].slave != 0 - && pl->axis[yN].slave_N == aN) { + fval_X = (cNX < 0) ? id_N : row[cNX]; + fval_Y = (cNY < 0) ? id_N : row[cNY]; - cN = pl->figure[fN].column_Y; + if ( fp_isfinite(fval_X) + && fp_isfinite(fval_Y)) { - scale = pl->axis[yN].scale; - offset = pl->axis[yN].offset; - } - else - break; + fval_X = fabs(fdot_X - fval_X); + fval_Y = fabs(fdot_Y - fval_Y); - plotDataRangeGet(pl, dN, cN, &min, &max); + if ( fval_X < tol_X + && fval_Y < tol_Y) { - min = min * scale + offset; - max = max * scale + offset; + fval_X /= tol_X; + fval_Y /= tol_Y; - if (started != 0) { + fval_X = fval_X * fval_X + + fval_Y * fval_Y; - fmin = (min < fmin) ? min : fmin; - fmax = (max > fmax) ? max : fmax; - } - else { - started = 1; + if (started != 0) { - fmin = min; - fmax = max; + if (fval_X < fbest) { + + fbest = fval_X; + best_N = id_N; + } + } + else { + started = 1; + + fbest = fval_X; + best_N = id_N; + } + } } + + id_N++; } - while (0); + while (1); + + if (span >= PLOT_SLICE_SPAN) + break; + } + else { + plotDataChunkSkip(pl, dN, &rN, &id_N); } + + if (rN == pl->data[dN].tail_N) + break; } + while (1); - *pmin = fmin; - *pmax = fmax; + if (started != 0) { - return started; + *m_id_N = best_N; + + lN = pl->data[dN].length_N; + + rN = pl->data[dN].head_N + (best_N - pl->data[dN].id_N); + rN = (rN > lN - 1) ? rN - lN : rN; + + row = plotDataGet(pl, dN, &rN); + } + else { + row = NULL; + } + + return row; } -static int -plotAxisRangeCond(plot_t *pl, int aN, int bN, double *pmin, double *pmax) +static void +plotDataErase(plot_t *pl, int dN, int cNX, int cNY, + double fmin_X, double fmin_Y, + double fmax_X, double fmax_Y) { - double min, max, fmin, fmax, scale, offset; - int fN, dN, cN, xN, yN, nN, started, cond; + fval_t *row; - started = 0; + double fval_X, fval_Y, fmin, fmax; + int xNX, xNY, rN, id_N, kN, job; - for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + xNX = plotDataRangeCacheFetch(pl, dN, cNX); + xNY = plotDataRangeCacheFetch(pl, dN, cNY); - if (pl->figure[fN].busy != 0 && pl->figure[fN].hidden == 0) { + rN = pl->data[dN].head_N; + id_N = pl->data[dN].id_N; - dN = pl->figure[fN].data_N; + do { + kN = plotDataChunkN(pl, dN, rN); + job = 1; - do { - if (pl->figure[fN].axis_X == aN) { + if (xNX >= 0 && pl->rcache[xNX].chunk[kN].computed != 0) { - cN = pl->figure[fN].column_X; - nN = pl->figure[fN].axis_Y; - } - else if (pl->figure[fN].axis_Y == aN) { + if (pl->rcache[xNX].chunk[kN].finite != 0) { - cN = pl->figure[fN].column_Y; - nN = pl->figure[fN].axis_X; - } - else - break; + fmin = pl->rcache[xNX].chunk[kN].fmin; + fmax = pl->rcache[xNX].chunk[kN].fmax; - if (bN >= 0) { + if ( fmax_X < fmin + || fmin_X > fmax) { - cond = plotDataRangeAxis(pl, dN, cN, bN, &min, &max); - } - else { - cond = plotDataRangeAxis(pl, dN, cN, nN, &min, &max); + job = 0; } + } + else { + job = 0; + } + } - if (cond != 0) { + if (xNY >= 0 && pl->rcache[xNY].chunk[kN].computed != 0) { - if (started != 0) { + if (pl->rcache[xNY].chunk[kN].finite != 0) { - fmin = (min < fmin) ? min : fmin; - fmax = (max > fmax) ? max : fmax; - } - else { - started = 1; + fmin = pl->rcache[xNY].chunk[kN].fmin; + fmax = pl->rcache[xNY].chunk[kN].fmax; - fmin = min; - fmax = max; - } + if ( fmax_Y < fmin + || fmin_Y > fmax) { + + job = 0; } } - while (0); + else { + job = 0; + } + } - do { - xN = pl->figure[fN].axis_X; - yN = pl->figure[fN].axis_Y; + if (job != 0) { + + do { + if (kN != plotDataChunkN(pl, dN, rN)) + break; + + row = plotDataWrite(pl, dN, &rN); + + if (row == NULL) + break; + + fval_X = (cNX < 0) ? id_N : row[cNX]; + fval_Y = (cNY < 0) ? id_N : row[cNY]; + + if ( fp_isfinite(fval_X) + && fp_isfinite(fval_Y)) { + + if ( fval_X > fmin_X && fval_X < fmax_X + && fval_Y > fmin_Y && fval_Y < fmax_Y) { + + row[cNX] = FP_NAN; + row[cNY] = FP_NAN; + } + } + + id_N++; + } + while (1); + } + else { + plotDataChunkSkip(pl, dN, &rN, &id_N); + } + + if (rN == pl->data[dN].tail_N) + break; + } + while (1); +} + +static int +plotDataCompareMatch(plot_t *pl, int dN, int cN1, int cN2) +{ + const fval_t *row; + + double X, Y; + int N, rN, id_N; + + rN = pl->data[dN].head_N; + id_N = pl->data[dN].id_N; + + N = 0; + + do { + row = plotDataGet(pl, dN, &rN); + + if (row == NULL) + break; + + X = (cN1 < 0) ? id_N : row[cN1]; + Y = (cN2 < 0) ? id_N : row[cN2]; + + if (fp_isfinite(X)) { + + if (fp_isfinite(Y)) { + + if (X != Y) { + + N++; + } + } + else { + N++; + } + } + else { + if (fp_isfinite(Y)) { + + N++; + } + } + + if (N >= 1) + break; + + id_N++; + } + while (1); + + return N; +} + + +void plotAxisLabel(plot_t *pl, int aN, const char *label) +{ + if (aN < 0 || aN >= PLOT_AXES_MAX) { + + ERROR("Axis number is out of range\n"); + return ; + } + + if (label[0] != 0) { + + strcpy(pl->axis[aN].label, label); + + pl->axis[aN].compact = (strlen(pl->axis[aN].label) >= 4) ? 0 : 1; + } +} + +int plotAxisRangeGet(plot_t *pl, int aN, double *pmin, double *pmax) +{ + double min, max, fmin, fmax, scale, offset; + int fN, dN, cN, xN, yN, started = 0; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if (pl->figure[fN].busy != 0 && pl->figure[fN].hidden == 0) { + + dN = pl->figure[fN].data_N; + + do { + if (pl->figure[fN].axis_X == aN) { + + cN = pl->figure[fN].column_X; + } + else if (pl->figure[fN].axis_Y == aN) { + + cN = pl->figure[fN].column_Y; + } + else + break; + + plotDataRangeGet(pl, dN, cN, &min, &max); + + if (started != 0) { + + fmin = (min < fmin) ? min : fmin; + fmax = (max > fmax) ? max : fmax; + } + else { + started = 1; + + fmin = min; + fmax = max; + } + } + while (0); + + do { + xN = pl->figure[fN].axis_X; + yN = pl->figure[fN].axis_Y; + + if ( pl->axis[xN].slave != 0 + && pl->axis[xN].slave_N == aN) { + + cN = pl->figure[fN].column_X; + + scale = pl->axis[xN].scale; + offset = pl->axis[xN].offset; + } + else if ( pl->axis[yN].slave != 0 + && pl->axis[yN].slave_N == aN) { + + cN = pl->figure[fN].column_Y; + + scale = pl->axis[yN].scale; + offset = pl->axis[yN].offset; + } + else + break; + + plotDataRangeGet(pl, dN, cN, &min, &max); + + min = min * scale + offset; + max = max * scale + offset; + + if (started != 0) { + + fmin = (min < fmin) ? min : fmin; + fmax = (max > fmax) ? max : fmax; + } + else { + started = 1; + + fmin = min; + fmax = max; + } + } + while (0); + } + } + + *pmin = fmin; + *pmax = fmax; + + return started; +} + +static int +plotAxisRangeCond(plot_t *pl, int aN, int bN, double *pmin, double *pmax) +{ + double min, max, fmin, fmax, scale, offset; + int fN, dN, cN, xN, yN, nN, started, cond; + + started = 0; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if (pl->figure[fN].busy != 0 && pl->figure[fN].hidden == 0) { + + dN = pl->figure[fN].data_N; + + do { + if (pl->figure[fN].axis_X == aN) { + + cN = pl->figure[fN].column_X; + nN = pl->figure[fN].axis_Y; + } + else if (pl->figure[fN].axis_Y == aN) { + + cN = pl->figure[fN].column_Y; + nN = pl->figure[fN].axis_X; + } + else + break; + + if (bN >= 0) { + + cond = plotDataRangeAxis(pl, dN, cN, bN, &min, &max); + } + else { + cond = plotDataRangeAxis(pl, dN, cN, nN, &min, &max); + } + + if (cond != 0) { + + if (started != 0) { + + fmin = (min < fmin) ? min : fmin; + fmax = (max > fmax) ? max : fmax; + } + else { + started = 1; + + fmin = min; + fmax = max; + } + } + } + while (0); + + do { + xN = pl->figure[fN].axis_X; + yN = pl->figure[fN].axis_Y; if ( pl->axis[xN].slave != 0 && pl->axis[xN].slave_N == aN) { @@ -2836,6 +3205,7 @@ void plotAxisScaleAutoCond(plot_t *pl, int aN, int bN) plotAxisScaleManual(pl, aN, fmin, fmax); } + pl->axis[aN].lock_scale = LOCK_FREE; pl->axis[aN].lock_tick = 0; } } @@ -3100,8 +3470,7 @@ plotAxisGetSorted(plot_t *pl, int bN, yaxis_t *map) if (job != 0) { - cond = plotAxisRangeCond(pl, aN, -1, &map[yN].fmin, - &map[yN].fmax); + cond = plotAxisRangeCond(pl, aN, -1, &map[yN].fmin, &map[yN].fmax); if (cond != 0) { @@ -3203,7 +3572,7 @@ int plotAxisGetByClick(plot_t *pl, int cur_X, int cur_Y) if (pl->axis[aN].busy == AXIS_BUSY_X) { - len = pl->layout_axis_box; + len = pl->layout_ruler_box; len += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; if ( cur_Y < pl->axis[aN].layout_pos + len @@ -3216,7 +3585,7 @@ int plotAxisGetByClick(plot_t *pl, int cur_X, int cur_Y) if (pl->axis[aN].busy == AXIS_BUSY_Y) { - len = pl->layout_axis_box; + len = pl->layout_ruler_box; len += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; if ( cur_X < pl->axis[aN].layout_pos + len @@ -3235,7 +3604,7 @@ int plotAxisGetByClick(plot_t *pl, int cur_X, int cur_Y) double plotAxisConvForward(plot_t *pl, int aN, double fval) { - double scale, offset, temp; + double scale, offset, length; int bN; scale = pl->axis[aN].scale; @@ -3250,15 +3619,15 @@ double plotAxisConvForward(plot_t *pl, int aN, double fval) if (pl->axis[aN].busy == AXIS_BUSY_X) { - temp = (double) (pl->viewport.max_x - pl->viewport.min_x); - scale *= temp; - offset = offset * temp + pl->viewport.min_x; + length = (double) (pl->viewport.max_x - pl->viewport.min_x); + scale *= length; + offset = offset * length + pl->viewport.min_x; } else if (pl->axis[aN].busy == AXIS_BUSY_Y) { - temp = (double) (pl->viewport.min_y - pl->viewport.max_y); - scale *= temp; - offset = offset * temp + pl->viewport.max_y; + length = (double) (pl->viewport.min_y - pl->viewport.max_y); + scale *= length; + offset = offset * length + pl->viewport.max_y; } return fval * scale + offset; @@ -3266,7 +3635,7 @@ double plotAxisConvForward(plot_t *pl, int aN, double fval) double plotAxisConvBackward(plot_t *pl, int aN, double xval) { - double scale, offset, temp; + double scale, offset, length; int bN; scale = pl->axis[aN].scale; @@ -3281,15 +3650,15 @@ double plotAxisConvBackward(plot_t *pl, int aN, double xval) if (pl->axis[aN].busy == AXIS_BUSY_X) { - temp = (double) (pl->viewport.max_x - pl->viewport.min_x); - scale *= temp; - offset = offset * temp + pl->viewport.min_x; + length = (double) (pl->viewport.max_x - pl->viewport.min_x); + scale *= length; + offset = offset * length + pl->viewport.min_x; } else if (pl->axis[aN].busy == AXIS_BUSY_Y) { - temp = (double) (pl->viewport.min_y - pl->viewport.max_y); - scale *= temp; - offset = offset * temp + pl->viewport.max_y; + length = (double) (pl->viewport.min_y - pl->viewport.max_y); + scale *= length; + offset = offset * length + pl->viewport.max_y; } return (xval - offset) / scale; @@ -3620,7 +3989,7 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) if (pl->data[dN].sub[sN].busy == SUBTRACT_TIME_MEDIAN) { - if (cN == pl->data[dN].sub[sN].op.median.column_1) { + if (cN == pl->data[dN].sub[sN].op.median.column_X) { linked = 1; break; @@ -3628,7 +3997,7 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) } else if (pl->data[dN].sub[sN].busy == SUBTRACT_DATA_MEDIAN) { - if (cN == pl->data[dN].sub[sN].op.median.column_2) { + if (cN == pl->data[dN].sub[sN].op.median.column_Y) { linked = 1; break; @@ -3636,7 +4005,7 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) } else if (pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { - if (cN == pl->data[dN].sub[sN].op.scale.column_1) { + if (cN == pl->data[dN].sub[sN].op.scale.column_X) { linked = 1; break; @@ -3652,8 +4021,7 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) } else if (pl->data[dN].sub[sN].busy == SUBTRACT_POLYFIT) { - if ( cN == pl->data[dN].sub[sN].op.polyfit.column_X - || cN == pl->data[dN].sub[sN].op.polyfit.column_Y) { + if (cN == pl->data[dN].sub[sN].op.polyfit.column_X) { linked = 1; break; @@ -3664,19 +4032,27 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) || pl->data[dN].sub[sN].busy == SUBTRACT_BINARY_MULTIPLICATION || pl->data[dN].sub[sN].busy == SUBTRACT_BINARY_HYPOTENUSE) { - if ( cN == pl->data[dN].sub[sN].op.binary.column_1 - || cN == pl->data[dN].sub[sN].op.binary.column_2) { + if ( cN == pl->data[dN].sub[sN].op.binary.column_X + || cN == pl->data[dN].sub[sN].op.binary.column_Y) { linked = 1; break; } } else if ( pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_DIFFERENCE - || pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_CUMULATIVE - || pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_BITMASK + || pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_CUMULATIVE) { + + if ( cN == pl->data[dN].sub[sN].op.filter.column_X + || cN == pl->data[dN].sub[sN].op.filter.column_Y) { + + linked = 1; + break; + } + } + else if ( pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_BITMASK || pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_LOW_PASS) { - if (cN == pl->data[dN].sub[sN].op.filter.column_1) { + if (cN == pl->data[dN].sub[sN].op.filter.column_Y) { linked = 1; break; @@ -3684,7 +4060,7 @@ plotCheckColumnLinked(plot_t *pl, int dN, int cN) } else if (pl->data[dN].sub[sN].busy == SUBTRACT_FILTER_MEDIAN) { - if (cN == pl->data[dN].sub[sN].op.median.column_1) { + if (cN == pl->data[dN].sub[sN].op.median.column_Y) { linked = 1; break; @@ -3758,31 +4134,147 @@ plotSubtractGarbage(plot_t *pl, int dN) while (N != 0); } -void plotFigureRemove(plot_t *pl, int fN) +static int +plotSubtractOriginal(plot_t *pl, int dN, int cN) { - int N, aN, rX = 1, rY = 1; + int fN, sN, cN1, modified; - if (fN < 0 || fN >= PLOT_FIGURE_MAX) { + sN = cN - pl->data[dN].column_N; - ERROR("Figure number is out of range\n"); - return ; - } + if ( sN >= 0 && sN < PLOT_SUBTRACT + && pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { - for (N = 0; N < PLOT_FIGURE_MAX; ++N) { + cN1 = pl->data[dN].sub[sN].op.scale.column_X; + modified = pl->data[dN].sub[sN].op.scale.modified; - if (pl->figure[N].busy != 0 && N != fN) { + if (modified == 0) { - if (pl->figure[N].axis_X == pl->figure[fN].axis_X) - rX = 0; + if ( pl->data[dN].sub[sN].op.scale.scale == (double) 1. + && pl->data[dN].sub[sN].op.scale.offset == (double) 0.) { - if (pl->figure[N].axis_Y == pl->figure[fN].axis_Y) - rY = 0; + cN = cN1; + goto plotSubtractMerge_END; + } } - } - pl->figure[fN].busy = 0; + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if ( pl->figure[fN].busy != 0 + && dN == pl->figure[fN].data_N + && cN != pl->figure[fN].column_X) { + + sN = pl->figure[fN].column_X - pl->data[dN].column_N; + + if ( sN >= 0 && sN < PLOT_SUBTRACT + && pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { + + if ( cN1 == pl->data[dN].sub[sN].op.scale.column_X + && modified == pl->data[dN].sub[sN].op.scale.modified) { + + if (plotDataCompareMatch(pl, dN, cN, pl->figure[fN].column_X) == 0) { + + cN = pl->figure[fN].column_X; + goto plotSubtractMerge_END; + } + } + } + } + + if ( pl->figure[fN].busy != 0 + && dN == pl->figure[fN].data_N + && cN != pl->figure[fN].column_Y) { + + sN = pl->figure[fN].column_Y - pl->data[dN].column_N; + + if ( sN >= 0 && sN < PLOT_SUBTRACT + && pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { + + if ( cN1 == pl->data[dN].sub[sN].op.scale.column_X + && modified == pl->data[dN].sub[sN].op.scale.modified) { + + if (plotDataCompareMatch(pl, dN, cN, pl->figure[fN].column_Y) == 0) { + + cN = pl->figure[fN].column_Y; + goto plotSubtractMerge_END; + } + } + } + } + } + } + +plotSubtractMerge_END: + + return cN; +} + +void plotTotalSubtractGarbage(plot_t *pl) +{ + int N, fN, dN, sN, cNX, cNY; + + do { + N = 0; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if (pl->figure[fN].busy != 0) { + + dN = pl->figure[fN].data_N; + + cNX = pl->figure[fN].column_X; + cNY = pl->figure[fN].column_Y; + + cNX = plotSubtractOriginal(pl, dN, cNX); + cNY = plotSubtractOriginal(pl, dN, cNY); + + pl->figure[fN].column_X = cNX; + pl->figure[fN].column_Y = cNY; + } + } + + for (sN = 0; sN < PLOT_SUBTRACT; ++sN) { + + if (pl->data[dN].sub[sN].busy != SUBTRACT_FREE) { + + cNX = sN + pl->data[dN].column_N; + + if (plotCheckColumnLinked(pl, dN, cNX) == 0) { + + pl->data[dN].sub[sN].busy = SUBTRACT_FREE; + + N++; + } + } + } + } + while (N != 0); +} + +void plotFigureRemove(plot_t *pl, int fN) +{ + int N, aN, on_X = 1, on_Y = 1; + + if (fN < 0 || fN >= PLOT_FIGURE_MAX) { - if (rX != 0) { + ERROR("Figure number is out of range\n"); + return ; + } + + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { + + if (pl->figure[N].busy != 0 && N != fN) { + + if (pl->figure[N].axis_X == pl->figure[fN].axis_X) + on_X = 0; + + if (pl->figure[N].axis_Y == pl->figure[fN].axis_Y) + on_Y = 0; + } + } + + pl->figure[fN].busy = 0; + + if (on_X != 0) { aN = pl->figure[fN].axis_X; @@ -3805,7 +4297,7 @@ void plotFigureRemove(plot_t *pl, int fN) } } - if (rY != 0) { + if (on_Y != 0) { aN = pl->figure[fN].axis_Y; @@ -4030,6 +4522,22 @@ int plotFigureAnyData(plot_t *pl) return dN; } +int plotFigureHaveData(plot_t *pl, int dN) +{ + int fN, N = 0; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if ( pl->figure[fN].busy != 0 + && pl->figure[fN].data_N == dN) { + + N++; + } + } + + return N; +} + static int plotGetSubtractTimeMedianByMatch(plot_t *pl, int dN, int cNX, int length, int unwrap) { @@ -4038,7 +4546,7 @@ plotGetSubtractTimeMedianByMatch(plot_t *pl, int dN, int cNX, int length, int un for (sN = 0; sN < PLOT_SUBTRACT; ++sN) { if ( pl->data[dN].sub[sN].busy == SUBTRACT_TIME_MEDIAN - && pl->data[dN].sub[sN].op.median.column_1 == cNX + && pl->data[dN].sub[sN].op.median.column_X == cNX && pl->data[dN].sub[sN].op.median.length == length && pl->data[dN].sub[sN].op.median.unwrap == unwrap) { @@ -4057,8 +4565,8 @@ plotGetSubtractScaleByMatch(plot_t *pl, int dN, int cN, double scale, double off for (sN = 0; sN < PLOT_SUBTRACT; ++sN) { - if (pl->data[dN].sub[sN].busy == SUBTRACT_SCALE - && pl->data[dN].sub[sN].op.scale.column_1 == cN + if ( pl->data[dN].sub[sN].busy == SUBTRACT_SCALE + && pl->data[dN].sub[sN].op.scale.column_X == cN && pl->data[dN].sub[sN].op.scale.scale == scale && pl->data[dN].sub[sN].op.scale.offset == offset) { @@ -4087,8 +4595,7 @@ plotGetFreeSubtract(plot_t *pl, int dN) return rN; } -tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, - int length, int unwrap, int opdata) +tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, int length, int unwrap, int opdata) { tuple_t uN = { -1, -1 }; int sNX, sNY; @@ -4118,7 +4625,7 @@ tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, } pl->data[dN].sub[sNX].busy = SUBTRACT_TIME_MEDIAN; - pl->data[dN].sub[sNX].op.median.column_1 = cNX; + pl->data[dN].sub[sNX].op.median.column_X = cNX; pl->data[dN].sub[sNX].op.median.length = length; pl->data[dN].sub[sNX].op.median.unwrap = unwrap; pl->data[dN].sub[sNX].op.median.opdata = 0; @@ -4133,9 +4640,9 @@ tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, } pl->data[dN].sub[sNY].busy = SUBTRACT_DATA_MEDIAN; - pl->data[dN].sub[sNY].op.median.column_1 = cNX; - pl->data[dN].sub[sNY].op.median.column_2 = cNY; - pl->data[dN].sub[sNY].op.median.column_3 = sNX + pl->data[dN].column_N; + pl->data[dN].sub[sNY].op.median.column_X = cNX; + pl->data[dN].sub[sNY].op.median.column_Y = cNY; + pl->data[dN].sub[sNY].op.median.column_T = sNX + pl->data[dN].column_N; pl->data[dN].sub[sNY].op.median.length = length; pl->data[dN].sub[sNY].op.median.unwrap = unwrap; pl->data[dN].sub[sNY].op.median.opdata = opdata; @@ -4162,18 +4669,32 @@ int plotGetSubtractScale(plot_t *pl, int dN, int cN, double scale, double offset if (sN < 0) { - sN = plotGetFreeSubtract(pl, dN); + sN = cN - pl->data[dN].column_N; - if (sN < 0) { + if ( sN >= 0 && sN < PLOT_SUBTRACT + && pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { - ERROR("Unable to get free subtract\n"); - return -1; + offset = scale * pl->data[dN].sub[sN].op.scale.offset + offset; + scale *= pl->data[dN].sub[sN].op.scale.scale; + + pl->data[dN].sub[sN].op.scale.scale = scale; + pl->data[dN].sub[sN].op.scale.offset = offset; } + else { + sN = plotGetFreeSubtract(pl, dN); - pl->data[dN].sub[sN].busy = SUBTRACT_SCALE; - pl->data[dN].sub[sN].op.scale.column_1 = cN; - pl->data[dN].sub[sN].op.scale.scale = scale; - pl->data[dN].sub[sN].op.scale.offset = offset; + if (sN < 0) { + + ERROR("Unable to get free subtract\n"); + return -1; + } + + pl->data[dN].sub[sN].busy = SUBTRACT_SCALE; + pl->data[dN].sub[sN].op.scale.column_X = cN; + pl->data[dN].sub[sN].op.scale.modified = 0; + pl->data[dN].sub[sN].op.scale.scale = scale; + pl->data[dN].sub[sN].op.scale.offset = offset; + } plotDataSubtractCompute(pl, dN, sN); } @@ -4183,6 +4704,40 @@ int plotGetSubtractScale(plot_t *pl, int dN, int cN, double scale, double offset return cN; } +static int +plotGetSubtractClone(plot_t *pl, int dN, int cN) +{ + int sN, modified = 0; + + sN = cN - pl->data[dN].column_N; + + if ( sN >= 0 && sN < PLOT_SUBTRACT + && pl->data[dN].sub[sN].busy == SUBTRACT_SCALE) { + + modified = pl->data[dN].sub[sN].op.scale.modified; + } + + sN = plotGetFreeSubtract(pl, dN); + + if (sN < 0) { + + ERROR("Unable to get free subtract\n"); + return -1; + } + + pl->data[dN].sub[sN].busy = SUBTRACT_SCALE; + pl->data[dN].sub[sN].op.scale.column_X = cN; + pl->data[dN].sub[sN].op.scale.modified = modified; + pl->data[dN].sub[sN].op.scale.scale = (double) 1.; + pl->data[dN].sub[sN].op.scale.offset = (double) 0.; + + plotDataSubtractCompute(pl, dN, sN); + + cN = sN + pl->data[dN].column_N; + + return cN; +} + int plotGetSubtractResample(plot_t *pl, int dN, int cNX, int in_dN, int in_cNX, int in_cNY) { int sN, cN; @@ -4245,8 +4800,8 @@ int plotGetSubtractBinary(plot_t *pl, int dN, int opSUB, int cN1, int cN2) } pl->data[dN].sub[sN].busy = opSUB; - pl->data[dN].sub[sN].op.binary.column_1 = cN1; - pl->data[dN].sub[sN].op.binary.column_2 = cN2; + pl->data[dN].sub[sN].op.binary.column_X = cN1; + pl->data[dN].sub[sN].op.binary.column_Y = cN2; plotDataSubtractCompute(pl, dN, sN); @@ -4255,7 +4810,7 @@ int plotGetSubtractBinary(plot_t *pl, int dN, int opSUB, int cN1, int cN2) return cN; } -int plotGetSubtractFilter(plot_t *pl, int dN, int cN, int opSUB, double gain) +int plotGetSubtractFilter(plot_t *pl, int dN, int cNX, int cNY, int opSUB, double gain) { int sN; @@ -4265,9 +4820,15 @@ int plotGetSubtractFilter(plot_t *pl, int dN, int cN, int opSUB, double gain) return -1; } - if (cN < -1 || cN >= pl->data[dN].column_N + PLOT_SUBTRACT) { + if (cNX < -1 || cNX >= pl->data[dN].column_N + PLOT_SUBTRACT) { - ERROR("Column number %i is out of range\n", cN); + ERROR("Column number %i is out of range\n", cNX); + return -1; + } + + if (cNY < -1 || cNY >= pl->data[dN].column_N + PLOT_SUBTRACT) { + + ERROR("Column number %i is out of range\n", cNY); return -1; } @@ -4280,14 +4841,15 @@ int plotGetSubtractFilter(plot_t *pl, int dN, int cN, int opSUB, double gain) } pl->data[dN].sub[sN].busy = opSUB; - pl->data[dN].sub[sN].op.filter.column_1 = cN; + pl->data[dN].sub[sN].op.filter.column_X = cNX; + pl->data[dN].sub[sN].op.filter.column_Y = cNY; pl->data[dN].sub[sN].op.filter.gain = gain; plotDataSubtractCompute(pl, dN, sN); - cN = sN + pl->data[dN].column_N; + cNY = sN + pl->data[dN].column_N; - return cN; + return cNY; } int plotGetSubtractMedian(plot_t *pl, int dN, int cN, int opSUB, int length) @@ -4321,7 +4883,7 @@ int plotGetSubtractMedian(plot_t *pl, int dN, int cN, int opSUB, int length) } pl->data[dN].sub[sN].busy = opSUB; - pl->data[dN].sub[sN].op.median.column_1 = cN; + pl->data[dN].sub[sN].op.median.column_Y = cN; pl->data[dN].sub[sN].op.median.length = length; pl->data[dN].sub[sN].op.median.unwrap = 0; pl->data[dN].sub[sN].op.median.opdata = 0; @@ -4349,7 +4911,7 @@ int plotGetFreeFigure(plot_t *pl) return fN; } -int plotFigureSubtractGetMedianConfig(plot_t *pl, int fN, int config[3]) +int plotFigureSubtractGetMedianConfig(plot_t *pl, int fN, int *length, int *unwrap, int *opdata) { int dN, cN, sN; @@ -4367,9 +4929,9 @@ int plotFigureSubtractGetMedianConfig(plot_t *pl, int fN, int config[3]) if ( sN >= 0 && sN < PLOT_SUBTRACT && pl->data[dN].sub[sN].busy == SUBTRACT_DATA_MEDIAN) { - config[0] = pl->data[dN].sub[sN].op.median.length; - config[1] = pl->data[dN].sub[sN].op.median.unwrap; - config[2] = pl->data[dN].sub[sN].op.median.opdata; + *length = pl->data[dN].sub[sN].op.median.length; + *unwrap = pl->data[dN].sub[sN].op.median.unwrap; + *opdata = pl->data[dN].sub[sN].op.median.opdata; return sN; } @@ -4399,8 +4961,8 @@ void plotFigureSubtractTimeMedian(plot_t *pl, int fN, int length, int unwrap, in if ( sN >= 0 && sN < PLOT_SUBTRACT && pl->data[dN].sub[sN].busy == SUBTRACT_DATA_MEDIAN) { - cNX = pl->data[dN].sub[sN].op.median.column_1; - cNY = pl->data[dN].sub[sN].op.median.column_2; + cNX = pl->data[dN].sub[sN].op.median.column_X; + cNY = pl->data[dN].sub[sN].op.median.column_Y; pl->figure[fN].column_X = cNX; pl->figure[fN].column_Y = cNY; @@ -4418,8 +4980,8 @@ void plotFigureSubtractTimeMedian(plot_t *pl, int fN, int length, int unwrap, in || pl->data[dN].sub[sN].op.median.unwrap != unwrap || pl->data[dN].sub[sN].op.median.opdata != opdata) { - cNX = pl->data[dN].sub[sN].op.median.column_1; - cNY = pl->data[dN].sub[sN].op.median.column_2; + cNX = pl->data[dN].sub[sN].op.median.column_X; + cNY = pl->data[dN].sub[sN].op.median.column_Y; pl->figure[fN].column_X = cNX; pl->figure[fN].column_Y = cNY; @@ -4568,7 +5130,7 @@ plotFigureSubtractAdd(plot_t *pl, int fN, int fN_1, int fN_2, int opSUB) void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain) { - int fN, dN, cN, aN; + int fN, dN, cNX, cNY, aN; if (fN_1 < 0 || fN_1 >= PLOT_FIGURE_MAX) { @@ -4577,7 +5139,8 @@ void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain) } dN = pl->figure[fN_1].data_N; - cN = pl->figure[fN_1].column_Y; + cNX = pl->figure[fN_1].column_X; + cNY = pl->figure[fN_1].column_Y; fN = plotGetFreeFigure(pl); @@ -4589,13 +5152,13 @@ void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain) if (opSUB == SUBTRACT_FILTER_MEDIAN) { - cN = plotGetSubtractMedian(pl, dN, cN, opSUB, (int) gain); + cNY = plotGetSubtractMedian(pl, dN, cNY, opSUB, (int) gain); } else { - cN = plotGetSubtractFilter(pl, dN, cN, opSUB, gain); + cNY = plotGetSubtractFilter(pl, dN, cNX, cNY, opSUB, gain); } - if (cN < 0) { + if (cNY < 0) { return ; } @@ -4618,8 +5181,7 @@ void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain) } } - plotFigureAdd(pl, fN, dN, pl->figure[fN_1].column_X, cN, - pl->figure[fN_1].axis_X, aN, ""); + plotFigureAdd(pl, fN, dN, cNX, cNY, pl->figure[fN_1].axis_X, aN, ""); if (opSUB == SUBTRACT_FILTER_DIFFERENCE) { @@ -4627,7 +5189,7 @@ void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain) } else if (opSUB == SUBTRACT_FILTER_CUMULATIVE) { - sprintf(pl->figure[fN].label, "C: %.75s", pl->figure[fN_1].label); + sprintf(pl->figure[fN].label, "I: %.75s", pl->figure[fN_1].label); } else if (opSUB == SUBTRACT_FILTER_BITMASK) { @@ -4696,7 +5258,7 @@ plotFigureSubtractBinaryLinked(plot_t *pl, int fN, int opSUB, int fNP[2]) if ( sN >= 0 && sN < PLOT_SUBTRACT && pl->data[dN].sub[sN].busy == opSUB) { - cN = pl->data[dN].sub[sN].op.binary.column_1; + cN = pl->data[dN].sub[sN].op.binary.column_X; sE = cN - pl->data[dN].column_N; dN1 = dN; @@ -4729,7 +5291,7 @@ plotFigureSubtractBinaryLinked(plot_t *pl, int fN, int opSUB, int fNP[2]) } } - cN = pl->data[dN].sub[sN].op.binary.column_2; + cN = pl->data[dN].sub[sN].op.binary.column_Y; sE = cN - pl->data[dN].column_N; dN1 = dN; @@ -4902,33 +5464,50 @@ void plotFigureSubtractSwitch(plot_t *pl, int opSUB) } } -void plotFigureSubtractResample(plot_t *pl, int fN) +void plotTotalSubtractResample(plot_t *pl, int dN, double tmin, double tmax) { - int N, dN, aN, cNX, cNY; + double scale, offset; + int N, cNX, cNY; - dN = pl->figure[fN].data_N; - aN = pl->figure[fN].axis_X; - cNX = pl->figure[fN].column_X; + if (dN < 0 || dN >= PLOT_DATASET_MAX) { + + ERROR("Dataset number is out of range\n"); + return ; + } + + if (pl->data[dN].column_N < 1) { + + ERROR("Dataset %i is not allocated\n", dN); + return ; + } for (N = 0; N < PLOT_FIGURE_MAX; ++N) { if ( pl->figure[N].busy != 0 - && pl->figure[N].hidden == 0 - && N != fN) { + && pl->figure[N].hidden == 0) { - if (aN != pl->figure[N].axis_X) { + if (pl->figure[N].axis_X != pl->on_X) { - ERROR("All figures must be on the same axis on X\n"); + ERROR("All figures must be on the active axis on X\n"); return ; } } } + N = plotDataLength(pl, dN); + + scale = (tmax - tmin) / (double) (N - 1); + offset = tmin; + + cNX = plotGetSubtractScale(pl, dN, -1, scale, offset); + + if (cNX < 0) + return ; + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { if ( pl->figure[N].busy != 0 - && pl->figure[N].hidden == 0 - && N != fN) { + && pl->figure[N].hidden == 0) { if ( dN != pl->figure[N].data_N || cNX != pl->figure[N].column_X) { @@ -5162,9 +5741,9 @@ plotLabelFusedCSV(plot_t *pl, char *label, const char *name, const char *unit) *l = 0; } -void plotFigureExportCSV(plot_t *pl, const char *file) +int plotFigureExportCSV(plot_t *pl, const char *file) { - int list_dN[16], list_cN[16], list_fN[16]; + int list_dN[20], list_cN[20], list_fN[20]; int N, fN, aN, job, len_N = 0; for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { @@ -5228,7 +5807,7 @@ void plotFigureExportCSV(plot_t *pl, const char *file) if (fd_csv == NULL) { ERROR("fopen(\"%s\"): %s\n", file, strerror(errno)); - return ; + return -1; } for (N = 0; N < len_N; ++N) { @@ -5270,6 +5849,8 @@ void plotFigureExportCSV(plot_t *pl, const char *file) fclose(fd_csv); } + + return 0; } void plotFigureClean(plot_t *pl) @@ -5302,6 +5883,8 @@ void plotFigureClean(plot_t *pl) pl->slice_on = 0; pl->slice_mode_N = 0; + pl->pick_on = 0; + pl->on_X = -1; pl->on_Y = -1; @@ -5311,6 +5894,7 @@ void plotFigureClean(plot_t *pl) pl->hover_axis = -1; pl->mark_on = 0; + pl->brush_on = 0; plotSketchClean(pl); } @@ -5319,12 +5903,15 @@ static void plotMarkLayout(plot_t *pl) { const fval_t *row; - double shuffle, total, scale, offset, fval_X, fval_Y; + + double bias, urand, sigma, total, scale, offset, fval_X, fval_Y; int fN, vN, aN, bN, cX, cY, cZ, N, id_N, fMAX = 0; + Uint32 rseed; + const int ltdense[PLOT_FIGURE_MAX] = { - 250, 353, 433, 500, 559, 612, 661, 707 /* 250 * sqrt(N) */ + 250, 353, 433, 500, 559, 612, 661, 707, 750, 790 /* 250 * sqrt(N) */ }; for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { @@ -5339,17 +5926,24 @@ plotMarkLayout(plot_t *pl) if (fMAX == 0) return ; + rseed = SDL_GetTicks(); + + rseed = rseed * 17317U + 1U; + rseed = rseed * 17317U + 1U; + pl->layout_mark_size = pl->layout_font_height * pl->mark_size / 200; pl->layout_mark_size = (pl->layout_mark_size < 1) ? 1 : pl->layout_mark_size; - pl->mark_count = (pl->viewport.max_x - pl->viewport.min_x) + pl->mark_length = (pl->viewport.max_x - pl->viewport.min_x) * pl->mark_density / (pl->layout_mark_size * ltdense[fMAX - 1]); - pl->mark_count = (pl->mark_count > PLOT_MARK_MAX) ? PLOT_MARK_MAX - : (pl->mark_count < 4) ? 4 : pl->mark_count; + pl->mark_length = (pl->mark_length > PLOT_MARK_MAX) ? PLOT_MARK_MAX + : (pl->mark_length < 4) ? 4 : pl->mark_length; - shuffle = (double) (SDL_GetTicks() % 100) / (double) (pl->mark_count * 100); - total = (double) (pl->mark_count * fMAX); + total = (double) (pl->viewport.max_x - pl->viewport.min_x); + sigma = (double) pl->layout_mark_size / total; + + total = (double) (pl->mark_length * fMAX); for (fN = 0, vN = 0; fN < PLOT_FIGURE_MAX; ++fN) { @@ -5371,10 +5965,21 @@ plotMarkLayout(plot_t *pl) + pl->axis[bN].offset; } - for (N = 0; N < pl->mark_count; ++N) { + rseed = rseed * 17317U + 1U; + bias = (double) ((rseed >> 16) & 65535U) + / (double) (pl->mark_length * 65535U); + + for (N = 0; N < pl->mark_length; ++N) { + + rseed = rseed * 17317U + 1U; + urand = (double) ((int) ((rseed >> 16) & 65535U) + - 32767) / (double) 32767U; - fval_X = shuffle + (double) (N * fMAX + vN) / total; - fval_X = (fval_X > 1.) ? fval_X - 1. : fval_X; + bias += urand * sigma; + + fval_X = bias + (double) (N * fMAX + vN) / total; + fval_X = (fval_X > 1.) ? fval_X - 1. + : (fval_X < 0.) ? fval_X + 1. : fval_X; fval_X = (fval_X - offset) / scale; @@ -5418,7 +6023,7 @@ plotMarkDraw(plot_t *pl, SDL_Surface *surface) if ( pl->figure[fN].busy != 0 && pl->figure[fN].hidden == 0) { - ncolor = (pl->figure[fN].hidden != 0) ? 9 : fN + 1; + ncolor = (pl->figure[fN].hidden != 0) ? 11 : fN + 1; fwidth = pl->figure[fN].width; fwidth = (fwidth < 1) ? 1 : fwidth; @@ -5457,7 +6062,7 @@ plotMarkDraw(plot_t *pl, SDL_Surface *surface) scale_Y *= Y; offset_Y = offset_Y * Y + pl->viewport.max_y; - for (N = 0; N < pl->mark_count; ++N) { + for (N = 0; N < pl->mark_length; ++N) { X = pl->figure[fN].mark_X[N] * scale_X + offset_X; Y = pl->figure[fN].mark_Y[N] * scale_Y + offset_Y; @@ -5520,8 +6125,8 @@ void plotGroupMedian(plot_t *pl, int gN, int length, int unwrap, int opdata) } pl->group[gN].op_time_median = (length >= 1) ? 1 : 0; - pl->group[gN].op_time_unwrap = (unwrap != 0) ? 1 : 0; - pl->group[gN].op_time_opdata = (opdata != 0) ? 1 : 0; + pl->group[gN].op_time_unwrap = unwrap; + pl->group[gN].op_time_opdata = opdata; pl->group[gN].length = length; } @@ -5550,6 +6155,8 @@ void plotSliceSwitch(plot_t *pl) for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + pl->figure[fN].slice_base_catch = pl->figure[fN].slice_busy; + if (pl->figure[fN].slice_busy != 0) { pl->figure[fN].slice_base_X = pl->figure[fN].slice_X; @@ -5570,9 +6177,10 @@ void plotSliceSwitch(plot_t *pl) void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) { const fval_t *row = NULL; + double fval_X, fval_Y; - int fN, aN, bN, dN, cX, cY, id_N; - int dN_s, aN_s, cX_s, job; + int N, fN, aN, bN, dN, cX, cY, id_N, job; + int dN_cache, aN_cache, cX_cache; if (pl->slice_mode_N == 2) return ; @@ -5584,17 +6192,18 @@ void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) if (pl->slice_axis_N < 0) { - ERROR("No valid axis number to slice\n"); + ERROR("No valid axis number to slice data\n"); return ; } - dN_s = -1; - aN_s = -1; - cX_s = -1; + dN_cache = -1; + aN_cache = -1; + cX_cache = -1; for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { pl->figure[fN].slice_busy = 0; + pl->figure[fN].slice_row = NULL; job = 0; @@ -5660,31 +6269,403 @@ void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) dN = pl->figure[fN].data_N; - if (dN_s != dN || aN_s != aN || cX_s != cX) { + if ( dN_cache != dN + || aN_cache != aN + || cX_cache != cX) { + + row = plotDataSliceGet(pl, dN, cX, fval_X, &id_N); + + dN_cache = dN; + aN_cache = aN; + cX_cache = cX; + } + + if (row != NULL) { + + cX = pl->figure[fN].column_X; + cY = pl->figure[fN].column_Y; + + fval_X = (cX < 0) ? id_N : row[cX]; + fval_Y = (cY < 0) ? id_N : row[cY]; + + pl->figure[fN].slice_busy = 1; + pl->figure[fN].slice_row = row; + pl->figure[fN].slice_id_N = id_N; + pl->figure[fN].slice_X = fval_X; + pl->figure[fN].slice_Y = fval_Y; + } + } + } + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if ( pl->figure[fN].slice_busy == 0 + && pl->figure[fN].busy != 0 + && pl->figure[fN].hidden == 0) { + + dN = pl->figure[fN].data_N; + + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { + + if ( pl->figure[N].slice_busy != 0 + && pl->figure[N].busy != 0 + && pl->figure[N].hidden == 0 + && pl->figure[N].slice_row != NULL + && pl->figure[N].data_N == dN) { + + row = pl->figure[N].slice_row; + id_N = pl->figure[N].slice_id_N; + + cX = pl->figure[fN].column_X; + cY = pl->figure[fN].column_Y; + + fval_X = (cX < 0) ? id_N : row[cX]; + fval_Y = (cY < 0) ? id_N : row[cY]; + + pl->figure[fN].slice_busy = 1; + pl->figure[fN].slice_X = fval_X; + pl->figure[fN].slice_Y = fval_Y; + + break; + } + } + } + } + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + pl->data_box_text[fN][0] = 0; + + if (pl->figure[fN].slice_busy != 0) { + + const read_t *rd = (const read_t *) pl->ld; + + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + fval_X = pl->figure[fN].slice_base_X; + fval_Y = pl->figure[fN].slice_base_Y; + + strcat(pl->data_box_text[fN], " \xCE\x94"); + plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_X - fval_X); + + strcat(pl->data_box_text[fN], "\xCE\x94"); + plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_Y - fval_Y); + } + else { + plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_X); + + dN = pl->figure[fN].data_N; + cY = pl->figure[fN].column_Y; + + if ( pl->fhexadecimal != 0 + && ( rd->data[dN].hint[cY] == DATA_HINT_HEX + || rd->data[dN].hint[cY] == DATA_HINT_OCT)) { + + plotDataBoxTextHex(pl, fN, pl->figure[fN].slice_Y); + } + else { + plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_Y); + } + } + } + } + + if (pl->data_box_on != DATA_BOX_SLICE) { + + pl->data_box_on = DATA_BOX_SLICE; + pl->data_box_X = pl->viewport.max_x; + pl->data_box_Y = 0; + } +} + +static void +plotSliceDrawLight(plot_t *pl, SDL_Surface *surface) +{ + double base_X, base_Y, data_X, data_Y, temp; + int fN, aN, bN; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if ( pl->figure[fN].slice_busy != 0 + && pl->figure[fN].slice_base_catch != 0) { + + aN = pl->figure[fN].axis_X; + bN = pl->figure[fN].axis_Y; + + base_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_base_X); + base_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_base_Y); + + data_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_X); + data_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_Y); + + if (data_X < base_X) { + + temp = base_X; + base_X = data_X; + data_X = temp; + } + + if (data_Y < base_Y) { + + temp = base_Y; + base_Y = data_Y; + data_Y = temp; + } + + SDL_LockSurface(surface); + + if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_X) { + + if (fp_isfinite(base_X) && fp_isfinite(data_X)) { + + drawClipRect(surface, &pl->viewport, + (int) base_X, pl->viewport.min_y, + (int) data_X, pl->viewport.max_y, + pl->sch->plot_hidden); + } + } + else if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_Y) { + + if (fp_isfinite(base_Y) && fp_isfinite(data_Y)) { + + drawClipRect(surface, &pl->viewport, + pl->viewport.min_x, (int) base_Y, + pl->viewport.max_x, (int) data_Y, + pl->sch->plot_hidden); + } + } + + SDL_UnlockSurface(surface); + } + } +} + +static void +plotSliceDraw(plot_t *pl, SDL_Surface *surface) +{ + double base_X, base_Y, data_X, data_Y; + int fN, aN, bN; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if (pl->figure[fN].slice_busy != 0) { + + aN = pl->figure[fN].axis_X; + bN = pl->figure[fN].axis_Y; + + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + base_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_base_X); + base_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_base_Y); + } + + data_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_X); + data_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_Y); + + SDL_LockSurface(surface); + + if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_X) { + + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + if (fp_isfinite(base_X)) { + + drawDashReset(pl->dw); + drawDash(pl->dw, surface, &pl->viewport, + base_X, pl->viewport.min_y, + base_X, pl->viewport.max_y, + pl->sch->plot_text, + pl->layout_fence_dash, + pl->layout_fence_space); + } + } + + if (fp_isfinite(data_X)) { + + drawDashReset(pl->dw); + drawDash(pl->dw, surface, &pl->viewport, + data_X, pl->viewport.min_y, + data_X, pl->viewport.max_y, + pl->sch->plot_text, + pl->layout_fence_dash, + pl->layout_fence_space); + } + } + else if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_Y) { + + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + if (fp_isfinite(base_Y)) { + + drawDashReset(pl->dw); + drawDash(pl->dw, surface, &pl->viewport, + pl->viewport.min_x, base_Y, + pl->viewport.max_x, base_Y, + pl->sch->plot_text, + pl->layout_fence_dash, + pl->layout_fence_space); + } + } + + if (fp_isfinite(data_Y)) { + + drawDashReset(pl->dw); + drawDash(pl->dw, surface, &pl->viewport, + pl->viewport.min_x, data_Y, + pl->viewport.max_x, data_Y, + pl->sch->plot_text, + pl->layout_fence_dash, + pl->layout_fence_space); + } + } + + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + if (fp_isfinite(base_X) && fp_isfinite(base_Y)) { + + drawDotCanvas(pl->dw, surface, &pl->viewport, + base_X, base_Y, + pl->layout_fence_point, 12, 0); + } + } + + if (fp_isfinite(data_X) && fp_isfinite(data_Y)) { + + drawDotCanvas(pl->dw, surface, &pl->viewport, + data_X, data_Y, + pl->layout_fence_point, 12, 0); + } + + SDL_UnlockSurface(surface); + } + } +} + +void plotPickTrack(plot_t *pl, int cur_X, int cur_Y) +{ + const fval_t *row = NULL; + + double fval_X, fval_Y, tol_X, tol_Y; + int N, fN, aN, bN, dN, cNX, cNY, id_N; + + if (pl->slice_mode_N == 2) + return ; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + pl->figure[fN].slice_busy = 0; + pl->figure[fN].slice_row = NULL; + + if ( pl->figure[fN].busy != 0 + && pl->figure[fN].hidden == 0) { + + aN = pl->figure[fN].axis_X; + bN = pl->figure[fN].axis_Y; + + cNX = pl->figure[fN].column_X; + cNY = pl->figure[fN].column_Y; + + fval_X = plotAxisConvBackward(pl, aN, cur_X); + fval_Y = plotAxisConvBackward(pl, bN, cur_Y); + + if (pl->data_box_on == DATA_BOX_PICK) { + + tol_X = plotAxisConvBackward(pl, aN, cur_X - pl->layout_font_height); + tol_Y = plotAxisConvBackward(pl, bN, cur_Y + pl->layout_font_height); + + tol_X = fval_X - tol_X; + tol_Y = fval_Y - tol_Y; + } + else { + tol_X = plotAxisConvBackward(pl, aN, cur_X - (pl->viewport.max_x - pl->viewport.min_x)); + tol_Y = plotAxisConvBackward(pl, bN, cur_Y + (pl->viewport.max_y - pl->viewport.min_y)); + + tol_X = fval_X - tol_X; + tol_Y = fval_Y - tol_Y; + } + + if ( pl->slice_mode_N == 1 && pl->shift_on != 0 + && pl->figure[fN].slice_base_catch == 1) { + + pl->figure[fN].slice_busy = 1; + pl->figure[fN].slice_X = fval_X; + pl->figure[fN].slice_Y = fval_Y; + } + + dN = pl->figure[fN].data_N; + + row = plotDataPickGet(pl, dN, cNX, cNY, + fval_X, fval_Y, tol_X, tol_Y, &id_N); + + if (row != NULL) { + + cNX = pl->figure[fN].column_X; + cNY = pl->figure[fN].column_Y; + + fval_X = (cNX < 0) ? id_N : row[cNX]; + fval_Y = (cNY < 0) ? id_N : row[cNY]; + + if (pl->figure[fN].slice_busy == 0) { + + pl->figure[fN].slice_busy = 1; + pl->figure[fN].slice_X = fval_X; + pl->figure[fN].slice_Y = fval_Y; + } + + pl->figure[fN].slice_row = row; + pl->figure[fN].slice_id_N = id_N; + } + } + } + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + if ( pl->figure[fN].slice_busy == 0 + && pl->figure[fN].busy != 0 + && pl->figure[fN].hidden == 0) { + + dN = pl->figure[fN].data_N; + + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { - row = plotDataSliceGet(pl, dN, cX, - fval_X, &id_N); + if ( pl->figure[N].slice_busy != 0 + && pl->figure[N].busy != 0 + && pl->figure[N].hidden == 0 + && pl->figure[N].slice_row != NULL + && pl->figure[N].data_N == dN) { - dN_s = dN; - aN_s = aN; - cX_s = cX; - } + row = pl->figure[N].slice_row; + id_N = pl->figure[N].slice_id_N; - if (row != NULL) { + cNX = pl->figure[fN].column_X; + cNY = pl->figure[fN].column_Y; - cX = pl->figure[fN].column_X; - cY = pl->figure[fN].column_Y; + fval_X = (cNX < 0) ? id_N : row[cNX]; + fval_Y = (cNY < 0) ? id_N : row[cNY]; - fval_X = (cX < 0) ? id_N : row[cX]; - fval_Y = (cY < 0) ? id_N : row[cY]; + pl->figure[fN].slice_busy = 2; + pl->figure[fN].slice_X = fval_X; + pl->figure[fN].slice_Y = fval_Y; - pl->figure[fN].slice_busy = 1; - pl->figure[fN].slice_X = fval_X; - pl->figure[fN].slice_Y = fval_Y; + break; + } } } } + for (fN = 0, N = 0; fN < PLOT_FIGURE_MAX; ++fN) { + + N += (pl->figure[fN].slice_busy != 0) ? 1 : 0; + } + + if (N == 0) + return ; + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { pl->data_box_text[fN][0] = 0; @@ -5693,7 +6674,8 @@ void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) const read_t *rd = (const read_t *) pl->ld; - if (pl->slice_mode_N != 0) { + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { fval_X = pl->figure[fN].slice_base_X; fval_Y = pl->figure[fN].slice_base_Y; @@ -5705,13 +6687,24 @@ void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_Y - fval_Y); } else { - plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_X); - dN = pl->figure[fN].data_N; - cY = pl->figure[fN].column_Y; - if ( rd->data[dN].hint[cY] == DATA_HINT_HEX - || rd->data[dN].hint[cY] == DATA_HINT_OCT) { + cNX = pl->figure[fN].column_Y; + cNY = pl->figure[fN].column_Y; + + if ( pl->fhexadecimal != 0 + && ( rd->data[dN].hint[cNX] == DATA_HINT_HEX + || rd->data[dN].hint[cNX] == DATA_HINT_OCT)) { + + plotDataBoxTextHex(pl, fN, pl->figure[fN].slice_X); + } + else { + plotDataBoxTextFmt(pl, fN, pl->figure[fN].slice_X); + } + + if ( pl->fhexadecimal != 0 + && ( rd->data[dN].hint[cNY] == DATA_HINT_HEX + || rd->data[dN].hint[cNY] == DATA_HINT_OCT)) { plotDataBoxTextHex(pl, fN, pl->figure[fN].slice_Y); } @@ -5722,18 +6715,18 @@ void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y) } } - if (pl->data_box_on != DATA_BOX_SLICE) { + if (pl->data_box_on != DATA_BOX_PICK) { - pl->data_box_on = DATA_BOX_SLICE; + pl->data_box_on = DATA_BOX_PICK; pl->data_box_X = pl->viewport.max_x; pl->data_box_Y = 0; } } static void -plotSliceLightDraw(plot_t *pl, SDL_Surface *surface) +plotPickDraw(plot_t *pl, SDL_Surface *surface) { - double base_X, base_Y, data_X, data_Y, temp; + double base_X, base_Y, data_X, data_Y; int fN, aN, bN; for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { @@ -5743,47 +6736,47 @@ plotSliceLightDraw(plot_t *pl, SDL_Surface *surface) aN = pl->figure[fN].axis_X; bN = pl->figure[fN].axis_Y; - base_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_base_X); - base_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_base_Y); + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { + + base_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_base_X); + base_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_base_Y); + } data_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_X); data_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_Y); - if (data_X < base_X) { - - temp = base_X; - base_X = data_X; - data_X = temp; - } - - if (data_Y < base_Y) { + SDL_LockSurface(surface); - temp = base_Y; - base_Y = data_Y; - data_Y = temp; - } + if ( pl->slice_mode_N != 0 + && pl->figure[fN].slice_base_catch != 0) { - SDL_LockSurface(surface); + if ( fp_isfinite(base_X) + && fp_isfinite(base_Y) + && fp_isfinite(data_X) + && fp_isfinite(data_Y)) { - if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_X) { + drawDashReset(pl->dw); + drawDashCanvas(pl->dw, surface, &pl->viewport, + base_X, base_Y, data_X, data_Y, + 12, pl->dw->thickness, + pl->layout_fence_dash, + pl->layout_fence_space); + } - if (fp_isfinite(base_X) && fp_isfinite(data_X)) { + if (fp_isfinite(base_X) && fp_isfinite(base_Y)) { - drawClipRect(surface, &pl->viewport, - base_X, pl->viewport.min_y, - data_X, pl->viewport.max_y, - pl->sch->plot_hidden); + drawDotCanvas(pl->dw, surface, &pl->viewport, + base_X, base_Y, + pl->layout_fence_point, 12, 0); } } - else if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_Y) { - if (fp_isfinite(base_Y) && fp_isfinite(data_Y)) { + if (fp_isfinite(data_X) && fp_isfinite(data_Y)) { - drawClipRect(surface, &pl->viewport, - pl->viewport.min_x, base_Y, - pl->viewport.max_x, data_Y, - pl->sch->plot_hidden); - } + drawDotCanvas(pl->dw, surface, &pl->viewport, + data_X, data_Y, + pl->layout_fence_point, 12, 0); } SDL_UnlockSurface(surface); @@ -5791,103 +6784,126 @@ plotSliceLightDraw(plot_t *pl, SDL_Surface *surface) } } -static void -plotSliceDraw(plot_t *pl, SDL_Surface *surface) +void plotBrushErase(plot_t *pl) { - double base_X, base_Y, data_X, data_Y; - int fN, aN, bN; + double fmin_X, fmin_Y, fmax_X, fmax_Y; + int N, fN, aN, bN, dN, cNX, cNY, sNX, sNY; + + int modified = (int) (SDL_GetTicks() & 65535U); + + modified += pl->brush_box_X + pl->brush_box_Y + + pl->brush_cur_X + pl->brush_cur_Y; for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) { - if (pl->figure[fN].slice_busy != 0) { + if ( pl->figure[fN].busy != 0 + && pl->figure[fN].hidden == 0 + && pl->figure[fN].brush_N != 0) { - aN = pl->figure[fN].axis_X; - bN = pl->figure[fN].axis_Y; + dN = pl->figure[fN].data_N; - if (pl->slice_mode_N != 0) { + cNX = pl->figure[fN].column_X; + cNY = pl->figure[fN].column_Y; - base_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_base_X); - base_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_base_Y); + if (cNX < pl->data[dN].column_N) { + + cNX = plotGetSubtractClone(pl, dN, cNX); } + else { + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { - data_X = plotAxisConvForward(pl, aN, pl->figure[fN].slice_X); - data_Y = plotAxisConvForward(pl, bN, pl->figure[fN].slice_Y); + if ( N != fN && pl->figure[N].busy != 0 + && dN == pl->figure[N].data_N + && cNX == pl->figure[N].column_X) { - SDL_LockSurface(surface); + cNX = plotGetSubtractClone(pl, dN, cNX); + break; + } - if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_X) { + if ( N != fN && pl->figure[N].busy != 0 + && dN == pl->figure[N].data_N + && cNX == pl->figure[N].column_Y) { + + cNX = plotGetSubtractClone(pl, dN, cNX); + break; + } + } + } - if (pl->slice_mode_N != 0) { + if (cNY < pl->data[dN].column_N) { - if (fp_isfinite(base_X)) { + cNY = plotGetSubtractClone(pl, dN, cNY); + } + else { + for (N = 0; N < PLOT_FIGURE_MAX; ++N) { - drawDashReset(pl->dw); - drawDash(pl->dw, surface, &pl->viewport, - base_X, pl->viewport.min_y, - base_X, pl->viewport.max_y, - pl->sch->plot_text, - pl->layout_fence_dash, - pl->layout_fence_space); + if ( N != fN && pl->figure[N].busy != 0 + && dN == pl->figure[N].data_N + && cNY == pl->figure[N].column_X) { + + cNY = plotGetSubtractClone(pl, dN, cNY); + break; } - } - if (fp_isfinite(data_X)) { + if ( N != fN && pl->figure[N].busy != 0 + && dN == pl->figure[N].data_N + && cNY == pl->figure[N].column_Y) { - drawDashReset(pl->dw); - drawDash(pl->dw, surface, &pl->viewport, - data_X, pl->viewport.min_y, - data_X, pl->viewport.max_y, - pl->sch->plot_text, - pl->layout_fence_dash, - pl->layout_fence_space); + cNY = plotGetSubtractClone(pl, dN, cNY); + break; + } } } - else if (pl->axis[pl->slice_axis_N].busy == AXIS_BUSY_Y) { - if (pl->slice_mode_N != 0) { + if ( cNX >= pl->data[dN].column_N + && cNY >= pl->data[dN].column_N) { - if (fp_isfinite(base_Y)) { + aN = pl->figure[fN].axis_X; + bN = pl->figure[fN].axis_Y; - drawDashReset(pl->dw); - drawDash(pl->dw, surface, &pl->viewport, - pl->viewport.min_x, base_Y, - pl->viewport.max_x, base_Y, - pl->sch->plot_text, - pl->layout_fence_dash, - pl->layout_fence_space); - } + if (pl->brush_box_X < pl->brush_cur_X) { + + fmin_X = plotAxisConvBackward(pl, aN, pl->brush_box_X); + fmax_X = plotAxisConvBackward(pl, aN, pl->brush_cur_X); + } + else { + fmin_X = plotAxisConvBackward(pl, aN, pl->brush_cur_X); + fmax_X = plotAxisConvBackward(pl, aN, pl->brush_box_X); } - if (fp_isfinite(data_Y)) { + if (pl->brush_box_Y < pl->brush_cur_Y) { - drawDashReset(pl->dw); - drawDash(pl->dw, surface, &pl->viewport, - pl->viewport.min_x, data_Y, - pl->viewport.max_x, data_Y, - pl->sch->plot_text, - pl->layout_fence_dash, - pl->layout_fence_space); + fmax_Y = plotAxisConvBackward(pl, bN, pl->brush_box_Y); + fmin_Y = plotAxisConvBackward(pl, bN, pl->brush_cur_Y); + } + else { + fmax_Y = plotAxisConvBackward(pl, bN, pl->brush_cur_Y); + fmin_Y = plotAxisConvBackward(pl, bN, pl->brush_box_Y); } - } - if (pl->slice_mode_N != 0) { + sNX = cNX - pl->data[dN].column_N; + sNY = cNY - pl->data[dN].column_N; - if (fp_isfinite(base_X) && fp_isfinite(base_Y)) { + if (pl->data[dN].sub[sNX].busy == SUBTRACT_SCALE) { - drawDotCanvas(pl->dw, surface, &pl->viewport, - base_X, base_Y, - pl->layout_fence_point, 10, 0); + pl->data[dN].sub[sNX].op.scale.modified += modified; } - } - if (fp_isfinite(data_X) && fp_isfinite(data_Y)) { + if (pl->data[dN].sub[sNY].busy == SUBTRACT_SCALE) { - drawDotCanvas(pl->dw, surface, &pl->viewport, - data_X, data_Y, - pl->layout_fence_point, 10, 0); - } + pl->data[dN].sub[sNY].op.scale.modified += modified; + } - SDL_UnlockSurface(surface); + plotDataErase(pl, dN, cNX, cNY, fmin_X, fmin_Y, fmax_X, fmax_Y); + + cNX = plotSubtractOriginal(pl, dN, cNX); + cNY = plotSubtractOriginal(pl, dN, cNY); + + pl->figure[fN].column_X = cNX; + pl->figure[fN].column_Y = cNY; + + plotSubtractGarbage(pl, dN); + } } } } @@ -6062,35 +7078,35 @@ plotDrawPalette(plot_t *pl) palette[6] = drawRGBMap(dw, sch->plot_figure[5]); palette[7] = drawRGBMap(dw, sch->plot_figure[6]); palette[8] = drawRGBMap(dw, sch->plot_figure[7]); - palette[9] = drawRGBMap(dw, sch->plot_hidden); - palette[10] = drawRGBMap(dw, sch->plot_text); + palette[9] = drawRGBMap(dw, sch->plot_figure[8]); + palette[10] = drawRGBMap(dw, sch->plot_figure[9]); + palette[11] = drawRGBMap(dw, sch->plot_hidden); + palette[12] = drawRGBMap(dw, sch->plot_text); } -static int -plotGetTickCached(plot_t *pl) +static Uint32 +plotGetTick(plot_t *pl) { - if (pl->tick_skip > 0) { + if (pl->tick_skip++ >= 63) { - pl->tick_skip--; - } - else { pl->tick_cached = SDL_GetTicks(); - pl->tick_skip = 63; + pl->tick_skip = 0; } return pl->tick_cached; } static void -plotDrawFigureTrial(plot_t *pl, int fN, int tTOP) +plotDrawFigureTrial(plot_t *pl, int fN, Uint32 tTOP) { const fval_t *row; + double scale_X, scale_Y, offset_X, offset_Y, im_MIN, im_MAX; double X, Y, last_X, last_Y, im_X, im_Y, last_im_X, last_im_Y; int dN, rN, xN, yN, xNR, yNR, aN, bN, id_N, id_N_top, kN, kN_cached; int job, skipped, line, rc, ncolor, fdrawing, fwidth; - ncolor = (pl->figure[fN].hidden != 0) ? 9 : fN + 1; + ncolor = (pl->figure[fN].hidden != 0) ? 11 : fN + 1; fdrawing = pl->figure[fN].drawing; fwidth = pl->figure[fN].width; @@ -6253,7 +7269,7 @@ plotDrawFigureTrial(plot_t *pl, int fN, int tTOP) line = 0; } - if (id_N > id_N_top || plotGetTickCached(pl) > tTOP) { + if (id_N > id_N_top || plotGetTick(pl) > tTOP) { pl->draw[fN].sketch = SKETCH_INTERRUPTED; pl->draw[fN].rN = rN; @@ -6344,7 +7360,7 @@ plotDrawFigureTrial(plot_t *pl, int fN, int tTOP) plotDataChunkSkip(pl, dN, &rN, &id_N); } - if (id_N > id_N_top || plotGetTickCached(pl) > tTOP) { + if (id_N > id_N_top || plotGetTick(pl) > tTOP) { pl->draw[fN].sketch = SKETCH_INTERRUPTED; pl->draw[fN].rN = rN; @@ -6390,7 +7406,7 @@ plotDrawSketch(plot_t *pl, SDL_Surface *surface) fN = pl->sketch[hN].figure_N; - ncolor = (pl->figure[fN].hidden != 0) ? 9 : fN + 1; + ncolor = (pl->figure[fN].hidden != 0) ? 11 : fN + 1; fdrawing = pl->sketch[hN].drawing; fwidth = pl->sketch[hN].width; @@ -6493,6 +7509,105 @@ plotDrawSketch(plot_t *pl, SDL_Surface *surface) SDL_UnlockSurface(surface); } +static void +plotDrawBrush(plot_t *pl, SDL_Surface *surface) +{ + double scale_X, offset_X, scale_Y, offset_Y; + double X, Y, *chunk, *lend; + int hN, fN, aN, bN, min_X, min_Y, max_X, max_Y; + + for (fN = 0; fN < PLOT_FIGURE_MAX; ++fN) + pl->figure[fN].brush_N = 0; + + hN = pl->sketch_list_todraw; + + SDL_LockSurface(surface); + + while (hN >= 0) { + + fN = pl->sketch[hN].figure_N; + + if (pl->figure[fN].hidden != 0) + goto plotDrawBrush_SKIP; + + aN = pl->figure[fN].axis_X; + scale_X = pl->axis[aN].scale; + offset_X = pl->axis[aN].offset; + + if (pl->axis[aN].slave != 0) { + + bN = pl->axis[aN].slave_N; + scale_X *= pl->axis[bN].scale; + offset_X = offset_X * pl->axis[bN].scale + pl->axis[bN].offset; + } + + aN = pl->figure[fN].axis_Y; + scale_Y = pl->axis[aN].scale; + offset_Y = pl->axis[aN].offset; + + if (pl->axis[aN].slave != 0) { + + bN = pl->axis[aN].slave_N; + scale_Y *= pl->axis[bN].scale; + offset_Y = offset_Y * pl->axis[bN].scale + pl->axis[bN].offset; + } + + X = (double) (pl->viewport.max_x - pl->viewport.min_x); + Y = (double) (pl->viewport.min_y - pl->viewport.max_y); + + scale_X *= X; + offset_X = offset_X * X + pl->viewport.min_x; + scale_Y *= Y; + offset_Y = offset_Y * Y + pl->viewport.max_y; + + if (pl->brush_box_X < pl->brush_cur_X) { + + min_X = pl->brush_box_X; + max_X = pl->brush_cur_X; + } + else { + min_X = pl->brush_cur_X; + max_X = pl->brush_box_X; + } + + if (pl->brush_box_Y < pl->brush_cur_Y) { + + min_Y = pl->brush_box_Y; + max_Y = pl->brush_cur_Y; + } + else { + min_Y = pl->brush_cur_Y; + max_Y = pl->brush_box_Y; + } + + chunk = pl->sketch[hN].chunk; + lend = chunk + pl->sketch[hN].length; + + while (chunk < lend) { + + X = *chunk++; + Y = *chunk++; + + X = X * scale_X + offset_X; + Y = Y * scale_Y + offset_Y; + + if ( X > min_X && X < max_X + && Y > min_Y && Y < max_Y) { + + drawDotCanvas(pl->dw, surface, &pl->viewport, + X, Y, pl->layout_fence_point, 12, 1); + + pl->figure[fN].brush_N++; + } + } + +plotDrawBrush_SKIP: + hN = pl->sketch[hN].linked; + } + + SDL_UnlockSurface(surface); +} + static void plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) { @@ -6633,7 +7748,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) if (hovered != 0) { - tdec = pl->layout_axis_box; + tdec = pl->layout_ruler_box; tdec += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; drawFillRect(surface, pl->viewport.min_x, lpos, pl->viewport.max_x, @@ -6693,7 +7808,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) if (hovered != 0) { - tdec = pl->layout_axis_box; + tdec = pl->layout_ruler_box; tdec += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; drawFillRect(surface, lpos - tdec, pl->viewport.min_y, lpos, @@ -6764,7 +7879,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) sprintf(numbuf, "E%+i", - tdec); tpos = (pl->axis[aN].compact == 0) ? - lpos + pl->layout_axis_box : + lpos + pl->layout_ruler_box : lpos + pl->layout_tick_tooth; tpos += pl->layout_font_height / 2; @@ -6837,7 +7952,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) } else { tpos = (pl->viewport.min_x + pl->viewport.max_x) / 2; - lpos = lpos + pl->layout_axis_box + pl->layout_font_height / 2; + lpos = lpos + pl->layout_ruler_box + pl->layout_font_height / 2; if (pl->axis[aN].label[0] != 0) { @@ -6868,7 +7983,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) sprintf(numbuf, "E%+i", - tdec); tpos = (pl->axis[aN].compact == 0) ? - lpos - pl->layout_axis_box : + lpos - pl->layout_ruler_box : lpos - pl->layout_tick_tooth; tpos -= pl->layout_font_height / 2; @@ -6942,7 +8057,7 @@ plotDrawAxis(plot_t *pl, SDL_Surface *surface, int aN) } } else { - lpos = lpos - pl->layout_axis_box - pl->layout_font_height / 2; + lpos = lpos - pl->layout_ruler_box - pl->layout_font_height / 2; tpos = (pl->viewport.min_y + pl->viewport.max_y) / 2; if (pl->axis[aN].label[0] != 0) { @@ -7022,7 +8137,7 @@ plotLegendDraw(plot_t *pl, SDL_Surface *surface) SDL_LockSurface(surface); - ncolor = (pl->figure[fN].hidden != 0) ? 9 : fN + 1; + ncolor = (pl->figure[fN].hidden != 0) ? 11 : fN + 1; hovered = (pl->hover_figure == fN) ? 1 : 0; if (pl->shift_on != 0) { @@ -7160,7 +8275,8 @@ plotDataBoxLayout(plot_t *pl) int N, size_X, size_Y; int size_N = 0, size_MAX = 0; - if (pl->data_box_on == DATA_BOX_SLICE) { + if ( pl->data_box_on == DATA_BOX_SLICE + || pl->data_box_on == DATA_BOX_PICK) { for (N = 0; N < PLOT_FIGURE_MAX; ++N) { @@ -7229,7 +8345,8 @@ plotDataBoxDraw(plot_t *pl, SDL_Surface *surface) SDL_UnlockSurface(surface); - if (pl->data_box_on == DATA_BOX_SLICE) { + if ( pl->data_box_on == DATA_BOX_SLICE + || pl->data_box_on == DATA_BOX_PICK) { for (N = 0; N < PLOT_FIGURE_MAX; ++N) { @@ -7329,7 +8446,7 @@ void plotLayout(plot_t *pl) pl->axis[aN].layout_pos = posX; - posX += pl->layout_axis_box; + posX += pl->layout_ruler_box + pl->dw->thickness; posX += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; } @@ -7340,7 +8457,7 @@ void plotLayout(plot_t *pl) pl->axis[aN].layout_pos = posY; - posY += pl->layout_axis_box; + posY += pl->layout_ruler_box + pl->dw->thickness; posY += (pl->axis[aN].compact == 0) ? pl->layout_label_box : 0; } } @@ -7359,13 +8476,13 @@ void plotLayout(plot_t *pl) if (pl->mark_on != 0) { - if (pl->mark_count == 0) { + if (pl->mark_length == 0) { plotMarkLayout(pl); } } else { - pl->mark_count = 0; + pl->mark_length = 0; } } @@ -7373,7 +8490,9 @@ static void plotDrawFigureTrialAll(plot_t *pl) { int FIGS[PLOT_FIGURE_MAX]; - int N, fN, fQ, lN, dN, tTOP; + int N, fN, fQ, lN, dN; + + Uint32 tTOP; lN = 0; @@ -7409,7 +8528,9 @@ plotDrawFigureTrialAll(plot_t *pl) if (pl->draw_in_progress != 0) { - tTOP = SDL_GetTicks() + 20; + pl->tick_cached = SDL_GetTicks(); + + tTOP = pl->tick_cached + (Uint32) PLOT_RUNTIME_MAX; drawClearTrial(pl->dw); @@ -7467,9 +8588,10 @@ plotDrawAxisAll(plot_t *pl, SDL_Surface *surface) void plotDraw(plot_t *pl, SDL_Surface *surface) { - if (pl->slice_mode_N != 0) { + if ( pl->slice_on != 0 + && pl->slice_mode_N != 0) { - plotSliceLightDraw(pl, surface); + plotSliceDrawLight(pl, surface); } drawPixmapAlloc(pl->dw, surface); @@ -7486,6 +8608,20 @@ void plotDraw(plot_t *pl, SDL_Surface *surface) plotMarkDraw(pl, surface); } + if (pl->slice_on != 0) { + + plotSliceDraw(pl, surface); + } + else if (pl->pick_on != 0) { + + plotPickDraw(pl, surface); + } + + if (pl->brush_on != 0) { + + plotDrawBrush(pl, surface); + } + SDL_LockSurface(surface); drawFlushCanvas(pl->dw, surface, &pl->viewport); @@ -7496,11 +8632,6 @@ void plotDraw(plot_t *pl, SDL_Surface *surface) plotDrawAxisAll(pl, surface); - if (pl->slice_on != 0) { - - plotSliceDraw(pl, surface); - } - plotLegendDraw(pl, surface); SDL_LockSurface(surface); diff --git a/pgui/gp/plot.h b/pgui/gp/plot.h index f5eea4f..9de74b2 100644 --- a/pgui/gp/plot.h +++ b/pgui/gp/plot.h @@ -43,10 +43,10 @@ #define PLOT_CHUNK_CACHE 4 #define PLOT_RCACHE_SIZE 32 #define PLOT_SLICE_SPAN 4 -#define PLOT_AXES_MAX 9 -#define PLOT_FIGURE_MAX 8 -#define PLOT_DATA_BOX_MAX 8 -#define PLOT_MEDIAN_MAX 91 +#define PLOT_AXES_MAX 10 +#define PLOT_FIGURE_MAX 10 +#define PLOT_DATA_BOX_MAX 10 +#define PLOT_MEDIAN_MAX 37 #define PLOT_POLYFIT_MAX 7 #define PLOT_SUBTRACT 20 #define PLOT_GROUP_MAX 40 @@ -54,6 +54,7 @@ #define PLOT_SKETCH_CHUNK_SIZE 32768 #define PLOT_SKETCH_MAX 800 #define PLOT_STRING_MAX 200 +#define PLOT_RUNTIME_MAX 20 enum { TTF_ID_NONE = 0, @@ -103,6 +104,12 @@ enum { SUBTRACT_FILTER_MEDIAN }; +enum { + UNWRAP_NONE = 0, + UNWRAP_OVERFLOW, + UNWRAP_BURST +}; + enum { SKETCH_STARTED = 0, SKETCH_INTERRUPTED, @@ -112,6 +119,7 @@ enum { enum { DATA_BOX_FREE = 0, DATA_BOX_SLICE, + DATA_BOX_PICK, DATA_BOX_POLYFIT }; @@ -175,9 +183,10 @@ typedef struct { struct { - int column_1; - int column_2; - int column_3; + int column_X; + int column_Y; + + int column_T; int length; int unwrap; @@ -200,7 +209,8 @@ typedef struct { struct { - int column_1; + int column_X; + int modified; double scale; double offset; @@ -232,17 +242,18 @@ typedef struct { struct { - int column_1; - int column_2; + int column_X; + int column_Y; } binary; struct { - int column_1; + int column_X; + int column_Y; double gain; - double state; + double state[2]; } filter; } @@ -324,11 +335,17 @@ typedef struct { double mark_Y[PLOT_MARK_MAX]; int slice_busy; + const fval_t *slice_row; + int slice_id_N; double slice_X; double slice_Y; + + int slice_base_catch; double slice_base_X; double slice_base_Y; + int brush_N; + char label[PLOT_STRING_MAX]; } figure[PLOT_FIGURE_MAX]; @@ -379,6 +396,19 @@ typedef struct { int slice_mode_N; int slice_axis_N; + int pick_on; + + int mark_on; + int mark_length; + int mark_size; + int mark_density; + + int brush_on; + int brush_box_X; + int brush_box_Y; + int brush_cur_X; + int brush_cur_Y; + struct { int sketch; @@ -398,7 +428,7 @@ typedef struct { int draw_in_progress; - int tick_cached; + Uint32 tick_cached; int tick_skip; struct { @@ -426,7 +456,7 @@ typedef struct { int layout_font_long; int layout_font_space; int layout_border; - int layout_axis_box; + int layout_ruler_box; int layout_label_box; int layout_tick_tooth; int layout_grid_dash; @@ -446,11 +476,6 @@ typedef struct { int hover_data_box; int hover_axis; - int mark_on; - int mark_count; - int mark_size; - int mark_density; - int interpolation; int defungap; @@ -459,6 +484,7 @@ typedef struct { int transparency; int fprecision; + int fhexadecimal; int lz4_compress; int shift_on; @@ -480,6 +506,7 @@ unsigned long long plotDataMemoryCached(plot_t *pl, int dN); void plotDataAlloc(plot_t *pl, int dN, int cN, int lN); void plotDataResize(plot_t *pl, int dN, int lN); +int plotDataLength(plot_t *pl, int dN); int plotDataSpaceLeft(plot_t *pl, int dN); void plotDataGrowUp(plot_t *pl, int dN); void plotDataSubtractCompute(plot_t *pl, int dN, int sN); @@ -495,6 +522,7 @@ void plotDataRangeCacheSubtractClean(plot_t *pl); int plotDataRangeCacheFetch(plot_t *pl, int dN, int cN); void plotAxisLabel(plot_t *pl, int aN, const char *label); +int plotAxisRangeGet(plot_t *pl, int aN, double *pmin, double *pmax); void plotAxisScaleManual(plot_t *pl, int aN, double min, double max); void plotAxisScaleAuto(plot_t *pl, int aN); void plotAxisScaleAutoCond(plot_t *pl, int aN, int bN); @@ -514,6 +542,7 @@ void plotAxisSlave(plot_t *pl, int aN, int bN, double scale, double offset, int void plotAxisRemove(plot_t *pl, int aN); void plotFigureAdd(plot_t *pl, int fN, int dN, int nX, int nY, int aX, int aY, const char *label); +void plotTotalSubtractGarbage(plot_t *pl); void plotFigureRemove(plot_t *pl, int fN); void plotFigureGarbage(plot_t *pl, int dN); void plotFigureMoveAxes(plot_t *pl, int fN); @@ -522,26 +551,26 @@ void plotFigureExchange(plot_t *pl, int fN_1, int fN_2); int plotFigureSelected(plot_t *pl); int plotFigureAnyData(plot_t *pl); +int plotFigureHaveData(plot_t *pl, int dN); -tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, - int length, int unwrap, int opdata); +tuple_t plotGetSubtractTimeMedian(plot_t *pl, int dN, int cNX, int cNY, int length, int unwrap, int opdata); int plotGetSubtractScale(plot_t *pl, int dN, int cN, double scale, double offset); int plotGetSubtractResample(plot_t *pl, int dN, int cN_X, int in_dN, int in_cN_X, int in_cN_Y); int plotGetSubtractBinary(plot_t *pl, int dN, int opSUB, int cN_1, int cN_2); -int plotGetSubtractFilter(plot_t *pl, int dN, int cN, int opSUB, double gain); +int plotGetSubtractFilter(plot_t *pl, int dN, int cNX, int cNY, int opSUB, double gain); int plotGetSubtractMedian(plot_t *pl, int dN, int cN, int opSUB, int length); int plotGetFreeFigure(plot_t *pl); -int plotFigureSubtractGetMedianConfig(plot_t *pl, int fN, int config[3]); +int plotFigureSubtractGetMedianConfig(plot_t *pl, int fN, int *length, int *unwrap, int *opdata); void plotFigureSubtractTimeMedian(plot_t *pl, int fN_1, int length, int unwrap, int opdata); void plotFigureSubtractScale(plot_t *pl, int fN_1, int aBUSY, double scale, double offset); void plotFigureSubtractFilter(plot_t *pl, int fN_1, int opSUB, double gain); void plotFigureSubtractSwitch(plot_t *pl, int opSUB); -void plotFigureSubtractResample(plot_t *pl, int fN); +void plotTotalSubtractResample(plot_t *pl, int dN, double tmin, double tmax); int plotDataBoxPolyfit(plot_t *pl, int fN); void plotFigureSubtractPolyfit(plot_t *pl, int fN_1, int N0, int N1); -void plotFigureExportCSV(plot_t *pl, const char *file); +int plotFigureExportCSV(plot_t *pl, const char *file); void plotFigureClean(plot_t *pl); void plotSketchClean(plot_t *pl); int plotGetSketchLength(plot_t *pl); @@ -553,6 +582,8 @@ void plotGroupScale(plot_t *pl, int gN, int knob, double scale, double offset); void plotSliceSwitch(plot_t *pl); void plotSliceTrack(plot_t *pl, int cur_X, int cur_Y); +void plotPickTrack(plot_t *pl, int cur_X, int cur_Y); +void plotBrushErase(plot_t *pl); int plotLegendGetByClick(plot_t *pl, int cur_X, int cur_Y); int plotLegendBoxGetByClick(plot_t *pl, int cur_X, int cur_Y); diff --git a/pgui/gp/read.c b/pgui/gp/read.c index 8e9057c..193c9fa 100644 --- a/pgui/gp/read.c +++ b/pgui/gp/read.c @@ -187,13 +187,12 @@ read_t *readAlloc(draw_t *dw, plot_t *pl) { read_t *rd; - rd = calloc(1, sizeof(read_t)); + rd = (read_t *) calloc(1, sizeof(read_t)); rd->dw = dw; rd->pl = pl; - strcpy(rd->screenpath, "."); - + rd->screenpath[0] = 0; rd->ttfname[0] = 0; rd->window_size_x = GP_MIN_SIZE_X; @@ -217,7 +216,7 @@ read_t *readAlloc(draw_t *dw, plot_t *pl) rd->preload = 8388608; rd->chunk = 4096; rd->timeout = 5000; - rd->length_N = 1000; + rd->length_N = 0; rd->bind_N = -1; rd->page_N = -1; @@ -236,11 +235,11 @@ readCutLabel(char *tbuf, const char *text, int allowed) { int length; - length = strlen(text); + length = (int) strlen(text); if (length > (allowed - 1)) { - text = utf8_skip_b(text, length - (allowed - 2)); + text = utf8_skip_byte(text, length - (allowed - 2)); strcpy(tbuf, "~"); strcat(tbuf, text); @@ -350,24 +349,6 @@ legacy_fopen_from_UTF8(const char *file, const char *mode) #endif /* _WINDOWS */ #ifdef _LEGACY -static int -legacy_GetFreeData(read_t *rd) -{ - int N, dN = -1; - - for (N = 0; N < PLOT_DATASET_MAX; ++N) { - - if ( rd->data[N].format == FORMAT_NONE - && rd->data[N].file[0] == 0) { - - dN = N; - break; - } - } - - return dN; -} - static int legacy_LabelExtract(char *s, char *label[9]) { @@ -461,7 +442,7 @@ void legacy_ConfigGRM(read_t *rd, const char *path, const char *confile, int dN, cN, pN, fN, line_N, lbN, stub, len; float fpN; - dN = legacy_GetFreeData(rd); + dN = readGetFreeData(rd); if (dN < 0) { @@ -489,8 +470,8 @@ void legacy_ConfigGRM(read_t *rd, const char *path, const char *confile, return ; } else { - len = fread(&stub, 2, 1, fd); - len += fread(&fpN, 4, 1, fd); + len = (int) fread(&stub, 2, 1, fd); + len += (int) fread(&fpN, 4, 1, fd); cN = (int) fpN; @@ -503,7 +484,7 @@ void legacy_ConfigGRM(read_t *rd, const char *path, const char *confile, } else { fseek(fd, 0UL, SEEK_SET); - len = fread(&fpN, 4, 1, fd); + len = (int) fread(&fpN, 4, 1, fd); cN = (int) fpN; @@ -667,7 +648,7 @@ void legacy_ConfigGRM(read_t *rd, const char *path, const char *confile, if (cY != cYm) { rd->page[pN].fig[fN].bY[N].busy = SUBTRACT_BINARY_SUBTRACTION; - rd->page[pN].fig[fN].bY[N].column_2 = cYm; + rd->page[pN].fig[fN].bY[N].column_Y = cYm; N++; } @@ -729,7 +710,7 @@ FILE *unified_fopen(const char *file, const char *mode) } static char * -readTimeGetBuf(char *s, int len, FILE *fd, int timeout) +readCSVGetBuf(char *s, int len, FILE *fd, int timeout) { int c, eol, nq, waiting; @@ -789,7 +770,7 @@ readTimeGetBuf(char *s, int len, FILE *fd, int timeout) } static int -readTEXTGetRow(read_t *rd, int dN, int label_N) +readCSVGetRow(read_t *rd, int dN, int label_N) { fval_t *row = rd->data[dN].row; int *hint = rd->data[dN].hint; @@ -928,7 +909,7 @@ readTEXTGetRow(read_t *rd, int dN, int label_N) } static int -readTEXTGetLabel(read_t *rd, int dN) +readCSVGetLabel(read_t *rd, int dN) { char *label, *s = rd->data[dN].buf; int m, N; @@ -989,12 +970,12 @@ readTEXTGetLabel(read_t *rd, int dN) } static int -readTEXTGetBOM(read_t *rd, FILE *fd) +readCSVGetBOM(FILE *fd) { char tbuf[8]; int len, bom = BOM_NONE; - len = fread(tbuf, 4, 1, fd); + len = (int) fread(tbuf, 4, 1, fd); fseek(fd, 0UL, SEEK_SET); @@ -1021,7 +1002,7 @@ readTEXTGetBOM(read_t *rd, FILE *fd) } static int -readTEXTGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) +readCSVGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) { int label_N, fixed_N, total_N; int N, cN, timeout; @@ -1033,10 +1014,10 @@ readTEXTGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) fixed_N = 0; total_N = 0; - timeout = 100; + timeout = 200; do { - r = readTimeGetBuf(rd->data[dN].buf, sizeof(rd->data[0].buf), fd, timeout); + r = readCSVGetBuf(rd->data[dN].buf, sizeof(rd->data[0].buf), fd, timeout); total_N++; @@ -1045,16 +1026,16 @@ readTEXTGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) if (label_N < 1) { - label_N = readTEXTGetLabel(rd, dN); + label_N = readCSVGetLabel(rd, dN); } else { - cN = readTEXTGetRow(rd, dN, label_N); + cN = readCSVGetRow(rd, dN, label_N); if (cN != 0) { if (cN > label_N) { - label_N = readTEXTGetLabel(rd, dN); + label_N = readCSVGetLabel(rd, dN); fixed_N = 0; } else { @@ -1065,7 +1046,7 @@ readTEXTGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) fixed_N++; - if (fixed_N >= 3) { + if (fixed_N >= READ_TEXT_HEAD_MAX) { rd->data[dN].line_N = total_N + 1; break; @@ -1088,7 +1069,7 @@ readTEXTGetCN(read_t *rd, int dN, FILE *fd, fval_t *rbuf, int *rbuf_N) } static void -readClose(read_t *rd, int dN) +readCloseFile(read_t *rd, int dN) { async_close(rd->data[dN].afd); @@ -1099,13 +1080,12 @@ readClose(read_t *rd, int dN) rd->data[dN].fd = NULL; rd->data[dN].afd = NULL; - - rd->files_N -= 1; } void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int fmt) { - fval_t rbuf[READ_COLUMN_MAX * 3]; + fval_t rbuf[READ_COLUMN_MAX * READ_TEXT_HEAD_MAX]; + int N, rbuf_N, bom; FILE *fd; @@ -1113,10 +1093,10 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f if (rd->data[dN].fd != NULL) { - readClose(rd, dN); + readCloseFile(rd, dN); } - if (fmt == FORMAT_PLAIN_STDIN) { + if (fmt == FORMAT_TEXT_STDIN) { fd = stdin; } @@ -1129,19 +1109,19 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f ERROR("fopen(\"%s\"): %s\n", file, strerror(errno)); } else { - if (fmt != FORMAT_PLAIN_STDIN) { + if (fmt != FORMAT_TEXT_STDIN) { file_stat(file, &bF); } - rd->data[dN].length_N = lN; + rd->data[dN].length_N = (rd->length_N < 1) ? lN : rd->length_N; - if ( fmt == FORMAT_PLAIN_STDIN - || fmt == FORMAT_PLAIN_TEXT) { + if ( fmt == FORMAT_TEXT_STDIN + || fmt == FORMAT_TEXT_CSV) { - if (fmt != FORMAT_PLAIN_STDIN) { + if (fmt != FORMAT_TEXT_STDIN) { - bom = readTEXTGetBOM(rd, fd); + bom = readCSVGetBOM(fd); if (bom == BOM_UTF_UNKNOWN) { @@ -1154,7 +1134,7 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f rd->data[dN].bom = bom; } - cN = readTEXTGetCN(rd, dN, fd, rbuf, &rbuf_N); + cN = readCSVGetCN(rd, dN, fd, rbuf, &rbuf_N); if (cN < 1) { @@ -1163,41 +1143,37 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f return ; } - if (bF != 0 && lN < 1) { + if (lN < 1) { - /* We do not use the file size to guess the - * length since there is an incremental dataset - * memory allocation. + /* We do not use the actual file size to guess + * the length since there is an incremental + * dataset memory allocation. * */ - lN = 1000; - } - else if (lN < 1) { - - lN = rd->length_N; + lN = (rd->length_N < 1) ? 1000 : rd->length_N; } } - else if (fmt == FORMAT_BINARY_FLOAT) { + else if (fmt == FORMAT_BINARY_FP_32) { - lN = (lN < 1) ? bF / (cN * sizeof(float)) : lN; + lN = (lN < 1) ? (int) (bF / (cN * sizeof(float))) : lN; rd->data[dN].line_N = 1; } - else if (fmt == FORMAT_BINARY_DOUBLE) { + else if (fmt == FORMAT_BINARY_FP_64) { - lN = (lN < 1) ? bF / (cN * sizeof(double)) : lN; + lN = (lN < 1) ? (int) (bF / (cN * sizeof(double))) : lN; rd->data[dN].line_N = 1; } #ifdef _LEGACY else if (fmt == FORMAT_BINARY_LEGACY_V1) { - lN = (lN < 1) ? (bF - 6) / (cN * 6) : lN; + lN = (lN < 1) ? (int) ((bF - 6) / (cN * 6)) : lN; rd->data[dN].line_N = 1; fseek(fd, 6UL, SEEK_SET); } else if (fmt == FORMAT_BINARY_LEGACY_V2) { - lN = (lN < 1) ? (bF - 4) / (cN * 4) : lN; + lN = (lN < 1) ? (int) ((bF - 4) / (cN * 4)) : lN; rd->data[dN].line_N = 1; fseek(fd, 4UL, SEEK_SET); @@ -1206,8 +1182,8 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f plotDataAlloc(rd->pl, dN, cN, lN + 1); - if ( fmt == FORMAT_PLAIN_STDIN - || fmt == FORMAT_PLAIN_TEXT) { + if ( fmt == FORMAT_TEXT_STDIN + || fmt == FORMAT_TEXT_CSV) { for (N = 0; N < rbuf_N; ++N) { @@ -1223,7 +1199,7 @@ void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int f rd->data[dN].fd = fd; rd->data[dN].afd = async_open(fd, rd->preload, rd->chunk, rd->timeout); - rd->files_N += 1; + rd->keep_N += 1; rd->bind_N = dN; } } @@ -1232,7 +1208,7 @@ void readOpenStub(read_t *rd, int dN, int cN, int lN, const char *file, int fmt) { rd->data[dN].length_N = lN; - lN = (lN < 1) ? 10 : lN; + lN = (lN < 1) ? 3 : lN; plotDataAlloc(rd->pl, dN, cN, lN + 1); @@ -1241,6 +1217,13 @@ void readOpenStub(read_t *rd, int dN, int cN, int lN, const char *file, int fmt) strcpy(rd->data[dN].file, file); + if (fmt == FORMAT_STUB_DATA) { + + rd->data[dN].fd = NULL; + rd->data[dN].afd = async_stub(rd->preload, rd->chunk, rd->timeout); + } + + rd->keep_N += 1; rd->bind_N = dN; } @@ -1276,15 +1259,36 @@ void readToggleHint(read_t *rd, int dN, int cN) } static int -readTEXTCSV(read_t *rd, int dN) +readSTUB(read_t *rd, int dN) { - int r, cN; + double *fbuf = (double *) rd->data[dN].buf; + int rc, N, cN = rd->pl->data[dN].column_N; - r = async_gets(rd->data[dN].afd, rd->data[dN].buf, sizeof(rd->data[0].buf)); + rc = async_read(rd->data[dN].afd, (void *) fbuf, cN * sizeof(double)); - if (r == ASYNC_OK) { + if (rc == ASYNC_OK) { - cN = readTEXTGetRow(rd, dN, rd->pl->data[dN].column_N); + for (N = 0; N < cN; ++N) + rd->data[dN].row[N] = (fval_t) fbuf[N]; + + plotDataInsert(rd->pl, dN, rd->data[dN].row); + + return 1; + } + + return 0; +} + +static int +readCSV(read_t *rd, int dN) +{ + int rc, cN; + + rc = async_gets(rd->data[dN].afd, rd->data[dN].buf, sizeof(rd->data[0].buf)); + + if (rc == ASYNC_OK) { + + cN = readCSVGetRow(rd, dN, rd->pl->data[dN].column_N); if (cN == rd->pl->data[dN].column_N) { @@ -1293,59 +1297,59 @@ readTEXTCSV(read_t *rd, int dN) return 1; } - else if (r == ASYNC_END_OF_FILE) { + else if (rc == ASYNC_END_OF_FILE) { - readClose(rd, dN); + readCloseFile(rd, dN); } return 0; } static int -readFLOAT(read_t *rd, int dN) +readFP32(read_t *rd, int dN) { - float *fb = (float *) rd->data[dN].buf; - int r, N, cN = rd->pl->data[dN].column_N; + float *fbuf = (float *) rd->data[dN].buf; + int rc, N, cN = rd->pl->data[dN].column_N; - r = async_read(rd->data[dN].afd, (void *) fb, cN * sizeof(float)); + rc = async_read(rd->data[dN].afd, (void *) fbuf, cN * sizeof(float)); - if (r == ASYNC_OK) { + if (rc == ASYNC_OK) { for (N = 0; N < cN; ++N) - rd->data[dN].row[N] = (fval_t) fb[N]; + rd->data[dN].row[N] = (fval_t) fbuf[N]; plotDataInsert(rd->pl, dN, rd->data[dN].row); return 1; } - else if (r == ASYNC_END_OF_FILE) { + else if (rc == ASYNC_END_OF_FILE) { - readClose(rd, dN); + readCloseFile(rd, dN); } return 0; } static int -readDOUBLE(read_t *rd, int dN) +readFP64(read_t *rd, int dN) { - double *fb = (double *) rd->data[dN].buf; - int r, N, cN = rd->pl->data[dN].column_N; + double *fbuf = (double *) rd->data[dN].buf; + int rc, N, cN = rd->pl->data[dN].column_N; - r = async_read(rd->data[dN].afd, (void *) fb, cN * sizeof(double)); + rc = async_read(rd->data[dN].afd, (void *) fbuf, cN * sizeof(double)); - if (r == ASYNC_OK) { + if (rc == ASYNC_OK) { for (N = 0; N < cN; ++N) - rd->data[dN].row[N] = (fval_t) fb[N]; + rd->data[dN].row[N] = (fval_t) fbuf[N]; plotDataInsert(rd->pl, dN, rd->data[dN].row); return 1; } - else if (r == ASYNC_END_OF_FILE) { + else if (rc == ASYNC_END_OF_FILE) { - readClose(rd, dN); + readCloseFile(rd, dN); } return 0; @@ -1356,17 +1360,17 @@ static int readLEGACY(read_t *rd, int dN) { char *fb = (char *) rd->data[dN].buf; - int r, N, cN = rd->pl->data[dN].column_N; + int rc, N, cN = rd->pl->data[dN].column_N; if (rd->data[dN].format == FORMAT_BINARY_LEGACY_V1) { - r = async_read(rd->data[dN].afd, (void *) fb, cN * 6); + rc = async_read(rd->data[dN].afd, (void *) fb, cN * 6); } else { - r = async_read(rd->data[dN].afd, (void *) fb, cN * 4); + rc = async_read(rd->data[dN].afd, (void *) fb, cN * 4); } - if (r == ASYNC_OK) { + if (rc == ASYNC_OK) { if (rd->data[dN].format == FORMAT_BINARY_LEGACY_V1) { @@ -1382,36 +1386,36 @@ readLEGACY(read_t *rd, int dN) return 1; } - else if (r == ASYNC_END_OF_FILE) { + else if (rc == ASYNC_END_OF_FILE) { - readClose(rd, dN); + readCloseFile(rd, dN); } return 0; } #endif /* _LEGACY */ -int readUpdate(read_t *rd) +int readDataLoad(read_t *rd) { - FILE *fd; - int dN, bN, tTOP, file_N = 0, ulN = 0; + int dN, keep_N = 0, ulN = 0; + + Uint32 tTOP; for (dN = 0; dN < PLOT_DATASET_MAX; ++dN) { - fd = rd->data[dN].fd; + FILE *fd = rd->data[dN].fd; - if (fd != NULL) { + tTOP = SDL_GetTicks() + (Uint32) PLOT_RUNTIME_MAX; - bN = 0; - file_N += 1; + if (fd != NULL) { - tTOP = SDL_GetTicks() + 20; + keep_N += 1; do { - if ( rd->data[dN].format == FORMAT_PLAIN_STDIN - || rd->data[dN].format == FORMAT_PLAIN_TEXT) { + if ( rd->data[dN].format == FORMAT_TEXT_STDIN + || rd->data[dN].format == FORMAT_TEXT_CSV) { - if (readTEXTCSV(rd, dN) != 0) { + if (readCSV(rd, dN) != 0) { ulN += 1; } @@ -1419,9 +1423,9 @@ int readUpdate(read_t *rd) break; } } - else if (rd->data[dN].format == FORMAT_BINARY_FLOAT) { + else if (rd->data[dN].format == FORMAT_BINARY_FP_32) { - if (readFLOAT(rd, dN) != 0) { + if (readFP32(rd, dN) != 0) { ulN += 1; } @@ -1429,9 +1433,9 @@ int readUpdate(read_t *rd) break; } } - else if (rd->data[dN].format == FORMAT_BINARY_DOUBLE) { + else if (rd->data[dN].format == FORMAT_BINARY_FP_64) { - if (readDOUBLE(rd, dN) != 0) { + if (readFP64(rd, dN) != 0) { ulN += 1; } @@ -1453,12 +1457,48 @@ int readUpdate(read_t *rd) } } #endif /* _LEGACY */ + else { + readCloseFile(rd, dN); + break; + } rd->data[dN].line_N++; - bN++; if ( rd->data[dN].length_N < 1 - && plotDataSpaceLeft(rd->pl, dN) < 10) { + && plotDataSpaceLeft(rd->pl, dN) < 3) { + + plotDataGrowUp(rd->pl, dN); + } + } + while (SDL_GetTicks() < tTOP); + + plotDataSubtractResidual(rd->pl, dN); + } + else if (rd->data[dN].format == FORMAT_STUB_DATA) { + + Uint32 tSTOP; + + tSTOP = rd->data[dN].afd->clock + + (Uint32) rd->data[dN].afd->timeout; + + if (SDL_GetTicks() < tSTOP) { + + keep_N += 1; + } + + do { + if (readSTUB(rd, dN) != 0) { + + ulN += 1; + } + else { + break; + } + + rd->data[dN].line_N++; + + if ( rd->data[dN].length_N < 1 + && plotDataSpaceLeft(rd->pl, dN) < 3) { plotDataGrowUp(rd->pl, dN); } @@ -1469,13 +1509,30 @@ int readUpdate(read_t *rd) } } - rd->files_N = (file_N < rd->files_N) ? file_N : rd->files_N; + rd->keep_N = keep_N; return ulN; } +int readGetFreeData(read_t *rd) +{ + int N, dN = -1; + + for (N = 0; N < PLOT_DATASET_MAX; ++N) { + + if ( rd->data[N].format == FORMAT_NONE + && rd->data[N].file[0] == 0) { + + dN = N; + break; + } + } + + return dN; +} + static int -configGetC(parse_t *pa) +configGetSym(parse_t *pa) { int rc; @@ -1504,7 +1561,7 @@ configGetC(parse_t *pa) } static int -configUngetC(parse_t *pa, int c) +configUngetSym(parse_t *pa, int c) { pa->unchar = c; @@ -1517,7 +1574,7 @@ configToken(read_t *rd, parse_t *pa) char *p = pa->tbuf; int c, n, rc = 0; - do { c = configGetC(pa); } + do { c = configGetSym(pa); } while (strchr(rd->mk_config.space, c) != NULL); if (c < 0) { @@ -1526,10 +1583,11 @@ configToken(read_t *rd, parse_t *pa) } else if (c == '"') { - c = configGetC(pa); + c = configGetSym(pa); n = 0; - while (c != -1 && c != '"' && strchr(rd->mk_config.lend, c) == NULL) { + while ( c != -1 && c != '"' + && strchr(rd->mk_config.lend, c) == NULL) { if (n < READ_FILE_PATH_MAX - 1) { @@ -1537,11 +1595,11 @@ configToken(read_t *rd, parse_t *pa) n++; } - c = configGetC(pa); + c = configGetSym(pa); } if (strchr(rd->mk_config.lend, c) != NULL) - configUngetC(pa, c); + configUngetSym(pa, c); *p = 0; } @@ -1562,13 +1620,13 @@ configToken(read_t *rd, parse_t *pa) n++; } - c = configGetC(pa); + c = configGetSym(pa); } while (c != -1 && strchr(rd->mk_config.space, c) == NULL && strchr(rd->mk_config.lend, c) == NULL); if (strchr(rd->mk_config.lend, c) != NULL) - configUngetC(pa, c); + configUngetSym(pa, c); *p = 0; } @@ -1630,7 +1688,7 @@ configParseFSM(read_t *rd, parse_t *pa) char lname[READ_FILE_PATH_MAX]; char *lbuf, *tbuf = pa->tbuf; - int r, failed, N; + int N, failed, rc; double argd[2]; int argi[4]; @@ -1643,9 +1701,11 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 0; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); + + if (rc == 0 && pa->newline != 0) { - if (r == 0 && pa->newline != 0) { + pa->newline = 0; sprintf(msg_tbuf, "unable to parse \"%.80s\"", tbuf); @@ -1657,9 +1717,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { lbuf = tbuf; @@ -1669,7 +1729,7 @@ configParseFSM(read_t *rd, parse_t *pa) lbuf = lpath; } - fd = unified_fopen(lbuf, "r"); + fd = unified_fopen(lbuf, "rc"); if (fd == NULL) { @@ -1700,14 +1760,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] > 0) { failed = 0; + rd->config_version = argi[0]; } else { @@ -1721,14 +1782,14 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { if (strcmp(tbuf, "normal") == 0) { @@ -1761,9 +1822,9 @@ configParseFSM(read_t *rd, parse_t *pa) argi[0], TTF_STYLE_ITALIC); } else { - r = plotFontOpen(rd->pl, tbuf, argi[0], TTF_STYLE_NORMAL); + rc = plotFontOpen(rd->pl, tbuf, argi[0], TTF_STYLE_NORMAL); - if (r == 0) { + if (rc == 0) { strcpy(rd->ttfname, tbuf); } @@ -1788,12 +1849,13 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; failed = 0; + rd->legacy_label = argi[0]; } while (0); @@ -1805,14 +1867,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - if (argi[0] > sizeof(rd->data[0].buf)) { + if (argi[0] > (int) sizeof(rd->data[0].buf)) { failed = 0; + rd->preload = argi[0]; } else { @@ -1826,14 +1889,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] > 0) { failed = 0; + rd->chunk = argi[0]; } else { @@ -1847,14 +1911,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0) { failed = 0; + rd->timeout = argi[0]; } else { @@ -1868,18 +1933,19 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - if (argi[0] > 0) { + if (argi[0] >= 0) { failed = 0; + rd->length_N = argi[0]; } else { - sprintf(msg_tbuf, "data length %i must be positive", argi[0]); + sprintf(msg_tbuf, "data length %i must be non-negative", argi[0]); } } while (0); @@ -1889,11 +1955,12 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { failed = 0; + strcpy(rd->screenpath, tbuf); } } @@ -1904,19 +1971,20 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; if (argi[0] >= GP_MIN_SIZE_X && argi[1] >= GP_MIN_SIZE_Y) { failed = 0; + rd->window_size_x = argi[0]; rd->window_size_y = argi[1]; } @@ -1931,14 +1999,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= LANG_EN && argi[0] < LANG_END_OF_LIST) { failed = 0; + rd->language = argi[0]; } else { @@ -1952,14 +2021,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] <= 2) { failed = 0; + rd->colorscheme = argi[0]; } else { @@ -1973,14 +2043,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] < 3) { failed = 0; + rd->dw->antialiasing = argi[0]; } else { @@ -1994,14 +2065,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] <= 1) { failed = 0; + rd->dw->blendfont = argi[0]; } else { @@ -2015,14 +2087,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 1 && argi[0] <= 3) { failed = 0; + rd->dw->thickness = argi[0]; } else { @@ -2036,14 +2109,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] > 0 && argi[0] < 1000) { failed = 0; + rd->dw->gamma = argi[0]; drawGamma(rd->dw); @@ -2059,14 +2133,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= -1 && argi[0] < READ_COLUMN_MAX) { failed = 0; + rd->timecol = argi[0]; } else { @@ -2080,14 +2155,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0) { failed = 0; + rd->shortfilename = argi[0]; } else { @@ -2101,14 +2177,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0) { failed = 0; + rd->fastdraw = argi[0]; } else { @@ -2122,14 +2199,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] <= 1) { failed = 0; + rd->pl->interpolation = argi[0]; } else { @@ -2143,14 +2221,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0) { failed = 0; + rd->pl->defungap = argi[0]; } else { @@ -2164,14 +2243,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] > 0 && argi[0] < 100) { failed = 0; + rd->pl->mark_density = argi[0]; } else { @@ -2185,14 +2265,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] > 0 && argi[0] < 100) { failed = 0; + rd->pl->mark_size = argi[0]; } else { @@ -2206,14 +2287,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] <= 1) { failed = 0; + rd->pl->transparency = argi[0]; } else { @@ -2227,14 +2309,15 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 1 && argi[0] <= 16) { failed = 0; + rd->pl->fprecision = argi[0]; } else { @@ -2243,16 +2326,39 @@ configParseFSM(read_t *rd, parse_t *pa) } while (0); } + else if (strcmp(tbuf, "hexadecimal") == 0) { + + failed = 1; + + do { + rc = configToken(rd, pa); + + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + else break; + + if (argi[0] >= 0 && argi[0] <= 1) { + + failed = 0; + + rd->pl->fhexadecimal = argi[0]; + } + else { + sprintf(msg_tbuf, "invalid hexadecimal %i", argi[0]); + } + } + while (0); + } else if (strcmp(tbuf, "delim") == 0) { failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { failed = 0; + rd->mk_text.delim = tbuf[0]; } } @@ -2263,11 +2369,12 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { failed = 0; + strcpy(rd->mk_text.space, tbuf); strcat(rd->mk_text.space, rd->mk_config.space); } @@ -2279,9 +2386,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (rd->bind_N != -1) { @@ -2299,6 +2406,7 @@ configParseFSM(read_t *rd, parse_t *pa) if (argi[0] >= 0 && argi[0] < 2) { failed = 0; + rd->pl->lz4_compress = argi[0]; } else { @@ -2312,9 +2420,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] < 0 || argi[0] >= PLOT_DATASET_MAX) { @@ -2323,30 +2431,36 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { - if (strcmp(tbuf, "stdin") == 0) { + if (strcmp(tbuf, "stub") == 0) { - argi[2] = FORMAT_PLAIN_STDIN; + argi[2] = FORMAT_STUB_DATA; } - else if (strcmp(tbuf, "text") == 0) { + else if (strcmp(tbuf, "stdin") == 0) { - argi[2] = FORMAT_PLAIN_TEXT; + argi[2] = FORMAT_TEXT_STDIN; } - else if (strcmp(tbuf, "float") == 0) { + else if ( strcmp(tbuf, "text") == 0 + || strcmp(tbuf, "csv") == 0) { - argi[2] = FORMAT_BINARY_FLOAT; + argi[2] = FORMAT_TEXT_CSV; } - else if (strcmp(tbuf, "double") == 0) { + else if ( strcmp(tbuf, "float") == 0 + || strcmp(tbuf, "fp32") == 0) { - argi[2] = FORMAT_BINARY_DOUBLE; + argi[2] = FORMAT_BINARY_FP_32; + } + else if (strcmp(tbuf, "fp64") == 0) { + + argi[2] = FORMAT_BINARY_FP_64; } else { sprintf(msg_tbuf, "invalid file format \"%.80s\"", tbuf); @@ -2355,7 +2469,29 @@ configParseFSM(read_t *rd, parse_t *pa) } else break; - if (argi[2] == FORMAT_PLAIN_STDIN) { + if (argi[2] == FORMAT_STUB_DATA) { + + int dN_remap; + + dN_remap = pa->dmap[argi[0]]; + + if (dN_remap < 0) { + + sprintf(msg_tbuf, "no free dataset to remap %i", argi[0]); + break; + } + + rc = configToken(rd, pa); + + if (rc == 0 && stoi(&rd->mk_config, &argi[3], tbuf) != NULL) ; + else break; + + readOpenStub(rd, dN_remap, argi[3], argi[1], "", argi[2]); + + failed = 0; + break; + } + else if (argi[2] == FORMAT_TEXT_STDIN) { int dN_remap; @@ -2377,18 +2513,18 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 0; break; } - else if ( argi[2] == FORMAT_BINARY_FLOAT - || argi[2] == FORMAT_BINARY_DOUBLE) { + else if ( argi[2] == FORMAT_BINARY_FP_32 + || argi[2] == FORMAT_BINARY_FP_64) { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[3], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[3], tbuf) != NULL) ; else break; } - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { int dN_remap; @@ -2412,8 +2548,8 @@ configParseFSM(read_t *rd, parse_t *pa) if (rd->data[dN_remap].fd == NULL) { - if ( argi[2] == FORMAT_BINARY_FLOAT - || argi[2] == FORMAT_BINARY_DOUBLE) { + if ( argi[2] == FORMAT_BINARY_FP_32 + || argi[2] == FORMAT_BINARY_FP_64) { readOpenStub(rd, dN_remap, argi[3], argi[1], lbuf, argi[2]); @@ -2434,9 +2570,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] < PLOT_DATASET_MAX) { @@ -2449,6 +2585,7 @@ configParseFSM(read_t *rd, parse_t *pa) rd->data[dN_remap].format != FORMAT_NONE) { failed = 0; + rd->bind_N = dN_remap; } else { @@ -2466,9 +2603,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (argi[0] < 0 || argi[0] >= PLOT_GROUP_MAX) { @@ -2484,9 +2621,9 @@ configParseFSM(read_t *rd, parse_t *pa) } do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r != 0) { + if (rc != 0) { failed = 0; break; @@ -2515,12 +2652,12 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); if (argi[0] >= 0 && argi[0] < PLOT_GROUP_MAX) { @@ -2540,14 +2677,14 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; if (argi[1] < 1 || argi[1] > PLOT_MEDIAN_MAX) { @@ -2559,15 +2696,15 @@ configParseFSM(read_t *rd, parse_t *pa) argi[2] = 0; argi[3] = 0; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { stoi(&rd->mk_config, &argi[2], tbuf); - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { stoi(&rd->mk_config, &argi[3], tbuf); } @@ -2591,19 +2728,19 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; else break; if (argi[0] >= 0 && argi[0] < PLOT_GROUP_MAX) { @@ -2624,7 +2761,7 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); if (rd->bind_N < 0) { @@ -2632,7 +2769,7 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - if (r == 0) { + if (rc == 0) { failed = 0; @@ -2678,9 +2815,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; if (rd->bind_N < 0) { @@ -2707,12 +2844,12 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); if (rd->page_N < 0) { @@ -2720,11 +2857,12 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - if (r == 0) { + if (rc == 0) { if (argi[0] >= 0 && argi[0] < PLOT_AXES_MAX) { failed = 0; + strcpy(rd->page[rd->page_N].ax[argi[0]].label, tbuf); } else { @@ -2739,24 +2877,24 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; else break; if (rd->page_N < 0) { @@ -2765,10 +2903,11 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - if (argi[0] >= 0 && argi[0] < PLOT_AXES_MAX - && argi[1] >= 0 && argi[1] < PLOT_AXES_MAX) { + if ( argi[0] >= 0 && argi[0] < PLOT_AXES_MAX + && argi[1] >= 0 && argi[1] < PLOT_AXES_MAX) { failed = 0; + rd->page[rd->page_N].ax[argi[0]].slave = 1; rd->page[rd->page_N].ax[argi[0]].slave_N = argi[1]; rd->page[rd->page_N].ax[argi[0]].scale = argd[0]; @@ -2785,17 +2924,17 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); if (rd->page_N < 0) { @@ -2816,11 +2955,12 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - if (r == 0) { + if (rc == 0) { if (rd->figure_N < PLOT_FIGURE_MAX - 1) { failed = 0; + rd->figure_N++; rd->page[rd->page_N].fig[rd->figure_N].busy = 1; @@ -2845,14 +2985,14 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; if (rd->figure_N < 0) { @@ -2861,10 +3001,11 @@ configParseFSM(read_t *rd, parse_t *pa) break; } - if (argi[0] >= 0 && argi[0] < PLOT_AXES_MAX - && argi[1] >= 0 && argi[1] < PLOT_AXES_MAX) { + if ( argi[0] >= 0 && argi[0] < PLOT_AXES_MAX + && argi[1] >= 0 && argi[1] < PLOT_AXES_MAX) { failed = 0; + rd->page[rd->page_N].fig[rd->figure_N].aX = argi[0]; rd->page[rd->page_N].fig[rd->figure_N].aY = argi[1]; } @@ -2874,21 +3015,22 @@ configParseFSM(read_t *rd, parse_t *pa) } while (0); } - else if (strcmp(tbuf, "xscale") == 0 || strcmp(tbuf, "yscale") == 0) { + else if ( strcmp(tbuf, "xscale") == 0 + || strcmp(tbuf, "yscale") == 0) { failed = 1; do { argi[0] = (int) tbuf[0]; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[1], tbuf) != NULL) ; else break; if (rd->figure_N < 0) { @@ -2932,16 +3074,17 @@ configParseFSM(read_t *rd, parse_t *pa) } while (0); } - else if (strcmp(tbuf, "xsubtract") == 0 || strcmp(tbuf, "ysubtract") == 0) { + else if ( strcmp(tbuf, "xsubtract") == 0 + || strcmp(tbuf, "ysubtract") == 0) { failed = 1; do { argi[0] = (int) tbuf[0]; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { if (strcmp(tbuf, "sub") == 0) { @@ -2965,9 +3108,9 @@ configParseFSM(read_t *rd, parse_t *pa) } } - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; else break; if (rd->figure_N < 0) { @@ -2988,7 +3131,7 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 0; rd->page[rd->page_N].fig[rd->figure_N].bX[N].busy = argi[1]; - rd->page[rd->page_N].fig[rd->figure_N].bX[N].column_2 = argi[2]; + rd->page[rd->page_N].fig[rd->figure_N].bX[N].column_Y = argi[2]; } } else if (argi[0] == 'y') { @@ -3003,22 +3146,23 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 0; rd->page[rd->page_N].fig[rd->figure_N].bY[N].busy = argi[1]; - rd->page[rd->page_N].fig[rd->figure_N].bY[N].column_2 = argi[2]; + rd->page[rd->page_N].fig[rd->figure_N].bY[N].column_Y = argi[2]; } } } while (0); } - else if (strcmp(tbuf, "xfilter") == 0 || strcmp(tbuf, "yfilter") == 0) { + else if ( strcmp(tbuf, "xfilter") == 0 + || strcmp(tbuf, "yfilter") == 0) { failed = 1; do { argi[0] = (int) tbuf[0]; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { if (strcmp(tbuf, "diff") == 0) { @@ -3032,14 +3176,14 @@ configParseFSM(read_t *rd, parse_t *pa) argi[1] = SUBTRACT_FILTER_BITMASK; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r != 0) { + if (rc != 0) { if (stoi(&rd->mk_config, &argi[3], tbuf) != NULL) ; else break; @@ -3052,18 +3196,18 @@ configParseFSM(read_t *rd, parse_t *pa) argi[1] = SUBTRACT_FILTER_LOW_PASS; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; + if (rc == 0 && stod(&rd->mk_config, &argd[0], tbuf) != NULL) ; else break; } else if (strcmp(tbuf, "med") == 0) { argi[1] = SUBTRACT_FILTER_MEDIAN; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[2], tbuf) != NULL) ; else break; if (argi[2] < 3 || argi[2] > PLOT_MEDIAN_MAX) { @@ -3148,9 +3292,9 @@ configParseFSM(read_t *rd, parse_t *pa) failed = 1; do { - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0) { + if (rc == 0) { if (strcmp(tbuf, "line") == 0) argi[0] = FIGURE_DRAWING_LINE; @@ -3165,9 +3309,9 @@ configParseFSM(read_t *rd, parse_t *pa) } else break; - r = configToken(rd, pa); + rc = configToken(rd, pa); - if (r == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; + if (rc == 0 && stoi(&rd->mk_config, &argi[1], tbuf) != NULL) ; else break; if (argi[1] >= 0 && argi[1] <= 16) { @@ -3196,15 +3340,15 @@ configParseFSM(read_t *rd, parse_t *pa) sprintf(msg_tbuf, "unknown token \"%.80s\"", tbuf); } - if (failed) { + if (failed != 0) { ERROR("%s:%i: %s\n", pa->file, pa->line_N, msg_tbuf); } - - pa->newline = 0; } - else if (r < 0) + else if (rc < 0) { + break; + } } while (1); } @@ -3279,7 +3423,7 @@ void readConfigGP(read_t *rd, const char *file, int fromUI) ERROR("fopen(\"%s\"): %s\n", file, strerror(errno)); } else { - if (readTEXTGetBOM(rd, fd) == BOM_UTF_UNKNOWN) { + if (readCSVGetBOM(fd) == BOM_UTF_UNKNOWN) { ERROR("Unsupported BOM in file \"%s\"\n", file); @@ -3312,14 +3456,12 @@ void readConfigGP(read_t *rd, const char *file, int fromUI) } } -void readConfigVerify(read_t *rd) +void readConfigSafe(read_t *rd) { if (rd->pl->font == NULL) { plotFontDefault(rd->pl, TTF_ID_ROBOTO_MONO_NORMAL, 24, TTF_STYLE_NORMAL); } - - rd->page_N = -1; } static void @@ -3499,7 +3641,7 @@ void readDatasetClean(read_t *rd, int dN) if (rd->data[dN].fd != NULL) { - readClose(rd, dN); + readCloseFile(rd, dN); } memset(&rd->data[dN], 0, sizeof(rd->data[0])); @@ -3661,7 +3803,7 @@ readTimeDataMap(plot_t *pl, int dN, int cNX, int cNY) } static int -readScaleDataMap(plot_t *pl, int dN, int cN, subtract_t *sb) +readScaleDataMap(plot_t *pl, int dN, int cNT, int cN, subtract_t *sb) { int N, gN, cMAP; @@ -3723,7 +3865,7 @@ readScaleDataMap(plot_t *pl, int dN, int cN, subtract_t *sb) || sb[N].busy == SUBTRACT_BINARY_HYPOTENUSE) { cMAP = plotGetSubtractBinary(pl, dN, sb[N].busy, - cN, sb[N].column_2); + cN, sb[N].column_Y); if (cMAP != -1) { @@ -3734,7 +3876,7 @@ readScaleDataMap(plot_t *pl, int dN, int cN, subtract_t *sb) || sb[N].busy == SUBTRACT_FILTER_CUMULATIVE || sb[N].busy == SUBTRACT_FILTER_LOW_PASS) { - cMAP = plotGetSubtractFilter(pl, dN, cN, + cMAP = plotGetSubtractFilter(pl, dN, cNT, cN, sb[N].busy, sb[N].args[0]); if (cMAP != -1) { @@ -3744,7 +3886,7 @@ readScaleDataMap(plot_t *pl, int dN, int cN, subtract_t *sb) } else if (sb[N].busy == SUBTRACT_FILTER_BITMASK) { - cMAP = plotGetSubtractFilter(pl, dN, cN, sb[N].busy, + cMAP = plotGetSubtractFilter(pl, dN, cNT, cN, sb[N].busy, sb[N].args[0] + sb[N].args[1] * (double) 0x100U); if (cMAP != -1) { @@ -3755,7 +3897,7 @@ readScaleDataMap(plot_t *pl, int dN, int cN, subtract_t *sb) else if (sb[N].busy == SUBTRACT_FILTER_MEDIAN) { cMAP = plotGetSubtractMedian(pl, dN, cN, - sb[N].busy, sb[N].args[0]); + sb[N].busy, (int) sb[N].args[0]); if (cMAP != -1) { @@ -3803,8 +3945,8 @@ void readSelectPage(read_t *rd, int pN) cX = uN.X; cY = uN.Y; - cX = readScaleDataMap(pl, pg->fig[N].dN, cX, pg->fig[N].bX); - cY = readScaleDataMap(pl, pg->fig[N].dN, cY, pg->fig[N].bY); + cX = readScaleDataMap(pl, pg->fig[N].dN, -1, cX, pg->fig[N].bX); + cY = readScaleDataMap(pl, pg->fig[N].dN, cX, cY, pg->fig[N].bY); plotFigureAdd(pl, N, pg->fig[N].dN, cX, cY, pg->fig[N].aX, pg->fig[N].aY, pg->fig[N].label); @@ -4007,8 +4149,8 @@ void readCombinePage(read_t *rd, int pN, int remap) cX = uN.X; cY = uN.Y; - cX = readScaleDataMap(pl, pg->fig[N].dN, cX, pg->fig[N].bX); - cY = readScaleDataMap(pl, pg->fig[N].dN, cY, pg->fig[N].bY); + cX = readScaleDataMap(pl, pg->fig[N].dN, -1, cX, pg->fig[N].bX); + cY = readScaleDataMap(pl, pg->fig[N].dN, cX, cY, pg->fig[N].bY); plotFigureAdd(pl, fN, pg->fig[N].dN, cX, cY, aX, aY, pg->fig[N].label); @@ -4045,9 +4187,9 @@ void readCombinePage(read_t *rd, int pN, int remap) plotAxisScaleDefault(pl); } -void readDataReload(read_t *rd) +int readDataReload(read_t *rd) { - int dN; + int dN, N = 0; for (dN = 0; dN < PLOT_DATASET_MAX; ++dN) { @@ -4057,7 +4199,11 @@ void readDataReload(read_t *rd) readOpenUnified(rd, dN, rd->data[dN].column_N, rd->data[dN].length_N, rd->data[dN].file, rd->data[dN].format); + + N++; } } + + return N; } diff --git a/pgui/gp/read.h b/pgui/gp/read.h index e8e1358..15d24d8 100644 --- a/pgui/gp/read.h +++ b/pgui/gp/read.h @@ -33,20 +33,21 @@ #define READ_TOKEN_MAX 80 #define READ_FILE_PATH_MAX 800 #define READ_TEXT_SCAN_MAX 9 +#define READ_TEXT_HEAD_MAX 3 #define READ_TEXT_DEVIATE_MAX 2 #define READ_SUBTRACT_MAX 4 #define GP_MIN_SIZE_X 640 #define GP_MIN_SIZE_Y 480 -#define GP_CONFIG_VERSION 16 - enum { FORMAT_NONE = 0, - FORMAT_PLAIN_STDIN, - FORMAT_PLAIN_TEXT, - FORMAT_BINARY_FLOAT, - FORMAT_BINARY_DOUBLE, + FORMAT_BLANK_DATA, + FORMAT_STUB_DATA, + FORMAT_TEXT_STDIN, + FORMAT_TEXT_CSV, + FORMAT_BINARY_FP_32, + FORMAT_BINARY_FP_64, #ifdef _LEGACY FORMAT_BINARY_LEGACY_V1, @@ -78,7 +79,7 @@ markup_t; typedef struct { int busy; - int column_2; + int column_Y; double args[2]; } @@ -194,7 +195,7 @@ typedef struct { page_t page[READ_PAGE_MAX]; - int files_N; + int keep_N; int bind_N; int page_N; @@ -211,7 +212,8 @@ read_t *readAlloc(draw_t *dw, plot_t *pl); void readClean(read_t *rd); void readOpenUnified(read_t *rd, int dN, int cN, int lN, const char *file, int fmt); void readToggleHint(read_t *rd, int dN, int cN); -int readUpdate(read_t *rd); +int readDataLoad(read_t *rd); +int readGetFreeData(read_t *rd); #ifdef _WINDOWS void legacy_ACP_to_UTF8(char *us, const char *text, int n); @@ -228,7 +230,7 @@ FILE *unified_fopen(const char *file, const char *mode); void readConfigIN(read_t *rd, const char *config, int fromUI); void readConfigGP(read_t *rd, const char *file, int fromUI); -void readConfigVerify(read_t *rd); +void readConfigSafe(read_t *rd); void readMakePages(read_t *rd, int dN, int cX, int fromUI); void readDatasetClean(read_t *rd, int dN); @@ -237,7 +239,7 @@ void readSetTimeColumn(read_t *rd, int dN, int cX); void readSelectPage(read_t *rd, int pN); void readCombinePage(read_t *rd, int pN, int remap); -void readDataReload(read_t *rd); +int readDataReload(read_t *rd); #endif /* _H_READ_ */ diff --git a/pgui/gp/scheme.c b/pgui/gp/scheme.c index fc26ac8..6a77049 100644 --- a/pgui/gp/scheme.c +++ b/pgui/gp/scheme.c @@ -34,6 +34,8 @@ void schemeFill(scheme_t *sch, int nu) sch->plot_figure[5] = 0xFF00FF; sch->plot_figure[6] = 0xFF7700; sch->plot_figure[7] = 0x7700FF; + sch->plot_figure[8] = 0xFF0077; + sch->plot_figure[9] = 0x0077FF; sch->plot_axis = 0x00BFCF; sch->plot_hovered = 0x223344; sch->plot_text = 0xFFFFFF; @@ -57,6 +59,8 @@ void schemeFill(scheme_t *sch, int nu) sch->plot_figure[5] = 0xFF00FF; sch->plot_figure[6] = 0xFF7700; sch->plot_figure[7] = 0x7700FF; + sch->plot_figure[8] = 0xFF0077; + sch->plot_figure[9] = 0x0077FF; sch->plot_axis = 0x005F6F; sch->plot_hovered = 0xCCDDEE; sch->plot_text = 0x000000; @@ -73,13 +77,15 @@ void schemeFill(scheme_t *sch, int nu) sch->plot_background = 0xFFFFFF; sch->plot_figure[0] = 0x000000; - sch->plot_figure[1] = 0x777777; - sch->plot_figure[2] = 0xBBBBBB; - sch->plot_figure[3] = 0x333333; - sch->plot_figure[4] = 0x555555; - sch->plot_figure[5] = 0x999999; - sch->plot_figure[6] = 0xCCCCCC; - sch->plot_figure[7] = 0xDDDDDD; + sch->plot_figure[1] = 0x555555; + sch->plot_figure[2] = 0x999999; + sch->plot_figure[3] = 0x111111; + sch->plot_figure[4] = 0x666666; + sch->plot_figure[5] = 0x888888; + sch->plot_figure[6] = 0x222222; + sch->plot_figure[7] = 0x333333; + sch->plot_figure[8] = 0x444444; + sch->plot_figure[9] = 0x777777; sch->plot_axis = 0x5F5F5F; sch->plot_hovered = 0xDDDDDD; sch->plot_text = 0x000000; diff --git a/pgui/gp/scheme.h b/pgui/gp/scheme.h index 099b96e..dd16f19 100644 --- a/pgui/gp/scheme.h +++ b/pgui/gp/scheme.h @@ -27,7 +27,7 @@ typedef struct { Uint32 plot_background; - Uint32 plot_figure[8]; + Uint32 plot_figure[10]; Uint32 plot_axis; Uint32 plot_hovered; Uint32 plot_text; diff --git a/pgui/gp/svg.c b/pgui/gp/svg.c index ff1272c..c70e458 100644 --- a/pgui/gp/svg.c +++ b/pgui/gp/svg.c @@ -32,7 +32,7 @@ svg_t *svgOpenNew(const char *file, int width, int height) { svg_t *g; - g = calloc(1, sizeof(svg_t)); + g = (svg_t *) calloc(1, sizeof(svg_t)); g->fd = unified_fopen(file, "w"); if (g->fd == NULL) { diff --git a/pgui/nksdl.c b/pgui/nksdl.c index 5b1817e..d632bea 100644 --- a/pgui/nksdl.c +++ b/pgui/nksdl.c @@ -27,6 +27,7 @@ #include #include +#include #include #include diff --git a/pgui/nuklear.h b/pgui/nuklear.h index 25a3e14..e74b3a8 100644 --- a/pgui/nuklear.h +++ b/pgui/nuklear.h @@ -1,225 +1,230 @@ /* -/// # Nuklear -/// ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) -/// -/// ## Contents -/// 1. About section -/// 2. Highlights section -/// 3. Features section -/// 4. Usage section -/// 1. Flags section -/// 2. Constants section -/// 3. Dependencies section -/// 5. Example section -/// 6. API section -/// 1. Context section -/// 2. Input section -/// 3. Drawing section -/// 4. Window section -/// 5. Layouting section -/// 6. Groups section -/// 7. Tree section -/// 8. Properties section -/// 7. License section -/// 8. Changelog section -/// 9. Gallery section -/// 10. Credits section -/// -/// ## About -/// This is a minimal state immediate mode graphical user interface toolkit -/// written in ANSI C and licensed under public domain. It was designed as a simple -/// embeddable user interface for application and does not have any dependencies, -/// a default renderbackend or OS window and input handling but instead provides a very modular -/// library approach by using simple input state for input and draw -/// commands describing primitive shapes as output. So instead of providing a -/// layered library that tries to abstract over a number of platform and -/// render backends it only focuses on the actual UI. -/// -/// ## Highlights -/// - Graphical user interface toolkit -/// - Single header library -/// - Written in C89 (a.k.a. ANSI C or ISO C90) -/// - Small codebase (~18kLOC) -/// - Focus on portability, efficiency and simplicity -/// - No dependencies (not even the standard library if not wanted) -/// - Fully skinnable and customizable -/// - Low memory footprint with total memory control if needed or wanted -/// - UTF-8 support -/// - No global or hidden state -/// - Customizable library modules (you can compile and use only what you need) -/// - Optional font baker and vertex buffer output -/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) -/// -/// ## Features -/// - Absolutely no platform dependent code -/// - Memory management control ranging from/to -/// - Ease of use by allocating everything from standard library -/// - Control every byte of memory inside the library -/// - Font handling control ranging from/to -/// - Use your own font implementation for everything -/// - Use this libraries internal font baking and handling API -/// - Drawing output control ranging from/to -/// - Simple shapes for more high level APIs which already have drawing capabilities -/// - Hardware accessible anti-aliased vertex buffer output -/// - Customizable colors and properties ranging from/to -/// - Simple changes to color by filling a simple color table -/// - Complete control with ability to use skinning to decorate widgets -/// - Bendable UI library with widget ranging from/to -/// - Basic widgets like buttons, checkboxes, slider, ... -/// - Advanced widget like abstract comboboxes, contextual menus,... -/// - Compile time configuration to only compile what you need -/// - Subset which can be used if you do not want to link or use the standard library -/// - Can be easily modified to only update on user input instead of frame updates -/// -/// ## Usage -/// This library is self contained in one single header file and can be used either -/// in header only mode or in implementation mode. The header only mode is used -/// by default when included and allows including this header in other headers -/// and does not contain the actual implementation.

-/// -/// The implementation mode requires to define the preprocessor macro -/// NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C -/// #define NK_IMPLEMENTATION -/// #include "nuklear.h" -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Also optionally define the symbols listed in the section "OPTIONAL DEFINES" -/// below in header and implementation mode if you want to use additional functionality -/// or need more control over the library. -/// -/// !!! WARNING -/// Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions. -/// -/// ### Flags -/// Flag | Description -/// --------------------------------|------------------------------------------ -/// NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation -/// NK_INCLUDE_FIXED_TYPES | If defined it will include header `` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself. -/// NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management. -/// NK_INCLUDE_STANDARD_IO | If defined it will include header `` and provide additional functions depending on file loading. -/// NK_INCLUDE_STANDARD_VARARGS | If defined it will include header and provide additional functions depending on file loading. -/// NK_INCLUDE_STANDARD_BOOL | If defined it will include header `` for nk_bool otherwise nuklear defines nk_bool as int. -/// NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,... -/// NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. -/// NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font -/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures. -/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released. -/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame. -/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit -/// NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events -/// -/// !!! WARNING -/// The following flags will pull in the standard C library: -/// - NK_INCLUDE_DEFAULT_ALLOCATOR -/// - NK_INCLUDE_STANDARD_IO -/// - NK_INCLUDE_STANDARD_VARARGS -/// -/// !!! WARNING -/// The following flags if defined need to be defined for both header and implementation: -/// - NK_INCLUDE_FIXED_TYPES -/// - NK_INCLUDE_DEFAULT_ALLOCATOR -/// - NK_INCLUDE_STANDARD_VARARGS -/// - NK_INCLUDE_STANDARD_BOOL -/// - NK_INCLUDE_VERTEX_BUFFER_OUTPUT -/// - NK_INCLUDE_FONT_BAKING -/// - NK_INCLUDE_DEFAULT_FONT -/// - NK_INCLUDE_STANDARD_VARARGS -/// - NK_INCLUDE_COMMAND_USERDATA -/// - NK_UINT_DRAW_INDEX -/// -/// ### Constants -/// Define | Description -/// --------------------------------|--------------------------------------- -/// NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it. -/// NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient. -/// NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient. -/// -/// !!! WARNING -/// The following constants if defined need to be defined for both header and implementation: -/// - NK_MAX_NUMBER_BUFFER -/// - NK_BUFFER_DEFAULT_INITIAL_SIZE -/// - NK_INPUT_MAX -/// -/// ### Dependencies -/// Function | Description -/// ------------|--------------------------------------------------------------- -/// NK_ASSERT | If you don't define this, nuklear will use with assert(). -/// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version. -/// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version. -/// NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. -/// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation. -/// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation. -/// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). -/// NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). -/// NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe. -/// -/// !!! WARNING -/// The following dependencies will pull in the standard C library if not redefined: -/// - NK_ASSERT -/// -/// !!! WARNING -/// The following dependencies if defined need to be defined for both header and implementation: -/// - NK_ASSERT -/// -/// !!! WARNING -/// The following dependencies if defined need to be defined only for the implementation part: -/// - NK_MEMSET -/// - NK_MEMCPY -/// - NK_SQRT -/// - NK_SIN -/// - NK_COS -/// - NK_STRTOD -/// - NK_DTOA -/// - NK_VSNPRINTF -/// -/// ## Example -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// // init gui state -/// enum {EASY, HARD}; -/// static int op = EASY; -/// static float value = 0.6f; -/// static int i = 20; -/// struct nk_context ctx; -/// -/// nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); -/// if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), -/// NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { -/// // fixed widget pixel width -/// nk_layout_row_static(&ctx, 30, 80, 1); -/// if (nk_button_label(&ctx, "button")) { -/// // event handling -/// } -/// -/// // fixed widget window ratio width -/// nk_layout_row_dynamic(&ctx, 30, 2); -/// if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; -/// if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; -/// -/// // custom widget pixel width -/// nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); -/// { -/// nk_layout_row_push(&ctx, 50); -/// nk_label(&ctx, "Volume:", NK_TEXT_LEFT); -/// nk_layout_row_push(&ctx, 110); -/// nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); -/// } -/// nk_layout_row_end(&ctx); -/// } -/// nk_end(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) -/// -/// ## API -/// +# Nuklear +![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) + +## Contents +1. About section +2. Highlights section +3. Features section +4. Usage section + 1. Flags section + 2. Constants section + 3. Dependencies section +5. Example section +6. API section + 1. Context section + 2. Input section + 3. Drawing section + 4. Window section + 5. Layouting section + 6. Groups section + 7. Tree section + 8. Properties section +7. License section +8. Changelog section +9. Gallery section +10. Credits section + +## About +This is a minimal state immediate mode graphical user interface toolkit +written in ANSI C and licensed under public domain. It was designed as a simple +embeddable user interface for application and does not have any dependencies, +a default renderbackend or OS window and input handling but instead provides a very modular +library approach by using simple input state for input and draw +commands describing primitive shapes as output. So instead of providing a +layered library that tries to abstract over a number of platform and +render backends it only focuses on the actual UI. + +## Highlights +- Graphical user interface toolkit +- Single header library +- Written in C89 (a.k.a. ANSI C or ISO C90) +- Small codebase (~18kLOC) +- Focus on portability, efficiency and simplicity +- No dependencies (not even the standard library if not wanted) +- Fully skinnable and customizable +- Low memory footprint with total memory control if needed or wanted +- UTF-8 support +- No global or hidden state +- Customizable library modules (you can compile and use only what you need) +- Optional font baker and vertex buffer output +- [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) + +## Features +- Absolutely no platform dependent code +- Memory management control ranging from/to + - Ease of use by allocating everything from standard library + - Control every byte of memory inside the library +- Font handling control ranging from/to + - Use your own font implementation for everything + - Use this libraries internal font baking and handling API +- Drawing output control ranging from/to + - Simple shapes for more high level APIs which already have drawing capabilities + - Hardware accessible anti-aliased vertex buffer output +- Customizable colors and properties ranging from/to + - Simple changes to color by filling a simple color table + - Complete control with ability to use skinning to decorate widgets +- Bendable UI library with widget ranging from/to + - Basic widgets like buttons, checkboxes, slider, ... + - Advanced widget like abstract comboboxes, contextual menus,... +- Compile time configuration to only compile what you need + - Subset which can be used if you do not want to link or use the standard library +- Can be easily modified to only update on user input instead of frame updates + +## Usage +This library is self contained in one single header file and can be used either +in header only mode or in implementation mode. The header only mode is used +by default when included and allows including this header in other headers +and does not contain the actual implementation.

+ +The implementation mode requires to define the preprocessor macro +NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C + #define NK_IMPLEMENTATION + #include "nuklear.h" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Also optionally define the symbols listed in the section "OPTIONAL DEFINES" +below in header and implementation mode if you want to use additional functionality +or need more control over the library. + +!!! WARNING + Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions. + +### Flags +Flag | Description +--------------------------------|------------------------------------------ +NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation +NK_INCLUDE_FIXED_TYPES | If defined it will include header `` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself. +NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management. +NK_INCLUDE_STANDARD_IO | If defined it will include header `` and provide additional functions depending on file loading. +NK_INCLUDE_STANDARD_VARARGS | If defined it will include header and provide additional functions depending on file loading. +NK_INCLUDE_STANDARD_BOOL | If defined it will include header `` for nk_bool otherwise nuklear defines nk_bool as int. +NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,... +NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. +NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font +NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures. +NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released. +NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame. +NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit +NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events + +!!! WARNING + The following flags will pull in the standard C library: + - NK_INCLUDE_DEFAULT_ALLOCATOR + - NK_INCLUDE_STANDARD_IO + - NK_INCLUDE_STANDARD_VARARGS + +!!! WARNING + The following flags if defined need to be defined for both header and implementation: + - NK_INCLUDE_FIXED_TYPES + - NK_INCLUDE_DEFAULT_ALLOCATOR + - NK_INCLUDE_STANDARD_VARARGS + - NK_INCLUDE_STANDARD_BOOL + - NK_INCLUDE_VERTEX_BUFFER_OUTPUT + - NK_INCLUDE_FONT_BAKING + - NK_INCLUDE_DEFAULT_FONT + - NK_INCLUDE_STANDARD_VARARGS + - NK_INCLUDE_COMMAND_USERDATA + - NK_UINT_DRAW_INDEX + +### Constants +Define | Description +--------------------------------|--------------------------------------- +NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it. +NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient. +NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient. + +!!! WARNING + The following constants if defined need to be defined for both header and implementation: + - NK_MAX_NUMBER_BUFFER + - NK_BUFFER_DEFAULT_INITIAL_SIZE + - NK_INPUT_MAX + +### Dependencies +Function | Description +------------|--------------------------------------------------------------- +NK_ASSERT | If you don't define this, nuklear will use with assert(). +NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version. +NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version. +NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. +NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation. +NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation. +NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). +NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). +NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe. + +!!! WARNING + The following dependencies will pull in the standard C library if not redefined: + - NK_ASSERT + +!!! WARNING + The following dependencies if defined need to be defined for both header and implementation: + - NK_ASSERT + +!!! WARNING + The following dependencies if defined need to be defined only for the implementation part: + - NK_MEMSET + - NK_MEMCPY + - NK_SQRT + - NK_SIN + - NK_COS + - NK_STRTOD + - NK_DTOA + - NK_VSNPRINTF + +## Example + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +// init gui state +enum {EASY, HARD}; +static int op = EASY; +static float value = 0.6f; +static int i = 20; +struct nk_context ctx; + +nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); +if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), + NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { + // fixed widget pixel width + nk_layout_row_static(&ctx, 30, 80, 1); + if (nk_button_label(&ctx, "button")) { + // event handling + } + + // fixed widget window ratio width + nk_layout_row_dynamic(&ctx, 30, 2); + if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; + + // custom widget pixel width + nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); + { + nk_layout_row_push(&ctx, 50); + nk_label(&ctx, "Volume:", NK_TEXT_LEFT); + nk_layout_row_push(&ctx, 110); + nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); + } + nk_layout_row_end(&ctx); +} +nk_end(&ctx); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) + +## API + */ #ifndef NK_SINGLE_FILE #define NK_SINGLE_FILE #endif +/** \file nuklear.h + * \brief main API and documentation file + * + * \details + */ #ifndef NK_NUKLEAR_H_ #define NK_NUKLEAR_H_ @@ -233,9 +238,10 @@ extern "C" { * * =============================================================== */ + #define NK_UNDEFINED (-1.0f) -#define NK_UTF_INVALID 0xFFFD /* internal invalid utf8 rune */ -#define NK_UTF_SIZE 4 /* describes the number of bytes a glyph consists of*/ +#define NK_UTF_INVALID 0xFFFD /**< internal invalid utf8 rune */ +#define NK_UTF_SIZE 4 /**< describes the number of bytes a glyph consists of*/ #ifndef NK_INPUT_MAX #define NK_INPUT_MAX 16 #endif @@ -252,6 +258,7 @@ extern "C" { * * =============================================================== */ + #ifndef NK_API #ifdef NK_PRIVATE #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L)) @@ -330,7 +337,7 @@ extern "C" { * * =============================================================== */ -#ifdef NK_INCLUDE_FIXED_TYPES + #ifdef NK_INCLUDE_FIXED_TYPES #include #define NK_INT8 int8_t #define NK_UINT8 uint8_t @@ -404,7 +411,7 @@ extern "C" { #include #define NK_BOOL bool #else - #define NK_BOOL int /* could be char, use int for drop-in replacement backwards compatibility */ + #define NK_BOOL int /**< could be char, use int for drop-in replacement backwards compatibility */ #endif #endif @@ -524,6 +531,10 @@ enum nk_symbol_type { NK_SYMBOL_TRIANGLE_RIGHT, NK_SYMBOL_PLUS, NK_SYMBOL_MINUS, + NK_SYMBOL_TRIANGLE_UP_OUTLINE, + NK_SYMBOL_TRIANGLE_DOWN_OUTLINE, + NK_SYMBOL_TRIANGLE_LEFT_OUTLINE, + NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE, NK_SYMBOL_MAX }; /* ============================================================================= @@ -531,159 +542,166 @@ enum nk_symbol_type { * CONTEXT * * =============================================================================*/ -/*/// ### Context -/// Contexts are the main entry point and the majestro of nuklear and contain all required state. -/// They are used for window, memory, input, style, stack, commands and time management and need -/// to be passed into all nuklear GUI specific functions. -/// -/// #### Usage -/// To use a context it first has to be initialized which can be achieved by calling -/// one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`. -/// Each takes in a font handle and a specific way of handling memory. Memory control -/// hereby ranges from standard library to just specifying a fixed sized block of memory -/// which nuklear has to manage itself from. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// // [...] -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// --------------------|------------------------------------------------------- -/// __nk_init_default__ | Initializes context with standard library memory allocation (malloc,free) -/// __nk_init_fixed__ | Initializes context from single fixed size memory block -/// __nk_init__ | Initializes context with memory allocator callbacks for alloc and free -/// __nk_init_custom__ | Initializes context from two buffers. One for draw commands the other for window/panel/table allocations -/// __nk_clear__ | Called at the end of the frame to reset and prepare the context for the next frame -/// __nk_free__ | Shutdown and free all memory allocated inside the context -/// __nk_set_user_data__| Utility function to pass user data to draw command +/** + * \page Context + * Contexts are the main entry point and the majestro of nuklear and contain all required state. + * They are used for window, memory, input, style, stack, commands and time management and need + * to be passed into all nuklear GUI specific functions. + * + * # Usage + * To use a context it first has to be initialized which can be achieved by calling + * one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`. + * Each takes in a font handle and a specific way of handling memory. Memory control + * hereby ranges from standard library to just specifying a fixed sized block of memory + * which nuklear has to manage itself from. + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * // [...] + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * # Reference + * Function | Description + * --------------------|------------------------------------------------------- + * \ref nk_init_default | Initializes context with standard library memory allocation (malloc,free) + * \ref nk_init_fixed | Initializes context from single fixed size memory block + * \ref nk_init | Initializes context with memory allocator callbacks for alloc and free + * \ref nk_init_custom | Initializes context from two buffers. One for draw commands the other for window/panel/table allocations + * \ref nk_clear | Called at the end of the frame to reset and prepare the context for the next frame + * \ref nk_free | Shutdown and free all memory allocated inside the context + * \ref nk_set_user_data| Utility function to pass user data to draw command */ + #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR -/*/// #### nk_init_default -/// Initializes a `nk_context` struct with a default standard library allocator. -/// Should be used if you don't want to be bothered with memory management in nuklear. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|--------------------------------------------------------------- -/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct -/// __font__ | Must point to a previously initialized font handle for more info look at font documentation -/// -/// Returns either `false(0)` on failure or `true(1)` on success. -/// -*/ + +/** + * # nk_init_default + * Initializes a `nk_context` struct with a default standard library allocator. + * Should be used if you don't want to be bothered with memory management in nuklear. + * + * ```c + * nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); + * ``` + * + * Parameter | Description + * ------------|--------------------------------------------------------------- + * \param[in] ctx | Must point to an either stack or heap allocated `nk_context` struct + * \param[in] font | Must point to a previously initialized font handle for more info look at font documentation + * + * \returns either `false(0)` on failure or `true(1)` on success. + */ NK_API nk_bool nk_init_default(struct nk_context*, const struct nk_user_font*); #endif -/*/// #### nk_init_fixed -/// Initializes a `nk_context` struct from single fixed size memory block -/// Should be used if you want complete control over nuklear's memory management. -/// Especially recommended for system with little memory or systems with virtual memory. -/// For the later case you can just allocate for example 16MB of virtual memory -/// and only the required amount of memory will actually be committed. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// !!! Warning -/// make sure the passed memory block is aligned correctly for `nk_draw_commands`. -/// -/// Parameter | Description -/// ------------|-------------------------------------------------------------- -/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct -/// __memory__ | Must point to a previously allocated memory block -/// __size__ | Must contain the total size of __memory__ -/// __font__ | Must point to a previously initialized font handle for more info look at font documentation -/// -/// Returns either `false(0)` on failure or `true(1)` on success. -*/ +/** + * # nk_init_fixed + * Initializes a `nk_context` struct from single fixed size memory block + * Should be used if you want complete control over nuklear's memory management. + * Especially recommended for system with little memory or systems with virtual memory. + * For the later case you can just allocate for example 16MB of virtual memory + * and only the required amount of memory will actually be committed. + * + * ```c + * nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); + * ``` + * + * !!! Warning + * make sure the passed memory block is aligned correctly for `nk_draw_commands`. + * + * Parameter | Description + * ------------|-------------------------------------------------------------- + * \param[in] ctx | Must point to an either stack or heap allocated `nk_context` struct + * \param[in] memory | Must point to a previously allocated memory block + * \param[in] size | Must contain the total size of memory + * \param[in] font | Must point to a previously initialized font handle for more info look at font documentation + * + * \returns either `false(0)` on failure or `true(1)` on success. + */ NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*); -/*/// #### nk_init -/// Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate -/// memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation -/// interface to nuklear. Can be useful for cases like monitoring memory consumption. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|--------------------------------------------------------------- -/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct -/// __alloc__ | Must point to a previously allocated memory allocator -/// __font__ | Must point to a previously initialized font handle for more info look at font documentation -/// -/// Returns either `false(0)` on failure or `true(1)` on success. -*/ -NK_API nk_bool nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*); -/*/// #### nk_init_custom -/// Initializes a `nk_context` struct from two different either fixed or growing -/// buffers. The first buffer is for allocating draw commands while the second buffer is -/// used for allocating windows, panels and state tables. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|--------------------------------------------------------------- -/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct -/// __cmds__ | Must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into -/// __pool__ | Must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables -/// __font__ | Must point to a previously initialized font handle for more info look at font documentation -/// -/// Returns either `false(0)` on failure or `true(1)` on success. -*/ + +/** + * # nk_init + * Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate + * memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation + * interface to nuklear. Can be useful for cases like monitoring memory consumption. + * + * ```c + * nk_bool nk_init(struct nk_context *ctx, const struct nk_allocator *alloc, const struct nk_user_font *font); + * ``` + * + * Parameter | Description + * ------------|--------------------------------------------------------------- + * \param[in] ctx | Must point to an either stack or heap allocated `nk_context` struct + * \param[in] alloc | Must point to a previously allocated memory allocator + * \param[in] font | Must point to a previously initialized font handle for more info look at font documentation + * + * \returns either `false(0)` on failure or `true(1)` on success. + */ +NK_API nk_bool nk_init(struct nk_context*, const struct nk_allocator*, const struct nk_user_font*); + +/** + * \brief Initializes a `nk_context` struct from two different either fixed or growing buffers. + * + * \details + * The first buffer is for allocating draw commands while the second buffer is + * used for allocating windows, panels and state tables. + * + * ```c + * nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); + * ``` + * + * \param[in] ctx Must point to an either stack or heap allocated `nk_context` struct + * \param[in] cmds Must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into + * \param[in] pool Must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables + * \param[in] font Must point to a previously initialized font handle for more info look at font documentation + * + * \returns either `false(0)` on failure or `true(1)` on success. + */ NK_API nk_bool nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*); -/*/// #### nk_clear -/// Resets the context state at the end of the frame. This includes mostly -/// garbage collector tasks like removing windows or table not called and therefore -/// used anymore. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_clear(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -*/ + +/** + * \brief Resets the context state at the end of the frame. + * + * \details + * This includes mostly garbage collector tasks like removing windows or table + * not called and therefore used anymore. + * + * ```c + * void nk_clear(struct nk_context *ctx); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + */ NK_API void nk_clear(struct nk_context*); -/*/// #### nk_free -/// Frees all memory allocated by nuklear. Not needed if context was -/// initialized with `nk_init_fixed`. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_free(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -*/ + +/** + * \brief Frees all memory allocated by nuklear; Not needed if context was initialized with `nk_init_fixed`. + * + * \details + * ```c + * void nk_free(struct nk_context *ctx); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + */ NK_API void nk_free(struct nk_context*); + #ifdef NK_INCLUDE_COMMAND_USERDATA -/*/// #### nk_set_user_data -/// Sets the currently passed userdata passed down into each draw command. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_set_user_data(struct nk_context *ctx, nk_handle data); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|-------------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __data__ | Handle with either pointer or index to be passed into every draw commands -*/ +/** + * \brief Sets the currently passed userdata passed down into each draw command. + * + * \details + * ```c + * void nk_set_user_data(struct nk_context *ctx, nk_handle data); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + * \param[in] data Handle with either pointer or index to be passed into every draw commands + */ NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); #endif /* ============================================================================= @@ -691,67 +709,70 @@ NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); * INPUT * * =============================================================================*/ -/*/// ### Input -/// The input API is responsible for holding the current input state composed of -/// mouse, key and text input states. -/// It is worth noting that no direct OS or window handling is done in nuklear. -/// Instead all input state has to be provided by platform specific code. This on one hand -/// expects more work from the user and complicates usage but on the other hand -/// provides simple abstraction over a big number of platforms, libraries and other -/// already provided functionality. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// // [...] -/// } -/// } nk_input_end(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Usage -/// Input state needs to be provided to nuklear by first calling `nk_input_begin` -/// which resets internal state like delta mouse position and button transitions. -/// After `nk_input_begin` all current input state needs to be provided. This includes -/// mouse motion, button and key pressed and released, text input and scrolling. -/// Both event- or state-based input handling are supported by this API -/// and should work without problems. Finally after all input state has been -/// mirrored `nk_input_end` needs to be called to finish input process. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// Event evt; -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// // [...] -/// } -/// } -/// nk_input_end(&ctx); -/// // [...] -/// nk_clear(&ctx); -/// } nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// --------------------|------------------------------------------------------- -/// __nk_input_begin__ | Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls -/// __nk_input_motion__ | Mirrors mouse cursor position -/// __nk_input_key__ | Mirrors key state with either pressed or released -/// __nk_input_button__ | Mirrors mouse button state with either pressed or released -/// __nk_input_scroll__ | Mirrors mouse scroll values -/// __nk_input_char__ | Adds a single ASCII text character into an internal text buffer -/// __nk_input_glyph__ | Adds a single multi-byte UTF-8 character into an internal text buffer -/// __nk_input_unicode__| Adds a single unicode rune into an internal text buffer -/// __nk_input_end__ | Ends the input mirroring process by calculating state changes. Don't call any `nk_input_xxx` function referenced above after this call -*/ +/** + * \page Input + * + * The input API is responsible for holding the current input state composed of + * mouse, key and text input states. + * It is worth noting that no direct OS or window handling is done in nuklear. + * Instead all input state has to be provided by platform specific code. This on one hand + * expects more work from the user and complicates usage but on the other hand + * provides simple abstraction over a big number of platforms, libraries and other + * already provided functionality. + * + * ```c + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * // [...] + * } + * } nk_input_end(&ctx); + * ``` + * + * # Usage + * Input state needs to be provided to nuklear by first calling `nk_input_begin` + * which resets internal state like delta mouse position and button transitions. + * After `nk_input_begin` all current input state needs to be provided. This includes + * mouse motion, button and key pressed and released, text input and scrolling. + * Both event- or state-based input handling are supported by this API + * and should work without problems. Finally after all input state has been + * mirrored `nk_input_end` needs to be called to finish input process. + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * // [...] + * } + * } + * nk_input_end(&ctx); + * // [...] + * nk_clear(&ctx); + * } nk_free(&ctx); + * ``` + * + * # Reference + * Function | Description + * --------------------|------------------------------------------------------- + * \ref nk_input_begin | Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls + * \ref nk_input_motion | Mirrors mouse cursor position + * \ref nk_input_key | Mirrors key state with either pressed or released + * \ref nk_input_button | Mirrors mouse button state with either pressed or released + * \ref nk_input_scroll | Mirrors mouse scroll values + * \ref nk_input_char | Adds a single ASCII text character into an internal text buffer + * \ref nk_input_glyph | Adds a single multi-byte UTF-8 character into an internal text buffer + * \ref nk_input_unicode| Adds a single unicode rune into an internal text buffer + * \ref nk_input_end | Ends the input mirroring process by calculating state changes. Don't call any `nk_input_xxx` function referenced above after this call + */ + enum nk_keys { NK_KEY_NONE, NK_KEY_SHIFT, @@ -794,679 +815,694 @@ enum nk_buttons { NK_BUTTON_DOUBLE, NK_BUTTON_MAX }; -/*/// #### nk_input_begin -/// Begins the input mirroring process by resetting text, scroll -/// mouse, previous mouse position and movement as well as key state transitions, -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_begin(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -*/ + +/** + * \brief Begins the input mirroring process by resetting text, scroll + * mouse, previous mouse position and movement as well as key state transitions. + * + * \details + * ```c + * void nk_input_begin(struct nk_context*); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + */ NK_API void nk_input_begin(struct nk_context*); -/*/// #### nk_input_motion -/// Mirrors current mouse position to nuklear -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_motion(struct nk_context *ctx, int x, int y); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __x__ | Must hold an integer describing the current mouse cursor x-position -/// __y__ | Must hold an integer describing the current mouse cursor y-position -*/ + +/** + * \brief Mirrors current mouse position to nuklear + * + * \details + * ```c + * void nk_input_motion(struct nk_context *ctx, int x, int y); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + * \param[in] x Must hold an integer describing the current mouse cursor x-position + * \param[in] y Must hold an integer describing the current mouse cursor y-position + */ NK_API void nk_input_motion(struct nk_context*, int x, int y); -/*/// #### nk_input_key -/// Mirrors the state of a specific key to nuklear -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __key__ | Must be any value specified in enum `nk_keys` that needs to be mirrored -/// __down__ | Must be 0 for key is up and 1 for key is down -*/ + +/** + * \brief Mirrors the state of a specific key to nuklear + * + * \details + * ```c + * void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + * \param[in] key Must be any value specified in enum `nk_keys` that needs to be mirrored + * \param[in] down Must be 0 for key is up and 1 for key is down + */ NK_API void nk_input_key(struct nk_context*, enum nk_keys, nk_bool down); -/*/// #### nk_input_button -/// Mirrors the state of a specific mouse button to nuklear -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __btn__ | Must be any value specified in enum `nk_buttons` that needs to be mirrored -/// __x__ | Must contain an integer describing mouse cursor x-position on click up/down -/// __y__ | Must contain an integer describing mouse cursor y-position on click up/down -/// __down__ | Must be 0 for key is up and 1 for key is down -*/ + +/** + * \brief Mirrors the state of a specific mouse button to nuklear + * + * \details + * ```c + * void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down); + * ``` + * + * \param[in] ctx Must point to a previously initialized `nk_context` struct + * \param[in] btn Must be any value specified in enum `nk_buttons` that needs to be mirrored + * \param[in] x Must contain an integer describing mouse cursor x-position on click up/down + * \param[in] y Must contain an integer describing mouse cursor y-position on click up/down + * \param[in] down Must be 0 for key is up and 1 for key is down + */ NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, nk_bool down); -/*/// #### nk_input_scroll -/// Copies the last mouse scroll value to nuklear. Is generally -/// a scroll value. So does not have to come from mouse and could also originate -/// TODO finish this sentence -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __val__ | vector with both X- as well as Y-scroll value -*/ + +/** + * \brief Copies the last mouse scroll value to nuklear. + * + * \details + * Is generally a scroll value. So does not have to come from mouse and could + * also originate from balls, tracks, linear guide rails, or other programs. + * + * ```c + * void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val); + * ``` + * + * \param[in] ctx | Must point to a previously initialized `nk_context` struct + * \param[in] val | vector with both X- as well as Y-scroll value + */ NK_API void nk_input_scroll(struct nk_context*, struct nk_vec2 val); -/*/// #### nk_input_char -/// Copies a single ASCII character into an internal text buffer -/// This is basically a helper function to quickly push ASCII characters into -/// nuklear. -/// -/// !!! Note -/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_char(struct nk_context *ctx, char c); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __c__ | Must be a single ASCII character preferable one that can be printed -*/ + +/** + * \brief Copies a single ASCII character into an internal text buffer + * + * \details + * This is basically a helper function to quickly push ASCII characters into + * nuklear. + * + * \note + * Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. + * + * ```c + * void nk_input_char(struct nk_context *ctx, char c); + * ``` + * + * \param[in] ctx | Must point to a previously initialized `nk_context` struct + * \param[in] c | Must be a single ASCII character preferable one that can be printed + */ NK_API void nk_input_char(struct nk_context*, char); -/*/// #### nk_input_glyph -/// Converts an encoded unicode rune into UTF-8 and copies the result into an -/// internal text buffer. -/// -/// !!! Note -/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_glyph(struct nk_context *ctx, const nk_glyph g); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __g__ | UTF-32 unicode codepoint -*/ + +/** + * \brief Converts an encoded unicode rune into UTF-8 and copies the result into an + * internal text buffer. + * + * \note + * Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. + * + * ```c + * void nk_input_glyph(struct nk_context *ctx, const nk_glyph g); + * ``` + * + * \param[in] ctx | Must point to a previously initialized `nk_context` struct + * \param[in] g | UTF-32 unicode codepoint + */ NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); -/*/// #### nk_input_unicode -/// Converts a unicode rune into UTF-8 and copies the result -/// into an internal text buffer. -/// !!! Note -/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_unicode(struct nk_context*, nk_rune rune); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -/// __rune__ | UTF-32 unicode codepoint -*/ + +/** + * \brief Converts a unicode rune into UTF-8 and copies the result + * into an internal text buffer. + * + * \details + * \note + * Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. + * + * ```c + * void nk_input_unicode(struct nk_context*, nk_rune rune); + * ``` + * + * \param[in] ctx | Must point to a previously initialized `nk_context` struct + * \param[in] rune | UTF-32 unicode codepoint + */ NK_API void nk_input_unicode(struct nk_context*, nk_rune); -/*/// #### nk_input_end -/// End the input mirroring process by resetting mouse grabbing -/// state to ensure the mouse cursor is not grabbed indefinitely. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_input_end(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to a previously initialized `nk_context` struct -*/ + +/** + * \brief End the input mirroring process by resetting mouse grabbing + * state to ensure the mouse cursor is not grabbed indefinitely. + * + * \details + * ```c + * void nk_input_end(struct nk_context *ctx); + * ``` + * + * \param[in] ctx | Must point to a previously initialized `nk_context` struct + */ NK_API void nk_input_end(struct nk_context*); -/* ============================================================================= + +/** ============================================================================= * * DRAWING * * =============================================================================*/ -/*/// ### Drawing -/// This library was designed to be render backend agnostic so it does -/// not draw anything to screen directly. Instead all drawn shapes, widgets -/// are made of, are buffered into memory and make up a command queue. -/// Each frame therefore fills the command buffer with draw commands -/// that then need to be executed by the user and his own render backend. -/// After that the command buffer needs to be cleared and a new frame can be -/// started. It is probably important to note that the command buffer is the main -/// drawing API and the optional vertex buffer API only takes this format and -/// converts it into a hardware accessible format. -/// -/// #### Usage -/// To draw all draw commands accumulated over a frame you need your own render -/// backend able to draw a number of 2D primitives. This includes at least -/// filled and stroked rectangles, circles, text, lines, triangles and scissors. -/// As soon as this criterion is met you can iterate over each draw command -/// and execute each draw command in a interpreter like fashion: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case //...: -/// //[...] -/// } -/// } -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// In program flow context draw commands need to be executed after input has been -/// gathered and the complete UI with windows and their contained widgets have -/// been executed and before calling `nk_clear` which frees all previously -/// allocated draw commands. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// Event evt; -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// [...] -/// } -/// } -/// nk_input_end(&ctx); -/// // -/// // [...] -/// // -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case ...: -/// // [...] -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// You probably noticed that you have to draw all of the UI each frame which is -/// quite wasteful. While the actual UI updating loop is quite fast rendering -/// without actually needing it is not. So there are multiple things you could do. -/// -/// First is only update on input. This of course is only an option if your -/// application only depends on the UI and does not require any outside calculations. -/// If you actually only update on input make sure to update the UI two times each -/// frame and call `nk_clear` directly after the first pass and only draw in -/// the second pass. In addition it is recommended to also add additional timers -/// to make sure the UI is not drawn more than a fixed number of frames per second. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// // [...wait for input ] -/// // [...do two UI passes ...] -/// do_ui(...) -/// nk_clear(&ctx); -/// do_ui(...) -/// // -/// // draw -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case ...: -/// //[...] -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// The second probably more applicable trick is to only draw if anything changed. -/// It is not really useful for applications with continuous draw loop but -/// quite useful for desktop applications. To actually get nuklear to only -/// draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and -/// allocate a memory buffer that will store each unique drawing output. -/// After each frame you compare the draw command memory inside the library -/// with your allocated buffer by memcmp. If memcmp detects differences -/// you have to copy the command buffer into the allocated buffer -/// and then draw like usual (this example uses fixed memory but you could -/// use dynamically allocated memory). -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// //[... other defines ...] -/// #define NK_ZERO_COMMAND_MEMORY -/// #include "nuklear.h" -/// // -/// // setup context -/// struct nk_context ctx; -/// void *last = calloc(1,64*1024); -/// void *buf = calloc(1,64*1024); -/// nk_init_fixed(&ctx, buf, 64*1024); -/// // -/// // loop -/// while (1) { -/// // [...input...] -/// // [...ui...] -/// void *cmds = nk_buffer_memory(&ctx.memory); -/// if (memcmp(cmds, last, ctx.memory.allocated)) { -/// memcpy(last,cmds,ctx.memory.allocated); -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case ...: -/// // [...] -/// } -/// } -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Finally while using draw commands makes sense for higher abstracted platforms like -/// X11 and Win32 or drawing libraries it is often desirable to use graphics -/// hardware directly. Therefore it is possible to just define -/// `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output. -/// To access the vertex output you first have to convert all draw commands into -/// vertexes by calling `nk_convert` which takes in your preferred vertex format. -/// After successfully converting all draw commands just iterate over and execute all -/// vertex draw commands: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// // fill configuration -/// struct your_vertex -/// { -/// float pos[2]; // important to keep it to 2 floats -/// float uv[2]; -/// unsigned char col[4]; -/// }; -/// struct nk_convert_config cfg = {}; -/// static const struct nk_draw_vertex_layout_element vertex_layout[] = { -/// {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)}, -/// {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)}, -/// {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)}, -/// {NK_VERTEX_LAYOUT_END} -/// }; -/// cfg.shape_AA = NK_ANTI_ALIASING_ON; -/// cfg.line_AA = NK_ANTI_ALIASING_ON; -/// cfg.vertex_layout = vertex_layout; -/// cfg.vertex_size = sizeof(struct your_vertex); -/// cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex); -/// cfg.circle_segment_count = 22; -/// cfg.curve_segment_count = 22; -/// cfg.arc_segment_count = 22; -/// cfg.global_alpha = 1.0f; -/// cfg.tex_null = dev->tex_null; -/// // -/// // setup buffers and convert -/// struct nk_buffer cmds, verts, idx; -/// nk_buffer_init_default(&cmds); -/// nk_buffer_init_default(&verts); -/// nk_buffer_init_default(&idx); -/// nk_convert(&ctx, &cmds, &verts, &idx, &cfg); -/// // -/// // draw -/// nk_draw_foreach(cmd, &ctx, &cmds) { -/// if (!cmd->elem_count) continue; -/// //[...] -/// } -/// nk_buffer_free(&cms); -/// nk_buffer_free(&verts); -/// nk_buffer_free(&idx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// --------------------|------------------------------------------------------- -/// __nk__begin__ | Returns the first draw command in the context draw command list to be drawn -/// __nk__next__ | Increments the draw command iterator to the next command inside the context draw command list -/// __nk_foreach__ | Iterates over each draw command inside the context draw command list -/// __nk_convert__ | Converts from the abstract draw commands list into a hardware accessible vertex format -/// __nk_draw_begin__ | Returns the first vertex command in the context vertex draw list to be executed -/// __nk__draw_next__ | Increments the vertex command iterator to the next command inside the context vertex command list -/// __nk__draw_end__ | Returns the end of the vertex draw list -/// __nk_draw_foreach__ | Iterates over each vertex draw command inside the vertex draw list -*/ -enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; -enum nk_convert_result { - NK_CONVERT_SUCCESS = 0, - NK_CONVERT_INVALID_PARAM = 1, - NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), - NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), - NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) -}; -struct nk_draw_null_texture { - nk_handle texture; /* texture handle to a texture with a white pixel */ - struct nk_vec2 uv; /* coordinates to a white pixel in the texture */ -}; -struct nk_convert_config { - float global_alpha; /* global alpha value */ - enum nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */ - enum nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */ - unsigned circle_segment_count; /* number of segments used for circles: default to 22 */ - unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */ - unsigned curve_segment_count; /* number of segments used for curves: default to 22 */ - struct nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */ - const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ - nk_size vertex_size; /* sizeof one vertex for vertex packing */ - nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ +/** + * \page Drawing + * This library was designed to be render backend agnostic so it does + * not draw anything to screen directly. Instead all drawn shapes, widgets + * are made of, are buffered into memory and make up a command queue. + * Each frame therefore fills the command buffer with draw commands + * that then need to be executed by the user and his own render backend. + * After that the command buffer needs to be cleared and a new frame can be + * started. It is probably important to note that the command buffer is the main + * drawing API and the optional vertex buffer API only takes this format and + * converts it into a hardware accessible format. + * + * # Usage + * To draw all draw commands accumulated over a frame you need your own render + * backend able to draw a number of 2D primitives. This includes at least + * filled and stroked rectangles, circles, text, lines, triangles and scissors. + * As soon as this criterion is met you can iterate over each draw command + * and execute each draw command in a interpreter like fashion: + * + * ```c + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case //...: + * //[...] + * } + * } + * ``` + * + * In program flow context draw commands need to be executed after input has been + * gathered and the complete UI with windows and their contained widgets have + * been executed and before calling `nk_clear` which frees all previously + * allocated draw commands. + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * [...] + * } + * } + * nk_input_end(&ctx); + * // + * // [...] + * // + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * // [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * You probably noticed that you have to draw all of the UI each frame which is + * quite wasteful. While the actual UI updating loop is quite fast rendering + * without actually needing it is not. So there are multiple things you could do. + * + * First is only update on input. This of course is only an option if your + * application only depends on the UI and does not require any outside calculations. + * If you actually only update on input make sure to update the UI two times each + * frame and call `nk_clear` directly after the first pass and only draw in + * the second pass. In addition it is recommended to also add additional timers + * to make sure the UI is not drawn more than a fixed number of frames per second. + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * // [...wait for input ] + * // [...do two UI passes ...] + * do_ui(...) + * nk_clear(&ctx); + * do_ui(...) + * // + * // draw + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * //[...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * The second probably more applicable trick is to only draw if anything changed. + * It is not really useful for applications with continuous draw loop but + * quite useful for desktop applications. To actually get nuklear to only + * draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and + * allocate a memory buffer that will store each unique drawing output. + * After each frame you compare the draw command memory inside the library + * with your allocated buffer by memcmp. If memcmp detects differences + * you have to copy the command buffer into the allocated buffer + * and then draw like usual (this example uses fixed memory but you could + * use dynamically allocated memory). + * + * ```c + * //[... other defines ...] + * #define NK_ZERO_COMMAND_MEMORY + * #include "nuklear.h" + * // + * // setup context + * struct nk_context ctx; + * void *last = calloc(1,64*1024); + * void *buf = calloc(1,64*1024); + * nk_init_fixed(&ctx, buf, 64*1024); + * // + * // loop + * while (1) { + * // [...input...] + * // [...ui...] + * void *cmds = nk_buffer_memory(&ctx.memory); + * if (memcmp(cmds, last, ctx.memory.allocated)) { + * memcpy(last,cmds,ctx.memory.allocated); + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * // [...] + * } + * } + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * Finally while using draw commands makes sense for higher abstracted platforms like + * X11 and Win32 or drawing libraries it is often desirable to use graphics + * hardware directly. Therefore it is possible to just define + * `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output. + * To access the vertex output you first have to convert all draw commands into + * vertexes by calling `nk_convert` which takes in your preferred vertex format. + * After successfully converting all draw commands just iterate over and execute all + * vertex draw commands: + * + * ```c + * // fill configuration + * struct your_vertex + * { + * float pos[2]; // important to keep it to 2 floats + * float uv[2]; + * unsigned char col[4]; + * }; + * struct nk_convert_config cfg = {}; + * static const struct nk_draw_vertex_layout_element vertex_layout[] = { + * {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)}, + * {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)}, + * {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)}, + * {NK_VERTEX_LAYOUT_END} + * }; + * cfg.shape_AA = NK_ANTI_ALIASING_ON; + * cfg.line_AA = NK_ANTI_ALIASING_ON; + * cfg.vertex_layout = vertex_layout; + * cfg.vertex_size = sizeof(struct your_vertex); + * cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex); + * cfg.circle_segment_count = 22; + * cfg.curve_segment_count = 22; + * cfg.arc_segment_count = 22; + * cfg.global_alpha = 1.0f; + * cfg.tex_null = dev->tex_null; + * // + * // setup buffers and convert + * struct nk_buffer cmds, verts, idx; + * nk_buffer_init_default(&cmds); + * nk_buffer_init_default(&verts); + * nk_buffer_init_default(&idx); + * nk_convert(&ctx, &cmds, &verts, &idx, &cfg); + * // + * // draw + * nk_draw_foreach(cmd, &ctx, &cmds) { + * if (!cmd->elem_count) continue; + * //[...] + * } + * nk_buffer_free(&cms); + * nk_buffer_free(&verts); + * nk_buffer_free(&idx); + * ``` + * + * # Reference + * Function | Description + * --------------------|------------------------------------------------------- + * \ref nk__begin | Returns the first draw command in the context draw command list to be drawn + * \ref nk__next | Increments the draw command iterator to the next command inside the context draw command list + * \ref nk_foreach | Iterates over each draw command inside the context draw command list + * \ref nk_convert | Converts from the abstract draw commands list into a hardware accessible vertex format + * \ref nk_draw_begin | Returns the first vertex command in the context vertex draw list to be executed + * \ref nk__draw_next | Increments the vertex command iterator to the next command inside the context vertex command list + * \ref nk__draw_end | Returns the end of the vertex draw list + * \ref nk_draw_foreach | Iterates over each vertex draw command inside the vertex draw list + */ + +enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; +enum nk_convert_result { + NK_CONVERT_SUCCESS = 0, + NK_CONVERT_INVALID_PARAM = 1, + NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), + NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), + NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) }; -/*/// #### nk__begin -/// Returns a draw command list iterator to iterate all draw -/// commands accumulated over one frame. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_command* nk__begin(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | must point to an previously initialized `nk_context` struct at the end of a frame -/// -/// Returns draw command pointer pointing to the first command inside the draw command list -*/ +struct nk_draw_null_texture { + nk_handle texture; /**!< texture handle to a texture with a white pixel */ + struct nk_vec2 uv; /**!< coordinates to a white pixel in the texture */ +}; +struct nk_convert_config { + float global_alpha; /**!< global alpha value */ + enum nk_anti_aliasing line_AA; /**!< line anti-aliasing flag can be turned off if you are tight on memory */ + enum nk_anti_aliasing shape_AA; /**!< shape anti-aliasing flag can be turned off if you are tight on memory */ + unsigned circle_segment_count; /**!< number of segments used for circles: default to 22 */ + unsigned arc_segment_count; /**!< number of segments used for arcs: default to 22 */ + unsigned curve_segment_count; /**!< number of segments used for curves: default to 22 */ + struct nk_draw_null_texture tex_null; /**!< handle to texture with a white pixel for shape drawing */ + const struct nk_draw_vertex_layout_element *vertex_layout; /**!< describes the vertex output format and packing */ + nk_size vertex_size; /**!< sizeof one vertex for vertex packing */ + nk_size vertex_alignment; /**!< vertex alignment: Can be obtained by NK_ALIGNOF */ +}; + +/** + * \brief Returns a draw command list iterator to iterate all draw + * commands accumulated over one frame. + * + * \details + * ```c + * const struct nk_command* nk__begin(struct nk_context*); + * ``` + * + * \param[in] ctx | must point to an previously initialized `nk_context` struct at the end of a frame + * + * \returns draw command pointer pointing to the first command inside the draw command list + */ NK_API const struct nk_command* nk__begin(struct nk_context*); -/*/// #### nk__next -/// Returns draw command pointer pointing to the next command inside the draw command list -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// __cmd__ | Must point to an previously a draw command either returned by `nk__begin` or `nk__next` -/// -/// Returns draw command pointer pointing to the next command inside the draw command list -*/ + +/** + * \brief Returns draw command pointer pointing to the next command inside the draw command list + * + * \details + * ```c + * const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + * \param[in] cmd | Must point to an previously a draw command either returned by `nk__begin` or `nk__next` + * + * \returns draw command pointer pointing to the next command inside the draw command list + */ NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); -/*/// #### nk_foreach -/// Iterates over each draw command inside the context draw command list -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_foreach(c, ctx) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// __cmd__ | Command pointer initialized to NULL -/// -/// Iterates over each draw command inside the context draw command list -*/ + +/** + * \brief Iterates over each draw command inside the context draw command list + * + * ```c + * #define nk_foreach(c, ctx) + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + * \param[in] cmd | Command pointer initialized to NULL + */ #define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c)) + #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -/*/// #### nk_convert -/// Converts all internal draw commands into vertex draw commands and fills -/// three buffers with vertexes, vertex draw commands and vertex indices. The vertex format -/// as well as some other configuration values have to be configured by filling out a -/// `nk_convert_config` struct. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, -/// struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// __cmds__ | Must point to a previously initialized buffer to hold converted vertex draw commands -/// __vertices__| Must point to a previously initialized buffer to hold all produced vertices -/// __elements__| Must point to a previously initialized buffer to hold all produced vertex indices -/// __config__ | Must point to a filled out `nk_config` struct to configure the conversion process -/// -/// Returns one of enum nk_convert_result error codes -/// -/// Parameter | Description -/// --------------------------------|----------------------------------------------------------- -/// NK_CONVERT_SUCCESS | Signals a successful draw command to vertex buffer conversion -/// NK_CONVERT_INVALID_PARAM | An invalid argument was passed in the function call -/// NK_CONVERT_COMMAND_BUFFER_FULL | The provided buffer for storing draw commands is full or failed to allocate more memory -/// NK_CONVERT_VERTEX_BUFFER_FULL | The provided buffer for storing vertices is full or failed to allocate more memory -/// NK_CONVERT_ELEMENT_BUFFER_FULL | The provided buffer for storing indices is full or failed to allocate more memory -*/ + +/** + * \brief Converts all internal draw commands into vertex draw commands and fills + * three buffers with vertexes, vertex draw commands and vertex indices. + * + * \details + * The vertex format as well as some other configuration values have to be + * configured by filling out a `nk_convert_config` struct. + * + * ```c + * nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, + * struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); + * ``` + * + * \param[in] ctx Must point to an previously initialized `nk_context` struct at the end of a frame + * \param[out] cmds Must point to a previously initialized buffer to hold converted vertex draw commands + * \param[out] vertices Must point to a previously initialized buffer to hold all produced vertices + * \param[out] elements Must point to a previously initialized buffer to hold all produced vertex indices + * \param[in] config Must point to a filled out `nk_config` struct to configure the conversion process + * + * \returns one of enum nk_convert_result error codes + * + * Parameter | Description + * --------------------------------|----------------------------------------------------------- + * NK_CONVERT_SUCCESS | Signals a successful draw command to vertex buffer conversion + * NK_CONVERT_INVALID_PARAM | An invalid argument was passed in the function call + * NK_CONVERT_COMMAND_BUFFER_FULL | The provided buffer for storing draw commands is full or failed to allocate more memory + * NK_CONVERT_VERTEX_BUFFER_FULL | The provided buffer for storing vertices is full or failed to allocate more memory + * NK_CONVERT_ELEMENT_BUFFER_FULL | The provided buffer for storing indices is full or failed to allocate more memory + */ NK_API nk_flags nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); -/*/// #### nk__draw_begin -/// Returns a draw vertex command buffer iterator to iterate over the vertex draw command buffer -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer -/// -/// Returns vertex draw command pointer pointing to the first command inside the vertex draw command buffer -*/ + +/** + * \brief Returns a draw vertex command buffer iterator to iterate over the vertex draw command buffer + * + * \details + * ```c + * const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + * \param[in] buf | Must point to an previously by `nk_convert` filled out vertex draw command buffer + * + * \returns vertex draw command pointer pointing to the first command inside the vertex draw command buffer + */ NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); -/*/// #### nk__draw_end -/// Returns the vertex draw command at the end of the vertex draw command buffer -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_draw_command* nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buf); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer -/// -/// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer -*/ + +/** + + * # # nk__draw_end + * \returns the vertex draw command at the end of the vertex draw command buffer + * + * ```c + * const struct nk_draw_command* nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buf); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + * \param[in] buf | Must point to an previously by `nk_convert` filled out vertex draw command buffer + * + * \returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer + + */ NK_API const struct nk_draw_command* nk__draw_end(const struct nk_context*, const struct nk_buffer*); -/*/// #### nk__draw_next -/// Increments the vertex draw command buffer iterator -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __cmd__ | Must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command -/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -/// -/// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer -*/ + +/** + * # # nk__draw_next + * Increments the vertex draw command buffer iterator + * + * ```c + * const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] cmd | Must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command + * \param[in] buf | Must point to an previously by `nk_convert` filled out vertex draw command buffer + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + * + * \returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer + + */ NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); -/*/// #### nk_draw_foreach -/// Iterates over each vertex draw command inside a vertex draw command buffer -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_draw_foreach(cmd,ctx, b) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __cmd__ | `nk_draw_command`iterator set to NULL -/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer -/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame -*/ + +/** + * # # nk_draw_foreach + * Iterates over each vertex draw command inside a vertex draw command buffer + * + * ```c + * #define nk_draw_foreach(cmd,ctx, b) + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] cmd | `nk_draw_command`iterator set to NULL + * \param[in] buf | Must point to an previously by `nk_convert` filled out vertex draw command buffer + * \param[in] ctx | Must point to an previously initialized `nk_context` struct at the end of a frame + */ + #define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) #endif -/* ============================================================================= + +/** ============================================================================= * * WINDOW * - * ============================================================================= -/// ### Window -/// Windows are the main persistent state used inside nuklear and are life time -/// controlled by simply "retouching" (i.e. calling) each window each frame. -/// All widgets inside nuklear can only be added inside the function pair `nk_begin_xxx` -/// and `nk_end`. Calling any widgets outside these two functions will result in an -/// assert in debug or no state change in release mode.

-/// -/// Each window holds frame persistent state like position, size, flags, state tables, -/// and some garbage collected internal persistent widget state. Each window -/// is linked into a window stack list which determines the drawing and overlapping -/// order. The topmost window thereby is the currently active window.

-/// -/// To change window position inside the stack occurs either automatically by -/// user input by being clicked on or programmatically by calling `nk_window_focus`. -/// Windows by default are visible unless explicitly being defined with flag -/// `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag -/// `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling -/// `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.

-/// -/// #### Usage -/// To create and keep a window you have to call one of the two `nk_begin_xxx` -/// functions to start window declarations and `nk_end` at the end. Furthermore it -/// is recommended to check the return value of `nk_begin_xxx` and only process -/// widgets inside the window if the value is not 0. Either way you have to call -/// `nk_end` at the end of window declarations. Furthermore, do not attempt to -/// nest `nk_begin_xxx` calls which will hopefully result in an assert or if not -/// in a segmentation fault. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // [... widgets ...] -/// } -/// nk_end(ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// In the grand concept window and widget declarations need to occur after input -/// handling and before drawing to screen. Not doing so can result in higher -/// latency or at worst invalid behavior. Furthermore make sure that `nk_clear` -/// is called at the end of the frame. While nuklear's default platform backends -/// already call `nk_clear` for you if you write your own backend not calling -/// `nk_clear` can cause asserts or even worse undefined behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// Event evt; -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// nk_input_xxx(...); -/// } -/// } -/// nk_input_end(&ctx); -/// -/// if (nk_begin_xxx(...) { -/// //[...] -/// } -/// nk_end(ctx); -/// -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case //...: -/// //[...] -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// ------------------------------------|---------------------------------------- -/// nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed -/// nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title -/// nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup -// -/// nk_window_find | Finds and returns the window with give name -/// nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window. -/// nk_window_get_position | Returns the position of the currently processed window -/// nk_window_get_size | Returns the size with width and height of the currently processed window -/// nk_window_get_width | Returns the width of the currently processed window -/// nk_window_get_height | Returns the height of the currently processed window -/// nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window -/// nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window -/// nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window -/// nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window -/// nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window -/// nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets -/// nk_window_get_scroll | Gets the scroll offset of the current window -/// nk_window_has_focus | Returns if the currently processed window is currently active -/// nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed -/// nk_window_is_closed | Returns if the currently processed window was closed -/// nk_window_is_hidden | Returns if the currently processed window was hidden -/// nk_window_is_active | Same as nk_window_has_focus for some reason -/// nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse -/// nk_window_is_any_hovered | Return if any window currently hovered -/// nk_item_is_any_active | Returns if any window or widgets is currently hovered or active + * =============================================================================*/ +/** + * \page Window + * Windows are the main persistent state used inside nuklear and are life time + * controlled by simply "retouching" (i.e. calling) each window each frame. + * All widgets inside nuklear can only be added inside the function pair `nk_begin_xxx` + * and `nk_end`. Calling any widgets outside these two functions will result in an + * assert in debug or no state change in release mode.

+ * + * Each window holds frame persistent state like position, size, flags, state tables, + * and some garbage collected internal persistent widget state. Each window + * is linked into a window stack list which determines the drawing and overlapping + * order. The topmost window thereby is the currently active window.

+ * + * To change window position inside the stack occurs either automatically by + * user input by being clicked on or programmatically by calling `nk_window_focus`. + * Windows by default are visible unless explicitly being defined with flag + * `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag + * `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling + * `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.

+ * + * # Usage + * To create and keep a window you have to call one of the two `nk_begin_xxx` + * functions to start window declarations and `nk_end` at the end. Furthermore it + * is recommended to check the return value of `nk_begin_xxx` and only process + * widgets inside the window if the value is not 0. Either way you have to call + * `nk_end` at the end of window declarations. Furthermore, do not attempt to + * nest `nk_begin_xxx` calls which will hopefully result in an assert or if not + * in a segmentation fault. + * + * ```c + * if (nk_begin_xxx(...) { + * // [... widgets ...] + * } + * nk_end(ctx); + * ``` + * + * In the grand concept window and widget declarations need to occur after input + * handling and before drawing to screen. Not doing so can result in higher + * latency or at worst invalid behavior. Furthermore make sure that `nk_clear` + * is called at the end of the frame. While nuklear's default platform backends + * already call `nk_clear` for you if you write your own backend not calling + * `nk_clear` can cause asserts or even worse undefined behavior. + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * nk_input_xxx(...); + * } + * } + * nk_input_end(&ctx); + * + * if (nk_begin_xxx(...) { + * //[...] + * } + * nk_end(ctx); + * + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case //...: + * //[...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * # Reference + * Function | Description + * ------------------------------------|---------------------------------------- + * \ref nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed + * \ref nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title + * \ref nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup + * + * \ref nk_window_find | Finds and returns the window with give name + * \ref nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window. + * \ref nk_window_get_position | Returns the position of the currently processed window + * \ref nk_window_get_size | Returns the size with width and height of the currently processed window + * \ref nk_window_get_width | Returns the width of the currently processed window + * \ref nk_window_get_height | Returns the height of the currently processed window + * \ref nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window + * \ref nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window + * \ref nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window + * \ref nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window + * \ref nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window + * \ref nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets + * \ref nk_window_get_scroll | Gets the scroll offset of the current window + * \ref nk_window_has_focus | Returns if the currently processed window is currently active + * \ref nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed + * \ref nk_window_is_closed | Returns if the currently processed window was closed + * \ref nk_window_is_hidden | Returns if the currently processed window was hidden + * \ref nk_window_is_active | Same as nk_window_has_focus for some reason + * \ref nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse + * \ref nk_window_is_any_hovered | Return if any window currently hovered + * \ref nk_item_is_any_active | Returns if any window or widgets is currently hovered or active // -/// nk_window_set_bounds | Updates position and size of the currently processed window -/// nk_window_set_position | Updates position of the currently process window -/// nk_window_set_size | Updates the size of the currently processed window -/// nk_window_set_focus | Set the currently processed window as active window -/// nk_window_set_scroll | Sets the scroll offset of the current window + * \ref nk_window_set_bounds | Updates position and size of the currently processed window + * \ref nk_window_set_position | Updates position of the currently process window + * \ref nk_window_set_size | Updates the size of the currently processed window + * \ref nk_window_set_focus | Set the currently processed window as active window + * \ref nk_window_set_scroll | Sets the scroll offset of the current window // -/// nk_window_close | Closes the window with given window name which deletes the window at the end of the frame -/// nk_window_collapse | Collapses the window with given window name -/// nk_window_collapse_if | Collapses the window with given window name if the given condition was met -/// nk_window_show | Hides a visible or reshows a hidden window -/// nk_window_show_if | Hides/shows a window depending on condition -*/ -/* -/// #### nk_panel_flags -/// Flag | Description -/// ----------------------------|---------------------------------------- -/// NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background -/// NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header -/// NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window -/// NK_WINDOW_CLOSABLE | Adds a closable icon into the header -/// NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header -/// NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window -/// NK_WINDOW_TITLE | Forces a header at the top at the window showing the title -/// NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame -/// NK_WINDOW_BACKGROUND | Always keep window in the background -/// NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-bottom corner instead right-bottom -/// NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus -/// -/// #### nk_collapse_states -/// State | Description -/// ----------------|----------------------------------------------------------- -/// __NK_MINIMIZED__| UI section is collased and not visible until maximized -/// __NK_MAXIMIZED__| UI section is extended and visible until minimized -///

-*/ + * \ref nk_window_close | Closes the window with given window name which deletes the window at the end of the frame + * \ref nk_window_collapse | Collapses the window with given window name + * \ref nk_window_collapse_if | Collapses the window with given window name if the given condition was met + * \ref nk_window_show | Hides a visible or reshows a hidden window + * \ref nk_window_show_if | Hides/shows a window depending on condition + + * # nk_panel_flags + * Flag | Description + * ----------------------------|---------------------------------------- + * NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background + * NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header + * NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window + * NK_WINDOW_CLOSABLE | Adds a closable icon into the header + * NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header + * NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window + * NK_WINDOW_TITLE | Forces a header at the top at the window showing the title + * NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame + * NK_WINDOW_BACKGROUND | Always keep window in the background + * NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-bottom corner instead right-bottom + * NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus + * + * # nk_collapse_states + * State | Description + * ----------------|----------------------------------------------------------- + * NK_MINIMIZED| UI section is collapsed and not visible until maximized + * NK_MAXIMIZED| UI section is extended and visible until minimized + */ + enum nk_panel_flags { NK_WINDOW_BORDER = NK_FLAG(0), NK_WINDOW_MOVABLE = NK_FLAG(1), @@ -1480,816 +1516,914 @@ enum nk_panel_flags { NK_WINDOW_SCALE_LEFT = NK_FLAG(9), NK_WINDOW_NO_INPUT = NK_FLAG(10) }; -/*/// #### nk_begin -/// Starts a new window; needs to be called every frame for every -/// window (unless hidden) or otherwise the window gets removed -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __title__ | Window title and identifier. Needs to be persistent over frames to identify the window -/// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame -/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors -/// -/// Returns `true(1)` if the window can be filled up with widgets from this point -/// until `nk_end` or `false(0)` otherwise for example if minimized -*/ + +/** + * # # nk_begin + * Starts a new window; needs to be called every frame for every + * window (unless hidden) or otherwise the window gets removed + * + * ```c + * nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] title | Window title and identifier. Needs to be persistent over frames to identify the window + * \param[in] bounds | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame + * \param[in] flags | Window flags defined in the nk_panel_flags section with a number of different window behaviors + * + * \returns `true(1)` if the window can be filled up with widgets from this point + * until `nk_end` or `false(0)` otherwise for example if minimized + + */ NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); -/*/// #### nk_begin_titled -/// Extended window start with separated title and identifier to allow multiple -/// windows with same title but not name -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Window identifier. Needs to be persistent over frames to identify the window -/// __title__ | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set -/// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame -/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors -/// -/// Returns `true(1)` if the window can be filled up with widgets from this point -/// until `nk_end` or `false(0)` otherwise for example if minimized -*/ + +/** + * # # nk_begin_titled + * Extended window start with separated title and identifier to allow multiple + * windows with same title but not name + * + * ```c + * nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Window identifier. Needs to be persistent over frames to identify the window + * \param[in] title | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set + * \param[in] bounds | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame + * \param[in] flags | Window flags defined in the nk_panel_flags section with a number of different window behaviors + * + * \returns `true(1)` if the window can be filled up with widgets from this point + * until `nk_end` or `false(0)` otherwise for example if minimized + + */ NK_API nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); -/*/// #### nk_end -/// Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup. -/// All widget calls after this functions will result in asserts or no state changes -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_end(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -*/ + +/** + * # # nk_end + * Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup. + * All widget calls after this functions will result in asserts or no state changes + * + * ```c + * void nk_end(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + + */ NK_API void nk_end(struct nk_context *ctx); -/*/// #### nk_window_find -/// Finds and returns a window from passed name -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Window identifier -/// -/// Returns a `nk_window` struct pointing to the identified window or NULL if -/// no window with the given name was found -*/ -NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); -/*/// #### nk_window_get_bounds -/// Returns a rectangle with screen position and size of the currently processed window -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns a `nk_rect` struct with window upper left window position and size -*/ + +/** + * # # nk_window_find + * Finds and returns a window from passed name + * + * ```c + * struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Window identifier + * + * \returns a `nk_window` struct pointing to the identified window or NULL if + * no window with the given name was found + */ +NK_API struct nk_window *nk_window_find(const struct nk_context *ctx, const char *name); + +/** + * # # nk_window_get_bounds + * \returns a rectangle with screen position and size of the currently processed window + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns a `nk_rect` struct with window upper left window position and size + + */ NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); -/*/// #### nk_window_get_position -/// Returns the position of the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns a `nk_vec2` struct with window upper left position -*/ + +/** + * # # nk_window_get_position + * \returns the position of the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns a `nk_vec2` struct with window upper left position + + */ NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); -/*/// #### nk_window_get_size -/// Returns the size with width and height of the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns a `nk_vec2` struct with window width and height -*/ -NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); -/*/// #### nk_window_get_width -/// Returns the width of the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// float nk_window_get_width(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns the current window width -*/ -NK_API float nk_window_get_width(const struct nk_context*); -/*/// #### nk_window_get_height -/// Returns the height of the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// float nk_window_get_height(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns the current window height -*/ -NK_API float nk_window_get_height(const struct nk_context*); -/*/// #### nk_window_get_panel -/// Returns the underlying panel which contains all processing state of the current window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// !!! WARNING -/// Do not keep the returned panel pointer around, it is only valid until `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_panel* nk_window_get_panel(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns a pointer to window internal `nk_panel` state. -*/ -NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); -/*/// #### nk_window_get_content_region -/// Returns the position and size of the currently visible and non-clipped space -/// inside the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_window_get_content_region(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `nk_rect` struct with screen position and size (no scrollbar offset) -/// of the visible space inside the current window -*/ -NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); -/*/// #### nk_window_get_content_region_min -/// Returns the upper left position of the currently visible and non-clipped -/// space inside the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// returns `nk_vec2` struct with upper left screen position (no scrollbar offset) -/// of the visible space inside the current window -*/ -NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); -/*/// #### nk_window_get_content_region_max -/// Returns the lower right screen position of the currently visible and -/// non-clipped space inside the currently processed window. -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `nk_vec2` struct with lower right screen position (no scrollbar offset) -/// of the visible space inside the current window -*/ -NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); -/*/// #### nk_window_get_content_region_size -/// Returns the size of the currently visible and non-clipped space inside the -/// currently processed window -/// -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `nk_vec2` struct with size the visible space inside the current window -*/ -NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context*); -/*/// #### nk_window_get_canvas -/// Returns the draw command buffer. Can be used to draw custom widgets -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// !!! WARNING -/// Do not keep the returned command buffer pointer around it is only valid until `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns a pointer to window internal `nk_command_buffer` struct used as -/// drawing canvas. Can be used to do custom drawing. -*/ -NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*); -/*/// #### nk_window_get_scroll -/// Gets the scroll offset for the current window -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// -------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __offset_x__ | A pointer to the x offset output (or NULL to ignore) -/// __offset_y__ | A pointer to the y offset output (or NULL to ignore) -*/ -NK_API void nk_window_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); -/*/// #### nk_window_has_focus -/// Returns if the currently processed window is currently active -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_has_focus(const struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `false(0)` if current window is not active or `true(1)` if it is -*/ -NK_API nk_bool nk_window_has_focus(const struct nk_context*); -/*/// #### nk_window_is_hovered -/// Return if the current window is being hovered -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_hovered(struct nk_context *ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `true(1)` if current window is hovered or `false(0)` otherwise -*/ -NK_API nk_bool nk_window_is_hovered(struct nk_context*); -/*/// #### nk_window_is_collapsed -/// Returns if the window with given name is currently minimized/collapsed -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of window you want to check if it is collapsed -/// -/// Returns `true(1)` if current window is minimized and `false(0)` if window not -/// found or is not minimized -*/ -NK_API nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); -/*/// #### nk_window_is_closed -/// Returns if the window with given name was closed by calling `nk_close` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of window you want to check if it is closed -/// -/// Returns `true(1)` if current window was closed or `false(0)` window not found or not closed -*/ -NK_API nk_bool nk_window_is_closed(struct nk_context*, const char*); -/*/// #### nk_window_is_hidden -/// Returns if the window with given name is hidden -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of window you want to check if it is hidden -/// -/// Returns `true(1)` if current window is hidden or `false(0)` window not found or visible -*/ -NK_API nk_bool nk_window_is_hidden(struct nk_context*, const char*); -/*/// #### nk_window_is_active -/// Same as nk_window_has_focus for some reason -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_active(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of window you want to check if it is active -/// -/// Returns `true(1)` if current window is active or `false(0)` window not found or not active -*/ -NK_API nk_bool nk_window_is_active(struct nk_context*, const char*); -/*/// #### nk_window_is_any_hovered -/// Returns if the any window is being hovered -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_window_is_any_hovered(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `true(1)` if any window is hovered or `false(0)` otherwise -*/ -NK_API nk_bool nk_window_is_any_hovered(struct nk_context*); -/*/// #### nk_item_is_any_active -/// Returns if the any window is being hovered or any widget is currently active. -/// Can be used to decide if input should be processed by UI or your specific input handling. -/// Example could be UI and 3D camera to move inside a 3D space. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_item_is_any_active(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// -/// Returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise -*/ -NK_API nk_bool nk_item_is_any_active(struct nk_context*); -/*/// #### nk_window_set_bounds -/// Updates position and size of window with passed in name -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to modify both position and size -/// __bounds__ | Must point to a `nk_rect` struct with the new position and size -*/ -NK_API void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); -/*/// #### nk_window_set_position -/// Updates position of window with passed name -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to modify both position -/// __pos__ | Must point to a `nk_vec2` struct with the new position -*/ -NK_API void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); -/*/// #### nk_window_set_size -/// Updates size of window with passed in name -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to modify both window size -/// __size__ | Must point to a `nk_vec2` struct with new window size -*/ -NK_API void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); -/*/// #### nk_window_set_focus -/// Sets the window with given name as active -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_set_focus(struct nk_context*, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to set focus on -*/ -NK_API void nk_window_set_focus(struct nk_context*, const char *name); -/*/// #### nk_window_set_scroll -/// Sets the scroll offset for the current window -/// !!! WARNING -/// Only call this function between calls `nk_begin_xxx` and `nk_end` -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// -------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __offset_x__ | The x offset to scroll to -/// __offset_y__ | The y offset to scroll to -*/ -NK_API void nk_window_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); -/*/// #### nk_window_close -/// Closes a window and marks it for being freed at the end of the frame -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_close(struct nk_context *ctx, const char *name); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to close -*/ + +/** + * # # nk_window_get_size + * \returns the size with width and height of the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns a `nk_vec2` struct with window width and height + + */ +NK_API struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); + +/** + * nk_window_get_width + * \returns the width of the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * float nk_window_get_width(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns the current window width + */ +NK_API float nk_window_get_width(const struct nk_context *ctx); + +/** + * # # nk_window_get_height + * \returns the height of the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * float nk_window_get_height(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns the current window height + + */ +NK_API float nk_window_get_height(const struct nk_context* ctx); + +/** + * # # nk_window_get_panel + * \returns the underlying panel which contains all processing state of the current window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * !!! \warning + * Do not keep the returned panel pointer around, it is only valid until `nk_end` + * ```c + * struct nk_panel* nk_window_get_panel(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns a pointer to window internal `nk_panel` state. + + */ +NK_API struct nk_panel* nk_window_get_panel(const struct nk_context* ctx); + +/** + * # # nk_window_get_content_region + * \returns the position and size of the currently visible and non-clipped space + * inside the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * struct nk_rect nk_window_get_content_region(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `nk_rect` struct with screen position and size (no scrollbar offset) + * of the visible space inside the current window + + */ +NK_API struct nk_rect nk_window_get_content_region(const struct nk_context* ctx); + +/** + * # # nk_window_get_content_region_min + * \returns the upper left position of the currently visible and non-clipped + * space inside the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * returns `nk_vec2` struct with upper left screen position (no scrollbar offset) + * of the visible space inside the current window + + */ +NK_API struct nk_vec2 nk_window_get_content_region_min(const struct nk_context *ctx); + +/** + * # # nk_window_get_content_region_max + * \returns the lower right screen position of the currently visible and + * non-clipped space inside the currently processed window. + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `nk_vec2` struct with lower right screen position (no scrollbar offset) + * of the visible space inside the current window + + */ +NK_API struct nk_vec2 nk_window_get_content_region_max(const struct nk_context *ctx); + +/** + * # # nk_window_get_content_region_size + * \returns the size of the currently visible and non-clipped space inside the + * currently processed window + * + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `nk_vec2` struct with size the visible space inside the current window + + */ +NK_API struct nk_vec2 nk_window_get_content_region_size(const struct nk_context *ctx); + +/** + * # # nk_window_get_canvas + * \returns the draw command buffer. Can be used to draw custom widgets + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * !!! \warning + * Do not keep the returned command buffer pointer around it is only valid until `nk_end` + * + * ```c + * struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns a pointer to window internal `nk_command_buffer` struct used as + * drawing canvas. Can be used to do custom drawing. + */ +NK_API struct nk_command_buffer* nk_window_get_canvas(const struct nk_context* ctx); + +/** + * # # nk_window_get_scroll + * Gets the scroll offset for the current window + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * void nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); + * ``` + * + * Parameter | Description + * -------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] offset_x | A pointer to the x offset output (or NULL to ignore) + * \param[in] offset_y | A pointer to the y offset output (or NULL to ignore) + + */ +NK_API void nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); + +/** + * # # nk_window_has_focus + * \returns if the currently processed window is currently active + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * nk_bool nk_window_has_focus(const struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `false(0)` if current window is not active or `true(1)` if it is + + */ +NK_API nk_bool nk_window_has_focus(const struct nk_context *ctx); + +/** + * # # nk_window_is_hovered + * Return if the current window is being hovered + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * ```c + * nk_bool nk_window_is_hovered(struct nk_context *ctx); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `true(1)` if current window is hovered or `false(0)` otherwise + + */ +NK_API nk_bool nk_window_is_hovered(const struct nk_context *ctx); + +/** + * # # nk_window_is_collapsed + * \returns if the window with given name is currently minimized/collapsed + * ```c + * nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of window you want to check if it is collapsed + * + * \returns `true(1)` if current window is minimized and `false(0)` if window not + * found or is not minimized + + */ +NK_API nk_bool nk_window_is_collapsed(const struct nk_context *ctx, const char *name); + +/** + * # # nk_window_is_closed + * \returns if the window with given name was closed by calling `nk_close` + * ```c + * nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of window you want to check if it is closed + * + * \returns `true(1)` if current window was closed or `false(0)` window not found or not closed + + */ +NK_API nk_bool nk_window_is_closed(const struct nk_context *ctx, const char* name); + +/** + * # # nk_window_is_hidden + * \returns if the window with given name is hidden + * ```c + * nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of window you want to check if it is hidden + * + * \returns `true(1)` if current window is hidden or `false(0)` window not found or visible + + */ +NK_API nk_bool nk_window_is_hidden(const struct nk_context *ctx, const char* name); + +/** + * # # nk_window_is_active + * Same as nk_window_has_focus for some reason + * ```c + * nk_bool nk_window_is_active(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of window you want to check if it is active + * + * \returns `true(1)` if current window is active or `false(0)` window not found or not active + */ +NK_API nk_bool nk_window_is_active(const struct nk_context *ctx, const char* name); + +/** + * # # nk_window_is_any_hovered + * \returns if the any window is being hovered + * ```c + * nk_bool nk_window_is_any_hovered(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `true(1)` if any window is hovered or `false(0)` otherwise + */ +NK_API nk_bool nk_window_is_any_hovered(const struct nk_context *ctx); + +/** + * # # nk_item_is_any_active + * \returns if the any window is being hovered or any widget is currently active. + * Can be used to decide if input should be processed by UI or your specific input handling. + * Example could be UI and 3D camera to move inside a 3D space. + * ```c + * nk_bool nk_item_is_any_active(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * + * \returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise + + */ +NK_API nk_bool nk_item_is_any_active(const struct nk_context *ctx); + +/** + * # # nk_window_set_bounds + * Updates position and size of window with passed in name + * ```c + * void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to modify both position and size + * \param[in] bounds | Must point to a `nk_rect` struct with the new position and size + + */ +NK_API void nk_window_set_bounds(struct nk_context *ctx, const char *name, struct nk_rect bounds); + +/** + * # # nk_window_set_position + * Updates position of window with passed name + * ```c + * void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to modify both position + * \param[in] pos | Must point to a `nk_vec2` struct with the new position + + */ +NK_API void nk_window_set_position(struct nk_context *ctx, const char *name, struct nk_vec2 pos); + +/** + * # # nk_window_set_size + * Updates size of window with passed in name + * ```c + * void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to modify both window size + * \param[in] size | Must point to a `nk_vec2` struct with new window size + + */ +NK_API void nk_window_set_size(struct nk_context *ctx, const char *name, struct nk_vec2 size); + +/** + * # # nk_window_set_focus + * Sets the window with given name as active + * ```c + * void nk_window_set_focus(struct nk_context*, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to set focus on + + */ +NK_API void nk_window_set_focus(struct nk_context *ctx, const char *name); + +/** + * # # nk_window_set_scroll + * Sets the scroll offset for the current window + * !!! \warning + * Only call this function between calls `nk_begin_xxx` and `nk_end` + * + * ```c + * void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y); + * ``` + * + * Parameter | Description + * -------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] offset_x | The x offset to scroll to + * \param[in] offset_y | The y offset to scroll to + + */ +NK_API void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y); + +/** + * # # nk_window_close + * Closes a window and marks it for being freed at the end of the frame + * ```c + * void nk_window_close(struct nk_context *ctx, const char *name); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to close + + */ NK_API void nk_window_close(struct nk_context *ctx, const char *name); -/*/// #### nk_window_collapse -/// Updates collapse state of a window with given name -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to close -/// __state__ | value out of nk_collapse_states section -*/ -NK_API void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); -/*/// #### nk_window_collapse_if -/// Updates collapse state of a window with given name if given condition is met -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to either collapse or maximize -/// __state__ | value out of nk_collapse_states section the window should be put into -/// __cond__ | condition that has to be met to actually commit the collapse state change -*/ -NK_API void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); -/*/// #### nk_window_show -/// updates visibility state of a window with given name -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to either collapse or maximize -/// __state__ | state with either visible or hidden to modify the window with -*/ -NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); -/*/// #### nk_window_show_if -/// Updates visibility state of a window with given name if a given condition is met -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __name__ | Identifier of the window to either hide or show -/// __state__ | state with either visible or hidden to modify the window with -/// __cond__ | condition that has to be met to actually commit the visbility state change -*/ -NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); -/*/// #### nk_window_show_if -/// Line for visual seperation. Draws a line with thickness determined by the current row height. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ----------------|------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __color__ | Color of the horizontal line -/// __rounding__ | Whether or not to make the line round -*/ + +/** + * # # nk_window_collapse + * Updates collapse state of a window with given name + * ```c + * void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to close + * \param[in] state | value out of nk_collapse_states section + + */ +NK_API void nk_window_collapse(struct nk_context *ctx, const char *name, enum nk_collapse_states state); + +/** + * # # nk_window_collapse_if + * Updates collapse state of a window with given name if given condition is met + * ```c + * void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to either collapse or maximize + * \param[in] state | value out of nk_collapse_states section the window should be put into + * \param[in] cond | condition that has to be met to actually commit the collapse state change + + */ +NK_API void nk_window_collapse_if(struct nk_context *ctx, const char *name, enum nk_collapse_states state, int cond); + +/** + * # # nk_window_show + * updates visibility state of a window with given name + * ```c + * void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to either collapse or maximize + * \param[in] state | state with either visible or hidden to modify the window with + */ +NK_API void nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states state); + +/** + * # # nk_window_show_if + * Updates visibility state of a window with given name if a given condition is met + * ```c + * void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] name | Identifier of the window to either hide or show + * \param[in] state | state with either visible or hidden to modify the window with + * \param[in] cond | condition that has to be met to actually commit the visibility state change + + */ +NK_API void nk_window_show_if(struct nk_context *ctx, const char *name, enum nk_show_states state, int cond); + +/** + * # # nk_window_show_if + * Line for visual separation. Draws a line with thickness determined by the current row height. + * ```c + * void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, NK_BOOL rounding) + * ``` + * + * Parameter | Description + * ----------------|------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] color | Color of the horizontal line + * \param[in] rounding | Whether or not to make the line round + */ NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk_bool rounding); + /* ============================================================================= * * LAYOUT * - * ============================================================================= -/// ### Layouting -/// Layouting in general describes placing widget inside a window with position and size. -/// While in this particular implementation there are five different APIs for layouting -/// each with different trade offs between control and ease of use.

-/// -/// All layouting methods in this library are based around the concept of a row. -/// A row has a height the window content grows by and a number of columns and each -/// layouting method specifies how each widget is placed inside the row. -/// After a row has been allocated by calling a layouting functions and then -/// filled with widgets will advance an internal pointer over the allocated row.

-/// -/// To actually define a layout you just call the appropriate layouting function -/// and each subsequent widget call will place the widget as specified. Important -/// here is that if you define more widgets then columns defined inside the layout -/// functions it will allocate the next row without you having to make another layouting

-/// call. -/// -/// Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API -/// is that you have to define the row height for each. However the row height -/// often depends on the height of the font.

-/// -/// To fix that internally nuklear uses a minimum row height that is set to the -/// height plus padding of currently active font and overwrites the row height -/// value if zero.

-/// -/// If you manually want to change the minimum row height then -/// use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to -/// reset it back to be derived from font height.

-/// -/// Also if you change the font in nuklear it will automatically change the minimum -/// row height for you and. This means if you change the font but still want -/// a minimum row height smaller than the font you have to repush your value.

-/// -/// For actually more advanced UI I would even recommend using the `nk_layout_space_xxx` -/// layouting method in combination with a cassowary constraint solver (there are -/// some versions on github with permissive license model) to take over all control over widget -/// layouting yourself. However for quick and dirty layouting using all the other layouting -/// functions should be fine. -/// -/// #### Usage -/// 1. __nk_layout_row_dynamic__

-/// The easiest layouting function is `nk_layout_row_dynamic`. It provides each -/// widgets with same horizontal space inside the row and dynamically grows -/// if the owning window grows in width. So the number of columns dictates -/// the size of each widget dynamically by formula: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// widget_width = (window_width - padding - spacing) * (1/colum_count) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Just like all other layouting APIs if you define more widget than columns this -/// library will allocate a new row and keep all layouting parameters previously -/// defined. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // first row with height: 30 composed of two widgets -/// nk_layout_row_dynamic(&ctx, 30, 2); -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // second row with same parameter as defined above -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // third row uses 0 for height which will use auto layouting -/// nk_layout_row_dynamic(&ctx, 0, 2); -/// nk_widget(...); -/// nk_widget(...); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// 2. __nk_layout_row_static__

-/// Another easy layouting function is `nk_layout_row_static`. It provides each -/// widget with same horizontal pixel width inside the row and does not grow -/// if the owning window scales smaller or bigger. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // first row with height: 30 composed of two widgets with width: 80 -/// nk_layout_row_static(&ctx, 30, 80, 2); -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // second row with same parameter as defined above -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // third row uses 0 for height which will use auto layouting -/// nk_layout_row_static(&ctx, 0, 80, 2); -/// nk_widget(...); -/// nk_widget(...); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// 3. __nk_layout_row_xxx__

-/// A little bit more advanced layouting API are functions `nk_layout_row_begin`, -/// `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly -/// specify each column pixel or window ratio in a row. It supports either -/// directly setting per column pixel width or widget window ratio but not -/// both. Furthermore it is a immediate mode API so each value is directly -/// pushed before calling a widget. Therefore the layout is not automatically -/// repeating like the last two layouting functions. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // first row with height: 25 composed of two widgets with width 60 and 40 -/// nk_layout_row_begin(ctx, NK_STATIC, 25, 2); -/// nk_layout_row_push(ctx, 60); -/// nk_widget(...); -/// nk_layout_row_push(ctx, 40); -/// nk_widget(...); -/// nk_layout_row_end(ctx); -/// // -/// // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75 -/// nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2); -/// nk_layout_row_push(ctx, 0.25f); -/// nk_widget(...); -/// nk_layout_row_push(ctx, 0.75f); -/// nk_widget(...); -/// nk_layout_row_end(ctx); -/// // -/// // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75 -/// nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2); -/// nk_layout_row_push(ctx, 0.25f); -/// nk_widget(...); -/// nk_layout_row_push(ctx, 0.75f); -/// nk_widget(...); -/// nk_layout_row_end(ctx); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// 4. __nk_layout_row__

-/// The array counterpart to API nk_layout_row_xxx is the single nk_layout_row -/// functions. Instead of pushing either pixel or window ratio for every widget -/// it allows to define it by array. The trade of for less control is that -/// `nk_layout_row` is automatically repeating. Otherwise the behavior is the -/// same. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // two rows with height: 30 composed of two widgets with width 60 and 40 -/// const float ratio[] = {60,40}; -/// nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75 -/// const float ratio[] = {0.25, 0.75}; -/// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// // -/// // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75 -/// const float ratio[] = {0.25, 0.75}; -/// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// 5. __nk_layout_row_template_xxx__

-/// The most complex and second most flexible API is a simplified flexbox version without -/// line wrapping and weights for dynamic widgets. It is an immediate mode API but -/// unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called -/// before calling the templated widgets. -/// The row template layout has three different per widget size specifier. The first -/// one is the `nk_layout_row_template_push_static` with fixed widget pixel width. -/// They do not grow if the row grows and will always stay the same. -/// The second size specifier is `nk_layout_row_template_push_variable` -/// which defines a minimum widget size but it also can grow if more space is available -/// not taken by other widgets. -/// Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic` -/// which are completely flexible and unlike variable widgets can even shrink -/// to zero if not enough space is provided. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // two rows with height: 30 composed of three widgets -/// nk_layout_row_template_begin(ctx, 30); -/// nk_layout_row_template_push_dynamic(ctx); -/// nk_layout_row_template_push_variable(ctx, 80); -/// nk_layout_row_template_push_static(ctx, 80); -/// nk_layout_row_template_end(ctx); -/// // -/// // first row -/// nk_widget(...); // dynamic widget can go to zero if not enough space -/// nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space -/// nk_widget(...); // static widget with fixed 80 pixel width -/// // -/// // second row same layout -/// nk_widget(...); -/// nk_widget(...); -/// nk_widget(...); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// 6. __nk_layout_space_xxx__

-/// Finally the most flexible API directly allows you to place widgets inside the -/// window. The space layout API is an immediate mode API which does not support -/// row auto repeat and directly sets position and size of a widget. Position -/// and size hereby can be either specified as ratio of allocated space or -/// allocated space local position and pixel size. Since this API is quite -/// powerful there are a number of utility functions to get the available space -/// and convert between local allocated space and screen space. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_begin_xxx(...) { -/// // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) -/// nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX); -/// nk_layout_space_push(ctx, nk_rect(0,0,150,200)); -/// nk_widget(...); -/// nk_layout_space_push(ctx, nk_rect(200,200,100,200)); -/// nk_widget(...); -/// nk_layout_space_end(ctx); -/// // -/// // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) -/// nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX); -/// nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1)); -/// nk_widget(...); -/// nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1)); -/// nk_widget(...); -/// } -/// nk_end(...); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// ----------------------------------------|------------------------------------ -/// nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value -/// nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height -/// nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window -/// nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size -// -/// nk_layout_row_dynamic | Current layout is divided into n same sized growing columns -/// nk_layout_row_static | Current layout is divided into n same fixed sized columns -/// nk_layout_row_begin | Starts a new row with given height and number of columns -/// nk_layout_row_push | Pushes another column with given size or window ratio -/// nk_layout_row_end | Finished previously started row -/// nk_layout_row | Specifies row columns in array as either window ratio or size -// -/// nk_layout_row_template_begin | Begins the row template declaration -/// nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space -/// nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width -/// nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size -/// nk_layout_row_template_end | Marks the end of the row template -// -/// nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size -/// nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio -/// nk_layout_space_end | Marks the end of the layouting space -// -/// nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated -/// nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space -/// nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates -/// nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space -/// nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates -*/ + * =============================================================================*/ +/** + * \page Layouting + * Layouting in general describes placing widget inside a window with position and size. + * While in this particular implementation there are five different APIs for layouting + * each with different trade offs between control and ease of use.

+ * + * All layouting methods in this library are based around the concept of a row. + * A row has a height the window content grows by and a number of columns and each + * layouting method specifies how each widget is placed inside the row. + * After a row has been allocated by calling a layouting functions and then + * filled with widgets will advance an internal pointer over the allocated row.

+ * + * To actually define a layout you just call the appropriate layouting function + * and each subsequent widget call will place the widget as specified. Important + * here is that if you define more widgets then columns defined inside the layout + * functions it will allocate the next row without you having to make another layouting

+ * call. + * + * Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API + * is that you have to define the row height for each. However the row height + * often depends on the height of the font.

+ * + * To fix that internally nuklear uses a minimum row height that is set to the + * height plus padding of currently active font and overwrites the row height + * value if zero.

+ * + * If you manually want to change the minimum row height then + * use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to + * reset it back to be derived from font height.

+ * + * Also if you change the font in nuklear it will automatically change the minimum + * row height for you and. This means if you change the font but still want + * a minimum row height smaller than the font you have to repush your value.

+ * + * For actually more advanced UI I would even recommend using the `nk_layout_space_xxx` + * layouting method in combination with a cassowary constraint solver (there are + * some versions on github with permissive license model) to take over all control over widget + * layouting yourself. However for quick and dirty layouting using all the other layouting + * functions should be fine. + * + * # Usage + * 1. __nk_layout_row_dynamic__

+ * The easiest layouting function is `nk_layout_row_dynamic`. It provides each + * widgets with same horizontal space inside the row and dynamically grows + * if the owning window grows in width. So the number of columns dictates + * the size of each widget dynamically by formula: + * + * ```c + * widget_width = (window_width - padding - spacing) * (1/column_count) + * ``` + * + * Just like all other layouting APIs if you define more widget than columns this + * library will allocate a new row and keep all layouting parameters previously + * defined. + * + * ```c + * if (nk_begin_xxx(...) { + * // first row with height: 30 composed of two widgets + * nk_layout_row_dynamic(&ctx, 30, 2); + * nk_widget(...); + * nk_widget(...); + * // + * // second row with same parameter as defined above + * nk_widget(...); + * nk_widget(...); + * // + * // third row uses 0 for height which will use auto layouting + * nk_layout_row_dynamic(&ctx, 0, 2); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * ``` + * + * 2. __nk_layout_row_static__

+ * Another easy layouting function is `nk_layout_row_static`. It provides each + * widget with same horizontal pixel width inside the row and does not grow + * if the owning window scales smaller or bigger. + * + * ```c + * if (nk_begin_xxx(...) { + * // first row with height: 30 composed of two widgets with width: 80 + * nk_layout_row_static(&ctx, 30, 80, 2); + * nk_widget(...); + * nk_widget(...); + * // + * // second row with same parameter as defined above + * nk_widget(...); + * nk_widget(...); + * // + * // third row uses 0 for height which will use auto layouting + * nk_layout_row_static(&ctx, 0, 80, 2); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * ``` + * + * 3. __nk_layout_row_xxx__

+ * A little bit more advanced layouting API are functions `nk_layout_row_begin`, + * `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly + * specify each column pixel or window ratio in a row. It supports either + * directly setting per column pixel width or widget window ratio but not + * both. Furthermore it is a immediate mode API so each value is directly + * pushed before calling a widget. Therefore the layout is not automatically + * repeating like the last two layouting functions. + * + * ```c + * if (nk_begin_xxx(...) { + * // first row with height: 25 composed of two widgets with width 60 and 40 + * nk_layout_row_begin(ctx, NK_STATIC, 25, 2); + * nk_layout_row_push(ctx, 60); + * nk_widget(...); + * nk_layout_row_push(ctx, 40); + * nk_widget(...); + * nk_layout_row_end(ctx); + * // + * // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75 + * nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2); + * nk_layout_row_push(ctx, 0.25f); + * nk_widget(...); + * nk_layout_row_push(ctx, 0.75f); + * nk_widget(...); + * nk_layout_row_end(ctx); + * // + * // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75 + * nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2); + * nk_layout_row_push(ctx, 0.25f); + * nk_widget(...); + * nk_layout_row_push(ctx, 0.75f); + * nk_widget(...); + * nk_layout_row_end(ctx); + * } + * nk_end(...); + * ``` + * + * 4. __nk_layout_row__

+ * The array counterpart to API nk_layout_row_xxx is the single nk_layout_row + * functions. Instead of pushing either pixel or window ratio for every widget + * it allows to define it by array. The trade of for less control is that + * `nk_layout_row` is automatically repeating. Otherwise the behavior is the + * same. + * + * ```c + * if (nk_begin_xxx(...) { + * // two rows with height: 30 composed of two widgets with width 60 and 40 + * const float ratio[] = {60,40}; + * nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * // + * // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75 + * const float ratio[] = {0.25, 0.75}; + * nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * // + * // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75 + * const float ratio[] = {0.25, 0.75}; + * nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * ``` + * + * 5. __nk_layout_row_template_xxx__

+ * The most complex and second most flexible API is a simplified flexbox version without + * line wrapping and weights for dynamic widgets. It is an immediate mode API but + * unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called + * before calling the templated widgets. + * The row template layout has three different per widget size specifier. The first + * one is the `nk_layout_row_template_push_static` with fixed widget pixel width. + * They do not grow if the row grows and will always stay the same. + * The second size specifier is `nk_layout_row_template_push_variable` + * which defines a minimum widget size but it also can grow if more space is available + * not taken by other widgets. + * Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic` + * which are completely flexible and unlike variable widgets can even shrink + * to zero if not enough space is provided. + * + * ```c + * if (nk_begin_xxx(...) { + * // two rows with height: 30 composed of three widgets + * nk_layout_row_template_begin(ctx, 30); + * nk_layout_row_template_push_dynamic(ctx); + * nk_layout_row_template_push_variable(ctx, 80); + * nk_layout_row_template_push_static(ctx, 80); + * nk_layout_row_template_end(ctx); + * // + * // first row + * nk_widget(...); // dynamic widget can go to zero if not enough space + * nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space + * nk_widget(...); // static widget with fixed 80 pixel width + * // + * // second row same layout + * nk_widget(...); + * nk_widget(...); + * nk_widget(...); + * } + * nk_end(...); + * ``` + * + * 6. __nk_layout_space_xxx__

+ * Finally the most flexible API directly allows you to place widgets inside the + * window. The space layout API is an immediate mode API which does not support + * row auto repeat and directly sets position and size of a widget. Position + * and size hereby can be either specified as ratio of allocated space or + * allocated space local position and pixel size. Since this API is quite + * powerful there are a number of utility functions to get the available space + * and convert between local allocated space and screen space. + * + * ```c + * if (nk_begin_xxx(...) { + * // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) + * nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX); + * nk_layout_space_push(ctx, nk_rect(0,0,150,200)); + * nk_widget(...); + * nk_layout_space_push(ctx, nk_rect(200,200,100,200)); + * nk_widget(...); + * nk_layout_space_end(ctx); + * // + * // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) + * nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX); + * nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1)); + * nk_widget(...); + * nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1)); + * nk_widget(...); + * } + * nk_end(...); + * ``` + * + * # Reference + * Function | Description + * ---------------------------------------------|------------------------------------ + * \ref nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value + * \ref nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height + * \ref nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window + * \ref nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size + * \ref nk_layout_row_dynamic | Current layout is divided into n same sized growing columns + * \ref nk_layout_row_static | Current layout is divided into n same fixed sized columns + * \ref nk_layout_row_begin | Starts a new row with given height and number of columns + * \ref nk_layout_row_push | Pushes another column with given size or window ratio + * \ref nk_layout_row_end | Finished previously started row + * \ref nk_layout_row | Specifies row columns in array as either window ratio or size + * \ref nk_layout_row_template_begin | Begins the row template declaration + * \ref nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space + * \ref nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width + * \ref nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size + * \ref nk_layout_row_template_end | Marks the end of the row template + * \ref nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size + * \ref nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio + * \ref nk_layout_space_end | Marks the end of the layouting space + * \ref nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated + * \ref nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space + * \ref nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates + * \ref nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space + * \ref nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates + */ + + enum nk_widget_align { NK_WIDGET_ALIGN_LEFT = 0x01, @@ -2305,773 +2439,838 @@ enum nk_widget_alignment { NK_WIDGET_RIGHT = NK_WIDGET_ALIGN_MIDDLE|NK_WIDGET_ALIGN_RIGHT }; -/*/// #### nk_layout_set_min_row_height -/// Sets the currently used minimum row height. -/// !!! WARNING -/// The passed height needs to include both your preferred row height -/// as well as padding. No internal padding is added. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_set_min_row_height(struct nk_context*, float height); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __height__ | New minimum row height to be used for auto generating the row height -*/ +/** + * Sets the currently used minimum row height. + * !!! \warning + * The passed height needs to include both your preferred row height + * as well as padding. No internal padding is added. + * + * ```c + * void nk_layout_set_min_row_height(struct nk_context*, float height); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] height | New minimum row height to be used for auto generating the row height + */ NK_API void nk_layout_set_min_row_height(struct nk_context*, float height); -/*/// #### nk_layout_reset_min_row_height -/// Reset the currently used minimum row height back to `font_height + text_padding + padding` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_reset_min_row_height(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -*/ + +/** + * Reset the currently used minimum row height back to `font_height + text_padding + padding` + * ```c + * void nk_layout_reset_min_row_height(struct nk_context*); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + */ NK_API void nk_layout_reset_min_row_height(struct nk_context*); -/*/// #### nk_layout_widget_bounds -/// Returns the width of the next row allocate by one of the layouting functions -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_layout_widget_bounds(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// -/// Return `nk_rect` with both position and size of the next row -*/ -NK_API struct nk_rect nk_layout_widget_bounds(struct nk_context*); -/*/// #### nk_layout_ratio_from_pixel -/// Utility functions to calculate window ratio from pixel size -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __pixel__ | Pixel_width to convert to window ratio -/// -/// Returns `nk_rect` with both position and size of the next row -*/ -NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); -/*/// #### nk_layout_row_dynamic -/// Sets current row layout to share horizontal space -/// between @cols number of widgets evenly. Once called all subsequent widget -/// calls greater than @cols will allocate a new row with same layout. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __height__ | Holds height of each widget in row or zero for auto layouting -/// __columns__ | Number of widget inside row -*/ + +/** + * \brief Returns the width of the next row allocate by one of the layouting functions + * + * \details + * ```c + * struct nk_rect nk_layout_widget_bounds(struct nk_context*); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * + * \return `nk_rect` with both position and size of the next row + */ +NK_API struct nk_rect nk_layout_widget_bounds(const struct nk_context *ctx); + +/** + * \brief Utility functions to calculate window ratio from pixel size + * + * \details + * ```c + * float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] pixel | Pixel_width to convert to window ratio + * + * \returns `nk_rect` with both position and size of the next row + */ +NK_API float nk_layout_ratio_from_pixel(const struct nk_context *ctx, float pixel_width); + +/** + * \brief Sets current row layout to share horizontal space + * between @cols number of widgets evenly. Once called all subsequent widget + * calls greater than @cols will allocate a new row with same layout. + * + * \details + * ```c + * void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] height | Holds height of each widget in row or zero for auto layouting + * \param[in] columns | Number of widget inside row + */ NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); -/*/// #### nk_layout_row_static -/// Sets current row layout to fill @cols number of widgets -/// in row with same @item_width horizontal size. Once called all subsequent widget -/// calls greater than @cols will allocate a new row with same layout. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __height__ | Holds height of each widget in row or zero for auto layouting -/// __width__ | Holds pixel width of each widget in the row -/// __columns__ | Number of widget inside row -*/ + +/** + * \brief Sets current row layout to fill @cols number of widgets + * in row with same @item_width horizontal size. Once called all subsequent widget + * calls greater than @cols will allocate a new row with same layout. + * + * \details + * ```c + * void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] height | Holds height of each widget in row or zero for auto layouting + * \param[in] width | Holds pixel width of each widget in the row + * \param[in] columns | Number of widget inside row + */ NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); -/*/// #### nk_layout_row_begin -/// Starts a new dynamic or fixed row with given height and columns. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __fmt__ | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns -/// __height__ | holds height of each widget in row or zero for auto layouting -/// __columns__ | Number of widget inside row -*/ + +/** + * \brief Starts a new dynamic or fixed row with given height and columns. + * + * \details + * ```c + * void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] fmt | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * \param[in] height | holds height of each widget in row or zero for auto layouting + * \param[in] columns | Number of widget inside row + */ NK_API void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); -/*/// #### nk_layout_row_push -/// Specifies either window ratio or width of a single column -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_push(struct nk_context*, float value); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __value__ | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call -*/ + +/** + * \breif Specifies either window ratio or width of a single column + * + * \details + * ```c + * void nk_layout_row_push(struct nk_context*, float value); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] value | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call + */ NK_API void nk_layout_row_push(struct nk_context*, float value); -/*/// #### nk_layout_row_end -/// Finished previously started row -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_end(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -*/ + +/** + * \brief Finished previously started row + * + * \details + * ```c + * void nk_layout_row_end(struct nk_context*); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + */ NK_API void nk_layout_row_end(struct nk_context*); -/*/// #### nk_layout_row -/// Specifies row columns in array as either window ratio or size -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns -/// __height__ | Holds height of each widget in row or zero for auto layouting -/// __columns__ | Number of widget inside row -*/ + +/** + * \brief Specifies row columns in array as either window ratio or size + * + * \details + * ```c + * void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); + * ``` + * + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] fmt | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * \param[in] height | Holds height of each widget in row or zero for auto layouting + * \param[in] columns | Number of widget inside row + */ NK_API void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); -/*/// #### nk_layout_row_template_begin -/// Begins the row template declaration -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_template_begin(struct nk_context*, float row_height); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __height__ | Holds height of each widget in row or zero for auto layouting -*/ + +/** + * # # nk_layout_row_template_begin + * Begins the row template declaration + * ```c + * void nk_layout_row_template_begin(struct nk_context*, float row_height); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] height | Holds height of each widget in row or zero for auto layouting + */ NK_API void nk_layout_row_template_begin(struct nk_context*, float row_height); -/*/// #### nk_layout_row_template_push_dynamic -/// Adds a dynamic column that dynamically grows and can go to zero if not enough space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_template_push_dynamic(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __height__ | Holds height of each widget in row or zero for auto layouting -*/ + +/** + * # # nk_layout_row_template_push_dynamic + * Adds a dynamic column that dynamically grows and can go to zero if not enough space + * ```c + * void nk_layout_row_template_push_dynamic(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] height | Holds height of each widget in row or zero for auto layouting + */ NK_API void nk_layout_row_template_push_dynamic(struct nk_context*); -/*/// #### nk_layout_row_template_push_variable -/// Adds a variable column that dynamically grows but does not shrink below specified pixel width -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_template_push_variable(struct nk_context*, float min_width); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __width__ | Holds the minimum pixel width the next column must always be -*/ + +/** + * # # nk_layout_row_template_push_variable + * Adds a variable column that dynamically grows but does not shrink below specified pixel width + * ```c + * void nk_layout_row_template_push_variable(struct nk_context*, float min_width); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] width | Holds the minimum pixel width the next column must always be + */ NK_API void nk_layout_row_template_push_variable(struct nk_context*, float min_width); -/*/// #### nk_layout_row_template_push_static -/// Adds a static column that does not grow and will always have the same size -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_template_push_static(struct nk_context*, float width); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __width__ | Holds the absolute pixel width value the next column must be -*/ + +/** + * # # nk_layout_row_template_push_static + * Adds a static column that does not grow and will always have the same size + * ```c + * void nk_layout_row_template_push_static(struct nk_context*, float width); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] width | Holds the absolute pixel width value the next column must be + */ NK_API void nk_layout_row_template_push_static(struct nk_context*, float width); -/*/// #### nk_layout_row_template_end -/// Marks the end of the row template -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_row_template_end(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -*/ + +/** + * # # nk_layout_row_template_end + * Marks the end of the row template + * ```c + * void nk_layout_row_template_end(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + */ NK_API void nk_layout_row_template_end(struct nk_context*); -/*/// #### nk_layout_space_begin -/// Begins a new layouting space that allows to specify each widgets position and size. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` -/// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns -/// __height__ | Holds height of each widget in row or zero for auto layouting -/// __columns__ | Number of widgets inside row -*/ + +/** + * # # nk_layout_space_begin + * Begins a new layouting space that allows to specify each widgets position and size. + * ```c + * void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` + * \param[in] fmt | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns + * \param[in] height | Holds height of each widget in row or zero for auto layouting + * \param[in] columns | Number of widgets inside row + */ NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); -/*/// #### nk_layout_space_push -/// Pushes position and size of the next widget in own coordinate space either as pixel or ratio -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// __bounds__ | Position and size in laoyut space local coordinates -*/ + +/** + * # # nk_layout_space_push + * Pushes position and size of the next widget in own coordinate space either as pixel or ratio + * ```c + * void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * \param[in] bounds | Position and size in laoyut space local coordinates + */ NK_API void nk_layout_space_push(struct nk_context*, struct nk_rect bounds); -/*/// #### nk_layout_space_end -/// Marks the end of the layout space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_layout_space_end(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -*/ + +/** + * # # nk_layout_space_end + * Marks the end of the layout space + * ```c + * void nk_layout_space_end(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + */ NK_API void nk_layout_space_end(struct nk_context*); -/*/// #### nk_layout_space_bounds -/// Utility function to calculate total space allocated for `nk_layout_space` -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_layout_space_bounds(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// -/// Returns `nk_rect` holding the total space allocated -*/ -NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); -/*/// #### nk_layout_space_to_screen -/// Converts vector from nk_layout_space coordinate space into screen space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// __vec__ | Position to convert from layout space into screen coordinate space -/// -/// Returns transformed `nk_vec2` in screen space coordinates -*/ -NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); -/*/// #### nk_layout_space_to_local -/// Converts vector from layout space into screen space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// __vec__ | Position to convert from screen space into layout coordinate space -/// -/// Returns transformed `nk_vec2` in layout space coordinates -*/ -NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); -/*/// #### nk_layout_space_rect_to_screen -/// Converts rectangle from screen space into layout space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// __bounds__ | Rectangle to convert from layout space into screen space -/// -/// Returns transformed `nk_rect` in screen space coordinates -*/ -NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); -/*/// #### nk_layout_space_rect_to_local -/// Converts rectangle from layout space into screen space -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// __bounds__ | Rectangle to convert from layout space into screen space -/// -/// Returns transformed `nk_rect` in layout space coordinates -*/ -NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); -/*/// #### nk_spacer -/// Spacer is a dummy widget that consumes space as usual but doesn't draw anything -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_spacer(struct nk_context* ); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` -/// -*/ -NK_API void nk_spacer(struct nk_context* ); +/** + * # # nk_layout_space_bounds + * Utility function to calculate total space allocated for `nk_layout_space` + * ```c + * struct nk_rect nk_layout_space_bounds(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * + * \returns `nk_rect` holding the total space allocated + */ +NK_API struct nk_rect nk_layout_space_bounds(const struct nk_context *ctx); + +/** + * # # nk_layout_space_to_screen + * Converts vector from nk_layout_space coordinate space into screen space + * ```c + * struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * \param[in] vec | Position to convert from layout space into screen coordinate space + * + * \returns transformed `nk_vec2` in screen space coordinates + */ +NK_API struct nk_vec2 nk_layout_space_to_screen(const struct nk_context* ctx, struct nk_vec2 vec); + +/** + * # # nk_layout_space_to_local + * Converts vector from layout space into screen space + * ```c + * struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * \param[in] vec | Position to convert from screen space into layout coordinate space + * + * \returns transformed `nk_vec2` in layout space coordinates + */ +NK_API struct nk_vec2 nk_layout_space_to_local(const struct nk_context *ctx, struct nk_vec2 vec); + +/** + * # # nk_layout_space_rect_to_screen + * Converts rectangle from screen space into layout space + * ```c + * struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * \param[in] bounds | Rectangle to convert from layout space into screen space + * + * \returns transformed `nk_rect` in screen space coordinates + */ +NK_API struct nk_rect nk_layout_space_rect_to_screen(const struct nk_context *ctx, struct nk_rect bounds); + +/** + * # # nk_layout_space_rect_to_local + * Converts rectangle from layout space into screen space + * ```c + * struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * \param[in] bounds | Rectangle to convert from layout space into screen space + * + * \returns transformed `nk_rect` in layout space coordinates + */ +NK_API struct nk_rect nk_layout_space_rect_to_local(const struct nk_context *ctx, struct nk_rect bounds); + +/** + * # # nk_spacer + * Spacer is a dummy widget that consumes space as usual but doesn't draw anything + * ```c + * void nk_spacer(struct nk_context* ); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` + * + */ +NK_API void nk_spacer(struct nk_context *ctx); + + +/** ============================================================================= + * + * GROUP + * + * =============================================================================*/ +/** + * \page Groups + * Groups are basically windows inside windows. They allow to subdivide space + * in a window to layout widgets as a group. Almost all more complex widget + * layouting requirements can be solved using groups and basic layouting + * fuctionality. Groups just like windows are identified by an unique name and + * internally keep track of scrollbar offsets by default. However additional + * versions are provided to directly manage the scrollbar. + * + * # Usage + * To create a group you have to call one of the three `nk_group_begin_xxx` + * functions to start group declarations and `nk_group_end` at the end. Furthermore it + * is required to check the return value of `nk_group_begin_xxx` and only process + * widgets inside the window if the value is not 0. + * Nesting groups is possible and even encouraged since many layouting schemes + * can only be achieved by nesting. Groups, unlike windows, need `nk_group_end` + * to be only called if the corresponding `nk_group_begin_xxx` call does not return 0: + * + * ```c + * if (nk_group_begin_xxx(ctx, ...) { + * // [... widgets ...] + * nk_group_end(ctx); + * } + * ``` + * + * In the grand concept groups can be called after starting a window + * with `nk_begin_xxx` and before calling `nk_end`: + * + * ```c + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * // Input + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * nk_input_xxx(...); + * } + * } + * nk_input_end(&ctx); + * // + * // Window + * if (nk_begin_xxx(...) { + * // [...widgets...] + * nk_layout_row_dynamic(...); + * if (nk_group_begin_xxx(ctx, ...) { + * //[... widgets ...] + * nk_group_end(ctx); + * } + * } + * nk_end(ctx); + * // + * // Draw + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * // [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * # Reference + * Function | Description + * --------------------------------|------------------------------------------- + * \ref nk_group_begin | Start a new group with internal scrollbar handling + * \ref nk_group_begin_titled | Start a new group with separated name and title and internal scrollbar handling + * \ref nk_group_end | Ends a group. Should only be called if nk_group_begin returned non-zero + * \ref nk_group_scrolled_offset_begin | Start a new group with manual separated handling of scrollbar x- and y-offset + * \ref nk_group_scrolled_begin | Start a new group with manual scrollbar handling + * \ref nk_group_scrolled_end | Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero + * \ref nk_group_get_scroll | Gets the scroll offset for the given group + * \ref nk_group_set_scroll | Sets the scroll offset for the given group + */ + /** + * \brief Starts a new widget group. Requires a previous layouting function to specify a pos/size. + * ```c + * nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] title | Must be an unique identifier for this group that is also used for the group header + * \param[in] flags | Window flags defined in the nk_panel_flags section with a number of different group behaviors + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ +NK_API nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); -/* ============================================================================= + /** + * \brief Starts a new widget group. Requires a previous layouting function to specify a pos/size. + * ```c + * nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); + * ``` * - * GROUP + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] id | Must be an unique identifier for this group + * \param[in] title | Group header title + * \param[in] flags | Window flags defined in the nk_panel_flags section with a number of different group behaviors * - * ============================================================================= -/// ### Groups -/// Groups are basically windows inside windows. They allow to subdivide space -/// in a window to layout widgets as a group. Almost all more complex widget -/// layouting requirements can be solved using groups and basic layouting -/// fuctionality. Groups just like windows are identified by an unique name and -/// internally keep track of scrollbar offsets by default. However additional -/// versions are provided to directly manage the scrollbar. -/// -/// #### Usage -/// To create a group you have to call one of the three `nk_group_begin_xxx` -/// functions to start group declarations and `nk_group_end` at the end. Furthermore it -/// is required to check the return value of `nk_group_begin_xxx` and only process -/// widgets inside the window if the value is not 0. -/// Nesting groups is possible and even encouraged since many layouting schemes -/// can only be achieved by nesting. Groups, unlike windows, need `nk_group_end` -/// to be only called if the corresponding `nk_group_begin_xxx` call does not return 0: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_group_begin_xxx(ctx, ...) { -/// // [... widgets ...] -/// nk_group_end(ctx); -/// } -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// In the grand concept groups can be called after starting a window -/// with `nk_begin_xxx` and before calling `nk_end`: -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// // Input -/// Event evt; -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// nk_input_xxx(...); -/// } -/// } -/// nk_input_end(&ctx); -/// // -/// // Window -/// if (nk_begin_xxx(...) { -/// // [...widgets...] -/// nk_layout_row_dynamic(...); -/// if (nk_group_begin_xxx(ctx, ...) { -/// //[... widgets ...] -/// nk_group_end(ctx); -/// } -/// } -/// nk_end(ctx); -/// // -/// // Draw -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case ...: -/// // [...] -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// #### Reference -/// Function | Description -/// --------------------------------|------------------------------------------- -/// nk_group_begin | Start a new group with internal scrollbar handling -/// nk_group_begin_titled | Start a new group with separated name and title and internal scrollbar handling -/// nk_group_end | Ends a group. Should only be called if nk_group_begin returned non-zero -/// nk_group_scrolled_offset_begin | Start a new group with manual separated handling of scrollbar x- and y-offset -/// nk_group_scrolled_begin | Start a new group with manual scrollbar handling -/// nk_group_scrolled_end | Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero -/// nk_group_get_scroll | Gets the scroll offset for the given group -/// nk_group_set_scroll | Sets the scroll offset for the given group -*/ -/*/// #### nk_group_begin -/// Starts a new widget group. Requires a previous layouting function to specify a pos/size. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __title__ | Must be an unique identifier for this group that is also used for the group header -/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ -NK_API nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); -/*/// #### nk_group_begin_titled -/// Starts a new widget group. Requires a previous layouting function to specify a pos/size. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __id__ | Must be an unique identifier for this group -/// __title__ | Group header title -/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); -/*/// #### nk_group_end -/// Ends a widget group -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_group_end(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -*/ + +/** + * # # nk_group_end + * Ends a widget group + * ```c + * void nk_group_end(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + */ NK_API void nk_group_end(struct nk_context*); -/*/// #### nk_group_scrolled_offset_begin -/// starts a new widget group. requires a previous layouting function to specify -/// a size. Does not keep track of scrollbar. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __x_offset__| Scrollbar x-offset to offset all widgets inside the group horizontally. -/// __y_offset__| Scrollbar y-offset to offset all widgets inside the group vertically -/// __title__ | Window unique group title used to both identify and display in the group header -/// __flags__ | Window flags from the nk_panel_flags section -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_group_scrolled_offset_begin + * starts a new widget group. requires a previous layouting function to specify + * a size. Does not keep track of scrollbar. + * ```c + * nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] x_offset| Scrollbar x-offset to offset all widgets inside the group horizontally. + * \param[in] y_offset| Scrollbar y-offset to offset all widgets inside the group vertically + * \param[in] title | Window unique group title used to both identify and display in the group header + * \param[in] flags | Window flags from the nk_panel_flags section + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); -/*/// #### nk_group_scrolled_begin -/// Starts a new widget group. requires a previous -/// layouting function to specify a size. Does not keep track of scrollbar. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __off__ | Both x- and y- scroll offset. Allows for manual scrollbar control -/// __title__ | Window unique group title used to both identify and display in the group header -/// __flags__ | Window flags from nk_panel_flags section -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_group_scrolled_begin + * Starts a new widget group. requires a previous + * layouting function to specify a size. Does not keep track of scrollbar. + * ```c + * nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] off | Both x- and y- scroll offset. Allows for manual scrollbar control + * \param[in] title | Window unique group title used to both identify and display in the group header + * \param[in] flags | Window flags from nk_panel_flags section + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); -/*/// #### nk_group_scrolled_end -/// Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_group_scrolled_end(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -*/ + +/** + * # # nk_group_scrolled_end + * Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin. + * ```c + * void nk_group_scrolled_end(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + */ NK_API void nk_group_scrolled_end(struct nk_context*); -/*/// #### nk_group_get_scroll -/// Gets the scroll position of the given group. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// -------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __id__ | The id of the group to get the scroll position of -/// __x_offset__ | A pointer to the x offset output (or NULL to ignore) -/// __y_offset__ | A pointer to the y offset output (or NULL to ignore) -*/ + +/** + * # # nk_group_get_scroll + * Gets the scroll position of the given group. + * ```c + * void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); + * ``` + * + * Parameter | Description + * -------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] id | The id of the group to get the scroll position of + * \param[in] x_offset | A pointer to the x offset output (or NULL to ignore) + * \param[in] y_offset | A pointer to the y offset output (or NULL to ignore) + */ NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); -/*/// #### nk_group_set_scroll -/// Sets the scroll position of the given group. -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// -------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __id__ | The id of the group to scroll -/// __x_offset__ | The x offset to scroll to -/// __y_offset__ | The y offset to scroll to -*/ + +/** + * # # nk_group_set_scroll + * Sets the scroll position of the given group. + * ```c + * void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); + * ``` + * + * Parameter | Description + * -------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] id | The id of the group to scroll + * \param[in] x_offset | The x offset to scroll to + * \param[in] y_offset | The y offset to scroll to + */ NK_API void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); -/* ============================================================================= + +/** ============================================================================= * * TREE * - * ============================================================================= -/// ### Tree -/// Trees represent two different concept. First the concept of a collapsible -/// UI section that can be either in a hidden or visible state. They allow the UI -/// user to selectively minimize the current set of visible UI to comprehend. -/// The second concept are tree widgets for visual UI representation of trees.

-/// -/// Trees thereby can be nested for tree representations and multiple nested -/// collapsible UI sections. All trees are started by calling of the -/// `nk_tree_xxx_push_tree` functions and ended by calling one of the -/// `nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label -/// and optionally an image to be displayed and the initial collapse state from -/// the nk_collapse_states section.

-/// -/// The runtime state of the tree is either stored outside the library by the caller -/// or inside which requires a unique ID. The unique ID can either be generated -/// automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`, -/// by `__FILE__` and a user provided ID generated for example by loop index with -/// function `nk_tree_push_id` or completely provided from outside by user with -/// function `nk_tree_push_hashed`. -/// -/// #### Usage -/// To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx` -/// functions to start a collapsible UI section and `nk_tree_xxx_pop` to mark the -/// end. -/// Each starting function will either return `false(0)` if the tree is collapsed -/// or hidden and therefore does not need to be filled with content or `true(1)` -/// if visible and required to be filled. -/// -/// !!! Note -/// The tree header does not require and layouting function and instead -/// calculates a auto height based on the currently used font size -/// -/// The tree ending functions only need to be called if the tree content is -/// actually visible. So make sure the tree push function is guarded by `if` -/// and the pop call is only taken if the tree is visible. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) { -/// nk_layout_row_dynamic(...); -/// nk_widget(...); -/// nk_tree_pop(ctx); -/// } -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// ----------------------------|------------------------------------------- -/// nk_tree_push | Start a collapsible UI section with internal state management -/// nk_tree_push_id | Start a collapsible UI section with internal state management callable in a look -/// nk_tree_push_hashed | Start a collapsible UI section with internal state management with full control over internal unique ID use to store state -/// nk_tree_image_push | Start a collapsible UI section with image and label header -/// nk_tree_image_push_id | Start a collapsible UI section with image and label header and internal state management callable in a look -/// nk_tree_image_push_hashed | Start a collapsible UI section with image and label header and internal state management with full control over internal unique ID use to store state -/// nk_tree_pop | Ends a collapsible UI section -// -/// nk_tree_state_push | Start a collapsible UI section with external state management -/// nk_tree_state_image_push | Start a collapsible UI section with image and label header and external state management -/// nk_tree_state_pop | Ends a collapsabale UI section -/// -/// #### nk_tree_type -/// Flag | Description -/// ----------------|---------------------------------------- -/// NK_TREE_NODE | Highlighted tree header to mark a collapsible UI section -/// NK_TREE_TAB | Non-highlighted tree header closer to tree representations -*/ -/*/// #### nk_tree_push -/// Starts a collapsible UI section with internal state management -/// !!! WARNING -/// To keep track of the runtime tree collapsible state this function uses -/// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want -/// to call this function in a loop please use `nk_tree_push_id` or -/// `nk_tree_push_hashed` instead. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_tree_push(ctx, type, title, state) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + * =============================================================================*/ +/** + * \page Tree + * Trees represent two different concept. First the concept of a collapsible + * UI section that can be either in a hidden or visible state. They allow the UI + * user to selectively minimize the current set of visible UI to comprehend. + * The second concept are tree widgets for visual UI representation of trees.

+ * + * Trees thereby can be nested for tree representations and multiple nested + * collapsible UI sections. All trees are started by calling of the + * `nk_tree_xxx_push_tree` functions and ended by calling one of the + * `nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label + * and optionally an image to be displayed and the initial collapse state from + * the nk_collapse_states section.

+ * + * The runtime state of the tree is either stored outside the library by the caller + * or inside which requires a unique ID. The unique ID can either be generated + * automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`, + * by `__FILE__` and a user provided ID generated for example by loop index with + * function `nk_tree_push_id` or completely provided from outside by user with + * function `nk_tree_push_hashed`. + * + * # Usage + * To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx` + * functions to start a collapsible UI section and `nk_tree_xxx_pop` to mark the + * end. + * Each starting function will either return `false(0)` if the tree is collapsed + * or hidden and therefore does not need to be filled with content or `true(1)` + * if visible and required to be filled. + * + * !!! Note + * The tree header does not require and layouting function and instead + * calculates a auto height based on the currently used font size + * + * The tree ending functions only need to be called if the tree content is + * actually visible. So make sure the tree push function is guarded by `if` + * and the pop call is only taken if the tree is visible. + * + * ```c + * if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) { + * nk_layout_row_dynamic(...); + * nk_widget(...); + * nk_tree_pop(ctx); + * } + * ``` + * + * # Reference + * Function | Description + * ----------------------------|------------------------------------------- + * nk_tree_push | Start a collapsible UI section with internal state management + * nk_tree_push_id | Start a collapsible UI section with internal state management callable in a look + * nk_tree_push_hashed | Start a collapsible UI section with internal state management with full control over internal unique ID use to store state + * nk_tree_image_push | Start a collapsible UI section with image and label header + * nk_tree_image_push_id | Start a collapsible UI section with image and label header and internal state management callable in a look + * nk_tree_image_push_hashed | Start a collapsible UI section with image and label header and internal state management with full control over internal unique ID use to store state + * nk_tree_pop | Ends a collapsible UI section + * nk_tree_state_push | Start a collapsible UI section with external state management + * nk_tree_state_image_push | Start a collapsible UI section with image and label header and external state management + * nk_tree_state_pop | Ends a collapsabale UI section + * + * # nk_tree_type + * Flag | Description + * ----------------|---------------------------------------- + * NK_TREE_NODE | Highlighted tree header to mark a collapsible UI section + * NK_TREE_TAB | Non-highlighted tree header closer to tree representations + */ + +/** + * # # nk_tree_push + * Starts a collapsible UI section with internal state management + * !!! \warning + * To keep track of the runtime tree collapsible state this function uses + * defines `__FILE__` and `__LINE__` to generate a unique ID. If you want + * to call this function in a loop please use `nk_tree_push_id` or + * `nk_tree_push_hashed` instead. + * + * ```c + * #define nk_tree_push(ctx, type, title, state) + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ #define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) -/*/// #### nk_tree_push_id -/// Starts a collapsible UI section with internal state management callable in a look -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_tree_push_id(ctx, type, title, state, id) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// __id__ | Loop counter index if this function is called in a loop -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_push_id + * Starts a collapsible UI section with internal state management callable in a look + * ```c + * #define nk_tree_push_id(ctx, type, title, state, id) + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * \param[in] id | Loop counter index if this function is called in a loop + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ #define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) -/*/// #### nk_tree_push_hashed -/// Start a collapsible UI section with internal state management with full -/// control over internal unique ID used to store state -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// __hash__ | Memory block or string to generate the ID from -/// __len__ | Size of passed memory block or string in __hash__ -/// __seed__ | Seeding value if this function is called in a loop or default to `0` -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_push_hashed + * Start a collapsible UI section with internal state management with full + * control over internal unique ID used to store state + * ```c + * nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * \param[in] hash | Memory block or string to generate the ID from + * \param[in] len | Size of passed memory block or string in __hash__ + * \param[in] seed | Seeding value if this function is called in a loop or default to `0` + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -/*/// #### nk_tree_image_push -/// Start a collapsible UI section with image and label header -/// !!! WARNING -/// To keep track of the runtime tree collapsible state this function uses -/// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want -/// to call this function in a loop please use `nk_tree_image_push_id` or -/// `nk_tree_image_push_hashed` instead. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_tree_image_push(ctx, type, img, title, state) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __img__ | Image to display inside the header on the left of the label -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_image_push + * Start a collapsible UI section with image and label header + * !!! \warning + * To keep track of the runtime tree collapsible state this function uses + * defines `__FILE__` and `__LINE__` to generate a unique ID. If you want + * to call this function in a loop please use `nk_tree_image_push_id` or + * `nk_tree_image_push_hashed` instead. + * + * ```c + * #define nk_tree_image_push(ctx, type, img, title, state) + * ``` + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] img | Image to display inside the header on the left of the label + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ #define nk_tree_image_push(ctx, type, img, title, state) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) -/*/// #### nk_tree_image_push_id -/// Start a collapsible UI section with image and label header and internal state -/// management callable in a look -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// #define nk_tree_image_push_id(ctx, type, img, title, state, id) -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __img__ | Image to display inside the header on the left of the label -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// __id__ | Loop counter index if this function is called in a loop -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_image_push_id + * Start a collapsible UI section with image and label header and internal state + * management callable in a look + * + * ```c + * #define nk_tree_image_push_id(ctx, type, img, title, state, id) + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] img | Image to display inside the header on the left of the label + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * \param[in] id | Loop counter index if this function is called in a loop + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ #define nk_tree_image_push_id(ctx, type, img, title, state, id) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) -/*/// #### nk_tree_image_push_hashed -/// Start a collapsible UI section with internal state management with full -/// control over internal unique ID used to store state -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __img__ | Image to display inside the header on the left of the label -/// __title__ | Label printed in the tree header -/// __state__ | Initial tree state value out of nk_collapse_states -/// __hash__ | Memory block or string to generate the ID from -/// __len__ | Size of passed memory block or string in __hash__ -/// __seed__ | Seeding value if this function is called in a loop or default to `0` -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_image_push_hashed + * Start a collapsible UI section with internal state management with full + * control over internal unique ID used to store state + * ```c + * nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] img | Image to display inside the header on the left of the label + * \param[in] title | Label printed in the tree header + * \param[in] state | Initial tree state value out of nk_collapse_states + * \param[in] hash | Memory block or string to generate the ID from + * \param[in] len | Size of passed memory block or string in __hash__ + * \param[in] seed | Seeding value if this function is called in a loop or default to `0` + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); -/*/// #### nk_tree_pop -/// Ends a collapsabale UI section -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_tree_pop(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` -*/ + +/** + * # # nk_tree_pop + * Ends a collapsabale UI section + * ```c + * void nk_tree_pop(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` + */ NK_API void nk_tree_pop(struct nk_context*); -/*/// #### nk_tree_state_push -/// Start a collapsible UI section with external state management -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __title__ | Label printed in the tree header -/// __state__ | Persistent state to update -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_state_push + * Start a collapsible UI section with external state management + * ```c + * nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] title | Label printed in the tree header + * \param[in] state | Persistent state to update + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); -/*/// #### nk_tree_state_image_push -/// Start a collapsible UI section with image and label header and external state management -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` -/// __img__ | Image to display inside the header on the left of the label -/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node -/// __title__ | Label printed in the tree header -/// __state__ | Persistent state to update -/// -/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise -*/ + +/** + * # # nk_tree_state_image_push + * Start a collapsible UI section with image and label header and external state management + * ```c + * nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` + * \param[in] img | Image to display inside the header on the left of the label + * \param[in] type | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node + * \param[in] title | Label printed in the tree header + * \param[in] state | Persistent state to update + * + * \returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise + */ NK_API nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); -/*/// #### nk_tree_state_pop -/// Ends a collapsabale UI section -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_tree_state_pop(struct nk_context*); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// ------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` -*/ + +/** + * # # nk_tree_state_pop + * Ends a collapsabale UI section + * ```c + * void nk_tree_state_pop(struct nk_context*); + * ``` + * + * Parameter | Description + * ------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` + */ NK_API void nk_tree_state_pop(struct nk_context*); #define nk_tree_element_push(ctx, type, title, state, sel) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) @@ -3102,31 +3301,31 @@ NK_API void nk_list_view_end(struct nk_list_view*); * * ============================================================================= */ enum nk_widget_layout_states { - NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ - NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ - NK_WIDGET_ROM, /* The widget is partially visible and cannot be updated */ - NK_WIDGET_DISABLED /* The widget is manually disabled and acts like NK_WIDGET_ROM */ + NK_WIDGET_INVALID, /**< The widget cannot be seen and is completely out of view */ + NK_WIDGET_VALID, /**< The widget is completely inside the window and can be updated and drawn */ + NK_WIDGET_ROM, /**< The widget is partially visible and cannot be updated */ + NK_WIDGET_DISABLED /**< The widget is manually disabled and acts like NK_WIDGET_ROM */ }; enum nk_widget_states { NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), - NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /* widget is neither active nor hovered */ - NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /* widget has been hovered on the current frame */ - NK_WIDGET_STATE_HOVER = NK_FLAG(4), /* widget is being hovered */ - NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ - NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ - NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ - NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ + NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /**!< widget is neither active nor hovered */ + NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /**!< widget has been hovered on the current frame */ + NK_WIDGET_STATE_HOVER = NK_FLAG(4), /**!< widget is being hovered */ + NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/**!< widget is currently activated */ + NK_WIDGET_STATE_LEFT = NK_FLAG(6), /**!< widget is from this frame on not hovered anymore */ + NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /**!< widget is being hovered */ + NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /**!< widget is currently activated */ }; NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); -NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); -NK_API struct nk_rect nk_widget_bounds(struct nk_context*); -NK_API struct nk_vec2 nk_widget_position(struct nk_context*); -NK_API struct nk_vec2 nk_widget_size(struct nk_context*); -NK_API float nk_widget_width(struct nk_context*); -NK_API float nk_widget_height(struct nk_context*); -NK_API nk_bool nk_widget_is_hovered(struct nk_context*); -NK_API nk_bool nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); -NK_API nk_bool nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, nk_bool down); +NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, const struct nk_context*, struct nk_vec2); +NK_API struct nk_rect nk_widget_bounds(const struct nk_context*); +NK_API struct nk_vec2 nk_widget_position(const struct nk_context*); +NK_API struct nk_vec2 nk_widget_size(const struct nk_context*); +NK_API float nk_widget_width(const struct nk_context*); +NK_API float nk_widget_height(const struct nk_context*); +NK_API nk_bool nk_widget_is_hovered(const struct nk_context*); +NK_API nk_bool nk_widget_is_mouse_clicked(const struct nk_context*, enum nk_buttons); +NK_API nk_bool nk_widget_has_mouse_click_down(const struct nk_context*, enum nk_buttons, nk_bool down); NK_API void nk_spacing(struct nk_context*, int cols); NK_API void nk_widget_disable_begin(struct nk_context* ctx); NK_API void nk_widget_disable_end(struct nk_context* ctx); @@ -3257,6 +3456,15 @@ NK_API float nk_slide_float(struct nk_context*, float min, float val, float max, NK_API int nk_slide_int(struct nk_context*, int min, int val, int max, int step); NK_API nk_bool nk_slider_float(struct nk_context*, float min, float *val, float max, float step); NK_API nk_bool nk_slider_int(struct nk_context*, int min, int *val, int max, int step); + +/* ============================================================================= + * + * KNOB + * + * ============================================================================= */ +NK_API nk_bool nk_knob_float(struct nk_context*, float min, float *val, float max, float step, enum nk_heading zero_direction, float dead_zone_degrees); +NK_API nk_bool nk_knob_int(struct nk_context*, int min, int *val, int max, int step, enum nk_heading zero_direction, float dead_zone_degrees); + /* ============================================================================= * * PROGRESSBAR @@ -3276,210 +3484,216 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo * * PROPERTIES * - * ============================================================================= -/// ### Properties -/// Properties are the main value modification widgets in Nuklear. Changing a value -/// can be achieved by dragging, adding/removing incremental steps on button click -/// or by directly typing a number. -/// -/// #### Usage -/// Each property requires a unique name for identification that is also used for -/// displaying a label. If you want to use the same name multiple times make sure -/// add a '#' before your name. The '#' will not be shown but will generate a -/// unique ID. Each property also takes in a minimum and maximum value. If you want -/// to make use of the complete number range of a type just use the provided -/// type limits from `limits.h`. For example `INT_MIN` and `INT_MAX` for -/// `nk_property_int` and `nk_propertyi`. In additional each property takes in -/// a increment value that will be added or subtracted if either the increment -/// decrement button is clicked. Finally there is a value for increment per pixel -/// dragged that is added or subtracted from the value. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// int value = 0; -/// struct nk_context ctx; -/// nk_init_xxx(&ctx, ...); -/// while (1) { -/// // Input -/// Event evt; -/// nk_input_begin(&ctx); -/// while (GetEvent(&evt)) { -/// if (evt.type == MOUSE_MOVE) -/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); -/// else if (evt.type == [...]) { -/// nk_input_xxx(...); -/// } -/// } -/// nk_input_end(&ctx); -/// // -/// // Window -/// if (nk_begin_xxx(...) { -/// // Property -/// nk_layout_row_dynamic(...); -/// nk_property_int(ctx, "ID", INT_MIN, &value, INT_MAX, 1, 1); -/// } -/// nk_end(ctx); -/// // -/// // Draw -/// const struct nk_command *cmd = 0; -/// nk_foreach(cmd, &ctx) { -/// switch (cmd->type) { -/// case NK_COMMAND_LINE: -/// your_draw_line_function(...) -/// break; -/// case NK_COMMAND_RECT -/// your_draw_rect_function(...) -/// break; -/// case ...: -/// // [...] -/// } -/// nk_clear(&ctx); -/// } -/// nk_free(&ctx); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// #### Reference -/// Function | Description -/// --------------------|------------------------------------------- -/// nk_property_int | Integer property directly modifying a passed in value -/// nk_property_float | Float property directly modifying a passed in value -/// nk_property_double | Double property directly modifying a passed in value -/// nk_propertyi | Integer property returning the modified int value -/// nk_propertyf | Float property returning the modified float value -/// nk_propertyd | Double property returning the modified double value -/// -*/ -/*/// #### nk_property_int -/// Integer property directly modifying a passed in value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Integer pointer to be modified -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -*/ + * =============================================================================*/ +/** + * \page Properties + * Properties are the main value modification widgets in Nuklear. Changing a value + * can be achieved by dragging, adding/removing incremental steps on button click + * or by directly typing a number. + * + * # Usage + * Each property requires a unique name for identification that is also used for + * displaying a label. If you want to use the same name multiple times make sure + * add a '#' before your name. The '#' will not be shown but will generate a + * unique ID. Each property also takes in a minimum and maximum value. If you want + * to make use of the complete number range of a type just use the provided + * type limits from `limits.h`. For example `INT_MIN` and `INT_MAX` for + * `nk_property_int` and `nk_propertyi`. In additional each property takes in + * a increment value that will be added or subtracted if either the increment + * decrement button is clicked. Finally there is a value for increment per pixel + * dragged that is added or subtracted from the value. + * + * ```c + * int value = 0; + * struct nk_context ctx; + * nk_init_xxx(&ctx, ...); + * while (1) { + * // Input + * Event evt; + * nk_input_begin(&ctx); + * while (GetEvent(&evt)) { + * if (evt.type == MOUSE_MOVE) + * nk_input_motion(&ctx, evt.motion.x, evt.motion.y); + * else if (evt.type == [...]) { + * nk_input_xxx(...); + * } + * } + * nk_input_end(&ctx); + * // + * // Window + * if (nk_begin_xxx(...) { + * // Property + * nk_layout_row_dynamic(...); + * nk_property_int(ctx, "ID", INT_MIN, &value, INT_MAX, 1, 1); + * } + * nk_end(ctx); + * // + * // Draw + * const struct nk_command *cmd = 0; + * nk_foreach(cmd, &ctx) { + * switch (cmd->type) { + * case NK_COMMAND_LINE: + * your_draw_line_function(...) + * break; + * case NK_COMMAND_RECT + * your_draw_rect_function(...) + * break; + * case ...: + * // [...] + * } + * nk_clear(&ctx); + * } + * nk_free(&ctx); + * ``` + * + * # Reference + * Function | Description + * --------------------|------------------------------------------- + * \ref nk_property_int | Integer property directly modifying a passed in value + * \ref nk_property_float | Float property directly modifying a passed in value + * \ref nk_property_double | Double property directly modifying a passed in value + * \ref nk_propertyi | Integer property returning the modified int value + * \ref nk_propertyf | Float property returning the modified float value + * \ref nk_propertyd | Double property returning the modified double value + * + + * # # nk_property_int + * Integer property directly modifying a passed in value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel); + * ``` + * + * Parameter | Description + * --------------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name | String used both as a label as well as a unique identifier + * \param[in] min | Minimum value not allowed to be underflown + * \param[in] val | Integer pointer to be modified + * \param[in] max | Maximum value not allowed to be overflown + * \param[in] step | Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging + */ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel); -/*/// #### nk_property_float -/// Float property directly modifying a passed in value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Float pointer to be modified -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -*/ + +/** + * # # nk_property_float + * Float property directly modifying a passed in value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel); + * ``` + * + * Parameter | Description + * --------------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name | String used both as a label as well as a unique identifier + * \param[in] min | Minimum value not allowed to be underflown + * \param[in] val | Float pointer to be modified + * \param[in] max | Maximum value not allowed to be overflown + * \param[in] step | Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging + */ NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel); -/*/// #### nk_property_double -/// Double property directly modifying a passed in value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Double pointer to be modified -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -*/ + +/** + * # # nk_property_double + * Double property directly modifying a passed in value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel); + * ``` + * + * Parameter | Description + * --------------------|----------------------------------------------------------- + * \param[in] ctx | Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name | String used both as a label as well as a unique identifier + * \param[in] min | Minimum value not allowed to be underflown + * \param[in] val | Double pointer to be modified + * \param[in] max | Maximum value not allowed to be overflown + * \param[in] step | Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging + */ NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel); -/*/// #### nk_propertyi -/// Integer property modifying a passed in value and returning the new value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// int nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, int max, int step, float inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Current integer value to be modified and returned -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -/// -/// Returns the new modified integer value -*/ + +/** + * # # nk_propertyi + * Integer property modifying a passed in value and returning the new value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * int nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, int max, int step, float inc_per_pixel); + * ``` + * + * \param[in] ctx Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name String used both as a label as well as a unique identifier + * \param[in] min Minimum value not allowed to be underflown + * \param[in] val Current integer value to be modified and returned + * \param[in] max Maximum value not allowed to be overflown + * \param[in] step Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel Value per pixel added or subtracted on dragging + * + * \returns the new modified integer value + */ NK_API int nk_propertyi(struct nk_context*, const char *name, int min, int val, int max, int step, float inc_per_pixel); -/*/// #### nk_propertyf -/// Float property modifying a passed in value and returning the new value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// float nk_propertyf(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Current float value to be modified and returned -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -/// -/// Returns the new modified float value -*/ + +/** + * # # nk_propertyf + * Float property modifying a passed in value and returning the new value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * float nk_propertyf(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel); + * ``` + * + * \param[in] ctx Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name String used both as a label as well as a unique identifier + * \param[in] min Minimum value not allowed to be underflown + * \param[in] val Current float value to be modified and returned + * \param[in] max Maximum value not allowed to be overflown + * \param[in] step Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel Value per pixel added or subtracted on dragging + * + * \returns the new modified float value + */ NK_API float nk_propertyf(struct nk_context*, const char *name, float min, float val, float max, float step, float inc_per_pixel); -/*/// #### nk_propertyd -/// Float property modifying a passed in value and returning the new value -/// !!! WARNING -/// To generate a unique property ID using the same label make sure to insert -/// a `#` at the beginning. It will not be shown but guarantees correct behavior. -/// -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c -/// float nk_propertyd(struct nk_context *ctx, const char *name, double min, double val, double max, double step, double inc_per_pixel); -/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// -/// Parameter | Description -/// --------------------|----------------------------------------------------------- -/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function -/// __name__ | String used both as a label as well as a unique identifier -/// __min__ | Minimum value not allowed to be underflown -/// __val__ | Current double value to be modified and returned -/// __max__ | Maximum value not allowed to be overflown -/// __step__ | Increment added and subtracted on increment and decrement button -/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging -/// -/// Returns the new modified double value -*/ + +/** + * # # nk_propertyd + * Float property modifying a passed in value and returning the new value + * !!! \warning + * To generate a unique property ID using the same label make sure to insert + * a `#` at the beginning. It will not be shown but guarantees correct behavior. + * + * ```c + * float nk_propertyd(struct nk_context *ctx, const char *name, double min, double val, double max, double step, double inc_per_pixel); + * ``` + * + * \param[in] ctx Must point to an previously initialized `nk_context` struct after calling a layouting function + * \param[in] name String used both as a label as well as a unique identifier + * \param[in] min Minimum value not allowed to be underflown + * \param[in] val Current double value to be modified and returned + * \param[in] max Maximum value not allowed to be overflown + * \param[in] step Increment added and subtracted on increment and decrement button + * \param[in] inc_per_pixel Value per pixel added or subtracted on dragging + * + * \returns the new modified double value + */ NK_API double nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel); + /* ============================================================================= * * TEXT EDIT @@ -3507,11 +3721,11 @@ enum nk_edit_types { NK_EDIT_EDITOR = NK_EDIT_SELECTABLE|NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB| NK_EDIT_CLIPBOARD }; enum nk_edit_events { - NK_EDIT_ACTIVE = NK_FLAG(0), /* edit widget is currently being modified */ - NK_EDIT_INACTIVE = NK_FLAG(1), /* edit widget is not active and is not being modified */ - NK_EDIT_ACTIVATED = NK_FLAG(2), /* edit widget went from state inactive to state active */ - NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */ - NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */ + NK_EDIT_ACTIVE = NK_FLAG(0), /**!< edit widget is currently being modified */ + NK_EDIT_INACTIVE = NK_FLAG(1), /**!< edit widget is not active and is not being modified */ + NK_EDIT_ACTIVATED = NK_FLAG(2), /**!< edit widget went from state inactive to state active */ + NK_EDIT_DEACTIVATED = NK_FLAG(3), /**!< edit widget went from state active to state inactive */ + NK_EDIT_COMMITED = NK_FLAG(4) /**!< edit widget has received an enter and lost focus */ }; NK_API nk_flags nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter); NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter); @@ -3540,18 +3754,18 @@ NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userd NK_API nk_bool nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); NK_API void nk_popup_close(struct nk_context*); NK_API void nk_popup_end(struct nk_context*); -NK_API void nk_popup_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); +NK_API void nk_popup_get_scroll(const struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); NK_API void nk_popup_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); /* ============================================================================= * * COMBOBOX * * ============================================================================= */ -NK_API int nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height, struct nk_vec2 size); +NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int selected, int item_height, struct nk_vec2 size); NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size); NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size); NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size); -NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size); +NK_API void nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size); NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size); NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size); NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); @@ -3663,6 +3877,10 @@ enum nk_style_colors { NK_COLOR_SCROLLBAR_CURSOR_HOVER, NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, NK_COLOR_TAB_HEADER, + NK_COLOR_KNOB, + NK_COLOR_KNOB_CURSOR, + NK_COLOR_KNOB_CURSOR_HOVER, + NK_COLOR_KNOB_CURSOR_ACTIVE, NK_COLOR_COUNT }; enum nk_style_cursor { @@ -3678,7 +3896,7 @@ enum nk_style_cursor { NK_API void nk_style_default(struct nk_context*); NK_API void nk_style_from_table(struct nk_context*, const struct nk_color*); NK_API void nk_style_load_cursor(struct nk_context*, enum nk_style_cursor, const struct nk_cursor*); -NK_API void nk_style_load_all_cursors(struct nk_context*, struct nk_cursor*); +NK_API void nk_style_load_all_cursors(struct nk_context*, const struct nk_cursor*); NK_API const char* nk_style_get_color_by_name(enum nk_style_colors); NK_API void nk_style_set_font(struct nk_context*, const struct nk_user_font*); NK_API nk_bool nk_style_set_cursor(struct nk_context*, enum nk_style_cursor); @@ -3710,7 +3928,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b); NK_API struct nk_color nk_rgb_fv(const float *rgb); NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); NK_API struct nk_color nk_rgb_hex(const char *rgb); -NK_API struct nk_color nk_rgb_factor(struct nk_color col, const float factor); +NK_API struct nk_color nk_rgb_factor(struct nk_color col, float factor); NK_API struct nk_color nk_rgba(int r, int g, int b, int a); NK_API struct nk_color nk_rgba_u32(nk_uint); @@ -3722,7 +3940,7 @@ NK_API struct nk_color nk_rgba_cf(struct nk_colorf c); NK_API struct nk_color nk_rgba_hex(const char *rgb); NK_API struct nk_colorf nk_hsva_colorf(float h, float s, float v, float a); -NK_API struct nk_colorf nk_hsva_colorfv(float *c); +NK_API struct nk_colorf nk_hsva_colorfv(const float *c); NK_API void nk_colorf_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_colorf in); NK_API void nk_colorf_hsva_fv(float *hsva, struct nk_colorf in); @@ -3817,11 +4035,11 @@ NK_API struct nk_vec2 nk_rect_size(struct nk_rect); NK_API int nk_strlen(const char *str); NK_API int nk_stricmp(const char *s1, const char *s2); NK_API int nk_stricmpn(const char *s1, const char *s2, int n); -NK_API int nk_strtoi(const char *str, const char **endptr); -NK_API float nk_strtof(const char *str, const char **endptr); +NK_API int nk_strtoi(const char *str, char **endptr); +NK_API float nk_strtof(const char *str, char **endptr); #ifndef NK_STRTOD #define NK_STRTOD nk_strtod -NK_API double nk_strtod(const char *str, const char **endptr); +NK_API double nk_strtod(const char *str, char **endptr); #endif NK_API int nk_strfilter(const char *text, const char *regexp); NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score); @@ -3837,159 +4055,161 @@ NK_API int nk_utf_len(const char*, int byte_len); NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); /* =============================================================== * - * FONT + * FONT + * + * ===============================================================*/ +/** + * \page Font + * Font handling in this library was designed to be quite customizable and lets + * you decide what you want to use and what you want to provide. There are three + * different ways to use the font atlas. The first two will use your font + * handling scheme and only requires essential data to run nuklear. The next + * slightly more advanced features is font handling with vertex buffer output. + * Finally the most complex API wise is using nuklear's font baking API. + * + * # Using your own implementation without vertex buffer output + * + * So first up the easiest way to do font handling is by just providing a + * `nk_user_font` struct which only requires the height in pixel of the used + * font and a callback to calculate the width of a string. This way of handling + * fonts is best fitted for using the normal draw shape command API where you + * do all the text drawing yourself and the library does not require any kind + * of deeper knowledge about which font handling mechanism you use. + * IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist + * over the complete life time! I know this sucks but it is currently the only + * way to switch between fonts. + * + * ```c + * float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) + * { + * your_font_type *type = handle.ptr; + * float text_width = ...; + * return text_width; + * } + * + * struct nk_user_font font; + * font.userdata.ptr = &your_font_class_or_struct; + * font.height = your_font_height; + * font.width = your_text_width_calculation; + * + * struct nk_context ctx; + * nk_init_default(&ctx, &font); + * ``` + * # Using your own implementation with vertex buffer output + * + * While the first approach works fine if you don't want to use the optional + * vertex buffer output it is not enough if you do. To get font handling working + * for these cases you have to provide two additional parameters inside the + * `nk_user_font`. First a texture atlas handle used to draw text as subimages + * of a bigger font atlas texture and a callback to query a character's glyph + * information (offset, size, ...). So it is still possible to provide your own + * font and use the vertex buffer output. + * + * ```c + * float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) + * { + * your_font_type *type = handle.ptr; + * float text_width = ...; + * return text_width; + * } + * void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) + * { + * your_font_type *type = handle.ptr; + * glyph.width = ...; + * glyph.height = ...; + * glyph.xadvance = ...; + * glyph.uv[0].x = ...; + * glyph.uv[0].y = ...; + * glyph.uv[1].x = ...; + * glyph.uv[1].y = ...; + * glyph.offset.x = ...; + * glyph.offset.y = ...; + * } + * + * struct nk_user_font font; + * font.userdata.ptr = &your_font_class_or_struct; + * font.height = your_font_height; + * font.width = your_text_width_calculation; + * font.query = query_your_font_glyph; + * font.texture.id = your_font_texture; + * + * struct nk_context ctx; + * nk_init_default(&ctx, &font); + * ``` + * + * # Nuklear font baker + * + * The final approach if you do not have a font handling functionality or don't + * want to use it in this library is by using the optional font baker. + * The font baker APIs can be used to create a font plus font atlas texture + * and can be used with or without the vertex buffer output. + * + * It still uses the `nk_user_font` struct and the two different approaches + * previously stated still work. The font baker is not located inside + * `nk_context` like all other systems since it can be understood as more of + * an extension to nuklear and does not really depend on any `nk_context` state. + * + * Font baker need to be initialized first by one of the nk_font_atlas_init_xxx + * functions. If you don't care about memory just call the default version + * `nk_font_atlas_init_default` which will allocate all memory from the standard library. + * If you want to control memory allocation but you don't care if the allocated + * memory is temporary and therefore can be freed directly after the baking process + * is over or permanent you can call `nk_font_atlas_init`. + * + * After successfully initializing the font baker you can add Truetype(.ttf) fonts from + * different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. + * functions. Adding font will permanently store each font, font config and ttf memory block(!) + * inside the font atlas and allows to reuse the font atlas. If you don't want to reuse + * the font baker by for example adding additional fonts you can call + * `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). + * + * As soon as you added all fonts you wanted you can now start the baking process + * for every selected glyph to image by calling `nk_font_atlas_bake`. + * The baking process returns image memory, width and height which can be used to + * either create your own image object or upload it to any graphics library. + * No matter which case you finally have to call `nk_font_atlas_end` which + * will free all temporary memory including the font atlas image so make sure + * you created our texture beforehand. `nk_font_atlas_end` requires a handle + * to your font texture or object and optionally fills a `struct nk_draw_null_texture` + * which can be used for the optional vertex output. If you don't want it just + * set the argument to `NULL`. + * + * At this point you are done and if you don't want to reuse the font atlas you + * can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration + * memory. Finally if you don't use the font atlas and any of it's fonts anymore + * you need to call `nk_font_atlas_clear` to free all memory still being used. + * + * ```c + * struct nk_font_atlas atlas; + * nk_font_atlas_init_default(&atlas); + * nk_font_atlas_begin(&atlas); + * nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); + * nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); + * const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); + * nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); + * + * struct nk_context ctx; + * nk_init_default(&ctx, &font->handle); + * while (1) { + * + * } + * nk_font_atlas_clear(&atlas); + * ``` + * The font baker API is probably the most complex API inside this library and + * I would suggest reading some of my examples `example/` to get a grip on how + * to use the font atlas. There are a number of details I left out. For example + * how to merge fonts, configure a font with `nk_font_config` to use other languages, + * use another texture coordinate format and a lot more: * - * ===============================================================*/ -/*/// ### Font -/// Font handling in this library was designed to be quite customizable and lets -/// you decide what you want to use and what you want to provide. There are three -/// different ways to use the font atlas. The first two will use your font -/// handling scheme and only requires essential data to run nuklear. The next -/// slightly more advanced features is font handling with vertex buffer output. -/// Finally the most complex API wise is using nuklear's font baking API. -// -/// #### Using your own implementation without vertex buffer output -/// -/// So first up the easiest way to do font handling is by just providing a -/// `nk_user_font` struct which only requires the height in pixel of the used -/// font and a callback to calculate the width of a string. This way of handling -/// fonts is best fitted for using the normal draw shape command API where you -/// do all the text drawing yourself and the library does not require any kind -/// of deeper knowledge about which font handling mechanism you use. -/// IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist -/// over the complete life time! I know this sucks but it is currently the only -/// way to switch between fonts. -/// -/// ```c -/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) -/// { -/// your_font_type *type = handle.ptr; -/// float text_width = ...; -/// return text_width; -/// } -/// -/// struct nk_user_font font; -/// font.userdata.ptr = &your_font_class_or_struct; -/// font.height = your_font_height; -/// font.width = your_text_width_calculation; -/// -/// struct nk_context ctx; -/// nk_init_default(&ctx, &font); -/// ``` -/// #### Using your own implementation with vertex buffer output -/// -/// While the first approach works fine if you don't want to use the optional -/// vertex buffer output it is not enough if you do. To get font handling working -/// for these cases you have to provide two additional parameters inside the -/// `nk_user_font`. First a texture atlas handle used to draw text as subimages -/// of a bigger font atlas texture and a callback to query a character's glyph -/// information (offset, size, ...). So it is still possible to provide your own -/// font and use the vertex buffer output. -/// -/// ```c -/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) -/// { -/// your_font_type *type = handle.ptr; -/// float text_width = ...; -/// return text_width; -/// } -/// void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) -/// { -/// your_font_type *type = handle.ptr; -/// glyph.width = ...; -/// glyph.height = ...; -/// glyph.xadvance = ...; -/// glyph.uv[0].x = ...; -/// glyph.uv[0].y = ...; -/// glyph.uv[1].x = ...; -/// glyph.uv[1].y = ...; -/// glyph.offset.x = ...; -/// glyph.offset.y = ...; -/// } -/// -/// struct nk_user_font font; -/// font.userdata.ptr = &your_font_class_or_struct; -/// font.height = your_font_height; -/// font.width = your_text_width_calculation; -/// font.query = query_your_font_glyph; -/// font.texture.id = your_font_texture; -/// -/// struct nk_context ctx; -/// nk_init_default(&ctx, &font); -/// ``` -/// -/// #### Nuklear font baker -/// -/// The final approach if you do not have a font handling functionality or don't -/// want to use it in this library is by using the optional font baker. -/// The font baker APIs can be used to create a font plus font atlas texture -/// and can be used with or without the vertex buffer output. -/// -/// It still uses the `nk_user_font` struct and the two different approaches -/// previously stated still work. The font baker is not located inside -/// `nk_context` like all other systems since it can be understood as more of -/// an extension to nuklear and does not really depend on any `nk_context` state. -/// -/// Font baker need to be initialized first by one of the nk_font_atlas_init_xxx -/// functions. If you don't care about memory just call the default version -/// `nk_font_atlas_init_default` which will allocate all memory from the standard library. -/// If you want to control memory allocation but you don't care if the allocated -/// memory is temporary and therefore can be freed directly after the baking process -/// is over or permanent you can call `nk_font_atlas_init`. -/// -/// After successfully initializing the font baker you can add Truetype(.ttf) fonts from -/// different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. -/// functions. Adding font will permanently store each font, font config and ttf memory block(!) -/// inside the font atlas and allows to reuse the font atlas. If you don't want to reuse -/// the font baker by for example adding additional fonts you can call -/// `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). -/// -/// As soon as you added all fonts you wanted you can now start the baking process -/// for every selected glyph to image by calling `nk_font_atlas_bake`. -/// The baking process returns image memory, width and height which can be used to -/// either create your own image object or upload it to any graphics library. -/// No matter which case you finally have to call `nk_font_atlas_end` which -/// will free all temporary memory including the font atlas image so make sure -/// you created our texture beforehand. `nk_font_atlas_end` requires a handle -/// to your font texture or object and optionally fills a `struct nk_draw_null_texture` -/// which can be used for the optional vertex output. If you don't want it just -/// set the argument to `NULL`. -/// -/// At this point you are done and if you don't want to reuse the font atlas you -/// can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration -/// memory. Finally if you don't use the font atlas and any of it's fonts anymore -/// you need to call `nk_font_atlas_clear` to free all memory still being used. -/// -/// ```c -/// struct nk_font_atlas atlas; -/// nk_font_atlas_init_default(&atlas); -/// nk_font_atlas_begin(&atlas); -/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); -/// nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); -/// const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); -/// nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); -/// -/// struct nk_context ctx; -/// nk_init_default(&ctx, &font->handle); -/// while (1) { -/// -/// } -/// nk_font_atlas_clear(&atlas); -/// ``` -/// The font baker API is probably the most complex API inside this library and -/// I would suggest reading some of my examples `example/` to get a grip on how -/// to use the font atlas. There are a number of details I left out. For example -/// how to merge fonts, configure a font with `nk_font_config` to use other languages, -/// use another texture coordinate format and a lot more: -/// -/// ```c -/// struct nk_font_config cfg = nk_font_config(font_pixel_height); -/// cfg.merge_mode = nk_false or nk_true; -/// cfg.range = nk_font_korean_glyph_ranges(); -/// cfg.coord_type = NK_COORD_PIXEL; -/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); -/// ``` -*/ + * ```c + * struct nk_font_config cfg = nk_font_config(font_pixel_height); + * cfg.merge_mode = nk_false or nk_true; + * cfg.range = nk_font_korean_glyph_ranges(); + * cfg.coord_type = NK_COORD_PIXEL; + * nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); + * ``` + */ + struct nk_user_font_glyph; typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, @@ -3998,84 +4218,56 @@ typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, #if defined(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) || defined(NK_INCLUDE_SOFTWARE_FONT) struct nk_user_font_glyph { - struct nk_vec2 uv[2]; - /* texture coordinates */ - struct nk_vec2 offset; - /* offset between top left and glyph */ - float width, height; - /* size of the glyph */ - float xadvance; - /* offset to the next glyph */ + struct nk_vec2 uv[2]; /**!< texture coordinates */ + struct nk_vec2 offset; /**!< offset between top left and glyph */ + float width, height; /**!< size of the glyph */ + float xadvance; /**!< offset to the next glyph */ }; #endif struct nk_user_font { - nk_handle userdata; - /* user provided font handle */ - float height; - /* max height of the font */ - nk_text_width_f width; - /* font string width in pixel callback */ + nk_handle userdata; /**!< user provided font handle */ + float height; /**!< max height of the font */ + nk_text_width_f width; /**!< font string width in pixel callback */ #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT - nk_query_font_glyph_f query; - /* font glyph callback to query drawing info */ - nk_handle texture; - /* texture handle to the used font atlas or texture */ + nk_query_font_glyph_f query; /**!< font glyph callback to query drawing info */ + nk_handle texture; /**!< texture handle to the used font atlas or texture */ #endif }; #ifdef NK_INCLUDE_FONT_BAKING enum nk_font_coord_type { - NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */ - NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */ + NK_COORD_UV, /**!< texture coordinates inside font glyphs are clamped between 0-1 */ + NK_COORD_PIXEL /**!< texture coordinates inside font glyphs are in absolute pixel */ }; struct nk_font; struct nk_baked_font { - float height; - /* height of the font */ - float ascent, descent; - /* font glyphs ascent and descent */ - nk_rune glyph_offset; - /* glyph array offset inside the font glyph baking output array */ - nk_rune glyph_count; - /* number of glyphs of this font inside the glyph baking array output */ - const nk_rune *ranges; - /* font codepoint ranges as pairs of (from/to) and 0 as last element */ + float height; /**!< height of the font */ + float ascent; /**!< font glyphs ascent and descent */ + float descent; /**!< font glyphs ascent and descent */ + nk_rune glyph_offset; /**!< glyph array offset inside the font glyph baking output array */ + nk_rune glyph_count; /**!< number of glyphs of this font inside the glyph baking array output */ + const nk_rune *ranges; /**!< font codepoint ranges as pairs of (from/to) and 0 as last element */ }; struct nk_font_config { - struct nk_font_config *next; - /* NOTE: only used internally */ - void *ttf_blob; - /* pointer to loaded TTF file memory block. - * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ - nk_size ttf_size; - /* size of the loaded TTF file memory block - * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ - - unsigned char ttf_data_owned_by_atlas; - /* used inside font atlas: default to: 0*/ - unsigned char merge_mode; - /* merges this font into the last font */ - unsigned char pixel_snap; - /* align every character to pixel boundary (if true set oversample (1,1)) */ - unsigned char oversample_v, oversample_h; - /* rasterize at high quality for sub-pixel position */ + struct nk_font_config *next; /**!< NOTE: only used internally */ + void *ttf_blob; /**!< pointer to loaded TTF file memory block. * \note not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + nk_size ttf_size; /**!< size of the loaded TTF file memory block * \note not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + + unsigned char ttf_data_owned_by_atlas; /**!< used inside font atlas: default to: 0*/ + unsigned char merge_mode; /**!< merges this font into the last font */ + unsigned char pixel_snap; /**!< align every character to pixel boundary (if true set oversample (1,1)) */ + unsigned char oversample_v, oversample_h; /**!< rasterize at high quality for sub-pixel position */ unsigned char padding[3]; - float size; - /* baked pixel height of the font */ - enum nk_font_coord_type coord_type; - /* texture coordinate format with either pixel or UV coordinates */ - struct nk_vec2 spacing; - /* extra pixel spacing between glyphs */ - const nk_rune *range; - /* list of unicode ranges (2 values per range, zero terminated) */ - struct nk_baked_font *font; - /* font to setup in the baking process: NOTE: not needed for font atlas */ - nk_rune fallback_glyph; - /* fallback glyph to use if a given rune is not found */ + float size; /**!< baked pixel height of the font */ + enum nk_font_coord_type coord_type; /**!< texture coordinate format with either pixel or UV coordinates */ + struct nk_vec2 spacing; /**!< extra pixel spacing between glyphs */ + const nk_rune *range; /**!< list of unicode ranges (2 values per range, zero terminated) */ + struct nk_baked_font *font; /**!< font to setup in the baking process: NOTE: not needed for font atlas */ + nk_rune fallback_glyph; /**!< fallback glyph to use if a given rune is not found */ struct nk_font_config *n; struct nk_font_config *p; }; @@ -4123,7 +4315,7 @@ struct nk_font_atlas { int font_num; }; -/* some language glyph codepoint ranges */ +/** some language glyph codepoint ranges */ NK_API const nk_rune *nk_font_default_glyph_ranges(void); NK_API const nk_rune *nk_font_chinese_glyph_ranges(void); NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void); @@ -4132,8 +4324,8 @@ NK_API const nk_rune *nk_font_korean_glyph_ranges(void); #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); #endif -NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*); -NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient); +NK_API void nk_font_atlas_init(struct nk_font_atlas*, const struct nk_allocator*); +NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, const struct nk_allocator *persistent, const struct nk_allocator *transient); NK_API void nk_font_atlas_begin(struct nk_font_atlas*); NK_API struct nk_font_config nk_font_config(float pixel_height); NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*); @@ -4148,46 +4340,48 @@ NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config); NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format); NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*); -NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode); +NK_API const struct nk_font_glyph* nk_font_find_glyph(const struct nk_font*, nk_rune unicode); NK_API void nk_font_atlas_cleanup(struct nk_font_atlas *atlas); NK_API void nk_font_atlas_clear(struct nk_font_atlas*); #endif -/* ============================================================== +/** ============================================================== * * MEMORY BUFFER * * ===============================================================*/ -/*/// ### Memory Buffer -/// A basic (double)-buffer with linear allocation and resetting as only -/// freeing policy. The buffer's main purpose is to control all memory management -/// inside the GUI toolkit and still leave memory control as much as possible in -/// the hand of the user while also making sure the library is easy to use if -/// not as much control is needed. -/// In general all memory inside this library can be provided from the user in -/// three different ways. -/// -/// The first way and the one providing most control is by just passing a fixed -/// size memory block. In this case all control lies in the hand of the user -/// since he can exactly control where the memory comes from and how much memory -/// the library should consume. Of course using the fixed size API removes the -/// ability to automatically resize a buffer if not enough memory is provided so -/// you have to take over the resizing. While being a fixed sized buffer sounds -/// quite limiting, it is very effective in this library since the actual memory -/// consumption is quite stable and has a fixed upper bound for a lot of cases. -/// -/// If you don't want to think about how much memory the library should allocate -/// at all time or have a very dynamic UI with unpredictable memory consumption -/// habits but still want control over memory allocation you can use the dynamic -/// allocator based API. The allocator consists of two callbacks for allocating -/// and freeing memory and optional userdata so you can plugin your own allocator. -/// -/// The final and easiest way can be used by defining -/// NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory -/// allocation functions malloc and free and takes over complete control over -/// memory in this library. -*/ +/** + * \page Memory Buffer + * A basic (double)-buffer with linear allocation and resetting as only + * freeing policy. The buffer's main purpose is to control all memory management + * inside the GUI toolkit and still leave memory control as much as possible in + * the hand of the user while also making sure the library is easy to use if + * not as much control is needed. + * In general all memory inside this library can be provided from the user in + * three different ways. + * + * The first way and the one providing most control is by just passing a fixed + * size memory block. In this case all control lies in the hand of the user + * since he can exactly control where the memory comes from and how much memory + * the library should consume. Of course using the fixed size API removes the + * ability to automatically resize a buffer if not enough memory is provided so + * you have to take over the resizing. While being a fixed sized buffer sounds + * quite limiting, it is very effective in this library since the actual memory + * consumption is quite stable and has a fixed upper bound for a lot of cases. + * + * If you don't want to think about how much memory the library should allocate + * at all time or have a very dynamic UI with unpredictable memory consumption + * habits but still want control over memory allocation you can use the dynamic + * allocator based API. The allocator consists of two callbacks for allocating + * and freeing memory and optional userdata so you can plugin your own allocator. + * + * The final and easiest way can be used by defining + * NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory + * allocation functions malloc and free and takes over complete control over + * memory in this library. + */ + struct nk_memory_status { void *memory; unsigned int type; @@ -4215,24 +4409,15 @@ struct nk_buffer_marker { struct nk_memory {void *ptr;nk_size size;}; struct nk_buffer { - struct nk_buffer_marker marker[NK_BUFFER_MAX]; - /* buffer marker to free a buffer to a certain offset */ - struct nk_allocator pool; - /* allocator callback for dynamic buffers */ - enum nk_allocation_type type; - /* memory management type */ - struct nk_memory memory; - /* memory and size of the current memory block */ - float grow_factor; - /* growing factor for dynamic memory management */ - nk_size allocated; - /* total amount of memory allocated */ - nk_size needed; - /* totally consumed memory given that enough memory is present */ - nk_size calls; - /* number of allocation calls */ - nk_size size; - /* current size of the buffer */ + struct nk_buffer_marker marker[NK_BUFFER_MAX]; /**!< buffer marker to free a buffer to a certain offset */ + struct nk_allocator pool; /**!< allocator callback for dynamic buffers */ + enum nk_allocation_type type; /**!< memory management type */ + struct nk_memory memory; /**!< memory and size of the current memory block */ + float grow_factor; /**!< growing factor for dynamic memory management */ + nk_size allocated; /**!< total amount of memory allocated */ + nk_size needed; /**!< totally consumed memory given that enough memory is present */ + nk_size calls; /**!< number of allocation calls */ + nk_size size; /**!< current size of the buffer */ }; #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR @@ -4240,7 +4425,7 @@ NK_API void nk_buffer_init_default(struct nk_buffer*); #endif NK_API void nk_buffer_init(struct nk_buffer*, const struct nk_allocator*, nk_size size); NK_API void nk_buffer_init_fixed(struct nk_buffer*, void *memory, nk_size size); -NK_API void nk_buffer_info(struct nk_memory_status*, struct nk_buffer*); +NK_API void nk_buffer_info(struct nk_memory_status*, const struct nk_buffer*); NK_API void nk_buffer_push(struct nk_buffer*, enum nk_buffer_allocation_type type, const void *memory, nk_size size, nk_size align); NK_API void nk_buffer_mark(struct nk_buffer*, enum nk_buffer_allocation_type type); NK_API void nk_buffer_reset(struct nk_buffer*, enum nk_buffer_allocation_type type); @@ -4248,21 +4433,21 @@ NK_API void nk_buffer_clear(struct nk_buffer*); NK_API void nk_buffer_free(struct nk_buffer*); NK_API void *nk_buffer_memory(struct nk_buffer*); NK_API const void *nk_buffer_memory_const(const struct nk_buffer*); -NK_API nk_size nk_buffer_total(struct nk_buffer*); +NK_API nk_size nk_buffer_total(const struct nk_buffer*); -/* ============================================================== +/** ============================================================== * * STRING * * ===============================================================*/ -/* Basic string buffer which is only used in context with the text editor +/** Basic string buffer which is only used in context with the text editor * to manage and manipulate dynamic or fixed size string content. This is _NOT_ * the default string handling method. The only instance you should have any contact * with this API is if you interact with an `nk_text_edit` object inside one of the * copy and paste functions and even there only for more advanced cases. */ struct nk_str { struct nk_buffer buffer; - int len; /* in codepoints/runes/glyphs */ + int len; /**!< in codepoints/runes/glyphs */ }; #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR @@ -4303,38 +4488,40 @@ NK_API const char *nk_str_at_const(const struct nk_str*, int pos, nk_rune *unico NK_API char *nk_str_get(struct nk_str*); NK_API const char *nk_str_get_const(const struct nk_str*); -NK_API int nk_str_len(struct nk_str*); -NK_API int nk_str_len_char(struct nk_str*); +NK_API int nk_str_len(const struct nk_str*); +NK_API int nk_str_len_char(const struct nk_str*); -/*=============================================================== +/**=============================================================== * * TEXT EDITOR * * ===============================================================*/ -/*/// ### Text Editor -/// Editing text in this library is handled by either `nk_edit_string` or -/// `nk_edit_buffer`. But like almost everything in this library there are multiple -/// ways of doing it and a balance between control and ease of use with memory -/// as well as functionality controlled by flags. -/// -/// This library generally allows three different levels of memory control: -/// First of is the most basic way of just providing a simple char array with -/// string length. This method is probably the easiest way of handling simple -/// user text input. Main upside is complete control over memory while the biggest -/// downside in comparison with the other two approaches is missing undo/redo. -/// -/// For UIs that require undo/redo the second way was created. It is based on -/// a fixed size nk_text_edit struct, which has an internal undo/redo stack. -/// This is mainly useful if you want something more like a text editor but don't want -/// to have a dynamically growing buffer. -/// -/// The final way is using a dynamically growing nk_text_edit struct, which -/// has both a default version if you don't care where memory comes from and an -/// allocator version if you do. While the text editor is quite powerful for its -/// complexity I would not recommend editing gigabytes of data with it. -/// It is rather designed for uses cases which make sense for a GUI library not for -/// an full blown text editor. +/** + * \page Text Editor + * Editing text in this library is handled by either `nk_edit_string` or + * `nk_edit_buffer`. But like almost everything in this library there are multiple + * ways of doing it and a balance between control and ease of use with memory + * as well as functionality controlled by flags. + * + * This library generally allows three different levels of memory control: + * First of is the most basic way of just providing a simple char array with + * string length. This method is probably the easiest way of handling simple + * user text input. Main upside is complete control over memory while the biggest + * downside in comparison with the other two approaches is missing undo/redo. + * + * For UIs that require undo/redo the second way was created. It is based on + * a fixed size nk_text_edit struct, which has an internal undo/redo stack. + * This is mainly useful if you want something more like a text editor but don't want + * to have a dynamically growing buffer. + * + * The final way is using a dynamically growing nk_text_edit struct, which + * has both a default version if you don't care where memory comes from and an + * allocator version if you do. While the text editor is quite powerful for its + * complexity I would not recommend editing gigabytes of data with it. + * It is rather designed for uses cases which make sense for a GUI library not for + * an full blown text editor. */ + #ifndef NK_TEXTEDIT_UNDOSTATECOUNT #define NK_TEXTEDIT_UNDOSTATECOUNT 99 #endif @@ -4397,7 +4584,7 @@ struct nk_text_edit { struct nk_text_undo_state undo; }; -/* filter function */ +/** filter function */ NK_API nk_bool nk_filter_default(const struct nk_text_edit*, nk_rune unicode); NK_API nk_bool nk_filter_ascii(const struct nk_text_edit*, nk_rune unicode); NK_API nk_bool nk_filter_float(const struct nk_text_edit*, nk_rune unicode); @@ -4406,11 +4593,11 @@ NK_API nk_bool nk_filter_hex(const struct nk_text_edit*, nk_rune unicode); NK_API nk_bool nk_filter_oct(const struct nk_text_edit*, nk_rune unicode); NK_API nk_bool nk_filter_binary(const struct nk_text_edit*, nk_rune unicode); -/* text editor */ +/** text editor */ #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR NK_API void nk_textedit_init_default(struct nk_text_edit*); #endif -NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size); +NK_API void nk_textedit_init(struct nk_text_edit*, const struct nk_allocator*, nk_size size); NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size); NK_API void nk_textedit_free(struct nk_text_edit*); NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len); @@ -4427,53 +4614,55 @@ NK_API void nk_textedit_redo(struct nk_text_edit*); * DRAWING * * ===============================================================*/ -/*/// ### Drawing -/// This library was designed to be render backend agnostic so it does -/// not draw anything to screen. Instead all drawn shapes, widgets -/// are made of, are buffered into memory and make up a command queue. -/// Each frame therefore fills the command buffer with draw commands -/// that then need to be executed by the user and his own render backend. -/// After that the command buffer needs to be cleared and a new frame can be -/// started. It is probably important to note that the command buffer is the main -/// drawing API and the optional vertex buffer API only takes this format and -/// converts it into a hardware accessible format. -/// -/// To use the command queue to draw your own widgets you can access the -/// command buffer of each window by calling `nk_window_get_canvas` after -/// previously having called `nk_begin`: -/// -/// ```c -/// void draw_red_rectangle_widget(struct nk_context *ctx) -/// { -/// struct nk_command_buffer *canvas; -/// struct nk_input *input = &ctx->input; -/// canvas = nk_window_get_canvas(ctx); -/// -/// struct nk_rect space; -/// enum nk_widget_layout_states state; -/// state = nk_widget(&space, ctx); -/// if (!state) return; -/// -/// if (state != NK_WIDGET_ROM) -/// update_your_widget_by_user_input(...); -/// nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); -/// } -/// -/// if (nk_begin(...)) { -/// nk_layout_row_dynamic(ctx, 25, 1); -/// draw_red_rectangle_widget(ctx); -/// } -/// nk_end(..) -/// -/// ``` -/// Important to know if you want to create your own widgets is the `nk_widget` -/// call. It allocates space on the panel reserved for this widget to be used, -/// but also returns the state of the widget space. If your widget is not seen and does -/// not have to be updated it is '0' and you can just return. If it only has -/// to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both -/// update and draw your widget. The reason for separating is to only draw and -/// update what is actually necessary which is crucial for performance. -*/ +/** + * \page Drawing + * This library was designed to be render backend agnostic so it does + * not draw anything to screen. Instead all drawn shapes, widgets + * are made of, are buffered into memory and make up a command queue. + * Each frame therefore fills the command buffer with draw commands + * that then need to be executed by the user and his own render backend. + * After that the command buffer needs to be cleared and a new frame can be + * started. It is probably important to note that the command buffer is the main + * drawing API and the optional vertex buffer API only takes this format and + * converts it into a hardware accessible format. + * + * To use the command queue to draw your own widgets you can access the + * command buffer of each window by calling `nk_window_get_canvas` after + * previously having called `nk_begin`: + * + * ```c + * void draw_red_rectangle_widget(struct nk_context *ctx) + * { + * struct nk_command_buffer *canvas; + * struct nk_input *input = &ctx->input; + * canvas = nk_window_get_canvas(ctx); + * + * struct nk_rect space; + * enum nk_widget_layout_states state; + * state = nk_widget(&space, ctx); + * if (!state) return; + * + * if (state != NK_WIDGET_ROM) + * update_your_widget_by_user_input(...); + * nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); + * } + * + * if (nk_begin(...)) { + * nk_layout_row_dynamic(ctx, 25, 1); + * draw_red_rectangle_widget(ctx); + * } + * nk_end(..) + * + * ``` + * Important to know if you want to create your own widgets is the `nk_widget` + * call. It allocates space on the panel reserved for this widget to be used, + * but also returns the state of the widget space. If your widget is not seen and does + * not have to be updated it is '0' and you can just return. If it only has + * to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both + * update and draw your widget. The reason for separating is to only draw and + * update what is actually necessary which is crucial for performance. + */ + enum nk_command_type { NK_COMMAND_NOP, NK_COMMAND_SCISSOR, @@ -4496,7 +4685,7 @@ enum nk_command_type { NK_COMMAND_CUSTOM }; -/* command base and header of every command inside the buffer */ + /** command base and header of every command inside the buffer */ struct nk_command { enum nk_command_type type; nk_size next; @@ -4670,25 +4859,25 @@ struct nk_command_buffer { nk_size begin, end, last; }; -/* shape outlines */ +/** shape outlines */ NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color); NK_API void nk_stroke_curve(struct nk_command_buffer*, float, float, float, float, float, float, float, float, float line_thickness, struct nk_color); NK_API void nk_stroke_rect(struct nk_command_buffer*, struct nk_rect, float rounding, float line_thickness, struct nk_color); NK_API void nk_stroke_circle(struct nk_command_buffer*, struct nk_rect, float line_thickness, struct nk_color); NK_API void nk_stroke_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, struct nk_color); NK_API void nk_stroke_triangle(struct nk_command_buffer*, float, float, float, float, float, float, float line_thichness, struct nk_color); -NK_API void nk_stroke_polyline(struct nk_command_buffer*, float *points, int point_count, float line_thickness, struct nk_color col); -NK_API void nk_stroke_polygon(struct nk_command_buffer*, float*, int point_count, float line_thickness, struct nk_color); +NK_API void nk_stroke_polyline(struct nk_command_buffer*, const float *points, int point_count, float line_thickness, struct nk_color col); +NK_API void nk_stroke_polygon(struct nk_command_buffer*, const float *points, int point_count, float line_thickness, struct nk_color); -/* filled shades */ +/** filled shades */ NK_API void nk_fill_rect(struct nk_command_buffer*, struct nk_rect, float rounding, struct nk_color); NK_API void nk_fill_rect_multi_color(struct nk_command_buffer*, struct nk_rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom); NK_API void nk_fill_circle(struct nk_command_buffer*, struct nk_rect, struct nk_color); NK_API void nk_fill_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, struct nk_color); NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0, float x1, float y1, float x2, float y2, struct nk_color); -NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, struct nk_color); +NK_API void nk_fill_polygon(struct nk_command_buffer*, const float *points, int point_count, struct nk_color); -/* misc */ +/** misc */ NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); NK_API void nk_draw_nine_slice(struct nk_command_buffer*, struct nk_rect, const struct nk_nine_slice*, struct nk_color); NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect, const char *text, int len, const struct nk_user_font*, struct nk_color, struct nk_color); @@ -4757,30 +4946,30 @@ NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys); * * ===============================================================*/ #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT -/* ### Draw List -/// The optional vertex buffer draw list provides a 2D drawing context -/// with antialiasing functionality which takes basic filled or outlined shapes -/// or a path and outputs vertexes, elements and draw commands. -/// The actual draw list API is not required to be used directly while using this -/// library since converting the default library draw command output is done by -/// just calling `nk_convert` but I decided to still make this library accessible -/// since it can be useful. -/// -/// The draw list is based on a path buffering and polygon and polyline -/// rendering API which allows a lot of ways to draw 2D content to screen. -/// In fact it is probably more powerful than needed but allows even more crazy -/// things than this library provides by default. -*/ +/** + * \page "Draw List" + * The optional vertex buffer draw list provides a 2D drawing context + * with antialiasing functionality which takes basic filled or outlined shapes + * or a path and outputs vertexes, elements and draw commands. + * The actual draw list API is not required to be used directly while using this + * library since converting the default library draw command output is done by + * just calling `nk_convert` but I decided to still make this library accessible + * since it can be useful. + * + * The draw list is based on a path buffering and polygon and polyline + * rendering API which allows a lot of ways to draw 2D content to screen. + * In fact it is probably more powerful than needed but allows even more crazy + * things than this library provides by default. + */ + #ifdef NK_UINT_DRAW_INDEX typedef nk_uint nk_draw_index; #else typedef nk_ushort nk_draw_index; #endif enum nk_draw_list_stroke { - NK_STROKE_OPEN = nk_false, - /* build up path has no connection back to the beginning */ - NK_STROKE_CLOSED = nk_true - /* build up path has a connection back to the beginning */ + NK_STROKE_OPEN = nk_false, /***< build up path has no connection back to the beginning */ + NK_STROKE_CLOSED = nk_true /***< build up path has a connection back to the beginning */ }; enum nk_draw_vertex_layout_attribute { @@ -4826,12 +5015,9 @@ struct nk_draw_vertex_layout_element { }; struct nk_draw_command { - unsigned int elem_count; - /* number of elements in the current draw batch */ - struct nk_rect clip_rect; - /* current screen clipping rectangle */ - nk_handle texture; - /* current texture to set */ + unsigned int elem_count; /**< number of elements in the current draw batch */ + struct nk_rect clip_rect; /**< current screen clipping rectangle */ + nk_handle texture; /**< current texture to set */ #ifdef NK_INCLUDE_COMMAND_USERDATA nk_handle userdata; #endif @@ -5075,6 +5261,39 @@ struct nk_style_slider { void(*draw_end)(struct nk_command_buffer*, nk_handle); }; +struct nk_style_knob { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* knob */ + struct nk_color knob_normal; + struct nk_color knob_hover; + struct nk_color knob_active; + struct nk_color knob_border_color; + + /* cursor */ + struct nk_color cursor_normal; + struct nk_color cursor_hover; + struct nk_color cursor_active; + + /* properties */ + float border; + float knob_border; + struct nk_vec2 padding; + struct nk_vec2 spacing; + float cursor_width; + float color_factor; + float disabled_factor; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + struct nk_style_progress { /* background */ struct nk_style_item normal; @@ -5220,6 +5439,7 @@ struct nk_style_chart { struct nk_vec2 padding; float color_factor; float disabled_factor; + nk_bool show_markers; }; struct nk_style_combo { @@ -5360,6 +5580,7 @@ struct nk_style { struct nk_style_toggle checkbox; struct nk_style_selectable selectable; struct nk_style_slider slider; + struct nk_style_knob knob; struct nk_style_progress progress; struct nk_style_property property; struct nk_style_edit edit; @@ -5410,6 +5631,7 @@ struct nk_chart_slot { int count; struct nk_vec2 last; int index; + nk_bool show_markers; }; struct nk_chart { @@ -5488,20 +5710,13 @@ struct nk_panel { struct nk_table; enum nk_window_flags { NK_WINDOW_PRIVATE = NK_FLAG(11), - NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, - /* special window type growing up in height while being filled to a certain maximum height */ - NK_WINDOW_ROM = NK_FLAG(12), - /* sets window widgets into a read only mode and does not allow input changes */ - NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM|NK_WINDOW_NO_INPUT, - /* prevents all interaction caused by input to either window or widgets inside */ - NK_WINDOW_HIDDEN = NK_FLAG(13), - /* Hides window and stops any window interaction and drawing */ - NK_WINDOW_CLOSED = NK_FLAG(14), - /* Directly closes and frees the window at the end of the frame */ - NK_WINDOW_MINIMIZED = NK_FLAG(15), - /* marks the window as minimized */ - NK_WINDOW_REMOVE_ROM = NK_FLAG(16) - /* Removes read only mode at the end of the window */ + NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, /**< special window type growing up in height while being filled to a certain maximum height */ + NK_WINDOW_ROM = NK_FLAG(12), /**< sets window widgets into a read only mode and does not allow input changes */ + NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM|NK_WINDOW_NO_INPUT, /**< prevents all interaction caused by input to either window or widgets inside */ + NK_WINDOW_HIDDEN = NK_FLAG(13), /**< Hides window and stops any window interaction and drawing */ + NK_WINDOW_CLOSED = NK_FLAG(14), /**< Directly closes and frees the window at the end of the frame */ + NK_WINDOW_MINIMIZED = NK_FLAG(15), /**< marks the window as minimized */ + NK_WINDOW_REMOVE_ROM = NK_FLAG(16) /**< Removes read only mode at the end of the window */ }; struct nk_popup_state { @@ -5573,29 +5788,32 @@ struct nk_window { /*============================================================== * STACK * =============================================================*/ -/*/// ### Stack -/// The style modifier stack can be used to temporarily change a -/// property inside `nk_style`. For example if you want a special -/// red button you can temporarily push the old button color onto a stack -/// draw the button with a red color and then you just pop the old color -/// back from the stack: -/// -/// nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); -/// nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); -/// nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); -/// nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); -/// -/// nk_button(...); -/// -/// nk_style_pop_style_item(ctx); -/// nk_style_pop_style_item(ctx); -/// nk_style_pop_style_item(ctx); -/// nk_style_pop_vec2(ctx); -/// -/// Nuklear has a stack for style_items, float properties, vector properties, -/// flags, colors, fonts and for button_behavior. Each has it's own fixed size stack -/// which can be changed at compile time. +/** + * \page Stack + * # Stack + * The style modifier stack can be used to temporarily change a + * property inside `nk_style`. For example if you want a special + * red button you can temporarily push the old button color onto a stack + * draw the button with a red color and then you just pop the old color + * back from the stack: + * + * nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); + * nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); + * nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); + * nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); + * + * nk_button(...); + * + * nk_style_pop_style_item(ctx); + * nk_style_pop_style_item(ctx); + * nk_style_pop_style_item(ctx); + * nk_style_pop_vec2(ctx); + * + * Nuklear has a stack for style_items, float properties, vector properties, + * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack + * which can be changed at compile time. */ + #ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE #define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 #endif @@ -5725,15 +5943,15 @@ struct nk_context { #ifdef NK_INCLUDE_COMMAND_USERDATA nk_handle userdata; #endif - /* text editor objects are quite big because of an internal + /** text editor objects are quite big because of an internal * undo/redo stack. Therefore it does not make sense to have one for * each window for temporary use cases, so I only provide *one* instance * for all windows. This works because the content is cleared anyway */ struct nk_text_edit text_edit; - /* draw buffer used for overlay drawing operation like cursor */ + /** draw buffer used for overlay drawing operation like cursor */ struct nk_command_buffer overlay; - /* windows */ + /** windows */ int build; int use_pool; struct nk_pool pool; @@ -5750,6 +5968,7 @@ struct nk_context { * MATH * =============================================================== */ #define NK_PI 3.141592654f +#define NK_PI_HALF 1.570796326f #define NK_UTF_INVALID 0xFFFD #define NK_MAX_FLOAT_PRECISION 2 @@ -5798,7 +6017,7 @@ struct nk_context { #define NK_ALIGN_PTR_BACK(x, mask)\ (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) -#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__) +#if ((defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)) && !defined(EMSCRIPTEN) #define NK_OFFSETOF(st,m) (__builtin_offsetof(st,m)) #else #define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) @@ -5933,6 +6152,12 @@ NK_LIB float nk_sin(float x); #ifndef NK_COS NK_LIB float nk_cos(float x); #endif +#ifndef NK_ATAN +NK_LIB float nk_atan(float x); +#endif +#ifndef NK_ATAN2 +NK_LIB float nk_atan2(float y, float x); +#endif NK_LIB nk_uint nk_round_up_pow2(nk_uint v); NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount); NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad); @@ -5942,6 +6167,7 @@ NK_LIB int nk_ifloord(double x); NK_LIB int nk_ifloorf(float x); NK_LIB int nk_iceilf(float x); NK_LIB int nk_log10(double n); +NK_LIB float nk_roundf(float x); /* util */ enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE}; @@ -5968,7 +6194,7 @@ NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct nk_user_font *f NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args); #endif #ifdef NK_INCLUDE_STANDARD_IO -NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc); +NK_LIB char *nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc); #endif /* buffer */ @@ -6009,11 +6235,11 @@ enum nk_window_insert_location { NK_LIB void *nk_create_window(struct nk_context *ctx); NK_LIB void nk_remove_window(struct nk_context*, struct nk_window*); NK_LIB void nk_free_window(struct nk_context *ctx, struct nk_window *win); -NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name); +NK_LIB struct nk_window *nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name); NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc); /* pool */ -NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity); +NK_LIB void nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, unsigned int capacity); NK_LIB void nk_pool_free(struct nk_pool *pool); NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size); NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool); @@ -6029,7 +6255,7 @@ NK_LIB void nk_remove_table(struct nk_window *win, struct nk_table *tbl); NK_LIB void nk_free_table(struct nk_context *ctx, struct nk_table *tbl); NK_LIB void nk_push_table(struct nk_window *win, struct nk_table *tbl); NK_LIB nk_uint *nk_add_value(struct nk_context *ctx, struct nk_window *win, nk_hash name, nk_uint value); -NK_LIB nk_uint *nk_find_value(struct nk_window *win, nk_hash name); +NK_LIB nk_uint *nk_find_value(const struct nk_window *win, nk_hash name); /* panel */ NK_LIB void *nk_create_panel(struct nk_context *ctx); @@ -6050,7 +6276,7 @@ NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, flo NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win); NK_LIB void nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_window *win, int modify); NK_LIB void nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx); -NK_LIB void nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx); +NK_LIB void nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx); /* popup */ NK_LIB nk_bool nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type); @@ -6202,7 +6428,6 @@ nk_stbtt_free(void *ptr, void *user_data) { - /* =============================================================== * * MATH @@ -6286,6 +6511,52 @@ nk_cos(float x) return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8))))))); } #endif +#ifndef NK_ATAN +#define NK_ATAN nk_atan +NK_LIB float +nk_atan(float x) +{ + /* ./lolremez --progress --float -d 9 -r "0:pi*2" "atan(x)" */ + float u = -1.0989005e-05f; + NK_ASSERT(x >= 0.0f && "TODO support negative floats"); + u = u * x + 0.00034117949f; + u = u * x + -0.0044932296f; + u = u * x + 0.032596264f; + u = u * x + -0.14088021f; + u = u * x + 0.36040401f; + u = u * x + -0.47017866f; + u = u * x + 0.00050198776f; + u = u * x + 1.0077682f; + u = u * x + -0.0004765437f; + return u; +} +#endif +#ifndef NK_ATAN2 +#define NK_ATAN2 nk_atan2 +NK_LIB float +nk_atan2(float y, float x) +{ + float ax = NK_ABS(x), + ay = NK_ABS(y); + /* 0 = +y +x 1 = -y +x + 2 = +y -x 3 = -y -x */ + nk_uint signs = (y < 0) | ((x < 0) << 1); + + float a; + if(y == 0.0 && x == 0.0) return 0.0f; + a = (ay > ax) + ? NK_PI_HALF - NK_ATAN(ax / ay) + : NK_ATAN(ay / ax); + + switch(signs){ + case 0: return a; + case 1: return -a; + case 2: return -a + NK_PI; + case 3: return a - NK_PI; + } + return 0.0f; /* prevents warning */ +} +#endif NK_LIB nk_uint nk_round_up_pow2(nk_uint v) { @@ -6353,6 +6624,11 @@ nk_log10(double n) if (neg) exp = -exp; return exp; } +NK_LIB float +nk_roundf(float x) +{ + return (x >= 0.0f) ? (float)nk_ifloorf(x + 0.5f) : (float)nk_iceilf(x - 0.5f); +} NK_API struct nk_rect nk_get_null_rect(void) { @@ -6647,7 +6923,7 @@ nk_strlen(const char *str) return siz; } NK_API int -nk_strtoi(const char *str, const char **endptr) +nk_strtoi(const char *str, char **endptr) { int neg = 1; const char *p = str; @@ -6667,15 +6943,15 @@ nk_strtoi(const char *str, const char **endptr) p++; } if (endptr) - *endptr = p; + *endptr = (char *)p; return neg*value; } NK_API double -nk_strtod(const char *str, const char **endptr) +nk_strtod(const char *str, char **endptr) { double m; double neg = 1.0; - const char *p = str; + char *p = (char *)str; double value = 0; double number = 0; @@ -6728,7 +7004,7 @@ nk_strtod(const char *str, const char **endptr) return number; } NK_API float -nk_strtof(const char *str, const char **endptr) +nk_strtof(const char *str, char **endptr) { float float_value; double double_value; @@ -7139,7 +7415,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) /* width argument */ width = NK_DEFAULT; if (*iter >= '1' && *iter <= '9') { - const char *end; + char *end; width = nk_strtoi(iter, &end); if (end == iter) width = -1; @@ -7157,7 +7433,7 @@ nk_vsnprintf(char *buf, int buf_size, const char *fmt, va_list args) precision = va_arg(args, int); iter++; } else { - const char *end; + char *end; precision = nk_strtoi(iter, &end); if (end == iter) precision = -1; @@ -7490,7 +7766,7 @@ nk_murmur_hash(const void * key, int len, nk_hash seed) } #ifdef NK_INCLUDE_STANDARD_IO NK_LIB char* -nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc) +nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc) { char *buf; FILE *fd; @@ -7658,7 +7934,7 @@ nk_parse_hex(const char *p, int length) return i; } NK_API struct nk_color -nk_rgb_factor(struct nk_color col, const float factor) +nk_rgb_factor(struct nk_color col, float factor) { if (factor == 1.0f) return col; @@ -7881,7 +8157,7 @@ nk_hsva_colorf(float h, float s, float v, float a) return out; } NK_API struct nk_colorf -nk_hsva_colorfv(float *c) +nk_hsva_colorfv(const float *c) { return nk_hsva_colorf(c[0], c[1], c[2], c[3]); } @@ -8060,7 +8336,6 @@ nk_color_hsv_bv(nk_byte *out, struct nk_color in) - /* =============================================================== * * UTF-8 @@ -8447,7 +8722,7 @@ nk_buffer_free(struct nk_buffer *b) b->pool.free(b->pool.userdata, b->memory.ptr); } NK_API void -nk_buffer_info(struct nk_memory_status *s, struct nk_buffer *b) +nk_buffer_info(struct nk_memory_status *s, const struct nk_buffer *b) { NK_ASSERT(b); NK_ASSERT(s); @@ -8473,7 +8748,7 @@ nk_buffer_memory_const(const struct nk_buffer *buffer) return buffer->memory.ptr; } NK_API nk_size -nk_buffer_total(struct nk_buffer *buffer) +nk_buffer_total(const struct nk_buffer *buffer) { NK_ASSERT(buffer); if (!buffer) return 0; @@ -8483,7 +8758,6 @@ nk_buffer_total(struct nk_buffer *buffer) - /* =============================================================== * * STRING @@ -8902,14 +9176,14 @@ nk_str_get_const(const struct nk_str *s) return (const char*)s->buffer.memory.ptr; } NK_API int -nk_str_len(struct nk_str *s) +nk_str_len(const struct nk_str *s) { NK_ASSERT(s); if (!s || !s->len || !s->buffer.allocated) return 0; return s->len; } NK_API int -nk_str_len_char(struct nk_str *s) +nk_str_len_char(const struct nk_str *s) { NK_ASSERT(s); if (!s || !s->len || !s->buffer.allocated) return 0; @@ -8933,7 +9207,6 @@ nk_str_free(struct nk_str *str) - /* ============================================================== * * DRAW @@ -9262,7 +9535,7 @@ nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, cmd->color = c; } NK_API void -nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count, +nk_stroke_polygon(struct nk_command_buffer *b, const float *points, int point_count, float line_thickness, struct nk_color col) { int i; @@ -9283,7 +9556,7 @@ nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count, } } NK_API void -nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count, +nk_fill_polygon(struct nk_command_buffer *b, const float *points, int point_count, struct nk_color col) { int i; @@ -9304,7 +9577,7 @@ nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count, } } NK_API void -nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count, +nk_stroke_polyline(struct nk_command_buffer *b, const float *points, int point_count, float line_thickness, struct nk_color col) { int i; @@ -9492,7 +9765,6 @@ nk_draw_text(struct nk_command_buffer *b, struct nk_rect r, - /* =============================================================== * * VERTEX @@ -9688,14 +9960,16 @@ nk_draw_list_push_image(struct nk_draw_list *list, nk_handle texture) struct nk_draw_command *prev = nk_draw_list_command_last(list); if (prev->elem_count == 0) { prev->texture = texture; - #ifdef NK_INCLUDE_COMMAND_USERDATA + #ifdef NK_INCLUDE_COMMAND_USERDATA prev->userdata = list->userdata; - #endif - } else if (prev->texture.id != texture.id - #ifdef NK_INCLUDE_COMMAND_USERDATA - || prev->userdata.id != list->userdata.id - #endif - ) nk_draw_list_push_command(list, prev->clip_rect, texture); + #endif + } else if (prev->texture.id != texture.id + #ifdef NK_INCLUDE_COMMAND_USERDATA + || prev->userdata.id != list->userdata.id + #endif + ) { + nk_draw_list_push_command(list, prev->clip_rect, texture); + } } } #ifdef NK_INCLUDE_COMMAND_USERDATA @@ -11142,7 +11416,7 @@ static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0 if (node->y > min_y) { /* raise min_y higher. */ /* we've accounted for all waste up to min_y, */ - /* but we'll now add more waste for everything we've visted */ + /* but we'll now add more waste for everything we've visited */ waste_area += visited_width * (node->y - min_y); min_y = node->y; /* the first time through, visited_width might be reduced */ @@ -11297,7 +11571,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i /* insert the new node into the right starting point, and */ /* let 'cur' point to the remaining nodes needing to be */ - /* stiched back in */ + /* stitched back in */ cur = *res.prev_link; if (cur->x < res.x) { @@ -16679,7 +16953,7 @@ nk_font_baker_memory(nk_size *temp, int *glyph_count, *temp += nk_build_align + nk_baker_align; } NK_INTERN struct nk_font_baker* -nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc) +nk_font_baker(void *memory, int glyph_count, int count, const struct nk_allocator *alloc) { struct nk_font_baker *baker; if (!memory) return 0; @@ -16696,7 +16970,7 @@ NK_INTERN int nk_font_bake_pack(struct nk_font_baker *baker, nk_size *image_memory, int *width, int *height, struct nk_recti *custom, const struct nk_font_config *config_list, int count, - struct nk_allocator *alloc) + const struct nk_allocator *alloc) { NK_STORAGE const nk_size max_height = 1024 * 32; const struct nk_font_config *config_iter, *it; @@ -16725,7 +16999,7 @@ nk_font_bake_pack(struct nk_font_baker *baker, it = config_iter; do { struct stbtt_fontinfo *font_info = &baker->build[i++].info; - font_info->userdata = alloc; + font_info->userdata = (void*)alloc; if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0))) return nk_false; @@ -16733,7 +17007,7 @@ nk_font_bake_pack(struct nk_font_baker *baker, } *height = 0; *width = (total_glyph_count > 1000) ? 1024 : 512; - stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc); + stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, (void*)alloc); { int input_i = 0; int range_n = 0; @@ -17037,7 +17311,7 @@ nk_font_query_font_glyph(nk_handle handle, float height, } #endif NK_API const struct nk_font_glyph* -nk_font_find_glyph(struct nk_font *font, nk_rune unicode) +nk_font_find_glyph(const struct nk_font *font, nk_rune unicode) { int i = 0; int count; @@ -17100,8 +17374,8 @@ nk_font_init(struct nk_font *font, float pixel_height, * * ProggyClean.ttf * Copyright (c) 2004, 2005 Tristan Grimmer - * MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) - * Download and more information at http://upperbounds.net + * MIT license https://github.com/bluescan/proggyfonts/blob/master/LICENSE + * Download and more information at https://github.com/bluescan/proggyfonts *-----------------------------------------------------------------------------*/ #ifdef __clang__ #pragma clang diagnostic push @@ -17426,7 +17700,7 @@ nk_font_atlas_init_default(struct nk_font_atlas *atlas) } #endif NK_API void -nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc) +nk_font_atlas_init(struct nk_font_atlas *atlas, const struct nk_allocator *alloc) { NK_ASSERT(atlas); NK_ASSERT(alloc); @@ -17437,7 +17711,7 @@ nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc) } NK_API void nk_font_atlas_init_custom(struct nk_font_atlas *atlas, - struct nk_allocator *permanent, struct nk_allocator *temporary) + const struct nk_allocator *permanent, const struct nk_allocator *temporary) { NK_ASSERT(atlas); NK_ASSERT(permanent); @@ -17907,7 +18181,6 @@ nk_font_atlas_clear(struct nk_font_atlas *atlas) - /* =============================================================== * * INPUT @@ -18211,13 +18484,13 @@ NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0) NK_COLOR(NK_COLOR_TOGGLE_HOVER, 120,120,120,255) \ NK_COLOR(NK_COLOR_TOGGLE_CURSOR, 45, 45, 45, 255) \ NK_COLOR(NK_COLOR_SELECT, 45, 45, 45, 255) \ - NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \ + NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \ NK_COLOR(NK_COLOR_SLIDER, 38, 38, 38, 255) \ NK_COLOR(NK_COLOR_SLIDER_CURSOR, 100,100,100,255) \ NK_COLOR(NK_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \ NK_COLOR(NK_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \ NK_COLOR(NK_COLOR_PROPERTY, 38, 38, 38, 255) \ - NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \ + NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \ NK_COLOR(NK_COLOR_EDIT_CURSOR, 175,175,175,255) \ NK_COLOR(NK_COLOR_COMBO, 45, 45, 45, 255) \ NK_COLOR(NK_COLOR_CHART, 120,120,120,255) \ @@ -18227,7 +18500,11 @@ NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0) NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \ NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \ NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \ - NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) + NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) \ + NK_COLOR(NK_COLOR_KNOB, 38, 38, 38, 255) \ + NK_COLOR(NK_COLOR_KNOB_CURSOR, 100,100,100,255) \ + NK_COLOR(NK_COLOR_KNOB_CURSOR_HOVER, 120,120,120,255) \ + NK_COLOR(NK_COLOR_KNOB_CURSOR_ACTIVE, 150,150,150,255) NK_GLOBAL const struct nk_color nk_default_color_style[NK_COLOR_COUNT] = { @@ -18287,6 +18564,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) struct nk_style_toggle *toggle; struct nk_style_selectable *select; struct nk_style_slider *slider; + struct nk_style_knob *knob; struct nk_style_progress *prog; struct nk_style_scrollbar *scroll; struct nk_style_edit *edit; @@ -18495,6 +18773,32 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) button->draw_end = 0; style->slider.dec_button = style->slider.inc_button; + /* knob */ + knob = &style->knob; + nk_zero_struct(*knob); + knob->normal = nk_style_item_hide(); + knob->hover = nk_style_item_hide(); + knob->active = nk_style_item_hide(); + knob->knob_normal = table[NK_COLOR_KNOB]; + knob->knob_hover = table[NK_COLOR_KNOB]; + knob->knob_active = table[NK_COLOR_KNOB]; + knob->cursor_normal = table[NK_COLOR_KNOB_CURSOR]; + knob->cursor_hover = table[NK_COLOR_KNOB_CURSOR_HOVER]; + knob->cursor_active = table[NK_COLOR_KNOB_CURSOR_ACTIVE]; + + knob->knob_border_color = table[NK_COLOR_BORDER]; + knob->knob_border = 1.0f; + + knob->padding = nk_vec2(2,2); + knob->spacing = nk_vec2(2,2); + knob->cursor_width = 2; + knob->color_factor = 1.0f; + knob->disabled_factor = NK_WIDGET_DISABLED_FACTOR; + + knob->userdata = nk_handle_ptr(0); + knob->draw_begin = 0; + knob->draw_end = 0; + /* progressbar */ prog = &style->progress; nk_zero_struct(*prog); @@ -18678,6 +18982,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) chart->rounding = 0; chart->color_factor = 1.0f; chart->disabled_factor = NK_WIDGET_DISABLED_FACTOR; + chart->show_markers = nk_true; /* combo */ combo = &style->combo; @@ -19010,7 +19315,7 @@ nk_style_load_cursor(struct nk_context *ctx, enum nk_style_cursor cursor, style->cursors[cursor] = c; } NK_API void -nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors) +nk_style_load_all_cursors(struct nk_context *ctx, const struct nk_cursor *cursors) { int i = 0; struct nk_style *style; @@ -19025,7 +19330,6 @@ nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors) - /* ============================================================== * * CONTEXT @@ -19088,7 +19392,7 @@ nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, return 1; } NK_API nk_bool -nk_init(struct nk_context *ctx, struct nk_allocator *alloc, +nk_init(struct nk_context *ctx, const struct nk_allocator *alloc, const struct nk_user_font *font) { NK_ASSERT(alloc); @@ -19377,7 +19681,7 @@ nk__next(struct nk_context *ctx, const struct nk_command *cmd) * * ===============================================================*/ NK_LIB void -nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, +nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, unsigned int capacity) { NK_ASSERT(capacity >= 1); @@ -19571,7 +19875,7 @@ nk_add_value(struct nk_context *ctx, struct nk_window *win, return &win->tables->values[win->tables->size++]; } NK_LIB nk_uint* -nk_find_value(struct nk_window *win, nk_hash name) +nk_find_value(const struct nk_window *win, nk_hash name) { struct nk_table *iter = win->tables; while (iter) { @@ -19591,7 +19895,6 @@ nk_find_value(struct nk_window *win, nk_hash name) - /* =============================================================== * * PANEL @@ -19667,12 +19970,12 @@ nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type) NK_LIB nk_bool nk_panel_is_sub(enum nk_panel_type type) { - return (type & NK_PANEL_SET_SUB)?1:0; + return ((int)type & (int)NK_PANEL_SET_SUB)?1:0; } NK_LIB nk_bool nk_panel_is_nonblock(enum nk_panel_type type) { - return (type & NK_PANEL_SET_NONBLOCK)?1:0; + return ((int)type & (int)NK_PANEL_SET_NONBLOCK)?1:0; } NK_LIB nk_bool nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type panel_type) @@ -19900,7 +20203,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan nk_draw_nine_slice(out, body, &style->window.fixed_background.data.slice, nk_white); break; case NK_STYLE_ITEM_COLOR: - nk_fill_rect(out, body, 0, style->window.fixed_background.data.color); + nk_fill_rect(out, body, style->window.rounding, style->window.fixed_background.data.color); break; } } @@ -20096,7 +20399,7 @@ nk_panel_end(struct nk_context *ctx) : (window->bounds.y + window->bounds.h)); struct nk_rect b = window->bounds; b.h = padding_y - window->bounds.y; - nk_stroke_rect(out, b, 0, layout->border, border_color); + nk_stroke_rect(out, b, style->window.rounding, layout->border, border_color); } /* scaler */ @@ -20256,7 +20559,7 @@ nk_free_window(struct nk_context *ctx, struct nk_window *win) nk_free_page_element(ctx, pe);} } NK_LIB struct nk_window* -nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name) +nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name) { struct nk_window *iter; iter = ctx->begin; @@ -20565,7 +20868,7 @@ nk_window_get_height(const struct nk_context *ctx) return ctx->current->bounds.h; } NK_API struct nk_rect -nk_window_get_content_region(struct nk_context *ctx) +nk_window_get_content_region(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20573,7 +20876,7 @@ nk_window_get_content_region(struct nk_context *ctx) return ctx->current->layout->clip; } NK_API struct nk_vec2 -nk_window_get_content_region_min(struct nk_context *ctx) +nk_window_get_content_region_min(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20582,7 +20885,7 @@ nk_window_get_content_region_min(struct nk_context *ctx) return nk_vec2(ctx->current->layout->clip.x, ctx->current->layout->clip.y); } NK_API struct nk_vec2 -nk_window_get_content_region_max(struct nk_context *ctx) +nk_window_get_content_region_max(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20592,7 +20895,7 @@ nk_window_get_content_region_max(struct nk_context *ctx) ctx->current->layout->clip.y + ctx->current->layout->clip.h); } NK_API struct nk_vec2 -nk_window_get_content_region_size(struct nk_context *ctx) +nk_window_get_content_region_size(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20601,7 +20904,7 @@ nk_window_get_content_region_size(struct nk_context *ctx) return nk_vec2(ctx->current->layout->clip.w, ctx->current->layout->clip.h); } NK_API struct nk_command_buffer* -nk_window_get_canvas(struct nk_context *ctx) +nk_window_get_canvas(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20610,7 +20913,7 @@ nk_window_get_canvas(struct nk_context *ctx) return &ctx->current->buffer; } NK_API struct nk_panel* -nk_window_get_panel(struct nk_context *ctx) +nk_window_get_panel(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20618,7 +20921,7 @@ nk_window_get_panel(struct nk_context *ctx) return ctx->current->layout; } NK_API void -nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) +nk_window_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) { struct nk_window *win; NK_ASSERT(ctx); @@ -20641,7 +20944,7 @@ nk_window_has_focus(const struct nk_context *ctx) return ctx->current == ctx->active; } NK_API nk_bool -nk_window_is_hovered(struct nk_context *ctx) +nk_window_is_hovered(const struct nk_context *ctx) { NK_ASSERT(ctx); NK_ASSERT(ctx->current); @@ -20656,7 +20959,7 @@ nk_window_is_hovered(struct nk_context *ctx) } } NK_API nk_bool -nk_window_is_any_hovered(struct nk_context *ctx) +nk_window_is_any_hovered(const struct nk_context *ctx) { struct nk_window *iter; NK_ASSERT(ctx); @@ -20683,14 +20986,14 @@ nk_window_is_any_hovered(struct nk_context *ctx) return 0; } NK_API nk_bool -nk_item_is_any_active(struct nk_context *ctx) +nk_item_is_any_active(const struct nk_context *ctx) { int any_hovered = nk_window_is_any_hovered(ctx); int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); return any_hovered || any_active; } NK_API nk_bool -nk_window_is_collapsed(struct nk_context *ctx, const char *name) +nk_window_is_collapsed(const struct nk_context *ctx, const char *name) { int title_len; nk_hash title_hash; @@ -20705,7 +21008,7 @@ nk_window_is_collapsed(struct nk_context *ctx, const char *name) return win->flags & NK_WINDOW_MINIMIZED; } NK_API nk_bool -nk_window_is_closed(struct nk_context *ctx, const char *name) +nk_window_is_closed(const struct nk_context *ctx, const char *name) { int title_len; nk_hash title_hash; @@ -20720,7 +21023,7 @@ nk_window_is_closed(struct nk_context *ctx, const char *name) return (win->flags & NK_WINDOW_CLOSED); } NK_API nk_bool -nk_window_is_hidden(struct nk_context *ctx, const char *name) +nk_window_is_hidden(const struct nk_context *ctx, const char *name) { int title_len; nk_hash title_hash; @@ -20735,7 +21038,7 @@ nk_window_is_hidden(struct nk_context *ctx, const char *name) return (win->flags & NK_WINDOW_HIDDEN); } NK_API nk_bool -nk_window_is_active(struct nk_context *ctx, const char *name) +nk_window_is_active(const struct nk_context *ctx, const char *name) { int title_len; nk_hash title_hash; @@ -20750,7 +21053,7 @@ nk_window_is_active(struct nk_context *ctx, const char *name) return win == ctx->active; } NK_API struct nk_window* -nk_window_find(struct nk_context *ctx, const char *name) +nk_window_find(const struct nk_context *ctx, const char *name) { int title_len; nk_hash title_hash; @@ -20780,7 +21083,6 @@ nk_window_set_bounds(struct nk_context *ctx, if (!ctx) return; win = nk_window_find(ctx, name); if (!win) return; - NK_ASSERT(ctx->current != win && "You cannot update a currently in procecss window"); win->bounds = bounds; } NK_API void @@ -20922,7 +21224,7 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, win = ctx->current; panel = win->layout; - NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP) && "popups are not allowed to have popups"); + NK_ASSERT(!((int)panel->type & (int)NK_PANEL_SET_POPUP) && "popups are not allowed to have popups"); (void)panel; title_len = (int)nk_strlen(title); title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_POPUP); @@ -21016,7 +21318,7 @@ nk_nonblock_begin(struct nk_context *ctx, /* popups cannot have popups */ win = ctx->current; panel = win->layout; - NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP)); + NK_ASSERT(!((int)panel->type & (int)NK_PANEL_SET_POPUP)); (void)panel; popup = win->popup.win; if (!popup) { @@ -21089,7 +21391,7 @@ nk_popup_close(struct nk_context *ctx) popup = ctx->current; NK_ASSERT(popup->parent); - NK_ASSERT(popup->layout->type & NK_PANEL_SET_POPUP); + NK_ASSERT((int)popup->layout->type & (int)NK_PANEL_SET_POPUP); popup->flags |= NK_WINDOW_HIDDEN; } NK_API void @@ -21125,7 +21427,7 @@ nk_popup_end(struct nk_context *ctx) nk_push_scissor(&win->buffer, win->layout->clip); } NK_API void -nk_popup_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) +nk_popup_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) { struct nk_window *popup; @@ -21357,7 +21659,7 @@ nk_contextual_end(struct nk_context *ctx) popup = ctx->current; panel = popup->layout; NK_ASSERT(popup->parent); - NK_ASSERT(panel->type & NK_PANEL_SET_POPUP); + NK_ASSERT((int)panel->type & (int)NK_PANEL_SET_POPUP); if (panel->flags & NK_WINDOW_DYNAMIC) { /* Close behavior This is a bit of a hack solution since we do not know before we end our popup @@ -21818,7 +22120,7 @@ nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, win->layout->row.item_width = (float)width; } NK_API float -nk_layout_ratio_from_pixel(struct nk_context *ctx, float pixel_width) +nk_layout_ratio_from_pixel(const struct nk_context *ctx, float pixel_width) { struct nk_window *win; NK_ASSERT(ctx); @@ -22147,7 +22449,7 @@ nk_layout_space_push(struct nk_context *ctx, struct nk_rect rect) layout->row.item = rect; } NK_API struct nk_rect -nk_layout_space_bounds(struct nk_context *ctx) +nk_layout_space_bounds(const struct nk_context *ctx) { struct nk_rect ret; struct nk_window *win; @@ -22166,7 +22468,7 @@ nk_layout_space_bounds(struct nk_context *ctx) return ret; } NK_API struct nk_rect -nk_layout_widget_bounds(struct nk_context *ctx) +nk_layout_widget_bounds(const struct nk_context *ctx) { struct nk_rect ret; struct nk_window *win; @@ -22185,7 +22487,7 @@ nk_layout_widget_bounds(struct nk_context *ctx) return ret; } NK_API struct nk_vec2 -nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret) +nk_layout_space_to_screen(const struct nk_context *ctx, struct nk_vec2 ret) { struct nk_window *win; struct nk_panel *layout; @@ -22201,7 +22503,7 @@ nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret) return ret; } NK_API struct nk_vec2 -nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret) +nk_layout_space_to_local(const struct nk_context *ctx, struct nk_vec2 ret) { struct nk_window *win; struct nk_panel *layout; @@ -22217,7 +22519,7 @@ nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret) return ret; } NK_API struct nk_rect -nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret) +nk_layout_space_rect_to_screen(const struct nk_context *ctx, struct nk_rect ret) { struct nk_window *win; struct nk_panel *layout; @@ -22233,7 +22535,7 @@ nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret) return ret; } NK_API struct nk_rect -nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret) +nk_layout_space_rect_to_local(const struct nk_context *ctx, struct nk_rect ret) { struct nk_window *win; struct nk_panel *layout; @@ -22285,7 +22587,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, layout->bounds.w, layout->row.columns); - #define NK_FRAC(x) (x - (float)(int)x) /* will be used to remove fookin gaps */ + #define NK_FRAC(x) (x - (float)(int)nk_roundf(x)) /* will be used to remove fookin gaps */ /* calculate the width of one item inside the current layout space */ switch (layout->row.type) { case NK_LAYOUT_DYNAMIC_FIXED: { @@ -22414,7 +22716,7 @@ nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx) layout->row.index++; } NK_LIB void -nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx) +nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx) { float y; int index; @@ -23132,7 +23434,7 @@ nk_list_view_end(struct nk_list_view *view) * * ===============================================================*/ NK_API struct nk_rect -nk_widget_bounds(struct nk_context *ctx) +nk_widget_bounds(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); @@ -23143,7 +23445,7 @@ nk_widget_bounds(struct nk_context *ctx) return bounds; } NK_API struct nk_vec2 -nk_widget_position(struct nk_context *ctx) +nk_widget_position(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); @@ -23155,7 +23457,7 @@ nk_widget_position(struct nk_context *ctx) return nk_vec2(bounds.x, bounds.y); } NK_API struct nk_vec2 -nk_widget_size(struct nk_context *ctx) +nk_widget_size(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); @@ -23167,7 +23469,7 @@ nk_widget_size(struct nk_context *ctx) return nk_vec2(bounds.w, bounds.h); } NK_API float -nk_widget_width(struct nk_context *ctx) +nk_widget_width(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); @@ -23179,7 +23481,7 @@ nk_widget_width(struct nk_context *ctx) return bounds.w; } NK_API float -nk_widget_height(struct nk_context *ctx) +nk_widget_height(const struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); @@ -23191,7 +23493,7 @@ nk_widget_height(struct nk_context *ctx) return bounds.h; } NK_API nk_bool -nk_widget_is_hovered(struct nk_context *ctx) +nk_widget_is_hovered(const struct nk_context *ctx) { struct nk_rect c, v; struct nk_rect bounds; @@ -23213,7 +23515,7 @@ nk_widget_is_hovered(struct nk_context *ctx) return nk_input_is_mouse_hovering_rect(&ctx->input, bounds); } NK_API nk_bool -nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn) +nk_widget_is_mouse_clicked(const struct nk_context *ctx, enum nk_buttons btn) { struct nk_rect c, v; struct nk_rect bounds; @@ -23235,7 +23537,7 @@ nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn) return nk_input_mouse_clicked(&ctx->input, btn, bounds); } NK_API nk_bool -nk_widget_has_mouse_click_down(struct nk_context *ctx, enum nk_buttons btn, nk_bool down) +nk_widget_has_mouse_click_down(const struct nk_context *ctx, enum nk_buttons btn, nk_bool down) { struct nk_rect c, v; struct nk_rect bounds; @@ -23307,7 +23609,7 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) return NK_WIDGET_VALID; } NK_API enum nk_widget_layout_states -nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx, +nk_widget_fitting(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_vec2 item_padding) { /* update the bounds to stand without padding */ @@ -24077,6 +24379,19 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points[2].y, foreground); } break; + case NK_SYMBOL_TRIANGLE_UP_OUTLINE: + case NK_SYMBOL_TRIANGLE_DOWN_OUTLINE: + case NK_SYMBOL_TRIANGLE_LEFT_OUTLINE: + case NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE: { + enum nk_heading heading; + struct nk_vec2 points[3]; + heading = (type == NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE) ? NK_RIGHT : + (type == NK_SYMBOL_TRIANGLE_LEFT_OUTLINE) ? NK_LEFT: + (type == NK_SYMBOL_TRIANGLE_UP_OUTLINE) ? NK_UP: NK_DOWN; + nk_triangle_from_direction(points, content, 0, 0, heading); + nk_stroke_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y, + points[2].x, points[2].y, border_width, foreground); + } break; default: case NK_SYMBOL_NONE: case NK_SYMBOL_MAX: break; @@ -25740,6 +26055,257 @@ nk_slider_int(struct nk_context *ctx, int min, int *val, int max, int step) +/* =============================================================== + * + * KNOB + * + * ===============================================================*/ + +NK_LIB float +nk_knob_behavior(nk_flags *state, struct nk_input *in, + struct nk_rect bounds, float knob_min, float knob_max, float knob_value, + float knob_step, float knob_steps, + enum nk_heading zero_direction, float dead_zone_percent) +{ + struct nk_vec2 origin; + float angle = 0.0f; + origin.x = bounds.x + (bounds.w / 2); + origin.y = bounds.y + (bounds.h / 2); + + nk_widget_state_reset(state); + + /* handle click and drag input */ + if(in && + in->mouse.buttons[NK_BUTTON_LEFT].down && + nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, bounds, nk_true)){ + /* calculate angle from origin and rotate */ + const float direction_rads[4] = { + NK_PI * 2.5f, /* 90 NK_UP */ + NK_PI * 2.0f, /* 0 NK_RIGHT */ + NK_PI * 1.5f, /* 270 NK_DOWN */ + NK_PI, /* 180 NK_LEFT */ + }; + *state = NK_WIDGET_STATE_ACTIVE; + + angle = NK_ATAN2(in->mouse.pos.y - origin.y, in->mouse.pos.x - origin.x) + direction_rads[zero_direction]; + angle -= (angle > NK_PI * 2) ? NK_PI * 3 : NK_PI; + + /* account for dead space applied when drawing */ + angle *= 1.0f / (1.0f - dead_zone_percent); + angle = NK_CLAMP(-NK_PI, angle, NK_PI); + + /* convert -pi -> pi range to 0.0 -> 1.0 */ + angle = (angle + NK_PI) / (NK_PI * 2); + + /* click to closest step */ + knob_value = knob_min + ( (int)(angle * knob_steps + (knob_step / 2)) ) * knob_step; + knob_value = NK_CLAMP(knob_min, knob_value, knob_max); + } + + /* knob widget state */ + if (nk_input_is_mouse_hovering_rect(in, bounds)){ + *state = NK_WIDGET_STATE_HOVERED; + if (in) { + /* handle scroll and arrow inputs */ + if (in->mouse.scroll_delta.y > 0 || + (in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked)) + knob_value += knob_step; + + if (in->mouse.scroll_delta.y < 0 || + (in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked)) + knob_value -= knob_step; + } + knob_value = NK_CLAMP(knob_min, knob_value, knob_max); + } + if (*state & NK_WIDGET_STATE_HOVER && + !nk_input_is_mouse_prev_hovering_rect(in, bounds)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, bounds)) + *state |= NK_WIDGET_STATE_LEFT; + + return knob_value; +} +NK_LIB void +nk_draw_knob(struct nk_command_buffer *out, nk_flags state, + const struct nk_style_knob *style, const struct nk_rect *bounds, float min, float value, float max, + enum nk_heading zero_direction, float dead_zone_percent) +{ + const struct nk_style_item *background; + struct nk_color knob_color, cursor; + + NK_UNUSED(min); + NK_UNUSED(max); + NK_UNUSED(value); + + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + knob_color = style->knob_active; + cursor = style->cursor_active; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + knob_color = style->knob_hover; + cursor = style->cursor_hover; + } else { + background = &style->normal; + knob_color = style->knob_normal; + cursor = style->cursor_normal; + } + + /* draw background */ + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *bounds, 0, nk_rgb_factor(background->data.color, style->color_factor)); + nk_stroke_rect(out, *bounds, 0, style->border, nk_rgb_factor(style->border_color, style->color_factor)); + break; + } + + /* draw knob */ + nk_fill_circle(out, *bounds, nk_rgb_factor(knob_color, style->color_factor)); + if(style->knob_border > 0){ + struct nk_rect border_bounds = *bounds; + border_bounds.x += style->knob_border / 2; + border_bounds.y += style->knob_border / 2; + border_bounds.w -= style->knob_border; + border_bounds.h -= style->knob_border; + nk_stroke_circle(out, border_bounds, style->knob_border, nk_rgb_factor(style->knob_border_color, style->color_factor)); + } + { /* calculate cursor line cords */ + float half_circle_size = (bounds->w / 2); + float angle = (value - min) / (max - min); + float alive_zone = 1.0f - dead_zone_percent; + struct nk_vec2 cursor_start, cursor_end; + const float direction_rads[4] = { + NK_PI * 1.5f, /* 90 NK_UP */ + 0.0f, /* 0 NK_RIGHT */ + NK_PI * 0.5f, /* 270 NK_DOWN */ + NK_PI, /* 180 NK_LEFT */ + }; + /* calculate + apply dead zone */ + angle = (angle * alive_zone) + (dead_zone_percent / 2); + + /* percentage 0.0 -> 1.0 to radians, rads are 0.0 to (2*pi) NOT -pi to pi */ + angle *= NK_PI * 2; + + /* apply zero angle */ + angle += direction_rads[zero_direction]; + if(angle > NK_PI * 2) + angle -= NK_PI * 2; + + cursor_start.x = bounds->x + half_circle_size + (angle > NK_PI); + cursor_start.y = bounds->y + half_circle_size + (angle < NK_PI_HALF || angle > (NK_PI * 1.5f)); + + cursor_end.x = cursor_start.x + (half_circle_size * NK_COS(angle)); + cursor_end.y = cursor_start.y + (half_circle_size * NK_SIN(angle)); + + /* cut off half of the cursor */ + cursor_start.x = (cursor_start.x + cursor_end.x) / 2; + cursor_start.y = (cursor_start.y + cursor_end.y) / 2; + + /* draw cursor */ + nk_stroke_line(out, cursor_start.x, cursor_start.y, cursor_end.x, cursor_end.y, 2, nk_rgb_factor(cursor, style->color_factor)); + } +} +NK_LIB float +nk_do_knob(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + float min, float val, float max, float step, + enum nk_heading zero_direction, float dead_zone_percent, + const struct nk_style_knob *style, struct nk_input *in) +{ + float knob_range; + float knob_min; + float knob_max; + float knob_value; + float knob_steps; + + NK_ASSERT(style); + NK_ASSERT(out); + if (!out || !style) + return 0; + + /* remove padding from knob bounds */ + bounds.y = bounds.y + style->padding.y; + bounds.x = bounds.x + style->padding.x; + bounds.h = NK_MAX(bounds.h, 2*style->padding.y); + bounds.w = NK_MAX(bounds.w, 2*style->padding.x); + bounds.w -= 2 * style->padding.x; + bounds.h -= 2 * style->padding.y; + if(bounds.h < bounds.w){ + bounds.x += (bounds.w - bounds.h) / 2; + bounds.w = bounds.h; + } + + /* make sure the provided values are correct */ + knob_max = NK_MAX(min, max); + knob_min = NK_MIN(min, max); + knob_value = NK_CLAMP(knob_min, val, knob_max); + knob_range = knob_max - knob_min; + knob_steps = knob_range / step; + + knob_value = nk_knob_behavior(state, in, bounds, knob_min, knob_max, knob_value, step, knob_steps, zero_direction, dead_zone_percent); + + /* draw knob */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_knob(out, *state, style, &bounds, knob_min, knob_value, knob_max, zero_direction, dead_zone_percent); + if (style->draw_end) style->draw_end(out, style->userdata); + return knob_value; +} +NK_API nk_bool +nk_knob_float(struct nk_context *ctx, float min_value, float *value, float max_value, + float value_step, enum nk_heading zero_direction, float dead_zone_degrees) +{ + struct nk_window *win; + struct nk_panel *layout; + struct nk_input *in; + const struct nk_style *style; + + int ret = 0; + float old_value; + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + NK_ASSERT(value); + NK_ASSERT(NK_BETWEEN(dead_zone_degrees, 0.0f, 360.0f)); + if (!ctx || !ctx->current || !ctx->current->layout || !value) + return ret; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return ret; + in = (state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + + old_value = *value; + *value = nk_do_knob(&ctx->last_widget_state, &win->buffer, bounds, min_value, + old_value, max_value, value_step, zero_direction, dead_zone_degrees / 360.0f, &style->knob, in); + + return (old_value > *value || old_value < *value); +} +NK_API nk_bool +nk_knob_int(struct nk_context *ctx, int min, int *val, int max, int step, + enum nk_heading zero_direction, float dead_zone_degrees) +{ + int ret; + float value = (float)*val; + ret = nk_knob_float(ctx, (float)min, &value, (float)max, (float)step, zero_direction, dead_zone_degrees); + *val = (int)value; + return ret; +} + + + + /* =============================================================== * * PROGRESS @@ -27201,7 +27767,7 @@ nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size) nk_str_init_fixed(&state->string, memory, size); } NK_API void -nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size size) +nk_textedit_init(struct nk_text_edit *state, const struct nk_allocator *alloc, nk_size size) { NK_ASSERT(state); NK_ASSERT(alloc); @@ -28177,7 +28743,9 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property * /* draw label */ text.padding = nk_vec2(0,0); - nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + if (name && name[0] != '#') { + nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); + } } NK_LIB void nk_do_property(nk_flags *ws, @@ -28195,7 +28763,7 @@ nk_do_property(nk_flags *ws, nk_filter_float }; nk_bool active, old; - int num_len = 0, name_len; + int num_len = 0, name_len = 0; char string[NK_MAX_NUMBER_BUFFER]; float size; @@ -28215,7 +28783,9 @@ nk_do_property(nk_flags *ws, left.y = property.y + style->border + property.h/2.0f - left.h/2; /* text label */ - name_len = nk_strlen(name); + if (name && name[0] != '#') { + name_len = nk_strlen(name); + } size = font->width(font->userdata, font->height, name, name_len); label.x = left.x + left.w + style->padding.x; label.w = (float)size + 2 * style->padding.x; @@ -28322,7 +28892,7 @@ nk_do_property(nk_flags *ws, text_edit->string.buffer.memory.ptr = dst; text_edit->string.buffer.size = NK_MAX_NUMBER_BUFFER; text_edit->mode = NK_TEXT_EDIT_MODE_INSERT; - nk_do_edit(ws, out, edit, NK_EDIT_FIELD|NK_EDIT_AUTO_SELECT, + nk_do_edit(ws, out, edit, (int)NK_EDIT_FIELD|(int)NK_EDIT_AUTO_SELECT, filters[filter], text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font); *length = text_edit->string.len; @@ -28629,7 +29199,8 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); - slot->range = slot->max - slot->min;} + slot->range = slot->max - slot->min; + slot->show_markers = style->show_markers;} /* draw chart background */ background = &style->background; @@ -28681,7 +29252,8 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, slot->highlight = highlight; slot->min = NK_MIN(min_value, max_value); slot->max = NK_MAX(min_value, max_value); - slot->range = slot->max - slot->min;} + slot->range = slot->max - slot->min; + slot->show_markers = style->show_markers;} } NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type type, @@ -28728,7 +29300,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; color = g->slots[slot].highlight; } - nk_fill_rect(out, bounds, 0, color); + if (g->slots[slot].show_markers) { + nk_fill_rect(out, bounds, 0, color); + } g->slots[slot].index += 1; return ret; } @@ -28752,7 +29326,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, color = g->slots[slot].highlight; } } - nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color); + if (g->slots[slot].show_markers) { + nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color); + } /* save current data point position */ g->slots[slot].last.x = cur.x; @@ -29811,7 +30387,7 @@ NK_API void nk_combo_close(struct nk_context *ctx) nk_contextual_close(ctx); } NK_API int -nk_combo(struct nk_context *ctx, const char **items, int count, +nk_combo(struct nk_context *ctx, const char *const *items, int count, int selected, int item_height, struct nk_vec2 size) { int i = 0; @@ -29929,7 +30505,7 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c } return selected; } NK_API void -nk_combobox(struct nk_context *ctx, const char **items, int count, +nk_combobox(struct nk_context *ctx, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size) { *selected = nk_combo(ctx, items, count, *selected, item_height, size); @@ -29958,7 +30534,6 @@ nk_combobox_callback(struct nk_context *ctx, - /* =============================================================== * * TOOLTIP @@ -29982,7 +30557,7 @@ nk_tooltip_begin(struct nk_context *ctx, float width) /* make sure that no nonblocking popup is currently active */ win = ctx->current; in = &ctx->input; - if (win->popup.win && (win->popup.type & NK_PANEL_SET_NONBLOCK)) + if (win->popup.win && ((int)win->popup.type & (int)NK_PANEL_SET_NONBLOCK)) return 0; w = nk_iceilf(width); @@ -30123,6 +30698,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2024/11/20 (4.12.2) - Fix int/float type conversion warnings in `nk_roundf` +/// - 2024/03/07 (4.12.1) - Fix bitwise operations warnings in C++20 /// - 2023/11/26 (4.12.0) - Added an alignment option to checkboxes and radio buttons. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() @@ -30269,7 +30846,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// dynamic and static widgets. /// - 2016/12/31 (1.30.0) - Extended scrollbar offset from 16-bit to 32-bit. /// - 2016/12/31 (1.29.2) - Fixed closing window bug of minimized windows. -/// - 2016/12/03 (1.29.1) - Fixed wrapped text with no seperator and C89 error. +/// - 2016/12/03 (1.29.1) - Fixed wrapped text with no separator and C89 error. /// - 2016/12/03 (1.29.0) - Changed text wrapping to process words not characters. /// - 2016/11/22 (1.28.6) - Fixed window minimized closing bug. /// - 2016/11/19 (1.28.5) - Fixed abstract combo box closing behavior. @@ -30407,7 +30984,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// precision. /// - 2016/08/08 (1.07.2) - Fixed compiling error without define `NK_INCLUDE_FIXED_TYPE`. /// - 2016/08/08 (1.07.1) - Fixed possible floating point error inside `nk_widget` leading -/// to wrong wiget width calculation which results in widgets falsely +/// to wrong widget width calculation which results in widgets falsely /// becoming tagged as not inside window and cannot be accessed. /// - 2016/08/08 (1.07.0) - Nuklear now differentiates between hiding a window (NK_WINDOW_HIDDEN) and /// closing a window (NK_WINDOW_CLOSED). A window can be hidden/shown diff --git a/pgui/phobia.c b/pgui/phobia.c index 8da6ca7..6f7a6b4 100644 --- a/pgui/phobia.c +++ b/pgui/phobia.c @@ -134,9 +134,9 @@ struct public { } telemetry; - gp_t *gp; + gpcon_t *gp; - int gp_ID; + Uint32 gp_ID; char popup_msg[LINK_MESSAGE_MAX]; int popup_enum; @@ -941,12 +941,15 @@ pub_open_GP(struct public *pub, const char *file) pub->gp = gp_Alloc(); sprintf(pub->lbuf, "chunk 10\n" - "timeout 10000\n" - "load 0 0 text \"%s\"\n" + "timeout 1000\n" + "load 0 0 csv \"%s\"\n" "mkpages 0\n", file); gp_TakeConfig(pub->gp, pub->lbuf); + (void) gp_GetSurface(pub->gp); + gp_PageCombine(pub->gp, 2, GP_PAGE_SELECT); + pub->gp_ID = gp_OpenWindow(pub->gp); } @@ -3825,7 +3828,7 @@ page_application(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); - reg_enum_toggle(pub, "ap.task_AUTOSTART", "Startup at powerup"); + reg_enum_toggle(pub, "ap.task_AUTOSTART", "Startup at the power up"); reg = link_reg_lookup(lp, "ap.task_AUTOSTART"); diff --git a/src/app/autostart.c b/src/app/autostart.c index e6c5966..9ca4f2a 100644 --- a/src/app/autostart.c +++ b/src/app/autostart.c @@ -7,7 +7,7 @@ #include "main.h" #include "regfile.h" -/* The application allows you to startup PMC automatically at powerup. +/* The application allows you to startup PMC automatically at power up. * */ LD_TASK void app_AUTOSTART(void *pData) @@ -16,8 +16,8 @@ LD_TASK void app_AUTOSTART(void *pData) if (xTaskGetTickCount() >= (TickType_t) 1000) { - /* If the application task was started much later than powerup - * we will pause to give you time for flash programing. + /* If the application task was started much later than power up + * we will pause to give you time for flash programming. * */ vTaskDelay((TickType_t) 5000); } diff --git a/src/phobia/lse.h b/src/phobia/lse.h index 649c9c4..0728245 100644 --- a/src/phobia/lse.h +++ b/src/phobia/lse.h @@ -127,9 +127,9 @@ int lse_getsize(int n_cascades, int n_full); * */ void lse_construct(lse_t *ls, int n_cascades, int n_len_of_x, int n_len_of_z); -/* The function updates \rm with a new data row-vector \xz which contains \x and - * \z concatenated. We does QR update of \rm by orthogonal transformation. Note - * that the contents of \xz will be destroyed. +/* The function updates \rm with a new data row-vector \xz which contains \x + * and \z concatenated. We are doing QR update of \rm by orthogonal + * transformation. Note that the contents of \xz will be destroyed. * */ void lse_insert(lse_t *ls, lse_float_t *xz); diff --git a/src/regfile.c b/src/regfile.c index a8ff369..4efa100 100644 --- a/src/regfile.c +++ b/src/regfile.c @@ -14,7 +14,7 @@ #define REG_DEF(l, e, q, u, f, m, p, t) { #l #e "\0" u, f, m, \ (rval_t * const) &(l q), \ - (void * const) p, (void * const) t} + (void * const) p, (void * const) t } #define REGFILE_MAX (sizeof(regfile) / sizeof(reg_t) - 1U) diff --git a/src/shell.c b/src/shell.c index e427692..175cb1d 100644 --- a/src/shell.c +++ b/src/shell.c @@ -586,13 +586,13 @@ LD_TASK void task_CMDSH(void *pData) sh_line_null(sh); } - else if (c == K_DLE || c == '*') { + else if (c == K_DLE) { /* Ctrl + P. * */ sh_history(sh, DIR_UP); } - else if (c == K_SO || c == '!') { + else if (c == K_SO) { /* Ctrl + N. * */ @@ -682,7 +682,7 @@ SH_DEF(help) if (strstr(cmd->sym, s) != NULL) { - printf("%s\n", cmd->sym); + printf("%s" EOL, cmd->sym); } ++cmd;