summaryrefslogtreecommitdiff
path: root/iup/test/dial.c
blob: 727934ca9d49b35f1da5fd3a8ef78d1d57fdba0e (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdlib.h>
#include <stdio.h>

#include "iup.h"
#include "iupcontrols.h"

static int help_cb(Ihandle* ih)
{
  printf("HELP_CB(%s)\n", IupGetName(ih));
  return IUP_DEFAULT;
}

static void printdial(Ihandle* ih, double a, char* color)
{
  Ihandle* label = NULL;
  char* u = NULL;
  char* type = IupGetAttribute(ih, "TYPE");

  switch(type[0])
  {
    case 'V':
      label = IupGetHandle("lbl_v");
      u = "deg";
      break;
    case 'H':
      label = IupGetHandle("lbl_h");
      u = "rad";
      break;
    case 'C':
      label = IupGetHandle("lbl_c");
      u = "deg";
      break;
  }

  if (label)
  {
    IupSetfAttribute(label, "TITLE", "%.3g %s", a, u);
    IupSetAttribute(label, "BGCOLOR", color);
  }
} 

static int mousemove(Ihandle* ih, double a)
{
  printdial(ih, a, "0 255 0");
  return IUP_DEFAULT;
} 

static int button_press(Ihandle* ih, double a)
{
  printdial(ih, a, "255 0 0");
  return IUP_DEFAULT;
} 

static int button_release(Ihandle* ih, double a)
{
  printdial(ih, a, NULL);
  return IUP_DEFAULT;
} 

void DialTest(void)
{
  char *error = NULL;
  Ihandle *dlg, *dial_h, *dial_v, *dial_c;

  error = IupLoad("dial.led");
  if (error)
  {
    error = IupLoad("../test/dial.led");
    if (error)
    {
      IupMessage("%s\n", error);
      return;
    }
  }

  dlg = IupGetHandle("dlg");
  dial_h = IupGetHandle("dial_h");
  dial_v = IupGetHandle("dial_v");
  dial_c = IupGetHandle("dial_c");

  IupSetFunction("dial_mousemove", (Icallback)mousemove);
  IupSetFunction("dial_buttonpress", (Icallback)button_press);
  IupSetFunction("dial_buttonrelease", (Icallback)button_release);

  IupSetCallback(dial_h, "HELP_CB", help_cb);
  IupSetCallback(dial_v, "HELP_CB", help_cb);

  IupSetAttribute(dial_h, "EXPAND", "HORIZONTAL");
  IupSetAttribute(dial_v, "EXPAND", "VERTICAL");

//  IupSetAttribute(dlg, "HELPBUTTON", "YES");
//  IupSetAttribute(dlg, "DIALOGFRAME", "YES");

  IupShow(dlg);
}

#ifndef BIG_TEST
int main(int argc, char* argv[])
{
  IupOpen(&argc, &argv);
  IupControlsOpen();

  DialTest();

  IupMainLoop();

  IupClose();

  return EXIT_SUCCESS;
}
#endif