summaryrefslogtreecommitdiff
path: root/iup/test/val.c
blob: c1b47243e0cd3838d101108290917061512847bc (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <stdlib.h>
#include <stdio.h>

#include "iup.h"
#include "iupkey.h"


static Ihandle *lbl_h=NULL, *lbl_v=NULL;

static void print_value(Ihandle *ih, double a)
{
  char *type = IupGetAttribute(ih, "TYPE");

  switch(type[0])
  {
    case 'V':
      IupSetfAttribute(lbl_v, "TITLE", "VALUE=%.2f", a);
      break;
    case 'H':
      IupSetfAttribute(lbl_h, "TITLE", "VALUE=%.2f", a);
      break;
  }
}

static int mousemove(Ihandle *ih, double a)
{
  printf("mousemove %.2f\n", a);
  print_value(ih, a);
  return IUP_DEFAULT;
}

static int button_press(Ihandle *ih, double a)
{
  char *type = IupGetAttribute(ih, "TYPE");

  printf("button_press %.2f\n", a);

  switch(type[0])
  {
    case 'V':
      IupSetAttribute(lbl_v, "FGCOLOR", "255 0 0");
      break;

    case 'H':
      IupSetAttribute(lbl_h, "FGCOLOR", "255 0 0");
      break;
  }

  print_value(ih, a);

  return IUP_DEFAULT;
}

static int button_release(Ihandle *ih, double a)
{
  char *type = IupGetAttribute(ih, "TYPE");

  printf("button_release %.2f\n", a);

  switch(type[0])
  {
    case 'V':
      IupSetAttribute(lbl_v, "FGCOLOR", "0 0 0");
      break;

    case 'H':
      IupSetAttribute(lbl_h, "FGCOLOR", "0 0 0");
      break;
  }

  print_value(ih, a);

  return IUP_DEFAULT;
}

char *iupKeyCodeToName(int code);

static int k_any(Ihandle *ih, int c)
{
  if (iup_isprint(c))
    printf("K_ANY(%d = %s \'%c\')\n", c, iupKeyCodeToName(c), (char)c);
  else
    printf("K_ANY(%d = %s)\n", c, iupKeyCodeToName(c));
  return IUP_CONTINUE;
}

static int getfocus_cb(Ihandle *ih)
{
  printf("GETFOCUS_CB()\n");
  return IUP_DEFAULT;
}

static int help_cb(Ihandle* ih)
{
  printf("HELP_CB()\n");
  return IUP_DEFAULT;
}
     
static int killfocus_cb(Ihandle *ih)
{
  printf("KILLFOCUS_CB()\n");
  return IUP_DEFAULT;
}

static int leavewindow_cb(Ihandle *ih)
{
  printf("LEAVEWINDOW_CB()\n");
  return IUP_DEFAULT;
}

static int enterwindow_cb(Ihandle *ih)
{
  printf("ENTERWINDOW_CB()\n");
  return IUP_DEFAULT;
}

void ValTest(void)
{
  Ihandle *dlg, *val_h, *val_v;

  lbl_v = IupLabel("VALUE=");
  IupSetAttribute(lbl_v, "SIZE", "70x");

  lbl_h = IupLabel("VALUE=");
  IupSetAttribute(lbl_h, "SIZE", "70x");

  val_v = IupVal("VERTICAL");
  IupSetAttribute(val_v, "MAX", "10.0");
  IupSetAttribute(val_v, "STEP", ".02");
  IupSetAttribute(val_v, "PAGESTEP", ".2");
  IupSetAttribute(val_v, "SHOWTICKS", "5");
//  IupSetAttribute(val_v, "TICKSPOS", "REVERSE");
  IupSetCallback(val_v, "HELP_CB",      (Icallback)help_cb);
  IupSetCallback(val_v, "GETFOCUS_CB",  (Icallback)getfocus_cb); 
  IupSetCallback(val_v, "KILLFOCUS_CB", (Icallback)killfocus_cb);
  IupSetCallback(val_v, "ENTERWINDOW_CB", (Icallback)enterwindow_cb);
  IupSetCallback(val_v, "LEAVEWINDOW_CB", (Icallback)leavewindow_cb);
  IupSetCallback(val_v, "K_ANY", (Icallback)k_any);
//  IupSetAttribute(val_v, "INVERTED", "NO");
  IupSetAttribute(val_v, "EXPAND", "VERTICAL");

  val_h = IupVal("HORIZONTAL");
  IupSetAttribute(val_h, "MAX", "100.0");
//  IupSetAttribute(val_h, "SHOWTICKS", "10");
//  IupSetAttribute(val_h, "TICKSPOS", "BOTH");   /* Windows Only */
//  IupSetAttribute(val_h, "INVERTED", "YES");
  IupSetAttribute(val_h, "EXPAND", "HORIZONTAL");
  
  dlg = IupDialog
  (
    IupHbox
    (
      IupSetAttributes(IupHbox
      (
        val_v,
        lbl_v,
        NULL
      ), "ALIGNMENT=ACENTER"),
      IupSetAttributes(IupVbox
      (
        val_h,
        lbl_h,
        NULL
      ), "ALIGNMENT=ACENTER"),
      NULL
    )
  );

  IupSetCallback(val_v, "BUTTON_PRESS_CB",  (Icallback) button_press);
  IupSetCallback(val_v, "BUTTON_RELEASE_CB",  (Icallback) button_release);
  IupSetCallback(val_v, "MOUSEMOVE_CB", (Icallback) mousemove); 

  IupSetCallback(val_h, "BUTTON_PRESS_CB",  (Icallback) button_press);
  IupSetCallback(val_h, "BUTTON_RELEASE_CB",  (Icallback) button_release);
  IupSetCallback(val_h, "MOUSEMOVE_CB", (Icallback) mousemove); 

  IupSetAttribute(dlg, "TITLE", "IupVal Test");
//  IupSetAttribute(IupGetChild(dlg, 0), "BGCOLOR", "50 50 255");
//  IupSetAttribute(IupGetChild(dlg, 0), "ACTIVE", "NO");
  IupSetAttribute(dlg, "MARGIN", "10x10");
  IupShowXY(dlg,IUP_CENTER,IUP_CENTER);
}

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

  ValTest();

  IupMainLoop();

  IupClose();

  return EXIT_SUCCESS;
}
#endif