static uint8_t transform_segments(gp_pixmap *pixmap, uint8_t seg_flags) { uint8_t seg1 = seg_flags & GP_CIRCLE_SEG1; uint8_t seg2 = seg_flags & GP_CIRCLE_SEG2; uint8_t seg3 = seg_flags & GP_CIRCLE_SEG3; uint8_t seg4 = seg_flags & GP_CIRCLE_SEG4; if (pixmap->axes_swap) GP_SWAP(seg1, seg3); if (pixmap->x_swap) { GP_SWAP(seg1, seg2); GP_SWAP(seg3, seg4); } if (pixmap->y_swap) { GP_SWAP(seg1, seg4); GP_SWAP(seg2, seg3); } seg1 = seg1 ? GP_CIRCLE_SEG1 : 0; seg2 = seg2 ? GP_CIRCLE_SEG2 : 0; seg3 = seg3 ? GP_CIRCLE_SEG3 : 0; seg4 = seg4 ? GP_CIRCLE_SEG4 : 0; return seg1|seg2|seg3|seg4; }
int gp_io_writef(gp_io *io, uint16_t *types, ...) { va_list va; uint8_t *ptr, t; int32_t i4; int16_t i2; va_start(va, types); while (*types != GP_IO_END) { switch (TYPE(*types)) { case GP_IO_CONST: t = VAL(*types); if (gp_io_write(io, &t, 1) != 1) goto err; break; case GP_IO_L2: case GP_IO_B2: i2 = va_arg(va, int); ptr = (void*)&i2; if (needs_swap(*types)) GP_SWAP(ptr[0], ptr[1]); if (gp_io_write(io, ptr, 2) != 2) goto err; break; case GP_IO_L4: case GP_IO_B4: i4 = va_arg(va, int); ptr = (void*)&i4; if (needs_swap(*types)) { GP_SWAP(ptr[0], ptr[3]); GP_SWAP(ptr[1], ptr[2]); } if (gp_io_write(io, ptr, 4) != 4) goto err; break; default: GP_WARN("Invalid type %"PRIu16"\n", *types); goto err; } types++; } va_end(va); return 0; err: va_end(va); return -1; }
void GP_BlitXYXY(const GP_Context *src, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1, GP_Context *dst, GP_Coord x2, GP_Coord y2) { /* Normalize source rectangle */ if (x1 < x0) GP_SWAP(x0, x1); if (y1 < y0) GP_SWAP(y0, y1); /* All coordinates are inside of src the context */ GP_CHECK(x0 < (GP_Coord)GP_ContextW(src)); GP_CHECK(y0 < (GP_Coord)GP_ContextH(src)); GP_CHECK(x1 < (GP_Coord)GP_ContextW(src)); GP_CHECK(y1 < (GP_Coord)GP_ContextH(src)); /* Destination is big enough */ GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst)); GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst)); GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2); }
void GP_BlitXYXY_Clipped(const GP_Context *src, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1, GP_Context *dst, GP_Coord x2, GP_Coord y2) { /* Normalize source rectangle */ if (x1 < x0) GP_SWAP(x0, x1); if (y1 < y0) GP_SWAP(y0, y1); /* * Handle all cases where at least one of dest coordinates are out of * the dest in positive direction -> src is out of dst completly. */ if (x2 >= (GP_Coord)GP_ContextW(dst) || y2 >= (GP_Coord)GP_ContextH(dst)) return; /* * The coordinates in dest are negative. * * We need to clip the source upper left corner accordingly. * * Notice that x2 and y2 are inside the dst rectangle now. * (>= 0 and < w, < h) */ if (x2 < 0) { x0 -= x2; x2 = 0; } if (y2 < 0) { y0 -= y2; y2 = 0; } /* Make sure souce coordinates are inside of the src */ x0 = GP_MAX(x0, 0); y0 = GP_MAX(y0, 0); x1 = GP_MIN(x1, (GP_Coord)GP_ContextW(src) - 1); y1 = GP_MIN(y1, (GP_Coord)GP_ContextH(src) - 1); /* And source rectangle fits inside of the destination */ GP_Coord src_w = x1 - x0 + 1; GP_Coord src_h = y1 - y0 + 1; GP_Coord dst_w = GP_ContextW(dst) - x2; GP_Coord dst_h = GP_ContextH(dst) - y2; GP_DEBUG(2, "Blitting %ix%i, available %ix%i", src_w, src_h, dst_w, dst_h); if (src_w > dst_w) x1 -= src_w - dst_w; if (src_h > dst_h) y1 -= src_h - dst_h; GP_DEBUG(2, "Blitting %ix%i->%ix%i in %ux%u to %ix%i in %ux%u", x0, y0, x1, y1, GP_ContextW(src), GP_ContextH(src), x2, y2, GP_ContextW(dst), GP_ContextH(dst)); GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2); }
static void event_loop(void) { GP_Event ev; for (;;) { GP_BackendWaitEvent(win, &ev); switch (ev.type) { case GP_EV_KEY: if (ev.code != GP_EV_KEY_DOWN) continue; switch (ev.val.key.key) { case GP_KEY_X: win->context->x_swap = !win->context->x_swap; break; case GP_KEY_Y: win->context->y_swap = !win->context->y_swap; break; case GP_KEY_R: win->context->axes_swap = !win->context->axes_swap; GP_SWAP(X, Y); break; case GP_KEY_SPACE: font_flag++; if (font) { if (font_flag > 5) font_flag = 0; } else { if (font_flag > 4) font_flag = 0; } break; case GP_KEY_UP: style.pixel_xspace++; style.pixel_yspace++; break; case GP_KEY_DOWN: style.pixel_xspace--; style.pixel_yspace--; break; case GP_KEY_RIGHT: style.pixel_xmul++; style.pixel_ymul++; break; case GP_KEY_LEFT: style.pixel_xmul--; style.pixel_ymul--; break; case GP_KEY_ESC: GP_BackendExit(win); exit(0); break; } break; case GP_EV_SYS: switch(ev.code) { case GP_EV_SYS_QUIT: GP_BackendExit(win); exit(0); break; case GP_EV_SYS_RESIZE: GP_BackendResizeAck(win); X = win->context->w; Y = win->context->h; break; } break; } redraw_screen(); GP_BackendFlip(win); } }