<commit_before>#include <fstream>
#include <dirent.h>

#include <fastuidraw/painter/painter.hpp>
#include <fastuidraw/text/glyph_cache.hpp>
#include <fastuidraw/text/font_freetype.hpp>
#include <fastuidraw/text/font_database.hpp>
#include <fastuidraw/gl_backend/gl_context_properties.hpp>

#include "sdl_painter_demo.hpp"
#include "PainterWidget.hpp"
#include "simple_time.hpp"
#include "PanZoomTracker.hpp"
#include "text_helper.hpp"
#include "read_path.hpp"
#include "ImageLoader.hpp"
#include "colorstop_command_line.hpp"
#include "command_line_list.hpp"
#include "cycle_value.hpp"
#include "text_helper.hpp"

#include "cell.hpp"
#include "table.hpp"
#include "random.hpp"

using namespace fastuidraw;

bool
compare_named_images(const named_image &lhs,
                     const named_image &rhs)
{
  return lhs.second < rhs.second;
}

class painter_cells:public sdl_painter_demo
{
public:
  painter_cells(void);

  ~painter_cells();

protected:
  void
  derived_init(int w, int h);

  void
  draw_frame(void);

  void
  handle_event(const SDL_Event &ev);

private:
  typedef std::pair<enum Painter::blend_mode_t, std::string> named_blend_mode;

  static
  void
  generate_random_colors(int count, std::vector<vec4> &out_values, bool force_opaque);

  static
  void
  dump_file(const std::string &filename, std::vector<std::string> &dest);

  void
  add_images(const std::string &filename, std::vector<named_image> &dest);

  void
  add_single_image(const std::string &filename, std::vector<named_image> &dest);

  void
  update_cts_params(void);

  command_line_argument_value<float> m_table_width, m_table_height;
  command_line_argument_value<int> m_num_cells_x, m_num_cells_y;
  command_line_argument_value<int> m_cell_group_size;
  command_line_argument_value<std::string> m_font;
  command_line_argument_value<float> m_pixel_size;
  enumerated_command_line_argument_value<enum glyph_type> m_renderer;
  command_line_argument_value<float> m_fps_pixel_size;
  command_line_list<std::string> m_strings;
  command_line_list<std::string> m_files;
  command_line_list<std::string> m_images;
  enumerated_command_line_argument_value<enum PainterBrush::image_filter> m_image_filter;
  command_line_argument_value<bool> m_image_use_mipmaps;
  command_line_argument_value<bool> m_use_atlas;
  command_line_argument_value<bool> m_draw_image_name;
  command_line_argument_value<int> m_num_background_colors;
  command_line_argument_value<bool> m_background_colors_opaque;
  command_line_argument_value<int> m_num_text_colors;
  command_line_argument_value<bool> m_text_colors_opaque;
  command_line_argument_value<int> m_num_rect_colors;
  command_line_argument_value<bool> m_rect_colors_opaque;
  command_line_argument_value<float> m_min_x_velocity, m_max_x_velocity;
  command_line_argument_value<float> m_min_y_velocity, m_max_y_velocity;
  command_line_argument_value<int> m_min_degree_per_second;
  command_line_argument_value<int> m_max_degree_per_second;
  command_line_argument_value<int> m_table_rotate_degrees_per_s;
  command_line_argument_value<float> m_change_stroke_width_rate;

  command_line_argument_value<int> m_num_frames;
  command_line_argument_value<int> m_skip_frames;
  command_line_argument_value<bool> m_init_show_all_table;
  command_line_argument_value<bool> m_init_table_rotating;
  command_line_argument_value<bool> m_init_table_clipped;
  command_line_argument_value<bool> m_init_cell_rotating;
  command_line_argument_value<bool> m_init_draw_text;
  command_line_argument_value<bool> m_init_draw_images;
  command_line_argument_value<float> m_init_stroke_width;
  command_line_argument_value<bool> m_init_anti_alias_stroking;

  CellSharedState m_cell_shared_state;
  TableParams m_table_params;
  PanZoomTrackerSDLEvent m_zoomer;
  Table *m_table;
  simple_time m_time, m_draw_timer;
  PainterPackedValue<PainterBrush> m_text_brush;

  unsigned int m_current_blend;
  std::vector<named_blend_mode> m_blend_labels;

  int m_frame;
  uint64_t m_benchmark_time_us;
  simple_time m_benchmark_timer;
  std::vector<uint64_t> m_frame_times;

  int m_show_surface, m_last_shown_surface;
};

