File: selection.cpp

package info (click to toggle)
qonk 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,076 kB
  • ctags: 2,026
  • sloc: cpp: 14,978; sh: 3,464; makefile: 200
file content (78 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2005 by Anthony Liekens anthony@liekens.net
#include "coordinate.h"
#include "selection.h"
#include "canvas.h"

Selection::Selection()
{
	state = NOT_SELECTING;
}

void
Selection::start(int x, int y)
{
  state = SELECTING;

  c1.setXMapped(x);
  c1.setYMapped(y);
  
  c2.setXMapped(x);
  c2.setYMapped(y);
}

void
Selection::update(int x, int y)
{
  // Updates lower bound if currently selecting
  if (state == SELECTING)
  {
    c2.setXMapped(x);
    c2.setYMapped(y);
  }
}

void
Selection::end()
{
  state = NOT_SELECTING;
}

void 
Selection::render() {
	if( state == SELECTING ) {
                Canvas::drawMouseSelection(c1, c2);
	}
}

double 
Selection::getMinX() const { 
  return ( c1.getX() < c2.getX() ? c1.getX() : c2.getX() );
}

double 
Selection::getMaxX() const { 
  return ( c1.getX() > c2.getX() ? c1.getX() : c2.getX() ); 
}

double 
Selection::getMinY() const { 
  return ( c1.getY() < c2.getY() ? c1.getY() : c2.getY() ); 
}

double 
Selection::getMaxY() const { 
  return ( c1.getY() > c2.getY() ? c1.getY() : c2.getY() ); 
}

bool
Selection::isEmpty() const
{
  return c1 == c2;
}

bool
Selection::isSelecting() const
{
  return state == SELECTING;
}