Subversion Repositories DIN Is Noise

Rev

Rev 2097 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1370 jag 1
/*
2
* box_selector.cc
2302 jag 3
* DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath
1713 jag 4
* DIN Is Noise is released under GNU Public License 2.0
1479 jag 5
* For more information, please visit https://dinisnoise.org/
1370 jag 6
*/
1005 jag 7
#include "box_selector.h"
1007 jag 8
#include "random.h"
9
#include "container.h"
1496 jag 10
#include "console.h"
1005 jag 11
 
1100 jag 12
box_selector::box_selector () {
13
  op = NONE;
14
  cross = 0;
1489 jag 15
  lis = 0;
1100 jag 16
  lmb_clicked = 0;
1489 jag 17
  rmb_clicked = 0;
1100 jag 18
}
19
 
1005 jag 20
int box_selector::handle_input () {
21
  if (is_lmb (this)) {
22
    if (lmb_clicked == 0) {
23
      if (op == NONE) {
24
        op = EXISTS;
25
        is_lmb.tie = this;
26
        if (lis) lis->region_begin ();
27
      } else if (op == EXISTS) {
28
        op = FINISH;
29
      }
30
      lmb_clicked = 1;
31
    }
1492 jag 32
  } else {
1489 jag 33
    lmb_clicked = rmb_clicked = 0;
1005 jag 34
    if (op == EXISTS) {
35
      if (lis) lis->region_update ();
36
    } else if (op == FINISH) {
37
      is_lmb.clear (this);
38
      if (lis) lis->region_end ();
39
      op = NONE;
40
    }
41
  }
42
  return 1;
43
}
44
 
45
 
1698 jag 46
void box_selector::draw (const box<float>& region) {
1005 jag 47
  if (op == EXISTS) {
1098 jag 48
    glEnable (GL_LINE_STIPPLE);
1620 jag 49
    glLineStipple (1, 0xf00f);
1101 jag 50
    glColor3f (1, 1, 1);
1005 jag 51
    boxp[0]=region.left;boxp[1]=region.bottom;
52
    boxp[2]=region.right;boxp[3]=region.bottom;
53
    boxp[4]=region.right;boxp[5]=region.top;
54
    boxp[6]=region.left;boxp[7]=region.top;
1698 jag 55
    glVertexPointer (2, GL_FLOAT, 0, boxp);
1005 jag 56
    glDrawArrays (GL_LINE_LOOP, 0, 4);
1100 jag 57
    if (cross) {
1763 jag 58
      glColor3f (0.25, 0.25, 0.25);
1100 jag 59
      int my = (region.bottom + region.top) / 2.0 + 0.5;
1923 jag 60
      /*boxp[0]=region.left;boxp[1]=my;
1763 jag 61
      boxp[2]=region.right;boxp[3]=my;
1923 jag 62
      glDrawArrays (GL_LINES, 0, 2);*/
63
      glBegin (GL_LINES);
64
        glVertex2i (region.left, my);
65
        glVertex2i (region.right, my);
66
      glEnd ();
67
 
1100 jag 68
      int mx = (region.left + region.right) / 2.0 + 0.5;
1923 jag 69
      /*boxp[0]=mx;boxp[1]=region.bottom;
1763 jag 70
      boxp[2]=mx;boxp[3]=region.top;
1923 jag 71
      glDrawArrays (GL_LINES, 0, 2);*/
72
      glBegin (GL_LINES);
73
        glVertex2i (mx, region.bottom);
74
        glVertex2i (mx, region.top);
75
      glEnd ();
1100 jag 76
    }
1094 jag 77
    glDisable (GL_LINE_STIPPLE);
1005 jag 78
  }
79
}
80
 
81
int box_selector::abort () {
82
  if (op != NONE) {
83
    op = NONE;
84
    is_lmb.clear (this);
85
    if (lis) lis->region_abort ();
86
    return 1;
87
  }
88
  return 0;
89
}