Old 05-30-2015, 03:38 AM   #1
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default Lua: GUI/graphics related stuff

I'm going to collect all my Lua GUI/gfx related code here.


Here's an empty template + mouse handling code (it's a little modified Schwa's GUI example):

Empty GUI template (30may15)
Code:
-- Empty GUI template

function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end


-----------------
-- Mouse table --
-----------------

local mouse = {  
                  -- Constants
                  LB = 1,
                  RB = 2,
                  CTRL = 4,
                  SHIFT = 8,
                  ALT = 16,
                  
                  -- "cap" function
                  cap = function (mask)
                          if mask == nil then
                            return gfx.mouse_cap end
                          return gfx.mouse_cap&mask == mask
                        end,
                  
                  -- Returns true if LMB down, else false
                  lb_down = function() return gfx.mouse_cap&1 == 1 end,
                  
                  -- Returns true if RMB down, else false
                  rb_down = function() return gfx.mouse_cap&2 == 2 end,
       
                  uptime = 0,
                  
                  last_x = -1, last_y = -1,
                  
                  -- Updated when LMB/RMB down and mouse is moving.
                  -- Both values are set to 0 when LMB/RMB is released
                  dx = 0, 
                  dy = 0,
                  
                  ox = 0, oy = 0,    -- left/right click coordinates
                  cap_count = 0,
                  
                  last_LMB_state = false,
                  last_RMB_state = false
               }
          
---------------------------------------------------------------------------




