| 1 | // Copyright 2005 by Anthony Liekens [email protected] |
| 2 | #include "coordinate.h" |
| 3 | #include "selection.h" |
| 4 | #include "canvas.h" |
| 5 | |
| 6 | Selection::Selection() |
| 7 | { |
| 8 | state = NOT_SELECTING; |
| 9 | } |
| 10 | |
| 11 | void |
| 12 | Selection::start(int x, int y) |
| 13 | { |
| 14 | state = SELECTING; |
| 15 | |
| 16 | c1.setXMapped(x); |
| 17 | c1.setYMapped(y); |
| 18 | |
| 19 | c2.setXMapped(x); |
| 20 | c2.setYMapped(y); |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | Selection::update(int x, int y) |
| 25 | { |
| 26 | // Updates lower bound if currently selecting |
| 27 | if (state == SELECTING) |
| 28 | { |
| 29 | c2.setXMapped(x); |
| 30 | c2.setYMapped(y); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | Selection::end() |
| 36 | { |
| 37 | state = NOT_SELECTING; |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | Selection::render() { |
| 42 | if( state == SELECTING ) { |
| 43 | Canvas::drawMouseSelection(c1, c2); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | double |
| 48 | Selection::getMinX() const { |
| 49 | return ( c1.getX() < c2.getX() ? c1.getX() : c2.getX() ); |
| 50 | } |
| 51 | |
| 52 | double |
| 53 | Selection::getMaxX() const { |
| 54 | return ( c1.getX() > c2.getX() ? c1.getX() : c2.getX() ); |
| 55 | } |
| 56 | |
| 57 | double |
| 58 | Selection::getMinY() const { |
| 59 | return ( c1.getY() < c2.getY() ? c1.getY() : c2.getY() ); |
| 60 | } |
| 61 | |
| 62 | double |
| 63 | Selection::getMaxY() const { |
| 64 | return ( c1.getY() > c2.getY() ? c1.getY() : c2.getY() ); |
| 65 | } |
| 66 | |
| 67 | bool |
| 68 | Selection::isEmpty() const |
| 69 | { |
| 70 | return c1 == c2; |
| 71 | } |
| 72 | |
| 73 | bool |
| 74 | Selection::isSelecting() const |
| 75 | { |
| 76 | return state == SELECTING; |
| 77 | } |
| 78 |