Blame view

emulateur/epsilon-nofrendo/python/port/modkandinsky_impl.cpp 1.51 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  extern "C" {
  #include "modkandinsky.h"
  }
  #include <kandinsky.h>
  #include "port.h"
  
  /* KDIonContext::sharedContext needs to be set to the wanted Rect before
   * calling kandinsky_get_pixel, kandinsky_set_pixel and kandinsky_draw_string.
   * We do this here with displaySandbox(), which pushes the SandboxController on
   * the stackViewController and forces the window to redraw itself.
   * KDIonContext::sharedContext is set to the frame of the last object drawn. */
  
  mp_obj_t kandinsky_color(mp_obj_t red, mp_obj_t green, mp_obj_t blue) {
    return
      MP_OBJ_NEW_SMALL_INT(
        KDColor::RGB888(
          mp_obj_get_int(red),
          mp_obj_get_int(green),
          mp_obj_get_int(blue)
        )
      );
  }
  
  mp_obj_t kandinsky_get_pixel(mp_obj_t x, mp_obj_t y) {
    KDColor c = KDIonContext::sharedContext()->getPixel(
      KDPoint(mp_obj_get_int(x), mp_obj_get_int(y))
    );
    return MP_OBJ_NEW_SMALL_INT(c);
  }
  
  mp_obj_t kandinsky_set_pixel(mp_obj_t x, mp_obj_t y, mp_obj_t color) {
    MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
    KDIonContext::sharedContext()->setPixel(
      KDPoint(mp_obj_get_int(x), mp_obj_get_int(y)),
      KDColor::RGB16(mp_obj_get_int(color))
    );
    return mp_const_none;
  }
  
  mp_obj_t kandinsky_draw_string(mp_obj_t text, mp_obj_t x, mp_obj_t y) {
    MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
    KDIonContext::sharedContext()->drawString(
      mp_obj_str_get_str(text),
      KDPoint(mp_obj_get_int(x), mp_obj_get_int(y))
    );
    return mp_const_none;
  }