Subversion Repositories DIN Is Noise

Rev

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

Rev Author Line No. Line
964 jag 1
/*
2
* curve_picker.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/
964 jag 6
*/
7
#include "curve_picker.h"
8
#include "curve_editor.h"
9
#include "ui_list.h"
10
#include "input.h"
1109 jag 11
#include "log.h"
12
#include "console.h"
964 jag 13
#include <vector>
14
#include <fstream>
15
using namespace std;
16
 
17
extern ui_list uis;
18
extern int mousex, mousey, mouseyy;
19
extern curve_picker_t curve_picker;
20
 
1682 jag 21
extern void makefam (widget* parent, widget* children, int n);
1109 jag 22
 
964 jag 23
void curve_picker_t::setup () {
1535 jag 24
  title.set_text ("Pick what?");
2175 jag 25
  widget* chld [] = {&title, &cancel, &comps};
26
  makefam (&pick, chld, 3);
1535 jag 27
  widget* w [] = {&title, &pick, &cancel, &comps};
28
  widget_load ("d_curve_picker", w, 4);
29
  cancel.set_text ("Cancel");
30
  pick.set_text ("Pick");
31
  LISTEN(pick, this);
32
  LISTEN(cancel, this);
33
  LISTEN(comps, this);
1533 jag 34
  n = 0;
1213 jag 35
  id = 0;
964 jag 36
}
37
 
38
curve_picker_t::~curve_picker_t () {
1535 jag 39
  widget* w [] = {&title, &pick, &cancel, &comps};
40
  widget_save ("d_curve_picker", w, 4);
964 jag 41
}
42
 
43
int curve_picker_t::handle_input () {
1534 jag 44
  if (!visible) return 0;
1535 jag 45
  widget* w [] = {&pick, &comps, &cancel, &title,};
46
  if (keypressed (SDLK_ESCAPE)) clicked (cancel);
47
  if (keypressed (SDLK_RETURN)) clicked (pick);
1112 jag 48
  int r = 0;
1535 jag 49
  for (int i = 0; i < 4;++i) {
1112 jag 50
    r = w[i]->handle_input ();
51
    if (r) break;
52
  }
964 jag 53
  return r;
54
}
55
 
56
void curve_picker_t::draw () {
57
  glEnable (GL_BLEND);
58
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1533 jag 59
    glColor4f (0, 0, 0, 0.7f);
964 jag 60
    glRecti (bg.left, bg.bottom, bg.right, bg.top);
61
  glDisable (GL_BLEND);
1535 jag 62
  widget* w [] = {&title, &pick, &cancel, &comps};
63
  for (int i = 0; i < 4;++i) w[i]->draw ();
64
  if (comps.hov != -1) curve_picker.id = comps.hov;
964 jag 65
}
66
 
67
void curve_picker_t::show () {
1213 jag 68
  id = 0;
1887 jag 69
  if (CRVED) n = CRVED->hitlist.size (); else n = 0;
1213 jag 70
  if (id < n) {
71
    widget::show ();
2175 jag 72
    int cx = pick.extents.left, cy = pick.extents.bottom;
73
    pick.move (mousex + viewport::handle_radius + 1 - cx, mouseyy - 2 * fnt.lift - cy ); // position picker to mouse loc
1533 jag 74
    hit_t::name_only = (CRVED->todo == curve_editor::PICK_CURVE);
1535 jag 75
    comps.clear ();
1533 jag 76
    for (int i = 0; i < n; ++i) {
77
      hit_t& hi = CRVED->hitlist[i];
78
      stringstream ss; ss << hi;
1535 jag 79
      comps.add (ss.str());
1533 jag 80
    }
2175 jag 81
    comps.set_pos (pick.posx, pick.posy);
1213 jag 82
    calc_bg ();
83
  }
964 jag 84
}
85
 
1213 jag 86
void curve_picker_t::hide () {
87
  widget::hide ();
88
  defocus (this);
89
}
90
 
964 jag 91
void curve_picker_t::calc_bg () {
92
  const int delta = 1;
1535 jag 93
  bg.left = title.extents.left - delta;
94
  bg.top = title.extents.top + delta;
95
  bg.right = max (cancel.extents.right, comps.extents.right) + delta;
96
  bg.bottom = comps.extents.bottom - delta;
1112 jag 97
  set_focus (this);
964 jag 98
}
99
 
100
void curve_picker_t::clicked (button& b) {
1535 jag 101
  if (&b == &comps || &b == &pick) CRVED->picked_using_picker (id);
964 jag 102
  curve_picker.hide ();
103
}