Separate drawing of cross hair
This commit is contained in:
parent
6b2c834466
commit
a1a57eb61c
3 changed files with 48 additions and 34 deletions
|
@ -137,6 +137,14 @@ GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent)
|
|||
|
||||
// Private namespace with helper function for create volume
|
||||
namespace priv {
|
||||
|
||||
/// <summary>
|
||||
/// Check if volume type is possible use for new text volume
|
||||
/// </summary>
|
||||
/// <param name="volume_type">Type</param>
|
||||
/// <returns>True when allowed otherwise false</returns>
|
||||
static bool is_valid(ModelVolumeType volume_type);
|
||||
|
||||
/// <summary>
|
||||
/// Prepare data for emboss
|
||||
/// </summary>
|
||||
|
@ -146,8 +154,6 @@ namespace priv {
|
|||
/// <returns>Base data for emboss text</returns>
|
||||
static DataBase create_emboss_data_base(const std::string &text, StyleManager &style_manager, std::shared_ptr<std::atomic<bool>> &cancel);
|
||||
|
||||
static bool is_valid(ModelVolumeType volume_type);
|
||||
|
||||
/// <summary>
|
||||
/// Start job for add new volume to object with given transformation
|
||||
/// </summary>
|
||||
|
@ -200,6 +206,7 @@ static void find_closest_volume(const Selection &selection,
|
|||
/// <param name="coor">Screen coordinat, where to create new object laying on bed</param>
|
||||
static void start_create_object_job(DataBase &emboss_data, const Vec2d &coor);
|
||||
|
||||
// Loaded icons enum
|
||||
// Have to match order of files in function GLGizmoEmboss::init_icons()
|
||||
enum class IconType : unsigned {
|
||||
rename = 0,
|
||||
|
@ -218,21 +225,13 @@ enum class IconType : unsigned {
|
|||
};
|
||||
// Define rendered version of icon
|
||||
enum class IconState : unsigned { activable = 0, hovered /*1*/, disabled /*2*/ };
|
||||
// selector for icon by enum
|
||||
const IconManager::Icon &get_icon(const IconManager::VIcons& icons, IconType type, IconState state);
|
||||
// short call of Slic3r::GUI::button
|
||||
bool draw_button(const IconManager::VIcons& icons, IconType type, bool disable = false);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
bool priv::is_valid(ModelVolumeType volume_type){
|
||||
if (volume_type == ModelVolumeType::MODEL_PART ||
|
||||
volume_type == ModelVolumeType::NEGATIVE_VOLUME ||
|
||||
volume_type == ModelVolumeType::PARAMETER_MODIFIER)
|
||||
return true;
|
||||
|
||||
BOOST_LOG_TRIVIAL(error) << "Can't create embossed volume with this type: " << (int)volume_type;
|
||||
return false;
|
||||
}
|
||||
|
||||
void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mouse_pos)
|
||||
{
|
||||
if (!priv::is_valid(volume_type)) return;
|
||||
|
@ -350,7 +349,7 @@ namespace priv {
|
|||
/// Get transformation to world
|
||||
/// - use fix after store to 3mf when exists
|
||||
/// </summary>
|
||||
/// <param name="gl_volume"></param>
|
||||
/// <param name="gl_volume">Scene volume</param>
|
||||
/// <param name="model">To identify MovelVolume with fix transformation</param>
|
||||
/// <returns></returns>
|
||||
static Transform3d world_matrix(const GLVolume *gl_volume, const Model *model);
|
||||
|
@ -544,26 +543,6 @@ static void draw_mouse_offset(const std::optional<Vec2d> &offset)
|
|||
}
|
||||
#endif // SHOW_OFFSET_DURING_DRAGGING
|
||||
|
||||
namespace priv {
|
||||
static void draw_cross_hair(const ImVec2 &position,
|
||||
float radius = 16.f,
|
||||
ImU32 color = ImGui::GetColorU32(ImVec4(1.f, 1.f, 1.f, .75f)),
|
||||
int num_segments = 0,
|
||||
float thickness = 4.f);
|
||||
} // namespace priv
|
||||
|
||||
void priv::draw_cross_hair(const ImVec2 &position, float radius, ImU32 color, int num_segments, float thickness)
|
||||
{
|
||||
auto draw_list = ImGui::GetOverlayDrawList();
|
||||
draw_list->AddCircle(position, radius, color, num_segments, thickness);
|
||||
auto dirs = {ImVec2{0, 1}, ImVec2{1, 0}, ImVec2{0, -1}, ImVec2{-1, 0}};
|
||||
for (const ImVec2 &dir : dirs) {
|
||||
ImVec2 start(position.x + dir.x * 0.5 * radius, position.y + dir.y * 0.5 * radius);
|
||||
ImVec2 end(position.x + dir.x * 1.5 * radius, position.y + dir.y * 1.5 * radius);
|
||||
draw_list->AddLine(start, end, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
set_volume_by_selection();
|
||||
|
@ -610,7 +589,7 @@ void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
|
|||
ImVec4(1.f, .3f, .3f, .75f)
|
||||
); // Warning color
|
||||
const float radius = 16.f;
|
||||
priv::draw_cross_hair(center, radius, color);
|
||||
ImGuiWrapper::draw_cross_hair(center, radius, color);
|
||||
}
|
||||
|
||||
#ifdef SHOW_FINE_POSITION
|
||||
|
@ -3519,6 +3498,16 @@ std::string GLGizmoEmboss::get_file_name(const std::string &file_path)
|
|||
// priv namespace implementation
|
||||
///////////////
|
||||
|
||||
bool priv::is_valid(ModelVolumeType volume_type)
|
||||
{
|
||||
if (volume_type == ModelVolumeType::MODEL_PART || volume_type == ModelVolumeType::NEGATIVE_VOLUME ||
|
||||
volume_type == ModelVolumeType::PARAMETER_MODIFIER)
|
||||
return true;
|
||||
|
||||
BOOST_LOG_TRIVIAL(error) << "Can't create embossed volume with this type: " << (int) volume_type;
|
||||
return false;
|
||||
}
|
||||
|
||||
DataBase priv::create_emboss_data_base(const std::string &text, StyleManager &style_manager, std::shared_ptr<std::atomic<bool>>& cancel)
|
||||
{
|
||||
// create volume_name
|
||||
|
|
|
@ -1514,6 +1514,17 @@ void ImGuiWrapper::draw(
|
|||
}
|
||||
}
|
||||
|
||||
void ImGuiWrapper::draw_cross_hair(const ImVec2 &position, float radius, ImU32 color, int num_segments, float thickness) {
|
||||
auto draw_list = ImGui::GetOverlayDrawList();
|
||||
draw_list->AddCircle(position, radius, color, num_segments, thickness);
|
||||
auto dirs = {ImVec2{0, 1}, ImVec2{1, 0}, ImVec2{0, -1}, ImVec2{-1, 0}};
|
||||
for (const ImVec2 &dir : dirs) {
|
||||
ImVec2 start(position.x + dir.x * 0.5 * radius, position.y + dir.y * 0.5 * radius);
|
||||
ImVec2 end(position.x + dir.x * 1.5 * radius, position.y + dir.y * 1.5 * radius);
|
||||
draw_list->AddLine(start, end, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGuiWrapper::contain_all_glyphs(const ImFont *font,
|
||||
const std::string &text)
|
||||
{
|
||||
|
|
|
@ -199,6 +199,20 @@ public:
|
|||
ImU32 color = ImGui::GetColorU32(COL_ORANGE_LIGHT),
|
||||
float thickness = 3.f);
|
||||
|
||||
/// <summary>
|
||||
/// Draw symbol of cross hair
|
||||
/// </summary>
|
||||
/// <param name="position">Center of cross hair</param>
|
||||
/// <param name="radius">Circle radius</param>
|
||||
/// <param name="color">Color of symbol</param>
|
||||
/// <param name="num_segments">Precission of circle</param>
|
||||
/// <param name="thickness">Thickness of Line in symbol</param>
|
||||
static void draw_cross_hair(const ImVec2 &position,
|
||||
float radius = 16.f,
|
||||
ImU32 color = ImGui::GetColorU32(ImVec4(1.f, 1.f, 1.f, .75f)),
|
||||
int num_segments = 0,
|
||||
float thickness = 4.f);
|
||||
|
||||
/// <summary>
|
||||
/// Check that font ranges contain all chars in string
|
||||
/// (rendered Unicodes are stored in GlyphRanges)
|
||||
|
|
Loading…
Reference in a new issue