News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.

Post Reply  Post Thread 
Using callbacks to move objects on the screen
Author Message
Junior Member

Posts: 35
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
RE: Using callbacks to move objects on the screen

which allows to rewrite the code to be more generic:

ww=350 --window (width and height)
fw = ww-20 -- frame
fh = ww-20
dw = fw-10 -- drag and drop area
dh = fw-10
sw = 10 -- square width
square = {}
square_selected = {}

-- :Square object
-- Constucts a little square on the screen that can be drag and dropped within a given display area.
-- @param x the x position of the square
-- @param y the y position of the square
-- @param c the color of the square
function square_create(x,y,c)
  sq = fltk:Fl_Button(x,y,sw,sw);
  return sq

-- Callbacks
function crosshair_cb()
  x = crosshair:xvalue()
  y = crosshair:yvalue()
  -- The crosshair area needs to be larger than the drag area, otherwise, a box that is on the far
  -- right or far bottom of the screen cannot be moved anymore.
  out:value("X: ".. xpos .."  Y: ".. ypos)
  out2:value("X: ".. string.format("%.2f",x) .."  Y: ".. string.format("%.2f",y))
  -- out:value("X: "..crosshair:xvalue() * ww .."  Y: "..crosshair:yvalue() * wh)

function square_cb(self)
  square_selected = self

-- GUI / Interface

w=fltk:Fl_Window(ww,wh,"murgaLua Drag and Drop Demo")


display = fltk:Fl_Group(10,10,fw,fh)

  square[1] = square_create(15,15,80)
  square[2] = square_create(200,200,60)

  crosshair:selection_color(36) -- same color as frame background
  -- crosshair:selection_color(72)

-- outputs, display the x and y values during drag and drop

-- required as button 1 is active by default and clicking anywhere on the screen
-- other than one of the two buttons crashes the app.
square_selected = square[1]


This post was last modified: 06-03-2007 04:35 AM by widged.

06-03-2007 04:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
RE: Using callbacks to move objects on the screen - widged - 06-03-2007 04:26 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: