Example #1
0
void print_message_text (int level, const char *text) {
  if (level >= 0) {
    begin_line ();
    print_spaces (level);
  }
  while (*text) {
    if (!strncmp (text, "<br>", 4)) {
      end_line ();
      begin_line ();
      print_spaces (level);
      text += 4;
    } else if (!strncmp (text, "&lt;", 4)) {
      add_char_line ('<');
      text += 4;
    } else if (!strncmp (text, "&gt;", 4)) {
      add_char_line ('>');
      text += 4;
    } else {
      add_char_line (*(text ++));
    }
  }
  if (line_pos) {
    end_line ();
  }
}
Example #2
0
void Writer::begin_write() {
  assert (state == w_stopped);
  state = w_running;

  indent_level = 0;
  need_indent = 0;
  data = WriterData();
  begin_line();
}
Example #3
0
void add_string_line (char *c, int len) {
  while (len > 0) {
    int x = len > LINE_SIZE - line_pos ? LINE_SIZE - line_pos : len;
    memcpy (line + line_pos, c, x);
    line_pos += x;
    c += x;
    len -= x;
    if (line_pos == LINE_SIZE) {
      end_line ();
      begin_line ();
    }
  }
}
Example #4
0
void print_message_array (int num, struct message **msg, int reverse) {
  int i;
  if (!reverse) {
    for (i = 0; i < num; i++) {
      begin_line ();
      add_string_line ("----------", 10);
      end_line ();
      print_message (0, msg[i]);
    }
    begin_line ();
    add_string_line ("----------", 10);
    end_line ();
  } else {
    for (i = num - 1; i >= 0; i--) {
      begin_line ();
      add_string_line ("----------", 10);
      end_line ();
      print_message (0, msg[i]);
    }
    begin_line ();
    add_string_line ("----------", 10);
    end_line ();
  }
}
int draw( void )
{
    
    if(wireframe)
    {
        glClearColor(1, 1, 1, 1);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glLineWidth(2);
    }
    else
    {
        glClearColor(0.2f, 0.2f, 0.2f, 1);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }
    
    // effacer l'image
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if(key_state('r'))
    {
        clear_key_state('r');
        reload_program();
    }
    
    // recupere les mouvements de la souris
    int mx, my;
    unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
    int mousex, mousey;
    SDL_GetMouseState(&mousex, &mousey);
    
    // deplace la camera
    if(mb & SDL_BUTTON(1))
        orbiter_rotation(camera, mx, my);      // tourne autour de l'objet
    else if(mb & SDL_BUTTON(2))
        orbiter_translation(camera, (float) mx / (float) window_width(), (float) my / (float) window_height()); // deplace le point de rotation
    else if(mb & SDL_BUTTON(3))
        orbiter_move(camera, mx);           // approche / eloigne l'objet
    
    // recupere les transformations
    Transform model= make_identity();
    Transform view= orbiter_view_transform(camera);
    Transform projection= orbiter_projection_transform(camera, window_width(), window_height(), 45);
    Transform viewport= make_viewport(window_width(), window_height());
    
    Transform mvp= projection * view * model;
    Transform mvpInv= make_inverse(mvp);
    Transform mv= model * view;
    
    // affiche l'objet
    if(program_failed == false)
    {
        if(key_state('w'))
        {
            clear_key_state('w');
            wireframe= !wireframe;
        }
        
        // configuration minimale du pipeline
        glBindVertexArray(vao);
        glUseProgram(program);
        
        // affecte une valeur aux uniforms
        // transformations standards
        program_uniform(program, "modelMatrix", model);
        program_uniform(program, "modelInvMatrix", make_inverse(model));
        program_uniform(program, "viewMatrix", view);
        program_uniform(program, "viewInvMatrix", make_inverse(view));
        program_uniform(program, "projectionMatrix", projection);
        program_uniform(program, "projectionInvMatrix", make_inverse(projection));
        program_uniform(program, "viewportMatrix", viewport);
        program_uniform(program, "viewportInvMatrix", make_inverse(viewport));
        
        program_uniform(program, "mvpMatrix", mvp);
        program_uniform(program, "mvpInvMatrix", mvpInv);
        
        program_uniform(program, "mvMatrix", mv);
        program_uniform(program, "normalMatrix", make_normal_transform(mv));
        
        // interactions
        program_uniform(program, "viewport", make_vec2(window_width(), window_height()));
        program_uniform(program, "time", (float) SDL_GetTicks());
        program_uniform(program, "motion", make_vec3(mx, my, mb & SDL_BUTTON(1)));
        program_uniform(program, "mouse", make_vec3(mousex, mousey, mb & SDL_BUTTON(1)));
        
        // textures
        for(unsigned int i= 0; i < (unsigned int) textures.size(); i++)
        {
            char uniform[1024];
            sprintf(uniform, "texture%d", i);
            program_use_texture(program, uniform, i, textures[i]);
        }
        
        // go
        glDrawArrays(GL_TRIANGLES, 0, vertex_count);
    }
    
    // affiche les infos
    begin(widgets);
    if(program_failed)
    {
        label(widgets, "[error] program '%s'", program_filename.path);
        begin_line(widgets);
        text_area(widgets, 20, program_log.c_str(), program_area);
    }
    else
    {
        label(widgets, "program '%s' running...", program_filename.path);
        if(mesh_filename[0] != 0)
        {
            begin_line(widgets);
            label(widgets, "mesh '%s', %u positions, %u texcoords, %u normals", mesh_filename.path, 
                (unsigned int) mesh.positions.size(),
                (unsigned int) mesh.texcoords.size(),
                (unsigned int) mesh.normals.size());
        }
        for(unsigned int i= 0; i < (unsigned int) texture_filenames.size(); i++)
        {
            begin_line(widgets);
            label(widgets, "texture%u '%s'", i, texture_filenames[i].path);
        }
    }
    end(widgets);
    
    draw(widgets, window_width(), window_height());
    
    
    if(key_state('s'))
    {
        clear_key_state('s');
        screenshot("shader_kit.png");
    }
    
    if(key_state('c'))
    {
        clear_key_state('c');
        write_orbiter(camera, "orbiter.txt");
    }
    if(key_state('v'))
    {
        clear_key_state('v');
        camera= read_orbiter("orbiter.txt");
    }
    
    return 1;
}
Example #6
0
void print_message (int level, const struct message *msg) {
  begin_line ();
  print_spaces (level);
  struct user *user = 0;
  if (!disable_sql) {
    user = vk_db_lookup_user (msg->uid);
    if (!user) {
      aio_profiles_get (1, &msg->uid, 1);
    }
  }
  static char buf[1001];
  int len;
  /*
  if (!user) {  
    len = snprintf (buf, 1000, "Message #%d %s user %d", msg->id, msg->out ? "to" : "from", msg->uid);
  } else {
    len = snprintf (buf, 1000, "Message #%d %s user %d (%s %s)", msg->id, msg->out ? "to" : "from", msg->uid, user->first_name, user->last_name);
  }*/
  if (msg->out) {
    len = snprintf (buf, 1000, COLOR_RED);
  } else {
    len = snprintf (buf, 1000, COLOR_GREEN);
  }
  if (msg->chat_id) {
    len += snprintf (buf + len, 1000 - len, "Chat %s: ", msg->title);
    if (len >= 1000) { len = 1000; }
  }
  if (!user) {
    len += snprintf (buf + len, 1000 - len, "id%d ", msg->uid);
  } else {
    len += snprintf (buf + len, 1000 - len, "%s %s ", user->first_name, user->last_name);
  }
  add_string_line (buf, len);
  //end_line ();
  //begin_line ();

  int now = time (0);

  long _t = msg->date;
  struct tm *lctime = localtime ((void *)&_t);
  print_spaces (level + 1);

  if (now - msg->date <= 60 * 60 * 12) {
    len = snprintf (buf, 1000, "%02d:%02d ", lctime->tm_hour, lctime->tm_min);
  } else if (now - msg->date <= 60 * 60 * 24 * 30) {
    len = snprintf (buf, 1000, "%02d-%02d %02d:%02d ", lctime->tm_mon + 1, lctime->tm_mday, lctime->tm_hour, lctime->tm_min);
  } else {
    len = snprintf (buf, 1000, "%04d-%02d-%02d %02d:%02d ", lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, lctime->tm_hour, lctime->tm_min);
  }
  /*len = snprintf (buf, 1000, "Created at [%04d-%02d-%02d %02d:%02d:%02d], state %s", 
    lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, 
    lctime->tm_hour, lctime->tm_min, lctime->tm_sec,
    msg->deleted ? "deleted" : msg->read_state ? "read" : "unread");*/
  add_string_line (buf, len);
  
  len = snprintf (buf, 1000, "%s " COLOR_NORMAL, msg->out ? "<<<" : ">>>");
  add_string_line (buf, len);
  if (message_has_line_break (msg->body)) {
    end_line ();
    begin_line ();
    print_message_text (level + 1, msg->body ? msg->body : "<none>");
  } else {
    print_message_text (-1, msg->body ? msg->body : "<none>");
    if (line_pos) {
      end_line ();
    }
  }
  /*begin_line ();
  print_spaces (level + 1);
  if (msg->chat_id <= 0) {
    len = snprintf (buf, 1000, "No chat");
  } else {
    len = snprintf (buf, 1000, "Chat_id %d", msg->chat_id);
  }
  add_string_line (buf, len);
  end_line ();*/
}
Example #7
0
void Writer::new_line() {
  end_line();
  begin_line();
}