painter_cells::
painter_cells(void):
  m_table_width(800, "table_width", "Table Width", *this),
  m_table_height(600, "table_height", "Table Height", *this),
  m_num_cells_x(10, "num_cells_x", "Number of cells across", *this),
  m_num_cells_y(10, "num_cells_y", "Number of cells down", *this),
  m_cell_group_size(1, "cell_group_size", "width and height in number of cells for cell group size", *this),
  m_font(default_font(), "font", "File from which to take font", *this),
  m_pixel_size(24.0f, "font_pixel_size", "Render size for text rendering", *this),
  m_renderer(adaptive_rendering,
             enumerated_string_type<enum glyph_type>()
             .add_entry("distance_field", distance_field_glyph, "Distance field rendering")
             .add_entry("restricted_rays", restricted_rays_glyph, "Restricted Rays rendering")
             .add_entry("adaptive", adaptive_rendering, "Adaptive rendering"),
             "glyph_render",
             "Specifies how to render glyphs",
             *this),
  m_fps_pixel_size(24.0f, "fps_font_pixel_size", "Render size for text rendering of fps", *this),
  m_strings("add_string", "add a string to use by the cells", *this),
  m_files("add_string_file", "add a string to use by a cell, taken from file", *this),
  m_images("add_image", "Add an image to use by the cells", *this),
  m_image_filter(PainterBrush::image_filter_nearest,
                 enumerated_string_type<enum PainterBrush::image_filter>()
                 .add_entry("nearest", PainterBrush::image_filter_nearest, "nearest filtering")
                 .add_entry("linear", PainterBrush::image_filter_linear, "(bi)linear filtering")
                 .add_entry("cubic", PainterBrush::image_filter_cubic, "(bi)cubic filtering"),
                 "image_filter",
                 "Specifies how to filter the images applied to the rects",
                 *this),
  m_image_use_mipmaps(true, "image_mipmap", "If true, apply mipmapp filtering to images", *this),
  m_use_atlas(true, "use_atlas",
              "If false, each image is realized as a texture; if "
              "GL_ARB_bindless_texture or GL_NV_bindless_texture "
              "is supported, the Image objects are realized as bindless "
              "texture, thus avoding draw breaks; if both of these "<commit_msg>demos/painter_cells: default option to NOT use mipmaps<commit_after>#include <fstream>
#include <dirent.h>

#include <fastuidraw/painter/painter.hpp>
#include <fastuidraw/text/glyph_cache.hpp>
#include <fastuidraw/text/font_freetype.hpp>
#include <fastuidraw/text/font_database.hpp>
#include <fastuidraw/gl_backend/gl_context_properties.hpp>

#include "sdl_painter_demo.hpp"
#include "PainterWidget.hpp"
#include "simple_time.hpp"
#include "PanZoomTracker.hpp"
#include "text_helper.hpp"
#include "read_path.hpp"
#include "ImageLoader.hpp"
#include "colorstop_command_line.hpp"
#include "command_line_list.hpp"
#include "cycle_value.hpp"
#include "text_helper.hpp"

#include "cell.hpp"
#include "table.hpp"
#include "random.hpp"

using namespace fastuidraw;

bool
compare_named_images(const named_image &lhs,
                     const named_image &rhs)
{
  return lhs.second < rhs.second;
}

class painter_cells:public sdl_painter_demo
{
public:
  painter_cells(void);

  ~painter_cells();

protected:
  void
  derived_init(int w, int h);

  void
  draw_frame(void);

  void
  handle_event(const SDL_Event &ev);

private:
  typedef std::pair<enum Painter::blend_mode_t, std::string> named_blend_mode;

  static
  void
  generate_random_colors(int count, std::vector<vec4> &out_values, bool force_opaque);

  static
  void
  dump_file(const std::string &filename, std::vector<std::string> &dest);

  void
  add_images(const std::string &filename, std::vector<named_image> &dest);

  void
  add_single_image(const std::string &filename, std::vector<named_image> &dest);

  void
  update_cts_params(void);

  command_line_argument_value<float> m_table_width, m_table_height;
  command_line_argument_value<int> m_num_cells_x, m_num_cells_y;
  command_line_argument_value<int> m_cell_group_size;
  command_line_argument_value<std::string> m_font;
  command_line_argument_value<float> m_pixel_size;
  enumerated_command_line_argument_value<enum glyph_type> m_renderer;
  command_line_argument_value<float> m_fps_pixel_size;
  command_line_list<std::string> m_strings;
  command_line_list<std::string> m_files;
  command_line_list<std::string> m_images;
  enumerated_command_line_argument_value<enum PainterBrush::image_filter> m_image_filter;
  command_line_argument_value<bool> m_image_use_mipmaps;
  command_line_argument_value<bool> m_use_atlas;
  command_line_argument_value<bool> m_draw_image_name;
  command_line_argument_value<int> m_num_background_colors;
  command_line_argument_value<bool> m_background_colors_opaque;
  command_line_argument_value<int> m_num_text_colors;
  command_line_argument_value<bool> m_text_colors_opaque;
  command_line_argument_value<int> m_num_rect_colors;
  command_line_argument_value<bool> m_rect_colors_opaque;
  command_line_argument_value<float> m_min_x_velocity, m_max_x_velocity;
  command_line_argument_value<float> m_min_y_velocity, m_max_y_velocity;
  command_line_argument_value<int> m_min_degree_per_second;
  command_line_argument_value<int> m_max_degree_per_second;
  command_line_argument_value<int> m_table_rotate_degrees_per_s;
  command_line_argument_value<float> m_change_stroke_width_rate;

  command_line_argument_value<int> m_num_frames;
  command_line_argument_value<int> m_skip_frames;
  command_line_argument_value<bool> m_init_show_all_table;
  command_line_argument_value<bool> m_init_table_rotating;
  command_line_argument_value<bool> m_init_table_clipped;
  command_line_argument_value<bool> m_init_cell_rotating;
  command_line_argument_value<bool> m_init_draw_text;
  command_line_argument_value<bool> m_init_draw_images;
  command_line_argument_value<float> m_init_stroke_width;
  command_line_argument_value<bool> m_init_anti_alias_stroking;

  CellSharedState m_cell_shared_state;
  TableParams m_table_params;
  PanZoomTrackerSDLEvent m_zoomer;
  Table *m_table;
  simple_time m_time, m_draw_timer;
  PainterPackedValue<PainterBrush> m_text_brush;

  unsigned int m_current_blend;
  std::vector<named_blend_mode> m_blend_labels;

  int m_frame;
  uint64_t m_benchmark_time_us;
  simple_time m_benchmark_timer;
  std::vector<uint64_t> m_frame_times;

  int m_show_surface, m_last_shown_surface;
};

painter_cells::
painter_cells(void):
  m_table_width(800, "table_width", "Table Width", *this),
  m_table_height(600, "table_height", "Table Height", *this),
  m_num_cells_x(10, "num_cells_x", "Number of cells across", *this),
  m_num_cells_y(10, "num_cells_y", "Number of cells down", *this),
  m_cell_group_size(1, "cell_group_size", "width and height in number of cells for cell group size", *this),
  m_font(default_font(), "font", "File from which to take font", *this),
  m_pixel_size(24.0f, "font_pixel_size", "Render size for text rendering", *this),
  m_renderer(adaptive_rendering,
             enumerated_string_type<enum glyph_type>()
             .add_entry("distance_field", distance_field_glyph, "Distance field rendering")
             .add_entry("restricted_rays", restricted_rays_glyph, "Restricted Rays rendering")
             .add_entry("adaptive", adaptive_rendering, "Adaptive rendering"),
             "glyph_render",
             "Specifies how to render glyphs",
             *this),
  m_fps_pixel_size(24.0f, "fps_font_pixel_size", "Render size for text rendering of fps", *this),
  m_strings("add_string", "add a string to use by the cells", *this),
  m_files("add_string_file", "add a string to use by a cell, taken from file", *this),
  m_images("add_image", "Add an image to use by the cells", *this),
  m_image_filter(PainterBrush::image_filter_nearest,
                 enumerated_string_type<enum PainterBrush::image_filter>()
                 .add_entry("nearest", PainterBrush::image_filter_nearest, "nearest filtering")
                 .add_entry("linear", PainterBrush::image_filter_linear, "(bi)linear filtering")
                 .add_entry("cubic", PainterBrush::image_filter_cubic, "(bi)cubic filtering"),
                 "image_filter",
                 "Specifies how to filter the images applied to the rects",
                 *this),
  m_image_use_mipmaps(false, "image_mipmap", "If true, apply mipmapp filtering to images", *this),
  m_use_atlas(true, "use_atlas",
              "If false, each image is realized as a texture; if "
              "GL_ARB_bindless_texture or GL_NV_bindless_texture "
              "is supported, the Image objects are realized as bindless "
              "texture, thus avoding draw breaks; if both of these "
{'fraction_non_alphanumeric': 0.09336647506602455, 'fraction_numerical': 0.0034177411837812647, 'mean_word_length': 5.826617179215271, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5872466', 'n_tokens_mistral': 4577, 'n_tokens_neox': 4424, 'n_words': 824}