jiayouxjh / grafx2

Automatically exported from code.google.com/p/grafx2
0 stars 0 forks source link

Lua binding for copying blocks in picture. #331

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1) Need bindings for drawing a line/rectangle/etc. Basically, everything
the user can do from the GUI should be also doable via lua scripts.

2) Should be able to create better script option menus, eg. with pull-down
menus and color selectors &c, not just the sliders.

Original issue reported on code.google.com by paxed%al...@gtempaccount.com on 23 Mar 2010 at 8:58

GoogleCodeExporter commented 9 years ago
for 1, I'm not sure how to do it, that's why it's not there yet.
Basically there are two ways : do you want to draw your shapes using the user 
brush, 
or the single pixel one ?

for 2, the inputbox is too limited for that already. Any idea on how to do it 
in a 
simple and efficient way ?

Original comment by pulkoma...@gmail.com on 23 Mar 2010 at 9:07

GoogleCodeExporter commented 9 years ago
1) If this is a serious demand, please give an example of what you would code if
these tools were available right now. Not "other people", no "maybes": Your 
actual need.
I suspect you actually want a macro recorder for future use, but in that case 
Lua
code is a very bad choice for storing the data (ex: When I draw freehand, Grafx2
records 400 coordinates per second. You don't want to see a function with 400 
arguments)

2) Lua isn't object-based, and doesn't allow custom data types. But it seems we 
can
use an auto-adapting syntax for describing the controls, something like:
new_inputbox(200, 100, "window_title",
  {type="label", x=12, y=21, text="Your choice"},
  {type="textbox", x=12, y=30, width=5, name="choice"},
  ....
)
Of course it will be very fun for the user to blindly design a window in text 
editor,
but hey, it's full customizable :)

Original comment by yrizoud on 23 Mar 2010 at 11:36

GoogleCodeExporter commented 9 years ago
I'd say it is possible to do something quite powerful using "userdata" type...

Also, that's how we designed all the windows in grafx2 and it worked quite fine 
:)

Original comment by pulkoma...@gmail.com on 24 Mar 2010 at 7:23

GoogleCodeExporter commented 9 years ago
Well, for now I'd be happy with just drawline(x1,y1,x2,y2,color) so that I 
wouldn't
need to implement that in lua. I tried doing it myself, but apparently
Draw_line_permanent() isn't the correct C function to use; it doesn't draw 
outside
the viewed area.

I was going to make a script to create hex grid, and that's easiest when you 
can draw
lines...

Original comment by paxed%al...@gtempaccount.com on 24 Mar 2010 at 7:36

GoogleCodeExporter commented 9 years ago
I agree for the drawline(). No brush, no effects, just plain pasting pixels from
point A to point B. The only clipping will be at image edges.
To get you going, I attach here a Lua implementation of a drawline() that you 
can use
in your script : I tested in Grafx2, it works. It uses putpicturepixel() to 
paste
pixels, and this one already performs clipping, so you can safely go outside of 
image
(ex: negative coordinates).
It's slightly slower than what we can do in C, but the result should be 
identical.

Original comment by yrizoud on 24 Mar 2010 at 2:02

Attachments:

GoogleCodeExporter commented 9 years ago
This could work too, a bit shorter...only tested it quickly, plz report any 
bugs.

function line(x1,y1,x2,y2,c)
 local n,st,m; m = math;
 st = m.max(1,m.abs(x2-x1),m.abs(y2-y1));
 for n = 0, st, 1 do
   putpicturepixel(m.floor(x1+n*(x2-x1)/st), m.floor(y1+n*(y2-y1)/st), c);
 end
end

Original comment by annas...@hotmail.com on 24 Mar 2010 at 6:28

GoogleCodeExporter commented 9 years ago

Original comment by pulkoma...@gmail.com on 9 Aug 2010 at 9:35

GoogleCodeExporter commented 9 years ago

Original comment by pulkoma...@gmail.com on 22 Aug 2010 at 1:40

GoogleCodeExporter commented 9 years ago

Original comment by pulkoma...@gmail.com on 20 Jan 2011 at 8:56

GoogleCodeExporter commented 9 years ago
Another idea :
It may be nice to have a lua script to run each time you finish a drawing 
operation (end_of_operation, or where the backup is done). This would for 
example allow to develop a constraint checker that runs on every drawing op and 
avoids doing it by hand. Of cours it should be possible to register/unregister 
the bindings easily, like regular FXs.

Original comment by pulkoma...@gmail.com on 9 Feb 2011 at 9:46

GoogleCodeExporter commented 9 years ago
Line, filled circle, circle and filled rect done.
Still missing is block copy. I need to think more to get something that works 
for brush<>picture<>spare, and not too much functions. 

Original comment by pulkoma...@gmail.com on 19 Feb 2011 at 12:45

GoogleCodeExporter commented 9 years ago
Lua version of copying blocks to spare done in Tiler.lua. Seems fast enough for 
my test case, but, it was a small picture.
If it becomes a problem, we'll reconsider accelerating it in C. Closing for now.

Original comment by pulkoma...@gmail.com on 24 Sep 2011 at 11:42