Exemple #1
0
bool updateTimer(guihckContext* ctx, guihckElementId id, void* data)
{
  (void) data;

  bool running = scm_is_true(guihckElementGetProperty(ctx, id, "running"));
  if(running)
  {
    double nextTimeout = scm_to_double(guihckElementGetProperty(ctx, id, "next-timeout"));
    double current = guihckContextGetTime(ctx);

    if(nextTimeout < 0)
    {
      double interval = scm_to_double(guihckElementGetProperty(ctx, id, "interval"));
      guihckElementProperty(ctx, id, "next-timeout", scm_from_double(current + interval));
      guihckElementProperty(ctx, id, "cycle", scm_from_int32(0));
    }
    else if(current >= nextTimeout)
    {
      int repeat = scm_to_int32(guihckElementGetProperty(ctx, id, "repeat"));
      int cycle = scm_to_int32(guihckElementGetProperty(ctx, id, "cycle"));
      cycle += 1;

      if(repeat < 0 || repeat > cycle)
      {
        double interval = scm_to_double(guihckElementGetProperty(ctx, id, "interval"));
        guihckElementProperty(ctx, id, "next-timeout", scm_from_double(nextTimeout + interval));
      }
      else
      {
        running = false;
        guihckElementProperty(ctx, id, "next-timeout", scm_from_double(-1));
        guihckElementProperty(ctx, id, "running", SCM_BOOL_F);
      }

      guihckElementProperty(ctx, id, "cycle", scm_from_int32(cycle));
      SCM onTimeout = guihckElementGetProperty(ctx, id, "on-timeout");
      guihckStackPushElement(ctx, id);
      SCM expression = scm_list_2(onTimeout, scm_from_int32(cycle));
      guihckContextExecuteExpression(ctx, expression);
      guihckStackPopElement(ctx);
    }
  }
  return running;
}
Exemple #2
0
SCM guileKeyName(SCM keyCode)
{
  guihckKey code = scm_to_int32(keyCode);
  const char* keyName = guihckContextGetKeyName(threadLocalContext.ctx, code);
  return keyName ? scm_from_utf8_string(keyName) : SCM_UNDEFINED;
}
/* Move 3D object */
void script_move(SCM object, SCM x, SCM y, SCM z)
{
   g_move(scm_to_int32(x),
          scm_to_int32(y),
          scm_to_int32(z));
}