~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/sdl_text.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <SDL/SDL.h>
 
2
#include <stdio.h>
 
3
#include <string.h>
 
4
#include <assert.h>
 
5
#include <emscripten.h>
 
6
 
 
7
int result = 0;
 
8
 
 
9
void one() {
 
10
  SDL_Event event;
 
11
  while (SDL_PollEvent(&event)) {
 
12
    switch (event.type) {
 
13
      case SDL_TEXTEDITING: assert(0); break;
 
14
      case SDL_TEXTINPUT:
 
15
        printf("Received %s\n", event.text.text);
 
16
        if (!strcmp("a", event.text.text)) {
 
17
          result = 1;
 
18
        } else if (!strcmp("A", event.text.text)) {
 
19
          REPORT_RESULT();
 
20
          emscripten_run_script("throw 'done'");
 
21
        }
 
22
        break;
 
23
      default: /* Report an unhandled event */
 
24
        printf("I don't know what this event is!\n");
 
25
    }
 
26
  }
 
27
}
 
28
 
 
29
int main() {
 
30
  SDL_Init(SDL_INIT_VIDEO);
 
31
  SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
 
32
  SDL_StartTextInput();
 
33
 
 
34
  emscripten_run_script("simulateKeyEvent('a'.charCodeAt(0))"); // a
 
35
  emscripten_run_script("simulateKeyEvent('A'.charCodeAt(0))"); // A
 
36
 
 
37
  one();
 
38
 
 
39
  return 0;
 
40
}