Home /Modules/ballum/ballum.sleela

ballum.sleela

lib/ballum/ballum.sleela · 141 line(s) · sleela

#sleela 2.5
material;
< ballum.sleela -- the self-contained, runnable Ballum demonstration. The >
< compiler run compiles one file as a single unit, so this aggregate inlines a >
< compact display + manager model (mirroring SLBallumDisplay / SLBallumManager / >
< SLBallumStatus and the native ballum/ manager) and a main that enumerates a >
< display, checks capabilities, and drives pixel/brightness/warmth/gamma >
< requests with honest, bounded results. >
<  >
< Status codes mirror ballum_status_t: 0 ok, 2 backend-unavailable, >
< 5 out-of-bounds, 7 unsupported, 100 bridge-required. Capability flags mirror >
< ballum_capability_t: 1 per-pixel, 2 blit, 4 brightness, 8 warmth, 16 gamma. >
class Ballum {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11532;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-23";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-23";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < --- a single display's facts --- >
  int width;
  int height;
  int caps;

  < --- manager state --- >
  < VM-local bridge index; <0 means no bridge >
  int handle;
  int lastStatus;

  void init() {
    width = 1920;
    height = 1080;
    < all capabilities >
    caps = 1 + 2 + 4 + 8 + 16;
    handle = -1;
    < BRIDGE_REQUIRED until bound >
    lastStatus = 100;
  }

  boolean nativeReady() { return handle >= 0; }
  void bind(int h) { handle = h; if (h >= 0) { lastStatus = 0; } else { lastStatus = 2; } }

  boolean has(int cap) { return (caps / cap) % 2 == 1; }
  boolean contains(int x, int y) { return x >= 0 && y >= 0 && x < width && y < height; }

  int clampBrightness(int p) { if (p < 0) { return 0; } if (p > 100) { return 100; } return p; }
  int clampWarmth(int k) { if (k < 1000) { return 1000; } if (k > 10000) { return 10000; } return k; }

  String statusText(int code) {
    if (code == 0) { return "ok"; }
    if (code == 2) { return "backend unavailable"; }
    if (code == 5) { return "out of bounds"; }
    if (code == 7) { return "unsupported"; }
    if (code == 100) { return "bridge required"; }
    return "other";
  }

  int setPixel(int x, int y) {
    if (!nativeReady()) { lastStatus = 100; return lastStatus; }
    if (!has(1)) { lastStatus = 7; return lastStatus; }
    if (!contains(x, y)) { lastStatus = 5; return lastStatus; }
    lastStatus = 0;
    return lastStatus;
  }

  int setBrightness(int percent) {
    if (!nativeReady()) { lastStatus = 100; return lastStatus; }
    if (!has(4)) { lastStatus = 7; return lastStatus; }
    lastStatus = 0;
    return lastStatus;
  }

  int setWarmth(int kelvin) {
    if (!nativeReady()) { lastStatus = 100; return lastStatus; }
    if (!has(8)) { lastStatus = 7; return lastStatus; }
    lastStatus = 0;
    return lastStatus;
  }

  void main() {
    print("=== Ballum pixel-level display control ===");
    init();

    < Before the host installs the native bridge, operations are honest about it. >
    print("set pixel before bridge: " + statusText(setPixel(10, 10)));

    < The host binds the VM-side native handle (ballum_backend_default present). >
    bind(7);
    print("bound native handle: " + handle);
    print("display: " + width + "x" + height);

    < A valid pixel on a per-pixel-capable display. >
    print("set pixel (10,10): " + statusText(setPixel(10, 10)));
    < Out of bounds is rejected before touching the device. >
    print("set pixel (5000,0): " + statusText(setPixel(5000, 0)));

    < Whole-display controls, clamped to their documented ranges. >
    int b = clampBrightness(250);
    print("brightness 250 -> clamp " + b + " : " + statusText(setBrightness(b)));
    int k = clampWarmth(3400);
    print("warmth 3400K (warm) : " + statusText(setWarmth(k)));

    print("done");
  }
}