void console_widget_t::calc_area(int x, int y) { /* calculate selection area */ if(mouse_drag_type) { /* copy rect */ /* calculate selection start location and selection width and height */ mouse_sx = i_min(loc_x(mouse_start_x), loc_x(x)); mouse_wx = i_abs(loc_x(x)-loc_x(mouse_start_x)); mouse_sy = i_min(loc_y(mouse_start_y), loc_y(y)); mouse_wy = i_abs(loc_y(y)-loc_y(mouse_start_y)); /* no point if mouse selection is empty */ mouse_wx = (mouse_wx == 0) ? 1 : mouse_wx; mouse_wy = (mouse_wy == 0) ? 1 : mouse_wy; /* clip selection to the size of the console */ mouse_wx = (mouse_sx+mouse_wx > console->config.x) ? console->config.x - mouse_sx : mouse_wx; mouse_wy = (mouse_sy+mouse_wy > console->config.y) ? console->config.y : mouse_wy; } else { /* copy lines */ /* calculate start and end of selection */ loc_start = loc_x(mouse_start_x) + loc_y(mouse_start_y) * console->config.x; loc_end = loc_x(x) + loc_y(y) * console->config.x; /* swap start and end as needed */ if(loc_start>loc_end) { int temp = loc_start; loc_start = loc_end; loc_end = temp; } } return; }
void Texture_Map(texture_t *texture, float tu, float tv, vec4f_t color) { uint8_t r, g, b, a; int u, v, pos; if (texture->buffer == NULL) { Color4f_Format(color, 255, 255, 255, 255); return; } /* using a % operator to cycle/repeat the texture if needed */ u = i_abs((int)(tu * texture->width) % texture->width); v = i_abs((int)(tv * texture->height) % texture->height); pos = (u + v * texture->width) * 4; r = texture->buffer[pos + 0]; g = texture->buffer[pos + 1]; b = texture->buffer[pos + 2]; a = texture->buffer[pos + 3]; Color4f_Format(color, r, g, b, a); }
// assume integer is 32 bits inline static int ObjKey(const LDObjid &oid, const int hashSize) { // make sure all positive return (((i_abs(oid.id[2]) & 0x7F)<<24) |((i_abs(oid.id[1]) & 0xFF)<<16) |i_abs(oid.id[0])) % hashSize; }
void i_line_aa(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, const i_color *val, int endp) { i_img_dim x, y; i_img_dim dx, dy; i_img_dim p; dx = x2 - x1; dy = y2 - y1; /* choose variable to iterate on */ if (i_abs(dx) > i_abs(dy)) { i_img_dim dx2, dy2, cpy; /* sort by x */ if (x1 > x2) { i_img_dim t; t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; } dx = i_abs(dx); dx2 = dx*2; dy = y2 - y1; if (dy<0) { dy = -dy; cpy = -1; } else { cpy = 1; } dy2 = dy*2; p = dy2 - dx2; /* this has to be like this for AA */ y = y1; for(x=x1; x<x2-1; x++) { int ch; i_color tval; double t = (dy) ? -(float)(p)/(float)(dx2) : 1; double t1, t2; if (t<0) t = 0; t1 = 1-t; t2 = t; i_gpix(im,x+1,y,&tval); for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]); i_ppix(im,x+1,y,&tval); i_gpix(im,x+1,y+cpy,&tval); for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]); i_ppix(im,x+1,y+cpy,&tval); if (p<0) { p += dy2; } else { y += cpy; p += dy2-dx2; } } } else { i_img_dim dy2, dx2, cpx; /* sort bx y */ if (y1 > y2) { i_img_dim t; t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; } dy = i_abs(dy); dx = x2 - x1; dy2 = dy*2; if (dx<0) { dx = -dx; cpx = -1; } else { cpx = 1; } dx2 = dx*2; p = dx2 - dy2; /* this has to be like this for AA */ x = x1; for(y=y1; y<y2-1; y++) { int ch; i_color tval; double t = (dx) ? -(double)(p)/(double)(dy2) : 1; double t1, t2; if (t<0) t = 0; t1 = 1-t; t2 = t; i_gpix(im,x,y+1,&tval); for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(t1*(double)tval.channel[ch]+t2*(double)val->channel[ch]); i_ppix(im,x,y+1,&tval); i_gpix(im,x+cpx,y+1,&tval); for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(t2*(double)tval.channel[ch]+t1*(double)val->channel[ch]); i_ppix(im,x+cpx,y+1,&tval); if (p<0) { p += dx2; } else { x += cpx; p += dx2-dy2; } } } if (endp) { i_ppix(im, x1, y1, val); i_ppix(im, x2, y2, val); } else { if (x1 != x2 || y1 != y2) i_ppix(im, x1, y1, val); } }
void i_line(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, const i_color *val, int endp) { i_img_dim x, y; i_img_dim dx, dy; i_img_dim p; dx = x2 - x1; dy = y2 - y1; /* choose variable to iterate on */ if (i_abs(dx) > i_abs(dy)) { i_img_dim dx2, dy2, cpy; /* sort by x */ if (x1 > x2) { i_img_dim t; t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; } dx = i_abs(dx); dx2 = dx*2; dy = y2 - y1; if (dy<0) { dy = -dy; cpy = -1; } else { cpy = 1; } dy2 = dy*2; p = dy2 - dx; y = y1; for(x=x1; x<x2-1; x++) { if (p<0) { p += dy2; } else { y += cpy; p += dy2-dx2; } i_ppix(im, x+1, y, val); } } else { i_img_dim dy2, dx2, cpx; /* sort bx y */ if (y1 > y2) { i_img_dim t; t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; } dy = i_abs(dy); dx = x2 - x1; dy2 = dy*2; if (dx<0) { dx = -dx; cpx = -1; } else { cpx = 1; } dx2 = dx*2; p = dx2 - dy; x = x1; for(y=y1; y<y2-1; y++) { if (p<0) { p += dx2; } else { x += cpx; p += dx2-dy2; } i_ppix(im, x, y+1, val); } } if (endp) { i_ppix(im, x1, y1, val); i_ppix(im, x2, y2, val); } else { if (x1 != x2 || y1 != y2) i_ppix(im, x1, y1, val); } }