Moving a circlewithin a rectangle

Hi i am currently working on a gauge and have one such that a rectangle is filled with the fill method in paint with certain values passed to it .
I would like to now develop a new gauge whereas a filled circle or ball would move along the inside of the rectangle instead of it being filled with color
I should also state that some values here are run in a thread and just called in this draw method. The repaint is also in a thread hence gives the
effect that the guage is moving constantly
the following code represents my draw method to post all the classes here would be really alot so any help with the draw method is appreciated
public void draw(Graphics2D g) {
// set up variables to use
        g.translate(getX(),getY());
        int w = getWidth()/2;
        int h = getHeight();
        int totalRange = 100-0;
        int units = h/totalRange;
        int value = getICUMonitor().getDiaSensor().getDiastolic();
        int valueHeight = value*units;
        int valueY = h-valueHeight;
        // setup a gradient paint
        GradientPaint redtowhite = new GradientPaint(5, 5, Color.blue, 5, 5,Color.blue);
        g.setPaint(redtowhite);
        // drawing the actual rectangle
        g.setColor(Color.LIGHT_GRAY);
        g.draw(new Rectangle2D.Double(0,0,w,h));
        // filling the rectangle with a color
        g.fill(new Rectangle2D.Double(0,valueY,w,valueHeight));
        // this draws small lines along the side of the rectangle as markers
        for(int i=0;i<getHeight()+10;i+=10){
            g.drawLine((int)w+2,i,(int)w+6,i);
        // here is just putting the numbers 0 on the first marker and 100 on the last
        g.drawString("100",(int)w+14,0);
        g.drawString("0",(int)w+14,(int)getHeight());
        g.translate(getX()*-1,getY()*-1);
    }

I would like to now develop a new gauge whereas a filled circle or ball would move along the inside of the rectangle instead of it being filled with colorThis is really simple, you just have to replace your fill Rectangle call with a drawRect and fillOval calls.
g.drawRect(0, valueY, w, valueHeight);
g.fillOval(w/2-8, valueY, 16, 16);// drawing a circle of width 16 on the top middle of rectangleAnd yes SSCCE would be helpful, if your problem is not as simple as I thought.
Thanks!

Similar Messages

  • Delay program until end TranslateTransition JavaFX

    Hey everyone,
    My name is Thomas and I am currently working on a final High School programming project. For this project we are programming a game with JavaFX, in which we feature several mini-games to improve children's mathematical skills. One of about 10 mini-games is a puzzle where you have to reach the exit of the level by sliding over ice.
    Let me explain the mechanics of this mini-game. When you press an arrow the character has to keep sliding in that direction until it bumps into an object (I have four rocks & borders of the map). What I decided to do is make a function for each direction in which I define a translation of a certain distance, and then keep repeating this translation until there is an object right next to the character, at which time it will stop moving. In many programming languages this would be an easy task, but there is a problem in JavaFX: when I execute the translation the code will continue executing, allowing the user to press a button while still moving which should not be allowed: the code has to wait until the movement is complete. Most languages have a delay(x ms) function for this, but JavaFX does not have one.
    I was wondering whether anyone knows a solution for this problem. I need to make a delay either in the TranslateTransition, or in a function since I made a while loop that keeps executing the translation but without a delay it executes the transition a million times.
    Any help will be greatly appreciated!
    Thomas Brouwer
    The code (with the loop I talked about as comments since it freezes the program):
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package javafx.toneel.pac;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.paint.Color;
    import javafx.animation.transition.TranslateTransition;
    import javafx.animation.*;
    var character: Rectangle;
    def scenewidth = 600;
    def sceneheight = 600;
    var topborder: Rectangle;
    var leftborder: Rectangle;
    var rightborder: Rectangle;
    var bottomborder: Rectangle;
    var Moving = false;
    var object1: Rectangle;
    var object2: Rectangle;
    var object3: Rectangle;
    var object4: Rectangle;
    var minX = scenewidth/12;
    var minY = sceneheight/12;
    var maxX = 11*scenewidth/12;
    var maxY = 11*sceneheight/12;
    * @author Thomas
    Stage {
    title: "Application title"
    scene: Scene {
    width: scenewidth
    height: sceneheight
    content: [
    //code to make the borders of the map. The map consists of blocks 10x10 and
    //another block as borders on each side, so 12 horizontally and 12 vertically
    topborder = Rectangle {
    width: scenewidth
    height: sceneheight/12
    x: 0
    y: 0
    fill: Color.BLUE
    leftborder = Rectangle {
    width: scenewidth/12
    height: sceneheight
    x: 0
    y: 0
    fill: Color.BLUE
    rightborder = Rectangle {
    width: scenewidth/12
    height: sceneheight
    x: 11*scenewidth/12
    y: 0
    fill: Color.BLUE
    bottomborder = Rectangle {
    width: scenewidth
    height: sceneheight/12
    x: 0
    y: 11*sceneheight/12
    fill: Color.BLUE
    //code to define the character
    character = Rectangle {
    width: scenewidth/12
    height: scenewidth/12
    x: 6*scenewidth/12
    y: 6*sceneheight/12
    fill: Color.BLUE
    //make the keyevent input accessible
    focusTraversable:true
    onKeyPressed: function( e: KeyEvent ) {
    //prevent key input while the object is already moving, but this
    //does not work either.
    if (Moving == false){
    if (e.code == KeyCode.VK_LEFT) {
    Moving = true;
    Movingcheckleft();
    if (e.code == KeyCode.VK_RIGHT) {
    Moving = true;
    Movingcheckright();
    if (e.code == KeyCode.VK_UP) {
    Moving = true;
    Movingcheckup();
    if (e.code == KeyCode.VK_DOWN) {
    Moving = true;
    Movingcheckdown();
    //code to define the objects
    object1 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 10*scenewidth/12 //one square from the rightborder
    y: sceneheight/12
    fill: Color.YELLOW
    object2 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 9*scenewidth/12 //two squares from the rightborder
    y: 8*sceneheight/12 //three squares from the bottomborder
    fill: Color.YELLOW
    object3 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 6*scenewidth/12 //five squares from the leftborder
    y: 7*sceneheight/12 //four squares from the bottomborder
    fill: Color.YELLOW
    object4 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 7*scenewidth/12 //four squares from the rightborder
    y: 2*sceneheight/12 //two squares from the topborder
    fill: Color.YELLOW
    function Movingcheckleft() {
    //move one square to the left
    var Transitionleft = TranslateTransition {
    node: character
    duration: 200ms
    byX: (-scenewidth/12)
    interpolator: Interpolator.LINEAR
    //check whether there is an object right of the character. As long as there isn't, the
    //character will move 1 square to the right. However, while expressions do not seem
    //to work in combination with Transition.play.
    //while (((character.x - scenewidth/12) != (object1.x)) and ((character.x - scenewidth/12) != (object2.x)) and ((character.x - scenewidth/12) != (object3.x)) and ((character.x - scenewidth/12) != (object4.x)) and (character.x != minX)){
    Transitionleft.play();
    Moving = false;
    x = 0;
    function Movingcheckright() {
    var Transitionright = TranslateTransition {
    node: character
    duration: 200ms
    byX: (scenewidth/12)
    interpolator: Interpolator.LINEAR
    //while (((character.x + scenewidth/12) != (object1.x)) and ((character.x + scenewidth/12) != (object2.x)) and ((character.x + scenewidth/12) != (object3.x)) and ((character.x + scenewidth/12) != (object4.x)) and (character.x != maxX)){
    Transitionright.play();
    Moving = false;
    function Movingcheckup() {
    var Transitionup = TranslateTransition {
    node: character
    duration: 200ms
    byY: (-sceneheight/12)
    interpolator: Interpolator.LINEAR
    //while (((character.y - sceneheight/12) != (object1.y)) and ((character.y - sceneheight/12) != (object2.y)) and ((character.y - sceneheight/12) != (object3.y)) and ((character.y - sceneheight/12) != (object4.y)) and (character.y != minY)){
    Transitionup.play();
    Moving = false;
    function Movingcheckdown() {
    var Transitiondown = TranslateTransition {
    node: character
    duration: 200ms
    byY: (sceneheight/12)
    interpolator: Interpolator.LINEAR
    //while (((character.y + sceneheight/12) != (object1.y)) and ((character.y + sceneheight/12) != (object2.y)) and ((character.y + sceneheight/12) != (object3.y)) and ((character.y + sceneheight/12) != (object4.y)) and (character.y != maxY)){{
    Transitiondown.play();
    Moving = false;
    }

    please manage your coding pattern before you post any topic!!
    Make forum helper easy to recognize your problem..

  • What happened to the 'Shape Mode' shortcut keys on the Pen Tool?

    For the longest time I've used both the Shape and Pen Tools for drawing vectors in Photoshop, but with CS6 I noticed a lot of weird behaviours. The one that is really getting to me is the lack of 'Shape Mode' shortcut keys when using the Pen Tool. When on the 'Shape Tool', fo example Cirle or Rectange, you can press the Shift to change the Shape Mode to 'Add', Alt to change it to 'Subtract' or both together to get 'Intersect'. This functionality used to exist on the Pen Tool too, but in CS6 I can't seem to get it working.
    A collegue suggested to move over to Illustrator for all my Vector needs, and I know that this a good advice. However the lack of quick/integrated changing between 'Shape Modes' in either product (now) makes drawing things alot slower (for me).
    Am I missing something, or is this feature now ommited in Photoshop CS6. If it is does anyone know if its possible to script something to allow this kind of behviour in Photoshop or Illustrator?
    cheers,
    Jon

    The modifier keys "Alt|Opt", "Ctrl|Cmd" and "Shift" work differently depending on the tool being used but the individual keys seem to provide somewhat related functions.
    For example the "Shift" key tends to be a constraining key Rectangle tools are constrained to square ellipse tools to Circles. However if there is an Active selection when you hold down the skey when you drag out a new selection it does not reset the current selection instead the new selection is not constrained and is added to the current selection. Shift constrains Transform tool to current aspect ratio,  Shift constrains Line tools to vertical, horizontal or 45 degree angles. Pen tool like line tool shift constrains the angle.
    The "Alt|Opt" key changes the way tools operate. Transforms are from the center not from the side or corner being dragged.  Selection tools like the rectangle and ellipse will cause the intal drag out be from the center however it there is a Active selection dragging out a new selection will be subtracted from the current selection. This key changes the Pen tool from draw mode to anchor point adjusting.
    The "Shift" and "Alt|Opt" modifier keys can be used together to have an operation be both constrain and from the center.
    The "Ctrl|Cmd" key seems to change the way a tool works on a control anchor point.  The Pen Tool changes from Pen Draw mode to Direct Selection tool to facilitate moving the point.  Transform can be distorted a single corner point can be moved and distort the rectangle bounding box.
    These keys may have other functions I don't know about.  Photoshop has many features so many I don't know if any one person know and uses all of them. For the rest of us they seem to be Photoshop hidden secrets.

  • Move an animator object from right to left

    How do I move an animator object from right to left?  I tried using the value with a minus sign in front of it. (i.e. -(xcoord) )  Please help.
    Thanks,
    Chris

    After you create the animator, click on it on the panel, you will see a rectangle. You can drag the rectangle to bigger or smaller. The graphic will be moving inside of this rectangle. In this rectangle, bottom left corner is x0 y0.  Top right cornet is x100, y100.
    Ryan Shi
    National Instruments
    Attachments:
    process1.zip ‏1 KB

  • Advice needed on timeline and knob

    hi all ,
    i modify the pointgraph example and included a knob from memefx to control the tranlation of the rectangle.
    so now i can control the animation back and fro using the knob. However, the interaction between the timeline.play() and the knob aren't sync.Below is my code for main.fx. no changes to pointgraph.fx.
    can someone advise me?
    To duplicate the problem, let the animation play and click the pause button. turn the knob forward and click the play button. you will see that the animation start off at a different time.

    var variable = bind myKnob.value;
    var myKnob = Knob {
        ui: BasicKnob {}
        min: 0, max: 530, minAngle:0, maxAngle:1440
        dialLinesLongEvery:5, dialLinesNumber:50, dialLinesWidth:1,
        translateX: 55, translateY:280
        scaleX: 0.25, scaleY: 0.25,
    // timeline for animation
    public var t = Timeline {
        repeatCount: 1
        keyFrames: [
            KeyFrame {
                time: 5s
                canSkip: true
                values: [
                    myKnob.value => 530.0 tween Interpolator.LINEAR
    /* adding everything in group to make changes easy */
    var gp = Group {
        content: [pg, pg1, pg2]
    /* stage can be written inside run() method */
    public function run(){
        t.play();
        var s = Stage {
            x: bind stageX
            y: bind stageY
            title: "24-Hour Temperatures in Major World Cities"
            width: 550
            height: 400
            style: StageStyle.DECORATED
            scene: Scene {
                fill: Color.BLACK
                content: [
                    gp,
                    /* rectangle moving and showing animation */
                    Rectangle {
                        translateX: bind myKnob.value
                        x: 10,
                        y: 10
                        width: 500,
                        height: 500
                        fill: Color.BLACK
                        opacity: 1.0
                    reloadButton, textButton, myKnob, playButton,textButton2,stopButton, textButton1,
                    // axis plotter
                    Path {
                        translateX: 50
                        translateY: 0
                        stroke: Color.WHITE
                        strokeWidth: 2
                        opacity: 0.4
                        elements: [
                            MoveTo {
                                x: 10.0,
                                y: 300.0
                            HLineTo {
                                x: 450.0
                            MoveTo {
                                x: 10.0,
                                y: 300.0
                            VLineTo {
                                y: 10.0
                    /* data on Axis */
                    Group {
                        translateX: 50
                        translateY: 0
                        content: for(num in [0..7]) {[
                                Text {
                                    fill: Color.WHITE
                                    font: Font {
                                        size: 10
                                    x: num * 60 + 5
                                    y: 320
                                    content: "{3*num}"
                                Text {
                                    fill: Color.WHITE
                                    font: Font {
                                        size: 10
                                    x: -5
                                    y: 320 - num * 50
                                    content: "{5*num}-"
                    Text {
                        fill: Color.WHITE
                        font: Font {
                            name: "Arial Bold"
                            size: 12
                        x: 500
                        y: 330
                        content: "Time"
                    Text {
                        rotate: -90
                        fill: Color.WHITE
                        font: Font {
                            name: "Arial Bold"
                            size: 12
                        x: -10,
                        y: 80
                        content: "Temperature"
    }

  • Unable to paint (using paint() in JPanel) inside mouse listeners

    This is hard to explain but I'll do my best :)
    I've created a little game and at some point I needed to make images "move" on the JPanel (through paint()), on a checkers-based game board.
    The game works like so:
    it has a mouse listener for clicks and movement, and the main game process is THINK(), REPAINT(), which is repeated until the user wins (the above is inside a while).
    The mouse actions were added to the constructor so they are always active, THINK changes the enemy's locations, and REPAINT simply calls "paint()" again.
    The picture is either an enemy or the player, and it can only "rest" on squares.
    (e.g. point's x and y must be divided in 50).
    While doing that, I wanted to make the movement more sleek and clean,
    instead of them simply jumping from one square to the other with a blink of the eye.
    So, I've created MOVEACTOR, that "moves" an enemy or a player from its current point (actor.getPoint()) to the requested future square (futurePoint).
    //actor = enemy or player, has getPoint() that returnes the current point on the board where he rests on.
    //futurePoint = the new point where the enemy or player should be after the animation.
    //please ignore obvious stuff that has nothing to do with what I asked -- those will be deleted in the future, for they are only temporary checking extra lines and stuff.
    //also feel free to ignore the "jumpX" things. Those are just to change images, to imitate physical "jumping" animation.
    protected void moveActor(Actor actor, Point futurePoint)
              Point presentPoint = actor.getPoint();
              int x = (int)presentPoint.getX(), y = (int)presentPoint.getY();
              int addToX, addToY;
              if (futurePoint.getX() > x) addToX = 1;
              else addToX = -1;
              if (futurePoint.getY() > y) addToY = 1;
              else addToY = -1;
              Point middlePoint = new Point(x,y);
              int imageCounter = 0;
              while ( (middlePoint.getX()!=futurePoint.getX()) && (middlePoint.getY()!=futurePoint.getY()) ){
                   imageCounter++;
                   x+=addToX;
                   y+=addToY;
                   middlePoint.setLocation(x,y);
                   actor.setPoint(middlePoint);
                   /*if (imageCounter<=10) actor.setStatus("jump1");
                   else if (imageCounter<=40) actor.setStatus("jump2");
                   else if (imageCounter<=50) actor.setStatus("jump3");*/
                   repaint();
                   try {animator.sleep(1);} catch (InterruptedException e) {}
              //actor.setStatus("idle");
         }I use the above on several occasions:
    [1] When an enemy moves. Summary:
                             if (playerIsToVillainsRight) xToAdd = 50;
                             else if (playerIsToVillainsLeft) xToAdd = -50;
                             else if (playerIsOnSameRowAsVillain) xToAdd = 0;
                             if (playerIsBelowVillain) yToAdd = 50;
                             else if (playerIsAboveVillain) yToAdd = -50;
                             else if (playerIsOnSameColumnAsVillain) yToAdd = 0;
                             Point futurePoint = new Point (villainX+xToAdd, villainY+yToAdd);
                             moveActor(actors[currentVillain], futurePoint);[2] When the player moves. Summary (this is inside the mouseClicked listener):
    //mouseLocation = MouseWEvent.getPoint();
    //stl, str, etc = rectangles that represents future location of the player on the board.
              if (waitingForPlayer) {
                   if (stl.contains(mouseLocation) && !hoveringVillain(stl)) {
                        moveActor(actors[0], stl.getLocation());
                        waitingForPlayer = false;
                   if (str.contains(mouseLocation) && !hoveringVillain(str)) {
                        moveActor(actors[0], str.getLocation());
                        waitingForPlayer = false;
                   if (sbl.contains(mouseLocation) && !hoveringVillain(sbl)) {
                        moveActor(actors[0], sbl.getLocation());
                        waitingForPlayer = false;                                   
                   if (sbr.contains(mouseLocation) && !hoveringVillain(sbr)) {
                        moveActor(actors[0], sbr.getLocation());
                        waitingForPlayer = false;
    SO ... WHAT IS THE QUESTION?!?
    What I see when I run the game:
    the animation of the enemy (first code) works, but the animation of the player (second code, inside the mouse listeners) -- doesn't!
    The purpose of the moveActor is to move the enemy or player pixel by pixel, until its in the future point,
    instead of skipping the pixels between the squares and going straight for the future location.
    So what comes out is, that the enemy is moving pixel by pixel, and the player simply jumps there!
    I doublechecked and if I use moveActor with the player OUTSIDE the mouse listener, it works (i think).
    Any ideas what is the source of this problem?
    Hope I made myself clear enough :D
    Thanks,
    Eshed.

    I don't know if thats what happens, nor how to fix the thread problems. The mosue actions are "threaded" by default, no? And the moving thing happens after the mouse was clicked, and if the enemy's moving the user can still move his mouse and get responses, like "enemy didn't move yet" and stuff.
    Here's the complete GamePanel.java:
    //drawings
    import javax.swing.ImageIcon;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    //events
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    //tools
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.MediaTracker;
    import java.awt.Dimension;
    //panels, buttons, etc
    import javax.swing.JPanel;
    /** The Game Panel.
    *The panel's size is 500x500, and each square is squaresized 50.
    *This is where the game actually "exists". Here its being updated, drawn, etc.*/
    public class GamePanel extends JPanel implements Runnable
         private static final int PWIDTH = 500;                              //Width of the panel.
         private static final int PHEIGHT = 500;                              //Height of the panel.
         private static final int SQUARESIZE = 50;                         //Size of each square in the panel.
         private boolean working = false;                                   //Game keeps going until this is FALSE.
         private volatile Thread animator;                                   //The animation thread.
         private ImageIcon stand,fall;                                        //Images for the background - ground and water.
         private static ImageHandler ih;                                        //An image handler for image loading.
         private int numOfImages = 0;                                        //Number of total images (max image qunatity).
         private Actor[] actors;                                                  //The actors: [0] is the player, rest are enemies.
         private Point mouseLocation;                                        //Saves the current mouse location for checking where the mouse is
         protected Rectangle stl, str, sbl, sbr;                              //squares around the player, for mouse stuff.
         protected Rectangle v1, v2, v3, v4, v5;                              //squares around each villain, for mouse stuff.
         protected Rectangle wholeBoard = new Rectangle(0,0,PWIDTH,PHEIGHT);
         protected boolean waitingForPlayer = true;
         private int currentVillain = 1;
         private boolean inSight = false;
         // in methods other than the listeners.
         /** Waits for the Window (or whatever this panel loads in) to settle in before doing anything.*/
         public void addNotify()
              super.addNotify();                                                                           //When the super finishes...
              go();                                                                                                         //..go, go, go!
         /** Starts the game.*/
         private void go()
              if (animator==null || !working)     {                                        //if the game isn't in process,
                   animator = new Thread(this);                                        //make the animator as the main process,
                   animator.start();                                                                      //and start it (because of the runnable it launches "run()".
         /**Constructor of the Game Panel.*/
         public GamePanel()
              numOfImages = 14;                                                                      //Total image num.
              ih = new ImageHandler(this,numOfImages);               //Setting a new image handler for the images.
              ih.addImage("player_idle", "images/p_idle.png");          //Adding images.
              ih.addImage("villain_idle", "images/v_idle.png");
              ih.addImage("stand", "images/stand.gif");
              ih.addImage("fallpng", "images/fall.png");
              ih.addImage("fall", "images/fall.gif");
              ih.addImage("ghost", "images/ghost.gif");
              ih.addImage("villain_angry", "images/v_angry.png");
              ih.addImage("player_angry", "images/p_angry.png");
              ih.addImage("player_jump1", "images/p_j1.gif");
              ih.addImage("player_jump2", "images/p_j2.gif");
              ih.addImage("player_jump3", "images/p_j3.gif");
              ih.addImage("villain_jump1", "images/v_j1.gif");
              ih.addImage("villain_jump2", "images/v_j2.gif");
              ih.addImage("villain_jump3", "images/v_j3.gif");
              setPreferredSize(new Dimension(PWIDTH,PHEIGHT));     //Setting size of the panel.
              setFocusable(true);                                                                                //This and the next makes the window "active" and focused.
              requestFocus();
              /** Mouse hovering settings.*/
              addMouseMotionListener( new MouseMotionAdapter()
                   /** When the mouse is moving, do these stuff.*/
                   public void mouseMoved(MouseEvent e1)
                         *  |  stl  |       | str   |          stl = squareTopLeft
                         *  |_______|_______|_______|       str = squareTopRight
                        *   |       |current|       |         current = player's location
                        *   |_______|_______|_______|       sbl = squareBottomLeft
                        *   |  sbl  |       |  sbr  |       sbr = squareBottomRight
                        *   |_______|_______|_______|
                        mouseLocation = e1.getPoint();
                        Dimension defaultSquareDimension = new Dimension(50,50);
                        //current-player-location points
                        Point topLeft = new Point((int)actors[0].getPoint().getX(), (int)actors[0].getPoint().getY());
                        Point topRight = new Point((int)actors[0].getPoint().getX()+50, (int)actors[0].getPoint().getY());
                        Point bottomLeft = new Point((int)actors[0].getPoint().getX(), (int)actors[0].getPoint().getY()+50);
                        Point bottomRight = new Point((int)actors[0].getPoint().getX()+50, (int)actors[0].getPoint().getY()+50);
                        //four-squares-around-the-player points
                        //T = top, B = bottom, R = right, L = left
                        Point ptl = new Point((int)topLeft.getX()-50,(int)topLeft.getY()-50);
                        Point ptr = new Point((int)topRight.getX(),(int)topRight.getY()-50);
                        Point pbl = new Point((int)bottomLeft.getX()-50,(int)bottomLeft.getY());
                        Point pbr = new Point((int)bottomRight.getX(),(int)bottomRight.getY());
                        //ghosts
                        stl = new Rectangle (ptl, defaultSquareDimension);
                        str = new Rectangle (ptr, defaultSquareDimension);
                        sbl = new Rectangle (pbl, defaultSquareDimension);
                        sbr = new Rectangle (pbr, defaultSquareDimension);
                        Rectangle player = new Rectangle(topLeft, defaultSquareDimension);     //rectangle of player
                        if (stl.contains(mouseLocation) && !hoveringVillain(stl))
                             actors[8] = new Actor("ghost", ptl);
                             else actors[8] = null;
                        if (str.contains(mouseLocation) && !hoveringVillain(str))
                             actors[9] = new Actor("ghost", ptr);
                             else actors[9] = null;
                        if (sbl.contains(mouseLocation) && !hoveringVillain(sbl))
                             actors[10] = new Actor("ghost", pbl);
                             else actors[10] = null;
                        if (sbr.contains(mouseLocation) && !hoveringVillain(sbr))
                             actors[11] = new Actor("ghost", pbr);
                             else actors[11] = null;
                   private boolean hoveringVillain(Rectangle r)
                        boolean onVillain = false;
                        for (int i=1; i<=5 && !onVillain; i++) onVillain = actors.getRect().equals(r);
                        return onVillain;
              /** Mouse-click settings.
              Note: only usable after moving the mouse. /
              addMouseListener (new MouseAdapter()
                   /** When the mouse button is clicked */
                   public void mouseClicked (MouseEvent me)
                        mouseClickedAction(me);
         private boolean hoveringVillain(Rectangle r)
              boolean onVillain = false;
              for (int i=1; i<=5 && !onVillain; i++) onVillain = actors[i].getRect().equals(r);
              return onVillain;
         public void mouseClickedAction(MouseEvent me)
              System.out.println("Point: "+me.getX()+","+me.getY());
              if (waitingForPlayer) {
                   //causes error if the mouse wasn't moved uptil now. try it.
                   mouseLocation = me.getPoint();
                   if (stl.contains(mouseLocation) && !hoveringVillain(stl)) {
                        moveActor(actors[0], stl.getLocation());
                        waitingForPlayer = false;
                   if (str.contains(mouseLocation) && !hoveringVillain(str)) {
                        moveActor(actors[0], str.getLocation());
                        waitingForPlayer = false;
                   if (sbl.contains(mouseLocation) && !hoveringVillain(sbl)) {
                        moveActor(actors[0], sbl.getLocation());
                        waitingForPlayer = false;                                   
                   if (sbr.contains(mouseLocation) && !hoveringVillain(sbr)) {
                        moveActor(actors[0], sbr.getLocation());
                        waitingForPlayer = false;
              } else MiscTools.shout("Wait for the computer to take action!");
              if (actors[0].getPoint().getY() == 0){
                   for (int i=1; i<=5; i++){
                             actors[i].setStatus("angry");
                   //repaint();
                   MiscTools.shout("Game Over! You Won!");
         /** First thing the Game Panel does.
         Initiating the variables, and then looping: updating, painting and sleeping./
         public void run() {
    Thread thisThread = Thread.currentThread();                                                  //Enables the restart action (two threads needed).
    init();                                                                                                                                            //Initialize the variables.
    while (animator == thisThread && working){                                                  //While the current thead is the game's and it's "on",
                   think();                                                                                                                             //Update the variables,
                   repaint();                                                                                                                             //Paint the stuff on the panel,
                   try {Thread.sleep(5);} catch (InterruptedException ex) {}                    //And take a wee nap.
         /** Initializing the variables.*/
         private void init()
              currentVillain = 1;
              working = true;                                                                                //Make the game ready for running.
              inSight = false;
              actors = new Actor[12];                                                                      //Six actors: player and 5*villains.
              actors[0] = new Actor("player", 200, 450);                                             //The first actor is the player.
              int yPoint = 50;                                                                           //The Y location of the villains (first row).
              /* ACTORS ON TOP, RIGHT, LEFT
              actors[1] = new Actor ("villain", 0, 350);
              actors[2] = new Actor ("villain", 0, 150);
              actors[3] = new Actor ("villain", 50, 0);
              actors[4] = new Actor ("villain", 250, 0);
              actors[5] = new Actor ("villain", 450, 0);
              actors[6] = new Actor ("villain", 450, 200);
              actors[7] = new Actor ("villain", 450, 400);
              /* ACTORS ON TOP*/
              for (int i=1; i<actors.length-4; i++){                                                  //As long as it doesnt go above the array...
                   actors[i] = new Actor ("villain", yPoint, 0);                                   //init the villains
                   actors[i].setStatus("idle");
                   yPoint+=100;                                                                           //and advance in the Y axis.
         /** Updating variables.*/
         private void think()
              if (!waitingForPlayer){
                   //initialize
                   int playerX = (int)actors[0].getPoint().getX();
                   int playerY = (int)actors[0].getPoint().getY();
                   boolean moved = false;
                   wholeBoard = new Rectangle(0,0,500,500);     //needed to check whether an actor is inside the board
                   //for (int in = 0; in<=5; in++) actors[in].setStatus("idle"); //"formatting" the actor's mood
                   if (playerY <= 1000) inSight = true;     //first eye contact between the player and villains.
                   int closestVillainLevel = 0;
                   int[] vills = closestVillain();
                   int moveCounter = 0;
                   if (inSight) {
                        while (!moved){               //while none of the villains made a move
                        moveCounter++;
                        if (moveCounter == 5) moved = true;
                        else{
                             currentVillain = vills[closestVillainLevel];
                             int villainX = (int)actors[currentVillain].getPoint().getX();
                             int villainY = (int)actors[currentVillain].getPoint().getY();
                             //clearing stuff up before calculating things
                             boolean playerIsBelowVillain = playerY > villainY;
                             boolean playerIsAboveVillain = playerY < villainY;
                             boolean playerIsOnSameRowAsVillain = playerY == villainY;
                             boolean playerIsToVillainsRight = playerX > villainX;
                             boolean playerIsToVillainsLeft = playerX < villainX;
                             boolean playerIsOnSameColumnAsVillain = playerX == villainX;
                             //System.out.println("\n-- villain number "+currentVillain+" --\n");
                             int xToAdd = 0, yToAdd = 0;
                             if (playerIsToVillainsRight) xToAdd = 50;
                             else if (playerIsToVillainsLeft) xToAdd = -50;
                             else if (playerIsOnSameRowAsVillain) xToAdd = 0;
                             if (playerIsBelowVillain) yToAdd = 50;
                             else if (playerIsAboveVillain) yToAdd = -50;
                             else if (playerIsOnSameColumnAsVillain) yToAdd = 0;
                             Point futurePoint = new Point (villainX+xToAdd, villainY+yToAdd);
                             if (legalPoint(futurePoint)){
                                  moveActor(actors[currentVillain], futurePoint);
                                  moved = true;
                                  //System.out.println("\nVillain "+currentVillain+" is now at "+actors[currentVillain].getPoint());
                             else closestVillainLevel=circleFive(closestVillainLevel);
                        } //end of else
                        } //end of while
                        //currentVillain = circleFive(currentVillain); //obsolete
                   } //end of ifInSight
                   waitingForPlayer = true;
         private boolean legalPoint(Point fp)
              return (wholeBoard.contains(fp) && !onPeople(fp) && legalSquare(fp));
         private boolean legalSquare(Point p)
              if ( (p.getX()==0 || p.getX()%100==0) && (p.getY()/50)%2!=0 ) return true;
              if ( (p.getX()/50)%2!=0 && (p.getY()==0 || p.getY()%100==0) ) return true;
              return false;
         //return the closest villain to the player, by its level of distance.
         public int[] closestVillain()
              //System.out.println("Trying to find the closest villain...");
              double[] gaps = new double[5];     //the distances array
              //System.out.println("The villains' distances are: ");
              for (int i=0; i<5; i++){
                   gaps[i] = distanceFromPlayer(actors[i+1].getPoint());     //filling the distances array
                   //System.out.print(gaps[i]+", ");
              int[] toReturn = new int[5];
              double smallestGapFound;
              double[] arrangedGaps = smallToLarge(gaps);
              for (int level=0; level<5; level++){
                   smallestGapFound = arrangedGaps[level];
                   for (int i=1; i<=5; i++){
                        if (smallestGapFound == distanceFromPlayer(actors[i].getPoint())){
                             toReturn[level] = i;
              return toReturn;
         private double[] smallToLarge(double[] nums)
              //System.out.println("\nArranging array... \n");
              double[] newArray = new double[5];
              int neweye = 0;
              double theSmallestOfTheArray;
              for (int i=0; i<nums.length; i++){
                   theSmallestOfTheArray = smallest(nums);
                   //System.out.println("\t\t>> Checking whether location "+i+" ("+nums[i]+") is equal to "+theSmallestOfTheArray);
                   if (nums[i] == theSmallestOfTheArray && nums[i]!=0.0){
                        //System.out.println("\t\t>> Adding "+nums[i]+" to the array...");
                        newArray[neweye] = nums[i];
                        //System.out.println("\t\t>> Erasing "+nums[i]+" from old array...\n");
                        nums[i] = 0.0;
                        neweye++;
                        i=-1;
              /*System.out.print("\nDONE: ");
              for (int i=0; i<newArray.length; i++)
                   System.out.print("["+newArray[i]+"] ");
              System.out.println();*/
              return newArray;
         private double smallest (double[] nums)
                   //System.out.print("\tThe smallest double: ");
                   double small = 0.0;
                   int j=0;
                   while (j<nums.length){               //checking for a starting "small" that is not a "0.0"
                        if (nums[j]!=0.0){
                             small = nums[j];
                             j = nums.length;
                        } else j++;
                   for (int i=1; i<nums.length; i++){
                        if (small>nums[i] && nums[i]!=0.0){
                             small = nums[i];
                   //System.out.println(small+".");
                   return small;
         private double distanceFromPlayer(Point vp)
              Point pp = actors[0].getPoint(); //pp=plaer's point, vp=villain's point
              double x = Math.abs(vp.getX() - pp.getX());
              double y = Math.abs(vp.getY() - pp.getY());
              return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
         private int circleFive(int num)
                   if (num>=5) return 0;
                   else return num+1;
         private boolean onPeople(Point p)
              for (int jj=0; jj<=5; jj++)
                   if (jj!=currentVillain && p.equals(actors[jj].getPoint()))
                        return true;
              return false;
         /** Painting the game onto the Game Panel.*/
         public void paintComponent(Graphics g)
              Graphics2D graphics = (Graphics2D)g;                                                            //Reset the graphics to have more features.
              //draw bg
              graphics.setColor(Color.white);                                                                                //"format" the panel.
              graphics.fillRect(0,0,500,500);
         char squareType = 'f';                                                                                                    //First square's type (stand or fall).
         for (int height=0; height<PHEIGHT; height=height+SQUARESIZE){     //Painting the matrix bg.
                   for (int width=0; width<PWIDTH; width=width+SQUARESIZE){
                        if (squareType=='f') {                                                                                               //If a "fall" is to be drawn,
                             ih.paint(graphics, "fallpng", new Dimension(width,height));          //Draw a non-animated image to bypass white stuff.
                             ih.paint(graphics, "fall", new Dimension(width,height));               //Draw the water animation.
                             squareType = 's';                                                                                                    //Make the next square a "stand".
                        } else if (squareType=='s'){                                                                                //If a "stand" is to be drawn,
                             ih.paint(graphics, "stand", new Dimension(width,height));          //Draw the ground image,
                             squareType = 'f';                                                                                                    //and make the next square a "fall".
                   if (squareType=='f') squareType = 's';                                                                 //After finishing a row, switch again so
                   else squareType = 'f';                                                                                                    // the next line will start with the same type (checkers).
              for (int i=actors.length-1; i>=0; i--){                                                                           //Draw the actors on the board.
                   if (actors[i]!=null)
                        ih.paint(graphics, actors[i].currentImage(), actors[i].getPoint());
         /** Restart the game.
         Or, in other words, stop, initialize and start (again) the animator thread and variables./
         public void restart()
              System.out.println("\n\n\nRESTARTING GAME\n\n\n");
              animator = null;                                                                                                                   //Emptying the thread.
              init();                                                                                                                                                 //Initializing.
              animator = new Thread(this);                                                                                     //Re-filling the thread with this panel's process.
              animator.start();                                                                                                                   //launch "run()".
         protected void moveActor(Actor actor, Point futurePoint)
              Point presentPoint = actor.getPoint();
              int x = (int)presentPoint.getX(), y = (int)presentPoint.getY();
              int addToX, addToY;
              if (futurePoint.getX() > x) addToX = 1;
              else addToX = -1;
              if (futurePoint.getY() > y) addToY = 1;
              else addToY = -1;
              Point middlePoint = new Point(x,y);
              int imageCounter = 0;
              while ( (middlePoint.getX()!=futurePoint.getX()) && (middlePoint.getY()!=futurePoint.getY()) ){
                   imageCounter++;
                   x+=addToX;
                   y+=addToY;
                   middlePoint.setLocation(x,y);
                   actor.setPoint(middlePoint);
                   /*if (imageCounter<=10) actor.setStatus("jump1");
                   else if (imageCounter<=40) actor.setStatus("jump2");
                   else if (imageCounter<=50) actor.setStatus("jump3");*/
                   repaint();
                   try {animator.sleep(1);} catch (InterruptedException e) {}
              //actor.setStatus("idle");

  • Can you size an image placed in a Tooltip trigger?

    In the Tooltip widget I've placed a png image in the trigger box (the blank box, not the rounded box where type goes), but can't seem to resize it. Is there a way I can do this?

    Assuming we're taking about images brought in via File:Place or by dragging and dropping a file from the Finder/Explorer, the resizing should work the same regardless of whether the image is in a trigger or not.
    When a graphic is in a trigger container in a widget, and first click to select will show "Widget" in the Control Strip. The second will show "Container" for the trigger container. The third will show "Image Frame" for the bounding/cropping rectangle around the image. From there a double click will select "Image" which can then be resize or moved within the cropping rectangle.
    To resize an image without changing its crop, click until the "Image Frame" is selecting, then grab a selection handle and resize. To change the crop, you can use the same approach, but hold down the Command/Control key while moving the selection handle.
    Hopefully that's helpful? Perhaps I'm not understanding the question/confusion?
    One nuance with objects inside a Container is that the container will resize to be large enough to fully encampass a contained object that is resized larger, but the Container will not automatically resize smaller when a contained object is made smaller.

  • Mouse pointer shape changing

    Hello....
    I have a panel . on this panel a rectangle is drawn by using 2D graphics... i want to change the mouse cursor when the mouse is in the middle of the rectangle and also change when the mouse is on a side of the rectangle. to show user that when he/she take the mouse pointer at the side of the rectangle then it will be drag mode..please give a example code...thank you

    It sounds like you'll need to use the setCursor method of your JPanel along with a MouseMotionListener to pick up when the cursor is moved over the drawn rectangle.

  • When I move a shape or text in Photoshop, the dimensions/size changes. How do I fix this? ex) moved a 20px x 40px rectangle, and rectangle's dimensions changed to 20px x 40.16px.

    When I move a shape or text in Photoshop, the dimensions/size changes. How do I fix this?
    It's always a decimal point too.
    ex 1) moved a 20px x 40px rectangle, and rectangle's dimensions changed to 20px x 40.16px.
    ex 2) moved a 124pt text to the right (Shift + arrow right a few times) and text changed to 14.06pt.

    When I move a shape or text in Photoshop, the dimensions/size changes. How do I fix this?
    It's always a decimal point too.
    ex 1) moved a 20px x 40px rectangle, and rectangle's dimensions changed to 20px x 40.16px.
    ex 2) moved a 124pt text to the right (Shift + arrow right a few times) and text changed to 14.06pt.

  • Blue rectangle moving across the screen

    Hi,
    Recently I installed ios7 in my iPod touch 5th generation.
    After installing this os, I was having a problem of blue rectangle moving across the screen. This usually comes if I connect the device to wifi.
    Did anybody faced the same issue?
    Regards,
    Santhosh

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • Embedded HTML is moving my rectangles

    Hello all,
    I'm embedding HTML (a Business Catalyst module) into my site and it moves down my two side rectangles.  I don't understand why because there's plenty of room.  I tried moving the rectangles (they're on a master page) backward, moving them to a separate layer, as well as moving the embedded HTML on the page they're on to a separate layer but nothing has helped.  Can someone please help me with this?
    I provided a link below.
    http://thecoffeebean.businesscatalyst.com/africa

    Yep, that's what I thought I'd see. The height of the box containing the HTML embed in Design view is important. It sets the minimum size of the output "div" and it also establishes the distance you'd like to have maintained between the item and what's below it. Thus in this case bottom of your HTML embed will remain above the top of the left side bar and when the HTML item ends up being much bigger on the live page everything will shift down.
    To fix this resize the HTML embed object in Muse Design view tall enough to contain a typical item from the module tag.

  • Moving a rectangle - [CS2 VB Script]

    Hi
    I'm writing a scatter proof programme and I have no problem importing the graphics into separate graphic frames. The problem happens
    when I attempt to move each frame into position.
    I'm using this code:
            For myCounter = 1 To UBound(myFileList) + 1
                myFile = myFileList(myCounter - 1)
                Set myPage = myPages.Item(PageCount)
                Set myRectangle = myPage.Rectangles.Add
                myRectangle.GeometricBounds = Array(0, 0, 40, 40)
                myRectangle.strokeWeight = 0
                myRectangle.strokeColor = myDocument.Swatches.Item("None")
                myRectangle.place myFile
                myRectangle.Label
                myRectangle.fit idFitOptions.idFrameToContent
                Y1 = myRectangle.GeometricBounds(0)
                X1 = myRectangle.GeometricBounds(1)
                Y2 = myRectangle.GeometricBounds(2)
                X2 = myRectangle.GeometricBounds(3)
         myRectangle.GeometricBounds = Array (Y1 + 20, X1 + 20, Y2 + 20, X2 + 20)
                myRectangle.fit idFitOptions.idFrameToContent
           Next
    If I don't use the second FrameToContent (the one before Next), the result is that the frame is moved but the graphic ends up zoomed
    down to about 50% of normal size.
    Putting in the second FrameToContent results in the graphic coming out the correct size, but the graphic frame doesn't move and remains
    in the top left corner of the screen.
    Is there a better way to move a graphic frame?
    TIA
    [Addendum]
    What appears to be happening is that the graphic frame moves, but the graphic stays in its original position. I want to move the graphic
    frame and move the contents by the same amount.
    Message was edited by: John Galvin

    Yes, I tried to group them first by
        Dim oGrp As GroupItem
        For Each oPageItem In oCurDoc.PageItems
            Set oGrp = oCurDoc.GroupItems.Add
            Set oPageItem = oGrp.PageItems.Add
            iCnt = iCnt + 1
            If iCnt > iPageItemCount  Then Exit For
        Next
         oCurDoc.Selection = oGrp
    But the selection is always "empty" - nothing been selected.  Why?
    Thanks.

  • Moving a rectangle or change color in "Run-Time "?

    First step, the objects of decoration you can modify its properties in "Run-Time "?
    Moving a rectangle or change color in "Run-Time "?
    I want to develop a mini SCADA application, where I have to do some animations usingsimple objects like Shapes.

    Yes, it is possible to modify decorations in runtime. An example is below.
    As you can see, you just need to get a reference to the front panel containing the decoraitions, and then use the Decos[] property to get an array of references to the decorations. These can be passed to a property node.
    Unfortunately, the decorations cannot be given a unique identifier, such as a label. So if you have multiple decorations, it can be tricky to modify the properties of a specific one. If you are only dealing with one shape, this won't be an issue. One roundabout way to pick out a particular decoration would be to search through the array references until you find the one with matching size and location on the front panel. Alternatively, you could use a disabled control, such as a boolean push button with no caption, and refer to that directly.
    Hope this helps.
    -Garrett

  • Cropping when moving and resizing a cropping rectangle

    I created a program that crops an image and displays the cropped image but I'm trying to add more functionality
    by making it movable and resizable. The rectangle moves and resizes but it only crops an image when user draws the rectangle and not when moved or resized. I know that the X,Y, height and width position of the rectangle would need to be updated but I'm not
    sure how I can accomplish this being new to WPF. Below is my user control "CropControl and the code behind. Also, I'm implementing my code using MVVM framework.
    XAML: 
    <UserControl x:Class="Klein_Tools_Profile_Pic_Generator.CropControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:s="clr-namespace:Klein_Tools_Profile_Pic_Generator"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
    <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
    <Rectangle Fill="Transparent"/>
    </ControlTemplate>
    <!-- ResizeDecorator Template -->
    <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
    <Grid>
    <s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 -4 0 0"
    VerticalAlignment="Top"/>
    <s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="-4 0 0 0"
    VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
    <s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="0 0 -4 0"
    VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
    <s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 0 0 -4"
    VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE"
    VerticalAlignment="Top" HorizontalAlignment="Left"/>
    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW"
    VerticalAlignment="Top" HorizontalAlignment="Right"/>
    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW"
    VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE"
    VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
    </Grid>
    </ControlTemplate>
    <!-- Designer Item Template-->
    <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
    <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
    <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
    <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
    </Grid>
    </ControlTemplate>
    </UserControl.Resources>
    <Canvas x:Name="BackPanel"
    MouseLeftButtonDown="LoadedImage_MouseLeftButtonDown"
    MouseMove="LoadedImage_MouseMove"
    MouseLeftButtonUp="LoadedImage_MouseLeftButtonUp"
    Background="Transparent">
    <ContentControl x:Name="contControl" Visibility="Collapsed"
    Template="{StaticResource DesignerItemTemplate}">
    <Rectangle x:Name="selectionRectangle" Fill="#220000FF"
    IsHitTestVisible="False"/>
    </ContentControl>
    </Canvas>
    </UserControl>
    CODE BEHIND:
    namespace Klein_Tools_Profile_Pic_Generator
    /// <summary>
    /// Interaction logic for CropControl.xaml
    /// </summary>
    public partial class CropControl : UserControl
    private bool isDragging = false;
    private Point anchorPoint = new Point();
    private bool moveRect;
    TranslateTransform trans = null;
    Point originalMousePosition;
    public CropControl()
    InitializeComponent();
    //Register the Dependency Property
    public static readonly DependencyProperty SelectionProperty =
    DependencyProperty.Register("Selection", typeof(Rect), typeof(CropControl), new PropertyMetadata(default(Rect)));
    public Rect Selection
    get { return (Rect)GetValue(SelectionProperty); }
    set { SetValue(SelectionProperty, value); }
    // this is used, to react on changes from ViewModel. If you assign a
    // new Rect in your ViewModel you will have to redraw your Rect here
    private static void OnSelectionChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e)
    Rect newRect = (Rect)e.NewValue;
    Rectangle selectionRectangle = d as Rectangle;
    if (selectionRectangle != null)
    return;
    selectionRectangle.SetValue(Canvas.LeftProperty, newRect.X);
    selectionRectangle.SetValue(Canvas.TopProperty, newRect.Y);
    selectionRectangle.Width = newRect.Width;
    selectionRectangle.Height = newRect.Height;
    private void LoadedImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    if (isDragging == false)
    anchorPoint.X = e.GetPosition(BackPanel).X;
    anchorPoint.Y = e.GetPosition(BackPanel).Y;
    Canvas.SetZIndex(selectionRectangle, 999);
    isDragging = true;
    BackPanel.Cursor = Cursors.Cross;
    private void LoadedImage_MouseMove(object sender, MouseEventArgs e)
    if (isDragging)
    double x = e.GetPosition(BackPanel).X;
    double y = e.GetPosition(BackPanel).Y;
    contControl.SetValue(Canvas.LeftProperty, Math.Min(x, anchorPoint.X));
    contControl.SetValue(Canvas.TopProperty, Math.Min(y, anchorPoint.Y));
    contControl.Width = Math.Abs(x - anchorPoint.X);
    contControl.Height = Math.Abs(y - anchorPoint.Y);
    if (contControl.Visibility != Visibility.Visible)
    contControl.Visibility = Visibility.Visible;
    private void Image_MouseMove(object sender, MouseEventArgs e)
    if (moveRect)
    trans = selectionRectangle.RenderTransform as TranslateTransform;
    if (trans == null)
    selectionRectangle.RenderTransformOrigin = new Point(0, 0);
    trans = new TranslateTransform();
    selectionRectangle.RenderTransform = trans;
    trans.Y = -(originalMousePosition.Y - e.GetPosition(BackPanel).Y);
    trans.X = -(originalMousePosition.X - e.GetPosition(BackPanel).X);
    e.Handled = false;
    private void LoadedImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    if (isDragging)
    isDragging = false;
    if (contControl.Width > 0)
    //Crop.IsEnabled = true;
    //Cut.IsEnabled = true;
    BackPanel.Cursor = Cursors.Arrow;
    contControl.GetValue(Canvas.LeftProperty);
    // Set the Selection to the new rect, when the mouse button has been released
    Selection = new Rect(
    (double)contControl.GetValue(Canvas.LeftProperty),
    (double)contControl.GetValue(Canvas.TopProperty),
    contControl.Width,
    contControl.Height);

    Hello HotSawz,
    The ResizeThumb and MoveThumb is not in your code so I cannot compile. Anyway, it is not the problem.
    Anyway, can you clarify more details about "it only crops an image when user draws the rectangle and not when moved or resized", it is already normal behavoir for you to draw a rectangle and then move it. What kind of action do you want? Do you
    mean some controls like this:
    http://www.codeproject.com/Articles/23158/A-Photoshop-like-Cropping-Adorner-for-WPF
    Best regards,
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Moving a rotated rectangle [AS CS5]

    I have a script that moves items from the top half of each page to a new page, essentially like this:
    set mybounds to visible bounds of myitem
    tell myitem to move to myPage1
    tell myitem to move to {item 2 of mybounds, item 1 of mybounds}
    Works great except when the item is a rectangle with rotation applied. In that case, getting the bounds of the rotated item returns the bounds of the item unrotated, but when moving the item, the move to coordinates correspond to the rotated item. (or something like that, I haven't worked out exactly what is going on — rotated items get moved to the wrong spot).
    Can anyone suggest and alternative method of moving to a new page that works for rotated items?

    Im having no problems with rotated objects… Moving to a new containing page will forget the visible bounds and the object will default to 0,0 but I can just re-apply the bounds back to position…
    tell application "Adobe InDesign CS2"
         tell the active document
              tell page 1
                   set ThisBox to the first rectangle
                   set BoxBounds to visible bounds of ThisBox
              end tell
              move ThisBox to page 2
              set visible bounds of ThisBox to BoxBounds
         end tell
    end tell

Maybe you are looking for

  • Using URL Alias in "main rule" for a new portal desktop.

    Hi I am having a scenario : I am having two different business functionality. For accessing them separately i have to create to different portal desktops. Each one will have there own iviews and roles. BUT They can have similar user ids. I.e. same us

  • How to get OS X Mail to treat Gmail like iOS Mail

    I really like how iOS Mail only downloads my Gmail's Inbox and other directories I navigate to. I don't like how OS X Mail downloads my entire malbox automatically. Is there a way to get OS X Mail to behave like iOS Mail in terms of what directories

  • HT4623 HELP with my IPAD2

    my software update option is missing from my settings menu

  • Fireworks CS6 - crashes all the time

    Hi. I have used adobes whole rage of products for years. Last 2 years I've starded using fireworks cs5 and now cs6 on Mac. We use it at work for weblayout wireframeing templating... really good program doing those kind of stuff. But I never really co

  • Corporate Sync & Droid X

    Has anyone had trouble getting corporate sync to work properly after downloading the Froyo update since lastnight? Prior to 2.2 the program worked properly. Email seemed to come through in a very timely manner, and I was able to download / view attac