daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest May 19th, 2017 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import
  2.   colors
  3.  
  4. when not defined(js):
  5.   import
  6.     events
  7.  
  8. import
  9.   ../../../src/frag,
  10.   ../../../src/frag/config,
  11.   ../../../src/frag/graphics/window,
  12.   ../../../src/frag/logger,
  13.   ../../../src/frag/modules/graphics
  14.  
  15. when not defined(js):
  16.   import
  17.     logo
  18.  
  19. type
  20.   App = ref object
  21.  
  22. when not defined(js):
  23.   proc resize*(e: EventArgs) =
  24.     let event = SDLEventMessage(e).event
  25.     let sdlEventData = event.sdlEventData
  26.     # let app = cast[App](event.userData)
  27.     let graphics = event.graphics
  28.     graphics.setViewRect(0, 0, 0, uint16 sdlEventData.window.data1, uint16 sdlEventData.window.data2)
  29.  
  30. proc initApp(app: App, ctx: Frag) =
  31.   logDebug "Initializing app..."
  32.   when not defined(js):
  33.     ctx.events.on(SDLEventType.WindowResize, resize)
  34.   logDebug "App initialized."
  35.  
  36. proc updateApp(app:App, ctx: Frag, deltaTime: float) =
  37.   discard
  38.  
  39. proc renderApp(app: App, ctx: Frag, deltaTime: float) =
  40.   ctx.graphics.clearView(0, ClearMode.Color.ord or ClearMode.Depth.ord, colors.Color(0x303030ff), 1.0, 0)
  41.   when not defined(js):
  42.     let size = ctx.graphics.getSize()
  43.  
  44.     ctx.graphics.drawDebugImage(
  45.       logo.fragLogo,
  46.       uint16 max(size[0] / 2 / 8, 40) - 40,
  47.       uint16 max(size[1] / 2 / 16, 12.5) - 12.5,
  48.       80,
  49.       25,
  50.       160
  51.     )
  52.  
  53. proc shutdownApp(app: App, ctx: Frag) =
  54.   logDebug "Shutting down app..."
  55.   logDebug "App shut down."
  56.  
  57. var conf: Config
  58.  
  59. when defined js:
  60.   conf = Config(rootWindowTitle: "Frag Example 00-hello-world")
  61.  
  62. else:
  63.   conf = Config(
  64.     rootWindowTitle: "Frag Example 00-hello-world",
  65.     rootWindowPosX: window.posUndefined, rootWindowPosY: window.posUndefined,
  66.     rootWindowWidth: 960, rootWindowHeight: 540,
  67.     resetFlags: ResetFlag.VSync,
  68.     logFileName: "example-00.log",
  69.     assetRoot: "../assets",
  70.     debugMode: BGFX_DEBUG_TEXT
  71.   )
  72.  
  73. startFrag(App(), conf)
RAW Paste Data
Top