Why do I need to a localGroup:insert( object ) with the corona director class? - mobile

I cant seem to wrap my head around the localGroup:insert command that is necessary when using the director class.
If I create my object with something like:
local btnBegin = display.newImage( "images/btn_begin.png", (display.viewableContentWidth/2)-200, display.contentHeight * .7 )
The image will display perfectly fine in the scene, even if I never do a
localGroup:insert( btnBegin )
I would have thought that the localGroup:insert would be necessary so that all of the components of the scene can be grouped to gether for the display, but isnt that the point of
function new()
at the begining of each scene? In my mind, I see it that creating all of my objects within the function already makes them local to the scene file. What does localGroup:insert accomplish?

As I understand it, you could have a HUD which you add straight to the screen and the localGroup containing your level. Then if you change level, you would only move away the level contained in the localGroup and keep the elements of the HUD you placed straight on the screen.

When you do display.newImage(...) this adds the display object to the main stage. As tomdemuyt has said, this might be useful for a HUD or some other graphics that appear between scenes.
The stage also contains your scene, defined here has localGroup. To add an object to your scene, you should insert it into the localGroup.
This is useful for example, if you have a menu scene containing menu buttons. If you press the "start game" button, when the screen transitions to the next scene all your menu items will be removed appropriately with the menu scene, instead of hanging around on the global stage.
It all comes down to the display hierarchy and how you want to organize it. It makes sense to have sub objects inserted into their appropriate parents:
the stage HAS A menu scene
the menu scene HAS A button
Makes more sense than:
the stage HAS A menu scene
the stage HAS A button

Related

Azure Maps - How to set drawing manager layers z-index to the top?

