示例#1
0
文件: daemon.c 项目: CurlyMoo/Splash
void main_draw_shape(struct template_t *tmp_tpl) {
	char *sval = NULL;
	if(template_get_setting_string(tmp_tpl, "shape", &sval) == 0) {
		int filled = 0, x = 0, y = 0, width = fb_width(), height = fb_height(), border = 0, fcolor = 0;
		int x1 = 0, x2 = 0, y1 = 0, y2 = 0, radius = 0, thickness = 1, zindex = 0;
		unsigned short *color = NULL;

		if(strcmp(sval, "rectangle") == 0 || strcmp(sval, "circle") == 0) {
			template_get_setting_number(tmp_tpl, "x", &x);
			template_get_setting_number(tmp_tpl, "y", &y);
			template_get_setting_number(tmp_tpl, "border", &border);
			template_get_setting_number(tmp_tpl, "filled", &filled);
		} else if(strcmp(sval, "line") == 0) {
			template_get_setting_number(tmp_tpl, "x1", &x1);
			template_get_setting_number(tmp_tpl, "x2", &x2);
			template_get_setting_number(tmp_tpl, "y1", &y1);
			template_get_setting_number(tmp_tpl, "y2", &y2);
			template_get_setting_number(tmp_tpl, "thickness", &thickness);
		}
		if(strcmp(sval, "rectangle") == 0) {
			template_get_setting_number(tmp_tpl, "width", &width);
			template_get_setting_number(tmp_tpl, "height", &height);
		} else if(strcmp(sval, "circle") == 0) {
			template_get_setting_number(tmp_tpl, "radius", &radius);
		}

		if(template_get_setting_color(tmp_tpl, "color", &color) != 0) {
			color = malloc(sizeof(unsigned short)*3);
			color[0] = 0, color[1] = 0, color[2] = 0;
			fcolor = 1;
		}

		template_get_setting_number(tmp_tpl, "z-index", &zindex);

		if(nodaemon == 0) {
			if(strcmp(sval, "rectangle") == 0) {
				if(filled) {
					draw_rectangle_filled(x, y, zindex, width, height, draw_color(color[0], color[1], color[2]));
				} else {
					draw_rectangle(x, y, zindex, width, height, border, draw_color(color[0], color[1], color[2]));
				}
			} else if(strcmp(sval, "circle") == 0) {
				if(filled) {
					draw_circle_filled(x, y, zindex, radius, draw_color(color[0], color[1], color[2]));
				} else {
					draw_circle(x, y, zindex, radius, border, draw_color(color[0], color[1], color[2]));
				}
			} else if(strcmp(sval, "line") == 0) {
				draw_line(x1, y1, x2, y2, zindex, thickness, draw_color(color[0], color[1], color[2]));
			}
		}
		if(fcolor) {
			free(color);
		}
	}
}
示例#2
0
// draws the player to the screen
void Player::drawPlayer() {
	set_fill_color(WHITE);

	int size = this->size;
	int xSize = this->facingEast ? size : size * -1;
	int x = this->pos.x;
	int y = this->pos.y;

	// draw the bill
	Point billP1 = Point::Point(x - xSize, y - size / 2);
	Point billP2 = Point::Point(x + xSize / 2, y - size);
	draw_rectangle_filled(billP1, billP2);

	// draw the head
	draw_square(x, y - size, size / 2);

	// draw the eyes
	draw_circle_filled(x - xSize / 4, y - (size * 12 / 11), size / 8);
	draw_circle_filled(x + xSize / 8, y - (size * 12 / 11), size / 8);

	// draw the left arm
	draw_square(x - xSize, y, size / 2);

	// draw the right arm
	draw_square(x + xSize, y, size / 2);

	// draw the left foot
	Point leftFootP1 = Point::Point(x - xSize, y + size);
	Point leftFootP2 = Point::Point(x + (xSize * 1/10), y + (size * 12/10));
	draw_rectangle_filled(leftFootP1, leftFootP2);

	// draw the right arm
	Point rightFootP1 = Point::Point(x + xSize, y + size);
	Point rightFootP2 = Point::Point(x + (xSize * 1/10), y + (size * 12/10));
	draw_rectangle_filled(rightFootP1, rightFootP2);
}
示例#3
0
void GLUTSimLightController::draw() {
  int w = glutGet(GLUT_WINDOW_WIDTH);
  int h = glutGet(GLUT_WINDOW_HEIGHT);
  float light_position[4] = {0.0, 0.0, -1.0, 0.0};

  glViewport(0, 0, w, h);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(35, (double) w/h, 0.1, 100.0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glClearColor(0, 0, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glTranslatef(0, 0, -3);

  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_POINT_SMOOTH);

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glEnable(GL_LIGHT0);
  glEnable(GL_NORMALIZE);

  struct Light {
    float radius;
    float color[3];
    float position[2];
  } lights[4] = {
    { .2, {  0, 0,.8 }, { -.5, -.5 } },
    { .2, { .8, 0, 0 }, {  .5, -.5 } },
    { .2, {  0,.8, 0 }, {  .5,  .5 } },
    { .2, { .9,.9,.9 }, { -.5,  .5 } },
  };
  for (unsigned i = 0; i != 4; ++i) {
    Light &l = lights[i];

    if (lights_enabled[i]) {
      glColor3fv(l.color);
      draw_circle_filled(l.position[0], l.position[1], l.radius);
    }
  }

  // Draw the beat monitor.
  const double beat_monitor_dim_time = .05;
  double elapsed = get_elapsed_time_in_seconds();
  if (elapsed - last_beat_time <= beat_monitor_dim_time) {
    double v = 1 - (elapsed - last_beat_time) / beat_monitor_dim_time;
    glColor3f(v, v, v);
    glRectf(-.9, -.9, -.7, -.8);
  }

  // Draw the 2D overlays.
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, w, 0, h, -1, 1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  const int textHeight = 15;
  char buffer[256];
  int y = 0;
  sprintf(buffer, "Time: %.4fs\n", elapsed);
  glColor3f(1, 1, 1);
  glutDrawString(10, 10 + textHeight*y++, buffer);

  if (true) {
    num_frames++;
    double fps = num_frames / elapsed;
    sprintf(buffer, "FPS: %.4fs\n", fps);
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    double bpm = light_manager->GetRecentBPM();
    sprintf(buffer, "BPM: %.4fs\n", bpm);
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    sprintf(buffer, "Program: %s\n", light_manager->GetProgramName().c_str());
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  if (light_manager) {
    sprintf(buffer, "Strobe Enabled: %s\n",
            light_manager->GetStrobeEnabled() ? "yes" : "no");
    glColor3f(1, 1, 1);
    glutDrawString(10, 10 + textHeight*y++, buffer);
  }

  glFlush();

  glutSwapBuffers();
}