lullaby/modules/render/nine_patch.cc
// Computes the position and texture coordinate for one dimension (the math
// works for both x and y).  The resulting spatial position and texture
// coordinate are written into p and u respectively.  For a single dimension of
// the nine patch, there are five cases a vertex can fall into, hence the five
// if-cases.
Computes the position and texture coordinate for one dimension (the math
works for both x and y).  The resulting spatial position and texture
coordinate are written into p and u respectively.  For a single dimension of
the nine patch, there are five cases a vertex can fall into, hence the five
if-cases.
Computes the position and texture coordinate for one dimension ( the math works for both x and y ) . The resulting spatial position and texture coordinate are written into p and u respectively . For a single dimension of the nine patch there are five cases a vertex can fall into hence the five if - cases .
void ComputeVertexValues(float size, float original_size, float low_slice,
                         int low_slice_index, float low_patch_width,
                         float high_slice, int high_slice_index,
                         float high_patch_width, float middle_patch_size,
                         float middle_patch_uv_size, int vertex_index,
                         float vertex_interval, float* p, float* u) {
  if (vertex_index < low_slice_index) {
    *p = vertex_interval;
    *u = SafeDiv(low_slice * vertex_interval, low_patch_width);
  } else if (vertex_index == low_slice_index) {
    *p = low_patch_width;
    *u = low_slice;
  } else if (vertex_index < high_slice_index) {
    *p = vertex_interval;
    const float distance_in_middle_patch = vertex_interval - low_patch_width;
    *u = SafeDiv(middle_patch_uv_size * distance_in_middle_patch,
                  middle_patch_size) +
         low_slice;
  } else if (vertex_index == high_slice_index) {
    *p = size - high_patch_width;
    *u = 1.0f - high_slice;
  } else {
    *p = vertex_interval;
    const float distance_in_high_patch_from_edge = size - vertex_interval;
    *u = 1.0f - SafeDiv(high_slice * distance_in_high_patch_from_edge,
                         high_patch_width);
  }
}
void ComputeVertexValues ( float size , float original_size , float low_slice , int low_slice_index , float low_patch_width , float high_slice , int high_slice_index , float high_patch_width , float middle_patch_size , float middle_patch_uv_size , int vertex_index , float vertex_interval , float * p , float * u ) { if ( vertex_index < low_slice_index ) { * p = vertex_interval ; * u = SafeDiv ( low_slice * vertex_interval , low_patch_width ) ; } else if ( vertex_index == low_slice_index ) { * p = low_patch_width ; * u = low_slice ; } else if ( vertex_index < high_slice_index ) { * p = vertex_interval ; const float distance_in_middle_patch = vertex_interval - low_patch_width ; * u = SafeDiv ( middle_patch_uv_size * distance_in_middle_patch , middle_patch_size ) + low_slice ; } else if ( vertex_index == high_slice_index ) { * p = size - high_patch_width ; * u = 1.0f - high_slice ; } else { * p = vertex_interval ; const float distance_in_high_patch_from_edge = size - vertex_interval ; * u = 1.0f - SafeDiv ( high_slice * distance_in_high_patch_from_edge , high_patch_width ) ; } }
Computes the position and texture coordinate for one dimension (the math
works for both x and y).
Computes the position and texture coordinate for one dimension ( the math works for both x and y ) .
// Set vertex x and u0. // Low patch. // Position is unchanged from the interval position. // Texture coordinate is computed by figuring out the fraction of the patch // this interval is at, and multiplying that by the original slice UV width. // Low slice column. // Position is the original size scaled by the low slice UV width. // Texture coordinate is simply the slice UV width. // Middle patch. // Position is unchanged from the interval position. // Texture coordinate is the middle patch's UV size scaled by the fraction // of the middle patch this interval is at, plus the UV width of the low // slice. // High slice column. // Position is the full size minus the size of the slice. // Texture coordinate is the whole texture (1.0f) minus this slice's // UV width. // High patch. // Position is unchanged from the interval position. // Texture coordinate is the end of this patch's UV minus the UV fraction // from the edge. // This counts backwards so that it is symmetrical to low_slice and matches // the way high_slice is measured, i.e. distance from edge.