File: inputValue.cpp

package info (click to toggle)
gmsh 4.8.4%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,812 kB
  • sloc: cpp: 378,014; ansic: 99,669; yacc: 7,216; python: 6,680; java: 3,486; lisp: 659; lex: 621; perl: 571; makefile: 470; sh: 440; xml: 415; javascript: 113; pascal: 35; modula3: 32
file content (77 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download
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
// Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.

#include "inputValue.h"
#include <FL/Fl_Group.H>
#include <stdlib.h>
#include <FL/math.h>

void inputValueFloat::new_input_cb(Fl_Widget *, void *v)
{
  inputValueFloat &t = *(inputValueFloat *)v;
  double nv = strtod(t.input.value(), nullptr);
  if(nv != t.value() || t.when() & FL_WHEN_NOT_CHANGED) {
    t.set_value(nv);
    t.set_changed();
    if(t.when()) t.do_callback();
  }
}

inputValueFloat::inputValueFloat(int x, int y, int w, int h, const char *l)
  : inputValue(x, y, w, h, l)
{
  input.type(FL_FLOAT_INPUT);
  input.callback(new_input_cb, this);
}

int inputValueFloat::handle(int event)
{
  double v;
  int delta;
  int mx = Fl::event_x_root();
  static int ix, drag;
  input.when(when());
  switch(event) {
  case FL_PUSH:
    if(!step()) goto DEFAULT;
    ix = mx;
    drag = Fl::event_button();
    handle_push();
    return 1;
  case FL_DRAG:
    if(!step()) goto DEFAULT;
    delta = mx - ix;
    if(delta > 5)
      delta -= 5;
    else if(delta < -5)
      delta += 5;
    else
      delta = 0;
    switch(drag) {
    case 3: v = increment(previous_value(), delta * 100); break;
    case 2: v = increment(previous_value(), delta * 10); break;
    default: v = increment(previous_value(), delta); break;
    }
    v = round(v);
    handle_drag(soft() ? softclamp(v) : clamp(v));
    ;
    return 1;
  case FL_RELEASE:
    if(!step()) goto DEFAULT;
    if(value() != previous_value() || !Fl::event_is_click())
      handle_release();
    else {
      Fl_Widget_Tracker wp(&input);
      input.handle(FL_PUSH);
      if(wp.exists()) input.handle(FL_RELEASE);
    }
    return 1;
  case FL_FOCUS: return input.take_focus();
  case FL_SHORTCUT: return input.handle(event);
  default:
  DEFAULT:
    return input.handle(event);
  }
}