using Red
function blabla(bla)
println(redTypeOf(bla))
return redUnset()
end
cf = cfunction(blabla, Ptr{Void}, (Ptr{Void},));
redOpen()
redRoutine(redWord("blabla"), "[]", cf);
cmd = "view [backdrop yellow t: text yellow {Hello World!}
button {Click} [blabla t]
]"
redDo(cmd)"[]", while you are trying to pass one. That will result in random values on stack.blabla function, just declare a proper type in the routine, like: "[obj [object!]]". Though we don't have direct accessors on objects yet exposed in libRed (I should add them asap).using Red
function blabla()
face_text = redPath(redWord("t"), redWord("text"))
println(redCString(redGetPath(face_text)))
return redUnset()
end
cf = cfunction(blabla, Ptr{Void}, (Ptr{Void},));
redOpen()
redRoutine(redWord("blabla"), "[]", cf);
cmd = "view [backdrop yellow t: text yellow {Hello World!}
button {Click} [blabla]
]"
redDo(cmd){obj [oject!]] bit was crucial. This works using Red
function blabla(t)
face_text = redPath(redWord("t"), redWord("text"))
println(unsafe_string(redCString(redGetPath(face_text))))
return redUnset()
end
cf = cfunction(blabla, Ptr{Void}, (Ptr{Void},));
redOpen()
redRoutine(redWord("blabla"), "[obj [object!]]", cf);
cmd = "view [backdrop yellow t: text yellow {Hello World!}
button {Click} [blabla t]
]"
redDo(cmd)`tests of the Red.jl repo. It works like the C version.redGetPath, why the redSetPath is ignored?function blabla(t)
face_text = redPath(redWord("t"), redWord("text"))
println(unsafe_string(redCString(redGetPath(face_text))))
redSetPath(face_text, redWord("BlaBla"))
println(unsafe_string(redCString(redGetPath(face_text))))
id = redSymbol("text");
redSetField(t, id, redWord("BlaBla"))
redProbe(redGetField(t, id));
return redUnset()
end
Hello World!
Hello World!
make error! [
code: none
type: 'script
id: 'invalid-path
arg1: none
arg2: 'text
arg3: none
near: none
where: 'redGetField
stack: 419201976
]`t/text field to a string value, so you need to pass redString("BlaBla") and not redWord("BlaBla").redGetField error, I'm investigating it...redWordcalls by redString).Red.jl repository.red.jl.using Red
function blabla(t, b)
id = redSymbol("text");
redSetField(t, id, redString("BlaBla"))
redProbe(redGetField(t, id));
id = redSymbol("size");
redSetField(t, id, redPair(160, 48))
redProbe(redGetField(t, id));
id = redSymbol("offset");
redSetField(t, id, redPair(20, 20))
redProbe(redGetField(t, id));
return redUnset()
end
cf = cfunction(blabla, Ptr{Void}, (Ptr{Void},Ptr{Void}));
redOpen()
redRoutine(redWord("blabla"), "[obj [object!] obj [object!]]", cf);
cmd = "view [backdrop yellow t: text yellow {Hello World!}
b: button {Click} [blabla t b]
]"
redDo(cmd)
it correctly prints
"BlaBla" 160x48 20x20
but the problem is that there are now two fields with the same name. One for the text t and the other for b button handle.
(from red console)
>> t
== make object! [
type: 'text
offset: 10x10
size: 80x24
text: "Hello World!"
...
>> b
== make object! [
type: 'button
offset: 99x9
size: 62x25
text: "Click"
imag...
and apparently only first one is caught. And notice that trying id = redSymbol("b/text");` didn't make any difference.redPrint(redRoutine(redWord("blabla"), "[obj [object!] obj [object!]]", cf))*** Script Error: duplicate variable specified: obj *** Where: redRoutine *** Stack:
"[obj1 [object!] obj2 [object!]]"t and b objects?id = redSymbol("t/text"); errors withmake error! [
code: none
type: 'script
id: 'invalid-path
arg1: none
arg2: 't/text
arg3: none
near: none
where: 'redGetField
stack: 410289092
]`t/text is not a symbol, it's a path.id = redSymbol("text")
redProbe(redGetField(t, id))
redProbe(redGetField(b, id))workspace() command and it will clear all variables and reset the state ... but just confirmed it's not enough. By running from the dos cmd I get an error, but a different one (perhaps because my version is older than yours)*** Script Error: blabla has no value *** Where: act *** Stack: view do-events do-actor do-safe`
workspace(): good to know. redRoutine fails and I click on the button.julia> redCString(C_NULL) *** Runtime Error 1: access violation *** at: 564C0D59h`
image command. In particular the part that refers to image(x,y,C).image(x,y,C) is about image placement, which is a trivial thing to accomplish in Red/View (either set the image face position, or use [Draw dialect](https://doc.red-lang.org/en/draw.html#_image) to paint, position and resize the image).view [ size 200x200 b: base transparent draw [pen red fill-pen pink circle 20x20 4] on-menu [print switch event/picked [act1 ["Hello"] act2 ["World!"]]] do [b/menu: ["Action 1" act1 "Action 2" act2]] ]
uicontextmenu in Matlab, so clearly the same concept).using Red
redOpen()
img = rand(UInt32, 400,400);
redSet(redSymbol("img"), redImage(400, 400, img, 0));
redDo("view/flags [size 500x500 image img] 'resize");`draw right now.view [base 200x200 draw [image i 0x0 200x200]]
0x0 for?0x0 is. And, sorry, I'm being dumb ask questions for which I already got an [answer](https://github.com/red/code/blob/master/Scripts/resize-image.red) (but before asking).'fit on a face and have any image in it automatically resized.image 200x200 img should work fine.line p1 p2 thousands of times seams out of question, and furthermore I also have not thought/tried on how to append to an existing figure.Red.jl repo.polygon](https://doc.red-lang.org/en/draw.html#_polygon)?lines because that's the Red command to create lines. Polygon is not a solution because it's a closed entity. What is missing is here is a 'polyline', which is like a polygon but not closed. line so we have an idea of where we *need* polyline.Line may not be as efficient or elegant, but it can work. Asking about draw testing in red/red or red/gui-branch would be good, as someone may have profiling tools or ideas already. I just generated draw blocks with a lot of line commands and timed showing the window.draw commands relatively quickly? Then we'd have some real numbers and test cases.polyline as line accepts any number of points:view layout [base 400x400 draw [line 0x0 200x200 400x0 100x100 0x400]]
line should be fast-enough for most use-cases, when providing a list of points (instead of just two). If there is no dynamic changes required, I strongly suggest drawing onto an image! and displaying that image.