summaryrefslogtreecommitdiff
path: root/html/examples/cdtext.wlua
blob: 556d02f1eeb7623c5bbbcbc3b97c262ee981a13e (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
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()