----------------------------------
-- Mouse event handling         --
-- (from Schwa's GUI example)   --
----------------------------------

function OnMouseDown(x, y, lmb_down, rmb_down)
  -- LMB clicked
  if not rmb_down and lmb_down and mouse.last_LMB_state == false then
    mouse.last_LMB_state = true
  end
  -- RMB clicked
  if not lmb_down and rmb_down and mouse.last_RMB_state == false then
    mouse.last_RMB_state = true
  end
  mouse.ox, mouse.oy = x, y -- mouse click coordinates
  mouse.cap_count = 0       -- reset mouse capture count
end


function OnMouseUp(x, y, lmb_down, rmb_down)
  -- handle "mouse button up" here
  mouse.uptime = os.clock()
  mouse.dx = 0
  mouse.dy = 0
  -- left mouse button was released
  if not lmb_down and mouse.last_LMB_state then mouse.last_LMB_state = false end
  -- right mouse button was released
  if not rmb_down and mouse.last_RMB_state then mouse.last_RMB_state = false end
end


function OnMouseDoubleClick(x, y)
  -- handle mouse double click here
end


function OnMouseMove(x, y)
  -- handle mouse move here, use mouse.down and mouse.capcnt
  mouse.last_x, mouse.last_y = x, y
  mouse.dx = gfx.mouse_x - mouse.ox
  mouse.dy = gfx.mouse_y - mouse.oy
  mouse.cap_count = mouse.cap_count + 1
end



-------------------------------------------------------------------------------------------


----------
-- Init --
----------

-- GUI table ----------------------------------------------------------------------------------
--   contains GUI related settings (some basic user definable settings), initial values etc. --
-----------------------------------------------------------------------------------------------
local gui = {}

function init()
  
  -- Add stuff to "gui" table
  gui.settings = {}                 -- Add "settings" table to "gui" table 
  gui.settings.font_size = 20       -- font size
  gui.settings.docker_id = 0        -- try 0, 1, 257, 513, 1027 etc.
  
  ---------------------------
  -- Initialize gfx window --
  ---------------------------
  
  gfx.init("", 200, 200, gui.settings.docker_id)
  gfx.setfont(1,"Arial", gui.settings.font_size)
  gfx.clear = 3355443  -- matches with "FUSION: Pro&Clean Theme :: BETA 01" http://forum.cockos.com/showthread.php?t=155329
  -- (Double click in ReaScript IDE to open the link)

  mainloop()
end


--------------
-- Mainloop --
--------------

function mainloop()
  local LB_DOWN = mouse.lb_down()           -- current left mouse button state is stored to "LB_DOWN"
  local RB_DOWN = mouse.rb_down()           -- current right mouse button state is stored to "RB_DOWN"
  local mx, my = gfx.mouse_x, gfx.mouse_y   -- current mouse coordinates are stored to "mx" and "my"
  
  -- (modded Schwa's GUI example)
  if (LB_DOWN and not RB_DOWN) or (RB_DOWN and not LB_DOWN) then   -- LMB or RMB pressed down?
    if (mouse.last_LMB_state == false and not RB_DOWN) or (mouse.last_RMB_state == false and not LB_DOWN) then
      OnMouseDown(mx, my, LB_DOWN, RB_DOWN)
      if mouse.uptime and os.clock() - mouse.uptime < 0.20 then
        OnMouseDoubleClick(mx, my)
      end
    elseif mx ~= mouse.last_x or my ~= mouse.last_y then
      OnMouseMove(mx, my)
    end
      
  elseif not LB_DOWN and mouse.last_RMB_state or not RB_DOWN and mouse.last_LMB_state then
    OnMouseUp(mx, my, LB_DOWN, RB_DOWN)
  end

  --------------
  -- Draw GUI --
  --------------
  
  gfx.x = 10
  gfx.y = 10
  gfx.printf("GUI template")
 
  gfx.update()
  if gfx.getchar() >= 0 then reaper.defer(mainloop) end
end

init()
spk77 is offline   Reply With Quote
Old 05-30-2015, 03:43 AM   #2
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default Show values from mouse table

Example:

Show values/variables from "mouse" table (using the template)

Code:
function msg(m)
  return reaper.ShowConsoleMsg(tostring(m) .. "\n")
end


-----------------
-- Mouse table --
-----------------

local mouse = {  
                  -- Constants
                  LB = 1,
                  RB = 2,
                  CTRL = 4,
                  SHIFT = 8,
                  ALT = 16,
                  
                  -- "cap" function
                  cap = function (mask)
                          if mask == nil then
                            return gfx.mouse_cap end
                          return gfx.mouse_cap&mask == mask
                        end,
                  
                  -- Returns true if LMB down, else false
                  lb_down = function() return gfx.mouse_cap&1 == 1 end,
                  
                  -- Returns true if RMB down, else false
                  rb_down = function() return gfx.mouse_cap&2 == 2 end,
       
                  uptime = 0,
                  
                  last_x = -1, last_y = -1,
                  
                  -- Updated when LMB/RMB down and mouse is moving.
                  -- Both values are set to 0 when LMB/RMB is released
                  dx = 0, 
                  dy = 0,
                  
                  ox = 0, oy = 0,    -- left/right click coordinates
                  cap_count = 0,
                  
                  last_LMB_state = false,
                  last_RMB_state = false
               }
          
---------------------------------------------------------------------------




----------------------------------
-- Mouse event handling         --
-- (from Schwa's GUI example)   --
----------------------------------

function OnMouseDown(x, y, lmb_down, rmb_down)
  -- LMB clicked
  if not rmb_down and lmb_down and mouse.last_LMB_state == false then
    mouse.last_LMB_state = true
  end
  -- RMB clicked
  if not lmb_down and rmb_down and mouse.last_RMB_state == false then
    mouse.last_RMB_state = true
  end
  mouse.ox, mouse.oy = x, y -- mouse click coordinates
  mouse.cap_count = 0       -- reset mouse capture count
end


function OnMouseUp(x, y, lmb_down, rmb_down)
  mouse.uptime = os.clock()
  mouse.dx = 0
  mouse.dy = 0
  if not lmb_down and mouse.last_LMB_state then mouse.last_LMB_state = false end
  if not rmb_down and mouse.last_RMB_state then mouse.last_RMB_state = false end
end


function OnMouseDoubleClick(x, y)
  -- handle mouse double click here
end


function OnMouseMove(x, y)
  -- handle mouse move here, use mouse.down and mouse.capcnt
  mouse.last_x, mouse.last_y = x, y
  mouse.dx = gfx.mouse_x - mouse.ox
  mouse.dy = gfx.mouse_y - mouse.oy
  mouse.cap_count = mouse.cap_count + 1
end


--------------------------------------
--Functions related to this example --
--------------------------------------

-- Draw values from "mouse table"
function draw_sorted_table(orig_table, sorted_table)
  local st = sorted_table
  local t = orig_table
  gfx.printf("Constants (red color = currently pressed)")
  gfx.y = gfx.y + gfx.texth
  gfx.x = 10
  
  for i,n in ipairs(st) do
    gfx.set(0.8,0.8,0.8,0.8)
    if type(t[st[i]]) ~= "function" then
      if i < 6 then
        gfx.x = 20 --end
        if mouse.cap(t[st[i]]) then -- get currently pressed btn/modifier
          gfx.set(0.8,0.1,0.1,1)    -- set red color
        end
      end
      gfx.printf("mouse."..tostring(n)..":\t  ") -- print key
      --end
      gfx.set(0.8,1,1,1)
      gfx.printf(tostring(t[st[i]])) -- print value
      gfx.x = 10
     
      -- add vertical spaces
      if i == 5 or i == 7 or i == 9 or i == 11 or i == 13 or i == 16 then
        gfx.y = gfx.y + gfx.texth
      end
      -- move to next line
      gfx.y = gfx.y + gfx.texth
    end
  end
  
end


-- Sort table alphabetically
function sorted_table(t)
  local st = {} -- sorted table
  for n in pairs(t) do 
    st[#st+1] = n
  end
  table.sort(st)
  return st
end


-- create a sorted array (= "mouse table keys" are sorted alphabetically and put to an array)
local sorted_mouse_t = sorted_table(mouse) -- call sorted_table function -> store to "sorted_mouse_t"


-- GUI drawing function
function draw_gui()
  gfx.x = 10
  gfx.y = 10
  
  -- Draw mouse coordinates
  gfx.printf("X: " .. tostring(gfx.mouse_x))
  gfx.y = gfx.y + gfx.texth
  gfx.x = 10
  gfx.printf("Y: " .. tostring(gfx.mouse_y))
  gfx.y = gfx.y + 2*gfx.texth
    
  -- Draw mouse table keys and values
  gfx.x = 10
  draw_sorted_table(mouse, sorted_mouse_t)
  
  -- Draw "docked state"
  gfx.x = 200
  gfx.y = 10
  gfx.printf("Docked state: " .. tostring(gfx.dock(-1)))
end



-------------------------------------------------------------------------------------------


----------
-- Init --
----------

-- GUI table --------------------------------------------
--   contains GUI related settings (some basic user definable settings), initial values etc.
---------------------------------------------------------
local gui = {}

function init()
  
  -- Add stuff to "gui" table
  gui.settings = {}                 -- Add "settings" table to "gui" table 
  gui.settings.font_size = 20       -- font size
  gui.settings.docker_id = 0        -- try 0, 1, 257, 513, 1027 etc.
  
  ---------------------------
  -- Initialize gfx window --
  ---------------------------
  
  gfx.init("", 380, 500, gui.settings.docker_id)
  gfx.setfont(1,"Arial", gui.settings.font_size)
  gfx.clear = 3355443  -- matches with "FUSION: Pro&Clean Theme :: BETA 01" http://forum.cockos.com/showthread.php?t=155329
  -- (Double click in ReaScript IDE to open the link)

  mainloop()
end


--------------
-- Mainloop --
--------------

function mainloop()
  local LB_DOWN = mouse.lb_down()           -- Get current left mouse button state
  local RB_DOWN = mouse.rb_down()           -- Get current right mouse button state
  local mx, my = gfx.mouse_x, gfx.mouse_y
  
  -- (modded Schwa's GUI example)
  if (LB_DOWN and not RB_DOWN) or (RB_DOWN and not LB_DOWN) then   -- LMB or RMB pressed down?
    if (mouse.last_LMB_state == false and not RB_DOWN) or (mouse.last_RMB_state == false and not LB_DOWN) then
      OnMouseDown(mx, my, LB_DOWN, RB_DOWN)
      if mouse.uptime and os.clock() - mouse.uptime < 0.20 then
        OnMouseDoubleClick(mx, my)
      end
    elseif mx ~= mouse.last_x or my ~= mouse.last_y then
      OnMouseMove(mx, my)
    end
      
  elseif not LB_DOWN and mouse.last_RMB_state or not RB_DOWN and mouse.last_LMB_state then
    OnMouseUp(mx, my, LB_DOWN, RB_DOWN)
  end

  --------------
  -- Draw GUI --
  --------------

  draw_gui()
 
  gfx.update()
  if gfx.getchar() >= 0 then reaper.defer(mainloop) end
end

init()
spk77 is offline   Reply With Quote
Old 05-30-2015, 05:05 AM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,045
Default

I don't think we can imagine mouse related scripts more complete than those :P

Thanks for sharing !
X-Raym is offline   Reply With Quote
Old 07-21-2015, 11:19 AM   #4
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default Menu class + example

Quote:
Originally Posted by X-Raym View Post
I don't think we can imagine mouse related scripts more complete than those :P

Thanks for sharing !
Thanks!

I've been working on a "Menu class". This is what I've done so far:

Code:
function msg(m)
  reaper.ShowConsoleMsg(tostring(m) .. "\n")
end

---------------
-- class.lua --
---------------

------------- "class.lua" is copied from http://lua-users.org/wiki/SimpleLuaClasses -----------

-- class.lua
-- Compatible with Lua 5.1 (not 5.0).
function class(base, init)
   local c = {}    -- a new class instance
   if not init and type(base) == 'function' then
      init = base
      base = nil
   elseif type(base) == 'table' then
    -- our new class is a shallow copy of the base class!
      for i,v in pairs(base) do
         c[i] = v
      end
      c._base = base
   end
   -- the class will be the metatable for all its objects,
   -- and they will look up their methods in it.
   c.__index = c

   -- expose a constructor which can be called by <classname>(<args>)
   local mt = {}
   mt.__call = function(class_tbl, ...)
   local obj = {}
   setmetatable(obj,c)
   if init then
      init(obj,...)
   else 
      -- make sure that any stuff from the base class is initialized!
      if base and base.init then
      base.init(obj, ...)
      end
   end
   return obj
   end
   c.init = init
   c.is_a = function(self, klass)
      local m = getmetatable(self)
      while m do 
         if m == klass then return true end
         m = m._base
      end
      return false
   end
   setmetatable(c, mt)
   return c
end
----------------------------------------------------------------------------------------


-----------------
-- Mouse table --
-----------------

 mouse = {  
                  -- Constants
                  LB = 1,
                  RB = 2,
                  CTRL = 4,
                  SHIFT = 8,
                  ALT = 16,
                  
                  -- "cap" function
                  cap = function (mask)
                          if mask == nil then
                            return gfx.mouse_cap end
                          return gfx.mouse_cap&mask == mask
                        end,
                          
                  uptime = 0,
                  
                  last_x = -1, last_y = -1,
                 
                  dx = 0,
                  dy = 0,
                  
                  ox_l = 0, oy_l = 0,    -- left click positions
                  ox_r = 0, oy_r = 0,    -- right click positions
                  capcnt = 0,
                  last_LMB_state = false,
                  last_RMB_state = false
               }
               
              
----------------
-- Menu class --
----------------

-- To create a new menu instance, call this function like this:
--   menu_name = Menu("menu_name")
local Menu = 
  class(
    function(menu, id)
      menu.id = id    
      menu.items = {} -- Menu items are collected to this table
    end
  )


------------------
-- Menu methods --
------------------

-- Returns the created table and table index in "menu_obj.items"
function Menu:add_item(...)
  t = ... or {}
  self.items[#self.items+1] = t -- add new menu item at the end of menu
  -- Parse arguments
  for i,v in pairs(t) do
    --msg(i .. " = " .. tostring(v))
    if i == "label" then
      t.label = v
    elseif i == "selected" then
      t.selected = v
    elseif i == "active" then
      t.active = v
    elseif i == "toggleable" then
      t.toggleable = v
    elseif i == "command" then
      t.command = v
    end
  end
  
  -- Default values for menu items
  -- Edit these
  if t.label == nil or t.label == "" then
    t.label = tostring(#self.items) -- if label is nil or "" -> label is set to "table index in menu_obj.items"
  end
  
  if t.selected == nil then
    t.selected = false   -- edit
  end
  
  if t.active == nil then
    t.active = true      -- edit
  end
  
  if t.toggleable == nil then
    t.toggleable = false -- edit
  end
  
  if t.command == nil then
    t.command = function() return end
  end
  return t, #self.items
end


-- Get menu item table at index
function Menu:get_item(index)
  if self.items[index] == nil then
    return false
  end
  return self.items[index]
end


-- Show menu at mx, my
function Menu:show(mx, my)
  gfx.x = mx
  gfx.y = my
  self.items_str = self:table_to_string() or ""
  self.val = gfx.showmenu(self.items_str)
  if self.val > 0 then
    self:update(self.val)
  end
end


function Menu:update(menu_item_index)
  local i = menu_item_index 
  if self.items[i].toggleable then
    self.items[i].selected = not self.items[i].selected
  end
  if self.items[i].command ~= nil then
    self.items[i].command()
  end
end


-- Convert "Menu_obj.items" to string
function Menu:table_to_string()
  if self.items == nil then
    return
  end
  self.items_str = ""
  
  for i=1, #self.items do
    s = ""
    local menu_item = self.items[i]
    if menu_item.selected then
      s = "!"
    end
    
    if not menu_item.active then
      s = s .. "#"
    end
    
    if #menu_item > 0 then
      --self.items[i]
      s = s .. ">"
    end
    
    if menu_item.label ~= "" then
      s = s .. menu_item.label .. "|"
    end
    
    if i < #self.items then
    --  s = s .. "|"
    end
    --aas = self
    self.items_str = self.items_str .. s
  end
  
  return self.items_str
end

--END of Menu class----------------------------------------------------



function mouse_on_rect(x,y,w,h)
  return gfx.mouse_x >= x and gfx.mouse_x <= x + w and gfx.mouse_y >= y and gfx.mouse_y <= y + h
end
   
    
function mainloop()
  RMB_state = mouse.cap(mouse.RB)
  mx = gfx.mouse_x
  my = gfx.mouse_y
  
  gfx.rect(10,10,gfx.w-20, 0.1*gfx.h,0) -- draw a rectangle for "context menu"
  if not mouse.last_RMB_state and gfx.mouse_cap&2 == 2 then
    -- right click registered inside the rectangle -> show "context menu" at mouse cursor
    if mouse_on_rect(10, 10, gfx.w-20 ,0.1*gfx.h) then
      context_menu:show(mx, my)
    -- (else) right click registered outside the rectangle ->show "right click menu" at mouse cursor
    else
      rc_menu:show(mx, my)
    end
  end

  mouse.last_RMB_state = RMB_state -- store current right mouse button state
  
  gfx.update()
  if gfx.getchar() >= 0 then reaper.defer(mainloop) end
end



-- Examples:
-------------------------------
-- Create "right click" menu --
-------------------------------

rc_menu = Menu("rc_menu")

---[[
rc_menu:add_item(
                  {  
                     label = "Right click menu item 1",
                     selected = true, 
                     active = true,
                     toggleable = true,
                     command = function() reaper.ShowConsoleMsg("Right click menu item 1\n") end
                  }
                )
                
rc_menu:add_item(
                  {  
                     label = "Right click menu item 2",
                     selected = true, 
                     active = false,
                     toggleable = true,
                     command = function() reaper.ShowConsoleMsg("Right click menu item 2\n") end
                  }
                )                

rc_menu:add_item(
                  {  
                     label = "Right click menu item 3",
                     selected = false, 
                     active = true,
                     toggleable = true,
                     command = function() reaper.ShowConsoleMsg("Right click menu item 3\n") end
                  }
                ) 
                                
--]]

---[[
---------------------------
-- Create "context" menu --
---------------------------
context_menu = Menu("context_menu")

-- Add first menu item
-- (all arguments are optional: edit "Menu:add_item" to change the default values)
context_menu:add_item(
                        {  
                           label = "Context menu item 1",
                           selected = false, 
                           active = true,
                           toggleable = false,
                           command = function() reaper.ShowConsoleMsg("Context menu item 1\n") end
                        }
                      )
--]]

---[[                      
-- Add second menu item
-- ("Menu:add_item" method can be called with variable number of arguments)

context_menu:add_item({label = "'Indicator'", active = false, selected = true}) -- this item is just an "indicator" 


-- Add third menu item (make it "toggleable")
-- "Menu:add_item" also returns the created table and table index in "menu_obj.items"
third_item, item_pos = context_menu:add_item({label = "Toggleable menu item", toggleable = true})

-- Each menu item triggers a function (if set)
-- Set a command for the third menu item:
third_item.command = function()
                      msg("'Selected' state changed to: " .. tostring(third_item.selected))
                     end
--]]
-------------------------------------------------------------------------------

gfx.init("Menu example", 300, 300)
gfx.set(1,1,1,1)
mainloop()
There's an example/comments at the end of the code. Submenus and separator items are not supported yet.
  • Each menu item triggers a function (if set)


spk77 is offline   Reply With Quote
Old 07-21-2015, 02:19 PM   #5
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 12,295
Default

I know so little... it's less than nothing, but I'm watching... Looks to me that spk77 is building the tools for those that are able to create the Brave New World of LUALUA... %^)
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is offline   Reply With Quote
Old 07-21-2015, 02:48 PM   #6
JHughes
Human being with feelings
 
JHughes's Avatar
 
Join Date: Aug 2007
Location: Too close to Charlotte, NC
Posts: 3,145
Default

As I predicted...we've yet to see the surface of LUA scratched.

Thanks spk77!
__________________
You can only Reverse, Switch, Invert or Flip POLARITY, not "PHASE".
JHughes is offline   Reply With Quote
Old 07-22-2015, 03:04 AM   #7
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default Added "menuitem.on_menu_show"

Updates:

July 26, 2015
  • Updated "menu class.lua"
  • Added an example: "menu example (add menu items dynamically).lua"

July 24, 2015
  • Added support for submenus and separators
  • Added an example: "menu example (submenus).lua"

Quote:
Originally Posted by hopi View Post
I know so little... it's less than nothing, but I'm watching... Looks to me that spk77 is building the tools for those that are able to create the Brave New World of LUALUA... %^)
Something like that, hopi, something like that

Quote:
Originally Posted by JHughes View Post
As I predicted...we've yet to see the surface of LUA scratched.

Thanks spk77!
There are many possibilities...we just have to create some reusable code/GUI elements to make things a little bit easier





Update:
  • added menuitem.on_menu_show (couldn't think of a better variable name )
  • on_menu_show is supposed to be a function
  • this function is executed just before the menu is shown (this is cpu friendly)
  • It's useful when synchronizing a menu item ('selected' state) with some REAPER toggle action.


Code snippet: (this should be in "init section")...:
Code:
-- Create a new menu instance
rc_menu = Menu("rc_menu")

-- Add a new menu item to menu
item = rc_menu:add_item(
                  {  
                     label = "Show mixer",
                     selected = true, 
                     active = true,
                     toggleable = true,
                     command = function() reaper.Main_OnCommand(40078, 0) end -- 40078 = toggle mixer visible
                  }
                )

-- Add "on_menu_show" function to last created menu item
-- This function is executed just before the menu is shown           
item.on_menu_show = function()
                      -- 40078 = toggle mixer visible
                      item.selected = reaper.GetToggleCommandState(40078) == 1 -- update this menu item's 'selected' state
                    end
... then, call menu_object:show in mainloop to show the menu
Code:
function mainloop()
  RMB_state = mouse.cap(mouse.RB)
  mx = gfx.mouse_x
  my = gfx.mouse_y
  
  if not mouse.last_RMB_state and gfx.mouse_cap&2 == 2 then
    -- right click pressed down -> show "right click menu" at mouse cursor
      rc_menu:show(mx, my)
  end

  mouse.last_RMB_state = RMB_state -- store current right mouse button state
  
  gfx.update()
  if gfx.getchar() >= 0 then reaper.defer(mainloop) end
end

Here's an example (classes are now in separate files - it's much cleaner and easier to maintain)
Menu example + included files:
https://stash.reaper.fm/24640/Menu%20...e%20220715.zip



Scripttease show:

Last edited by spk77; 07-26-2015 at 04:42 AM.
spk77 is offline   Reply With Quote
Old 07-22-2015, 03:11 AM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,045
Default

Thanks for putting works in templates/model/framework and documentation... It can really helps making great scripts more easily !
X-Raym is offline   Reply With Quote
Old 07-22-2015, 03:27 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default

Quote:
Originally Posted by X-Raym View Post
Thanks for putting works in templates/model/framework and documentation... It can really helps making great scripts more easily !
Thanks X-Raym!
Making a documentation is quite annoying/time consuming, especially because English is not my first language.
And I really appreciate your work on reascripts/reascript tutorials
spk77 is offline   Reply With Quote
Old 07-22-2015, 04:13 AM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,045
Default

@spk77
Oh sure it does...
... But it worth it ! A good documentation is like an invitation If you polish it, you will have more guests into the party !

Well, you may not learn of lot of things from my tutorials haha ! ^^ You are still way more advanced than me !
X-Raym is offline   Reply With Quote
Old 07-24-2015, 08:58 AM   #11
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default

Update:

Another scripttease show:




This was the easiest way to add support for submenus, not the best...
  • > at the start of label: spawn a submenu
  • < at the start of label: last item in a submenu
  • <> or >< should work also
  • | at the end of label: adds a separator

Init section could look like this:

(see menu example (submenus).lua in the zip)
Code:
-- Create a "Menu" instance
local rc_menu = Menu("rc_menu")


-- Add menu items to "rc_menu"

-- Top level items
item1 = rc_menu:add_item({label = "Top level - Item 1"})            
item2 = rc_menu:add_item({label = ">Submenu 1"})                   -- ">" at the start spawns a submenu
  -- Submenu 1 items
  item3 = rc_menu:add_item({label = "SM 1 - Item 1"})
  item4 = rc_menu:add_item({label = "<>SM 2 - Last item of SM 1"}) -- End of "submenu 1", and start of "submenu 2"
    -- Submenu 2 items
    item5 = rc_menu:add_item({label = "SM 2 - Item 1"})
    item6 = rc_menu:add_item({label = "SM 2 - Item 2|"})            -- "|" at the end adds a separator
    item7 = rc_menu:add_item({label = "<SM 2 - Item 3"})           -- End of "submenu 2" (next items are top level items)
-- Last two top level items
item9 = rc_menu:add_item({label = "Top level - Item 2|"})          -- "|" at the end adds a separator
item10 = rc_menu:add_item({label = "Top level - Item 3"})
spk77 is offline   Reply With Quote
Old 07-26-2015, 04:46 AM   #12
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,286
Default Menu class - add menu items dynamically

Updated:
July 26, 2015

spk77 is offline   Reply With Quote
Old 06-09-2017, 12:37 PM   #13
Airal
Human being with feelings
 
Join Date: Nov 2015
Posts: 376
Default

Does anyone else have a problem with the mouse modifiers not responding to changes when the script loses focus, even when getting focus it no longer responds for the lifetime of the script?
Airal is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.