void OSGDebugDrawInterface::AddAxes(const dtEntity::Matrix& m, const dtEntity::Vec4f& color, float size, float duration, bool depthTestEnabled) { float arroww = 0.1f; osg::Vec3 p0(0, 0, 0); osg::Vec3 p1(0, 0, 1); osg::Vec3 p2(0, 1, 0); osg::Vec3 p3(1, 0, 0); osg::Vec3 p1a(arroww, 0, 1 - arroww); osg::Vec3 p1b(-arroww, 0, 1 - arroww); osg::Vec3 p2a(arroww, 1 - arroww, 0); osg::Vec3 p2b(-arroww, 1 - arroww, 0); osg::Vec3 p3a(1 - arroww, 0, arroww); osg::Vec3 p3b(1 - arroww, 0, -arroww); std::vector<osg::Vec3> lines(18); lines[0] = m * p0; lines[1] = m * p1; lines[2] = m * p0; lines[3] = m * p2; lines[4] = m * p0; lines[5] = m * p3; lines[6] = m * p1; lines[7] = m * p1a; lines[8] = m * p1; lines[9] = m * p1b; lines[10] = m * p2; lines[11] = m * p2a; lines[12] = m * p2; lines[13] = m * p2b; lines[14] = m * p3; lines[15] = m * p3a; lines[16] = m * p3; lines[17] = m * p3b; AddLines(lines, color, size, duration, depthTestEnabled); }
void WTextSourceViewerLine::drawFoldingLineVisible(QPainter &p,const QPointF &p1,const QPointF &p2) { QPolygonF area; float demi_char_space=char_space/2.0f; QPointF pos(0.0f,(p1.y()+p2.y())/2.0f-demi_char_space); QRectF text_pos(pos,QSizeF(char_space,char_space)); QPointF p3(demi_char_space,p2.y()); QRectF endPoint2(p2.x()-2,p2.y()-2,4,4); QBrush b=p.brush(); p.setBrush(Qt::black); if (p1!=p2) { QPointF p0(demi_char_space,p1.y()); QPointF p1b(demi_char_space,pos.y()); QPointF p2b(demi_char_space,pos.y()+char_space); QRectF endPoint1(p1.x()-2,p1.y()-2,4,4); area << p0 << p1 ; area << p0 << p1b ; area << p2b << p3 ; area << p3 << p2 ; p.drawEllipse(endPoint1); } else { QPointF p1c(char_space,p2.y()); area << p1c << p2 ; } p.drawEllipse(endPoint2); p.setBrush(b); p.drawLines(area); float pos_size=char_space; QRectF rectangle(pos.x(),pos.y(),pos_size,pos_size); p.drawRoundRect(rectangle); float _x1=pos.x()+3.0f; float _y=pos.y()+pos_size/2.0f; float _x2=pos.x()+pos_size-3.0f; p.drawLine(QPointF(_x1,_y),QPointF(_x2,_y)); }
int mossa(int numero1, int numero2, int giocatore) { int risultato; if(giocatore==1) { risultato = p1a(numero1, numero2); risultato = p1b(risultato); } else { risultato = p2a(numero1, numero2); risultato = p2b(risultato); } giocatore=3-giocatore; if(decodifica1(risultato)<3 || decodifica2(risultato)<3) return giocatore; return mossa(decodifica1(risultato), decodifica2(risultato), giocatore); }
QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth) { qreal x1 = pLine.x1(); qreal y1 = pLine.y1(); qreal x2 = pLine.x2(); qreal y2 = pLine.y2(); qreal alpha = (90.0 - pLine.angle()) * PI / 180.0; qreal hypothenuse = pWidth / 2; // TODO UB 4.x PERF cache sin/cos table qreal opposite = sin(alpha) * hypothenuse; qreal adjacent = cos(alpha) * hypothenuse; QPointF p1a(x1 - adjacent, y1 - opposite); QPointF p1b(x1 + adjacent, y1 + opposite); QPointF p2a(x2 - adjacent, y2 - opposite); QPointF p2b(x2 + adjacent, y2 + opposite); QPainterPath painterPath; painterPath.moveTo(p1a); painterPath.lineTo(p2a); painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0); //painterPath.lineTo(p2b); painterPath.lineTo(p1b); painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0); painterPath.closeSubpath(); return painterPath.toFillPolygon(); }
void CompileThreadBlock::thread() { EditableMap::Lights& lights = wmap->get_light_sources(); Tileset *ts = wmap->get_tileset_ptr(); size_t nlgt = lights.size(); int mw = wmap->get_width(); int mh = wmap->get_height(); int tw = ts->get_tile_width(); int th = ts->get_tile_height(); int w = mw * tw; int h = mh * th; short **pmap = wmap->get_map(); short **pdeco = wmap->get_decoration(); Point pr; for (size_t i = 0; i < nlgt; i++) { { Scope<Mutex> lock(mtx); finished_percent = 100 * (i + 1) / nlgt; if (cancelled) { break; } } int r = lights[i]->radius; int colr = lights[i]->r; int colg = lights[i]->g; int colb = lights[i]->b; int lmaxsq = r * r; int lx = lights[i]->x; int ly = lights[i]->y; Point p2(static_cast<float>(lx * tw + (tw / 2)), static_cast<float>(ly * th + (th / 2))); int lsx = static_cast<int>(p2.x) - r; int lsy = static_cast<int>(p2.y) - r; int lex = static_cast<int>(p2.x) + r; int ley = static_cast<int>(p2.y) + r; if (lsx < 0) lsx = 0; if (lsy < 0) lsy = 0; if (lex > w) lex = w; if (ley > h) ley = h; int txs = lsx / tw; int txe = lex / tw; int tys = lsy / th; int tye = ley / th; for (int y = lsy; y < ley; y++) { for (int x = lsx; x < lex; x++) { int dindex = pdeco[y / th][x / tw]; if (dindex < 0) { lightmap[y][x * 4 + 3] = 0; } else { bool contact = false; Point p1(static_cast<float>(x), static_cast<float>(y)); float xd = p2.x - p1.x; float yd = p2.y - p1.y; float dist = xd * xd + yd * yd; if (dist < lmaxsq) { for (int tx = txs; tx < txe; tx++) { for (int ty = tys; ty < tye; ty++) { short index = pmap[ty][tx]; if (index >= 0) { if (ts->get_tile(index)->is_light_blocking()) { Point p1l(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2l(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p1r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p2r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); Point p1t(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2t(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p1b(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p2b(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); if (intersection(p1, p2, p1l, p2l, pr) || intersection(p1, p2, p1r, p2r, pr) || intersection(p1, p2, p1t, p2t, pr) || intersection(p1, p2, p1b, p2b, pr)) { contact = true; break; } } } } if (contact) { break; } } } else { contact = true; } if (!contact) { int v = static_cast<int>(sqrt(65025.0f * dist / lmaxsq)); if (v < lightmap[y][x * 4 + 3]) { double l = 1.0 - (static_cast<double>(v) / 255.0); lightmap[y][x * 4 + 0] = static_cast<unsigned char>(colr * l); lightmap[y][x * 4 + 1] = static_cast<unsigned char>(colg * l); lightmap[y][x * 4 + 2] = static_cast<unsigned char>(colb * l); lightmap[y][x * 4 + 3] = v; } } } } } } Scope<Mutex> lock(mtx); finished = true; }
/** Redefined. */ void AddressBarButton::paintEvent(QPaintEvent *) { QStylePainter p(this); QRect r = rect().adjusted(0, 1, -1, -(1 + extra)); static const int arrowWidth = r.height(); QPalette palette = QApplication::palette(); QLinearGradient g(rect().topLeft(), rect().bottomLeft()); g.setColorAt(0, palette.base().color()); g.setColorAt(1, palette.window().color()); p.fillRect(r, g); // Compute size of rectangles to display text and right arrow if (_atLeastOneSubDir) { if (isLeftToRight()) { _arrowRect = QRect(r.width() - arrowWidth, r.y(), arrowWidth, r.height()); _textRect = QRect(r.x(), r.y(), r.width() - arrowWidth, r.height()); } else { _arrowRect = QRect(r.x(), r.y(), arrowWidth, r.height()); _textRect = QRect(r.x() + arrowWidth, r.y(), r.width() - arrowWidth, r.height()); } } else { _textRect = r.adjusted(0, 0, -5, 0); } // Highlight button if mouse is over QPoint pos = mapFromGlobal(QCursor::pos()); p.save(); QBrush brush; if (_addressBar->isDown()) { brush = palette.highlight().color().lighter(); } else { brush = palette.highlight().color().lighter(lighterValue); } if (_highlighted) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); if (_atLeastOneSubDir) { p.drawRect(_arrowRect); } } else { if (_atLeastOneSubDir) { if (_textRect.contains(pos) || _arrowRect.contains(pos)) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); p.drawRect(_arrowRect); } else { p.setPen(Qt::NoPen); p.setBrush(Qt::NoBrush); p.drawRect(_textRect); p.drawRect(_arrowRect); } } else { if (_textRect.contains(pos)) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); } } } p.restore(); // Draw folder's name QColor lighterBG = palette.highlight().color().lighter(); QColor highlightedText = palette.highlightedText().color(); if (rect().contains(pos) && SettingsPrivate::instance()->isCustomTextColorOverriden()) { p.setPen(palette.highlightedText().color()); } else if (qAbs(lighterBG.value() - highlightedText.value()) > 128 && _highlighted) { p.setPen(highlightedText); } else { p.setPen(palette.text().color()); } // Special case for root and drives bool root = false; if (_path.isRoot()) { QPixmap pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20); QString drive; if (_isAbsoluteRoot) { pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20); if (isLeftToRight()) { p.drawPixmap(2, 3, 20, 20, pixmap); } else { p.drawPixmap(18, 3, 20, 20, pixmap); } } else { drive = AddressBar::getVolumeInfo(_path.absolutePath()); if (!_isAbsoluteRoot && !drive.isEmpty()) { // Add a small offset to simulate a pressed button if (_highlighted) { p.translate(1, 1); } p.drawText(_textRect.adjusted(5, 0, 0, 0), Qt::AlignCenter, drive); } pixmap = QFileIconProvider().icon(QFileIconProvider::Drive).pixmap(20, 20); } } else { if (!_path.dirName().isEmpty()) { // Add a small offset to simulate a pressed button if (_highlighted) { p.translate(1, 1); } p.drawText(_textRect.adjusted(0, 0, 0, 0), Qt::AlignCenter, _path.dirName()); } } if (_atLeastOneSubDir) { QStyleOptionButton o; o.initFrom(this); p.save(); p.setPen(Qt::NoPen); p.setBrush(o.palette.mid()); if (root && _addressBar->hasHiddenFolders()) { /// Right To Left QPoint p1(o.rect.x() + 32, o.rect.y() + 11), p2(o.rect.x() + 29, o.rect.y() + 14), p2b(o.rect.x() + 29, o.rect.y() + 13), p3(o.rect.x() + 32, o.rect.y() + 16); p.save(); p.setPen(Qt::black); p.setRenderHint(QPainter::Antialiasing); p.drawLine(p1, p2); p.drawLine(p2b, p3); p.translate(4, 0); p.drawLine(p1, p2); p.drawLine(p2b, p3); p.restore(); } else { int w = _arrowRect.width() / 3; int h = this->rect().height() / 3; QRect indicatorArrow(_arrowRect.x() + w + 1, _arrowRect.y() + h, w, h); o.rect = indicatorArrow; p.setRenderHint(QPainter::Antialiasing); p.save(); QPen pen(palette.mid().color()); pen.setWidthF(1.5); pen.setJoinStyle(Qt::MiterJoin); p.setPen(pen); QPolygon pol; QPoint p1, p2, p3; if (_highlighted) { p.translate(0, -1); p1 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2); p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2); p3 = QPoint(o.rect.x() + o.rect.width() / 2, o.rect.y() + o.rect.height()); } else if (isLeftToRight()) { p1 = QPoint(o.rect.x(), o.rect.y()); p2 = QPoint(o.rect.x(), o.rect.y() + o.rect.height()); p3 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2); } else { p1 = QPoint(o.rect.x() + o.rect.width(), o.rect.y()); p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height()); p3 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2); } pol.append(p1); pol.append(p2); pol.append(p3); p.drawPolygon(pol); p.restore(); p.setRenderHint(QPainter::Antialiasing, false); } p.restore(); } }
void EncodeBlock(uchar *nbin, int nn) { register uchar cl; register uchar *fly; register int i,pos,lim; bin = nbin; n = nn; px.ran_encode(n,0); if(!n) return; step(); if(st.reverse) Reverse(bin,bin+n); baza=-1; // Radix sort memset(r, 0, sizeof(trax2)); sfin = bin+n; //scans for(fly=bin; fly<sfin-1; fly++) r[p2b(fly)]++; r[ch=0x10000] = pos = n; i = 256; do { i--; cl=0; do { pos -= r[--ch]; r2a[ch] = r[ch] = pos; }while(--cl); rb[i] = pos; if((uchar)i == *bin) { p[--pos] = 0; r[ch]--; }//for start }while(i); sfin[0] = 0xFF; fly=bin; //border do if(BADSUF(fly)) p[r2a[p2b(fly)]++] = fly+1-bin, fly++; while(++fly<sfin); // Direct sort for(ch=0; ch<0x10000; ch++) { ray(p+r[ch], p+r2a[ch], bin-5); } memcpy(r2a,r+1,sizeof(trax2)-sizeof(int)); step(); *sfin=0xFF; //Right2Left wave cl=0; do { cl--; lim = r2a[(cl<<8)+cl]; for(i=r[(uint)(cl+1)<<8]-1; i>=lim; i--) { unsigned char cc = bin[pos = p[i]+1]; if(cc <= cl) p[--r2a[(cc<<8)+cl]] = pos; } for(lim = r2a[(cl<<8)+cl]; i>=lim; i--) if(bin[pos = p[i]+1] == cl) p[--lim] = pos; }while(cl); sfin=(uchar*)p; //Left2Right wave cl=0; i=0; do { ch = r[((int)cl+1)<<8]-r[cl<<8]; assert(i == r[cl<<8]); for(; ch--; i++,sfin++) { uchar sym; if((pos = 1+p[i]) == n) { //got '$' index baza = i; *sfin = *bin; continue; }//finish sym = *sfin = bin[pos]; if(rb[sym] > i) p[rb[sym]++] = pos; } }while(++cl); step(); memcpy(bin,p,n); px.Perform(p,bin,n); px.ran_encode(baza,0); }
void CompileThreadPixel::thread() { EditableMap::Lights& lights = wmap->get_light_sources(); Tileset *ts = wmap->get_tileset_ptr(); size_t nlgt = lights.size(); int mw = wmap->get_width(); int mh = wmap->get_height(); int tw = ts->get_tile_width(); int th = ts->get_tile_height(); int w = mw * tw; int h = mh * th; short **pmap = wmap->get_map(); short **pdeco = wmap->get_decoration(); Point pr; for (size_t i = 0; i < nlgt; i++) { { ScopeMutex lock(mtx); finished_percent = 100 * (i + 1) / nlgt; } int r = lights[i]->radius; int lmaxsq = r * r; int lx = lights[i]->x; int ly = lights[i]->y; Point p2(static_cast<float>(lx * tw + (tw / 2)), static_cast<float>(ly * th + (th / 2))); int lsx = static_cast<int>(p2.x) - r; int lsy = static_cast<int>(p2.y) - r; int lex = static_cast<int>(p2.x) + r; int ley = static_cast<int>(p2.y) + r; if (lsx < 0) lsx = 0; if (lsy < 0) lsy = 0; if (lex > w) lex = w; if (ley > h) ley = h; int txs = lsx / tw; int txe = lex / tw; int tys = lsy / th; int tye = ley / th; for (int y = lsy; y < ley; y++) { for (int x = lsx; x < lex; x++) { int dindex = pdeco[y / th][x / tw]; if (dindex < 0) { lightmap[y][x * 4 + 3] = 0; } else { bool contact = false; Point p1(static_cast<float>(x), static_cast<float>(y)); float xd = p2.x - p1.x; float yd = p2.y - p1.y; float dist = xd * xd + yd * yd; if (dist < lmaxsq) { for (int tx = txs; tx < txe; tx++) { for (int ty = tys; ty < tye; ty++) { short index = pmap[ty][tx]; if (index >= 0) { if (ts->get_tile(index)->is_light_blocking()) { TileGraphic *tg = ts->get_tile(index)->get_tilegraphic(); TileGraphicGL *tggl = static_cast<TileGraphicGL *>(tg); if (tggl->get_bytes_per_pixel(0) < 4) { Point p1l(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2l(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p1r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p2r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); Point p1t(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2t(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p1b(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p2b(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); if (intersection(p1, p2, p1l, p2l, pr) || intersection(p1, p2, p1r, p2r, pr) || intersection(p1, p2, p1t, p2t, pr) || intersection(p1, p2, p1b, p2b, pr)) { contact = true; break; } } else { unsigned char *p = tggl->get_picture_array(0); for (int py = 0; py < th; py++) { for (int px = 0; px < tw; px++) { if (p[3] == 255) { Point p1v(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) - 0.5f); Point p2v(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) + 0.5f); Point p1h(static_cast<float>(tx * tw + px) - 0.5f, static_cast<float>(ty * th + py) + 0.5f); Point p2h(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) + 0.5f); if (intersection(p1, p2, p1v, p2v, pr) || intersection(p1, p2, p1h, p2h, pr)) { contact = true; break; } } p += 4; } if (contact) { break; } } if (contact) { break; } } } } } if (contact) { break; } } } else { contact = true; } if (!contact) { int v = static_cast<int>(sqrt(65025.0f * dist / lmaxsq)); if (v < lightmap[y][x * 4 + 3]) { lightmap[y][x * 4 + 3] = v; } } } } } } ScopeMutex lock(mtx); finished = true; }