/** * @brief Render all GUI items in a window, i.e. copy the respective images * into the draw buffer. * * @param window pointer to a ws window structure of the window to be rendered * @param items pointer to the array of items * @param till maximum index in use for the @a items, i.e. number of last item in array * @param drawbuf memory location of the @a window's draw buffer */ void RenderAll(wsWindow *window, guiItem *items, int till, char *drawbuf) { uint32_t *db; guiItem *item; guiImage *image = NULL; int dw, i, index, x; char *trans; unsigned int d; db = (uint32_t *)drawbuf; dw = window->Width; for (i = 0; i <= till; i++) { item = &items[i]; switch (item->pressed) { case btnPressed: index = 0; break; case btnReleased: index = 1; break; default: index = 2; break; } switch (item->type) { case itButton: PutImage(item->x, item->y, db, dw, &item->Bitmap, 3, index, True); break; case itPimage: PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, True); break; case itHPotmeter: PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, True); PutImage(item->x + (item->width - item->pbwidth) * item->value / 100.0, item->y, db, dw, &item->Mask, 3, index, True); break; case itVPotmeter: PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, False); PutImage(item->x, item->y + (item->height - item->pbheight) * (1.0 - item->value / 100.0), db, dw, &item->Mask, 3, index, True); break; case itRPotmeter: PutImage(item->x, item->y, db, dw, &item->Bitmap, item->numphases, (item->numphases - 1) * item->value / 100.0, True); if (item->Mask.Image) { double radius, radian; int y; // keep the button inside the potmeter outline radius = (FFMIN(item->width, item->height) - FFMAX(item->pbwidth, item->pbheight)) / 2.0; radian = item->value / 100.0 * item->arclength + item->zeropoint; // coordinates plus a correction for a non-square item // (remember: both axes are mirrored, we have a clockwise radian) x = radius * (1 + cos(radian)) + FFMAX(0, (item->width - item->height) / 2.0) + 0.5; y = radius * (1 + sin(radian)) + FFMAX(0, (item->height - item->width) / 2.0) + 0.5; PutImage(item->x + x, item->y + y, db, dw, &item->Mask, 3, index, True); } break; case itSLabel: if (item->width == -1) item->width = fntTextWidth(item->fontid, item->label); image = fntTextRender(item, 0, item->label); if (image) PutImage(item->x, item->y, db, dw, image, 1, 0, True); break; case itDLabel: trans = TranslateVariables(item->label); if (!item->text || (strcmp(item->text, trans) != 0)) { free(item->text); item->text = strdup(trans); item->textwidth = fntTextWidth(item->fontid, trans); item->starttime = GetTimerMS(); item->last_x = 0; } d = GetTimerMS() - item->starttime; if (d < DLABEL_DELAY) x = item->last_x; // don't scroll yet else { int l; char c[2]; l = (item->textwidth ? item->textwidth : item->width); x = (l ? l - ((d - DLABEL_DELAY) / 20) % l - 1 : 0); c[0] = *item->text; c[1] = 0; if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { item->starttime = GetTimerMS(); // stop again item->last_x = x; // at current x pos } } image = fntTextRender(item, x, trans); if (image) PutImage(item->x, item->y, db, dw, image, 1, 0, True); break; } } wsImageRender(window, drawbuf); }
void RenderAll(wsTWindow *window, wItem *Items, int nrItems, char *db) { wItem *item; guiImage *image = NULL; int i, ofs; image_buffer = db; image_width = window->Width; for (i = 0; i < nrItems + 1; i++) { item = &Items[i]; switch (item->pressed) { case btnPressed: ofs = 0; break; case btnReleased: ofs = 1; break; default: ofs = 2; break; } switch (item->type) { case itButton: PutImage(&item->Bitmap, item->x, item->y, 3, ofs); break; case itPotmeter: if (item->numphases == 1) SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); else PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); break; case itHPotmeter: if (item->numphases == 1) SimplePotmeterPutImage(&item->Bitmap, item->x, item->y, item->value / 100.0); else PutImage(&item->Bitmap, item->x, item->y, item->numphases, (item->numphases - 1) * (item->value / 100.0)); PutImage(&item->Mask, item->x + (item->width - item->pwidth) * (item->value / 100.0), item->y, 3, ofs); break; case itVPotmeter: PutImage(&item->Bitmap, item->x, item->y, item->numphases, item->numphases * (1.0 - item->value / 100.0)); PutImage(&item->Mask, item->x, item->y + (item->height - item->pheight) * (1.0 - item->value / 100.0), 3, ofs); break; case itSLabel: if (item->width == -1) item->width = fntTextWidth(item->fontid, item->label); image = fntTextRender(item, 0, item->label); if (image) PutImage(image, item->x, item->y, 1, 0); break; case itDLabel: { int x; unsigned int d; char *t = Translate(item->label); if (!item->text || (strcmp(item->text, t) != 0)) { free(item->text); item->text = strdup(t); item->textwidth = fntTextWidth(item->fontid, t); item->starttime = GetTimerMS(); item->last_x = 0; } d = GetTimerMS() - item->starttime; if (d < DLABEL_DELAY) x = item->last_x; // don't scroll yet else { int l; char c[2]; l = (item->textwidth ? item->textwidth : item->width); x = l - ((d - DLABEL_DELAY) / 20) % l - 1; c[0] = *item->text; c[1] = '\0'; if (x < (fntTextWidth(item->fontid, c) + 1) >> 1) { item->starttime = GetTimerMS(); // stop again item->last_x = x; // at current x pos } } image = fntTextRender(item, x, t); } if (image) PutImage(image, item->x, item->y, 1, 0); break; } } wsConvert(window, db); }