summaryrefslogtreecommitdiff
path: root/html/examples
diff options
context:
space:
mode:
Diffstat (limited to 'html/examples')
-rw-r--r--html/examples/cdalign.wlua67
-rw-r--r--html/examples/cdtext.wlua59
-rw-r--r--html/examples/imagergb.wlua35
-rw-r--r--html/examples/iupcdaux.lua45
-rw-r--r--html/examples/iuplua_cdlua.wlua58
-rw-r--r--html/examples/rubberband.wlua54
6 files changed, 318 insertions, 0 deletions
diff --git a/html/examples/cdalign.wlua b/html/examples/cdalign.wlua
new file mode 100644
index 0000000..849d258
--- /dev/null
+++ b/html/examples/cdalign.wlua
@@ -0,0 +1,67 @@
+require("iupcdaux") -- utility module used in some samples
+
+dlg = iupcdaux.new_dialog(w, h)
+cnv = dlg[1] -- retrieve the IUP canvas
+
+function DrawText(canvas, x, y, text, align)
+ canvas:TextAlignment(align)
+ canvas:Mark(x, y)
+ canvas:Text(x, y, text)
+ xmin, xmax, ymin, ymax = canvas:GetTextBox(x, y, text)
+ canvas:Rect(xmin, xmax, ymin, ymax)
+end
+
+text_aligment = {
+ cd.NORTH,
+ cd.SOUTH,
+ cd.EAST,
+ cd.WEST,
+ cd.NORTH_EAST,
+ cd.NORTH_WEST,
+ cd.SOUTH_EAST,
+ cd.SOUTH_WEST,
+ cd.CENTER,
+ cd.BASE_LEFT,
+ cd.BASE_CENTER,
+ cd.BASE_RIGHT
+}
+
+text_aligment_str = {
+ "NORTH",
+ "SOUTH",
+ "EAST",
+ "WEST",
+ "NORTH EAST",
+ "NORTH WEST",
+ "SOUTH EAST",
+ "SOUTH WEST",
+ "CENTER",
+ "BASE LEFT",
+ "BASE CENTER",
+ "BASE RIGHT"
+}
+
+
+-- custom function used in action callback
+-- from the iupcdaux module
+function cnv:Draw(canvas)
+ canvas:MarkSize(40)
+ canvas:Font("Courier", cd.PLAIN, 12)
+
+ i = 1
+ while (i <= 12) do
+ DrawText(canvas, 100, 35*i + 30, text_aligment_str[i], text_aligment[i])
+ i = i + 1
+ end
+end
+
+
+--tmpCanvas = cd.CreateCanvas(cd.PS, "cdalign.ps")
+--tmpCanvas:Clear()
+--cnv:Draw(tmpCanvas)
+--tmpCanvas:Kill()
+
+
+dlg:show()
+iup.MainLoop()
+
diff --git a/html/examples/cdtext.wlua b/html/examples/cdtext.wlua
new file mode 100644
index 0000000..556d02f
--- /dev/null
+++ b/html/examples/cdtext.wlua
@@ -0,0 +1,59 @@
+require("iupcdaux") -- utility module used in some samples
+
+--require"cdluacontextplus"
+--cd.UseContextPlus(1)
+
+dlg = iupcdaux.new_dialog(w, h)
+cnv = dlg[1] -- retrieve the IUP canvas
+
+function DrawTextBox(canvas, x, y, text)
+ canvas:Mark(x, y)
+ canvas:Text(x, y, text)
+ w, h = canvas:GetTextSize(text)
+ xmin = x - w/2
+ ymin = y - h/2
+ xmax = x + w/2
+ ymax = y + h/2
+ canvas:Line(xmin, ymin, xmax, ymin)
+ canvas:Line(xmin, ymin, xmin, ymax)
+ canvas:Line(xmin, ymax, xmax, ymax)
+ canvas:Line(xmax, ymin, xmax, ymax)
+end
+
+-- custom function used in action callback
+-- from the iupcdaux module
+function cnv:Draw(canvas)
+
+ -- Available in ContextPlus drivers or in IMAGERGB driver
+ -- canvas:SetAttribute("ANTIALIAS", "1")
+
+ canvas:TextAlignment(cd.CENTER)
+ canvas:MarkSize(40)
+
+ canvas:Font("Courier", cd.PLAIN, 12)
+ local aa = canvas:GetAttribute("ANTIALIAS")
+ if (aa == "1") then
+ DrawTextBox(canvas, 130, 30, "ANTIALIAS=1")
+ else
+ DrawTextBox(canvas, 130, 30, "ANTIALIAS=0")
+ end
+
+ canvas:Font("Courier", cd.ITALIC, 34)
+ DrawTextBox(canvas, 130, 160, "xxxxxppx")
+
+ canvas:Font("Times", cd.PLAIN, 12)
+ DrawTextBox(canvas, 130, 290, "taaaa")
+
+ canvas:Font("Times", cd.BOLD, 14)
+ DrawTextBox(canvas, 130, 370, "gggggggg")
+end
+
+
+--tmpCanvas = cd.CreateCanvas(cd.PS, "cdtext.ps")
+--tmpCanvas:Clear()
+--cnv:Draw(tmpCanvas)
+--tmpCanvas:Kill()
+
+
+dlg:show()
+iup.MainLoop()
diff --git a/html/examples/imagergb.wlua b/html/examples/imagergb.wlua
new file mode 100644
index 0000000..b7c6f11
--- /dev/null
+++ b/html/examples/imagergb.wlua
@@ -0,0 +1,35 @@
+require("iupcdaux") -- utility module used in some samples
+
+w = 100
+h = 100
+
+image_rgb = cd.CreateImageRGB(w, h)
+
+size = w * h
+i = 0
+while i < size do
+
+ if i < size/2 then
+ image_rgb.r[i] = 255
+ image_rgb.g[i] = 0
+ image_rgb.b[i] = 0
+ else
+ image_rgb.r[i] = 0
+ image_rgb.g[i] = 0
+ image_rgb.b[i] = 255
+ end
+
+ i = i + 1
+end
+
+dlg = iupcdaux.new_dialog(w, h)
+cnv = dlg[1] -- retrieve the IUP canvas
+
+-- custom function used in action callback
+-- from the iupcdaux module
+function cnv:Draw(canvas)
+ canvas:PutImageRectRGB(image_rgb, 0, 0, w, h, 0, 0, 0, 0)
+end
+
+dlg:show()
+iup.MainLoop()
diff --git a/html/examples/iupcdaux.lua b/html/examples/iupcdaux.lua
new file mode 100644
index 0000000..18ae23c
--- /dev/null
+++ b/html/examples/iupcdaux.lua
@@ -0,0 +1,45 @@
+require"cdlua"
+require"iuplua"
+require"iupluacd"
+
+iupcdaux = {}
+iupcdaux.count = 0
+
+-- Function to easy create a new IUP dialog with an IUP canvas,
+-- and a CD canvas pointing to that IUP canvas
+
+function iupcdaux.new_dialog(w, h)
+
+ -- defaul size
+ w = w or 300
+ h = h or 200
+
+ cnv = iup.canvas { bgcolor="255 255 255", rastersize=w.."x"..h }
+ dlg = iup.dialog { cnv; title="canvas_"..(iupcdaux.count+1) }
+
+ function cnv:map_cb()
+ canvas = cd.CreateCanvas(cd.IUP, self)
+ self.canvas = canvas -- store the CD canvas in a IUP attribute
+ end
+
+ function cnv:action()
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+ canvas:Activate()
+ canvas:Clear()
+
+ if (self.Draw) then
+ self:Draw(canvas)
+ end
+ end
+
+ function dlg:close_cb()
+ cnv = self[1]
+ canvas = cnv.canvas -- retrieve the CD canvas from the IUP attribute
+ canvas:Kill()
+ self:destroy()
+ return iup.IGNORE -- because we destroy the dialog
+ end
+
+ iupcdaux.count = iupcdaux.count + 1
+ return dlg
+end
diff --git a/html/examples/iuplua_cdlua.wlua b/html/examples/iuplua_cdlua.wlua
new file mode 100644
index 0000000..5528117
--- /dev/null
+++ b/html/examples/iuplua_cdlua.wlua
@@ -0,0 +1,58 @@
+require"cdlua"
+require"iuplua"
+require"iupluacd"
+
+cnv = iup.canvas {size = "200x100"}
+
+box = iup.vbox{
+ iup.button { title="Version" },
+ cnv,
+ iup.button { title="Close" },
+ }
+
+dlg = iup.dialog{box; title="Example IUPLUA/CDLUA"}
+
+function cnv:map_cb()
+ canvas = cd.CreateCanvas(cd.IUP, self)
+ self.canvas = canvas -- store the CD canvas in a IUP attribute
+end
+
+function dlg:close_cb()
+ cnv = self[1][2]
+ canvas = cnv.canvas -- retrieve the CD canvas from the IUP attribute
+ canvas:Kill()
+ self:destroy()
+ return iup.IGNORE -- because we destroy the dialog
+end
+
+bt_version = dlg[1][1]
+function bt_version:action()
+ iup.Message("Version", "CD Version: " .. cd.Version() .. "\nIUP Version: " .. iup.Version() .. "\n" .. _VERSION)
+end
+
+bt_close = dlg[1][3]
+function bt_close:action()
+ return iup.CLOSE
+end
+
+function cnv:action()
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+
+ canvas:Activate()
+ canvas:Clear()
+ canvas:Foreground (cd.RED)
+ canvas:Box (10, 55, 10, 55)
+ canvas:Foreground(cd.EncodeColor(255, 32, 140))
+ canvas:Line(0, 0, 300, 100)
+end
+
+function cnv:button_cb(b, e, x, y, r)
+ print ("Button: " .. "Button="..tostring(b).." Pressed="..tostring(e).." X="..tostring(x).." Y="..tostring(y) )
+end
+
+function cnv:resize_cb(w, h)
+ print("Resize: Width="..w.." Height="..h)
+end
+
+dlg:show()
+iup.MainLoop()
diff --git a/html/examples/rubberband.wlua b/html/examples/rubberband.wlua
new file mode 100644
index 0000000..595373a
--- /dev/null
+++ b/html/examples/rubberband.wlua
@@ -0,0 +1,54 @@
+require("iupcdaux") -- utility module used in some samples
+
+dlg = iupcdaux.new_dialog(w, h)
+cnv = dlg[1] -- retrieve the IUP canvas
+
+
+function cnv:button_cb(button,pressed,x,y,r)
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+
+ -- start drag if button1 is pressed
+ if button ==iup.BUTTON1 and pressed == 1 then
+ y = canvas:UpdateYAxis(y)
+
+ -- prepare for XOR
+ canvas:Foreground(cd.WHITE)
+ canvas:WriteMode(cd.XOR)
+
+ xstart = x
+ ystart = y
+ drag = 1
+ first = 1
+ else
+ if (drag == 1) then
+ drag = 0
+ canvas:Rect(xstart,xend,ystart,yend)
+ end
+ end
+end
+
+
+function cnv:motion_cb(x,y,r)
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+
+ if (drag == 1) then
+ y = canvas:UpdateYAxis(y)
+
+ if (first == 1) then
+ first = 0
+ else
+ canvas:Rect(xstart,xend,ystart,yend)
+ end
+
+ canvas:Rect(xstart,x,ystart,y)
+
+ xend = x
+ yend = y
+ end
+end
+
+first = 1
+drag = 0
+
+dlg:show()
+iup.MainLoop()