void GuiListboxEntry::draw(int x, int y, int width, DrawType draw_type) { Subsystem& s = gui.get_subsystem(); float alpha = gui.get_alpha(this); Font *f = gui.get_font(); if (draw_type == DrawTypeSelected) { int th = f->get_font_height(); s.set_color(0.5f, 0.5f, 0.5f, alpha); s.draw_box(x, y, width, th); } else if (draw_type == DrawTypeTitle) { int th = f->get_font_height(); s.set_color(0.5f, 0.5f, 1.0f, alpha); s.draw_box(x, y, width, th); } s.set_color(1.0f, 1.0f, 1.0f, alpha); size_t sz = columns.size(); int width0 = width; for (size_t i = 1; i < sz; i++) { width0 -= columns[i].width + Spc; } draw_column(columns[0], x, y, width0); x += width0 + Spc; for (size_t i = 1; i < sz; i++) { int w = columns[i].width; draw_column(columns[i], x, y, w); x += columns[i].width + Spc; } s.reset_color(); }
void raycasting(t_env *e) { int x; x = 0; while (x < WIN_WIDTH) { e->cam_x = (2.0 * x / (double)(WIN_WIDTH)) - 1.0; e->rpos_x = e->pos_x; e->rpos_y = e->pos_y; e->rdir_x = e->dir_x + e->plan_x * e->cam_x; e->rdir_y = e->dir_y + e->plan_y * e->cam_x; e->map_x = (int)(e->rpos_x); e->map_y = (int)(e->rpos_y); e->ddist_x = sqrt(1 + (e->rdir_y * e->rdir_y) / (e->rdir_x * e->rdir_x)); e->ddist_y = sqrt(1 + (e->rdir_x * e->rdir_x) / (e->rdir_y * e->rdir_y)); e->hit = 0; digital_differential_analizer(e); optic_correction(e); get_height_column(e); draw_column(e, x); x++; } mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); }
void draw_real_map(t_map *map, t_img *img) { int x; t_raycaster r; x = 0; while (x < img->width) { init_ray(&r, map, img, x); ray_cast(&r, map); draw_column(&r, map, img, x); x++; } }
void update_frame(const GameState *game) { init_video_buffer(); // Draw puzzle int nr_block = game->nr_block_h * game->nr_block_v; for (int i = 0; i < nr_block; i++) { int block_index = game->block[i]; // Draw a block int scr_x = (i % game->nr_block_h) * game->block_w; int scr_y = (i / game->nr_block_h) * game->block_h; int pic_x = (block_index % game->nr_block_h) * game->block_w; int pic_y = (block_index / game->nr_block_h) * game->block_h; for (int off_y = 0; off_y < game->block_h; off_y++) { for (int off_x = 0; off_x < game->block_w; off_x++) { draw_pixel(scr_x + off_x, scr_y + off_y, get_color(game->image, pic_x + off_x, pic_y + off_y, game->image_w, game->image_h)); } } } // Draw frame for (int i = 0; i < game->nr_block_h + 1; i++) { int scr_x = i * game->block_w; draw_column(scr_x, 0, 6, get_scr_h(), 0); } for (int i = 0; i < game->nr_block_v + 1; i++) { int scr_y = i * game->block_h; draw_row(0, scr_y, 6, get_scr_w(), 0); } draw_border(game->block_x * game->block_w, game->block_y * game->block_h, game->block_w, game->block_h, 3, 0x000000ff); if (game->select == 1) { draw_border(game->select_block_x * game->block_w, game->select_block_y * game->block_h, game->block_w, game->block_h, 3, 0x00ff0000); } update_screen(); }
static void draw_rect_tests(SkCanvas* canvas) { draw_square(canvas, 10, 10); draw_column(canvas, 30, 10); draw_bar(canvas, 10, 30); }
void draw_graph(double val) { int index = 0, loop_n = min(max_x, history_n), n = 0, n2 = 0; double avg = 0, sd = 0; double avg2 = 0, sd2 = 0; double mi = MY_DOUBLE_INF, ma = -MY_DOUBLE_INF, diff = 0.0; for(index=0; index<loop_n; index++) { double val = history[index]; if (!history_set[index]) continue; mi = min(val, mi); ma = max(val, ma); avg += val; sd += val * val; n++; } if (!n) return; avg /= (double)n; sd = sqrt((sd / (double)n) - pow(avg, 2.0)); mi = max(mi, avg - sd); ma = min(ma, avg + sd); for(index=0; index<loop_n; index++) { double val = history[index]; if (!history_set[index]) continue; if (val < mi || val > ma) continue; avg2 += val; sd2 += val * val; n2++; } if (n2) { avg2 /= (double)n2; sd2 = sqrt((sd2 / (double)n2) - pow(avg2, 2.0)); mi = max(mi, avg2 - sd2); ma = min(ma, avg2 + sd2); diff = ma - mi; if (diff == 0.0) diff = 1.0; wattron(w_line1, A_REVERSE); myprintloc(w_line1, 0, 0, gettext("graph range: %7.2fms - %7.2fms "), mi, ma); wattroff(w_line1, A_REVERSE); wnoutrefresh(w_line1); /* fprintf(stderr, "%d| %f %f %f %f\n", h_stats.n, mi, avg, ma, sd); */ for(index=0; index<loop_n; index++) { char overflow = 0, limitter = 0; double val = 0, height = 0; int i_h = 0, x = max_x - (1 + index); if (!history_set[index]) { mvwchgat(w_stats, stats_h - 1, x, 1, A_REVERSE, C_CYAN, NULL); continue; } if (history[index] < graph_limit) val = history[index]; else { val = graph_limit; limitter = 1; } height = (val - mi) / diff; if (height > 1.0) { height = 1.0; overflow = 1; } i_h = (int)(height * stats_h); /* fprintf(stderr, "%d %f %f %d %d\n", index, history[index], height, i_h, overflow); */ draw_column(w_stats, x, i_h, overflow, limitter); } } }
void draw_fft(void) { double mx_mag = 0.0; int index = 0, highest = 0; int cx = 0, cy = 0; /* double max_freq = hz / 2.0; */ double highest_freq = 0, avg_freq_index = 0.0, total_val = 0.0, avg_freq = 0.0; int dummy = 0; getyx(w_slow, cy, cx); for(index=0; index<max_x; index++) { double val = 0.0; if (history_set[index]) val = history[index]; else val = index > 0 ? history[index - 1] : 0; if (val > graph_limit) val = graph_limit; history_temp[index] = val; } fft_do(history_temp, history_fft_magn, history_fft_phase); for(index=1; index<max_x/2; index++) { avg_freq_index += (double)index * history_fft_magn[index]; total_val += history_fft_magn[index]; if (history_fft_magn[index] > mx_mag) { mx_mag = history_fft_magn[index]; highest = index; } } highest_freq = (hz / (double)max_x) * (double)highest; avg_freq_index /= total_val; avg_freq = (hz / (double)max_x) * avg_freq_index; wattron(w_line1, A_REVERSE); myprintloc(w_line1, 0, 38, gettext("highest: %6.2fHz, avg: %6.2fHz"), highest_freq, avg_freq); wattroff(w_line1, A_REVERSE); wnoutrefresh(w_line1); dummy = max_x / 2 + 1; if (draw_phase) { int y = 0; for(y=0; y<slow_n; y++) mvwchgat(w_slow, y, dummy, 1, A_REVERSE, C_WHITE, NULL); for(index=0; index<slow_n; index++) mvwchgat(w_slow, index, 0, max_x, A_NORMAL, C_WHITE, NULL); for(index=1; index<dummy - 1; index++) draw_rad_column(w_slow, index - 1, history_fft_phase[index]); } else { for(index=0; index<slow_n; index++) mvwchgat(w_slow, index, max_x / 2, max_x / 2, A_NORMAL, C_WHITE, NULL); } for(index=1; index<dummy; index++) { int height_magn = (int)((double)slow_n * (history_fft_magn[index] / mx_mag)); draw_column(w_slow, max_x / 2 + index - 1, height_magn, 0, 0); } wmove(w_slow, cy, cx); wnoutrefresh(w_slow); }
static void garnish_distibution(unsigned int num_counts, const char *title) { unsigned int i; /* Set normal font */ fprintf(distribution.out, "/Helvetica findfont "); fprintf(distribution.out, "%u scalefont setfont ", NORMAL_FONT_SIZE); /* Figure out max string length: answer on stack */ max_length(distribution.out, REMARKS, distribution.remarks[TOP], distribution.remarks[BOTTOM], num_counts); /* We need to be at far right + width of remarks column (on stack) */ fprintf(distribution.out, "dup %u add 0 moveto\n", distribution.remark); /* Takes column width from the stack, moves cursor LEFT. */ draw_column(distribution.out, REMARKS, distribution.remarks[TOP], distribution.remarks[BOTTOM], NORMAL_FONT_SIZE, num_counts, false); /* Move to origin. */ fprintf(distribution.out, "0 0 moveto\n"); /* Moves cursor left */ draw_numbers(distribution.out, num_counts, false); /* Draw table title */ fprintf(distribution.out, "/Helvetica findfont "); fprintf(distribution.out, "%u scalefont setfont ", TOP_LEFT_INFO_FONT_SIZE); /* Move up a little */ fprintf(distribution.out, "0 %u rmoveto\n", TOP_LEFT_INFO_FONT_SIZE); fprintf(distribution.out,"gsave (Table II - Distribution of the Effective Votes - %s)" " show grestore\n", get_time_string()); /* Draw quota calculation */ if (distribution.quota != 0) { fprintf(distribution.out, "0 %u rmoveto gsave\n", TOP_LEFT_INFO_FONT_SIZE*3); fprintf(distribution.out, "(Quota = ) show\n"); fprintf(distribution.out, "gsave 0 %u rmoveto ( %u) show grestore\n", TOP_LEFT_INFO_FONT_SIZE/2+3, distribution.num_formals); fprintf(distribution.out, "gsave 0 -%u rmoveto ( %u+1) show grestore\n", TOP_LEFT_INFO_FONT_SIZE/2+3, distribution.num_seats); fprintf(distribution.out, "gsave %u 0 rlineto stroke grestore\n", TOP_LEFT_INFO_FONT_SIZE * 5); fprintf(distribution.out, "%u 0 rmoveto ( + 1 = %u) show grestore\n", TOP_LEFT_INFO_FONT_SIZE * 5, distribution.quota); } /* Draw total for casual vacancy. */ if (distribution.vacancy_total_votes != 0) { fprintf(distribution.out, "0 %u rmoveto gsave" " (Total votes to be distributed = %u)" " show grestore\n", TOP_LEFT_INFO_FONT_SIZE*3, distribution.vacancy_total_votes); } /* Draw title */ fprintf(distribution.out, "/Helvetica findfont "); fprintf(distribution.out, "%u scalefont setfont ", TITLE_FONT_SIZE); fprintf(distribution.out, "0 %u rmoveto\n", TOP_LEFT_INFO_FONT_SIZE + TITLE_FONT_SIZE*2); fprintf(distribution.out, "gsave" " (Scrutiny Sheet for %s - Division of %s) " "show grestore\n", title, distribution.ename); for (i = 0; i < num_counts; i++) { free(distribution.remarks[TOP][i]); distribution.remarks[TOP][i] = NULL; free(distribution.remarks[BOTTOM][i]); distribution.remarks[BOTTOM][i] = NULL; } }
static void garnish_counting(unsigned int num_counts, const char *title) { unsigned int i; fprintf(counting.out, "/Helvetica findfont "); fprintf(counting.out, "%u scalefont setfont ", DESCRIP_FONT_SIZE); /* Figure out max string length: answer on stack */ max_length(counting.out, COUNT_DESCRIP, counting.count_descrip[TOP], counting.count_descrip[BOTTOM], num_counts); /* Move to origin. */ fprintf(counting.out, "0 0 moveto\n"); /* Takes column width from the stack, moves cursor LEFT. */ /* Note that draw_column considers pairs above and below the line, and Table 1 considers the pairs to be those within a "box". So TOP and BOTTOM are reversed, and TOP is move "up" one */ draw_column(counting.out, COUNT_DESCRIP, counting.count_descrip[BOTTOM], counting.count_descrip[TOP]+1, DESCRIP_FONT_SIZE, num_counts, true); /* Moves cursor left again */ draw_numbers(counting.out, num_counts, true); /* Draw table title */ fprintf(counting.out, "/Helvetica findfont "); fprintf(counting.out, "%u scalefont setfont ", TOP_LEFT_INFO_FONT_SIZE); /* Move up a little */ fprintf(counting.out, "0 %u rmoveto\n", TOP_LEFT_INFO_FONT_SIZE); fprintf(counting.out,"gsave (Table I - Counting of the Choices - %s) show grestore\n", get_time_string()); /* Draw number of votes */ fprintf(counting.out, "0 %u rmoveto\n", TOP_LEFT_INFO_FONT_SIZE*3); /* mod for cas vac */ if (counting.num_formals == 0) counting.num_formals = distribution.vacancy_total_ballots; fprintf(counting.out, "gsave (Number of formal papers: %u." " Number of informal papers: %u.) show grestore\n", counting.num_formals, counting.num_informals); /* Draw title */ fprintf(counting.out, "/Helvetica findfont "); fprintf(counting.out, "%u scalefont setfont ", TITLE_FONT_SIZE); fprintf(counting.out, "0 %u rmoveto\n", TOP_LEFT_INFO_FONT_SIZE + TITLE_FONT_SIZE*2); fprintf(counting.out, "gsave" " (Scrutiny Sheet for %s - Division of %s) " "show grestore\n", title, counting.ename); for (i = 0; i < num_counts; i++) { free(counting.count_descrip[TOP][i]); counting.count_descrip[TOP][i] = NULL; free(counting.count_descrip[BOTTOM][i]); counting.count_descrip[BOTTOM][i] = NULL; } }