virtual void on_key(int x, int y, unsigned key, unsigned flags) { if(key == ' ') { agg::trans_affine mtx; mtx *= agg::trans_affine_translation((m_min_x + m_max_x) * -0.5, (m_min_y + m_max_y) * -0.5); mtx *= agg::trans_affine_scaling(m_scale.value()); mtx *= agg::trans_affine_rotation(agg::deg2rad(m_rotate.value())); mtx *= agg::trans_affine_translation((m_min_x + m_max_x) * 0.5, (m_min_y + m_max_y) * 0.5); mtx *= agg::trans_affine_translation(m_x, m_y); double m[6]; mtx.store_to(m); char buf[128]; sprintf(buf, "%3.3f, %3.3f, %3.3f, %3.3f, %3.3f, %3.3f", m[0], m[1], m[2], m[3], m[4], m[5]); message(buf); FILE* fd = fopen(full_file_name("transform.txt"), "a"); fprintf(fd, "%s\n", buf); fclose(fd); } }
virtual void on_ctrl_change() { if(m_benchmark.status()) { int i; on_draw(); update_window(); scanline_rasterizer ras; pixfmt pixf(rbuf_window()); base_renderer rb(pixf); solid_renderer solid(rb); draft_renderer draft(rb); char buf[256]; if(m_draft.status()) { start_timer(); for(i = 0; i < 10; i++) { draw_scene(ras, solid, draft); } sprintf(buf, "%3.3f milliseconds", elapsed_time()); } else { double times[5]; for(m_draw = 0; m_draw < 4; m_draw++) { start_timer(); for(i = 0; i < 10; i++) { draw_scene(ras, solid, draft); } times[m_draw] = elapsed_time(); } m_draw = 3; times[4] = times[3]; times[3] -= times[2]; times[2] -= times[1]; times[1] -= times[0]; FILE* fd = fopen(full_file_name("benchmark"), "a"); fprintf(fd, "%10.3f %10.3f %10.3f %10.3f %10.3f\n", times[0], times[1], times[2], times[3], times[4]); fclose(fd); sprintf(buf, " pipeline add_path sort render total\n" "%10.3f %10.3f %10.3f %10.3f %10.3f", times[0], times[1], times[2], times[3], times[4]); } message(buf); m_benchmark.status(false); force_redraw(); } }
virtual void on_key(int x, int y, unsigned key, unsigned flags) { if(key == ' ') { FILE* fd = fopen(full_file_name("coord"), "w"); fprintf(fd, "%.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f, %.0f", m_curve1.x1(), m_curve1.y1(), m_curve1.x2(), m_curve1.y2(), m_curve1.x3(), m_curve1.y3(), m_curve1.x4(), m_curve1.y4()); fclose(fd); } }
virtual void on_key(int x, int y, unsigned key, unsigned flags) { if(key == ' ') { FILE* fd = fopen(full_file_name("alpha"), "w"); int i; for(i = 0; i < agg::span_conv_brightness_alpha_rgb8::array_size; i++) { int alpha = agg::int8u(m_alpha.value(double(i) / double(agg::span_conv_brightness_alpha_rgb8::array_size)) * 255.0); if(i % 32 == 0) fprintf(fd, "\n"); fprintf(fd, "%3d, ", alpha); } fclose(fd); } }
virtual ~the_application() { write_gamma_txt(full_file_name("gamma.txt")); write_gamma_bin(full_file_name("gamma.bin")); }
virtual void on_init() { read_gamma(full_file_name("gamma.txt")); }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid r(rb); rb.clear(agg::rgba(1, 1, 1)); scanline_type sl; agg::rasterizer_scanline_aa<> ras; agg::simple_polygon_vertex_source path1(m_poly1.polygon(), m_poly1.num_points(), false, false); agg::simple_polygon_vertex_source path2(m_poly2.polygon(), m_poly2.num_points(), false, false); typedef agg::conv_bspline<agg::simple_polygon_vertex_source> conv_bspline_type; conv_bspline_type bspline1(path1); conv_bspline_type bspline2(path2); bspline1.interpolation_step(1.0 / m_num_points.value()); bspline2.interpolation_step(1.0 / m_num_points.value()); typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type; typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type; typedef agg::conv_transform<conv_font_segm_type, agg::trans_double_path> conv_font_trans_type; agg::trans_double_path tcurve; conv_font_curve_type fcurves(m_fman.path_adaptor()); conv_font_segm_type fsegm(fcurves); conv_font_trans_type ftrans(fsegm, tcurve); tcurve.preserve_x_scale(m_preserve_x_scale.status()); if(m_fixed_len.status()) tcurve.base_length(1140.0); tcurve.base_height(30.0); tcurve.add_paths(bspline1, bspline2); fsegm.approximation_scale(3.0); fcurves.approximation_scale(5.0); if(m_feng.load_font(full_file_name("timesi.ttf"), 0, agg::glyph_ren_outline)) { double x = 0.0; double y = 3.0; const char* p = text; m_feng.hinting(false); m_feng.height(40); while(*p) { const agg::glyph_cache* glyph = m_fman.glyph(*p); if(glyph) { if(x > tcurve.total_length1()) break; m_fman.add_kerning(&x, &y); m_fman.init_embedded_adaptors(glyph, x, y); if(glyph->data_type == agg::glyph_data_outline) { ras.reset(); ras.add_path(ftrans); r.color(agg::rgba8(0, 0, 0)); agg::render_scanlines(ras, sl, r); } // increment pen position x += glyph->advance_x; y += glyph->advance_y; } ++p; } } else { message("Please copy file timesi.ttf to the current directory\n" "or download it from http://www.antigrain.com/timesi.zip"); } typedef agg::conv_stroke<conv_bspline_type> conv_stroke_type; conv_stroke_type stroke1(bspline1); conv_stroke_type stroke2(bspline2); stroke1.width(2.0); stroke2.width(2.0); r.color(agg::rgba8(170, 50, 20, 100)); ras.add_path(stroke1); agg::render_scanlines(ras, sl, r); ras.add_path(stroke2); agg::render_scanlines(ras, sl, r); //-------------------------- // Render the "poly" tool and controls r.color(agg::rgba(0, 0.3, 0.5, 0.2)); ras.add_path(m_poly1); agg::render_scanlines(ras, sl, r); ras.add_path(m_poly2); agg::render_scanlines(ras, sl, r); agg::render_ctrl(ras, sl, rb, m_fixed_len); agg::render_ctrl(ras, sl, rb, m_preserve_x_scale); agg::render_ctrl(ras, sl, rb, m_animate); agg::render_ctrl(ras, sl, rb, m_num_points); //-------------------------- }
bool open(const char* fname) { return m_shape.open(full_file_name(fname)); }
//------------------------------------------------------------------------ bool platform_support::load_img(unsigned idx, const char* file) { if (idx < max_images) { char path[B_PATH_NAME_LENGTH]; sprintf(path, "%s/%s%s", m_specific->fAppPath, file, img_ext()); BBitmap* transBitmap = BTranslationUtils::GetBitmap(path); if (transBitmap && transBitmap->IsValid()) { if(transBitmap->ColorSpace() != B_RGB32 && transBitmap->ColorSpace() != B_RGBA32) { // ups we got a smart ass Translator making our live harder delete transBitmap; return false; } color_space format = B_RGB24; switch (m_format) { case pix_format_gray8: format = B_GRAY8; break; case pix_format_rgb555: format = B_RGB15; break; case pix_format_rgb565: format = B_RGB16; break; case pix_format_rgb24: format = B_RGB24_BIG; break; case pix_format_bgr24: format = B_RGB24; break; case pix_format_abgr32: case pix_format_argb32: case pix_format_bgra32: format = B_RGB32; break; case pix_format_rgba32: format = B_RGB32_BIG; break; } BBitmap* bitmap = new (nothrow) BBitmap(transBitmap->Bounds(), 0, format); if (!bitmap || !bitmap->IsValid()) { fprintf(stderr, "failed to allocate temporary bitmap!\n"); delete transBitmap; delete bitmap; return false; } delete m_specific->fImages[idx]; rendering_buffer rbuf_tmp; attach_buffer_to_BBitmap(rbuf_tmp, transBitmap, m_flip_y); m_specific->fImages[idx] = bitmap; attach_buffer_to_BBitmap(m_rbuf_img[idx], bitmap, m_flip_y); rendering_buffer* dst = &m_rbuf_img[idx]; switch(m_format) { case pix_format_gray8: return false; // color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_gray8()); break; break; case pix_format_rgb555: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb555()); break; break; case pix_format_rgb565: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb565()); break; break; case pix_format_rgb24: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break; break; case pix_format_bgr24: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgr24()); break; break; case pix_format_abgr32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_abgr32()); break; break; case pix_format_argb32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_argb32()); break; break; case pix_format_bgra32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgra32()); break; break; case pix_format_rgba32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break; break; } delete transBitmap; return true; } else { fprintf(stderr, "failed to load bitmap: '%s'\n", full_file_name(file)); } } return false; }
/** Deletes a directory. */ bool DeleteDirectory(const std::string& directoryName, bool include_sub_directories) { DIR *dir; // open the directory dir = opendir(directoryName.c_str()); if (nullptr == dir) { return false; } // Traverse the directory: this may be needed for handling recursive calls. struct dirent *ent; while ((ent = readdir(dir)) != nullptr) { // Decide what to do with the directory entry switch (ent->d_type) { case DT_REG: { // DeleteFile std::string full_file_name(directoryName); full_file_name = GetNameWithPlatformTrailingSlash(full_file_name, true); full_file_name.append(ent->d_name); // It's a file. Try to remove it. int file_deletion_result = std::remove(full_file_name.c_str()); if (file_deletion_result != 0) { // some error was encountered. closedir(dir); return false; } } break; case DT_DIR: if (include_sub_directories) { std::string sub_directoryName(ent->d_name); if (sub_directoryName != "." && sub_directoryName != "..") { std::string full_path_sub_dir(directoryName); full_path_sub_dir = GetNameWithPlatformTrailingSlash(full_path_sub_dir, true); full_path_sub_dir.append(sub_directoryName); // Call the function recursively if (!DeleteDirectory(full_path_sub_dir, true)) { // failed to delete a subdirectory. Abort closedir(dir); return false; } } } // Could scan sub-directory recursively .. but do nothing break; default: // device entries // NOP break; } } closedir(dir); // The contents of the directory were deleted. Now delete the directory itself. #if GUSLIB_PLATFORM_TYPE == GUSLIB_PLATFORM_TYPE_WINDOWS if (_rmdir(directoryName.c_str()) != -1) { return true; } else { return false; } #else if (rmdir(directoryName.c_str()) != -1) { return true; } else { return false; } #endif // GUSLIB_PLATFORM_TYPE == GUSLIB_PLATFORM_TYPE_WINDOWS return true; }