Fix fabricjs Animating Demo - fabricjs

I'm new in fabricjs. I'm expecting to draw a line with a circle moving on it.
I found this Demo quite useful, but I have no idea why the crosses are not animating. I think that they are supposed to change their size.
So can anyone tell me how to fix this demo? Or is there anything I've done wrong?
Thanks.

fabricjs 1.7.0 introduced object caching. It would appear that in the animation demo the crosses are being redrawn from the cache, so they don't update. For a quick and dirty solution, if you disable caching (by setting objectCaching to false) at an object level, the demo works again. Alternatively, you can set the dirty flag on each object to let it know that the object has changed. For example, in the timeout from the demo, just modify it slightly:
canvas.forEachObject(function(obj){
obj.animateWidthHeight();
obj.dirty = true;
});
http://jsfiddle.net/7gvJG/139/

Related

What exactly does layout_scrollFlags = "snapMargins" do?

I've read the documentation of this attribute:
An additional flag to be used with 'snap'. If set, the view will be snapped to its top and bottom margins, as opposed to the edges of the view itself.
https://developer.android.com/reference/com/google/android/material/appbar/AppBarLayout.LayoutParams.html#scroll_flag_snap
But I can't observe any actual effect in my app. What margin are they talking about? Every margin on the CollapsingToolbarLayout (on which this attribute is set) completely destroys the layout.
Not sure if it's useful yet, but here is the difference:)
If you pass snap as scroll flag, then it will move your view (in my case this search bar, it's linearLayout) to it's edge NOT INCLUDING the margin_layout
Then I've tried snap|snapMargin and it moved with the margin
P.S. No idea why snapMargin doesn't work without snap ¯\_(ツ)_/¯
This attribute is responsible for a scrolling behavior of AppBarLayout and its children. You can apply it directly to AppBarLayout or on the inside views, in the xml layout of your AppCompatActivity. It has to be an instance of AppCompatActivity if you want to use AppBar features. Also, the design library must be included in Gradle dependencies, like so: implementation 'com.android.support:design:26.1.0'
Please refer this link:-[https://medium.com/#tonia.tkachuk/appbarlayout-scroll-behavior-with-layout-scrollflags-2eec41b4366b][1]

Resizable MKOverlay using MKOverlayRenderer

I want to have a custom MKOverlay that's a circle anchored to the user location annotation that the user can resize by pinching. I was able to successfully achieve this using MKOverlayPathRenderer and a custom MKOverlay object by overriding the createPath method and making an arc. The resizing and moving of the overlay was handled by using KVO on the radius and coordinate properties of my overlay. However the resizing was incredibly choppy and the boundingMapRect wasn't correctly calculated.
I've also tried using an image and instead of subclassing MKOverlayPathRenderer just MKOverlayRenderer, overriding - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context but when I resize my CPU percentage jumps to 160% usage (not great yeah?) and the boundingRect is again being drawn incorrectly.
I really think the way to do it is with MKOverlayPathRenderer and maybe having an atomic counter of some kind so that a redraw only gets called say every 5 or 10 times the pinch gesture is triggered.
Does anyone have any suggestions? I've also considered but haven't tried making a UIView and adding it as a subview to the map view and putting the pinch gesture on that but that seems hacky and dirty.
When you computed new boundingMapRect on the Overlay, you must invoke invalidatePath on your Renderer. After that, system will invoke createPath for you when appropriate.

fabric.js make active object on top of others when dragging

my question is, fabric.js makes active object on top of others when dragging.
I know a property can do this, can't remind.
Thanks.
You can do it like this:
canvas.add(red, blue); // add youre objects..
function myDrag(e) { // funciton on drag (moving)
e.target.bringToFront();
}
canvas.on({
'object:moving': myDrag,
});
Want to add more events? Use the Event inspector # fabricjs
I made a working Fiddle. Hopes it helps...
I know it's been a long time since you asked this but I want to answer it if anyone would stuck for that.
This behavior is default in fabric js right know but if you want to change it just set preserveObjectStacking to false when initializing the canvas. See more in documentation.

Using GDI+ to draw tooltip

I'm new to GDI+ programming and am looking for some advice.
I am loading an image from a file and displaying it using the following functions (some pseudo code included):
Gdiplus::Image *i = new Gdiplus::Image(file, other parameters ... );
Gdiplus::DrawImage(i, other parameters ... );
I would like to associate a tooltip with the image. Is there any way that I can automatically set/attach a tooltip to the Gdiplus::Image objact (or any other Gdiplus control that I wish to draw for that matter)?
If not, how can such functionality be achieved? I have looked at CToolTipCtrl in WTL but don't know how to attach it to the Gdiplus::Image.
Thanks in advance.
After investigating this more, I've realised that this is not possible, so to speak. You must use GDI+ to draw your own tool tip my monitoring mouse events to see when it is hovering over something, then using the device context to do the drawing withing the mouse hover event handler.

Core data dirty flag not being set

I have a core data document based cocoa app that is working well except for one slightly odd problem.
For some reason, if I make a change to any of my fields the menu/window don't seem to recognize it - ie. the red close button doesn't get the black 'dirty' indicator and the File/Save menu item isn't enabled. However, if I attempt to close the application (via command-Q), I do get the popup asking me if I want to save my changes.
It seems that the document's dirty flag is being set, but the window/menu items aren't reacting to it. I am curious as to where I might look to see why this might be the case. I suspect that it may have something to do with my window not knowing about my ManagedObjectContext...
The only slightly atypical behaviour is that my document's makeWindowControllers method has been overridden and I am adding my window controllers using a call to my document's [self addWindowController:xxx] method. My window controllers subclass from NSWindowController so I had to add my own instance variable to each window controller to hold the ManagedObjectContext, but I suspect that this isn't getting passed to the window/menu. Not sure what the normal pattern is here...
Anyway, any thoughts would be much appreciated. Thanks
From the description it sounds like your UI elements are not actually bound to the document itself. If so, then the UI elements are not observing the document and are not reacting to changes in the document. Check the bindings.
Thanks in part to TechZen, and also re-reading my own question (in particular, where I said "I suspect that it may have something to do with my window not knowing about my ManagedObjectContext") I started to look at the bindings for my WindowController subclass.
As it turned out, I hadn't bound the window outlet for the File's Owner to my actual NSWindow. As soon as I did that, the black dirty dot and the window's menus started behaving correctly.

Resources