I want to use gestures in my nativescript-angular app. When I log this:
console.log("Pinch scale: " + args.scale + " state: " + args.state);
args.state gives me numbers (1,2,3), but in the docs they referred to names such as: began or cancelled. Waht is the corresponding name to each number?
GestureStateTypes are defined like this
export enum GestureStateTypes {
/**
* Gesture canceled.
*/
cancelled,
/**
* Gesture began.
*/
began,
/**
* Gesture changed.
*/
changed,
/**
* Gesture ended.
*/
ended
}
As per enum nature in TS first elemnet will auto assigned 0 if it is not assigned any value and then it will be auto incremented .
so final result will be cancelled=0,began=1,changed=2 and ended=3. but you should avoid directly checking to its value like args.state==1 and instead should use args.state==GestureStateTypes.began.
Related
I am currently working on a small multi-touch game using the processing language with the TUIO library.
I want to manually set the CursorID depending on which half of the screen the cursor is added and since the only time the method is called it just prints a message as seen below.
// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
if (verbose) println("add cur "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
//redraw();
}
I searched a bit around but I wasn't able to find anything. Is there a way to change the implementation of the addTuioCursor() method?
You should still be able to set do add your logic on top of it.
For example you would have your separate list of custom cursor IDs which you update based on the TuioCursor event.
This is just an illustration, assuming you have an ArrayList of Integer to add your custom ID:
// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
if (verbose) println("add cur "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
// if newly added cursor is on the left half of the screen
if(tcur.getX() < width / 2){
// set a custom ID
int customID = (int)random(0,100);
// add a custom ID
//leftCursorsList.add(customID);
}
}
This is intself might not be super youself: you may want to make your custom cursor class to hold not just the ID, but perhaps the x,y or a reference to the TuioCursor, whatever serves your end goal. There is nothing stopping you from manageing your own list of custom cursor data based on TUIO events.
Situation
Let's say you have a Scene which contains a single complex control that itself contains a TextArea. The complex control is composed in a way, that when it gains the focus the TextArea gains the focus.
The ComplexControl has the ability to make the TextArea non-editable. Then a key input can has another semantic than operating a text. The new semantic can be defined by the ComplexControl or any node soemwhat higher in the scene graph.
The Scene has a global shortcut CTRL+N for opening a new Tab/View. In context of the ComplexControl CRTL+N semantic is creating a new Text document.
------------------------
| Scene |
| ------------------ |
| | ComplexControl | |
| | ------------ | |
| | | TextArea | | |
| | ------------ | |
| ------------------ |
------------------------
Objective
React globally or by a node somewhat higher in the scene graph on KeyEvents / KeyCombinations. Any control somewhat lower can take over the events, so that in a more special context an occurred event has more relevance as globally defined.
Suggestion
Setting a KeyHandler onto the Scene or a higher Node. Any EventHandler closer to the Source/Target of the EventDispatchChain" can consume the event. This way the KeyHandler can prevent the Scene or any higher Node from reacting on the key input, which is what the user intends in the special context of a control. Therefore an EventFilter at the higher place is not suitable.
Trouble
The TextArea consumes always any key event, even if it's not the intention of the design. No EventHandler higher in the EventDispatchChain gets informed.
Problem
How can it be forced to give the event back from the TextArea without consuming it and then let it bubble up the EventDispatchChain?
How can delivering the Event down to the TextArea be prevented without consuming it, so that it not even knows anything about the event.
Thanx to sillyfly, who showed me the way. As an answer to question 2, here's the resulting source. I decided to place the functionality at a central point for reuse and give the opportunity to make the suppression condition based. Please don't blame me for the class name, that's not the point ;-)
public class EventUtil {
/**
* Prevents Events of the given <b>eventTypes</b> to be passed down during the
* event capturing phase, if the <b>condition</b> is met.
*
* #param node
* The Node, whose descendants should not be informed about the Event
* #param eventTypes
* The types of Events for which the prevention should be valid
* #param condition
* The condition that must be met to prevent passing the Event down
*/
public static void preventPassDown(Node node, Supplier<Boolean> condition, EventType<?>... eventTypes) {
for (EventType<?> eventType : eventTypes) {
if (eventTypes == null) {
return;
}
node.addEventFilter(eventType, event -> {
if (condition.get()) {
event.consume();
Parent parent = node.getParent();
if (parent != null) {
Event.fireEvent(parent, event);
}
}
});
}
}
/**
* Prevents Events of the given <b>eventTypes</b> to be passed down during the
* event capturing phase.
*
* #param node
* The Node, whose descendants should not be informed about the Event
* #param eventTypes
* The types of Events for which the prevention should be valid
*/
public static void preventPassDown(Node node, EventType<?>... eventTypes) {
preventPassDown(node, () -> true, eventTypes);
}
If someone finds an answer to question 1, please feel free to jump in.
I have a JavaFX sorted tableview - defined as follows in the overridden initialize method:
// Bind the FX tableview to the data - allowing sorting
final SortedList<LoadedWotsitModel> sortedList =
new SortedList<LoadedWotsitModel>(configurationDataManager.getLoadedWotsit());
tableLoadedWotsit.setItems(sortedList);
sortedList.comparatorProperty().bind(tableLoadedWotsit.comparatorProperty());
// Sort by time
colTime.setSortType(TableColumn.SortType.ASCENDING);
tableLoadedWotsit.getSortOrder().add(colTime);
This works fine, other columns in the table are also sortable by the user.
When the dialog is closed and re-opened, it is sorted in the order the user last chose. I want to be able to make it sort by my default colTime column every time the dialog is displayed (not the previously chosen user sort order).
What event can I hook into to re-sort the table when it is displayed?
My solution was to use a menu controller and invoke the dialog in code thus:
myDialogController.sortByTimeAscending();
myDialog.show();
Allowing me to call a method in the controller directly that performs the sorting.
/**
* Sort by time (ascending).
*/
public void sortByTimeAscending()
{
colTime.setSortType(TableColumn.SortType.ASCENDING);
tableLoadedWotsit.getSortOrder().clear();
tableLoadedWotsit.getSortOrder().add(colTime);
}
Its my understanding that UIAutomator is unable to automate any elements where NAF = true in uiautomatorviewer. Ive searched high and low but i cant for the life of me find what NAF stands for. Does anyone know?
"Not Accessibility Friendly"
These are UI elements which are apparently interactive, but which don't have accessibility affordances like content descriptions.
From the source for AccessibilityNodeInfoDumper.java (part of uiautomator):
/**
* We're looking for UI controls that are enabled, clickable but have no
* text nor content-description. Such controls configuration indicate an
* interactive control is present in the UI and is most likely not
* accessibility friendly. We refer to such controls here as NAF controls
* (Not Accessibility Friendly)
*
* #param node
* #return false if a node fails the check, true if all is OK
*/
private static boolean nafCheck(AccessibilityNodeInfo node) {
boolean isNaf = node.isClickable() && node.isEnabled()
&& safeCharSeqToString(node.getContentDescription()).isEmpty()
&& safeCharSeqToString(node.getText()).isEmpty();
if (!isNaf)
return true;
// check children since sometimes the containing element is clickable
// and NAF but a child's text or description is available. Will assume
// such layout as fine.
return childNafCheck(node);
}
NAF stands for " Not Accessibility Friendly" .
I am writing a c program to do some calculations.It would really help me if I was able to get responses by clicks of mouse.
How can i do this also If it is not possible then using which functions or libraries of C only would I be able to do that.
Ncurses has support for GPM (mouse library).
Excerpt from Ncurses interfacing with the mouse how-to:
Once a class of mouse events have been enabled, getch() class of functions return KEY_MOUSE every time some mouse event happens. Then the mouse event can be retrieved with getmouse().
The code approximately looks like this:
MEVENT event;
ch = getch();
if(ch == KEY_MOUSE)
if(getmouse(&event) == OK)
. /* Do some thing with the event */
.
.
getmouse() returns the event into the pointer given to it. It's a structure which contains
typedef struct
{
short id; /* ID to distinguish multiple devices */
int x, y, z; /* event coordinates */
mmask_t bstate; /* button state bits */
}
The bstate is the main variable we are interested in. It tells the button state of the mouse.
Then with a code snippet like the following, we can find out what happened.
if(event.bstate & BUTTON1_PRESSED)
printw("Left Button Pressed");