I would like to make an different animation depending if the switch is off or on.
Let say if my switch is ON my sprite move x +10
if my switch is OFF my sprite move y +10
I don't find a correct way to apply it.
Thanks
You could use one out of three PatchTrees with a simple logic.
The first one works like this: after pressing LMB, your sprite translates 0.1 along +X. After releasing LMB sprite returns to its default position (0). The same thing happens with pressing and releasing RMB (Y+0.1).
The second scheme uses slightly different logic: clicking LMB you translate your sprite X+0.1 and clicking RMB you translate your sprite Y+0.1. This logic can be accomplished if you use "Counter" patch (with "Reset" parameter).
Remember! your QC's default XY grid ranges from -1 to +1 for X and Y (totally 2 for each axis).
The third one is a switcher based on a formula of inversion: abs(a-b).
b=1. I used patch named "Mathematical expression". This PatchTree is made just for one input (LMB for instance). Maybe third scheme is what you are looking for.
Logic is simple:
if a = 0 -> abs(0-1) -> abs(-1) = 1
...
if a = 1 -> abs(1-1) -> abs(0) = 0
Related
This sounds like a really simple issue but somehow I do not know how to easily solve it. Inside one row (UIStackView horizontal), I am trying to place two buttons (Cancel and OK) so that Cancel button will be at 1/4 (of the whole length) from left and Ok will be at the 3/4 (of the whole length) from left. I would like the buttons to be fixed length and not stretching to occupy the whole row.
Is there a way to solve it with just one UIStackView with 2 buttons? I am sure there a lots of alternatives (programing a view / use 3 UIStackViews).
Thanks.
hope you can find an easy way using equalWidthconstraints instead for UIStackView.
ie.
1. You should place both buttons in a sam line.and make sure both button's width are same .
2.then you select both buttons and put EqualWidthConstraint.
3.After that pin the left button with top,left and right .
4.pin the right button with right,top spaces,
5.then you double click on the equalwidthconstraints and give Multiplier as you needed ; like 1:4,3:4 something like that. Thank you
I am using a ZedGraphControl in a WindowsForms project in C#. The ZedGraphControl is V5.1.5.
The data in the control is static and I add it all before the form is shown. The X axis of the data consists of numbers indicating seconds offset from the beginning. in other words from 0 to some number of seconds.
I want to initially show the last 5 seconds, but provide a horizontal scrollbar so the user can scroll back and forth. I set the "graphPane.XAxis.Scale.Max = maxX;" where maxX is the largest X value in my data. I set the "graphPane.XAxis.Scale.Min = maxX - 5;".
The data starts off displaying the way I want it, but when the user scrolls the horizontal bar, bizzar behavior occurs.
As you drag the thumb of the scrollbar to the left, the beginning of the data shown in the grid moves to the lower values as expected, and the thumb of the scrollbar moves to the left, but the right edge of the thumb stays at the right of the scrollbar and you cannot move back to the right. It is as if the data to the right of the viewing range gets truncated as you scroll left.
I cannot find any reason for this nor any way to control it. Does anyone have any ideas about this behavior?
Ok, found it myself.
I found a fine article that describes scrolling:
Add a ScrollBar
In it the author specifically says "the scrolling will be wacky because the scrollable range has not been set".
I used the sample "Manually Setting the Scroll Range" and the part that I was missing is setting the zedGraphControl1.ScrollMinX and zedGraphControl1.ScrollMaxX properties. Once I defined these values everything started working as expected. I also found that in my case, the value of zedGraphControl1.IsAutoScrollRange had no effect, but I left it set to false to be consistent with the example. This would probably have an effect if the dataset is dynamic.
Spent hours trying to figure this out and still haven't got it. None of the documentation mentions anything about it. Is this something rebol just can't do without manually having to rearrange everything with origin?
Perhaps I'm just expecting too much?
edit: well I've discovered a hack: indent num, then indent -num on the next line . Out of all the spectacular features of this language why couldn't they have just added a simple command like center?
There is a CENTER-FACE function you can reuse to align faces, but unfortunately it doesn't work very well from my experience. Here is a simpler replacement version that should do the trick:
center-face: func [face [object!] parent [object!]][
face/offset: parent/size - face/size / 2
]
Here is a usage example:
lay: layout [
size 300x300
b: button "Hello World"
]
center-face b lay
view lay
First off, VID is not Rebol, but a demonstration dialect written by the author, Carl Sassenrath, to demonstrate how interfaces could be dialected in Rebol. There are others including RebGUI ( http://www.dobeash.com/rebgui.html ) though I suspect there isn't a way to center buttons there either as neither author considered it important.
You can also use PAD to align the cursor close to the center of the layout.
We can't center or align stuff based on the window itself because controls do not have any way to refer to their parent face until AFTER the parent has had 'SHOW called on it.
face/parent-face isn't set until the parent has been shown. So in normal VID you need to tweak the gui just after the initial layout & view has been done.
here is a little script which shows how to center any face, after its been shown at least once.
view/new is used to delay event handling, in order to modify the layout.
rebol []
center: func [face][
face/offset/x: (face/parent-face/size/x / 2) - (face/size/x / 2)
show face
]
view/new layout [
across
t: h1 "This is a centered title!"
return
button "1"
button "2"
button "3"
button "4"
]
center t
do-events
How is it possible to get, directly from the Matlab command window, the position (i.e. the coordinates) of an object (e.g. an arrow, a rectangle or sim.) that I have drawn on a plot?
You can usually do this using the handle graphics properties. For example:
Make a plot
h = plot(1:10, rand(10,1));
Then get the actual values of the points
x = get(h,'xdata')
y = get(h,'ydata')
Different types of objects have different properties, sometimes you have to explore. In that case this syntax is useful.
get(h) %This displays all available properties on `h` to the command window
A final useful tidbit is the gco ("get current object") function, which provides the handle of the last item that you plotted or manually clicked on. This can help if you're not sure where the plotted item came from.
Edit:
To find all of the properties which are descendents of an object, use either findobj, or findall. For example:
findobj(gcf); %Returns all non-hidden, typical objects. This should be your first attempt.
findall(gcf); %Returns all children, even hidden object, such as titles, manually added annotations, and UI menus
This call removes some common UI annotations
get(findall(gcf,'-not','type','uimenu','-not','type','uitoggletool','-not','type','uipushtool','-not','type','uitogglesplittool'),'type')
(Presumably the last example could be improved with a properly designed regexp, but I can't seem to get that working right now.)
I have a bar chart that will never go below zero (never go negative), 0 y axis. How do I limit panning/scrolling so that the y0 line is always at the base of the graph?
The requirement is to not be able to pan below pointy = 0 in view;
Subscribe for ZoomEvent or Scroll event (you must check which one would be more suitable in your situation).
Create a handler for that event and inside of it, check if current pane.YAxis.Scale.Min < 0. If so, change it manually. That should do the trick.