Hi.
More visual example in attach.
w/o debug printing.
On mouse click it draw 4 lines (from left to right):
1. emulated line (via cd.Pixel)
2. emulated line, then XOR cd.Line
3. cd.Line, then XOR emulated line
4. cd.Line in GUI-selected WriteMode
For xored lines: WHITE fill BLACK xor CYAN = RED overlaps, BLACK
underlaps -)
Emulated line always as CAPFLAT.
Looks like that 1 missed pixel at the top - is center for square in
CAPSQUARE and, also, is center for half-circle for CAPROUND.
Missed pixels at bottom - also missed in CAPSQUARE. But in CAPROUND - ok.
Same bugs for horisontal lines. (not realised in this example)
--
Regards,
Karagy.
require "cdlua"
require "iuplua"
require "iupluacd"
local cnv = iup.canvas {
rastersize = "80x80",
expand = "NO",
--border = "NO",
-- user-defined attrs
line_width = 1,
line_tpad = 4,
line_bpad = 4,
write_mode = cd.XOR,
line_join = cd.MITER,
line_cap = cd.CAPFLAT,
line_color = cd.EncodeColor(0, 255, 255),
}
function cnv:map_cb()
self.canvas = cd.CreateCanvas(cd.IUP, self)
end
function cnv:emulate_vline(x, y1, y2, w, mode, color)
local c = self.canvas
local dx_l = math.modf(w/2)
local dx_r = math.modf((w-1)/2)
c:WriteMode(mode)
for _x = x-dx_l, x+dx_r do
for _y=y1,y2 do
c:Pixel(_x, _y, color)
end
end
end
function cnv:cd_vline(x, y1, y2, mode, color)
local c = self.canvas
c:WriteMode(mode)
c:LineWidth(self.line_width)
c:Foreground(color)
c:LineJoin(self.line_join)
c:LineCap(self.line_cap)
c:Line(x,y1,x,y2)
end
-- draw vertical bar
function cnv:draw_vline(x)
local c = self.canvas
c:Activate()
c:Background(cd.WHITE)
c:Clear()
local w,h = c:GetSize()
local y1 = 0 + self.line_bpad
local y2 = h - 1 - self.line_tpad
-- emulated line via cd.Pixel only
local xx = x - 30
self:emulate_vline(xx, y1, y2, self.line_width, cd.REPLACE, cd.BLACK)
-- emulated line via cd.Pixel
local xx = x - 20
self:emulate_vline(xx, y1, y2, self.line_width, cd.REPLACE, cd.BLACK)
-- and XOR cd.Line over emulated line
self:cd_vline(xx, y1, y2, cd.XOR, cd.CYAN)
-- and back to front
-- FILL cd.Line
local xx = x - 10
self:cd_vline(xx, y1, y2, cd.REPLACE, cd.BLACK)
-- and xor emulated line over it
self:emulate_vline(xx, y1, y2, self.line_width, cd.XOR, cd.CYAN)
-- original
self:cd_vline(x, y1, y2, self.write_mode, cd.CYAN)
c:Deactivate()
end
function cnv:move_vline(x, y)
local w,h = self.canvas:GetSize()
if x >= 0 and x < w then
local _x = self.old_x or x
if _x ~= x then
self:draw_vline(_x)
_x = x
end
self:draw_vline(x)
self.old_x = _x
end
end
function cnv:button_cb(but, pressed, x, y, status)
if but == iup.BUTTON1
then
self.old_x = pressed == 1 and x
self:draw_vline(x)
end
end
function cnv:motion_cb(x, y, status)
if status:sub(3,3) == "1" then
self:move_vline(x)
end
end
local dlg = iup.dialog {
iup.frame{
iup.vbox{
margin = "2x2",
-- canvas
iup.hbox{
cnv,
iup.vbox{
margin = "0x0",
iup.frame{
title = "LineWidth",
iup.vbox{
margin = "10x",
iup.fill{},
iup.text{
visiblecolumns = 2,
spin = "YES",
spinmin = 1,
spin_cb = function (self, pos)
cnv.line_width = pos
end,
},
iup.fill{},
},
},
},
iup.vbox{
iup.frame{
title = "Top Pad",
iup.vbox{
margin = "10x",
iup.fill{},
iup.text{
visiblecolumns = 2,
spin = "YES",
spinmin = 0,
spinvalue = 4,
spin_cb = function (self, pos)
cnv.line_tpad = pos
end,
},
iup.fill{},
},
},
iup.frame{
title = "Bottom Pad",
iup.vbox{
margin = "10x",
iup.fill{},
iup.text{
visiblecolumns = 2,
spin = "YES",
spinmin = 0,
spinvalue = 4,
spin_cb = function (self, pos)
cnv.line_bpad = pos
end,
},
iup.fill{},
},
},
},
},
iup.hbox{
iup.frame{
title = "WriteMode",
iup.radio{
iup.vbox{
iup.toggle{
title="XOR",
action = function (self, state)
if state == 1 then
cnv.write_mode = cd.XOR
end
end,
},
iup.toggle{
title="REPLACE",
action = function (self, state)
if state == 1 then
cnv.write_mode = cd.REPLACE
end
end,
},
iup.fill{},
},
},
},
iup.frame{
title = "LineJoin",
iup.radio{
iup.vbox{
iup.toggle{
title="MITER",
action = function (self, state)
if state == 1 then
cnv.line_join = cd.MITER
end
end,
},
iup.toggle{
title="BEVEL",
action = function (self, state)
if state == 1 then
cnv.line_join = cd.BEVEL
end
end,
},
iup.toggle{
title="ROUND",
action = function (self, state)
if state == 1 then
cnv.line_join = cd.ROUND
end
end,
},
iup.fill{},
},
},
},
iup.frame{
title = "LineCap",
iup.radio{
iup.vbox{
iup.toggle{
title="CAPFLAT",
action = function (self, state)
if state == 1 then
cnv.line_cap = cd.CAPFLAT
end
end,
},
iup.toggle{
title="CAPSQUARE",
action = function (self, state)
if state == 1 then
cnv.line_cap = cd.CAPSQUARE
end
end,
},
iup.toggle{
title="CAPROUND",
action = function (self, state)
if state == 1 then
cnv.line_cap = cd.CAPROUND
end
end,
},
iup.fill{},
},
},
},
},
},
},
--size = "HALFx",
}
dlg:showxy(iup.CENTER, iup.CENTER)
iup.MainLoop()
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users