bool ScrollBar::Set(int apagepos) { int op = pagepos; pagepos = apagepos; if(pagepos > totalsize - pagesize) pagepos = totalsize - pagesize; if(pagepos < 0) pagepos = 0; int slsize = GetRange(); int mint = max(minthumb, style->thumbmin); if(totalsize <= 0) SetThumb(0, slsize); else { double thumbsize = slsize * pagesize / (double) totalsize; double rest = slsize * pagesize - thumbsize * totalsize; double ts, ps; if(thumbsize >= slsize || thumbsize < 0) { ts = slsize; ps = 0; } else if(thumbsize <= mint) { ps = ((slsize - mint) * (double)pagepos + rest) / (double) (totalsize - pagesize); ts = mint; } else { ps = (slsize * (double)pagepos + rest) / (double) totalsize; ts = thumbsize; } SetThumb(ffloor(ps), fceil(ts)); } if(pagepos != op) { Refresh(); WhenScroll(); return true; } return false; }
virtual void Paint(Draw &w) { Size sz = GetSize(); for(int i = 0; i < cols; i++) { Color c = (i & 1) ? Red : Yellow; w.DrawRect(int(i * cx), 0, fceil(cx), sz.cy, c); } ready = true; }
int ilog10(double d) { if(IsNull(d) || d == 0) return Null; return fceil(log10(fabs(d))); }
void painter2D::draw_line(float x1, float y1, float x2, float y2, unsigned char r, unsigned char g, unsigned char b, imagebuffer *ib) { float prestep, fcy, faux, xd, yd; int top_y, bottom_y, top_x, bottom_x, j; int x, x_inc, y, y_inc, offset0, ofs, w; unsigned int *img32, col32; // rigetti banali if ((x1<0) && (x2<0)) return; if ((y1<0) && (y2<0)) return; if ((x1>=(float)(ib->width)) && (x2>=(float)(ib->width))) return; if ((y1>=(float)(ib->height)) && (y2>=(float)(ib->height))) return; col32=(unsigned int)(b | (g << 8) | (r << 16)); xd=x2-x1; yd=y2-y1; img32=ib->uint32ptr; if (fabsf(yd)>fabsf(xd)) { if (y1>y2) { faux=y1; y1=y2; y2=faux; faux=x1; x1=x2; x2=faux; } // subpixel + clipping prestep=-y1; if (y1>=0) { fcy=fceil(y1); prestep=fcy + prestep; top_y=myfist(fcy); } else top_y=0; if (y2 >= (float)(ib->height)) bottom_y=ib->height; else bottom_y=myfist(fceil(y2)); faux=(x2 - x1)/(y2-y1); x_inc=myfist16(faux); x=myfist16(x1 + prestep*faux); offset0=ib->muly[top_y]; for (j=abs(bottom_y-top_y); j>0; j--) { w=ceil16(x); if ((w>=0) && (w<ib->width)) { ofs=offset0 + w; img32[ofs]=col32; } offset0=offset0+ib->width; x+=x_inc; } } else { if (x1>x2) { faux=y1; y1=y2; y2=faux; faux=x1; x1=x2; x2=faux; } // subpixel + clipping prestep=-x1; if (x1>=0) { fcy=fceil(x1); prestep=fcy + prestep; bottom_x=myfist(fcy); } else bottom_x=0; if (x2 >= (float)(ib->width)) top_x=ib->width; else top_x=myfist(fceil(x2)); faux=(y2-y1)/(x2-x1); /* if ((y1<0) && (y2>=0)) { bottom_x=bottom_x + myfist(fceil(-y1/faux)); y1=0; prestep=0; } else if ((y1>=0) && (y2<0)) { top_x=top_x - myfist(fceil(-y2/faux)); } */ y_inc=myfist16(faux); y=myfist16(y1 + prestep*faux); for (j=bottom_x; j<top_x; j++) { w=ceil16(y); if ((w>=0) && (w<ib->height)) { ofs=ib->muly[w]+j; img32[ofs]=col32; } y+=y_inc; } } }
void painter2D::draw_aaline(float x1, float y1, float x2, float y2, unsigned char r, unsigned char g, unsigned char b, imagebuffer *ib) { float prestep, fcy, faux, xd, yd; int top_y, bottom_y, top_x, bottom_x, j, cx, fraz, ifraz; int x, x_inc, y, y_inc, offset0, ofs, c1, c2, c3, w; unsigned char *img; // rigetti banali if ((x1<0) && (x2<0)) return; if ((y1<0) && (y2<0)) return; if ((x1>(float)(ib->width)) && (x2>(float)(ib->width))) return; if ((y1>(float)(ib->height)) && (y2>(float)(ib->height))) return; xd=x2-x1; yd=y2-y1; img=ib->uchar8ptr; if (fabsf(yd)>fabsf(xd)) { if (y1>y2) { faux=y1; y1=y2; y2=faux; faux=x1; x1=x2; x2=faux; } // subpixel + clipping prestep=-y1; if (y1>=0) { fcy=fceil(y1); prestep=fcy + prestep; top_y=myfist(fcy); } else top_y=0; if (y2 >= (float)(ib->height)) bottom_y=ib->height; else bottom_y=myfist(fceil(y2)); faux=(x2 - x1)/(y2-y1); x_inc=myfist16(faux); x=myfist16(x1 + prestep*faux); offset0=ib->muly[top_y]; for (j=abs(bottom_y-top_y); j>0; j--) { cx=ceil16(x); if ((cx>=0) && (cx<ib->width-1)) { ofs=offset0 + cx; fraz=x & 0x0000FFFF; ifraz=0x10000-fraz; c1=(fraz*b)>>16; c2=(fraz*g)>>16; c3=(fraz*r)>>16; img[ofs*4]=b-(unsigned char)c1; img[ofs*4+1]=g-(unsigned char)c2; img[ofs*4+2]=r-(unsigned char)c3; c1=(ifraz*b)>>16; c2=(ifraz*g)>>16; c3=(ifraz*r)>>16; img[ofs*4+4]=b-(unsigned char)c1; img[ofs*4+5]=g-(unsigned char)c2; img[ofs*4+6]=r-(unsigned char)c3; } offset0=offset0+ib->width; x+=x_inc; } }