Subversion Repositories DIN Is Noise

Rev

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

Rev Author Line No. Line
964 jag 1
/*
2
* plugin.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
 
8
 
9
#include "plugin.h"
10
#include "curve_editor.h"
11
#include "vector2d.h"
12
#include "ui_list.h"
13
#include "field.h"
14
#include "viewwin.h"
15
#include "console.h"
16
#include "log.h"
17
 
18
#include <vector>
19
#include <fstream>
20
using namespace std;
21
 
22
plugin::plugin () {
978 jag 23
  name = "from_plugin";
24
  ss.str (name);
964 jag 25
  num_ctrls = 0;
26
  shapeform = 1;
27
  pts = 0;
978 jag 28
  pts_n = 0;
964 jag 29
  mix = 1;
30
  undo = 1;
978 jag 31
  ed = 0;
982 jag 32
  npts = 0;
964 jag 33
}
34
 
35
void plugin::setup () {
36
 
1555 jag 37
  num_ctrls = 2;
1586 jag 38
  ctrls.resize (num_ctrls);
39
  ctrls[0] = &cb_auto_apply;
40
  ctrls[1] = &b_apply;
964 jag 41
 
1120 jag 42
  b_apply.set_text ("Apply");
43
  cb_auto_apply.set_text ("Auto apply");
964 jag 44
 
45
  b_apply.set_listener (this);
46
  cb_auto_apply.set_listener (this);
47
 
1223 jag 48
  b_apply.click_repeat = 1;
49
 
964 jag 50
  ss.precision (10);
51
 
52
}
53
 
54
void plugin::update () {
1344 jag 55
  for (int i = 0; i < num_ctrls; ++i) ctrls[i]->update ();
964 jag 56
}
57
 
58
int plugin::handle_input () {
59
  int r = 0;
1344 jag 60
  if (!_folded) for (int i = 0; i < num_ctrls; ++i) r |= ctrls[i]->handle_input ();
964 jag 61
  return r;
62
}
63
 
64
void plugin::draw () {
1344 jag 65
  if (!_folded) for (int i = 0; i < num_ctrls; ++i) ctrls[i]->draw ();
964 jag 66
}
67
 
68
 
69
void plugin::clicked (button& b) {
70
  uis.crved->apply_plugin (this);
71
}
72
 
73
void plugin::changed (field& f) {
1542 jag 74
  do_render ();
964 jag 75
}
76
 
77
void plugin::changed (checkbutton& cb) {
78
  if (&cb == &cb_auto_apply) {
79
    if (cb.state) {
80
      uis.crved->apply_plugin (this);
81
      mix = undo = 0;
82
    } else mix = undo = 1;
83
  }
84
}
85
 
86
void plugin::try_auto_apply () {
1539 jag 87
  if (cb_auto_apply.state) ed->apply_plugin (this);
964 jag 88
}
89
 
1532 jag 90
void plugin::try_auto_apply (curve_editor* ed) {
91
  if (cb_auto_apply.state) ed->apply_plugin (this);
92
}
93
 
964 jag 94
void plugin::unfold () {
95
  for (int i = 0, j = num_ctrls; i < j; ++i) ctrls[i]->show ();
96
  _folded = 0;
97
}
98
 
99
void plugin::fold () {
100
  for (int i = 0, j = num_ctrls; i < j; ++i) ctrls[i]->hide ();
101
  _folded = 1;
102
}
103
 
104
void plugin::draw (curve_editor* ed) {
105
  glColor3f (clr.r, clr.g, clr.b);
106
  glVertexPointer (2, GL_FLOAT, 0, pts);
982 jag 107
  glDrawArrays (GL_LINE_STRIP, 0, npts);
964 jag 108
}
109
 
110
plugin::~plugin () {
111
  if (pts) delete[] pts;
112
}
113
 
114
string plugin::make_fname () {
115
  extern string user_data_dir;
116
  return (user_data_dir + "p_" + name);
117
}
118
 
978 jag 119
void plugin::gen_pts () {
120
  if (ed) {
982 jag 121
    npts = points.size ();
122
    if (pts_n < npts) {
978 jag 123
      if (pts) delete[] pts;
982 jag 124
      pts_n = npts;
978 jag 125
      pts = new float [2 * pts_n];
126
    }
127
    float wx, wy;
982 jag 128
    for (int i = 0, k = 0; i < npts; ++i) {
978 jag 129
      point<float>& p = points[i];
130
      ed->obj2win (p.x, p.y, wx, wy);
131
      pts[k++] = wx; pts[k++] = wy;
132
    }
133
  }
134
}
964 jag 135
 
978 jag 136
void plugin::set_ed (curve_editor* e) {
137
  ed = e;
138
  gen_pts ();
139
}
1532 jag 140
 
141
void plugin::do_render () {
142
  render ();
143
  try_auto_apply ();
144
}
145
 
146
void plugin::do_render (curve_editor* ed) {
147
  render ();
148
  try_auto_apply (ed);
149
}