void CheckBox::draw(void) { if(!isExposed()) return; // Draw the box if(enabled) drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl ,2, 4, 7, 7); else drawGradient(theme->col_light_ctrl_disabled, theme->col_dark_ctrl_disabled,2, 4, 7, 7); drawLine(1, 3, 9, 1, theme->col_outline); drawLine(1,11, 9, 1, theme->col_outline); drawLine(1, 3, 9, 0, theme->col_outline); drawLine(9, 3, 9, 0, theme->col_outline); // Clear up if(!albino) drawFullBox(0, 0, 11, 3, theme->col_light_bg); else drawFullBox(0, 0, 11, 3, theme->col_dark_bg); // Checked or not if(checked == true) drawMonochromeIcon(1, 0, 10, 10, haken_bin); // Text if(!albino) drawString(label, 13, 2, 255, theme->col_text); else drawString(label, 13, 2, 255, theme->col_lighter_bg); }
//-------------------------------------------------------------- void ofApp::setup(){ Consider.loadImage("Consider.png"); Everything.loadImage("Everything.png"); tobe.loadImage("tobe.png"); an.loadImage("an.png"); Experiment.loadImage("Experiment.png"); salmon.setHsb(0,140,224); tan.setHsb(30,58,234); // (x/360*255, x/100*255, x/100*255) brown.setHsb(30,96,63); yellow.setHsb(34,150,234); green.setHsb(49,127,219); royal.setHsb(157,127,181); blue.setHsb(133,138,214); pink.setHsb(4,43,237); imggrad.allocate(800 ,800,OF_IMAGE_COLOR); drawGradient(); // ofEnableAntiAliasing(); ofSetLineWidth(2); last = ofGetElapsedTimeMillis(); col.setHsb(0,255,255); yellow.setHex(0xF9FF4B); Myradius=10; }
void RecordBox::draw(void) { drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, 0, 0, width, 16); drawLine(0,16, width, 1, theme->col_outline); if(recording==true) { drawFullBox(0, 17, width, RECORDBOX_HEIGHT-17, theme->col_signal); labelmsg->setTheme(theme, theme->col_signal); labelmsg2->setTheme(theme, theme->col_signal); buttoncancel->setTheme(theme, theme->col_signal); labelrec->show(); labelmsg->hide(); labelmsg2->hide(); buttoncancel->hide(); } else { drawFullBox(0, 17, width, RECORDBOX_HEIGHT-17, theme->col_light_bg); labelrec->hide(); labelmsg->show(); labelmsg2->show(); buttoncancel->show(); buttoncancel->pleaseDraw(); } drawBorder(); u8 titlewidth = getStringWidth(title)+5; drawString(title, (RECORDBOX_WIDTH-titlewidth)/2, 2, titlewidth+5); labelmsg->pleaseDraw(); labelmsg2->pleaseDraw(); labelrec->pleaseDraw(); }
void ex1() { SDL_SetWindowTitle( SDL_GL_GetCurrentWindow(), "ex1" ); Uint32 color1, color2; color1 = SDL_MapRGB( backBuffer->format, 200, 40, 40 ); color2 = SDL_MapRGB( backBuffer->format, 40, 40, 200 ); drawGradient( backBuffer, 0, WIN_W-1, WIN_H/2-1, color1, color2 ); }
inline static QImage renderedDesignElement(DesignElementType type, int variation, QSize *size, const QSize &requestedSize) { Q_UNUSED(size) const ElementVariationList *elements = type == DesignElementTypeButton ? buttonVariations() : frameVariations(); const qreal requestedRatio = requestedSize.width() / qreal(requestedSize.height()); const ElementVariations *elementWithNearestRatio = &elements->last(); foreach (const ElementVariations &element, *elements) { if (qAbs(requestedRatio - element.widthToHeightRatio) < qAbs(requestedRatio - elementWithNearestRatio->widthToHeightRatio)) { elementWithNearestRatio = &element; } else if (element.widthToHeightRatio > elementWithNearestRatio->widthToHeightRatio) { break; } } const QString &elementId = idPrefix + elementWithNearestRatio->elementIds.at(variation % elementWithNearestRatio->elementIds.count()); static QImage cachedGradientButton; static QImage cachedGradientFrame; QImage &cachedGradient = type == DesignElementTypeButton ? cachedGradientButton : cachedGradientFrame; if (cachedGradient.size() == requestedSize) { QImage result(cachedGradient); QPainter p(&result); designRenderer()->render(&p, elementId, result.rect()); return result; } else { QImage result(requestedSize, QImage::Format_ARGB32); result.fill(0); drawGradient(type, result); cachedGradient = result; QPainter p(&result); designRenderer()->render(&p, elementId, result.rect()); return result; } }
QImage GradientLoader::drawGradient(const QStringList& data) { if (data.isEmpty()) { return QImage(); } GradientList gradientList = extractGradients(data); return drawGradient(gradientList); }
void NormalizeBox::draw(void) { drawGradient(theme->col_list_highlight1, theme->col_list_highlight2, 0, 0, width, 16); drawLine(0,16, width, 1, RGB15(0,0,0)|BIT(15)); drawFullBox(0, 17, width, NORMALIZEBOX_HEIGHT-17, theme->col_light_bg); drawBorder(); u8 titlewidth = getStringWidth(title)+5; drawString(title, (NORMALIZEBOX_WIDTH-titlewidth)/2, 2, titlewidth+5); gui.draw(); }
CGImageRef createCGImageFromGradient(int width, int height, pixelfmt_rgbx8888_t start, pixelfmt_rgbx8888_t end, int direction) { int bpp; size_t bytesPerRow; size_t bytesPerImage; void *base; void (*drawGradient)(uint32_t *base, int width, size_t bytesPerRow, int height); CGColorSpaceRef rgbColourSpace; CGDataProviderRef dataProvider; CGImageRef image; bpp = 32; bytesPerRow = ROWBYTES16ALIGNED(width, bpp); bytesPerImage = bytesPerRow * height; base = malloc(bytesPerImage); if (base == NULL) return NULL; setupGradient32bpp(start, end); drawGradient = (direction == 0) ? drawXGradient32bpp : drawYGradient32bpp; drawGradient(base, width, bytesPerRow, height); rgbColourSpace = CGColorSpaceCreateDeviceRGB(); dataProvider = CGDataProviderCreateWithData(NULL, base, bytesPerImage, releaseDataCallback); image = CGImageCreate(width, height, 8, bpp, bytesPerRow, rgbColourSpace, kCGImageAlphaNoneSkipLast, dataProvider, NULL, // decode array false, // should interpolate kCGRenderingIntentDefault); CGDataProviderRelease(dataProvider); CGColorSpaceRelease(rgbColourSpace); return image; }
void GroupOfButtons::draw() { drawGradient(Area(Area::CXYWH, cx, cy, getW(), getH()), Color(0,0,0,100), Color(0,0,0,0)); al_draw_text(font(font_size), Color::white(), cx, cy - getH()/2 + space()*1.5 - font_size/2, ALLEGRO_ALIGN_CENTER, title.c_str()); for (auto& b: buttons) { b.draw(); } for (auto& t: textboxes) { t.box.draw(); } }
void Button::draw() { Color c = color; if (cs.getInvaded()) c += 75; else if (cs.getIsPressed()) c -= 75; float gradient_diff = 11.0/7.0; drawGradient(area, c + Color(static_cast<float>(c.getR())/(gradient_diff), static_cast<float>(c.getG())/(gradient_diff), static_cast<float>(c.getB())/(gradient_diff)), c - Color(static_cast<float>(c.getR())/(gradient_diff), static_cast<float>(c.getG())/(gradient_diff), static_cast<float>(c.getB())/(gradient_diff))); al_draw_text(font(area.h()/3), [](bool b)->Color{return b ? Color::white() : Color::black();}(color.ifDark()), area.cx(), area.cy() - area.h()/6, ALLEGRO_ALIGN_CENTER, text.c_str()); }
/* Expose function for the gradient area */ static gboolean onExposeGradient(GtkWidget *gradient, GdkEventExpose *event, gpointer data) { GdkWindow *drawable = GTK_LAYOUT(gradient)->bin_window; GtkWidget *greyramp = GTK_WIDGET(data); if (drawable && greyramp) { drawGradient(drawable, greyramp); drawWhiteMarker(drawable, greyramp); drawBlackMarker(drawable, greyramp); drawThresholdMarker(drawable, greyramp); } return TRUE; }
void Background::draw() { if (checkState() == Qt::Checked) { glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF()); } else { glClearColor(1.0f, 1.0f, 1.0f, 0.0f); } glClear(GL_COLOR_BUFFER_BIT); if (false) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); drawGradient(); } }
QImage GradientLoader::generateThumbnail(QFile& file) { QTextStream in(&file); QStringList data; while (!in.atEnd()) { data << in.readLine(); } // close the file file.close(); QImage thumb; if (isValidResourceFileData(data)) { thumb = drawGradient(data); } return thumb; }
void RadioButton::draw(void) { // Draw the dot //drawFullBox(2, 2, 7, 7, col); drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl ,2, 2, 7, 7); drawLine(3, 1, 5, 1, theme->col_outline); drawLine(3, 9, 5, 1, theme->col_outline); drawLine(1, 3, 5, 0, theme->col_outline); drawLine(9, 3, 5, 0, theme->col_outline); drawPixel(2, 2, theme->col_outline); drawPixel(8, 2, theme->col_outline); drawPixel(2, 8, theme->col_outline); drawPixel(8, 8, theme->col_outline); // Filled or not if(active == true) { drawFullBox(4, 4, 3, 3, theme->col_outline); } // Text drawString(label, 13, 0); }
void SampleDisplay::draw(void) { if(!isExposed()) return; // // Border and background // //drawFullBox(0, 0, width, height, theme->col_dark_bg); u32 colcol = theme->col_dark_bg | theme->col_dark_bg << 16; for(int j=y;j<y+height;++j) dmaFillWordsDamnFast(colcol, *vram+256*j+x, width*2); if(active==false) { drawBorder(); } else { drawBorder(RGB15(31,0,0)|BIT(15)); } // Now comes sample-dependant stuff, so return if we have no sample if((smp==0)||(smp->getNSamples()==0)) return; // // Selection // s32 selleft = sampleToPixel(MIN(selstart, selend)); s32 selwidth = sampleToPixel(MAX(selstart, selend)) - selleft; bool dontdraw = false; if( (selleft >= 0) && (selleft < width-2) && (selleft + selwidth > width - 2) ) { selwidth = (width-2) - selleft; } else if( (selleft < 0) && (selleft + selwidth > 0) && (selleft + selwidth < width-2) ) { selwidth += selleft; selleft = 0; } else if( (selleft < 0) && (selleft + selwidth > width-2) ) { selwidth = width-2; selleft = 0; } else if( (selleft + selwidth < 0) || (selleft > width-2) ) { dontdraw = true; } if(selection_exists && !dontdraw) { drawFullBox(selleft+1, 1, selwidth, DRAW_HEIGHT+1, RGB15(31,31,0)|BIT(15)); } // // Scrollbar // // Right Button if(pen_on_scroll_right) { drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8); } else { drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8); } // This draws the right-arrow s8 j, p; for(j=0;j<3;j++) { for(p=-j;p<=j;++p) { *(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+width-j-3) = RGB15(0,0,0) | BIT(15); } } drawBox(width-SCROLLBAR_WIDTH, height-SCROLLBUTTON_HEIGHT, 9, 9); // Left Button if(pen_on_scroll_left) { drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, 1, height-9, 8, 8); } else { drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, 1, height-9, 8, 8); } // This draws the down-arrow for(j=2;j>=0;j--) { for(p=-j;p<=j;++p) { *(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+j+3) = theme->col_icon; } } drawBox(0, height-9, 9, 9); drawBox(0, height-SCROLLBAR_WIDTH, width, SCROLLBAR_WIDTH); // Clear Scrollbar drawGradient(theme->col_medium_bg, theme->col_light_bg, SCROLLBUTTON_HEIGHT, height-SCROLLBAR_WIDTH+1, width-2*SCROLLBUTTON_HEIGHT, SCROLLBAR_WIDTH-2); // The scroll thingy if(pen_on_scrollthingy) { drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_light_ctrl); } else { drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_dark_ctrl); } drawBox(SCROLLBUTTON_HEIGHT-1+scrollthingypos, height-SCROLLBAR_WIDTH, scrollthingywidth, SCROLLBAR_WIDTH); // // Sample // u16 colortable[DRAW_HEIGHT+2]; for(u8 i=0; i<DRAW_HEIGHT+2; ++i) colortable[i] = interpolateColor(theme->col_light_ctrl, theme->col_dark_ctrl, i); // TODO; Eliminate floats here!! /* float step = (float)(smp->getNSamples() >> zoom_level) / (float)(width-2); float pos = 0.0f; u32 renderwindow = (u32)MAX(1, MIN(100, ceil(step))); */ #define _fix(x) ((x)<<12) int step = divf32(_fix(smp->getNSamples() >> zoom_level), _fix(width-2)); int pos = 0; int ceil_step = step; if (ceil_step & 0xFFF) { ceil_step &= ~0xFFF; ceil_step ++; } u32 renderwindow = MAX(1, MIN(100, ceil_step>>12)); u16 middle = (DRAW_HEIGHT+2)/2;//-1; s32 lastmax=0, lastmin=0; if(smp->is16bit() == true) { s16 *data; s16 *base = (s16*)smp->getData() + pixelToSample(0); for(u32 i=1; i<u32(width-1); ++i) { data = &(base[pos>>12]); s32 maxsmp = -32767, minsmp = 32767; for(u32 j=0;j<renderwindow;++j) { if(*data > maxsmp) maxsmp = *data; if(*data < minsmp) minsmp = *data; data++; } s32 maxy = div32((DRAW_HEIGHT+2) * maxsmp, 2 * 32767); s32 miny = div32((DRAW_HEIGHT+2) * minsmp, 2 * 32767); if(i>1) { if(lastmin > maxy) maxy = lastmin; if(lastmax < miny) miny = lastmax; } for(s16 j=miny; j<=maxy; ++j) (*vram)[SCREEN_WIDTH*(y+middle-j)+x+i] = colortable[middle-j]; lastmax = maxy; lastmin = miny; *(*vram+SCREEN_WIDTH*(y+middle)+x+i) = colortable[middle]; pos += step; } } else {
QPixmap FoundCountIcon::circledTextPixmap(const QString &text, int height, const QFont &font, const QColor &color) const { QString key = QString("BLI-%1.%2.%3.%4") .arg(text).arg(height).arg(font.toString()).arg(color.rgb()); if (QPixmap* cached = QPixmapCache::find(key)) { return *cached; } // Compute the sizes of the image components: QRectF textRect = QFontMetrics(font).boundingRect(0, 0, /*width=*/1, height, Qt::AlignLeft | Qt::AlignTop, text); qreal xMargin = height / 6; qreal width = xMargin + textRect.width() + xMargin; // Create the gradient image: QPixmap gradient(3 * width, 3 * height); // We double the size to be able to smooth scale down it (== antialiased curves) QPainter gradientPainter(&gradient); #if 1 // Enable the new look of the gradient: const QPalette& palette = m_basketTree->palette(); QColor topColor = palette.color(QPalette::Highlight).lighter(130); //120 QColor topMidColor = palette.color(QPalette::Highlight).lighter(105); //105 QColor bottomMidColor = palette.color(QPalette::Highlight).darker(130); //120 QColor bottomColor = palette.color(QPalette::Highlight); drawGradient(&gradientPainter, topColor, topMidColor, 0, 0, gradient.width(), gradient.height() / 2, /*sunken=*/false, /*horz=*/true, /*flat=*/false); drawGradient(&gradientPainter, bottomMidColor, bottomColor, 0, gradient.height() / 2, gradient.width(), gradient.height() - gradient.height() / 2, /*sunken=*/false, /*horz=*/true, /*flat=*/false); gradientPainter.fillRect(0, 0, gradient.width(), 3, palette.color(QPalette::Highlight)); #else drawGradient(&gradientPainter, palette().color(QPalette::Highlight), palette().color(QPalette::Highlight).darker(), 0, 0, gradient.width(), gradient.height(), /*sunken=*/false, /*horz=*/true, /*flat=*/false); #endif gradientPainter.end(); // Draw the curved rectangle: QBitmap curvedRectangle(3 * width, 3 * height); curvedRectangle.fill(Qt::color0); QPainter curvePainter(&curvedRectangle); curvePainter.setPen(Qt::color1); curvePainter.setBrush(Qt::color1); curvePainter.setClipRect(0, 0, 3*(height / 5), 3*(height)); // If the width is small, don't fill the right part of the pixmap curvePainter.drawEllipse(0, 3*(-height / 4), 3*(height), 3*(height * 3 / 2)); // Don't forget we double the sizes curvePainter.setClipRect(3*(width - height / 5), 0, 3*(height / 5), 3*(height)); curvePainter.drawEllipse(3*(width - height), 3*(-height / 4), 3*(height), 3*(height * 3 / 2)); curvePainter.setClipping(false); curvePainter.fillRect(3*(height / 6), 0, 3*(width - 2 * height / 6), 3*(height), curvePainter.brush()); curvePainter.end(); // Apply the curved rectangle as the mask of the gradient: gradient.setMask(curvedRectangle); QImage resultImage = gradient.toImage(); //resultImage.setAlphaBuffer(true); resultImage.convertToFormat(QImage::Format_ARGB32); // Scale down the image smoothly to get anti-aliasing: QPixmap pmScaled = QPixmap::fromImage(resultImage.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Draw the text, and return the result: QPainter painter(&pmScaled); painter.setPen(color); painter.setFont(font); painter.drawText(0 + 1, 0, width, height, Qt::AlignHCenter | Qt::AlignVCenter, text); painter.end(); QPixmapCache::insert(key, pmScaled); return pmScaled; }
void ListBox::draw(void) { if(!isExposed()) return; calcScrollThingy(); u16 rows_displayed = (height-1)/ROW_HEIGHT; u16 i; // Horizontal Separator Lines for(i=0;i<rows_displayed-1;++i) { drawLine(1,ROW_HEIGHT*(i+1),width-SCROLLBAR_WIDTH-1,1,theme->col_sepline); } // Fill rows for(i=0;i<rows_displayed;++i) { if(scrollpos+i==activeelement) { drawGradient(theme->col_list_highlight1, theme->col_list_highlight2, 1, ROW_HEIGHT*i+1, width-SCROLLBAR_WIDTH-1, ROW_HEIGHT-1); } else { drawGradient(theme->col_medium_bg, theme->col_light_bg, 1, ROW_HEIGHT*i+1, width-SCROLLBAR_WIDTH-1, ROW_HEIGHT-1); } } // Vertical number separator line if(show_numbers) { drawLine(COUNTER_WIDTH,1,height-2,0,theme->col_sepline); } // Scrollbar // Upper Button if(buttonstate==SCROLLUP) { drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, width-SCROLLBAR_WIDTH+1, 1, 8, 8); } else { drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, width-SCROLLBAR_WIDTH+1, 1, 8, 8); } // This draws the up-arrow s8 j, p; for(j=0;j<3;j++) { for(p=-j;p<=j;++p) { *(*vram+SCREEN_WIDTH*(y+j+3)+x+width-SCROLLBAR_WIDTH+4+p) = RGB15(0,0,0) | BIT(15); } } drawBox(width-SCROLLBAR_WIDTH, 0, 9, 9); // Lower Button if(buttonstate==SCROLLDOWN) { drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, width-SCROLLBAR_WIDTH+1, height-9, 8, 8); } else { drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, width-SCROLLBAR_WIDTH+1, height-9, 8, 8); } // This draws the down-arrow for(j=2;j>=0;j--) { for(p=-j;p<=j;++p) { *(*vram+SCREEN_WIDTH*(y-j+height-4)+x+width-SCROLLBAR_WIDTH+4+p) = RGB15(0,0,0) | BIT(15); } } drawBox(width-SCROLLBAR_WIDTH, height-9, 9, 9); drawBox(width-SCROLLBAR_WIDTH, 0, SCROLLBAR_WIDTH,height); // Clear Scrollbar drawGradient(theme->col_medium_bg, theme->col_light_bg, width-SCROLLBAR_WIDTH+1, SCROLLBUTTON_HEIGHT, SCROLLBAR_WIDTH-2, height-2*SCROLLBUTTON_HEIGHT); // The scroll thingy if(buttonstate==SCROLLTHINGY) { drawFullBox(width-SCROLLBAR_WIDTH+1, SCROLLBUTTON_HEIGHT-1+scrollthingypos, SCROLLBAR_WIDTH-2, scrollthingyheight, theme->col_list_highlight2); } else { drawFullBox(width-SCROLLBAR_WIDTH+1, SCROLLBUTTON_HEIGHT-1+scrollthingypos, SCROLLBAR_WIDTH-2, scrollthingyheight, theme->col_list_highlight1); } drawBox(width-SCROLLBAR_WIDTH, SCROLLBUTTON_HEIGHT+scrollthingypos-1, SCROLLBAR_WIDTH, scrollthingyheight); // Numbers (if enabled) u16 contentoffset; if(show_numbers) { char *numberstr = (char*)malloc(4); //iprintf("%u %u\n",scrollpos,elements.size()); u16 offset; if(zero_offset==true) { offset=0; } else { offset=1; } for(i=0;(i<height/ROW_HEIGHT)&&(scrollpos+i<elements.size());++i) { sprintf(numberstr,"%2x",scrollpos+i+offset); drawString(numberstr, 2, ROW_HEIGHT*i+2); } free(numberstr); contentoffset = COUNTER_WIDTH; } else { contentoffset = 0; } // Content for(i=0;(i<height/ROW_HEIGHT)&&(scrollpos+i<elements.size());++i) { drawString(elements.at(scrollpos+i).c_str(), contentoffset+2, ROW_HEIGHT*i+2, width-contentoffset-2-SCROLLBAR_WIDTH-2); } drawBorder(); }
void GradientLayer::draw(Graphics* const TheGraphics, const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Real32 Opacity) const { if(getMFColors()->size() == getMFStops()->size()) { if(getMFColors()->size() == 1) { TheGraphics->drawQuad(TopLeft, Pnt2f(BottomRight.x(), TopLeft.y()), BottomRight, Pnt2f(TopLeft.x(), BottomRight.y()), getColors(0), getColors(0), getColors(0), getColors(0), Opacity); } else { Pnt2f StartPosition= TopLeft; StartPosition[0] += getStartPosition()[0]*(BottomRight[0] - TopLeft[0]); StartPosition[1] += getStartPosition()[1]*(BottomRight[1] - TopLeft[1]); Pnt2f EndPosition= TopLeft; EndPosition[0] += getEndPosition()[0]*(BottomRight[0] - TopLeft[0]); EndPosition[1] += getEndPosition()[1]*(BottomRight[1] - TopLeft[1]); //Calculate the coordinate system Vec2f u(EndPosition-StartPosition); u.normalize(); Vec3f v3D(Vec3f(u.x(), u.y(), 0.0f).cross(Vec3f(0.0,0.0,-1.0))); Vec2f v(v3D.x(), v3D.y()); Matrix22<Real32> CoordinateSystem(u.x(), u.y(), v.x(), v.y()); Pnt2f Min; Pnt2f Max; { //Calculate the bounding box in the new coordinate system Pnt2f UVTopLeft(CoordinateSystem*TopLeft), UVBottomRight(CoordinateSystem*BottomRight), UVTopRight(CoordinateSystem*Vec2f(BottomRight.x(), TopLeft.y())), UVBottomLeft(CoordinateSystem*Vec2f(TopLeft.x(), BottomRight.y())); Min.setValues( osgMin(UVTopLeft.x(), osgMin(UVBottomRight.x(), osgMin(UVTopRight.x(), UVBottomLeft.x()))), osgMin(UVTopLeft.y(), osgMin(UVBottomRight.y(), osgMin(UVTopRight.y(), UVBottomLeft.y())))); Max.setValues( osgMax(UVTopLeft.x(), osgMax(UVBottomRight.x(), osgMax(UVTopRight.x(), UVBottomLeft.x()))), osgMax(UVTopLeft.y(), osgMax(UVBottomRight.y(), osgMax(UVTopRight.y(), UVBottomLeft.y())))); } Pnt2f Origin(CoordinateSystem.inverse() * Min); Real32 PreStartLength(((CoordinateSystem*StartPosition).x()-Min.x())/(Max.x() - Min.x())), PostEndLength((Max.x()- (CoordinateSystem*EndPosition).x())/(Max.x() - Min.x())), GradientLength(1.0f-PostEndLength-PreStartLength); if(getSpreadMethod() == SPREAD_REFLECT|| getSpreadMethod() == SPREAD_REPEAT) { //Code for drawing the Gradient with Repeating/Reflection //Determine the Number of Repeats UInt32 RepeatCount = static_cast<UInt32>(osgCeil(1.0f/GradientLength)); //Determine the relative location in the gradient that the Start left is at Real32 StartGradientLocation = PreStartLength - GradientLength * osgCeil(PreStartLength/GradientLength); //Determine whether the start is a reflection or normal bool isReflection = getSpreadMethod() == SPREAD_REFLECT && static_cast<UInt32>(osgCeil(PreStartLength/GradientLength))%2==1; for(UInt32 i(0) ; i<RepeatCount ; ++i) { if(isReflection) { drawGradient(TheGraphics, Origin, Max-Min,u,StartGradientLocation+GradientLength*(i+1),StartGradientLocation+GradientLength*i,Opacity); } else { drawGradient(TheGraphics, Origin, Max-Min,u,StartGradientLocation+GradientLength*i,StartGradientLocation+GradientLength*(i+1),Opacity); } if(getSpreadMethod() == SPREAD_REFLECT) { isReflection = !isReflection; } } } else { //Code for drawing the Gradient with Padding //Front Pad if(PreStartLength != 0.0f) { drawPad(TheGraphics, Origin, Max-Min,u,0.0,PreStartLength,getMFColors()->front(),Opacity); } drawGradient(TheGraphics, Origin, Max-Min,u,PreStartLength,PreStartLength+GradientLength,Opacity); //End Pad if(PostEndLength != 0.0f) { drawPad(TheGraphics, Origin, Max-Min,u,PreStartLength+GradientLength,1.0,getMFColors()->back(),Opacity); } } } } }
void QmitkPopupColorChooser::paintEvent(QPaintEvent*) { QPainter painter(this); drawGradient( &painter ); }