In my design page, the user will be creating/drawing new shapes, in addition to adding image overlays. I'm finding that any shapes drawn using the drawing manager are rendering underneath any image overlays added to the map, see below:
I'd like to know how to achieve a couple of tasks:
1 - How to set the drawing manager so any shape (rectangle/point/circle etc be default is always added as an upper/top layer when the drawingcomplete event has fired, that way the shapes will always appear above any images added to the map.
2 - How to programatically change the order of the various layers created during design, given the user may want to adjust the z-index of the various layers to suit their own endering requirements.
The MS docs here is not really helping me understand how to achieve the above, but also doesnt mention anything about shapes/layers that currently reside within the drawing manager.
Partial answer but along the right tracks...
We can retrieve the shapes (drawing manager layers) from the drawing manager so we have a reference to them.
When i add an image overlay, before actually adding/rendering it to the map, i would first get the shape layers from the drawing manager, then remove them from the map.
Next we add the image overlay to the map and add the shape layers back in as well, its the order that we add/remove the layers that seems to be relevant here.
Once i had added all layers back to the map in the chosen order, i was still able to put the drawing manager into edit mode and select the shape for editing, so i beleive this will work as my solution going forwards.
// Create the image layer
var imageLayer = new atlas.layer.ImageLayer({
url: 'myImageUrl,
coordinates: coordinates
})
// Then get the existing shapes (layers) from the DM
var layers = drawingManager.getLayers();
console.log(layers);
// Remove the shapes.
map.layers.remove(layers.polygonLayer); // polygonLayer as an example...
// Add new image overlay, then the shapes
map.layers.add([imageLayer, layers.polygonLayer]);

How to handle mouse motion events in GTK3?

I am trying to implement the following feature using C/GTK3/Cairo:
-Left click on an GtkDrawingArea Widget and printf the coordinates Xo and Yo.
-While keeping the left button down, move the mouse and draw a line conecting (Xo,Yo) to the current mouse position.
-Release the left mouse button and printf("something")
How do I do this? Anyone knows of a good tutorial showing how to handle mouse clicl-move events?
So far, the best I found was this zetcode lines (which shows how to handle mouse click events but not button-down/move/button-up and this , which explains how to change the mouse cursor when hovering over a Widget.
Thanks
Did you see this GtkDrawingArea demo from the Gtk people? This one is written in C, but there is a Python version of the same program (links updated - thanks #kyuuhachi).
Anyway, in the constructor (__init__), calls are connected to the motion_notify_event.
You also need to connect to the button_press_event and the button_release_event.
Then, on button press, you save the coordinates of the start point. (and save it to the end point too, which are the same for now).
On each motion_notify_event, you delete the previous line (by overwriting), and redraw it to the new end point.
Finally, when the button is released, the line is final.
It's much easier if you use a canvas widget, for example GooCanvas, which takes care of most of the updating. You can just update the coordinates of the line object, and it will move itself. Also you can easily remove lines. The 'algorithm' is similar as above:
Connect button_press_event, button_release_event, and motion_notifyevent to the canvas,
When a button press occurs, create a GooCanvas.polyline object, and set begin and endpoint,
Update the endpoint on each motion_notify_event
Finalize with a button_release_event.

Render Visual 3D Container on top in Viewport3D

Using Helixtoolkit you have set up a scene (viewport). Added the camera, default lights, grids, etc. You also added a SortingVisual3D where you add various box elements for example. They are rendered as they are placed in the view. Everything fine.
Now I would like to achieve is to create a new container for 3D objects where my moving gizmo would be placed (every object gets one). If I add gizmo to sorting container, it might not be visible (box overlapping gizmo), so I need a separate container which has to be rendered on top of everything.
How to set container (content) to be rendered on top of everything - regardless of its physical location while still keeping it in the correct 3d space when rotating camera. Something like 3dsmax does (example).
Tnx
Ok, found the solution myself. What you want to do is to make an overlay and transform Point3D to Point and place objects there (a canvas for example).

Creating and moving a Shape in Visual Studio C++/CLI

I am working on a little school project and I have to use Visual Studio C++/CLI with Windows Forms Application.
Since I am new to Windows Forms I am having some difficulties.
What I would like to achieve:
Press a button
A PictureBox will be created at starting position
A timer will move the PictureBoxto some given position
Pressing the button again will spawn a NEW PictureBox with a different name which will begin to move in the same direction as the first rectangle
and so on.
Note: These pictureboxes have to have a different background color which must be randomly chosen out of 3 colors.
What I need to know is....
I know how to move a picturebox, but how do I dynamically create one with a custom name and color after a button press?
Thanks in advance!
Because you mention this is a school project, here is some high-level advice:
You can draw on a form by either subscribing to the Paint event (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint%28v=vs.110%29.aspx) or overriding the OnPaint method (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v=vs.110).aspx). Take a look at the Graphics object in the EventArgs.
When the timer elapses, make adjustments to local variables (keeping track of the desired position of the Rectangle) and then call Invalidate() (https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate(v=vs.110).aspx) to force the form to be redrawn.
I hope this helps you get pointed in the right direction.

Canvas - dynamic drawing and managing shapes

I'm trying to make an application which allows the user to draw shapes to the canvas. Once drawn, I would like for the user to be able to select, move, resize, basically manipulate the shapes in any which way.
I have done something similar in XNA and that was quite easy due to the fact that there was a draw loop. In Silverlight there is no such thing as far as I understand and I am having trouble figuring out how to manage the objects on the canvas. As in what is the best way to manage the canvas' children collection to ensure appropriate response of the UI to what the user does.
Most examples out there are pretty basic and do not go anywhere near this kind of thing. I would be grateful if somebody who has done this before could tell me how they approached the problem.
Thinking about it for a while I think I figured out how it works.
There is a draw loop for the canvas, which is the draw loop of the top level parent container which it lives on.
The difference with XNA I guess is that the collection of items to draw on the canvas doesn't need to be explicitly drawn, since the canvas takes care of drawing its children automatically.
So, what I need is some way to hold on to any object I add to the canvas' children... I can then update the objects drawing properties and the changes will be reflected in the canvas next time it refreshes.
I guess a dictionary of some sort in which to store the items I put in the list might be best...?
Not a finished answer yet, but I guess I understand half of it now.

Resources