Search in sources :

Example 1 with Target

use of com.android.tools.idea.uibuilder.scene.target.Target in project android by JetBrains.

the class SceneMouseInteraction method mouseRelease.

/**
   * Simulate releasing the mouse above the given anchor of the component
   * with the given componentId
   *
   * @param componentId the id of the component we will release the mouse above
   * @param targetClass the class of target we want to click on
   * @param pos         which target to click on
   */
public void mouseRelease(String componentId, Class targetClass, int pos) {
    SceneComponent component = myScene.getSceneComponent(componentId);
    if (component != null) {
        ArrayList<Target> targets = component.getTargets();
        int n = 0;
        for (Target target : targets) {
            if (targetClass.isInstance(target)) {
                if (pos == n) {
                    mouseRelease(target.getCenterX(), target.getCenterY());
                    return;
                }
                n++;
            }
        }
    }
}
Also used : AnchorTarget(com.android.tools.idea.uibuilder.scene.target.AnchorTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) ResizeTarget(com.android.tools.idea.uibuilder.scene.target.ResizeTarget)

Example 2 with Target

use of com.android.tools.idea.uibuilder.scene.target.Target in project android by JetBrains.

the class SceneDragHandler method commit.

@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    if (myComponent != null) {
        NlComponent nlComponent = components.get(0);
        NlComponent root = nlComponent.getRoot();
        root.ensureNamespace(SdkConstants.SHERPA_PREFIX, SdkConstants.AUTO_URI);
        SceneComponent component = scene.getSceneComponent(myComponent);
        if (component != null) {
            ArrayList<Target> targets = component.getTargets();
            int dx = x - myComponent.w / 2;
            int dy = y - myComponent.h / 2;
            for (int i = 0; i < targets.size(); i++) {
                if (targets.get(i) instanceof DragDndTarget) {
                    DragDndTarget target = (DragDndTarget) targets.get(i);
                    target.mouseRelease(scene.pxToDp(dx), scene.pxToDp(dy), nlComponent);
                    break;
                }
            }
        }
    }
    insertComponents(-1, insertType);
    scene.setDnDComponent(null);
    scene.checkRequestLayoutStatus();
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget)

Example 3 with Target

use of com.android.tools.idea.uibuilder.scene.target.Target in project android by JetBrains.

the class SceneDragHandler method update.

@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
    String result = super.update(x, y, modifiers);
    if (myComponent == null) {
        return "undefined";
    }
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    SceneComponent component = scene.getSceneComponent(myComponent);
    int dx = x - myComponent.w / 2;
    int dy = y - myComponent.h / 2;
    myComponent.x = dx;
    myComponent.y = dy;
    if (component != null) {
        ArrayList<Target> targets = component.getTargets();
        for (int i = 0; i < targets.size(); i++) {
            if (targets.get(i) instanceof DragDndTarget) {
                DragDndTarget target = (DragDndTarget) targets.get(i);
                target.mouseDrag(scene.pxToDp(dx), scene.pxToDp(dy), target);
                break;
            }
        }
    }
    scene.checkRequestLayoutStatus();
    return result;
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Target

use of com.android.tools.idea.uibuilder.scene.target.Target in project android by JetBrains.

the class SceneDragHandler method start.

@Override
public void start(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
    super.start(x, y, modifiers);
    if (myComponent == null) {
        return;
    }
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    scene.needsRebuildList();
    SceneComponent component = scene.getSceneComponent(myComponent);
    ArrayList<Target> targets = component.getTargets();
    int dx = x - myComponent.w / 2;
    int dy = y - myComponent.h / 2;
    for (int i = 0; i < targets.size(); i++) {
        if (targets.get(i) instanceof DragDndTarget) {
            DragDndTarget target = (DragDndTarget) targets.get(i);
            target.mouseDown(scene.pxToDp(dx), scene.pxToDp(dy));
            break;
        }
    }
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget)

Example 5 with Target

use of com.android.tools.idea.uibuilder.scene.target.Target in project android by JetBrains.

the class SceneComponent method layout.

//endregion
/////////////////////////////////////////////////////////////////////////////
//region Layout
/////////////////////////////////////////////////////////////////////////////
public boolean layout(@NotNull SceneContext sceneTransform, long time) {
    boolean needsRepaint = false;
    myCurrentLeft = myAnimatedDrawX.getValue(time);
    myCurrentTop = myAnimatedDrawY.getValue(time);
    myCurrentRight = myCurrentLeft + myAnimatedDrawWidth.getValue(time);
    myCurrentBottom = myCurrentTop + myAnimatedDrawHeight.getValue(time);
    needsRepaint |= myAnimatedDrawX.animating;
    needsRepaint |= myAnimatedDrawY.animating;
    needsRepaint |= myAnimatedDrawWidth.animating;
    needsRepaint |= myAnimatedDrawHeight.animating;
    int num = myTargets.size();
    for (int i = 0; i < num; i++) {
        Target target = myTargets.get(i);
        needsRepaint |= target.layout(sceneTransform, myCurrentLeft, myCurrentTop, myCurrentRight, myCurrentBottom);
    }
    int childCount = myChildren.size();
    for (int i = 0; i < childCount; i++) {
        SceneComponent child = myChildren.get(i);
        needsRepaint |= child.layout(sceneTransform, time);
    }
    return needsRepaint;
}
Also used : ResizeTarget(com.android.tools.idea.uibuilder.scene.target.ResizeTarget) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) AnchorTarget(com.android.tools.idea.uibuilder.scene.target.AnchorTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target)

Aggregations

Target (com.android.tools.idea.uibuilder.scene.target.Target)8 DragDndTarget (com.android.tools.idea.uibuilder.scene.target.DragDndTarget)6 AnchorTarget (com.android.tools.idea.uibuilder.scene.target.AnchorTarget)5 ResizeTarget (com.android.tools.idea.uibuilder.scene.target.ResizeTarget)5 DragTarget (com.android.tools.idea.uibuilder.scene.target.DragTarget)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 Nullable (org.jetbrains.annotations.Nullable)1