Comments (2)
So, here's am minimal code example that implements an eyedropper that shows the pixel color under the mouse cursor. The code works fine unless we embed that view in a CLayeredViewContainer on Mac, pa->getColor(color); always returns black in that case. On Windows it works either way which implies that it has something to do with the CALayer based implementation.
I'm aware that the backround graphic could be accessed directly, but imagine the CEyedropperView ::drawRect() implementation could draw anything.
class CEyedropperView : public CView
{
public:
CEyedropperView(const CRect &size, CFrame *parent, CBitmap *hBackround) : CView(size)
{
setBackground(hBackround);
oc = COffscreenContext::create(parent, getWidth(), getHeight());
}
virtual void drawRect(CDrawContext *pContext, const CRect& updateRect) override
{
// Draw contents to COffscreenContext.
if(oc)
{
oc->beginDraw();
CView::drawRect(oc, updateRect);
oc->endDraw();
}
// NOTE: We could simply use oc->copyFrom() here so stuff doesn't need
// to be drawn twice, but that would also require oc to be oversampled
// for HighDPI / Retina displays. That doesn't have anything to do with
// the issue itself though
CView::drawRect(pContext, updateRect);
// Draw eyedropper: The oc's bitmap is used to retrieve the pixel values
// under the mouse cursor
if(oc && eyedropperActive)
{
auto pa = VSTGUI::owned(CBitmapPixelAccess::create(oc->getBitmap()));
if(pa)
{
CColor color;
pa->setPosition(uint32_t(lastMousePoint.x), uint32_t(lastMousePoint.y));
pa->getColor(color);
CRect rect(-15.0, -15.0, +15.0, +15.0);
rect.offset(lastMousePoint);
pContext->setDrawMode(kAntiAliasing);
pContext->setLineWidth(2.0);
pContext->setFrameColor(kWhiteCColor);
pContext->setFillColor(color);
pContext->drawEllipse(rect, kDrawFilledAndStroked);
}
}
}
// Keep track of mouse cursor position
virtual CMouseEventResult onMouseMoved(CPoint& where, const CButtonState& buttons) override
{
if(where != lastMousePoint)
{
lastMousePoint = where;
invalid();
}
return CView::onMouseMoved(where, buttons);
}
virtual CMouseEventResult onMouseEntered(CPoint& where, const CButtonState& buttons) override
{
if(getFrame())
getFrame()->setCursor(kCursorHand);
eyedropperActive = true;
invalid();
return kMouseEventHandled;
}
virtual CMouseEventResult onMouseExited(CPoint& where, const CButtonState& buttons) override
{
if(getFrame())
getFrame()->setCursor(kCursorDefault);
eyedropperActive = false;
invalid();
return kMouseEventHandled;
}
CLASS_METHODS(CEyedropperView, CView);
protected:
SharedPointer<COffscreenContext> oc;
CPoint lastMousePoint;
bool eyedropperActive{false};
};
from vstgui.
OK, now I understand the issue. The problem is, that CLayeredViewContainers are an optimization and are not redrawn in a normal way. So you cannot call draw(..) or drawRect(..) on it. That are no-ops.
A possible workaround is, to find all instances in your view hierarchy and after you've drawn the normal views, you call drawViewLayer() on that instances (you have to cast to IPlatformViewLayerDelegate before, otherwise the method is protected). You may have to offset the draw context by the top-left position of the view relative to the frame.
from vstgui.
Related Issues (20)
- Reintroduce setBackOffset() / getBackOffset() and respect the backOffset in all views / controls HOT 4
- FR - Linux HIDPI support HOT 9
- Requesting accessibility implementation, expose GUI controls to platform specific APIs HOT 7
- Use of new CMultiBitmap implementation in CAnimKnob is not backwards compatible HOT 1
- 4.12.1 cswitch.cpp fails compilation with VSTGUI_ENABLE_DEPRECATED_METHODS=0 HOT 1
- CAnimKnob not receiving mouse button release in some hosts HOT 20
- Unhandled exception when using vstgui HOT 2
- compile error after updating to Xcode 14.3: no member named 'move' in namespace 'std'
- getChildViewsOfType() with option 'deep' searches only one level deep HOT 1
- ui built on ver 4.11+ will flicker especially run on vst3plugintesthost 64bit HOT 8
- Issue when building with Xcode 14.3 HOT 1
- Segment Button segment names string gets replaced by parameter steps normalized value in Release build HOT 3
- Font drawing inconsistencies between Mac and Windows HOT 5
- [Windows] Cannot move window after a COptionMenu has been popped up HOT 2
- Standalone application crash with newest version of vst3sdk (3.7.9) on Windows when using transforms HOT 6
- std::unique_ptr of forward-declared types HOT 1
- COptionMenu().getMax() returns 18446744073709551616
- Build error while compiling vst3sdk on Fedora 40 HOT 2
- Mac Fails to compile generated project HOT 1
- Custom Fonts on Windows broken if ExitDll called but DLL not actually unloaded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vstgui.