static int draw_double_component (ModeInfo *mi, int i) { int count = draw_component (mi, i, 0); glFrontFace(GL_CCW); glScalef (1, 1, -1); count += draw_component (mi, i, 0); glScalef (1, 1, -1); glFrontFace(GL_CW); return count; }
void draw_component(int origin_x, int origin_y, component *comp) { int x = comp->x+origin_x; int y = comp->y+origin_y; if (comp->hidden == 0) { set_style(comp->style); set_color(comp->color); set_bgcolor(comp->bgcolor); draw(x, y, comp->resource); } if (comp->next != NULL) { draw_component(origin_x, origin_y, comp->next); } if (comp->child != NULL) { draw_component(x, y, comp->child); } }
static int draw_fin_edge_half (ModeInfo *mi, flapper *f) { int count = 0; glPushMatrix(); count += draw_component (mi, SPLITFLAP_FIN_EDGE_HALF); glPopMatrix(); return count; }
static int draw_disc_quarter (ModeInfo *mi, flapper *f) { int count = 0; glPushMatrix(); count += draw_component (mi, SPLITFLAP_DISC_QUARTER); glPopMatrix(); return count; }
static int draw_frame_quarter (ModeInfo *mi, flapper *f) { int count = 0; glPushMatrix(); count += draw_component (mi, SPLITFLAP_QUARTER_FRAME); glPopMatrix(); return count; }
static int draw_fin_face_half (ModeInfo *mi, flapper *f) { int count = 0; if (MI_IS_WIREFRAME(mi)) return 0; glPushMatrix(); count += draw_component (mi, SPLITFLAP_FIN_FACE_HALF); glPopMatrix(); return count; }
static int draw_camera_1 (ModeInfo *mi, camera *c) { int count = 0; GLfloat scale = 0.01; GLfloat color[4] = { 1, 0, 0, 1 }; glPushMatrix(); glTranslatef (c->pos.x, c->pos.y, c->pos.z); glScalef (scale, scale, scale); glRotatef (90, 1, 0, 0); glRotatef (-90, 0, 1, 0); count += draw_double_component (mi, CAMERA_MOUNT); glRotatef (-c->facing, 0, 1, 0); glRotatef (-c->pitch, 0, 0, 1); count += draw_double_component (mi, CAMERA_HINGE); if (c->state == WARM_UP) { if (c->tick < 0.2) glTranslatef ((0.2 - c->tick) / (scale * 3), 0, 0); } if (c->state == ZOT) { glTranslatef ((0.005 - frand(0.01)) / scale, (0.005 - frand(0.01)) / scale, (0.005 - frand(0.01)) / scale); } count += draw_double_component (mi, CAMERA_BODY); if (c->state == ZOT) { glTranslatef ((0.005 - frand(0.01)) / scale, (0.005 - frand(0.01)) / scale, (0.005 - frand(0.01)) / scale); } count += draw_double_component (mi, CAMERA_CAP); switch (c->state) { case IDLE: break; case WARM_UP: color[0] = 1.0 - c->tick; break; case ZOT: color[0] = 1.0; break; case COOL_DOWN: color[0] = c->tick; break; default: abort(); break; } count += draw_component (mi, CAMERA_LENS, (c->state == IDLE ? 0 : color)); # ifdef DEBUG if (debug_p && c->state != ZOT) { glDisable (GL_LIGHTING); glColor3f (1, 1, 0); glBegin (GL_LINES); glVertex3f (0, BEAM_ZOFF / scale, 0); glVertex3f (-100 / scale, BEAM_ZOFF / scale, 0); glEnd(); if (!MI_IS_WIREFRAME(mi)) glEnable (GL_LIGHTING); } # endif glPopMatrix(); return count; }
ENTRYPOINT void draw_splitflap (ModeInfo *mi) { splitflap_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *bp->glx_context); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); glRotatef(current_device_rotation(), 0, 0, 1); glScalef (0.1, 0.1, 0.1); /* because of gluLookAt */ { double x, y, z; get_position (bp->rot, &x, &y, &z, !bp->button_down_p); glTranslatef((x - 0.5) * 8, (y - 0.5) * 8, (z - 0.5) * 8); gltrackball_rotate (bp->trackball); if (face_front_p) { double maxx = 120; double maxy = 60; double maxz = 45; get_position (bp->rot2, &x, &y, &z, !bp->button_down_p); if (bp->spinx) glRotatef (maxy/2 - x*maxy, 1, 0, 0); if (bp->spiny) glRotatef (maxx/2 - y*maxx, 0, 1, 0); if (bp->spinz) glRotatef (maxz/2 - z*maxz, 0, 0, 1); } else { get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); glRotatef (x * 360, 1, 0, 0); glRotatef (y * 360, 0, 1, 0); glRotatef (z * 360, 0, 0, 1); } } /* Fit the whole grid on the screen */ { GLfloat r = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); int cells = (grid_width > grid_height ? grid_width * r : grid_height); GLfloat s = 8; # ifdef HAVE_MOBILE s *= 2; /* #### What. Why is this necessary? */ #endif s /= cells; glScalef (s, s, s); } mi->polygon_count = 0; mi->polygon_count += draw_component (mi, SPLITFLAP_OUTER_FRAME); { GLfloat xoff = (bp->clock_p == 12 ? COLON_WIDTH * 3 : bp->clock_p == 24 ? COLON_WIDTH * 2 : 0); glTranslatef (1 - (grid_width + xoff), 1 - grid_height, 0); } /* We must render all text after all polygons, or alpha blending doesn't work right. */ draw_flappers (mi, False); draw_flappers (mi, True); glPopMatrix (); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
static gboolean draw_callback(GtkWidget *widget,cairo_t *cr,gpointer data) { guint width=gtk_widget_get_allocated_width(widget); guint height=gtk_widget_get_allocated_height(widget); double sw,sh,spacing; //PangoLayout* pn=gtk_widget_create_pango_layout(widget,"HELLO? IS THIS WORKING?(\u2126)"); PangoContext* pc=gtk_widget_get_pango_context(widget); PangoLayout* pn=pango_layout_new(pc); sw=((double)width-2*gutter)/grid.width; sh=((double)height-2*gutter)/grid.height; spacing=MIN(sw,sh); cairo_set_source_rgb(cr,0,0,255); // cairo_arc(cr,mouseX,mouseY,5,0,2*G_PI); cairo_translate(cr,(double)width/2,(double)height/2); cairo_translate(cr,-(double)grid.width/2.0*spacing,-(double)grid.height/2.0*spacing); int i,j; cairo_set_source_rgb(cr,0,0,0); for(i=0;i<grid.map.ccount;i++) { Component* c=grid.map.components+i; int A=c->A; int B=c->B; draw_component(cr,pc,spacing,spacing*(A%(grid.width+1)),spacing*(A/(grid.width+1)),spacing*(B%(grid.width+1)),spacing*(B/(grid.width+1)),c); } cairo_set_source_rgb(cr,0,0,0); char buffer[20]; for(i=0;i<=grid.width;i++) { for(j=0;j<=grid.height;j++) { if(draw_flags&VOLTAGES){ sprintf(buffer,"%.2fV",grid.map.vertices[i+j*(grid.width+1)].voltage); pango_layout_set_text(pn,buffer,-1); int w,h; pango_layout_get_pixel_size(pn,&w,&h); cairo_arc(cr,i*spacing,j*spacing,25,0,2*G_PI); cairo_set_source_rgb(cr,1.0,1.0,1.0); cairo_fill_preserve(cr); cairo_set_source_rgb(cr,0.0,0.0,0.0); cairo_stroke(cr); cairo_move_to(cr,i*spacing-w/2,j*spacing-h/2); pango_cairo_update_layout(cr,pn); pango_cairo_show_layout(cr,pn); cairo_new_path(cr); /* sprintf(buffer,"%gV",grid.map.vertices[i+j*(grid.width+1)].voltage); pango_layout_set_text(pn,buffer,-1); int w,h; pango_layout_get_pixel_size(pn,&w,&h); cairo_arc(cr,i*spacing,j*spacing,w/2,0,2*G_PI); cairo_set_source_rgb(cr,1.0,1.0,1.0); cairo_fill_preserve(cr); cairo_set_source_rgb(cr,0.0,0.0,0.0); cairo_stroke(cr); cairo_move_to(cr,i*spacing-w/2,j*spacing-h/2); pango_cairo_update_layout(cr,pn); pango_cairo_show_layout(cr,pn); cairo_new_path(cr);*/ }else{ cairo_arc(cr,i*spacing,j*spacing,2,0,2*G_PI); cairo_set_source_rgb(cr,1.0,1.0,1.0); cairo_fill_preserve(cr); cairo_set_source_rgb(cr,0.0,0.0,0.0); cairo_stroke(cr); } } } //pango_cairo_show_layout(cr,pn); return FALSE; }