Example #1
0
/**
 * \brief Implementation of drawable:fade_out().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_fade_out(lua_State* l) {

  uint32_t delay = 20;
  int callback_ref = LUA_REFNIL;

  Drawable& drawable = check_drawable(l, 1);

  if (lua_gettop(l) >= 2) {
    // the second argument can be the delay or the callback
    int index = 2;
    if (lua_isnumber(l, index)) {
      delay = lua_tonumber(l, index);
      index++;
    }
    // the next argument (if any) is the callback
    if (lua_gettop(l) >= index) {
      luaL_checktype(l, index, LUA_TFUNCTION);
      lua_settop(l, index);
      callback_ref = luaL_ref(l, LUA_REGISTRYINDEX);
    }
  }

  TransitionFade* transition = new TransitionFade(
      Transition::TRANSITION_CLOSING,
      drawable.get_transition_surface());
  transition->set_delay(delay);
  drawable.start_transition(*transition, callback_ref, &get_lua_context(l));

  return 0;
}
Example #2
0
/**
 * \brief Implementation of drawable:fade_out().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_fade_out(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    uint32_t delay = 20;
    ScopedLuaRef callback_ref;

    Drawable& drawable = *check_drawable(l, 1);

    if (lua_gettop(l) >= 2) {
      // the second argument can be the delay or the callback
      int index = 2;
      if (lua_isnumber(l, index)) {
        delay = lua_tonumber(l, index);
        index++;
      }
      // the next argument (if any) is the callback
      callback_ref = LuaTools::opt_function(l, index);
    }

    TransitionFade* transition(new TransitionFade(
        Transition::Direction::CLOSING,
        drawable.get_transition_surface()
    ));
    transition->clear_color();
    transition->set_delay(delay);
    drawable.start_transition(
        std::unique_ptr<Transition>(transition),
        callback_ref
    );

    return 0;
  });
}
Example #3
0
/**
 * \brief Implementation of drawable:stop_movement().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_stop_movement(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);

  drawable.stop_movement();

  return 0;
}
Example #4
0
/**
 * \brief Implementation of drawable:get_xy().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_xy(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);

  lua_pushinteger(l, drawable.get_xy().get_x());
  lua_pushinteger(l, drawable.get_xy().get_y());
  return 2;
}
Example #5
0
/**
 * \brief Implementation of drawable:get_xy().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_xy(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);

    lua_pushinteger(l, drawable.get_xy().x);
    lua_pushinteger(l, drawable.get_xy().y);
    return 2;
  });
}
Example #6
0
/**
 * \brief Implementation of drawable:stop_movement().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_stop_movement(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);

    drawable.stop_movement();

    return 0;
  });
}
Example #7
0
/**
 * \brief Implementation of drawable:set_xy().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_set_xy(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);
  int x = luaL_checkint(l, 2);
  int y = luaL_checkint(l, 3);

  drawable.set_xy(Rectangle(x, y));

  return 0;
}
Example #8
0
/**
 * \brief Implementation of drawable:draw().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::drawable_api_draw(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);
  Surface& dst_surface = check_surface(l, 2);
  int x = luaL_optint(l, 3, 0);
  int y = luaL_optint(l, 4, 0);
  drawable.draw(dst_surface, x, y);

  return 0;
}
Example #9
0
/**
 * \brief Implementation of drawable:set_blend_mode().
 * \param l the Lua context that is calling this function
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_set_blend_mode(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);
    BlendMode blend_mode = LuaTools::check_enum<BlendMode>(l, 2);

    drawable.set_blend_mode(blend_mode);

    return 0;
  });
}
Example #10
0
/**
 * \brief Implementation of drawable:set_xy().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_set_xy(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);
    int x = LuaTools::check_int(l, 2);
    int y = LuaTools::check_int(l, 3);

    drawable.set_xy(Point(x, y));

    return 0;
  });
}
Example #11
0
/**
 * \brief Implementation of drawable:get_blend_mode().
 * \param l the Lua context that is calling this function
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_blend_mode(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);

    BlendMode blend_mode = drawable.get_blend_mode();

    push_string(l, enum_to_name(blend_mode));

    return 1;
  });
}
Example #12
0
/**
 * \brief Implementation of drawable:draw().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::drawable_api_draw(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);
    SurfacePtr dst_surface = check_surface(l, 2);
    int x = LuaTools::opt_int(l, 3, 0);
    int y = LuaTools::opt_int(l, 4, 0);
    drawable.draw(dst_surface, x, y);

    return 0;
  });
}
Example #13
0
/**
 * \brief Finalizer of types sprite, surface and text surface.
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::drawable_meta_gc(lua_State* l) {

  LuaContext& lua_context = get_lua_context(l);
  Drawable& drawable = check_drawable(l, 1);

  if (lua_context.has_drawable(&drawable)) {
    // This drawable was created from Lua.
    lua_context.remove_drawable(&drawable);
  }
  userdata_meta_gc(l);

  return 0;
}
Example #14
0
/**
 * \brief Implementation of drawable:get_movement().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_movement(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);

  Movement* movement = drawable.get_movement();
  if (movement == NULL) {
    lua_pushnil(l);
  }
  else {
    push_userdata(l, *movement);
  }

  return 1;
}
Example #15
0
/**
 * \brief Finalizer of types sprite, surface and text surface.
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_meta_gc(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    LuaContext& lua_context = get_lua_context(l);
    DrawablePtr drawable = check_drawable(l, 1);

    if (lua_context.has_drawable(drawable)) {
      // This drawable was created from Lua.
      lua_context.remove_drawable(drawable);
    }
    userdata_meta_gc(l);

    return 0;
  });
}
Example #16
0
/**
 * \brief Implementation of drawable:get_movement().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_movement(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);
    std::shared_ptr<Movement> movement = drawable.get_movement();
    if (movement == nullptr) {
      lua_pushnil(l);
    }
    else {
      push_movement(l, *movement);
    }

    return 1;
  });
}
Example #17
0
/**
 * \brief Implementation of drawable:draw_region().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::drawable_api_draw_region(lua_State* l) {

  Drawable& drawable = check_drawable(l, 1);
  Rectangle region(
      luaL_checkint(l, 2),
      luaL_checkint(l, 3),
      luaL_checkint(l, 4),
      luaL_checkint(l, 5)
  );
  Surface& dst_surface = check_surface(l, 6);
  Rectangle dst_position(
     luaL_optint(l, 7, 0),
     luaL_optint(l, 8, 0)
  );
  drawable.draw_region(region, dst_surface, dst_position);

  return 0;
}
Example #18
0
/**
 * \brief Implementation of drawable:draw_region().
 * \param l the Lua context that is calling this function
 * \return number of values to return to Lua
 */
int LuaContext::drawable_api_draw_region(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);
    Rectangle region = {
        LuaTools::check_int(l, 2),
        LuaTools::check_int(l, 3),
        LuaTools::check_int(l, 4),
        LuaTools::check_int(l, 5)
    };
    SurfacePtr dst_surface = check_surface(l, 6);
    Point dst_position = {
        LuaTools::opt_int(l, 7, 0),
        LuaTools::opt_int(l, 8, 0)
    };
    drawable.draw_region(region, dst_surface, dst_position);

    return 0;
  });
}