Panel Image.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /******************************************************************************/
  2. struct PanelImageParams
  3. {
  4. struct Light
  5. {
  6. Bool enabled ; // if light is enabled , default=false
  7. Flt intensity , // light intensity , 0..1 , default=0.5
  8. back , // back light intensity , -1..1 , default=0.25
  9. highlight , // highlight , 0..1 , default=0
  10. highlight_cut , // highlight cut-off , 0..1 , default=0.8
  11. specular , // specular intensity , 0..1 , default=1.0 (this is multiplied by section specular intensity)
  12. specular_back , // back specular intensity , -1..1 , default=0
  13. specular_exp , // specular exponent , 0..Inf, default=32
  14. specular_highlight , // specular highligt , 0..1 , default=0
  15. specular_highlight_cut; // specular highligt cut-off, 0..1 , default=0.8
  16. Vec2 angle ; // light angle , -1..1 , default=(0, 0.4)
  17. Light();
  18. #if EE_PRIVATE
  19. Bool save(File &f)C;
  20. Bool load(File &f) ;
  21. #endif
  22. };
  23. struct ImageParams
  24. {
  25. enum MODE : Byte
  26. {
  27. MULTIPLY , // result = src * image
  28. SCALE , // result = src * ScaleFactor(image-0.5)
  29. ADD , // result = src + image
  30. ADD_SIGNED, // result = src + (image-0.5)
  31. BLEND , // result = Blend(src, image)
  32. };
  33. MODE mode ; // default=MULTIPLY
  34. Bool blur_clamp; // if use clamping when blurring the image, default=false
  35. Int blur ; // blur range (in pixels), 0..256, default=0
  36. Flt uv_scale , // image uv scale , 0..Inf, default=1
  37. uv_warp , // image uv warp by depth, 0..1 , default=0
  38. intensity ; // intensity , 0..1 , default=0
  39. Vec2 uv_offset ; // image uv offset , -Inf..Inf, default=(0, 0)
  40. #if EE_PRIVATE
  41. Bool is()C {return !Equal(intensity, 0);}
  42. Bool save(File &f)C;
  43. Bool load(File &f) ;
  44. #endif
  45. ImageParams();
  46. };
  47. struct Section
  48. {
  49. Flt size , // section size , this parameter is unused for section #0, 0..1, default=0
  50. top_offset , // section top offset, this parameter is unused for section #0, -1..1, default=0
  51. round_depth , // if use round depth or linear depth, 0..1, 0=linear, 1=round, default=1
  52. outer_depth , // for section #0 this specifies the outer ring depth , for section #1 this specifies center ring depth, 0..1, default=1
  53. inner_depth , // 0..1, default=1
  54. inner_distance , // for section #0 this specifies the inner ring distance, for section #1 this specifies center ring distance, 0..1, default=0.5
  55. specular , // section specular intensity, 0..1, default=0 (this is multiplied by light specular intensity)
  56. reflection_intensity; // intensity of reflection image, used when "reflection!=null", 0..1, default=0.3
  57. Vec2 smooth_depth ; // depth smoothing intensity, x=horizontal, y=vertical, 0..1, default=(0, 0)
  58. Color color, // section color, default=WHITE
  59. outer_color, inner_color, // outer/inner color, default=WHITE
  60. color_top, color_bottom, color_left, color_right, // top/bottom/left/right color, default=WHITE
  61. outer_border_color, inner_border_color, prev_border_color; // border colors, default=(0, 0, 0, 128), (255, 255, 255, 64), TRANSPARENT
  62. C Image *depth_overlay, *color_overlay, *reflection; // images, default=null
  63. ImageParams depth_overlay_params, color_overlay_params, depth_noise, color_noise; // image parameters
  64. Section();
  65. #if EE_PRIVATE
  66. Bool save(File &f)C;
  67. Bool load(File &f) ;
  68. #endif
  69. };
  70. Bool cut_left, cut_right, cut_bottom, cut_top, // if cut-off the sides, default=false
  71. cut_corners[2][2] , // if cut-off the corners, default=false
  72. force_uniform_stretch[2]; // if force uniform stretching [0]-horizontal, [1]=vertical, default=(false, false)
  73. Int resolution , // image resolution (in pixels), 1..Inf, default=64
  74. width, height ; // image size multipliers, 1..8, default=(1, 1)
  75. Flt round_corners , // 0..1, default=0.5
  76. cut_corner_slope , // 0..2, default=1
  77. cut_corner_amount , // 0..1, default=1
  78. left_slope , // -1..1, default=0
  79. right_slope , // -1..1, default=0
  80. border_size , // 0..1, default=2.0/resolution (which is 1 pixel of the panel image)
  81. outer_glow_spread , // 0..1, default=0.5
  82. outer_glow_radius , // 0..1, border_size*12 (which is 12 pixels of the panel image)
  83. inner_glow_radius , // 0..1, border_size*12 (which is 12 pixels of the panel image)
  84. light_ambient , // ambient lighting, 0..1, default=0.5
  85. depth , // depth multiplier, 0..1, default=1
  86. round_depth , // if use round depth or linear depth, 0..1, 0=linear, 1=round, default=1
  87. inner_distance , // inner ring distance used for calculating depth, 0..1, default=0.5
  88. shadow_radius , // 0..1, default=0
  89. shadow_opacity , // 0..1, default=0.5
  90. shadow_spread , // 0..1, default=0.5
  91. max_side_stretch ; // affects maximum allowed stretching of the side parts of the image, 0..Inf, default=0.2
  92. Vec2 smooth_depth , // depth smoothing intensity, x=horizontal, y=vertical, 0..1, default=(0, 0)
  93. extend ; // extend side outwards, 0..1, default=0
  94. Rect extend_inner_padd ; // extend inner padding, -1..1, default=0
  95. Light lights [2] ; // lights for this panel image
  96. Section sections[2] ; // sections in this panel image
  97. Color color, // global color, default=WHITE
  98. color_top, color_bottom, color_left, color_right, // global top/bottom/left/right color, default=WHITE
  99. outer_glow_color, inner_glow_color; // outer/inner glow colors, default=TRANSPARENT
  100. Flt images_size, // 3x3 images size multiplier , 0..Inf, default=0.5
  101. top_height, // height of the top images, 0..1 , default=1
  102. bottom_height, // height of the bottom images, 0..1 , default=1
  103. left_right_width , // width of the left and right middle images, 0..1 , default=1
  104. top_corner_width , // width of the left and right top images, 0..1 , default=1
  105. bottom_corner_width ; // width of the left and right bottom images, 0..1 , default=1
  106. C Image *top_image, *bottom_image, *center_image, *left_image, *right_image, *top_left_image, *top_right_image, *bottom_left_image, *bottom_right_image; // 3x3 images, default=null
  107. Bool save(File &f)C; // save parameters to file, false on fail, this does not save image pointers
  108. Bool load(File &f) ; // load parameters from file, false on fail
  109. PanelImageParams();
  110. };
  111. /******************************************************************************/
  112. struct PanelImage
  113. {
  114. Image image;
  115. // manage
  116. void create(C PanelImageParams &params, Image *depth_map=null, Int super_sample=4, FILTER_TYPE filter=FILTER_BEST, Threads *threads=null); // create 'PanelImage' from specified 'params', 'depth_map'=optional parameter allowing to obtain the depth map of the panel for debugging purposes, 'super_sample'=super sampling used for creating the Panel Image (higher value increases the quality of the image, but makes it slower to create it), 'filter'=filter used when down-sampling the super sampled image to normal size (unused when super sampling was not enabled), 'threads'=optionally pass a created 'Threads' object to create the 'PanelImage' in multi-threaded mode
  117. // get
  118. Bool extendedRect (C Rect &rect, Rect &extended )C; // returns true if 'extended' is different than 'rect'
  119. void innerPadding (C Rect &rect, Rect &padding )C; // get inner padding of 'rect' rectangle 'PanelImage'
  120. C Rect& defaultInnerPadding ( )C {return _inner_padding;} // get default inner padding
  121. void defaultInnerPaddingSize( Vec2 &padd_size)C;
  122. // draw
  123. void draw( C Rect &rect)C; // draw at specified 'rect' screen rectangle
  124. void draw(C Color &color, C Color &color_add, C Rect &rect)C; // draw at specified 'rect' screen rectangle with custom colors
  125. void drawVertical( C Rect &rect)C; // draw at specified 'rect' screen rectangle in vertical mode
  126. void drawVertical(C Color &color, C Color &color_add, C Rect &rect)C; // draw at specified 'rect' screen rectangle in vertical mode with custom colors
  127. void drawFrac (C Color &color, C Color &color_add, C Rect &rect, Flt frac_x, Bool include_padding)C; // draw at specified 'rect' screen rectangle with custom colors and horizontally limited to 'frac_x' (0..1) fraction, 'include_padding'=if take padding into account when processing the fraction
  128. void drawVerticalFrac(C Color &color, C Color &color_add, C Rect &rect, Flt frac_y, Bool include_padding)C; // draw at specified 'rect' screen rectangle with custom colors and vertically limited to 'frac_y' (0..1) fraction, 'include_padding'=if take padding into account when processing the fraction
  129. void drawBaseLines (C Color &line_color, C Rect &rect)C; // draw lines on unscaled image
  130. void drawScaledLines (C Color &line_color, C Rect &rect)C; // draw lines on scaled image
  131. void drawInnerPadding(C Color &line_color, C Rect &rect)C; // draw lines of inner padding
  132. // io
  133. Bool save(C Str &name)C; // save PanelImage to file, false on fail
  134. Bool load(C Str &name) ; // load PanelImage from file, false on fail
  135. Bool save( File &f )C; // save PanelImage to file, false on fail
  136. Bool load( File &f ) ; // load PanelImage from file, false on fail
  137. void del(); // delete manually, this can be called optionally to release panel image memory
  138. PanelImage();
  139. #if EE_PRIVATE
  140. void drawBorders (C Color &color, C Color &color_add, C Rect &rect)C; // draw only borders
  141. Bool getSideScale (C Rect &rect, Flt &scale)C;
  142. Bool getSideScaleVertical(C Rect &rect, Flt &scale)C;
  143. void zero();
  144. #else
  145. private:
  146. #endif
  147. Bool _same_x, _padd_any, _force_uniform_stretch[2];
  148. Flt _size_x[3][2], _size_y[2], _tex_x[3][2], _tex_y[2]; // [y][x]
  149. Vec2 _side_size, _padd, _tex_left_top, _tex_right_bottom;
  150. Rect _inner_padding;
  151. };
  152. /******************************************************************************/
  153. DECLARE_CACHE(PanelImage, PanelImages, PanelImagePtr); // 'PanelImages' cache storing 'PanelImage' objects which can be accessed by 'PanelImagePtr' pointer
  154. /******************************************************************************/