Beispiel #1
0
VAL RESIZE(VM* vm, int w, int h) {
    VAL m;
    idris_constructor(m, vm, 6, 2, 0);
    idris_setConArg(m, 0, MKINT((intptr_t)w));
    idris_setConArg(m, 1, MKINT((intptr_t)h));
    return m;
}
Beispiel #2
0
VAL BUTTON(VM* vm, int tag, int b, int x, int y) {
    VAL button;

    switch(b) {
    case SDL_BUTTON_LEFT:
        idris_constructor(button, vm, 0, 0, 0);
        break;
    case SDL_BUTTON_MIDDLE:
        idris_constructor(button, vm, 1, 0, 0);
        break;
    case SDL_BUTTON_RIGHT:
        idris_constructor(button, vm, 2, 0, 0);
        break;
    default:
        idris_constructor(button, vm, 0, 0, 0);
        break;
    }

    VAL event;
    idris_constructor(event, vm, tag, 3, 0);
    idris_setConArg(event, 0, button);
    idris_setConArg(event, 1, MKINT((intptr_t)x));
    idris_setConArg(event, 2, MKINT((intptr_t)y));

    return event;
}
Beispiel #3
0
void* processEvent(VM* vm, int r, SDL_Event * e) {
  VAL idris_event;

  SDL_Event event = *e;
  idris_requireAlloc(128); // Conservative!


  if (r==0) {
    idris_constructor(idris_event, vm, 0, 0, 0); // Nothing
  }
  else {
    VAL ievent = NULL;
    switch(event.type) {
    case SDL_KEYDOWN:
      ievent = KEY(vm, 0, event.key.keysym.sym);
      break;
    case SDL_KEYUP:
      ievent = KEY(vm, 1, event.key.keysym.sym);
      break;
    case SDL_MOUSEMOTION:
      ievent = MOTION(vm, event.motion.x, event.motion.y,
		      event.motion.xrel, event.motion.yrel);
      break;
    case SDL_MOUSEBUTTONDOWN:
      ievent = BUTTON(vm, 3, event.button.button, event.button.x, event.button.y);
      break;
    case SDL_MOUSEBUTTONUP:
      ievent = BUTTON(vm, 4, event.button.button, event.button.x, event.button.y);
      break;
    case SDL_MOUSEWHEEL:
      idris_constructor(ievent, vm, 5, 1, 0);
      idris_setConArg(ievent, 0, MKINT((intptr_t) event.wheel.y));
      break;
    case SDL_WINDOWEVENT:
      switch(event.window.event) {
      case SDL_WINDOWEVENT_RESIZED:
	ievent = RESIZE(vm, event.window.data1, event.window.data2);
	break;
      default:
	// TODO: other window event
	idris_constructor(ievent, vm, 8, 0, 0);
      }
      break;
    case SDL_QUIT:
      idris_constructor(ievent, vm, 7, 0, 0);
      break;
    default:
      idris_constructor(idris_event, vm, 0, 0, 0); // Nothing
      idris_doneAlloc(vm);
      return idris_event;
    }
    idris_constructor(idris_event, vm, 1, 1, 0);
    idris_setConArg(idris_event, 0, ievent); // Just ievent
  }
  
  idris_doneAlloc(vm);
  return idris_event;
}
Beispiel #4
0
VAL MOTION(VM* vm, int x, int y, int relx, int rely) {
    VAL m;
    idris_constructor(m, vm, 2, 4, 0);
    idris_setConArg(m, 0, MKINT((intptr_t)x));
    idris_setConArg(m, 1, MKINT((intptr_t)y));
    idris_setConArg(m, 2, MKINT((intptr_t)relx));
    idris_setConArg(m, 3, MKINT((intptr_t)rely));
    return m;
}
Beispiel #5
0
VAL idr_lock_texture(SDL_Texture* texture, VM* vm) {
  VAL m;

  void *pixels;
  int pitch;
  SDL_LockTexture(texture, NULL, &pixels, &pitch);  

  idris_requireAlloc(128); // Conservative!

  idris_constructor(m, vm, 0, 0, 0);
  idris_setConArg(m, 0, MKPTR(vm, pixels));
  idris_setConArg(m, 1, MKINT((intptr_t) pitch));
  idris_doneAlloc(vm);

  return m;
}
Beispiel #6
0
VAL idris_mkFileError(VM* vm) {
    VAL result;
    switch(errno) {
        // Make sure this corresponds to the FileError structure in
        // Prelude.File
        case ENOENT:
            idris_constructor(result, vm, 2, 0, 0);
            break;
        case EACCES:
            idris_constructor(result, vm, 3, 0, 0);
            break;
        default:
            idris_constructor(result, vm, 4, 1, 0);
            idris_setConArg(result, 0, MKINT((intptr_t)errno));
            break;
    }
    return result;
}
Beispiel #7
0
VAL KEY(VM* vm, int tag, SDL_Keycode key) {
    VAL k;

    switch(key) {
    case SDLK_UP:
        idris_constructor(k, vm, 0, 0, 0);
	break;
    case SDLK_DOWN:
        idris_constructor(k, vm, 1, 0, 0);
	break;
    case SDLK_LEFT:
        idris_constructor(k, vm, 2, 0, 0);
	break;
    case SDLK_RIGHT:
        idris_constructor(k, vm, 3, 0, 0);
	break;
    case SDLK_ESCAPE:
        idris_constructor(k, vm, 4, 0, 0);
	break;
    case SDLK_SPACE:
        idris_constructor(k, vm, 5, 0, 0);
	break;
    case SDLK_TAB:
        idris_constructor(k, vm, 6, 0, 0);
	break;
    case SDLK_F1:
        idris_constructor(k, vm, 7, 0, 0);
	break;
    case SDLK_F2:
        idris_constructor(k, vm, 8, 0, 0);
	break;
    case SDLK_F3:
        idris_constructor(k, vm, 9, 0, 0);
	break;
    case SDLK_F4:
        idris_constructor(k, vm, 10, 0, 0);
	break;
    case SDLK_F5:
        idris_constructor(k, vm, 11, 0, 0);
	break;
    case SDLK_F6:
        idris_constructor(k, vm, 12, 0, 0);
	break;
    case SDLK_F7:
        idris_constructor(k, vm, 13, 0, 0);
	break;
    case SDLK_F8:
        idris_constructor(k, vm, 14, 0, 0);
	break;
    case SDLK_F9:
        idris_constructor(k, vm, 15, 0, 0);
	break;
    case SDLK_F10:
        idris_constructor(k, vm, 16, 0, 0);
	break;
    case SDLK_F11:
        idris_constructor(k, vm, 17, 0, 0);
	break;
    case SDLK_F12:
        idris_constructor(k, vm, 18, 0, 0);
	break;
    case SDLK_F13:
        idris_constructor(k, vm, 19, 0, 0);
	break;
    case SDLK_F14:
        idris_constructor(k, vm, 20, 0, 0);
	break;
    case SDLK_F15:
        idris_constructor(k, vm, 21, 0, 0);
	break;
    case SDLK_LSHIFT:
        idris_constructor(k, vm, 22, 0, 0);
	break;
    case SDLK_RSHIFT:
        idris_constructor(k, vm, 23, 0, 0);
	break;
    case SDLK_LCTRL:
        idris_constructor(k, vm, 24, 0, 0);
	break;
    case SDLK_RCTRL:
        idris_constructor(k, vm, 25, 0, 0);
	break;
    default:
        idris_constructor(k, vm, 26, 1, 0);
        // safe because there's no further allocation.
        idris_setConArg(k, 0, MKINT((intptr_t)key));
	break;
    }

    VAL event;
    idris_constructor(event, vm, tag, 1, 0);
    idris_setConArg(event, 0, k);

    return event;
}