void render_content(unsigned char *buffer, const char *content) { /* Frame */ render_rectangle(buffer, TITLE_HEIGHT + 8, 4, LINES * SYMBOL_HEIGHT + 3, COLUMNS * SYMBOL_WIDTH + 2, BLACK); /* Area */ render_rectangle(buffer, CONTENT_TOP, CONTENT_LEFT, LINES * SYMBOL_HEIGHT + 1, COLUMNS * SYMBOL_WIDTH, WHITE); /* Text */ for (int i = 0; i != LINES; ++i) { for (int j = 0; j != COLUMNS; ++j){ render_symbol(buffer + (CONTENT_TOP + i * SYMBOL_HEIGHT) * SCREEN_WIDTH + CONTENT_LEFT + j * SYMBOL_WIDTH, content[i * COLUMNS + j], BLACK); } } }
void render_exit_menu(exit_menu_t *state, float cursor_x, float cursor_y) { // Update center of cursor set_cursor_position(state->cursor_state, cursor_x, cursor_y); // Check if anything selected check_cursor_in_image(state->cursor_state, state->mandelbrot_state); check_cursor_in_image(state->cursor_state, state->sph_state); check_cursor_in_image(state->cursor_state, state->terminal_state); // Draw background rectangle float center[2] = {0.0f, 0.0f}; float gl_dims[2] = {2.0f, 0.7f}; float background_color[4] = {1.0f, 1.0f, 1.0f, 0.8f}; render_rectangle(state->rectangle_state, center, gl_dims, background_color); // Draw mandelbrot image draw_image(state->mandelbrot_state); // Draw terminal image draw_image(state->terminal_state); // Draw SPH image draw_image(state->sph_state); // Draw cursor draw_cursor(state->cursor_state); }
/* Renders window `task' and all next windows recursively */ void render_task(unsigned char *buffer, struct task_t *task){ if(task != 0){ /* We render front task last */ render_task(buffer, task->next); render_rectangle(buffer + task->begin, 0, 0, task->size / SCREEN_WIDTH + 1, task->size % SCREEN_WIDTH, BLACK); render_rectangle(buffer + task->begin, 1, 1, task->size / SCREEN_WIDTH - 1, task->size % SCREEN_WIDTH - 2, LIGHT_GRAY); render_rectangle(buffer + task->begin, 2, 2, task->size / SCREEN_WIDTH - 2, task->size % SCREEN_WIDTH - 3, DARK_GRAY); render_rectangle(buffer + task->begin, 2, 2, task->size / SCREEN_WIDTH - 3, task->size % SCREEN_WIDTH - 4, GRAY); render_rectangle(buffer + task->begin, 4, 4, TITLE_HEIGHT, task->size % SCREEN_WIDTH - 8, BLUE); for(int i = 0; task->cmdline[i] != 0; ++i){ render_symbol(buffer + task->begin + 5 * SCREEN_WIDTH + 6 + i * SYMBOL_WIDTH, task->cmdline[i], WHITE); } /* Render window content */ (*task->handler)(task, msg_render, (int)buffer); } }
int main(int argc, char *argv[]) { char filename[128]; snprintf(filename, sizeof(filename), "%s/images/rec_test.png", getenv("HOME")); render_rectangle(filename); printf("It worked!\n"); return 0; }
void Color_Wheel::setColor(QColor c) { qreal oldh = huem; huem = c.hueF(); if ( huem < 0 ) huem = 0; sat = c.saturationF(); val = c.valueF(); if ( !qFuzzyCompare(oldh+1,huem+1) ) render_rectangle(); update(); emit colorChanged(c); }
void Color_Wheel::paintEvent(QPaintEvent * ) { double selector_w = 6; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(geometry().width()/2,geometry().height()/2); // hue wheel if ( hue_ring.isNull() ) render_ring(); painter.drawPixmap(-outer_radius(),-outer_radius(),hue_ring); // hue selector painter.setPen(QPen(Qt::black,3)); painter.setBrush(Qt::NoBrush); QLineF ray(0,0,outer_radius(),0); ray.setAngle(huem*360); QPointF h1 = ray.p2(); ray.setLength(inner_radius()); QPointF h2 = ray.p2(); painter.drawLine(h1,h2); // lum-sat square if ( sat_val_square.isNull() ) render_rectangle(); painter.rotate(-huem*360-45); ray.setLength(inner_radius()); ray.setAngle(135); painter.drawImage(ray.p2(),sat_val_square); // lum-sat selector //painter.rotate(135); painter.setPen(QPen( val > 0.5 ? Qt::black : Qt::white ,3)); painter.setBrush(Qt::NoBrush); double max_dist = square_size(); painter.drawEllipse(QPointF(sat*max_dist-max_dist/2, val*max_dist-max_dist/2 ), selector_w,selector_w); }
void Color_Wheel::mouseMoveEvent(QMouseEvent *ev) { if ( mouse_status == Drag_Circle ) { huem = line_to_point(ev->pos()).angle()/360.0; render_rectangle(); emit colorSelected(color()); emit colorChanged(color()); update(); } else if ( mouse_status == Drag_Square ) { QLineF glob_mouse_ln = line_to_point(ev->pos()); QLineF center_mouse_ln ( QPointF(0,0), glob_mouse_ln.p2() - glob_mouse_ln.p1() ); center_mouse_ln.setAngle(center_mouse_ln.angle()-huem*360-45); sat = center_mouse_ln.x2()/square_size()+0.5; val = center_mouse_ln.y2()/square_size()+0.5; if ( sat > 1 ) sat = 1; else if ( sat < 0 ) sat = 0; if ( val > 1 ) val = 1; else if ( val < 0 ) val = 0; emit colorSelected(color()); emit colorChanged(color()); update(); } }
void renderer_render(renderer *renderer, world *world, cache *cache) { // Clear surface to black SDL_SetRenderDrawColor(renderer->sdl_renderer, 0, 0, 0, 0); SDL_RenderClear(renderer->sdl_renderer); // RenderCopy legit surfaces for(int i = 0; i < MAX_ENTITY; i++) { int mask = world->mask[i]; if ((mask & GRAPHIC) == GRAPHIC) { render_graphic(renderer, world, cache, i); } else if (((mask & POINT) == POINT) && ((mask & COLOR) == COLOR) && ((mask & POSITION) == POSITION)) { render_point(renderer, world, i); } else if (((mask & LINE) == LINE) && ((mask & COLOR) == COLOR)) { render_line(renderer, world, i); } else if (((mask & RECT) == RECT) && ((mask & POSITION) == POSITION)) { render_rectangle(renderer, world, i); } else if ((mask & ANIMATED_SPRITE) == ANIMATED_SPRITE) { render_animated_sprite(renderer, world, cache, i); } } // Update screen surface SDL_RenderPresent(renderer->sdl_renderer); }
void render::run(rawTexture* imageList, int size){ // variables Timer timer(1000 / 30); SDL_Renderer* ren; SDL_Window* win; int win_x = 200; int win_y = 200; int win_w = 400; int win_h = 400; // Create the window Uint32 window_flags = SDL_WINDOW_SHOWN; win = SDL_CreateWindow( "binPackerTest", win_x, win_y, win_w, win_h, window_flags ); if(win == NULL){ printf("Failed to create window\n"); return; } // create the renderer Uint32 ren_flags = SDL_RENDERER_ACCELERATED; ren_flags = SDL_RENDERER_PRESENTVSYNC; ren = SDL_CreateRenderer(win, -1, ren_flags); if(ren == NULL){ SDL_DestroyWindow(win); printf("Failed to create renderer\n"); return; } // main loop SDL_Event e; bool exit_flag = false; bool draw_flag = false; timer.start(); for(;;){ while(SDL_PollEvent(&e) && exit_flag == false){ if(e.type == SDL_QUIT){ exit_flag = true; } else if(isKeyboardEvent(e)){ const Uint8* keyboard = SDL_GetKeyboardState(NULL); if(keyboard[SDL_SCANCODE_ESCAPE]){ SDL_Event ev; SDL_zero(ev); ev.type = SDL_QUIT; ev.quit.type = SDL_QUIT; ev.quit.timestamp = SDL_GetTicks(); SDL_PushEvent(&ev); } } else if(isMouseEvent(e)){ // do nothing } else if(e.type >= SDL_USEREVENT){ if(e.user.type == timer.type){ draw_flag = true; } // do nothing } } if(exit_flag){ break; } if(draw_flag){ // draw the shit here. SDL_RenderClear(ren); SDL_Rect rect; SDL_Color color = { 90, 90, 120, 140 }; for(int i = 0; i < size; ++i){ rect.x = imageList[i].extent.x(); rect.y = imageList[i].extent.y(); rect.w = imageList[i].extent.w(); rect.h = imageList[i].extent.h(); render_rectangle(ren, &rect, color); } SDL_RenderPresent(ren); } } // destruction timer.stop(); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); }
void Color_Wheel::setWheelWidth(unsigned w) { wheel_width = w; render_rectangle(); update(); }
void Color_Wheel::setHue(qreal h) { huem = qMax(0.0,qMin(1.0,h)); render_rectangle(); update(); }
void Color_Wheel::resizeEvent(QResizeEvent *) { render_ring(); render_rectangle(); }