What are the available options for Canvas initialisation in FabricJs? - fabricjs

initialize takes an "options" object according to the documentation here
However, it seems that the options object is not defined. I briefly searched the source code, but that didn't reveal anything.
Where can I get the definition of options object?

You can pass options object as the second parameter of constructor as here:
new fabric.Canvas('c', {
width: 600,
height: 600
})
Then when will invoke the initialize method all props in options object, in the end, will set to fabric canvas object. You can see it here in source code.
So, the definition of options object is all props and methods of fabric.Canvas. You can see them in source code below the initialize method, uniScaleTransform, uniScaleKey, centeredScaling etc. You can pass all of them to options object

Related

How to check if node has property without instancing?

I'm trying to check if a certain node type has a property
without actually needing to make an instance of it
like this:
print("z_index" in Position2D);
Classes in ClassDB
If we are talking about a build-in class (not a custom class that you created, but one that is part of Godot), you can use ClassDB to get the property:
var properties := ClassDB.class_get_property_list("Position2D")
Classes from Godot Scripts
If the class is not in ClassDB (which is the case custom classes), but you have the script, you can use the script to get the property list:
var properties := preload("res://custom_class.gd").get_script_property_list()
If you don't have the script, perhaps you can find it. This code uses the hidden project setting "_global_script_classes" to find the path of the script for a class given the name_of_class you are looking for, and loads it:
if ProjectSettings.has_setting("_global_script_classes"):
for x in ProjectSettings.get_setting("_global_script_classes"):
if x.class == name_of_class:
return load(x.path)
Addendum: This is no longer available in Godot 4.
Other classes
However, the above approach will not work for every type of script. In those cases, I'm afraid the best way is to instance it. You can still get the properties from the instance and cache them (perhaps put them in a dictionary) so that you are not creating a new instance every time you need to query:
var properties := (CustomClass.new()).get_property_list()
Query the properties
Regardless of how you got the property list, you can query them the same way. For example this code looks for a property with name "z_index" and gets its type:
var found := false
var type := TYPE_NIL
for property in properties:
if property.name == "z_index":
found = true
type = property.type
break
prints(found, type)
The type is a Variant.Type constant.
Theraot's answer is correct, since it provides a way to check attributes without creating an instance of a node/gdscript.
You can also check the properties of an existing instance of a node/scene by doing this:
if "attribute_name" in thing:
pass # do stuff here
Practical example; During a signal triggered by two Area2Ds colliding, check if one node's attribute item_type is set:
func _on_area_2d_area_entered(area):
if "item_type" in area:
print(area["item_type"])

How to use a librarie in views in Codeigniter4

i trie to use a own library in a view, but it failed with "undefined property: CodeIgniter\View\View::$mylib"
This is the Base Controller
protected $mylib;
/**
* Constructor.
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
// $this->session = \Config\Services::session();
//Include our librarie with http-request
$this->mylib = new mylib(service('request'));
}
In the Controller i use it in this way, here i can work with my libray without any trouble. The testfunction will return a simple text.
namespace App\Controllers;
//Important to add our librarie (session, rbac, login etc.)
use App\Libraries\mylib;
...
die("Test: $this->mylib->testfunction());
If i try the same in my view file i recieve the error.
die("Test: $this->mylib->testfunction());
What i do wrong?
Update
In the meantime i find a way to work with my library in the views
at top of my view-file i add this
use App\Libraries\mylib;
$this->mylib = new mylib(service('request'));
It works, but is there a way to make the whole thing easier so that I don't have to write these lines in every view-file but maybe only once in e.g. Base-Controller?
What i do wrong?
You're assuming that because you created that Library in the Controller that it is automatically accessible in a View, which is incorrect, regardless if it's a class property of the Controller or not.
Anything that is not already in the View needs to be passed in when you "use" it (i.e. the view() function's second parameter). So you can either create the Library in the Controller and pass the entire object into the View, or continue creating it directly in the View as you're doing now.
The first option tends to be a little cleaner.

Nodejs ES6 class not returning methods [duplicate]

I know that if I type:
$('body');
I get a jQuery object. However on chrome's console I'll only see the internal array of the jQuery object, despite the fact that jQuery methods are accessible like
$('body').hide();
Why the console don't show me all the accessible methods and how did jQuery manage to do this magic?
If it's just because these methods are defined on a prototype, then how come when I write these lines:
function Person(){this.myProp = 'test'};
var person = new Person();
Person.prototype.proto = 'test2';
and then I inspect person in chrome I will see:
__proto__: Person
constructor: Person()
proto: "test2"
but when Inspecting $('body'); then no proto is shown on dev tools?
The methods are on the prototype of the object. Both the console and console.log() do not, by default, show items on the prototype.
If you examine a jQuery object in the Chrome debugger, you can expand the prototype and can then see all the methods there.
So, what you are seeing is just the chosen implementation of the console. It shows direct instance properties, not items on the prototype.
When I put this code into a page:
function Person(){this.myProp = 'test'};
Person.prototype.proto = 'test2';
var person = new Person();
var jq = $("body");
And, then examine both person and jq in the Chrome debugger, I see this:
which shows the `proto property on both objects. And, if I expand that property for the jQuery object, it does indeed show all the methods.

Scaling images in JavaFX

I am using ImageViewBuilder to create an ImageView and I need to test the properties preserveRatio , fitWidth and fitheight
I was looking at the docs and still cannot figure out how to.
Help will be appreciated. Here is my code (not SSCCE)
ImageView img = ImageViewBuilder
.create()
.image(new Image("http://projavafx.com/images/earthrise.jpg")) // path to image
.build();
If someone could please update the code to show me how to use the fitHeight() and fitWidth() methods then that would be highly appreciated.
IT is not entirely clear what you are trying to do. To use the fitWidth/fitHeight/preserveRatio properties, you can either use the get/set.. methods or,
ImageView img = ImageViewBuilder
.create()
.image(new Image("http://projavafx.com/images/earthrise.jpg")) // path to image
.build();
img.setFitHeight(value); // or getFitHeight() if that is what you need.
img.setFitWidth(value); // or getFitWidth() if that is what you need.
img.preserveRatioProperty(true); // or isPreserveRation() if that is what you need.
or alternatively, access the properties and then call the get/set methods on those:
img.fitHeightProperty().set(value);
img.fitWidthProperty().set(value);
img.preserveRatioProperty().set(true);
This is pretty basic. If you put more information about what exactly the problem is, then you might get a more specific and less basic answer.
chooks

C# objects Xaml factory method for XamlWriter

My class uses an image as Property (public Image myImage). When this class is serialized (XamlWriter) it works fine, reading it back gives an exception:
'No matching constructor found on type
'System.Drawing.Bitmap'. You can use
the Arguments or FactoryMethod
directives to construct this type.'
Line number '5' and line position '8'.
Obviously there is a constructor missing for Bitmap with ColorPalette as argument:
<sd:Bitmap>
<sd:Bitmap.Palette>
<sdi:ColorPalette />
</sd:Bitmap.Palette>
</sd:Bitmap>
I understand that I can specify a factory method creating the bitmap somehow. I also found some articles about directives for this such as http://www.wpftutorial.net/XAML2009.html
However, I am not an expert in Xaml and do not understand how and where to define / declare the method on my attribute. Unfortunately i do also not find an example for this.
I expect some like
[FactoryMethod("XYZ")]
public Image myImage ....
but actually have found nothing. Any idea / example you know?

Resources