Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Window controls and interaction


Now that you've got the basic functionality to draw and manipulate windows, you can design your own control elements such as buttons, edit boxes, and many other.

This recipe will show you how to create buttons and edit boxes that users can interact with. There will be three subsections where each one will deal with one king of control element.

Getting ready

This recipe will use the concepts of the previous window element to create window controls. You should be able to create and draw a window and handle input events. You'll be using mouse and keyboard events primarily.

First, you should extend the applicable event types with keyboard operations. You can do this by adding two event handlers, as shown in the following code:

events[SDL.SDL_KEYDOWN] = function(_event)
  local event = _event.key
  local key = event.keysym.sym
  local mod = event.keysym.mod
  if gui.focusedWindow then
    gui.focusedWindow.callSignal(SDL.SDL_KEYDOWN, key, mod)
  end
end
events[SDL.SDL_KEYUP...