void draw_rect(Image* image, int x1, int y1, int x2, int y2, color_t color) { int t; if (x1 > x2) { t = x1; x1 = x2; x2 = t; } if (y1 > y2) { t = y1; y1 = y2; y2 = t; } if ((x2 < 0) || (x1 >= image->width()) || (y2 < 0) || (y1 >= image->height())) return; draw_hline(image, x1, y1, x2, color); draw_hline(image, x1, y2, x2, color); if (y2-y1 > 1) { draw_vline(image, x1, y1+1, y2-1, color); draw_vline(image, x2, y1+1, y2-1, color); } }
void draw_filled_circle(FBDev *dev, int cx, int cy, int radius, uint32_t pixel, uint32_t fill) { int error = -radius; int x = radius; int y = 0; while (x >= y) { draw_hline(dev, cx + x, cx - x, cy + y, fill); draw_hline(dev, cx + x, cx - x, cy - y, fill); draw_hline(dev, cx + y, cx - y, cy + x, fill); draw_hline(dev, cx + y, cx - y, cy - x, fill); fb_draw(dev, cx + x, cy + y, pixel); fb_draw(dev, cx - x, cy + y, pixel); fb_draw(dev, cx + x, cy - y, pixel); fb_draw(dev, cx - x, cy - y, pixel); fb_draw(dev, cx + y, cy + x, pixel); fb_draw(dev, cx - y, cy + x, pixel); fb_draw(dev, cx + y, cy - x, pixel); fb_draw(dev, cx - y, cy - x, pixel); error += y; y++; error += y; if (error >= 0) { error += -x; x--; error += -x; } } }
static void fill_circle_points_y(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel) { if (x == 0) draw_hline(cx-y, cy, 2*y+1, pixel); else { draw_hline(cx-y, cy-x, 2*y+1, pixel); draw_hline(cx-y, cy+x, 2*y+1, pixel); } }
static void fill_circle_points_x(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel) { if (x == 0) { set_pixel(cx, cy-y, pixel); set_pixel(cx, cy+y, pixel); } else { draw_hline(cx-x, cy-y, 2*x+1, pixel); draw_hline(cx-x, cy+y, 2*x+1, pixel); } }
void generic_draw_rect(u32 x, u32 y, u32 width, u32 height, pixel_t pixel) { draw_hline(x, y, width, pixel); if (height >= 1) { if (height >= 2) { draw_vline(x, y+1, height-2, pixel); if (width >= 1) draw_vline(x+width-1, y+1, height-2, pixel); } draw_hline(x, y+height-1, width, pixel); } }
static void fill_ellipse_points(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel) { if (x == 0) { set_pixel(cx, cy-y, pixel); set_pixel(cx, cy+y, pixel); } else if (y == 0) { draw_hline(cx-x, cy, 2*x+1, pixel); } else { draw_hline(cx-x, cy-y, 2*x+1, pixel); draw_hline(cx-x, cy+y, 2*x+1, pixel); } }
void drawbox(int x1, int y1, int x2, int y2) { cputcharxy(x1, y1, '+'); draw_hline(x1, y1+1, y2-1, '-'); cputcharxy(x1, y2, '+'); draw_vline(x1+1, y2, x2-1, '|'); cputcharxy(x2, y2, '+'); draw_hline(x2, y1+1, y2-1, '-'); cputcharxy(x2, y1, '+'); draw_vline(x1+1, y1, x2-1, '|'); gotoxy(x1, y1); }
static void draw_pixel_rect(DiaRenderer *self, int x, int y, int width, int height, Color *color) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); guint8 r,g,b; int start, len; int stride; r = color->red*0xff; g = color->green*0xff; b = color->blue*0xff; stride = renderer->pixel_width*3; /* clip in x */ start = x; len = width; CLIP_1D_LEN(renderer->clip_rect.left, renderer->clip_rect.right, start, len); /* top line */ if ( (y>=renderer->clip_rect.top) && (y<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y, len, r, g, b); } /* bottom line */ if ( (y+height>=renderer->clip_rect.top) && (y+height<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y+height, len, r, g, b); } /* clip in y */ start = y; len = height; CLIP_1D_LEN(renderer->clip_rect.top, renderer->clip_rect.bottom, start, len); /* left line */ if ( (x>=renderer->clip_rect.left) && (x<renderer->clip_rect.right) ) { draw_vline(self, x, start, len, r, g, b); } /* right line */ if ( (x+width>=renderer->clip_rect.left) && (x+width<renderer->clip_rect.right) ) { draw_vline(self, x+width, start, len, r, g, b); } }
void draw_rubberbox(GtkWidget *drawing_area, GdkRect rect) { GdkRect c; GdkRect oc; GdkRect update_rect; c = rect; oc = old_rect; if ((c.x > skin_infos.width) || (c.y > skin_infos.height) || ((c.x + c.w) > skin_infos.width) || ((c.y + c.h) > skin_infos.height)) return; g_object_unref(pixbuf); pixbuf = gdk_pixbuf_copy(skin_infos.img_orig); draw_hline(c.x, c.y, c.w); draw_hline(c.x, c.y + c.h, c.w); draw_vline(c.x, c.y, c.h); draw_vline(c.x + c.w, c.y, c.h); /* * 2 calls to SDL_UpdateRect : * + erase the old rect * + draw the new one * * We could composite a new rectangle with the new and old ones, * but this would consume more resources than these 2 calls. * Plus it would complicate the code. *sigh* */ update_rect.x = oc.x; update_rect.y = oc.y; update_rect.w = ((oc.w + oc.x + 1) <= skin_infos.width) ? (oc.w + 1) : oc.w; /* add 2 to really erase the lines (right, bottom) ... */ update_rect.h = ((oc.h + oc.y + 1) <= skin_infos.height) ? (oc.h + 1) : oc.h; /* ... but be careful */ gtk_widget_draw (drawing_area, (GdkRectangle *)(&update_rect)); update_rect.x = c.x; update_rect.y = c.y; update_rect.w = ((c.w + c.x + 1) <= skin_infos.width) ? (c.w + 1) : c.w; /* add 2 to really erase the lines (right, bottom) ... */ update_rect.h = ((c.h + c.y + 1) <= skin_infos.height) ? (c.h + 1) : c.h; /* ... but be careful */ gtk_widget_draw (drawing_area, (GdkRectangle *)&update_rect); tmp_rect = rect; /* when called from callbacks.c (for LCD or keys) */ old_rect = rect; /* save coords */ }
void fill_rect(FBDev *dev, int x, int y, int w, int h, uint32_t pixel, uint32_t fill) { int i; for (i = y; i < y+h; i++) { draw_hline(dev, x, x+w, i, fill); } draw_rect(dev, x, y, w, h, pixel); }
//------------------------------------------------------------------- // Generic rectangle // 'flags' defines type - filled, round corners, shadow and border thickness void draw_rectangle(coord x1, coord y1, coord x2, coord y2, twoColors cl, int flags) { // Normalise values if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); // Check if completely off screen if ((x2 < 0) || (y2 < 0) || (x1 >= camera_screen.width) || (y1 >= camera_screen.height)) return; int round = (flags & RECT_ROUND_CORNERS) ? 1 : 0; int thickness; int i; // Shadow (do this first, as edge draw shrinks rectangle for fill) if (flags & RECT_SHADOW_MASK) { thickness = ((flags & RECT_SHADOW_MASK) >> 4); for (i=1; i<=thickness; i++) { draw_vline(x2+i, y1+1, y2 - y1, COLOR_BLACK); draw_hline(x1+1, y2+i, x2 - x1 + thickness, COLOR_BLACK); } }
static enum test_res test002_func(void) { int i; u32 a, b, x1, x2, y1, y2; fill_rect(0, 0, fb_var.xres, fb_var.yres, black_pixel); for (i = 0; i <= Y_BLOCKS; i++) draw_hline(0, i*(fb_var.yres-1)/Y_BLOCKS, fb_var.xres, white_pixel); for (i = 0; i <= X_BLOCKS; i++) draw_vline(i*(fb_var.xres-1)/X_BLOCKS, 0, fb_var.yres, white_pixel); draw_ellipse(fb_var.xres/2, fb_var.yres/2, 3*fb_var.xres/8, fb_var.yres/2-1, white_pixel); a = (fb_var.xres-1)/X_BLOCKS; b = (fb_var.yres-1)/Y_BLOCKS; x1 = (fb_var.xres-1)/X_BLOCKS; y1 = (fb_var.yres-1)/Y_BLOCKS; x2 = (X_BLOCKS-1)*(fb_var.xres-1)/X_BLOCKS; y2 = (Y_BLOCKS-1)*(fb_var.yres-1)/Y_BLOCKS; draw_ellipse(x1, y1, a, b, white_pixel); draw_ellipse(x2, y1, a, b, white_pixel); draw_ellipse(x1, y2, a, b, white_pixel); draw_ellipse(x2, y2, a, b, white_pixel); wait_for_key(10); return TEST_OK; }
void draw_box(int_32* fb, int x0, int y0, int x1, int y1, int_32 col) { int y; for (y = y0; y <= y1; ++y) { draw_hline(fb, y, x0, x1, col); } }
void generic_draw_line(u32 x1, u32 y1, u32 x2, u32 y2, pixel_t pixel) { int dx, dy, sx, sy, e; dx = x2-x1; dy = y2-y1; if (dy == 0) { if (dx < 0) { dx = -dx; x1 = x2; } draw_hline(x1, y1, dx+1, pixel); } else if (dx == 0) { if (dy < 0) { dy = -dy; y1 = y2; } draw_vline(x1, y1, dy+1, pixel); } else { if (dy < 0) { dy = -dy; sy = -1; } else { sy = 1; } if (dx < 0) { dx = -dx; sx = -1; } else { sx = 1; } if (dx > dy) { e = -dx/2; set_pixel(x1, y1, pixel); while (x1 != x2) { e += dy; if (e >= 0) { y1 += sy; e -= dx; } x1 += sx; set_pixel(x1, y1, pixel); } } else { e = -dy/2; set_pixel(x1, y1, pixel); while (y1 != y2) { e += dx; if (e >= 0) { x1 += sx; e -= dy; } y1 += sy; set_pixel(x1, y1, pixel); } } } }
static void fill_slope(bitmap_rgb32 &bitmap, struct view *view, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) { if(y1 > view->y2) return; if(y2 <= view->y1) { int delta = y2-y1; *nx1 = x1+delta*sl1; *nx2 = x2+delta*sl2; return; } if(y2 > view->y2) y2 = view->y2+1; if(y1 < view->y1) { int delta = view->y1 - y1; x1 += delta*sl1; x2 += delta*sl2; y1 = view->y1; } if(x1 > x2 || (x1==x2 && sl1 > sl2)) { INT32 t, *tp; t = x1; x1 = x2; x2 = t; t = sl1; sl1 = sl2; sl2 = t; tp = nx1; nx1 = nx2; nx2 = tp; } while(y1 < y2) { if(y1 >= view->y1) { int xx1 = x1>>FRAC_SHIFT; int xx2 = x2>>FRAC_SHIFT; if(xx1 <= view->x2 || xx2 >= view->x1) { if(xx1 < view->x1) xx1 = view->x1; if(xx2 > view->x2) xx2 = view->x2; if(color & MOIRE) draw_hline_moired(bitmap, xx1, xx2, y1, color); else draw_hline(bitmap, xx1, xx2, y1, color); } } x1 += sl1; x2 += sl2; y1++; }
void main(void) { fb_init(WIDTH, HEIGHT, DEPTH, FB_SINGLEBUFFER); for( int y = 0; y < HEIGHT; y += 16 ) draw_hline(y, GL_WHITE); for( int x = 0; x < WIDTH; x += 16 ) draw_vline(x, GL_WHITE); }
static void render(struct widget *w) { struct widget_priv *priv = (struct widget_priv*) w->priv; struct canvas *ca = &w->ca; int i, j, y = -1; long yy; char buf[10], d = 0; int major_tick = priv->range / 5; int minor_tick = major_tick / 4; for (i = 0; i < priv->range; i++) { yy = ((long) i * Y_SIZE) / priv->range; if ((yy == y) && (d == 1)) continue; y = Y_SIZE - (int) yy; j = priv->speed_i + i - priv->range/2; if(j < 0) continue; if (j % major_tick == 0) { sprintf(buf, "%3d", j); draw_str(buf, 2, y - 2, ca, 0); draw_ohline(X_CENTER - 2, X_CENTER + 4, y, 1, 3, ca); d = 1; } else if (j % minor_tick == 0) { draw_ohline(X_CENTER - 2, X_CENTER + 2, y, 1, 3, ca); d = 1; } else { d = 0; } } draw_frect(1, Y_CENTER-4, X_CENTER - 10, Y_CENTER + 4, 0, ca); sprintf(buf, "%3d", (int) priv->speed_i); draw_str(buf, 2, Y_CENTER - 3, ca, 0); draw_hline(0, X_CENTER - 10, Y_CENTER - 5, 1, ca); draw_hline(0, X_CENTER - 10, Y_CENTER + 5, 1, ca); draw_vline(0, Y_CENTER - 3 , Y_CENTER + 3, 1, ca); draw_line(X_CENTER-10, Y_CENTER-5, X_CENTER-10+5, Y_CENTER, 1, ca); draw_line(X_CENTER-10, Y_CENTER+5, X_CENTER-10+5, Y_CENTER, 1, ca); }
static void render(struct widget *w) { struct widget_priv *priv = w->priv; struct canvas *ca = &w->ca; int i, j, y = -1; long yy; char buf[10], d = 0; int major_tick = priv->range / 5; int minor_tick = major_tick / 4; for (i = 0; i < priv->range; i++) { yy = ((long) i * Y_SIZE) / priv->range; if ((yy == y) && (d == 1)) continue; y = Y_SIZE - (int) yy; j = priv->altitude + i - priv->range/2; if (j % major_tick == 0) { draw_ohline(X_CENTER + 2, X_CENTER - 4, y, 1, 3, ca); sprintf(buf, "%d", j); draw_jstr(buf, X_SIZE-2, y, JUST_RIGHT | JUST_VCENTER, ca, 0); d = 1; } else if (j % minor_tick == 0) { draw_ohline(X_CENTER + 2, X_CENTER - 2, y, 1, 3, ca); d = 1; } else { d = 0; } } draw_frect(X_CENTER + 11, Y_CENTER-5, X_SIZE-2, Y_CENTER + 5, 0, ca); draw_hline(X_CENTER + 10, X_SIZE - 1, Y_CENTER-6, 1, ca); draw_hline(X_CENTER + 10, X_SIZE - 1, Y_CENTER+6, 1, ca); draw_vline(X_SIZE - 1, Y_CENTER-5, Y_CENTER+5, 1, ca); /* draw arrow */ draw_line(X_CENTER+10, Y_CENTER-6, X_CENTER+10-5, Y_CENTER, 1, ca); draw_line(X_CENTER+10, Y_CENTER+6, X_CENTER+10-5, Y_CENTER, 1, ca); sprintf(buf, "%d", (unsigned int) priv->altitude); draw_jstr(buf, X_SIZE-2, Y_CENTER, JUST_RIGHT | JUST_VCENTER, ca, 0); }
void draw_line(FBDev *dev, int x1, int y1, int x2, int y2, uint32_t pixel) { int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py; // Handle simple cases first if (x1 == x2) { draw_vline(dev, x1, y1, y2, pixel); } else if (y1 == y2) { draw_hline(dev, x1, x2, y1, pixel); } dx = x2 - x1; // Delta x dy = y2 - y1; // Delta y dxabs = abs(dx); // Absolute delta dyabs = abs(dy); // Absolute delta sdx = (dx > 0) ? 1 : -1; // signum function sdy = (dy > 0) ? 1 : -1; // signum function x = dyabs >> 1; y = dxabs >> 1; px = x1; py = y1; if (dxabs >= dyabs) { // Draw along x for (i = 0; i < dxabs; i++) { y += dyabs; if (y >= dxabs) { y -= dxabs; py += sdy; } px += sdx; fb_draw(dev, px, py, pixel); } } else { // Draw along y for (i = 0; i < dyabs; i++) { x += dxabs; if (x >= dyabs) { x -= dyabs; px += sdx; } py += sdy; fb_draw(dev, px, py, pixel); } } }
int main(void) { tga_init(128,64); ucg_Init(&ucg, &ucg_dev_tga, ucg_ext_none, (ucg_com_fnptr)0); ucg_SetFontMode(&ucg, UCG_FONT_MODE_TRANSPARENT); ucg_SetColor(&ucg, 0, 0, 0, 0); ucg_DrawBox(&ucg, 0, 0, 128, 64); ucg_SetFont(&ucg, ucg_font_ncenB18_tf); ucg_SetColor(&ucg, 0, 0, 0, 255); ucg_DrawPixel(&ucg, 70,20); ucg_SetColor(&ucg, 0, 255, 0, 0); //ucg_SetFontPosBottom(&ucg); /* ucg_DrawGlyph(&ucg, 70, 20, 0, 'A'); ucg_DrawGlyph(&ucg, 70, 20, 1, 'A'); ucg_DrawGlyph(&ucg, 70, 20, 2, 'A'); ucg_DrawGlyph(&ucg, 70, 20, 3, 'A'); ucg_SetColor(&ucg, 0, 255, 255, 255); vrule(&ucg, 30, 0, 20, 1); vrule(&ucg, 30, 0, 20, 0); */ //pos(&ucg, 70, 20, 0); //hrule(&ucg, 0, 20, 70, 1); //hrule(&ucg, 0, 20, 70, 0); ucg_SetColor(&ucg, 0, 255, 0, 0); ucg_SetColor(&ucg, 1, 0, 255, 0); ucg_SetColor(&ucg, 2, 255, 0, 255); ucg_SetColor(&ucg, 3, 0, 255, 255); ucg_DrawGradientLine(&ucg, 10, 40, 100, 0); ucg_DrawGradientBox(&ucg, 10, 43, 100, 20); tga_save("test.tga"); draw_pixel(&ucg); draw_hline(&ucg); draw_vline(&ucg); set_clip_range(&ucg); draw_text_baseline(&ucg); draw_text_bottom(&ucg); draw_text_top(&ucg); draw_text_center(&ucg); draw_text_ascent_descent(&ucg); draw_text_dir1(&ucg); draw_box(&ucg); draw_frame(&ucg); draw_rbox(&ucg); draw_rframe(&ucg); draw_gradient_box(&ucg); draw_gradient_line(&ucg); draw_disc(&ucg); draw_circle(&ucg); draw_triangle(&ucg); set_scale2x2(&ucg); set_font_mode_1(&ucg); set_font_mode_2(&ucg); solid_font_variants(&ucg); string_overwrite(&ucg, 1); string_overwrite(&ucg, 5); string_overwrite(&ucg, 10); return 0; }
void generic_fill_rect(u32 x, u32 y, u32 width, u32 height, pixel_t pixel) { while (height--) draw_hline(x, y++, width, pixel); }
static void hline_for_image(int x1, int y, int x2, Data* data) { draw_hline(data->image, x1, y, x2, data->color); }
void N6100LCD::clear(uint16_t color) { for(int i = 0; i < COL_HEIGHT; i++) { draw_hline(color, 0, i, ROW_LENGTH); } }
static void render(struct widget *w) { struct widget_priv *priv = w->priv; struct canvas *ca = &w->ca; char buf[10]; unsigned long d = (unsigned long) priv->home->distance; unsigned int r = (w->ca.width/2)-2; int x, y; int min_increment; long i, scale; struct point ils_points[5] = { {-4, -6}, {-4, 6}, {0, 10}, {4, 6}, {4, -6} }; struct polygon ils = { .len = 5, .points = ils_points, }; struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} }; struct polygon uav = { .len = 4, .points = uav_points, }; struct polygon *p; x = (w->ca.width/2)-1; y = (w->ca.height/2)-1; draw_vline(x, 0, r*2, 2, ca); draw_hline(0, r*2, y, 2, ca); //draw_circle(x, y, r+1, 3, ca); draw_circle(x, y, r , 2, ca); /* auto scale */ switch (get_units(w->cfg)) { default: case UNITS_METRIC: min_increment = 500; scale = ((d / min_increment) + 1) * min_increment; sprintf(buf, "%um", (unsigned int) scale); break; case UNITS_IMPERIAL: d *= M2FEET; min_increment = 1000; scale = ((d / min_increment) + 1) * min_increment; if (d > 5000) { d = (d * 1000) / MILE2FEET; scale /= 1000; sprintf(buf, "%umi", (unsigned int) scale); } else { sprintf(buf, "%uf", (unsigned int) scale); } break; } draw_str(buf, 0, 0, ca, 0); i = (long) d * r; i /= scale; switch (w->cfg->props.mode >> 1) { case 0: default: /* radar fixed at uav heading, home moves */ x += sin(DEG2RAD(priv->home->direction)) * i; y -= cos(DEG2RAD(priv->home->direction)) * i; transform_polygon(&ils, x, y, priv->stats->launch_heading - priv->heading - 180); p = &ils; break; case 1: /* radar always facing north, uav moves */ x += sin(DEG2RAD(priv->home->uav_bearing)) * i; y -= cos(DEG2RAD(priv->home->uav_bearing)) * i; transform_polygon(&uav, x, y, priv->heading); p = &uav; break; case 2: /* radar always facing launch direction, uav moves */ x += sin(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i; y -= cos(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i; transform_polygon(&uav, x, y, priv->heading - priv->stats->launch_heading); p = &uav; break; case 3: /* testing waypoints */ /* radar always facing north, uav moves with waypoints */ if (priv->wp_seq > 0) { long i_wp = (long) priv->wp_distance * r; i_wp /= scale; int x_wp = x, y_wp = y; x_wp += sin(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp; y_wp -= cos(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp; sprintf(buf, "%d", priv->wp_seq); draw_str(buf, x_wp, y_wp, ca, 0); } x += sin(DEG2RAD(priv->home->uav_bearing)) * i; y -= cos(DEG2RAD(priv->home->uav_bearing)) * i; transform_polygon(&uav, x, y, priv->heading); p = &uav; break; } draw_polygon(p, 3, ca); move_polygon(p, -1, -1); draw_polygon(p, 1, ca); } const struct widget_ops radar_widget_ops = { .name = "Radar", .mavname = "RADAR", .id = WIDGET_RADAR_ID, .init = NULL, .open = open, .render = render, .close = NULL, };
static void draw_pixel_line(DiaRenderer *self, int x1, int y1, int x2, int y2, Color *color) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); guint8 r,g,b; guint8 *ptr; int start, len; int stride; int i; int x, y; int dx, dy, adx, ady; int incx, incy; int incx_ptr, incy_ptr; int frac_pos; IntRectangle *clip_rect; r = color->red*0xff; g = color->green*0xff; b = color->blue*0xff; if (y1==y2) { /* Horizontal line */ start = x1; len = x2-x1; CLIP_1D_LEN(renderer->clip_rect.left, renderer->clip_rect.right, start, len); /* top line */ if ( (y1>=renderer->clip_rect.top) && (y1<=renderer->clip_rect.bottom) ) { draw_hline(self, start, y1, len, r, g, b); } return; } if (x1==x2) { /* Vertical line */ start = y1; len = y2-y1; CLIP_1D_LEN(renderer->clip_rect.top, renderer->clip_rect.bottom, start, len); /* left line */ if ( (x1>=renderer->clip_rect.left) && (x1<=renderer->clip_rect.right) ) { draw_vline(self, x1, start, len, r, g, b); } return; } /* Ugh, kill me slowly for writing this line-drawer. * It is actually a standard bresenham, but not very optimized. * It is also not very well tested. */ stride = renderer->pixel_width*3; clip_rect = &renderer->clip_rect; dx = x2-x1; dy = y2-y1; adx = (dx>=0)?dx:-dx; ady = (dy>=0)?dy:-dy; x = x1; y = y1; ptr = renderer->rgb_buffer + x*3 + y*stride; if (adx>=ady) { /* x-major */ if (dx>0) { incx = 1; incx_ptr = 3; } else { incx = -1; incx_ptr = -3; } if (dy>0) { incy = 1; incy_ptr = stride; } else { incy = -1; incy_ptr = -stride; } frac_pos = adx; for (i=0;i<=adx;i++) { /* Amazing... He does the clipping in the inner loop! It must be horribly inefficient! */ if ( (x>=clip_rect->left) && (x<=clip_rect->right) && (y>=clip_rect->top) && (y<=clip_rect->bottom) ) { ptr[0] = r; ptr[1] = g; ptr[2] = b; } x += incx; ptr += incx_ptr; frac_pos += ady*2; if ((frac_pos > 2*adx) || ((dy>0)&&(frac_pos == 2*adx))) { y += incy; ptr += incy_ptr; frac_pos -= 2*adx; } } } else { /* y-major */ if (dx>0) { incx = 1; incx_ptr = 3; } else { incx = -1; incx_ptr = -3; } if (dy>0) { incy = 1; incy_ptr = stride; } else { incy = -1; incy_ptr = -stride; } frac_pos = ady; for (i=0;i<=ady;i++) { /* Amazing... He does the clipping in the inner loop! It must be horribly inefficient! */ if ( (x>=clip_rect->left) && (x<=clip_rect->right) && (y>=clip_rect->top) && (y<=clip_rect->bottom) ) { ptr[0] = r; ptr[1] = g; ptr[2] = b; } y += incy; ptr += incy_ptr; frac_pos += adx*2; if ((frac_pos > 2*ady) || ((dx>0)&&(frac_pos == 2*ady))) { x += incx; ptr += incx_ptr; frac_pos -= 2*ady; } } } }
void draw_rect(FBDev *dev, int x, int y, int w, int h, uint32_t pixel) { draw_hline(dev, x, x+w, y, pixel); draw_hline(dev, x, x+w, y+h, pixel); draw_vline(dev, x, y, y+h, pixel); draw_vline(dev, x+w, y, y+h, pixel); }
void model1_state::fill_slope(bitmap_rgb32 &bitmap, view_t *view, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) { if(y1 > view->y2) { return; } if (y2 <= view->y1) { int delta = y2 - y1; *nx1 = x1 + delta * sl1; *nx2 = x2 + delta * sl2; return; } if (y2 > view->y2) { y2 = view->y2 + 1; } if (y1 < view->y1) { int delta = view->y1 - y1; x1 += delta * sl1; x2 += delta * sl2; y1 = view->y1; } if (x1 > x2 || (x1 == x2 && sl1 > sl2)) { INT32 t = x1; x1 = x2; x2 = t; t = sl1; sl1 = sl2; sl2 = t; INT32 *tp = nx1; nx1 = nx2; nx2 = tp; } while(y1 < y2) { if(y1 >= view->y1) { int xx1 = x1>>FRAC_SHIFT; int xx2 = x2>>FRAC_SHIFT; if(xx1 <= view->x2 || xx2 >= view->x1) { if(xx1 < view->x1) { xx1 = view->x1; } if(xx2 > view->x2) { xx2 = view->x2; } if(color & MOIRE) { draw_hline_moired(bitmap, xx1, xx2, y1, color); } else { draw_hline(bitmap, xx1, xx2, y1, color); } } } x1 += sl1; x2 += sl2; y1++; }