summaryrefslogtreecommitdiff
path: root/iup/srclua3/iuplua_pplot.c
blob: 588f20301b8c9a6abc0cef72239ff551f5144862 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <stdlib.h>

#include <lua.h>
#include <lauxlib.h>

#include "iup.h"
#include "iuplua.h"
#include "iup_pplot.h"

#include <cd.h>
#include <cdlua.h>

#include "il.h"


static int pplot_edit_cb(Ihandle *self, int p0, int p1, float p2, float p3, float *p4, float *p5)
{
  lua_Object obj;
  iuplua_call_start(self, "edit_cb");
  lua_pushnumber(p0);
  lua_pushnumber(p1);
  lua_pushnumber(p2);
  lua_pushnumber(p3);
  if (lua_call ("iupCallMethod"))
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  obj = lua_getresult (1);
  if (obj == LUA_NOOBJECT)
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  else if (lua_isnumber (obj))
  {
    int ret;
    *p4 = (float)lua_getnumber (obj);

    obj = lua_getresult (2);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_IGNORE;
    }
    *p5 = (float)lua_getnumber (obj);

    obj = lua_getresult (4);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_DEFAULT;
    }
    ret = (int)lua_getnumber (obj);
    lua_endblock ();
    return ret;
  }

  lua_endblock ();
  return IUP_IGNORE;
}

static int pplot_postdraw_cb(Ihandle *self, cdCanvas* cnv)
{
  iuplua_call_start(self, "postdraw_cb");
  cdlua_pushcanvas(cnv);
  return iuplua_call();
}

static int pplot_predraw_cb(Ihandle *self, cdCanvas* cnv)
{
  iuplua_call_start(self, "predraw_cb");
  cdlua_pushcanvas(cnv);
  return iuplua_call();
}

static int pplot_deleteend_cb(Ihandle *self)
{
  iuplua_call_start(self, "deleteend_cb");
  return iuplua_call();
}

static int pplot_selectbegin_cb(Ihandle *self)
{
  iuplua_call_start(self, "selectbegin_cb");
  return iuplua_call();
}

static int pplot_editend_cb(Ihandle *self)
{
  iuplua_call_start(self, "editend_cb");
  return iuplua_call();
}

static int pplot_editbegin_cb(Ihandle *self)
{
  iuplua_call_start(self, "editbegin_cb");
  return iuplua_call();
}

static int pplot_selectend_cb(Ihandle *self)
{
  iuplua_call_start(self, "selectend_cb");
  return iuplua_call();
}

static int pplot_select_cb(Ihandle *self, int p0, int p1, float p2, float p3, int p4)
{
  iuplua_call_start(self, "select_cb");
  lua_pushnumber(p0);
  lua_pushnumber(p1);
  lua_pushnumber(p2);
  lua_pushnumber(p3);
  lua_pushnumber(p4);
  return iuplua_call();
}

static int pplot_deletebegin_cb(Ihandle *self)
{
  iuplua_call_start(self, "deletebegin_cb");
  return iuplua_call();
}

static int pplot_delete_cb(Ihandle *self, int p0, int p1, float p2, float p3)
{
  iuplua_call_start(self, "delete_cb");
  lua_pushnumber(p0);
  lua_pushnumber(p1);
  lua_pushnumber(p2);
  lua_pushnumber(p3);
  return iuplua_call();
}

static void PPlot(void)
{
  int tag = (int)lua_getnumber(lua_getglobal("iuplua_tag"));
  lua_pushusertag(IupPPlot(), tag);
}

static void PPlotBegin(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotBegin(ih, luaL_check_int(2));
}

static void PPlotAdd(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotAdd(ih, (float)luaL_check_number(2), (float)luaL_check_number(3));
}

static void PPlotAddStr(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotAddStr(ih, luaL_check_string(2), (float)luaL_check_number(3));
}

static void PPlotEnd(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  int ret = IupPPlotEnd(ih);
  lua_pushnumber(ret);
}

static void PPlotInsertStr(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotInsertStr(ih, luaL_check_int(2), luaL_check_int(3), luaL_check_string(4), (float)luaL_check_number(5));
}

static void PPlotInsert(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotInsert(ih, luaL_check_int(2), luaL_check_int(3), (float)luaL_check_number(4), (float)luaL_check_number(5));
}

static void PPlotTransform(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  int ix, iy;
  IupPPlotTransform(ih, (float)luaL_check_number(2), (float)luaL_check_number(3), &ix, &iy);
  lua_pushnumber(ix);
  lua_pushnumber(iy);
}

static void PPlotPaintTo(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPPlotPaintTo(ih, cdlua_checkcanvas(2));
}

int iup_pplotlua_open(void)
{
  lua_register("iupCreatePPlot", PPlot);

  lua_register("iup_pplot_edit_cb", (lua_CFunction)pplot_edit_cb);
  lua_register("iup_pplot_deleteend_cb", (lua_CFunction)pplot_deleteend_cb);
  lua_register("iup_pplot_selectbegin_cb", (lua_CFunction)pplot_selectbegin_cb);
  lua_register("iup_pplot_postdraw_cb", (lua_CFunction)pplot_postdraw_cb);
  lua_register("iup_pplot_editend_cb", (lua_CFunction)pplot_editend_cb);
  lua_register("iup_pplot_editbegin_cb", (lua_CFunction)pplot_editbegin_cb);
  lua_register("iup_pplot_selectend_cb", (lua_CFunction)pplot_selectend_cb);
  lua_register("iup_pplot_select_cb", (lua_CFunction)pplot_select_cb);
  lua_register("iup_pplot_deletebegin_cb", (lua_CFunction)pplot_deletebegin_cb);
  lua_register("iup_pplot_predraw_cb", (lua_CFunction)pplot_predraw_cb);
  lua_register("iup_pplot_delete_cb", (lua_CFunction)pplot_delete_cb);

  iuplua_register("IupPPlotBegin", PPlotBegin);
  iuplua_register("IupPPlotAdd", PPlotAdd);
  iuplua_register("IupPPlotAddStr", PPlotAddStr);
  iuplua_register("IupPPlotEnd", PPlotEnd);
  iuplua_register("IupPPlotInsertStr", PPlotInsertStr);
  iuplua_register("IupPPlotInsert", PPlotInsert);
  iuplua_register("IupPPlotTransform", PPlotTransform);
  iuplua_register("IupPPlotPaintTo", PPlotPaintTo);

#ifdef IUPLUA_USELOH
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/pplot_be64.loh"
#else
#include "loh/pplot_be32.loh"
#endif
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/pplot_le64w.loh"
#else
#include "loh/pplot_le64.loh"
#endif
#else
#include "loh/pplot.loh"
#endif
#endif
#else
  iuplua_dofile("luapplot.lua");
#endif

  return 1;
}