void ofxNUIWidgetNode::widgetEventListener(ofxUIEventArgs &e) { for (int i=0; i < getCanvas()->getWidgets().size(); i++) { ofxUIWidget *widget = getCanvas()->getWidgets().at(i); if(e.widget->getName() == widget->getName()){ /* Slider */ if (widget->getKind() == OFX_UI_WIDGET_SLIDER_H || widget->getKind() == OFX_UI_WIDGET_SLIDER_V) { ofxUISlider *slider = dynamic_cast<ofxUISlider*>(widget); widgetFunctions(slider->getName()); } /* Int Slider */ else if (widget->getKind() == OFX_UI_WIDGET_INTSLIDER_H || widget->getKind() == OFX_UI_WIDGET_INTSLIDER_V) { ofxUIIntSlider *intSlider = dynamic_cast<ofxUIIntSlider*>(widget); widgetFunctions(intSlider->getName()); } /* Number Dialer */ else if (widget->getKind() == OFX_UI_WIDGET_NUMBERDIALER) { ofxUINumberDialer *numberDialer = dynamic_cast<ofxUINumberDialer*>(widget); widgetFunctions(numberDialer->getName()); } /* Drop Down List */ else if (widget->getKind() == OFX_UI_WIDGET_DROPDOWNLIST) { ofxUIDropDownList *dropDownList = dynamic_cast<ofxUIDropDownList*>(widget); if (ofGetMousePressed() == false && dropDownList->getSelected().size()) { ofxUIWidget *selected = dropDownList->getSelected().front(); widgetFunctions(selected->getName()); } } /* Label Button */ else if (widget->getKind() == OFX_UI_WIDGET_LABELBUTTON) { ofxUILabelButton *labelButton = dynamic_cast<ofxUILabelButton*>(widget); if(ofGetMousePressed() == false){ widgetFunctions(labelButton->getName()); labelButton->setValue(false); } } /* Text Input */ else if (widget->getKind() == OFX_UI_WIDGET_TEXTINPUT) { ofxUITextInput *textInput = dynamic_cast<ofxUITextInput*>(widget); widgetFunctions(textInput->getName()); } break; } } }
TransFuncPrimitive* TransFuncIntensityGradientPainter::getPrimitiveUnderMouse(tgt::vec2 pos) { TransFuncPrimitive* clicked = 0; getCanvas()->getGLFocus(); glPushAttrib(GL_ALL_ATTRIB_BITS); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glLoadIdentity(); glDisable(GL_BLEND); // paint all primitives with special color // (first component is id and both other components are 123) tf_->paintForSelection(); glPopMatrix(); glPopAttrib(); // read pixels at clicked position GLubyte pixel[3]; glReadPixels(static_cast<int>(getCanvas()->getWidth()*pos.x), static_cast<int>(getCanvas()->getHeight()*pos.y), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); if ((pixel[1] == 123) && (pixel[2] == 123)) clicked = tf_->getPrimitive(pixel[0]); // no primitive clicked but the user could have clicked on a control point if (!clicked) clicked = tf_->getPrimitiveForClickedControlPoint(pos); return clicked; }
void TransFuncIntensityGradientPainter::mouseMoveEvent(tgt::MouseEvent* event) { event->accept(); tgt::ivec2 size = getCanvas()->getSize(); tgt::vec2 pos = tgt::vec2( static_cast<float>(event->x()) / size.x, 1.f-static_cast<float>(event->y()) / size.y); tgt::vec2 offset = pos - mouseCoord_; if (selectedPrimitive_) { if (!dragging_) { emit toggleInteractionMode(true); dragging_ = true; } // test whether the movement is correct /*bool inside = */selectedPrimitive_->move(offset); // one or more control points are moved outside of the canvas // -> do not allow movement and reset mouse cursor to position before movement //if (!inside) { //tgt::QtCanvas* canvas = static_cast<tgt::QtCanvas*>(getCanvas()); //QPoint p(static_cast<int>(mouseCoord_.x * size.x), //static_cast<int>((1.f - mouseCoord_.y) * size.y)); //p = canvas->mapToGlobal(p); //QCursor::setPos(p); //} //else { mouseCoord_ = pos; updateTF(); //} } getCanvas()->update(); }
void ofxNUIWidgetNode::customDraw2D() { ofxNUINode::customDraw2D(); if (getCanvas()->isVisible()) { getCanvas()->draw(); } }
void ofxNUIWidgetNode::update() { ofxNUINode::update(); if (getCanvas()->isVisible()) { updateSuperCanvas(); getCanvas()->update(); } }
//----------------------------------------------------------------------------- // Name: GUIEditableTextLine // Desc: Initializes the class //----------------------------------------------------------------------------- GUIEditableTextLine::GUIEditableTextLine() : myMouseSentinel(this), myKeyboardSentinel(this), myTextElement(this) { myCaretLocation = 0; myHorizontalTextOffset = 0.0f; myTextElement.setClippingArea(getCanvas()->getArea()); myTextElement.setSourceCanvas(getCanvas()); }
static sk_sp<SkImage> render(const SkTextBlob* blob) { auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(blob->bounds().width()), SkScalarRoundToInt(blob->bounds().height())); if (!surf) { return nullptr; // bounds are empty? } surf->getCanvas()->clear(SK_ColorWHITE); surf->getCanvas()->drawTextBlob(blob, -blob->bounds().left(), -blob->bounds().top(), SkPaint()); return surf->makeImageSnapshot(); }
// Tests getFont with default font TEST_F( Surface, font_default ){ canvas::Rect rect(0, 0, 720, 576); canvas::Surface* s = getCanvas()->createSurface( rect ); ASSERT_TRUE( s != NULL ); std::vector<std::string> familiesGet = s->getFont().families(); ASSERT_TRUE( std::find(familiesGet.begin(), familiesGet.end(), "Tiresias") != familiesGet.end() ); getCanvas()->destroy( s ); }
/// Surface rendered from an image and then setVisible to false. TEST_F( SurfaceVisible, nothing_compare ) { canvas::Surface* s = getCanvas()->createSurfaceFromPath( util::getImageName("blue.jpg") ); ASSERT_TRUE( s != NULL ); s->autoFlush(true); s->setVisible(false); ASSERT_FALSE( s->isVisible() ); ASSERT_TRUE( util::compareImages( getCanvas(), "nothing" ) ); getCanvas()->destroy( s ); }
TEST_F(Surface, font_descent_without_font_family_setted) { canvas::Surface* s = getCanvas()->createSurface(canvas::Rect(0, 0, 720, 576)); canvas::Font f; s->setFont(f); ASSERT_TRUE( s != NULL ); ASSERT_TRUE(compare(s->fontDescent(), 2, THRESHOLD )); getCanvas()->destroy(s); }
void DivNode::render(GLContext* pContext, const glm::mat4& transform) { if (getCrop() && getSize() != glm::vec2(0,0)) { getCanvas()->pushClipRect(pContext, transform, m_ClipVA); } for (unsigned i = 0; i < getNumChildren(); i++) { getChild(i)->maybeRender(pContext, transform); } if (getCrop() && getSize() != glm::vec2(0,0)) { getCanvas()->popClipRect(pContext, transform, m_ClipVA); } }
static void draw_zero_length_capped_paths(SkCanvas* canvas, bool aa) { canvas->translate(kCellPad, kCellPad); SkImageInfo info = canvas->imageInfo().makeWH(kCellWidth, kCellHeight); auto surface = canvas->makeSurface(info); if (!surface) { surface = SkSurface::MakeRasterN32Premul(kCellWidth, kCellHeight); } SkPaint paint; paint.setColor(SK_ColorWHITE); paint.setAntiAlias(aa); paint.setStyle(SkPaint::kStroke_Style); int numFailedTests = 0; for (auto cap : kCaps) { for (auto width : kWidths) { paint.setStrokeCap(cap); paint.setStrokeWidth(width); canvas->save(); for (auto verb : kAllVerbs) { SkString pathStr; pathStr.appendf("M %f %f ", (kCellWidth - 1) * 0.5f, (kCellHeight - 1) * 0.5f); if (verb) { pathStr.append(verb); } SkPath path; SkParsePath::FromSVGString(pathStr.c_str(), &path); surface->getCanvas()->clear(SK_ColorTRANSPARENT); surface->getCanvas()->drawPath(path, paint); auto img = surface->makeImageSnapshot(); // All cases should draw one cap, except for butt capped, and dangling moves // (without a verb or close), which shouldn't draw anything. int expectedCaps = ((SkPaint::kButt_Cap == cap) || !verb) ? 0 : 1; if (!draw_path_cell(canvas, img.get(), expectedCaps)) { ++numFailedTests; } canvas->translate(kCellWidth + kCellPad, 0); } canvas->restore(); canvas->translate(0, kCellHeight + kCellPad); } } canvas->drawColor(numFailedTests > 0 ? kFailureRed : kSuccessGreen); }
// Set visible to false and then to true TEST_F( SurfaceVisible, image_true_dynamic){ canvas::Surface* s = getCanvas()->createSurfaceFromPath( util::getImageName( "red.jpg" ) ); ASSERT_TRUE( s != NULL ); s->setVisible(false); ASSERT_FALSE(s->isVisible()); s->autoFlush(true); s->setVisible(true); ASSERT_TRUE(s->isVisible()); ASSERT_TRUE( util::compareImages( getCanvas(), getExpectedPath("true_dynamic"))); getCanvas()->destroy( s ); }
TEST_F(Surface, font_descent_without_font_family_smallcaps_size20) { canvas::Surface* s = getCanvas()->createSurface(canvas::Rect(0, 0, 720, 576)); canvas::Font f; f.size(20); f.smallCaps(true); s->setFont(f); ASSERT_TRUE( s != NULL ); ASSERT_TRUE(compare(s->fontDescent(), 5, THRESHOLD )); getCanvas()->destroy(s); }
bool LinePath::insertPoint( int pointIndex, const QPoint &point ) { int count = m_LineList.count(); if( count == 0 ) return false; const bool bLoading = UMLApp::app()->getDocument()->loading(); if( count == 1 || pointIndex == 1) { QCanvasLine * first = m_LineList.first(); QPoint sp = first -> startPoint(); QPoint ep = first -> endPoint(); first -> setPoints( sp.x(), sp.y(), point.x(), point.y() ); QCanvasLine * line = new QCanvasLine( getCanvas() ); line -> setZ( -2 ); line -> setPoints( point.x(), point.y(), ep.x(), ep.y() ); line -> setPen( getPen() ); line -> setVisible( true ); m_LineList.insert( 1, line ); if (!bLoading) setupSelected(); return true; } if( count + 1 == pointIndex ) { QCanvasLine * before = m_LineList.last(); QPoint sp = before -> startPoint(); QPoint ep = before -> endPoint(); before -> setPoints( sp.x(), sp.y(), point.x(), point.y() ); QCanvasLine * line = new QCanvasLine( getCanvas() ); line -> setPoints( point.x(), point.y(), ep.x(), ep.y() ); line -> setZ( -2 ); line -> setPen( getPen() ); line -> setVisible( true ); m_LineList.append( line ); if (!bLoading) setupSelected(); return true; } QCanvasLine * before = m_LineList.at( pointIndex - 1 ); QPoint sp = before -> startPoint(); QPoint ep = before -> endPoint(); before -> setPoints( sp.x(), sp.y(), point.x(), point.y() ); QCanvasLine * line = new QCanvasLine(getCanvas() ); line -> setPoints( point.x(), point.y(), ep.x(), ep.y() ); line -> setZ( -2 ); line -> setPen( getPen() ); line -> setVisible( true ); m_LineList.insert( pointIndex, line ); if (!bLoading) setupSelected(); return true; }
TEST_F(Surface, font_descent_with_dejavusans_family_setted) { canvas::Surface* s = getCanvas()->createSurface(canvas::Rect(0, 0, 720, 576)); canvas::Font f; std::vector<std::string> families; families.push_back("DejaVuSans"); f.families(families); s->setFont(f); ASSERT_TRUE( s != NULL ); ASSERT_TRUE(compare(s->fontDescent(), 2, THRESHOLD )); getCanvas()->destroy(s); }
void VoreenPainter::initialize() { if (getCanvas()) { getCanvas()->getGLFocus(); } else { LWARNING("initialize(): No canvas"); } glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); }
void pix_frei0r :: openMess(t_symbol*s) { if(!m_canopen) { error("this instance cannot dynamically change the plugin"); return; } std::string pluginname = s->s_name; if(m_plugin) { delete m_plugin; } m_plugin=NULL; try { std::string filename = pluginname; gem::RTE::RTE*rte=gem::RTE::RTE::getRuntimeEnvironment(); if(rte) { filename=rte->findFile(pluginname, GemDylib::getDefaultExtension(), getCanvas()); } m_plugin = new F0RPlugin(filename); } catch (GemException&x) { error("%s", x.what()); } if(NULL==m_plugin) { error("unable to open '%s'", pluginname.c_str()); return; } }
// Test drawing text with some unusual matricies. // We measure success by not crashing or asserting. DEF_TEST(DrawText_weirdMatricies, r) { auto surface = SkSurface::MakeRasterN32Premul(100,100); auto canvas = surface->getCanvas(); SkPaint paint; paint.setAntiAlias(true); paint.setLCDRenderText(true); struct { SkScalar textSize; SkScalar matrix[9]; } testCases[] = { // 2x2 singular {10, { 0, 0, 0, 0, 0, 0, 0, 0, 1}}, {10, { 0, 0, 0, 0, 1, 0, 0, 0, 1}}, {10, { 0, 0, 0, 1, 0, 0, 0, 0, 1}}, {10, { 0, 0, 0, 1, 1, 0, 0, 0, 1}}, {10, { 0, 1, 0, 0, 1, 0, 0, 0, 1}}, {10, { 1, 0, 0, 0, 0, 0, 0, 0, 1}}, {10, { 1, 0, 0, 1, 0, 0, 0, 0, 1}}, {10, { 1, 1, 0, 0, 0, 0, 0, 0, 1}}, {10, { 1, 1, 0, 1, 1, 0, 0, 0, 1}}, // See https://bugzilla.mozilla.org/show_bug.cgi?id=1305085 . { 1, {10, 20, 0, 20, 40, 0, 0, 0, 1}}, }; for (const auto& testCase : testCases) { paint.setTextSize(testCase.textSize); const SkScalar(&m)[9] = testCase.matrix; SkMatrix mat; mat.setAll(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]); canvas->setMatrix(mat); canvas->drawString("Hamburgefons", 10, 10, paint); } }
// Verify that associated bitmap cache entries are purged on SkImage destruction. DEF_TEST(BitmapCache_discarded_image, reporter) { // Cache entries associated with SkImages fall into two categories: // // 1) generated image bitmaps (managed by the image cacherator) // 2) scaled/resampled bitmaps (cached when HQ filters are used) // // To exercise the first cache type, we use generated/picture-backed SkImages. // To exercise the latter, we draw scaled bitmap images using HQ filters. const SkMatrix xforms[] = { SkMatrix::MakeScale(1, 1), SkMatrix::MakeScale(1.7f, 0.5f), }; for (size_t i = 0; i < SK_ARRAY_COUNT(xforms); ++i) { test_discarded_image(reporter, xforms[i], []() { auto surface(SkSurface::MakeRasterN32Premul(10, 10)); surface->getCanvas()->clear(SK_ColorCYAN); return surface->makeImageSnapshot(); }); test_discarded_image(reporter, xforms[i], []() { SkPictureRecorder recorder; SkCanvas* canvas = recorder.beginRecording(10, 10); canvas->clear(SK_ColorCYAN); return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10), nullptr, nullptr, SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); }); } }
static void test_discarded_image(skiatest::Reporter* reporter, const SkMatrix& transform, sk_sp<SkImage> (*buildImage)()) { auto surface(SkSurface::MakeRasterN32Premul(10, 10)); SkCanvas* canvas = surface->getCanvas(); // SkBitmapCache is global, so other threads could be evicting our bitmaps. Loop a few times // to mitigate this risk. const unsigned kRepeatCount = 42; for (unsigned i = 0; i < kRepeatCount; ++i) { SkAutoCanvasRestore acr(canvas, true); sk_sp<SkImage> image(buildImage()); // always use high quality to ensure caching when scaled SkPaint paint; paint.setFilterQuality(kHigh_SkFilterQuality); // draw the image (with a transform, to tickle different code paths) to ensure // any associated resources get cached canvas->concat(transform); canvas->drawImage(image, 0, 0, &paint); const auto desc = SkBitmapCacheDesc::Make(image.get()); // delete the image image.reset(nullptr); // all resources should have been purged SkBitmap result; REPORTER_ASSERT(reporter, !SkBitmapCache::Find(desc, &result)); } }
static void test_crbug131181() { /* fX = 18.8943768, fY = 129.121277 }, { fX = 18.8937435, fY = 129.121689 }, { fX = 18.8950119, fY = 129.120422 }, { fX = 18.5030727, fY = 129.13121 */ uint32_t data[] = { 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 }; SkPath path; moveToH(&path, &data[0]); cubicToH(&path, &data[2]); auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkPaint paint; paint.setAntiAlias(true); surface->getCanvas()->drawPath(path, paint); }
// test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint) static void test_big_aa_rect(skiatest::Reporter* reporter) { SkBitmap output; SkPMColor pixel[1]; output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4); auto surf = SkSurface::MakeRasterN32Premul(300, 33300); SkCanvas* canvas = surf->getCanvas(); SkRect r = { 0, 33000, 300, 33300 }; int x = SkScalarRoundToInt(r.left()); int y = SkScalarRoundToInt(r.top()); // check that the pixel in question starts as transparent (by the surface) if (surf->readPixels(output, x, y)) { REPORTER_ASSERT(reporter, 0 == pixel[0]); } else { REPORTER_ASSERT(reporter, false, "readPixels failed"); } SkPaint paint; paint.setAntiAlias(true); paint.setColor(SK_ColorWHITE); canvas->drawRect(r, paint); // Now check that it is BLACK if (surf->readPixels(output, x, y)) { // don't know what swizzling PMColor did, but white should always // appear the same. REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]); } else { REPORTER_ASSERT(reporter, false, "readPixels failed"); } }
void TransFuncIntensityGradientPainter::histogramBrightnessChanged(int brightness) { histogramBrightness_ = brightness / 100.f; updateHistogramTexture(); getCanvas()->update(); }
void TransFuncIntensityGradientPainter::toggleHistogramLogarithmic(int state) { histogramLogarithmic_ = static_cast<bool>(state); updateHistogramTexture(); getCanvas()->update(); }
void ofxNUIWidgetNode::setCamera(ofEasyCam *_cam) { ofxNUINode::setCamera(_cam); ofAddListener(getCanvas()->newGUIEvent, this, &ofxNUIWidgetNode::widgetEventListener); updateSuperCanvasPosition(); }
void RasterNode::scheduleFXRender() { if (m_pFXNode) { getCanvas()->scheduleFXRender( dynamic_pointer_cast<RasterNode>(shared_from_this())); } }
// Need to exercise drawing an inverse-path whose bounds intersect the clip, // but whose edges do not (since its a quad which draws only in the bottom half // of its bounds). // In the debug build, we used to assert in this case, until it was fixed. // static void test_inversepathwithclip() { SkPath path; path.moveTo(0, 20); path.quadTo(10, 10, 20, 20); path.toggleInverseFillType(); SkPaint paint; auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkCanvas* canvas = surface->getCanvas(); canvas->save(); canvas->clipRect(SkRect::MakeWH(19, 11)); paint.setAntiAlias(false); canvas->drawPath(path, paint); paint.setAntiAlias(true); canvas->drawPath(path, paint); canvas->restore(); // Now do the test again, with the path flipped, so we only draw in the // top half of our bounds, and have the clip intersect our bounds at the // bottom. path.reset(); // preserves our filltype path.moveTo(0, 10); path.quadTo(10, 20, 20, 10); canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11)); paint.setAntiAlias(false); canvas->drawPath(path, paint); paint.setAntiAlias(true); canvas->drawPath(path, paint); }
void ofxNUIWidgetNode::setHighlight(bool _isHighlighted) { ofxNUINode::setHighlight(_isHighlighted); if (!isHighlighted() && !isActive()) { getCanvas()->setVisible(false); } else if (isHighlighted()) { getCanvas()->setVisible(true); updateSuperCanvas(); getCanvas()->autoSizeToFitWidgets(); } }
ofxUIEnvelopeEditor* ofxNUIWidgetNode::addWidgetEnvelopeEditor(string _name, ofxUIEnvelope*_envelope, bool _isFreq) { ofxUIEnvelopeEditor *envelopeEditor; getCanvas()->addWidgetDown(envelopeEditor = new ofxUIEnvelopeEditor(_name, _envelope,ENVELOPE_EDITOR_WIDTH, ENVELOPE_EDITOR_HEIGHT, 0.0f, 0.0f)); envelopeEditor->isFrequency = _isFreq; return envelopeEditor; }