diff --git a/debian/solvespace.install b/debian/solvespace.install index ff23693..18c897c 100644 --- a/debian/solvespace.install +++ b/debian/solvespace.install @@ -1,3 +1,4 @@ usr/bin/solvespace usr/share/icons usr/share/applications +usr/share/solvespace diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index 4e37b58..153aeaf 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -96,6 +96,13 @@ else() # Unix endfunction() endif() +function(add_resources) + foreach(name ${ARGN}) + add_resource(${name}) + set(resource_list "${resource_list}" PARENT_SCOPE) + endforeach() +endfunction() + # Second, register all resources. if(WIN32) add_resource(win32/icon.ico RT_ICON_GROUP APP_ICON) @@ -117,7 +124,50 @@ else() RENAME application.x-solvespace.png) endforeach() endif() -add_resource(banner.txt) + +add_resources( + banner.txt + icons/graphics-window/angle.png + icons/graphics-window/arc.png + icons/graphics-window/assemble.png + icons/graphics-window/bezier.png + icons/graphics-window/circle.png + icons/graphics-window/construction.png + icons/graphics-window/equal.png + icons/graphics-window/extrude.png + icons/graphics-window/horiz.png + icons/graphics-window/in3d.png + icons/graphics-window/lathe.png + icons/graphics-window/length.png + icons/graphics-window/line.png + icons/graphics-window/ontoworkplane.png + icons/graphics-window/other-supp.png + icons/graphics-window/parallel.png + icons/graphics-window/perpendicular.png + icons/graphics-window/pointonx.png + icons/graphics-window/point.png + icons/graphics-window/rectangle.png + icons/graphics-window/ref.png + icons/graphics-window/same-orientation.png + icons/graphics-window/sketch-in-3d.png + icons/graphics-window/sketch-in-plane.png + icons/graphics-window/step-rotate.png + icons/graphics-window/step-translate.png + icons/graphics-window/symmetric.png + icons/graphics-window/tangent-arc.png + icons/graphics-window/text.png + icons/graphics-window/trim.png + icons/graphics-window/vert.png + icons/text-window/constraint.png + icons/text-window/edges.png + icons/text-window/faces.png + icons/text-window/hidden-lines.png + icons/text-window/mesh.png + icons/text-window/normal.png + icons/text-window/outlines.png + icons/text-window/point.png + icons/text-window/shaded.png + icons/text-window/workplane.png) # Third, distribute the resources. add_custom_target(resources diff --git a/res/icons/graphics-window/angle.png b/res/icons/graphics-window/angle.png new file mode 100644 index 0000000..f70252a Binary files /dev/null and b/res/icons/graphics-window/angle.png differ diff --git a/res/icons/graphics-window/arc.png b/res/icons/graphics-window/arc.png new file mode 100644 index 0000000..807b736 Binary files /dev/null and b/res/icons/graphics-window/arc.png differ diff --git a/res/icons/graphics-window/assemble.png b/res/icons/graphics-window/assemble.png new file mode 100644 index 0000000..4dad1f7 Binary files /dev/null and b/res/icons/graphics-window/assemble.png differ diff --git a/res/icons/graphics-window/bezier.png b/res/icons/graphics-window/bezier.png new file mode 100644 index 0000000..9d2c240 Binary files /dev/null and b/res/icons/graphics-window/bezier.png differ diff --git a/res/icons/graphics-window/circle.png b/res/icons/graphics-window/circle.png new file mode 100644 index 0000000..c176b44 Binary files /dev/null and b/res/icons/graphics-window/circle.png differ diff --git a/res/icons/graphics-window/construction.png b/res/icons/graphics-window/construction.png new file mode 100644 index 0000000..35ddcb2 Binary files /dev/null and b/res/icons/graphics-window/construction.png differ diff --git a/res/icons/graphics-window/equal.png b/res/icons/graphics-window/equal.png new file mode 100644 index 0000000..6037aed Binary files /dev/null and b/res/icons/graphics-window/equal.png differ diff --git a/res/icons/graphics-window/extrude.png b/res/icons/graphics-window/extrude.png new file mode 100644 index 0000000..5b57a0e Binary files /dev/null and b/res/icons/graphics-window/extrude.png differ diff --git a/res/icons/graphics-window/horiz.png b/res/icons/graphics-window/horiz.png new file mode 100644 index 0000000..dc94540 Binary files /dev/null and b/res/icons/graphics-window/horiz.png differ diff --git a/res/icons/graphics-window/in3d.png b/res/icons/graphics-window/in3d.png new file mode 100644 index 0000000..bad460f Binary files /dev/null and b/res/icons/graphics-window/in3d.png differ diff --git a/res/icons/graphics-window/lathe.png b/res/icons/graphics-window/lathe.png new file mode 100644 index 0000000..8cee058 Binary files /dev/null and b/res/icons/graphics-window/lathe.png differ diff --git a/res/icons/graphics-window/length.png b/res/icons/graphics-window/length.png new file mode 100644 index 0000000..b48715e Binary files /dev/null and b/res/icons/graphics-window/length.png differ diff --git a/res/icons/graphics-window/line.png b/res/icons/graphics-window/line.png new file mode 100644 index 0000000..b99a0d8 Binary files /dev/null and b/res/icons/graphics-window/line.png differ diff --git a/res/icons/graphics-window/ontoworkplane.png b/res/icons/graphics-window/ontoworkplane.png new file mode 100644 index 0000000..fbf6ff3 Binary files /dev/null and b/res/icons/graphics-window/ontoworkplane.png differ diff --git a/res/icons/graphics-window/other-supp.png b/res/icons/graphics-window/other-supp.png new file mode 100644 index 0000000..b2ea5a9 Binary files /dev/null and b/res/icons/graphics-window/other-supp.png differ diff --git a/res/icons/graphics-window/parallel.png b/res/icons/graphics-window/parallel.png new file mode 100644 index 0000000..fe89e2f Binary files /dev/null and b/res/icons/graphics-window/parallel.png differ diff --git a/res/icons/graphics-window/perpendicular.png b/res/icons/graphics-window/perpendicular.png new file mode 100644 index 0000000..e9bf5d5 Binary files /dev/null and b/res/icons/graphics-window/perpendicular.png differ diff --git a/res/icons/graphics-window/point.png b/res/icons/graphics-window/point.png new file mode 100644 index 0000000..d50ffff Binary files /dev/null and b/res/icons/graphics-window/point.png differ diff --git a/res/icons/graphics-window/pointonx.png b/res/icons/graphics-window/pointonx.png new file mode 100644 index 0000000..d0f6b67 Binary files /dev/null and b/res/icons/graphics-window/pointonx.png differ diff --git a/res/icons/graphics-window/rectangle.png b/res/icons/graphics-window/rectangle.png new file mode 100644 index 0000000..d36dc4c Binary files /dev/null and b/res/icons/graphics-window/rectangle.png differ diff --git a/res/icons/graphics-window/ref.png b/res/icons/graphics-window/ref.png new file mode 100644 index 0000000..19f3b88 Binary files /dev/null and b/res/icons/graphics-window/ref.png differ diff --git a/res/icons/graphics-window/same-orientation.png b/res/icons/graphics-window/same-orientation.png new file mode 100644 index 0000000..850d2da Binary files /dev/null and b/res/icons/graphics-window/same-orientation.png differ diff --git a/res/icons/graphics-window/sketch-in-3d.png b/res/icons/graphics-window/sketch-in-3d.png new file mode 100644 index 0000000..0a73b6b Binary files /dev/null and b/res/icons/graphics-window/sketch-in-3d.png differ diff --git a/res/icons/graphics-window/sketch-in-plane.png b/res/icons/graphics-window/sketch-in-plane.png new file mode 100644 index 0000000..c52c40c Binary files /dev/null and b/res/icons/graphics-window/sketch-in-plane.png differ diff --git a/res/icons/graphics-window/step-rotate.png b/res/icons/graphics-window/step-rotate.png new file mode 100644 index 0000000..22969f6 Binary files /dev/null and b/res/icons/graphics-window/step-rotate.png differ diff --git a/res/icons/graphics-window/step-translate.png b/res/icons/graphics-window/step-translate.png new file mode 100644 index 0000000..2901f9e Binary files /dev/null and b/res/icons/graphics-window/step-translate.png differ diff --git a/res/icons/graphics-window/symmetric.png b/res/icons/graphics-window/symmetric.png new file mode 100644 index 0000000..e6e80eb Binary files /dev/null and b/res/icons/graphics-window/symmetric.png differ diff --git a/res/icons/graphics-window/tangent-arc.png b/res/icons/graphics-window/tangent-arc.png new file mode 100644 index 0000000..d9dc40a Binary files /dev/null and b/res/icons/graphics-window/tangent-arc.png differ diff --git a/res/icons/graphics-window/text.png b/res/icons/graphics-window/text.png new file mode 100644 index 0000000..8923573 Binary files /dev/null and b/res/icons/graphics-window/text.png differ diff --git a/res/icons/graphics-window/trim.png b/res/icons/graphics-window/trim.png new file mode 100644 index 0000000..248e448 Binary files /dev/null and b/res/icons/graphics-window/trim.png differ diff --git a/res/icons/graphics-window/vert.png b/res/icons/graphics-window/vert.png new file mode 100644 index 0000000..f137913 Binary files /dev/null and b/res/icons/graphics-window/vert.png differ diff --git a/res/icons/text-window/constraint.png b/res/icons/text-window/constraint.png new file mode 100644 index 0000000..bc1a717 Binary files /dev/null and b/res/icons/text-window/constraint.png differ diff --git a/res/icons/text-window/edges.png b/res/icons/text-window/edges.png new file mode 100644 index 0000000..fcfd009 Binary files /dev/null and b/res/icons/text-window/edges.png differ diff --git a/res/icons/text-window/faces.png b/res/icons/text-window/faces.png new file mode 100644 index 0000000..e92cd5d Binary files /dev/null and b/res/icons/text-window/faces.png differ diff --git a/res/icons/text-window/hidden-lines.png b/res/icons/text-window/hidden-lines.png new file mode 100644 index 0000000..6d7a33f Binary files /dev/null and b/res/icons/text-window/hidden-lines.png differ diff --git a/res/icons/text-window/mesh.png b/res/icons/text-window/mesh.png new file mode 100644 index 0000000..efc6278 Binary files /dev/null and b/res/icons/text-window/mesh.png differ diff --git a/res/icons/text-window/normal.png b/res/icons/text-window/normal.png new file mode 100644 index 0000000..c87ea51 Binary files /dev/null and b/res/icons/text-window/normal.png differ diff --git a/res/icons/text-window/outlines.png b/res/icons/text-window/outlines.png new file mode 100644 index 0000000..2c07fba Binary files /dev/null and b/res/icons/text-window/outlines.png differ diff --git a/res/icons/text-window/point.png b/res/icons/text-window/point.png new file mode 100644 index 0000000..4216881 Binary files /dev/null and b/res/icons/text-window/point.png differ diff --git a/res/icons/text-window/shaded.png b/res/icons/text-window/shaded.png new file mode 100644 index 0000000..0dff1ae Binary files /dev/null and b/res/icons/text-window/shaded.png differ diff --git a/res/icons/text-window/workplane.png b/res/icons/text-window/workplane.png new file mode 100644 index 0000000..7df6897 Binary files /dev/null and b/res/icons/text-window/workplane.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d7f57cf..f1d53bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,17 +84,6 @@ endif() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated) -file(GLOB icons ${CMAKE_CURRENT_SOURCE_DIR}/icons/*.png) -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.cpp - ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.h - COMMAND $ - ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.cpp - ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.h - ${icons} - DEPENDS png2c ${icons} - VERBATIM) - file(GLOB chars ${CMAKE_CURRENT_SOURCE_DIR}/fonts/private/*.png) list(SORT chars) add_custom_command( @@ -119,11 +108,7 @@ add_custom_command( set(generated_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/generated/vectorfont.table.h - ${CMAKE_CURRENT_BINARY_DIR}/generated/bitmapfont.table.h - ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.h) - -set(generated_SOURCES - ${CMAKE_CURRENT_BINARY_DIR}/generated/icons.cpp) + ${CMAKE_CURRENT_BINARY_DIR}/generated/bitmapfont.table.h) # platform dependencies @@ -241,7 +226,6 @@ add_executable(solvespace WIN32 MACOSX_BUNDLE ${libslvs_SOURCES} ${util_SOURCES} ${platform_SOURCES} - ${generated_SOURCES} ${generated_HEADERS} ${solvespace_HEADERS} ${solvespace_SOURCES} diff --git a/src/glhelper.cpp b/src/glhelper.cpp index f789121..95c1244 100644 --- a/src/glhelper.cpp +++ b/src/glhelper.cpp @@ -876,44 +876,31 @@ void ssglBitmapText(const std::string &str, Vector p) glDisable(GL_TEXTURE_2D); } -void ssglDrawPixelsWithTexture(uint8_t *data, int w, int h) -{ -#define MAX_DIM 32 - static uint8_t Texture[MAX_DIM*MAX_DIM*3]; - int i, j; - if(w > MAX_DIM || h > MAX_DIM) oops(); - - for(i = 0; i < w; i++) { - for(j = 0; j < h; j++) { - Texture[(j*MAX_DIM + i)*3 + 0] = data[(j*w + i)*3 + 0]; - Texture[(j*MAX_DIM + i)*3 + 1] = data[(j*w + i)*3 + 1]; - Texture[(j*MAX_DIM + i)*3 + 2] = data[(j*w + i)*3 + 2]; - } - } - +void ssglDrawPixmap(const Pixmap &pixmap, bool flip) { glBindTexture(GL_TEXTURE_2D, TEXTURE_DRAW_PIXELS); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, MAX_DIM, MAX_DIM, 0, - GL_RGB, GL_UNSIGNED_BYTE, Texture); + int format = pixmap.hasAlpha ? GL_RGBA : GL_RGB; + glTexImage2D(GL_TEXTURE_2D, 0, format, pixmap.width, pixmap.height, 0, + format, GL_UNSIGNED_BYTE, pixmap.data.get()); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2d(0, h); + glTexCoord2d(0.0, flip ? 0.0 : 1.0); + glVertex2d(0.0, (double)pixmap.height); - glTexCoord2d(((double)w)/MAX_DIM, 0); - glVertex2d(w, h); + glTexCoord2d(1.0, flip ? 0.0 : 1.0); + glVertex2d((double)pixmap.width, (double)pixmap.height); - glTexCoord2d(((double)w)/MAX_DIM, ((double)h)/MAX_DIM); - glVertex2d(w, 0); + glTexCoord2d(1.0, flip ? 1.0 : 0.0); + glVertex2d((double)pixmap.width, 0.0); - glTexCoord2d(0, ((double)h)/MAX_DIM); - glVertex2d(0, 0); + glTexCoord2d(0.0, flip ? 1.0 : 0.0); + glVertex2d(0.0, 0.0); glEnd(); glDisable(GL_TEXTURE_2D); } diff --git a/src/icons/angle.png b/src/icons/angle.png deleted file mode 100644 index 7001a9d..0000000 Binary files a/src/icons/angle.png and /dev/null differ diff --git a/src/icons/arc.png b/src/icons/arc.png deleted file mode 100644 index 8c09e1a..0000000 Binary files a/src/icons/arc.png and /dev/null differ diff --git a/src/icons/assemble.png b/src/icons/assemble.png deleted file mode 100644 index 5db2d6b..0000000 Binary files a/src/icons/assemble.png and /dev/null differ diff --git a/src/icons/bezier.png b/src/icons/bezier.png deleted file mode 100644 index 73620cd..0000000 Binary files a/src/icons/bezier.png and /dev/null differ diff --git a/src/icons/circle.png b/src/icons/circle.png deleted file mode 100644 index aec46a3..0000000 Binary files a/src/icons/circle.png and /dev/null differ diff --git a/src/icons/constraint.png b/src/icons/constraint.png deleted file mode 100644 index a0e1889..0000000 Binary files a/src/icons/constraint.png and /dev/null differ diff --git a/src/icons/construction.png b/src/icons/construction.png deleted file mode 100644 index fe3149a..0000000 Binary files a/src/icons/construction.png and /dev/null differ diff --git a/src/icons/edges.png b/src/icons/edges.png deleted file mode 100644 index d89c046..0000000 Binary files a/src/icons/edges.png and /dev/null differ diff --git a/src/icons/equal.png b/src/icons/equal.png deleted file mode 100644 index f1ae3ff..0000000 Binary files a/src/icons/equal.png and /dev/null differ diff --git a/src/icons/extrude.png b/src/icons/extrude.png deleted file mode 100644 index 6d4a44a..0000000 Binary files a/src/icons/extrude.png and /dev/null differ diff --git a/src/icons/faces.png b/src/icons/faces.png deleted file mode 100644 index 8fd4e36..0000000 Binary files a/src/icons/faces.png and /dev/null differ diff --git a/src/icons/hidden-lines.png b/src/icons/hidden-lines.png deleted file mode 100644 index 35ea04b..0000000 Binary files a/src/icons/hidden-lines.png and /dev/null differ diff --git a/src/icons/horiz.png b/src/icons/horiz.png deleted file mode 100644 index 5706c69..0000000 Binary files a/src/icons/horiz.png and /dev/null differ diff --git a/src/icons/in3d.png b/src/icons/in3d.png deleted file mode 100644 index 0d6be07..0000000 Binary files a/src/icons/in3d.png and /dev/null differ diff --git a/src/icons/lathe.png b/src/icons/lathe.png deleted file mode 100644 index 3596fe3..0000000 Binary files a/src/icons/lathe.png and /dev/null differ diff --git a/src/icons/length.png b/src/icons/length.png deleted file mode 100644 index 8396bb1..0000000 Binary files a/src/icons/length.png and /dev/null differ diff --git a/src/icons/line.png b/src/icons/line.png deleted file mode 100644 index 8a02224..0000000 Binary files a/src/icons/line.png and /dev/null differ diff --git a/src/icons/mesh.png b/src/icons/mesh.png deleted file mode 100644 index dde867b..0000000 Binary files a/src/icons/mesh.png and /dev/null differ diff --git a/src/icons/normal.png b/src/icons/normal.png deleted file mode 100644 index c88c250..0000000 Binary files a/src/icons/normal.png and /dev/null differ diff --git a/src/icons/ontoworkplane.png b/src/icons/ontoworkplane.png deleted file mode 100644 index b476e8f..0000000 Binary files a/src/icons/ontoworkplane.png and /dev/null differ diff --git a/src/icons/other-supp.png b/src/icons/other-supp.png deleted file mode 100644 index 2bb6368..0000000 Binary files a/src/icons/other-supp.png and /dev/null differ diff --git a/src/icons/outlines.png b/src/icons/outlines.png deleted file mode 100644 index b1c95ab..0000000 Binary files a/src/icons/outlines.png and /dev/null differ diff --git a/src/icons/parallel.png b/src/icons/parallel.png deleted file mode 100644 index 4b8ef99..0000000 Binary files a/src/icons/parallel.png and /dev/null differ diff --git a/src/icons/perpendicular.png b/src/icons/perpendicular.png deleted file mode 100644 index b93d8b3..0000000 Binary files a/src/icons/perpendicular.png and /dev/null differ diff --git a/src/icons/point.png b/src/icons/point.png deleted file mode 100644 index e8a14d5..0000000 Binary files a/src/icons/point.png and /dev/null differ diff --git a/src/icons/pointonx.png b/src/icons/pointonx.png deleted file mode 100644 index ad15c56..0000000 Binary files a/src/icons/pointonx.png and /dev/null differ diff --git a/src/icons/rectangle.png b/src/icons/rectangle.png deleted file mode 100644 index 272dbfa..0000000 Binary files a/src/icons/rectangle.png and /dev/null differ diff --git a/src/icons/ref.png b/src/icons/ref.png deleted file mode 100644 index afd64c3..0000000 Binary files a/src/icons/ref.png and /dev/null differ diff --git a/src/icons/same-orientation.png b/src/icons/same-orientation.png deleted file mode 100644 index c612ee5..0000000 Binary files a/src/icons/same-orientation.png and /dev/null differ diff --git a/src/icons/shaded.png b/src/icons/shaded.png deleted file mode 100644 index 5fb452d..0000000 Binary files a/src/icons/shaded.png and /dev/null differ diff --git a/src/icons/sketch-in-3d.png b/src/icons/sketch-in-3d.png deleted file mode 100644 index 204fd8c..0000000 Binary files a/src/icons/sketch-in-3d.png and /dev/null differ diff --git a/src/icons/sketch-in-plane.png b/src/icons/sketch-in-plane.png deleted file mode 100644 index 86811e8..0000000 Binary files a/src/icons/sketch-in-plane.png and /dev/null differ diff --git a/src/icons/step-rotate.png b/src/icons/step-rotate.png deleted file mode 100644 index 6c38a16..0000000 Binary files a/src/icons/step-rotate.png and /dev/null differ diff --git a/src/icons/step-translate.png b/src/icons/step-translate.png deleted file mode 100644 index faaeff0..0000000 Binary files a/src/icons/step-translate.png and /dev/null differ diff --git a/src/icons/symmetric.png b/src/icons/symmetric.png deleted file mode 100644 index 6eb9cad..0000000 Binary files a/src/icons/symmetric.png and /dev/null differ diff --git a/src/icons/tangent-arc.png b/src/icons/tangent-arc.png deleted file mode 100644 index 0db8ac3..0000000 Binary files a/src/icons/tangent-arc.png and /dev/null differ diff --git a/src/icons/text.png b/src/icons/text.png deleted file mode 100644 index 01eb028..0000000 Binary files a/src/icons/text.png and /dev/null differ diff --git a/src/icons/trim.png b/src/icons/trim.png deleted file mode 100644 index daa0878..0000000 Binary files a/src/icons/trim.png and /dev/null differ diff --git a/src/icons/vert.png b/src/icons/vert.png deleted file mode 100644 index 41eeb6e..0000000 Binary files a/src/icons/vert.png and /dev/null differ diff --git a/src/icons/workplane.png b/src/icons/workplane.png deleted file mode 100644 index c451453..0000000 Binary files a/src/icons/workplane.png and /dev/null differ diff --git a/src/resource.cpp b/src/resource.cpp index 656509a..3f3f540 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -4,9 +4,14 @@ // Copyright 2016 whitequark //----------------------------------------------------------------------------- #include "solvespace.h" +#include namespace SolveSpace { +//----------------------------------------------------------------------------- +// Resource loading functions +//----------------------------------------------------------------------------- + std::string LoadString(const std::string &name) { size_t size; const void *data = LoadResource(name, &size); @@ -15,4 +20,105 @@ std::string LoadString(const std::string &name) { return std::string(static_cast(data), size); } +Pixmap LoadPNG(const std::string &name) { + size_t size; + const void *data = LoadResource(name, &size); + if(data == NULL) oops(); + + Pixmap pixmap = Pixmap::FromPNG(static_cast(data), size); + if(pixmap.IsEmpty()) oops(); + + return pixmap; +} + +//----------------------------------------------------------------------------- +// Pixmap manipulation +//----------------------------------------------------------------------------- + +void Pixmap::Clear() { + *this = {}; +} + +static Pixmap ReadPNGIntoPixmap(png_struct *png_ptr, png_info *info_ptr) { + png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, NULL); + + Pixmap pixmap = {}; + pixmap.width = png_get_image_width(png_ptr, info_ptr); + pixmap.height = png_get_image_height(png_ptr, info_ptr); + pixmap.hasAlpha = png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA; + + size_t stride = pixmap.width * pixmap.GetBytesPerPixel(); + if(stride % 4 != 0) stride += 4 - stride % 4; + pixmap.stride = stride; + + pixmap.data = std::unique_ptr(new uint8_t[pixmap.stride * pixmap.height]); + uint8_t **rows = png_get_rows(png_ptr, info_ptr); + for(size_t y = 0; y < pixmap.height; y++) { + memcpy(&pixmap.data[pixmap.stride * y], rows[y], + pixmap.width * pixmap.GetBytesPerPixel()); + } + + return pixmap; +} + +Pixmap Pixmap::FromPNG(const uint8_t *data, size_t size) { + Pixmap pixmap = {}; + struct Slice { const uint8_t *data; size_t size; }; + Slice dataSlice = { data, size }; + png_struct *png_ptr = NULL; + png_info *info_ptr = NULL; + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if(!png_ptr) goto exit; + info_ptr = png_create_info_struct(png_ptr); + if(!info_ptr) goto exit; + + if(setjmp(png_jmpbuf(png_ptr))) goto exit; + + png_set_read_fn(png_ptr, &dataSlice, + [](png_struct *png_ptr, uint8_t *data, size_t size) { + Slice *dataSlice = (Slice *)png_get_io_ptr(png_ptr); + if(size <= dataSlice->size) { + memcpy(data, dataSlice->data, size); + dataSlice->data += size; + dataSlice->size -= size; + } else { + png_error(png_ptr, "EOF"); + } + }); + + pixmap = ReadPNGIntoPixmap(png_ptr, info_ptr); + +exit: + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return pixmap; +} + +Pixmap Pixmap::FromPNG(FILE *f) { + Pixmap pixmap = {}; + + png_struct *png_ptr = NULL; + png_info *info_ptr = NULL; + + uint8_t header[8]; + if(fread(header, 1, sizeof(header), f) != sizeof(header)) goto exit; + if(png_sig_cmp(header, 0, sizeof(header))) goto exit; + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if(!png_ptr) goto exit; + info_ptr = png_create_info_struct(png_ptr); + if(!info_ptr) goto exit; + + if(setjmp(png_jmpbuf(png_ptr))) goto exit; + + png_init_io(png_ptr, f); + png_set_sig_bytes(png_ptr, sizeof(header)); + + pixmap = ReadPNGIntoPixmap(png_ptr, info_ptr); + +exit: + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return pixmap; +} + } diff --git a/src/resource.h b/src/resource.h index 10c0ea6..e597196 100644 --- a/src/resource.h +++ b/src/resource.h @@ -7,6 +7,8 @@ #ifndef __RESOURCE_H #define __RESOURCE_H +class Pixmap; + // Only the following function is platform-specific. // It returns a pointer to resource contents that is aligned to at least // sizeof(void*) and has a global lifetime, or NULL if a resource with @@ -14,5 +16,23 @@ const void *LoadResource(const std::string &name, size_t *size); std::string LoadString(const std::string &name); +Pixmap LoadPNG(const std::string &name); + +class Pixmap { +public: + size_t width; + size_t height; + size_t stride; + bool hasAlpha; + std::unique_ptr data; + + static Pixmap FromPNG(const uint8_t *data, size_t size); + static Pixmap FromPNG(FILE *f); + + bool IsEmpty() const { return width == 0 && height == 0; } + size_t GetBytesPerPixel() const { return hasAlpha ? 4 : 3; } + + void Clear(); +}; #endif diff --git a/src/solvespace.h b/src/solvespace.h index 25b6a40..165f16f 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -356,7 +356,7 @@ void ssglColorRGB(RgbaColor rgb); void ssglColorRGBa(RgbaColor rgb, double a); void ssglDepthRangeOffset(int units); void ssglDepthRangeLockToFront(bool yes); -void ssglDrawPixelsWithTexture(uint8_t *data, int w, int h); +void ssglDrawPixmap(const Pixmap &pixmap, bool flip = false); void ssglInitializeBitmapFont(); void ssglBitmapText(const std::string &str, Vector p); void ssglBitmapCharQuad(char32_t chr, double x, double y); diff --git a/src/textwin.cpp b/src/textwin.cpp index 78e4308..0249710 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -4,7 +4,6 @@ // Copyright 2008-2013 Jonathan Westhues. //----------------------------------------------------------------------------- #include "solvespace.h" -#include "generated/icons.h" const TextWindow::Color TextWindow::fgColors[] = { { 'd', RGBi(255, 255, 255) }, @@ -30,19 +29,19 @@ const TextWindow::Color TextWindow::bgColors[] = { bool TextWindow::SPACER = false; TextWindow::HideShowIcon TextWindow::hideShowIcons[] = { - { &(SS.GW.showWorkplanes), Icon_workplane, "workplanes from inactive groups"}, - { &(SS.GW.showNormals), Icon_normal, "normals" }, - { &(SS.GW.showPoints), Icon_point, "points" }, - { &(SS.GW.showConstraints), Icon_constraint, "constraints and dimensions" }, - { &(SS.GW.showFaces), Icon_faces, "XXX - special cased" }, - { &SPACER, 0, 0 }, - { &(SS.GW.showShaded), Icon_shaded, "shaded view of solid model" }, - { &(SS.GW.showEdges), Icon_edges, "edges of solid model" }, - { &(SS.GW.showOutlines), Icon_outlines, "outline of solid model" }, - { &(SS.GW.showMesh), Icon_mesh, "triangle mesh of solid model" }, - { &SPACER, 0, 0 }, - { &(SS.GW.showHdnLines), Icon_hidden_lines, "hidden lines" }, - { 0, 0, 0 } + { &(SS.GW.showWorkplanes), "workplane", "workplanes from inactive groups", {} }, + { &(SS.GW.showNormals), "normal", "normals", {} }, + { &(SS.GW.showPoints), "point", "points", {} }, + { &(SS.GW.showConstraints), "constraint", "constraints and dimensions", {} }, + { &(SS.GW.showFaces), "faces", "XXX - special cased", {} }, + { &SPACER, 0, 0, {} }, + { &(SS.GW.showShaded), "shaded", "shaded view of solid model", {} }, + { &(SS.GW.showEdges), "edges", "edges of solid model", {} }, + { &(SS.GW.showOutlines), "outlines", "outline of solid model", {} }, + { &(SS.GW.showMesh), "mesh", "triangle mesh of solid model", {} }, + { &SPACER, 0, 0, {} }, + { &(SS.GW.showHdnLines), "hidden-lines", "hidden lines", {} }, + { 0, 0, 0, {} } }; void TextWindow::MakeColorTable(const Color *in, float *out) { @@ -379,13 +378,15 @@ void TextWindow::DrawOrHitTestIcons(int how, double mx, double my) continue; } + if(hsi->icon.IsEmpty()) { + hsi->icon = LoadPNG(ssprintf("icons/text-window/%s.png", hsi->iconName)); + } + if(how == PAINT) { glPushMatrix(); glTranslated(x, y-24, 0); - // Only thing that matters about the color is the alpha, - // should be one for no transparency glColor3d(0, 0, 0); - ssglDrawPixelsWithTexture(hsi->icon, 24, 24); + ssglDrawPixmap(hsi->icon); glPopMatrix(); if(hsi == hoveredIcon) { @@ -433,7 +434,7 @@ void TextWindow::DrawOrHitTestIcons(int how, double mx, double my) if(how == PAINT) { std::string str; - if(tooltippedIcon->icon == Icon_faces) { + if(tooltippedIcon->var == &(SS.GW.showFaces)) { if(SS.GW.showFaces) { str = "Don't make faces selectable with mouse"; } else { diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 77f795f..1594e79 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -6,52 +6,52 @@ // Copyright 2008-2013 Jonathan Westhues. //----------------------------------------------------------------------------- #include "solvespace.h" -#include "generated/icons.h" -static uint8_t SPACER[1]; -static const struct { - uint8_t *image; +static const char *SPACER = ""; +static struct { + const char *iconName; int menu; const char *tip; + Pixmap icon; } Toolbar[] = { - { Icon_line, GraphicsWindow::MNU_LINE_SEGMENT, "Sketch line segment" }, - { Icon_rectangle, GraphicsWindow::MNU_RECTANGLE, "Sketch rectangle" }, - { Icon_circle, GraphicsWindow::MNU_CIRCLE, "Sketch circle" }, - { Icon_arc, GraphicsWindow::MNU_ARC, "Sketch arc of a circle" }, - { Icon_text, GraphicsWindow::MNU_TTF_TEXT, "Sketch curves from text in a TrueType font" }, - { Icon_tangent_arc, GraphicsWindow::MNU_TANGENT_ARC, "Create tangent arc at selected point" }, - { Icon_bezier, GraphicsWindow::MNU_CUBIC, "Sketch cubic Bezier spline" }, - { Icon_point, GraphicsWindow::MNU_DATUM_POINT, "Sketch datum point" }, - { Icon_construction, GraphicsWindow::MNU_CONSTRUCTION, "Toggle construction" }, - { Icon_trim, GraphicsWindow::MNU_SPLIT_CURVES, "Split lines / curves where they intersect" }, - { SPACER, 0, 0 }, + { "line", GraphicsWindow::MNU_LINE_SEGMENT, "Sketch line segment", {} }, + { "rectangle", GraphicsWindow::MNU_RECTANGLE, "Sketch rectangle", {} }, + { "circle", GraphicsWindow::MNU_CIRCLE, "Sketch circle", {} }, + { "arc", GraphicsWindow::MNU_ARC, "Sketch arc of a circle", {} }, + { "text", GraphicsWindow::MNU_TTF_TEXT, "Sketch curves from text in a TrueType font", {} }, + { "tangent-arc", GraphicsWindow::MNU_TANGENT_ARC, "Create tangent arc at selected point", {} }, + { "bezier", GraphicsWindow::MNU_CUBIC, "Sketch cubic Bezier spline", {} }, + { "point", GraphicsWindow::MNU_DATUM_POINT, "Sketch datum point", {} }, + { "construction", GraphicsWindow::MNU_CONSTRUCTION, "Toggle construction", {} }, + { "trim", GraphicsWindow::MNU_SPLIT_CURVES, "Split lines / curves where they intersect", {} }, + { SPACER, 0, 0, {} }, - { Icon_length, GraphicsWindow::MNU_DISTANCE_DIA, "Constrain distance / diameter / length" }, - { Icon_angle, GraphicsWindow::MNU_ANGLE, "Constrain angle" }, - { Icon_horiz, GraphicsWindow::MNU_HORIZONTAL, "Constrain to be horizontal" }, - { Icon_vert, GraphicsWindow::MNU_VERTICAL, "Constrain to be vertical" }, - { Icon_parallel, GraphicsWindow::MNU_PARALLEL, "Constrain to be parallel or tangent" }, - { Icon_perpendicular, GraphicsWindow::MNU_PERPENDICULAR, "Constrain to be perpendicular" }, - { Icon_pointonx, GraphicsWindow::MNU_ON_ENTITY, "Constrain point on line / curve / plane / point" }, - { Icon_symmetric, GraphicsWindow::MNU_SYMMETRIC, "Constrain symmetric" }, - { Icon_equal, GraphicsWindow::MNU_EQUAL, "Constrain equal length / radius / angle" }, - { Icon_same_orientation,GraphicsWindow::MNU_ORIENTED_SAME, "Constrain normals in same orientation" }, - { Icon_other_supp, GraphicsWindow::MNU_OTHER_ANGLE, "Other supplementary angle" }, - { Icon_ref, GraphicsWindow::MNU_REFERENCE, "Toggle reference dimension" }, - { SPACER, 0, 0 }, + { "length", GraphicsWindow::MNU_DISTANCE_DIA, "Constrain distance / diameter / length", {} }, + { "angle", GraphicsWindow::MNU_ANGLE, "Constrain angle", {} }, + { "horiz", GraphicsWindow::MNU_HORIZONTAL, "Constrain to be horizontal", {} }, + { "vert", GraphicsWindow::MNU_VERTICAL, "Constrain to be vertical", {} }, + { "parallel", GraphicsWindow::MNU_PARALLEL, "Constrain to be parallel or tangent", {} }, + { "perpendicular", GraphicsWindow::MNU_PERPENDICULAR, "Constrain to be perpendicular", {} }, + { "pointonx", GraphicsWindow::MNU_ON_ENTITY, "Constrain point on line / curve / plane / point", {} }, + { "symmetric", GraphicsWindow::MNU_SYMMETRIC, "Constrain symmetric", {} }, + { "equal", GraphicsWindow::MNU_EQUAL, "Constrain equal length / radius / angle", {} }, + { "same-orientation",GraphicsWindow::MNU_ORIENTED_SAME, "Constrain normals in same orientation", {} }, + { "other-supp", GraphicsWindow::MNU_OTHER_ANGLE, "Other supplementary angle", {} }, + { "ref", GraphicsWindow::MNU_REFERENCE, "Toggle reference dimension", {} }, + { SPACER, 0, 0, {} }, - { Icon_extrude, GraphicsWindow::MNU_GROUP_EXTRUDE, "New group extruding active sketch" }, - { Icon_lathe, GraphicsWindow::MNU_GROUP_LATHE, "New group rotating active sketch" }, - { Icon_step_rotate, GraphicsWindow::MNU_GROUP_ROT, "New group step and repeat rotating" }, - { Icon_step_translate, GraphicsWindow::MNU_GROUP_TRANS, "New group step and repeat translating" }, - { Icon_sketch_in_plane, GraphicsWindow::MNU_GROUP_WRKPL, "New group in new workplane (thru given entities)" }, - { Icon_sketch_in_3d, GraphicsWindow::MNU_GROUP_3D, "New group in 3d" }, - { Icon_assemble, GraphicsWindow::MNU_GROUP_LINK, "New group linking / assembling file" }, - { SPACER, 0, 0 }, + { "extrude", GraphicsWindow::MNU_GROUP_EXTRUDE, "New group extruding active sketch", {} }, + { "lathe", GraphicsWindow::MNU_GROUP_LATHE, "New group rotating active sketch", {} }, + { "step-rotate", GraphicsWindow::MNU_GROUP_ROT, "New group step and repeat rotating", {} }, + { "step-translate", GraphicsWindow::MNU_GROUP_TRANS, "New group step and repeat translating", {} }, + { "sketch-in-plane", GraphicsWindow::MNU_GROUP_WRKPL, "New group in new workplane (thru given entities)", {} }, + { "sketch-in-3d", GraphicsWindow::MNU_GROUP_3D, "New group in 3d", {} }, + { "assemble", GraphicsWindow::MNU_GROUP_LINK, "New group linking / assembling file", {} }, + { SPACER, 0, 0, {} }, - { Icon_in3d, GraphicsWindow::MNU_NEAREST_ISO, "Nearest isometric view" }, - { Icon_ontoworkplane, GraphicsWindow::MNU_ONTO_WORKPLANE, "Align view to active workplane" }, - { NULL, 0, 0 } + { "in3d", GraphicsWindow::MNU_NEAREST_ISO, "Nearest isometric view", {} }, + { "ontoworkplane", GraphicsWindow::MNU_ONTO_WORKPLANE, "Align view to active workplane", {} }, + { NULL, 0, 0, {} } }; void GraphicsWindow::ToolbarDraw(void) { @@ -141,8 +141,8 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my, } toolTip = { false, NULL }; bool leftpos = true; - for(i = 0; Toolbar[i].image; i++) { - if(Toolbar[i].image == SPACER) { + for(i = 0; Toolbar[i].iconName; i++) { + if(Toolbar[i].iconName == SPACER) { if(!leftpos) { leftpos = true; y -= 32; @@ -164,9 +164,17 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my, continue; } + if(Toolbar[i].icon.IsEmpty()) { + std::string name = ssprintf("icons/graphics-window/%s.png", Toolbar[i].iconName); + Toolbar[i].icon = LoadPNG(name); + } + if(paint) { - glRasterPos2i(x - 12, y - 12); - glDrawPixels(24, 24, GL_RGB, GL_UNSIGNED_BYTE, Toolbar[i].image); + glPushMatrix(); + glTranslated(x - Toolbar[i].icon.width / 2, y - Toolbar[i].icon.height / 2, 0); + glColor4d(0, 0, 0, 1.0); + ssglDrawPixmap(Toolbar[i].icon, /*flip=*/true); + glPopMatrix(); if(toolbarHovered == Toolbar[i].menu || pending.operation == Toolbar[i].menu) { diff --git a/src/ui.h b/src/ui.h index 4cbc4e8..873b93b 100644 --- a/src/ui.h +++ b/src/ui.h @@ -62,8 +62,9 @@ public: // The row of icons at the top of the text window, to hide/show things typedef struct { bool *var; - uint8_t *icon; + const char *iconName; const char *tip; + Pixmap icon; } HideShowIcon; static HideShowIcon hideShowIcons[]; static bool SPACER; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 93fb750..9f3e09d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,12 +4,6 @@ include_directories( link_directories( ${PNG_LIBRARY_DIRS}) -add_executable(png2c - png2c.cpp) - -target_link_libraries(png2c - ${PNG_LIBRARIES}) - add_executable(unifont2c unifont2c.cpp) diff --git a/tools/png2c.cpp b/tools/png2c.cpp deleted file mode 100644 index 49d2249..0000000 --- a/tools/png2c.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include -#include -#include - -#define die(msg) do { fprintf(stderr, "%s\n", msg); abort(); } while(0) - -void write_png(FILE *out, const char *filename) { - FILE *fp = fopen(filename, "rb"); - if (!fp) - die("png fopen failed"); - - png_byte header[8] = {}; - if(fread(header, 1, 8, fp) != 8) - die("png fread failed"); - - if(png_sig_cmp(header, 0, 8)) - die("png_sig_cmp failed"); - - png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if(!png) - die("png_create_read_struct failed"); - - png_set_expand(png); - png_set_strip_alpha(png); - - png_infop png_info = png_create_info_struct(png); - if (!png_info) - die("png_create_info_struct failed"); - - if (setjmp(png_jmpbuf(png))) - die("png_init_io failed"); - - png_init_io(png, fp); - png_set_sig_bytes(png, 8); - - png_read_info(png, png_info); - - int width = png_get_image_width(png, png_info); - int height = png_get_image_height(png, png_info); - if(width != 24 || height != 24) - die("not a 24x24 png"); - - png_read_update_info(png, png_info); - - if (setjmp(png_jmpbuf(png))) - die("png_read_image failed"); - - png_bytepp image = (png_bytepp) malloc(sizeof(png_bytep) * height); - for (int y = 0; y < height; y++) - image[y] = (png_bytep) malloc(png_get_rowbytes(png, png_info)); - - png_read_image(png, (png_bytepp) image); - - for(int y = height - 1; y >= 0; y--) { - for(int x = 0; x < (int)png_get_rowbytes(png, png_info); x += 3) { - unsigned char r = image[y][x + 0], - g = image[y][x + 1], - b = image[y][x + 2]; - - if(r + g + b < 11) - r = g = b = 30; - fprintf(out, " 0x%02x, 0x%02x, 0x%02x,\n", r, g, b); - } - } - - for (int y = 0; y < height; y++) - free(image[y]); - free(image); - - fclose(fp); - - png_destroy_read_struct(&png, &png_info, NULL); -} - -int main(int argc, char** argv) { - if(argc < 3) { - fprintf(stderr, "Usage: %s
...\n", - argv[0]); - return 1; - } - - FILE *source = fopen(argv[1], "wt"); - if(!source) - die("source fopen failed"); - - FILE *header = fopen(argv[2], "wt"); - if(!header) - die("header fopen failed"); - - fprintf(source, "/**** This is a generated file - do not edit ****/\n\n"); - fprintf(header, "/**** This is a generated file - do not edit ****/\n\n"); - - for(int i = 3; i < argc; i++) { - const char *filename = argv[i]; - const char *basename = strrchr(filename, '/'); /* cmake uses / even on Windows */ - if(basename == NULL) { - basename = filename; - } else { - basename++; // skip separator - } - - char *stemname = (char*) calloc(strlen(basename), 1); - strncpy(stemname, basename, strchr(basename, '.') - basename); - for(size_t j = 0; j < strlen(stemname); j++) { - if(!isalnum(stemname[j])) - stemname[j] = '_'; - } - - fprintf(header, "extern unsigned char Icon_%s[24*24*3];\n", stemname); - - fprintf(source, "unsigned char Icon_%s[24*24*3] = {\n", stemname); - write_png(source, filename); - fprintf(source, "};\n\n"); - - free(stemname); - } - - fclose(source); - fclose(header); -}