void GUIDrawBorder(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 outLeft, Uint32 inLeft, Uint32 outRight, Uint32 inRight, bool topLeft){ if(outLeft!=0){ vlineColor(dst,x1,y1,y2-1,outLeft); hlineColor(dst,x1,x2-1,y1,outLeft); } if(inLeft!=0){ vlineColor(dst,x1+1,y1+1,y2-2,inLeft); hlineColor(dst,x1+1,x2-2,y1+1,inLeft); } if(outRight!=0){ vlineColor(dst,x2,y1+1,y2,outRight); hlineColor(dst,x1+1,x2-1,y2,outRight); } if(inRight!=0){ vlineColor(dst,x2-1,y1+2,y2-1,inRight); hlineColor(dst,x1+2,x2-2,y2-1,inRight); } if(topLeft){ outRight=outLeft; inRight=inLeft; } pixelColor(dst,x2,y1,outRight); pixelColor(dst,x1,y2,outRight); pixelColor(dst,x1+1,y2-1,inRight); pixelColor(dst,x2-1,y1+1,inRight); }
void GUICheckBox::Draw(SDL_Surface *dst){ if(isCircle){ int rad = ((posX2-posX1<posY2-posY1)?(posX2-posX1):(posY2-posY1))-7; filledCircleColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,0xFFFFFFFF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,135,315,0x000000FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad+1,135,315,0x808080FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,315,135,0xD4D0C8FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad+1,315,135,0xFFFFFFFF); if(isChecked)filledCircleColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad-3,0x000000FF); }else{ boxColor(dst,posX1,posY1,posX2,posY2,0xFFFFFFFF); GUIDrawBorder(dst,posX1,posY1,posX2,posY2,0x808080FF,0x404040FF,0xFFFFFFFF,0xD4D0C8FF); if(isChecked){ int tickX=((posX2+posX1)/2)-2,tickY=((posY2+posY1)/2)-3; Uint32 clr=0x000000FF; boxColor(dst,tickX+1,tickY+4,tickX+3,tickY+5,clr); boxColor(dst,tickX+4,tickY+2,tickX+5,tickY+3,clr); vlineColor(dst,tickX,tickY+2,tickY+4,clr); vlineColor(dst,tickX+6,tickY,tickY+2,clr); pixelColor(dst,tickX+1,tickY+3,clr); pixelColor(dst,tickX+3,tickY+3,clr); pixelColor(dst,tickX+4,tickY+4,clr); pixelColor(dst,tickX+5,tickY+1,clr); pixelColor(dst,tickX+2,tickY+6,clr); } } }
/* Here we draw the vectorscope layout */ void make_vectorscope_layout() { int i, p1_x, p1_y, p2_x, p2_y; double temp; char text[4]; boxColor(screen, vector_x-130, vector_y+130, vector_x+130, vector_y-130, black); hlineColor(screen, vector_x-20, vector_x-128, vector_y, white); hlineColor(screen, vector_x+20, vector_x+128, vector_y, white); vlineColor(screen, vector_x, vector_y-20, vector_y-128, white); vlineColor(screen, vector_x, vector_y+20, vector_y+128, white); circleColor(screen,vector_x, vector_y, 20, white); circleColor(screen,vector_x, vector_y, 50, white); circleColor(screen,vector_x, vector_y, 80, white); circleColor(screen,vector_x, vector_y,112, white); for (i =0; i<36; i++) { /* Here we draw the degree scale */ temp = 112* cos (i*(10/57.3)) ; /* sin & cos only accept radiant */ p1_x = round(temp); /* and not degree input */ temp = 112* sin (i*(10/57.3) ); p1_y = round(temp); temp = 117* cos (i*(10/57.3) ); p2_x = round(temp); temp = 117* sin (i*(10/57.3) ); p2_y = round(temp); lineColor(screen, vector_x + p1_x, vector_y + p1_y, vector_x + p2_x, vector_y + p2_y, white); } sprintf(text, "0"); /* Creating the grad description */ stringColor(screen, vector_x + 135 , vector_y - 3, text, white); sprintf(text, "90"); stringColor(screen, vector_x - 7 , vector_y - 145, text, white); sprintf(text, "180"); stringColor(screen, vector_x - 155 , vector_y - 3, text, white); sprintf(text, "270"); stringColor(screen, vector_x - 10 , vector_y + 135, text, white); makepoint( 90, 60); /* length, arc, for purple */ makepoint( 96, 104); /* length, arc, for red */ makepoint( 67, 166); /* length, arc, for yellow */ makepoint( 90, 241); /* length, arc, for green */ makepoint( 96, 283); /* length, arc, for cyan */ makepoint( 67, 346); /* length, arc, for blue */ }
static PyObject* _gfx_vlinecolor (PyObject *self, PyObject* args) { PyObject *surface, *color; int x, _y1, y2; pguint32 c; ASSERT_VIDEO_INIT (NULL); if (!PyArg_ParseTuple (args, "OiiiO:vline", &surface, &x, &_y1, &y2, &color)) return NULL; if (!PySDLSurface_Check (surface)) { PyErr_SetString (PyExc_TypeError, "surface must be a Surface"); return NULL; } if (!ColorFromObj (color, &c)) return NULL; if (vlineColor (((PySDLSurface*)surface)->surface, (Sint16) x, (Sint16)_y1, (Sint16)y2, (Uint32)c) == -1) { PyErr_SetString (PyExc_PyGameError, SDL_GetError ()); return NULL; } Py_RETURN_NONE; }
void Draw_Geometry() { int flag = 1; SDL_FillRect(WINDOW, NULL, 0xffffffff); while( flag ){ switch( rand() % 7 ){ case 0: hlineColor(WINDOW, AXIS, AXIS, AXIS, COLOR); break; case 1: vlineColor(WINDOW, AXIS, AXIS, AXIS, COLOR); break; case 2: rectangleColor(WINDOW, AXIS, AXIS, AXIS, AXIS, COLOR); break; case 3: lineColor(WINDOW, AXIS, AXIS, AXIS, AXIS, COLOR); break; case 4: circleColor(WINDOW, AXIS, AXIS, AXIS, COLOR); break; case 5: pieColor(WINDOW, AXIS, AXIS, AXIS, THETA, THETA, COLOR); break; case 6: trigonColor(WINDOW, AXIS, AXIS, AXIS, AXIS, AXIS, AXIS, COLOR); break; default: break; } SDL_UpdateRect(WINDOW, 0, 0, 0, 0); printf("again->'a' reset->'r' exit->'e'\n"); char ch = getchar(), c = getchar(); switch( ch ){ case 'a': flag = 1; break; case 'r': SDL_FillRect(WINDOW, NULL, 0xffffffff); break; case 'e': flag = 0; break; default : flag = 1; break; } } }
static void label_wlan_channels(SDL_Surface *s, int sx, int x0, int y0) { int x, xb, y, i, c; xb = x0; y = s->h-y0+4; for (i = 0; i != wlan_channels(); i++) { c = i+1; /* Japan special channel: 22 MHz from channel 13 */ if (c == 14) xb += X_STEP*12/5-X_STEP; if (c > 9) { x = xb; digit(s, c/10, CWLAN(0)); } else { x = xb-3; } digit(s, c % 10, CWLAN(1)); if (show_wlan_channel(c)) { hlineColor(s, xb-WLAN_XR, xb+WLAN_XR, y-WLAN_YH, WLAN_RGBA); vlineColor(s, xb, y-2, y-WLAN_YH+1, WLAN_RGBA); } xb += sx; } }
int GeoLayer::vline(int16_t x, int16_t y1, int16_t y2, uint32_t col) { if(!surf) { error("%s can't run: layer not initialized", __PRETTY_FUNCTION__); return -1; } res = vlineColor(surf, x, y1, y2, col); if(res < 0) error("error in %s", __PRETTY_FUNCTION__); return(res); }
/* Here we draw the layout of the histogram */ void draw_histogram_layout(int x_off, int y_off) { int i, offset; char text[3]; hlineColor(screen, x_off, x_off+257, y_off+101 , white); vlineColor(screen, x_off-1, y_off, y_off+101, white); vlineColor(screen, x_off+257,y_off,y_off+101, white); if (scalepercent == 0) { for (i = 0; i < 15; i++) { offset = i*16+ 16; vlineColor(screen, x_off+offset, y_off+101, y_off+105, white); } vlineColor(screen, x_off+128, y_off+106, y_off+110, white); /* Description of the axis */ stringColor(screen, x_off-5 +16 , y_off+115, "16", white); stringColor(screen, x_off-9 +128, y_off+115, "128", white); stringColor(screen, x_off-9 +240, y_off+115, "240", white); } else { for (i =0; i< 11;i++) { offset = (int)i*21.9 + 16; vlineColor(screen, x_off+offset, y_off+101, y_off+105, white); } } for (i = 0; i < 6; i++) /*Labeling the y axis in percent */ { hlineColor(screen, x_off-5, x_off, y_off+ i*20, white); offset = 100- i*20; sprintf(text, "%i", offset); stringColor(screen, x_off-30 , y_off+ i*20 -3 , text, white); } }
//------------------------------------------------------------ ShowFixation() // void ShowFixation() { hlineColor(screen, (int)(FIXATION_X - FIXATION_WIDTH / 2), \ (int)(FIXATION_X + FIXATION_WIDTH / 2), \ FIXATION_Y, RGBA_White); vlineColor(screen, FIXATION_X, (int)(FIXATION_Y - FIXATION_HEIGHT / 2), \ (int)(FIXATION_Y + FIXATION_HEIGHT / 2), \ RGBA_White); }
/* * vykresluje mrizku hraciho pole */ int drawBorder(SDL_Surface *screen) { SDL_FillRect(screen, NULL, BLACK); for(int i = 1; i < MAXX+1; ++i) { hlineColor(screen, 0, MAXY * FIELD_SIZE, i * FIELD_SIZE, 0xffffff50); } for(int i = 1; i < MAXY; ++i) { vlineColor(screen, i * FIELD_SIZE, 0, MAXX * FIELD_SIZE, 0xffffff50); } SDL_UpdateRect(screen, 0,0,0,0); return 0; }
//------------------------------------------------------------ ShowFixation() // void ShowFixation() { //-TODO- Sustituir este metodo por uno basado en pintar rectángulos // de ancho configurable por una constante en ior.h hlineColor(screen, (int)(FIXATION_X - FIXATION_WIDTH / 2), \ (int)(FIXATION_X + FIXATION_WIDTH / 2), \ FIXATION_Y, RGBA_White); vlineColor(screen, FIXATION_X, (int)(FIXATION_Y - FIXATION_HEIGHT / 2), \ (int)(FIXATION_Y + FIXATION_HEIGHT / 2), \ RGBA_White); }
void GUITextBox::Draw(SDL_Surface *dst){ boxColor(dst,posX1,posY1,posX2,posY2,fontBackColor); renderedText.Blit(dst,textX1,textY1,textX2-textX1,textY2-textY1,false,false,curOffX,curOffY); rectangleColor(dst,posX1,posY1,posX2,posY2,BORDER); if(CursorBlink())boxColor(dst,curDrawX,curDrawY,curDrawX,curDrawY+curDrawH,0x330000FF); if(showScroll){ scrollX.Draw(dst); scrollY.Draw(dst); } if(showPointer){ vlineColor(dst,mouseX,mouseY-6,mouseY+6,0x00000080); hlineColor(dst,mouseX-3,mouseX+3,mouseY-7,0x00000080); hlineColor(dst,mouseX-3,mouseX+3,mouseY+7,0x00000080); } }
void BCursor::paint() { if(screen){ if(visible){ vlineColor(screen,x,y,y+height-1,cursor_color); SDL_UpdateRect(screen,x,y,COURSOR_WIDTH,height); visible=false; }else { resume(); visible=true; } } }
/** * Desenhador de RectNoScrolling retirado da SDL_gfx mais nova. */ int Sprite::drawRoundRectNoScrolling(Rectangle rect, int r, int g, int b, int a, int rad, Screen *screen) { SDL_Surface * dst; Sint16 x1, y1, x2, y2; Uint32 color; int result; dst = screen->getTopScreen(); x1 = rect.x; x2 = rect.x + rect.w; y1 = rect.y; y2 = rect.y + rect.h; color = ((Uint32) r << 24) | ((Uint32) g << 16) | ((Uint32) b << 8) | (Uint32) a; Sint16 w, h, tmp; Sint16 xx1, xx2, yy1, yy2; /* * Check destination surface */ if (dst == NULL) { return -1; } /* * Check radius vor valid range */ if (rad < 0) { return -1; } /* * Special case - no rounding */ if (rad == 0) { return rectangleColor(dst, x1, y1, x2, y2, color); } /* * Check visibility of clipping rectangle */ if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) { return 0; } /* * Test for special cases of straight lines or single point */ if (x1 == x2) { if (y1 == y2) { return (pixelColor(dst, x1, y1, color)); } else { return (vlineColor(dst, x1, y1, y2, color)); } } else { if (y1 == y2) { return (hlineColor(dst, x1, x2, y1, color)); } } /* * Swap x1, x2 if required */ if (x1 > x2) { tmp = x1; x1 = x2; x2 = tmp; } /* * Swap y1, y2 if required */ if (y1 > y2) { tmp = y1; y1 = y2; y2 = tmp; } /* * Calculate width&height */ w = x2 - x1; h = y2 - y1; /* * Maybe adjust radius */ if ((rad * 2) > w) { rad = w / 2; } if ((rad * 2) > h) { rad = h / 2; } /* * Draw corners */ result = 0; xx1 = x1 + rad; xx2 = x2 - rad; yy1 = y1 + rad; yy2 = y2 - rad; result |= arcColor(dst, xx1, yy1, rad, 180, 270, color); result |= arcColor(dst, xx2, yy1, rad, 270, 360, color); result |= arcColor(dst, xx1, yy2, rad, 90, 180, color); result |= arcColor(dst, xx2, yy2, rad, 0, 90, color); /* * Draw lines */ if (xx1 <= xx2) { result |= hlineColor(dst, xx1, xx2, y1, color); result |= hlineColor(dst, xx1, xx2, y2, color); } if (yy1 <= yy2) { result |= vlineColor(dst, x1, yy1, yy2, color); result |= vlineColor(dst, x2, yy1, yy2, color); } return 1; }
void render_decorations(slide *sl) { int x1, y1; int below, above; SDL_Rect dst; style *st = sl->st; Uint32 border_pen = colour->pens->item(st->bordercolour); free_decorations(sl); below = sl->deck_size - sl->card; above = sl->card - 1; if(below > 0) { sl->decor.top = alloc_surface(sl->scr_w, CARD_EDGE * below); sl->decor.right = alloc_surface(CARD_EDGE * below, sl->scr_h + CARD_EDGE * below); clear_surface(sl->decor.top, colour->grey_fill); clear_surface(sl->decor.right, colour->grey_fill); for(int i = 0; i < below; i++) { // Top edge: x1 = CARD_EDGE * (i + 1); y1 = CARD_EDGE * (below - i - 1); dst.x = x1; dst.y = y1; dst.w = sl->scr_w - x1; dst.h = CARD_EDGE; SDL_FillRect(sl->decor.top, &dst, st->enablebar ? colour->fills->item(st->barcolour) : colour->fills->item(st->bgcolour)); for(int j = 0; j < st->slideborder; j++) { hlineColor(sl->decor.top, x1 + j, sl->scr_w - 1, y1 + j, border_pen); vlineColor(sl->decor.top, x1 + j, y1 + j, y1 + CARD_EDGE - 1, border_pen); } // Top-right corner: x1 = 0; y1 = CARD_EDGE * (below - i - 1); dst.x = x1; dst.y = y1; dst.w = CARD_EDGE * i; dst.h = CARD_EDGE; SDL_FillRect(sl->decor.right, &dst, st->enablebar ? colour->fills->item(st->barcolour) : colour->fills->item(st->bgcolour)); for(int j = 0; j < st->slideborder; j++) { hlineColor(sl->decor.right, 0, CARD_EDGE * (i + 1) - 1, y1 + j, border_pen); } // Right edge: x1 = CARD_EDGE * i; y1 = CARD_EDGE * (below - i - 1); dst.x = x1; dst.y = y1 + st->slideborder; dst.w = CARD_EDGE; dst.h = sl->scr_h - st->slideborder; SDL_FillRect(sl->decor.right, &dst, colour->fills->item(st->bgcolour)); for(int j = 0; j < st->slideborder; j++) { vlineColor(sl->decor.right, x1 + CARD_EDGE - 1 - j, y1, y1 + sl->scr_h - 1, border_pen); hlineColor(sl->decor.right, x1, x1 + CARD_EDGE - 1, y1 + sl->scr_h - 1 - j, border_pen); } // Titlebar area: if(st->enablebar) { x1 = CARD_EDGE * i; y1 = CARD_EDGE * (below - i - 1) + st->slideborder; dst.x = x1; dst.y = y1; dst.w = CARD_EDGE - st->slideborder; dst.h = to_screen_coords(st->titlespacing - TITLE_EDGE) - st->slideborder; SDL_FillRect(sl->decor.right, &dst, colour->fills->item(st->barcolour)); } // Dividing line below bar: x1 = CARD_EDGE * i; y1 = CARD_EDGE * (below - i - 1); if(st->enablebar) { for(int j = 0; j < st->barborder; j++) { hlineColor(sl->decor.right, x1, x1 + CARD_EDGE - 1, y1 + to_screen_coords(st->titlespacing - TITLE_EDGE - 1) + j, colour->pens->item(st->bordercolour)); } } } } if(above > 0) { sl->decor.left = alloc_surface(CARD_EDGE * above, sl->scr_h + CARD_EDGE * above); sl->decor.bottom = alloc_surface(sl->scr_w, CARD_EDGE * above); clear_surface(sl->decor.left, colour->grey_fill); clear_surface(sl->decor.bottom, colour->grey_fill); for(int i = 0; i < above; i++) { // Bottom edge: x1 = 0; y1 = CARD_EDGE * i; dst.x = x1; dst.y = y1; dst.w = sl->scr_w - CARD_EDGE * (i + 1); dst.h = CARD_EDGE; SDL_FillRect(sl->decor.bottom, &dst, colour->light_grey_fill); for(int j = 0; j < st->slideborder; j++) { hlineColor(sl->decor.bottom, 0, sl->scr_w - CARD_EDGE * (i + 1) - 1, y1 + CARD_EDGE - 1 - j, border_pen); vlineColor(sl->decor.bottom, sl->scr_w - CARD_EDGE * (i + 1) - 1 - j, y1, y1 + CARD_EDGE - 1, border_pen); } // Bottom-left corner: x1 = CARD_EDGE * (above - i - 1); y1 = sl->scr_h + CARD_EDGE * i; dst.x = x1; dst.y = y1; dst.w = (i + 1) * CARD_EDGE; dst.h = CARD_EDGE; SDL_FillRect(sl->decor.left, &dst, colour->light_grey_fill); // Left edge: x1 = CARD_EDGE * (above - i - 1); y1 = CARD_EDGE * (i + 1); dst.x = x1; dst.y = y1; dst.w = CARD_EDGE; dst.h = sl->scr_h; SDL_FillRect(sl->decor.left, &dst, colour->light_grey_fill); for(int j = 0; j < st->slideborder; j++) { hlineColor(sl->decor.left, x1, x1 + CARD_EDGE - 1, y1 + j, border_pen); hlineColor(sl->decor.left, x1, x1 + (i + 1) * CARD_EDGE - 1, y1 + sl->scr_h - 1 - j, border_pen); vlineColor(sl->decor.left, x1 + j, y1, y1 + sl->scr_h - 1, border_pen); } } } }
void digit(SDL_Surface *s, int n, int x0, int x1, int y0, int ym, int y1, uint32_t fg) { switch (n) { case 8: hlineColor(s, x0, x1, ym, fg); /* fall through */ case 0: hlineColor(s, x0, x1, y0, fg); vlineColor(s, x0, y0, y1, fg); /* fall through */ case 7: hlineColor(s, x0, x1, y1, fg); vlineColor(s, x1, y0, y1, fg); break; case 1: lineColor(s, x0, ym, x1, y1, fg); vlineColor(s, x1, y0, y1, fg); break; case 2: hlines_3(s, x0, x1, y0, ym, y1, fg); vlineColor(s, x0, y0, ym, fg); vlineColor(s, x1, ym, y1, fg); break; case 9: vlineColor(s, x0, ym, y1, fg); /* fall through */ case 3: hlines_3(s, x0, x1, y0, ym, y1, fg); vlineColor(s, x1, y0, y1, fg); break; case 4: hlineColor(s, x0, x1, ym, fg); vlineColor(s, x0, ym, y1, fg); vlineColor(s, x1, y0, y1, fg); break; case 6: hlines_3(s, x0, x1, y0, ym, y1, fg); vlineColor(s, x0, y0, y1, fg); vlineColor(s, x1, y0, ym, fg); break; case 5: hlines_3(s, x0, x1, y0, ym, y1, fg); vlineColor(s, x0, ym, y1, fg); vlineColor(s, x1, y0, ym, fg); break; default: abort(); } }
void highlight(slide *sl, int viewx, int viewy, int scale) { int x1, y1, x2, y2; int clearance, extent, thickness; if(scale == 1) { thickness = 5; clearance = 9; extent = 90; } else if(scale == 3) { thickness = 3; clearance = 5; extent = 40; } else if(scale == 9) { thickness = 2; clearance = 2; extent = 20; } else { error("Impossible case in highlight()"); exit(-1); } if(extent > sl->scr_w / scale) extent = sl->scr_w / scale; if(extent > sl->scr_h / scale) extent = sl->scr_h / scale; x1 = (sl->x - viewx) / scale - clearance; x2 = (sl->x + sl->scr_w - 1 - viewx) / scale + clearance; y1 = (sl->y - viewy) / scale - clearance; y2 = (sl->y + sl->scr_h - 1 - viewy) / scale + clearance; for(int i = 0; i < thickness; i++) { // Top left: hlineColor(screen, x1 - i, x1 + extent + i, y1 - i, colour->red_pen); vlineColor(screen, x1 - i, y1 - i, y1 + extent + i, colour->red_pen); // Top right: hlineColor(screen, x2 - extent - i, x2 + i, y1 - i, colour->red_pen); vlineColor(screen, x2 + i, y1 - i, y1 + extent + i, colour->red_pen); // Bottom left: hlineColor(screen, x1 - i, x1 + extent + i, y2 + i, colour->red_pen); vlineColor(screen, x1 - i, y2 - extent - i, y2 + i, colour->red_pen); // Bottom right: hlineColor(screen, x2 - extent - i, x2 + i, y2 + i, colour->red_pen); vlineColor(screen, x2 + i, y2 - extent - i, y2 + i, colour->red_pen); } }
void draw_picture(SDL_Surface * sf, double temps[16][4], double t_amb) { int x, y; double maxval = -INFINITY, minval = INFINITY; double f, g; char buf[32]; int range; SDL_Color fg_black = { 0, 0, 0 }; SDL_Color fg_white = { 255, 255, 255 }; SDL_Rect rect; SDL_Surface *txt_sf; SDL_FillRect(sf, NULL, 0); for (y = 0; y < 4; y++) { for (x = 0; x < 16; x++) { if (temps[x][y] > maxval) maxval = temps[x][y]; if (temps[x][y] < minval) minval = temps[x][y]; } } f = maxval - minval; range = (f * RANGE_MULTIPLIER) > 255 ? 255 : f * RANGE_MULTIPLIER; f = range / f; for (y = 0; y < 4; y++) { for (x = 0; x < 16; x++) { Uint32 col = color_from_temp(temps[x][3 - y], f, minval); boxColor(sf, x * PIX_SIZE, y * PIX_SIZE, x * PIX_SIZE + PIX_SIZE - 1, y * PIX_SIZE + PIX_SIZE - 1, col); sprintf(buf, "%3.1f", temps[x][3 - y]); txt_sf = TTF_RenderText_Blended(font, buf, (col >> 24) < 150 ? fg_white : fg_black); rect.w = txt_sf->w; rect.h = txt_sf->h; rect.x = x * PIX_SIZE + 10; if ((temps[x][3 - y] <= -10) || (temps[x][3 - y] >= 100)) rect.x -= 5; rect.y = y * PIX_SIZE + 20; SDL_BlitSurface(txt_sf, NULL, sf, &rect); SDL_FreeSurface(txt_sf); } } f = range; f /= 255; g = 0; for (x = 0; x < 256; x++, g += f) { vlineColor(sf, x + 80, PIX_SIZE * 4, PIX_SIZE * 4 + PIX_SIZE, 0x80ff + (((int)g) << 16) + (((int)g) << 24)); } sprintf(buf, "%3.1f%cC", minval, 0xb0); txt_sf = TTF_RenderText_Blended(font, buf, fg_white); rect.w = txt_sf->w; rect.h = txt_sf->h; rect.x = minval < 0 ? 0 : 10; rect.y = 4 * PIX_SIZE + 30; SDL_BlitSurface(txt_sf, NULL, sf, &rect); SDL_FreeSurface(txt_sf); sprintf(buf, "%3.1f%cC", maxval, 0xb0); txt_sf = TTF_RenderText_Blended(font, buf, fg_white); rect.w = txt_sf->w; rect.h = txt_sf->h; rect.x = 80 + 256 + 10; rect.y = 4 * PIX_SIZE + 30; SDL_BlitSurface(txt_sf, NULL, sf, &rect); SDL_FreeSurface(txt_sf); SDL_Flip(sf); }
/* Show the frame stat */ void make_stat() { int percent_y, percent_u, percent_v, percent_fy, percent_fu, percent_fv; long long num_pixels_y, num_pixels_u, num_pixels_v; long long f_pixels_y, f_pixels_u, f_pixels_v; int peak_y, peak_u, peak_v, peak_fy, peak_fu, peak_fv; int i,j; peak_y = 0; peak_u = 0; peak_v = 0; peak_fy = 0; peak_fu = 0; peak_fv = 0; num_pixels_y = y_stats[0]; num_pixels_u = u_stats[0]; num_pixels_v = v_stats[0]; f_pixels_y = fy_stats[0]; f_pixels_u = fu_stats[0]; f_pixels_v = fv_stats[0]; /* geting the maimal number for all frames */ for (i = 0; i < 255; i++) { /* getting the maximal numbers for Y, U, V for all frames */ if (num_pixels_y < y_stats[i]) { num_pixels_y = y_stats[i]; peak_y = i; } if (num_pixels_u < u_stats[i]) { num_pixels_u = u_stats[i]; peak_u = i; } if (num_pixels_v < v_stats[i]) { num_pixels_v = v_stats[i]; peak_v = i; } /* getting the maximal numbers for Y, U, V for the current frame */ fy_stats[i]= y_stats[i] - ly_stats[i]; ly_stats[i] = y_stats[i]; if (f_pixels_y < fy_stats[i]) { f_pixels_y = fy_stats[i]; peak_fy = i; } fu_stats[i]= u_stats[i] - lu_stats[i]; lu_stats[i] = u_stats[i]; if (f_pixels_u < fu_stats[i]) { f_pixels_u = fu_stats[i]; peak_fu = i; } fv_stats[i]= v_stats[i] - lv_stats[i]; lv_stats[i] = v_stats[i]; if (f_pixels_v < fv_stats[i]) { f_pixels_v = fv_stats[i]; peak_fv = i; } } num_pixels_y = (num_pixels_y /100); num_pixels_u = (num_pixels_u /100); num_pixels_v = (num_pixels_v /100); f_pixels_y = (f_pixels_y /100); f_pixels_u = (f_pixels_u /100); f_pixels_v = (f_pixels_v /100); /* The description for the histogram */ make_histogram_desc(number_of_frames); number_of_frames++; make_vectorscope_layout(); /*draw the vectorscope basic layout*/ clear_histogram_area(); /* Here we delete the old histograms */ make_histogram_stat(peak_y, peak_u, peak_v, sum1_x, stat); make_histogram_stat(peak_fy, peak_fu, peak_fv, frm1_x , stat); for (i = 0; i < 255; i++) { percent_y = (y_stats[i] / num_pixels_y); percent_u = (u_stats[i] / num_pixels_u); percent_v = (v_stats[i] / num_pixels_v); percent_fy = (fy_stats[i] / f_pixels_y); percent_fu = (fu_stats[i] / f_pixels_u); percent_fv = (fv_stats[i] / f_pixels_v); if ((i < 16) || (i > 235)) /* Y luma */ { /* Red means out of the allowed range */ vlineColor(screen,(sum1_x+i),sum1_y+100, ((sum1_y+100)-percent_y),red); vlineColor(screen,(frm1_x+i),frm1_y+100, ((frm1_y+100)-percent_fy),red); } else { vlineColor(screen,(sum1_x+i),sum1_y+100, ((sum1_y+100)-percent_y),gray); vlineColor(screen,(frm1_x+i),frm1_y+100, ((frm1_y+100)-percent_fy),gray); } if ((i < 16) || (i > 240)) /* U V chroma */ { /* Red means out of the allowed range */ vlineColor(screen,(sum2_x+i),sum2_y+100, ((sum2_y+100)-percent_u),red); vlineColor(screen,(sum3_x+i),sum3_y+100, ((sum3_y+100)-percent_v),red); vlineColor(screen,(frm2_x+i),frm2_y+100, ((frm2_y+100)-percent_fu),red); vlineColor(screen,(frm3_x+i),frm3_y+100, ((frm3_y+100)-percent_fv),red); } else { vlineColor(screen,(sum2_x+i),sum2_y+100, ((sum2_y+100)-percent_u),gray); vlineColor(screen,(sum3_x+i),sum3_y+100, ((sum3_y+100)-percent_v),gray); vlineColor(screen,(frm2_x+i),frm2_y+100, ((frm2_y+100)-percent_fu),gray); vlineColor(screen,(frm3_x+i),frm3_y+100, ((frm3_y+100)-percent_fv),gray); } } for (i=0; i < 260; i++) for (j=0; j < 260; j++) if (vectorfield[i][j]== 1) pixelColor(screen, (vector_x+ i- 127), (vector_y+ j- 132) ,red); SDL_UpdateRect(screen,0,0,0,0); }
void WaveDrawBox_vrefresh(void *vthis) { WaveDrawBox *this = WAVE_DRAW_BOX(vthis); if ((! this->sample_freq) || (! this->bunch)) { fprintf(stderr, "WaveDrawBox_vrefresh: Failed on assertion ((! this->sample_freq) || (! this->bunch)) == true\n%s\n", toString(this)); WIDGET(this)->visible = false; return; } this->xrange = this->sample_freq / this->bunch + 1; this->zero_x = this->padx; this->zero_y = WIDGET(this)->pos.h >> 1; WIDGET(this)->pos.w = this->xrange + (this->padx << 1); WIDGET(this)->maxx = WIDGET(this)->pos.x + WIDGET(this)->pos.w; WIDGET(this)->maxy = WIDGET(this)->pos.y + WIDGET(this)->pos.h; if (DEBUG) fprintf(stderr, "WaveDrawBox_vrefresh: [1] %s\n", toString(this)); if (WIDGET(this)->surf) { if (DEBUG) fprintf(stderr, "WaveDrawBox_vrefresh: [2] Surface exists filling with BGCOLOR\n"); if (SDL_FillRect(WIDGET(this)->surf, NULL, WDB_BGCOLOR)) { fprintf(stderr, "WaveDrawBox_vrefresh: [1] Failed to fill background surface (FillRect) %s\n", SDL_GetError()); WIDGET(this)->visible = false; return; } } else { if (DEBUG) fprintf(stderr, "WaveDrawBox_vrefresh: [2] Surface not exists creating\n"); if (! (WIDGET(this)->surf = Static_newSurface(WIDGET(this)->pos.w, WIDGET(this)->pos.h))) { fprintf(stderr, "WaveDrawBox_vrefresh: Failed to fill create background surface (SDL_CreateRGBSurface) %s\n", SDL_GetError()); WIDGET(this)->visible = false; return; } if (DEBUG) fprintf(stderr, "WaveDrawBox_vrefresh: [2] Filling created surface with BGCOLOR\n"); if (SDL_FillRect(WIDGET(this)->surf, NULL, WDB_BGCOLOR)) { fprintf(stderr, "WaveDrawBox_vrefresh: [2] Failed to fill background surface (FillRect) %s\n", SDL_GetError()); WIDGET(this)->visible = false; return; } } /* Draw axes */ u16 y1 = WIDGET(this)->pos.h - this->pady - this->my; u16 x1 = this->padx + this->xrange; this->relx_min = this->zero_x; this->relx_max = x1-1; this->rely_min = this->pady + this->my; this->rely_max = y1; hlineColor(WIDGET(this)->surf, this->padx, x1, WIDGET(this)->pos.h >> 1, WDB_AXES_COLOR); hlineColor(WIDGET(this)->surf, this->padx, x1, this->rely_min, WDB_MAXY_COLOR); hlineColor(WIDGET(this)->surf, this->padx, x1, y1, WDB_MAXY_COLOR); y1 += this->my; vlineColor(WIDGET(this)->surf, this->padx, this->pady, y1, WDB_AXES_COLOR); vlineColor(WIDGET(this)->surf, x1, this->pady, y1, WDB_AXES_COLOR); this->yrange = this->rely_max - this->rely_min; if (this->xrange != (this->relx_max - this->relx_min + 1)) { fprintf(stderr, "WaveDrawBox_vrefresh: Failed on assertion (this->xrange != (this->relx_max - this->relx_min + 1)) == true\n%s\n", toString(this)); WIDGET(this)->visible = false; return; } if ((this->xrange == 0) || (this->xrange >= this->sample_freq)) { fprintf(stderr, "WaveDrawBox_vrefresh: Failed on assertion ((this->xrange == 0) || (this->xrange >= this->sample_freq)) == true\n%s\n", toString(this)); WIDGET(this)->visible = false; return; } if (! this->points) { this->points = calloc(this->xrange, sizeof(wdb_point)); this->afg->points = this->points; this->afg->points_size = this->xrange; } if (! this->samples) { this->samples = calloc(this->sample_freq, sizeof(float)); this->afg->samples = this->samples; this->afg->samples_size = this->sample_freq; } if (DEBUG) { fprintf(stderr, "WaveDrawBox_vrefresh: Final: %s\n", toString(this)); fprintf(stderr, "WaveDrawBox_vrefresh: Surface: %s\n", Static_surfaceToString(WIDGET(this)->surf)); } WIDGET(this)->visible = true; }
void * hax_sdl_main(void *configuration) { hax_thread_config_t * hax_configs = (hax_thread_config_t *) configuration; hax_general_settings_t * hax_user_settings = &hax_configs->user_settings; hax_sdl_data * hax_sound_data = (hax_sdl_data *) hax_configs->data_zone; printf("[SDL] Thread Start!\n"); FPSmanager hax_fps; float displ = 0; SDL_initFramerate(&hax_fps); SDL_setFramerate(&hax_fps, 60); // SDL video initialisation if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); pthread_exit((void *) 1); } atexit(SDL_Quit); SDL_Surface* screen = SDL_SetVideoMode(hax_user_settings->window_w, hax_user_settings->window_h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( !screen ) { printf("Unable to set %i x %i video: %s\n", hax_user_settings->window_w, hax_user_settings->window_h, SDL_GetError()); pthread_exit((void *) 1); } printf("[SDL] Waiting to start...\n"); fflush(stdout); std::cout.flush(); hax_configs->timer->start(); printf("[SDL] Firing Loop!\n"); fflush(stdout); std::cout.flush(); while (*hax_user_settings->message) { hax_configs->timer->wait_next_activation(); hax_configs->timer->stat_execution_start(); // We catch an SDL signal SDL_Event event; while (SDL_PollEvent(&event)) { // If there was any signal switch (event.type) { // We exit if the window is closed case SDL_QUIT: *hax_user_settings->message = false; break; // We also check for keypresses case SDL_KEYDOWN: { // Then we exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) *hax_user_settings->message = false; break; } } } // end of message processing // At first we clear the screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); vlineColor(screen, screen->w / 2, 0, screen->h, 0xffffffff); printf("[SDL] Requiring Locks!\n"); fflush(stdout); std::cout.flush(); // Here we lock the data and then plot amplitude and spectrums hax_sound_data->lock_data(); printf("[SDL] Plotting Sound Data!\n"); fflush(stdout); std::cout.flush(); draw_sound(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_sound_channel(), hax_sound_data->get_right_sound_channel(), (screen->h)/7, (screen->h)/7, 0xff00ffff); draw_real_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_right_spectrum(), (screen->h*7)/14, ((screen->h)/14), (char *)"Right", 0x00ffffff ); draw_imaginary_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_right_spectrum(), (screen->h*9)/14, ((screen->h)/14), (char *)"Right", 0x00ffffff ); draw_real_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_spectrum(), (screen->h*11)/14, ((screen->h)/14), (char *)"Left", 0x00ffffff); draw_imaginary_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_spectrum(), (screen->h*13)/14, ((screen->h)/14), (char *)"Left", 0x00ffffff ); printf("[SDL] Releasing Locks!\n"); fflush(stdout); std::cout.flush(); hax_sound_data->unlock_data(); // Finally, we update the screen SDL_Flip(screen); displ ++; hax_configs->timer->stat_update(); } printf("Exited cleanly\n"); // Printing Thread Statistics hax_configs->timer->stats_print(); pthread_exit((void *) 0); }