void GameViewBattle::on_render(CL_GraphicContext &gc, const CL_Rect &clip_rect) { CL_GUIThemePart part(this); part.render_box(gc, get_size(), clip_rect); CL_String text = cl_format("%1 vs %2", player_from->name, player_to->name); CL_Size text_size = font_small.get_text_size(gc, text); int xpos = (get_width() - text_size.width) / 2; int ypos = get_height() / 2 + 10; font_small.draw_text(gc, xpos, ypos, text); int attack_strength = 0; int defense_strength = 0; if(attack_results.size() > 0 && defense_results.size() > 0) { int dice_count = attack_results.size(); int dice_width = dice_count * 35; xpos = (get_width() - dice_width) / 2; ypos = 20; for(int i = 0; i < cl_min(dice_count, current_dice_index); i++) { attack_strength += attack_results[i]; sprite_dices.set_frame(attack_results[i] - 1); sprite_dices.draw(gc, (float)xpos, (float)ypos); xpos += 35; } dice_count = defense_results.size(); dice_width = dice_count * 35; xpos = (get_width() - dice_width) / 2; ypos = get_height() - 45 - 20; for(int i = 0; i < cl_min(dice_count, current_dice_index); i++) { defense_strength += defense_results[i]; sprite_dices.set_frame(defense_results[i] - 1); sprite_dices.draw(gc, (float)xpos, (float)ypos); xpos += 35; } } text = CL_StringHelp::int_to_text(attack_strength); text_size = font_large.get_text_size(gc, text); xpos = (get_width() - text_size.width) / 2; ypos = 109; font_large.draw_text(gc, xpos, ypos, text); text = CL_StringHelp::int_to_text(defense_strength); text_size = font_large.get_text_size(gc, text); xpos = (get_width() - text_size.width) / 2; ypos = get_height() - 80; font_large.draw_text(gc, xpos, ypos, text); }
cl_byte64 CL_ZipReader_Impl::deflate_read(void *data, cl_byte64 size, bool read_all) { zs.next_out = (Bytef *) data; zs.avail_out = size; // Continue feeding zlib data until we get our data: while (zs.avail_out > 0) { // zlib needs more data: if (zs.avail_in == 0 && compressed_pos < local_header.compressed_size) { // Read some compressed data: int received_input = 0; while (received_input < 16*1024) { received_input += input.receive(zbuffer, int(cl_min(16*1024, local_header.compressed_size - compressed_pos)), true); if (compressed_pos + received_input == local_header.compressed_size) break; } compressed_pos += received_input; zs.next_in = (Bytef *) zbuffer; zs.avail_in = received_input; } // Decompress data: int result = inflate(&zs, (compressed_pos == local_header.compressed_size) ? Z_FINISH : Z_NO_FLUSH); if (result == Z_STREAM_END) break; if (result == Z_NEED_DICT) throw CL_Exception("Zlib inflate wants a dictionary!"); if (result == Z_DATA_ERROR) throw CL_Exception("Zip data stream is corrupted"); if (result == Z_STREAM_ERROR) throw CL_Exception("Zip stream structure was inconsistent!"); if (result == Z_MEM_ERROR) throw CL_Exception("Zlib did not have enough memory to decompress file!"); if (result == Z_BUF_ERROR) throw CL_Exception("Not enough data in buffer when Z_FINISH was used"); if (result != Z_OK) throw CL_Exception("Zlib inflate failed while decompressing zip file!"); } return size - zs.avail_out; }
void CL_AES192_Decrypt_Impl::add(const void *_data, int size) { if (calculated) reset(); if (!initialisation_vector_set) throw CL_Exception("AES-192 initialisation vector has not been set"); if (!cipher_key_set) throw CL_Exception("AES-192 cipher key has not been set"); const unsigned char *data = (const unsigned char *) _data; int pos = 0; while (pos < size) { int data_left = size - pos; int buffer_space = aes192_block_size_bytes - chunk_filled; int data_used = cl_min(buffer_space, data_left); memcpy(chunk + chunk_filled, data + pos, data_used); chunk_filled += data_used; pos += data_used; if (chunk_filled == aes192_block_size_bytes) { if ((!padding_enabled) || (pos < size) ) // Do not process chunk on the last block if padding is enabled, as calculate() must process it { process_chunk(); chunk_filled = 0; } } } }
CL_SpanLayout_Impl::FloatBox CL_SpanLayout_Impl::float_box_any(FloatBox box, int max_width, const std::vector<FloatBox> &floats1) { bool restart; do { restart = false; for (size_t i=0; i<floats1.size(); i++) { int top = cl_max(floats1[i].rect.top, box.rect.top); int bottom = cl_min(floats1[i].rect.bottom, box.rect.bottom); if (bottom > top && box.rect.left < floats1[i].rect.right) { CL_Size s = box.rect.get_size(); box.rect.left = floats1[i].rect.left; box.rect.right = box.rect.left+s.width; if (!box_fits_on_line(box, max_width)) { box.rect.left = 0; box.rect.right = s.width; box.rect.top = floats1[i].rect.bottom; box.rect.bottom = box.rect.top + s.height; restart = true; break; } } } } while(restart); return box; }
static void RGB_2_HSL(float r, float g, float b, float *h, float *s, float *l) { float var_R = ( r / 255.0 ); //RGB from 0 to 255 float var_G = ( g / 255.0 ); float var_B = ( b / 255.0 ); float var_Min = cl_min( var_R, var_G, var_B ); //Min. value of RGB float var_Max = cl_max( var_R, var_G, var_B ); //Max. value of RGB float del_Max = var_Max - var_Min; //Delta RGB value *l = ( var_Max + var_Min ) / 2.0; if ( del_Max == 0 ) { //This is a gray, no chroma... *h = 0; //HSL results from 0 to 1 *s = 0; } else { //Chromatic data... if ( *l < 0.5 ) *s = del_Max / ( var_Max + var_Min ); else *s = del_Max / ( 2.0 - var_Max - var_Min ); float del_R = ( ( ( var_Max - var_R ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max; float del_G = ( ( ( var_Max - var_G ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max; float del_B = ( ( ( var_Max - var_B ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max; if ( var_R == var_Max ) *h = del_B - del_G; else if ( var_G == var_Max ) *h = ( 1.0 / 3.0 ) + del_R - del_B; else if ( var_B == var_Max ) *h = ( 2.0 / 3.0 ) + del_G - del_R; if ( *h < 0 ) *h += 1; if ( *h > 1 ) *h -= 1; } }
CL_SpanLayout_Impl::TextSizeResult CL_SpanLayout_Impl::find_text_size(CL_GraphicContext &gc, const TextBlock &block, unsigned int object_index) { CL_Font font = objects[object_index].font; if (layout_cache.object_index != object_index) { layout_cache.object_index = object_index; layout_cache.metrics = font.get_font_metrics(); } TextSizeResult result; result.start = block.start; int pos = block.start; int x_position = 0; while (pos != block.end) { int end = cl_min(objects[object_index].end, block.end); CL_StringRef subtext = text.substr(pos, end-pos); CL_Size text_size = font.get_text_size(gc, subtext); result.width += text_size.width; result.height = cl_max(result.height, (int)(layout_cache.metrics.get_height()+layout_cache.metrics.get_external_leading())/*text_size.height*/); result.ascender = cl_max(result.ascender, (int)layout_cache.metrics.get_ascent()); result.descender = cl_max(result.descender, (int)layout_cache.metrics.get_descent()); LineSegment segment; segment.type = object_text; segment.start = pos; segment.end = end; segment.font = objects[object_index].font; segment.color = objects[object_index].color; segment.id = objects[object_index].id; segment.x_position = x_position; segment.width = text_size.width; segment.ascender = (int)layout_cache.metrics.get_ascent(); segment.descender = (int)layout_cache.metrics.get_descent(); x_position += text_size.width; result.segments.push_back(segment); pos = end; if (pos == objects[object_index].end) { object_index++; result.objects_traversed++; if (object_index < objects.size()) { layout_cache.object_index = object_index; font = objects[object_index].font; layout_cache.metrics = font.get_font_metrics(); } } } result.end = pos; return result; }
bool CL_ZipIODevice_FileEntry::seek(int seek_pos, CL_IODevice::SeekMode mode) { cl_byte64 absolute_pos = 0; switch (mode) { case CL_IODevice::seek_set: absolute_pos = seek_pos; break; case CL_IODevice::seek_cur: absolute_pos = pos + seek_pos; break; case CL_IODevice::seek_end: absolute_pos = file_header.uncompressed_size + seek_pos; break; } switch (file_header.compression_method) { case zip_compress_store: // no compression iodevice.seek(int(absolute_pos-pos), CL_IODevice::seek_cur); break; case zip_compress_deflate: // if backward seeking, restart at beginning of stream. if (absolute_pos < pos) { deinit(); init(); } char buffer[1024]; while (absolute_pos > pos) { int received = receive(buffer, int(cl_min(absolute_pos-pos, 1024)), true); if (received == 0) break; } break; case zip_compress_shrunk: case zip_compress_expand_factor_1: case zip_compress_expand_factor_2: case zip_compress_expand_factor_3: case zip_compress_expand_factor_4: case zip_compress_implode: case zip_compress_tokenize: case zip_compress_deflate64: case zip_compress_pkware_implode: return false; } return true; }
CL_Rect CL_Quad::get_bounds() const { return CL_Rect( cl_min(cl_min(cl_min(x1, x2), x3), x4), cl_min(cl_min(cl_min(y1, y2), y3), y4), cl_max(cl_max(cl_max(x1, x2), x3), x4), cl_max(cl_max(cl_max(y1, y2), y3), y4)); }
CL_Rect CL_Quadx<Type>::get_bounds() const { return CL_Rect( cl_min(cl_min(cl_min(p.x, q.x), r.x), s.x), cl_min(cl_min(cl_min(p.y, q.y), r.y), s.y), cl_max(cl_max(cl_max(p.x, q.x), r.x), s.x), cl_max(cl_max(cl_max(p.y, q.y), r.y), s.y)); }
CL_ColorHSVx<int>::CL_ColorHSVx(const CL_Color &color) { int red = color.get_red(); int green = color.get_green(); int blue = color.get_blue(); const int min_value = cl_min(red,cl_min(blue, green)); const int max_value = cl_max(red,cl_max(blue, green)); a = color.get_alpha(); if (min_value == max_value) { h = 0; s = 0; v = min_value; return; } s = max_value != 0 ? 255 * (max_value - min_value) / max_value : 0; v = max_value; float r = float(max_value - red) / (max_value - min_value); float g = float(max_value - green) / (max_value - min_value); float b = float(max_value - blue) / (max_value - min_value); if (max_value == red) { h = (60 * (b - g))+0.5f; } else if (max_value == green) { h = (60 * (2 + r - b))+0.5f; } else { h = (60 * (4 + g - r))+0.5f; } }
CL_ColorHSVx<double>::CL_ColorHSVx(const CL_Colord &color) { double red = color.get_red(); double green = color.get_green(); double blue = color.get_blue(); const double min_value = cl_min(red,cl_min(blue, green)); const double max_value = cl_max(red,cl_max(blue, green)); a = color.get_alpha(); if (min_value == max_value) { h = 0.0; s = 0.0; v = min_value; return; } s = max_value != 0.0 ? (max_value - min_value) / max_value : 0.0; v = max_value; double r = double(max_value - red) / (max_value - min_value); double g = double(max_value - green) / (max_value - min_value); double b = double(max_value - blue) / (max_value - min_value); if (max_value == red) { h = (60.0 * (b - g)); } else if (max_value == green) { h = (60.0 * (2.0 + r - b)); } else { h = (60.0 * (4.0 + g - r)); } }
CL_ColorHSVx<float>::CL_ColorHSVx(const CL_Colorf &color) { float red = color.get_red(); float green = color.get_green(); float blue = color.get_blue(); const float min_value = cl_min(red,cl_min(blue, green)); const float max_value = cl_max(red,cl_max(blue, green)); a = color.get_alpha(); if (min_value == max_value) { h = 0.0f; s = 0.0f; v = min_value; return; } s = max_value != 0.0f ? (max_value - min_value) / max_value : 0.0f; v = max_value; float r = float(max_value - red) / (max_value - min_value); float g = float(max_value - green) / (max_value - min_value); float b = float(max_value - blue) / (max_value - min_value); if (max_value == red) { h = (60.0f * (b - g)); } else if (max_value == green) { h = (60.0f * (2.0f + r - b)); } else { h = (60.0f * (4.0f + g - r)); } }
bool CL_SpanLayout_Impl::box_fits_on_line(const FloatBox &box, int max_width) { for (size_t i=0; i<floats_right.size(); i++) { int top = cl_max(floats_right[i].rect.top, box.rect.top); int bottom = cl_min(floats_right[i].rect.bottom, box.rect.bottom); if (bottom > top) { if (box.rect.right + floats_right[i].rect.right > max_width) return false; } } return true; }
CL_ColorHSVf::operator CL_Colorf() { float hue = cl_min(359.0f,cl_max(0.0f,h)); float saturation = cl_min(1.0f,cl_max(0.0f,s)); float value = cl_min(1.0f,cl_max(0.0f,v)); if (saturation == 0.0f) { return CL_Colorf(value, value, value, a); } int section = (int)(hue / 60); float f = (hue / 60.0f) - ((float) section); float p = value * (1.0f - saturation); float q = value * (1.0f - saturation * f); float t = value * (1.0f - saturation * (1.0f - f)); if (section == 1) { return CL_Colorf(q, value, p, a); } if (section == 2) { return CL_Colorf(p, value, t, a); } if (section == 3) { return CL_Colorf(p, q, value, a); } if (section == 4) { return CL_Colorf(t, p, value, a); } if (section == 5) { return CL_Colorf(value, p, q, a); } return CL_Colorf(value, t, p, a); }
CL_ColorHSVd::operator CL_Colord() { double hue = cl_min(359.0,cl_max(0.0,h)); double saturation = cl_min(1.0,cl_max(0.0,s)); double value = cl_min(1.0,cl_max(0.0,v)); if (saturation == 0.0f) { return CL_Colord(value, value, value, a); } int section = (int)(hue / 60); double f = (hue / 60.0) - ((double) section); double p = value * (1.0 - saturation); double q = value * (1.0 - saturation * f); double t = value * (1.0 - saturation * (1.0 - f)); if (section == 1) { return CL_Colord(q, value, p, a); } if (section == 2) { return CL_Colord(p, value, t, a); } if (section == 3) { return CL_Colord(p, q, value, a); } if (section == 4) { return CL_Colord(t, p, value, a); } if (section == 5) { return CL_Colord(value, p, q, a); } return CL_Colord(value, t, p, a); }
CL_ColorHSVi::operator CL_Color() { int hue = cl_min(359,cl_max(0,h)); int saturation = cl_min(255,cl_max(0,s)); int value = cl_min(255,cl_max(0,v)); if (saturation == 0) { return CL_Color(value, value, value, a); } int section = (int)(hue / 60); int f = ((hue*256) / 60) - (section*256); int p = (value * (255 - saturation))/255; int q = (value * (255 - ((saturation * f) /256) ))/255; int t = (value * (255 - ((saturation * (256 - f)) / 256) ))/255; if (section == 1) { return CL_Color(q, value, p, a); } if (section == 2) { return CL_Color(p, value, t, a); } if (section == 3) { return CL_Color(p, q, value, a); } if (section == 4) { return CL_Color(t, p, value, a); } if (section == 5) { return CL_Color(value, p, q, a); } return CL_Color(value, t, p, a); }
CL_String CL_RingBuffer::read_to_string(size_t length) { CL_String s(length, ' '); size_t bytes_read = 0; while (bytes_read < length) { const char *d = get_read_pos(); size_t available = cl_min(length - bytes_read, get_read_size()); for (size_t i = 0; i < available; i++) s[bytes_read + i] = d[i]; bytes_read += available; read(available); } return s; }
int CL_ZipIODevice_FileEntry::receive(void *buffer, int size, bool receive_all) { if (size == 0) return 0; if (peeked_data.get_size() > 0) { int peek_amount = cl_min(size, peeked_data.get_size()); memcpy(buffer, peeked_data.get_data(), peek_amount); memmove(peeked_data.get_data(), peeked_data.get_data()+peek_amount, peeked_data.get_size()-peek_amount); peeked_data.set_size(peeked_data.get_size()-peek_amount); if (peek_amount <= size) return peek_amount + receive((char*) buffer+peek_amount, size-peek_amount, receive_all); } return lowlevel_read(buffer, size, receive_all); }
int CL_IODeviceProvider_File::read(void *buffer, int size, bool read_all) { if (size == 0) return 0; if (peeked_data.get_size() > 0) { #define cl_min(a,b) ((a)<(b)?(a):(b)) int peek_amount = cl_min(size, peeked_data.get_size()); memcpy(buffer, peeked_data.get_data(), peek_amount); memmove(peeked_data.get_data(), peeked_data.get_data()+peek_amount, peeked_data.get_size()-peek_amount); peeked_data.set_size(peeked_data.get_size()-peek_amount); if (peek_amount <= size) return peek_amount + read((char*) buffer+peek_amount, size-peek_amount, read_all); } return lowlevel_read(buffer, size, read_all); }
int CL_LineSegment2x<int>::point_distance(const CL_Vec2i &point) { int L = cl_pow2(q.x-p.x) + cl_pow2(q.y-p.y); int r = ((point.x-p.x)*(q.x-p.x)+(point.y-p.y)*(q.y-p.y)) / L; if( r <= 0 || r >= 1 ) { return cl_min( point.distance(p), point.distance(q) ); } int s = ((p.y-point.y)*(q.x-p.x)-(p.x-point.x)*(q.y-p.y)) / L; s *= (int) (sqrt((float) L) + 0.5f); if (s < 0) s = -s; return s; }
Type CL_LineSegment2x<Type>::point_distance(const CL_Vec2<Type> &point) { Type L = cl_pow2(q.x-p.x) + cl_pow2(q.y-p.y); Type r = ((point.x-p.x)*(q.x-p.x)+(point.y-p.y)*(q.y-p.y)) / L; if( r <= 0 || r >= 1 ) { return cl_min( point.distance(p), point.distance(q) ); } Type s = ((p.y-point.y)*(q.x-p.x)-(p.x-point.x)*(q.y-p.y)) / L; s *= sqrt(L); if (s < ((Type)0)) s = -s; return s; }
void TokenGroup::addToken(Token* token, float_t score) { if(numTokens < MAX_NUM_TOKENS_PER_GROUP) { if(numTokens==0) { startOffset=token->startOffset(); endOffset=token->endOffset(); } else { startOffset=cl_min(startOffset,token->startOffset()); endOffset=cl_max(endOffset,token->endOffset()); } tokens[numTokens].set(token->termBuffer(),token->startOffset(),token->endOffset(),token->type());; scores[numTokens]=score; numTokens++; } }
void CL_PixelFillRenderer::clear(const CL_Colorf &color) { int dest_buffer_width = colorbuffer0.size.width; int dest_buffer_height = colorbuffer0.size.height; unsigned char *dest_data = (unsigned char *) colorbuffer0.data; CL_Color c = color; unsigned int color8888 = (c.get_alpha() << 24) + (c.get_red() << 16) + (c.get_green() << 8) + c.get_blue(); unsigned char *ptr_color8888 = (unsigned char *) &color8888; for (int y = find_first_line_for_core(clip_rect.top, core, num_cores); y < clip_rect.bottom; y += num_cores) { unsigned char *line = dest_data + y * dest_buffer_width * 4 + clip_rect.left * 4; unsigned int line_align = ((line) - ((unsigned char *) 0)) & 0xf; // A gcc safe way of obtaining an address int pos = 0; int length = clip_rect.get_width()*4; // Write single bytes until we are byte aligned: if (line_align) { int prefix_length = cl_min(length, (int) (16 - line_align)); for (; pos < prefix_length; pos++) line[pos] = ptr_color8888[pos&0x3]; } // Figure out how our 16 bytes should look like after we applied the alignment: unsigned int b0 = ptr_color8888[(pos+0)&0x3]; unsigned int b1 = ptr_color8888[(pos+1)&0x3]; unsigned int b2 = ptr_color8888[(pos+2)&0x3]; unsigned int b3 = ptr_color8888[(pos+3)&0x3]; __m128i c_sse = _mm_set1_epi32((b3<<24)+(b2<<16)+(b1<<8)+b0); // Fill 16 byte aligned: int align_length = length-pos-15; for (; pos < align_length; pos+=16) _mm_stream_si128((__m128i*)(line+pos), c_sse); // Fill remaining bytes: for (; pos < length; pos++) line[pos] = ptr_color8888[pos&0x3]; } }
float CL_LineMath::distance_to_line(float x, float y, float *line) { const float &Ax = line[0]; const float &Ay = line[1]; const float &Bx = line[2]; const float &By = line[3]; float L = sqrt( pow2(Bx-Ax) + pow2(By-Ay) ); float r = ((x-Ax)*(Bx-Ax)+(y-Ay)*(By-Ay))/pow2(L); if( r <= 0 || r >= 1 ) { CL_Pointf p(x,y); CL_Pointf A(Ax,Ay); CL_Pointf B(Bx,By); return cl_min( p.distance(A), p.distance(B) ); } float s = ((Ay-y)*(Bx-Ax)-(Ax-x)*(By-Ay)) / pow2(L); return fabs(s)*L; }
Rect Rect::get_rot_bounds(const Point &hotspot, float angle) const { //Find the rotated positions of each corner Rect retVal(*this); Point ul = Point(retVal.left, retVal.top).rotate(hotspot, angle); Point ur = Point(retVal.right, retVal.top).rotate(hotspot, angle); Point ll = Point(retVal.left, retVal.bottom).rotate(hotspot, angle); Point lr = Point(retVal.right, retVal.bottom).rotate(hotspot, angle); //Use the sidemost corners as the bounds of the new rectangle retVal.left = cl_min(cl_min(ul.x, ur.x), cl_min(ll.x, lr.x)); retVal.right = cl_max(cl_max(ul.x, ur.x), cl_max(ll.x, lr.x)); retVal.top = cl_min(cl_min(ul.y, ur.y), cl_min(ll.y, lr.y)); retVal.bottom = cl_max(cl_max(ul.y, ur.y), cl_max(ll.y, lr.y)); return retVal; }
void CL_CSSUsedValues::set_height(const CL_CSSBoxProperties &properties) { height = 0; undetermined_height = false; if (replaced) { if (!is_absolute(properties)) { if (properties.height.type == CL_CSSBoxHeight::type_length) { height = properties.height.length.value; } else if (properties.height.type == CL_CSSBoxHeight::type_percentage) { if (containing.undetermined_height) { height = 0; undetermined_height = true; } else { height = containing.height * properties.height.percentage / 100.0f; } } else if (properties.height.type == CL_CSSBoxHeight::type_auto) { height = 0; undetermined_height = true; } } else { height = 0; undetermined_height = true; // 'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block } } else if (is_inline(properties)) { // Height does not apply. height = 0; undetermined_height = true; } else if (is_block(properties)) { if (properties.height.type == CL_CSSBoxHeight::type_length) { height = properties.height.length.value; } else if (properties.height.type == CL_CSSBoxHeight::type_percentage) { if (containing.undetermined_height) { height = 0; undetermined_height = true; } else { height = containing.height * properties.height.percentage / 100.0f; } } else if (properties.height.type == CL_CSSBoxHeight::type_auto) { height = 0; undetermined_height = true; } } else if (is_absolute(properties)) { height = 0; undetermined_height = true; // 'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block } if (!undetermined_height) { if (properties.max_height.type == CL_CSSBoxMaxHeight::type_length) { height = cl_min(height, properties.max_height.length.value); } else if (properties.max_height.type == CL_CSSBoxMaxHeight::type_percentage && !containing.undetermined_height) { height = cl_min(height, properties.max_height.percentage * containing.height / 100.0f); } if (properties.min_height.type == CL_CSSBoxMinHeight::type_length) { height = cl_max(height, properties.min_height.length.value); } else if (properties.min_height.type == CL_CSSBoxMinHeight::type_percentage && !containing.undetermined_height) { height = cl_max(height, properties.min_height.percentage * containing.height / 100.0f); } } calc_noncontent_height(properties); }
void CL_ListViewIcon::draw(CL_GraphicContext &gc, const CL_Rect &rect, CL_ListViewDisplayMode mode, const CL_Colorf &color) { CL_Sprite sp = get_sprite(mode); if (!sp.is_null()) { float scale = 1.0; sp.set_color(color); // if (mode == listview_mode_thumbnails && sp.get_frame_size(0) != rect.get_size()) if (impl->scalable && (sp.get_frame_size(0) != rect.get_size())) { // Scale to max vertically or horizontally. float sx, sy; sx = rect.get_width()/float(sp.get_width()); sy = rect.get_height()/(float)sp.get_height(); if (sx <= 0 || sy <= 0) { return; } scale = cl_min(sx, sy); sp.set_scale(scale,scale); } CL_Rect R = rect; CL_Point offset = get_offset(mode); R.translate(offset); if (!impl->scalable && offset == CL_Point(0,0)) { // center in cell rect. int center_offset_x = int((float)rect.get_center().x - (float)rect.left - scale*(float)sp.get_width()/2.0); int center_offset_y = int((float)rect.get_center().y - (float)rect.top - scale*(float)sp.get_height()/2.0); R.left += center_offset_x; R.top += center_offset_y; } if (!impl->scalable) sp.draw(gc, (float)R.left, (float)R.top); else sp.draw(gc, R); return; } CL_PixelBuffer pb = get_pixel_buffer(mode); if (!pb.is_null()) { float scale = 1.0; float center_offset_x = 0, center_offset_y = 0; // if (mode == listview_mode_thumbnails && pb.get_size() != rect.get_size()) if (impl->scalable && (pb.get_size() != rect.get_size())) { float sx = 1.0, sy = 1.0; // Scale to max vertically or horizontally. sx = rect.get_width()/float(pb.get_width()); sy = rect.get_height()/(float)pb.get_height(); if (sx <= 0 || sy <= 0) { return; } scale = cl_min(sx, sy); // center in the rect. center_offset_x = (float)rect.get_center().x - (float)rect.left - scale*(float)pb.get_width()/2.0f; center_offset_y = (float)rect.get_center().y - (float)rect.top - scale*(float)pb.get_height()/2.0f; } CL_Point offset = get_offset(mode); gc.draw_pixels(rect.left + center_offset_x + offset.x, rect.top + center_offset_y + offset.y, scale, scale, pb, pb.get_size(), color); } }
void CL_CSSUsedValues::set_width(const CL_CSSBoxProperties &properties) { margin.left = get_margin_width(properties.margin_width_left); margin.right = get_margin_width(properties.margin_width_right); border.left = properties.border_width_left.length.value; border.right = properties.border_width_right.length.value; padding.left = get_padding_width(properties.padding_width_left); padding.right = get_padding_width(properties.padding_width_right); width = 0; undetermined_width = false; if (replaced) { if (properties.width.type == CL_CSSBoxWidth::type_auto && properties.height.type == CL_CSSBoxHeight::type_auto && intrinsic.has_width) { width = intrinsic.width; } else if (properties.width.type == CL_CSSBoxWidth::type_auto && properties.height.type == CL_CSSBoxHeight::type_auto && intrinsic.has_height && intrinsic.has_ratio) { width = intrinsic.height / intrinsic.ratio; } else if (properties.width.type == CL_CSSBoxWidth::type_auto && properties.height.type == CL_CSSBoxHeight::type_auto && intrinsic.has_ratio) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { width = containing.width - margin.left - margin.right - border.left - border.right - padding.left - padding.right; } } else if (properties.width.type == CL_CSSBoxWidth::type_auto && intrinsic.has_width) { width = intrinsic.width; } else if (properties.width.type == CL_CSSBoxWidth::type_auto) { width = 300; // bug: Should be 300px (css physical length) /*if (width > device.width) { width = largest_2_1_ratio_rect(); }*/ } } else if (is_inline(properties)) { // width property does not apply. width = 0; undetermined_width = true; } else if (is_absolute(properties)) { if (properties.width.type == CL_CSSBoxWidth::type_length) { width = properties.width.length.value; } else if (properties.width.type == CL_CSSBoxWidth::type_percentage) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { width = properties.width.percentage * containing.width / 100.0f; } } else if (properties.width.type == CL_CSSBoxWidth::type_auto && properties.left.type != CL_CSSBoxLeft::type_auto && properties.right.type != CL_CSSBoxRight::type_auto) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { // To do: Handle the cases where the length property is a percentage. Also determine what the containing box is (the viewport/page-area?) width = containing.width - properties.left.length.value - properties.right.length.value - margin.left - margin.right - border.left - border.right - padding.left - padding.right; } } else if (properties.width.type == CL_CSSBoxWidth::type_auto) { width = 0.0f; undetermined_width = true; // shrink-to-fit } } else if (is_floating(properties) || is_inline_block(properties)) { if (properties.width.type == CL_CSSBoxWidth::type_length) { width = properties.width.length.value; } else if (properties.width.type == CL_CSSBoxWidth::type_percentage) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { width = properties.width.percentage * containing.width / 100.0f; } } else if (properties.width.type == CL_CSSBoxWidth::type_auto) { width = 0.0f; undetermined_width = true; // shrink-to-fit } } else if (is_block(properties)) { if (properties.width.type == CL_CSSBoxWidth::type_length) { width = properties.width.length.value; } else if (properties.width.type == CL_CSSBoxWidth::type_percentage) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { width = properties.width.percentage * containing.width / 100.0f; } } else if (properties.width.type == CL_CSSBoxWidth::type_auto) { if (containing.undetermined_width) { width = 0; undetermined_width = true; } else { width = cl_max(0.0f, containing.width - margin.left - margin.right - border.left - border.right - padding.left - padding.right); } } } if (!undetermined_width) { if (properties.max_width.type == CL_CSSBoxMaxWidth::type_length) { width = cl_min(width, properties.max_width.length.value); } else if (properties.max_width.type == CL_CSSBoxMaxWidth::type_percentage && !containing.undetermined_width) { width = cl_min(width, properties.max_width.percentage * containing.width / 100.0f); } if (properties.min_width.type == CL_CSSBoxMinWidth::type_length) { width = cl_max(width, properties.min_width.length.value); } else if (properties.min_width.type == CL_CSSBoxMinWidth::type_percentage && !containing.undetermined_width) { width = cl_max(width, properties.min_width.percentage * containing.width / 100.0f); } } calc_noncontent_width(properties); }
size_t CL_RingBuffer::get_read_size() { size_t end_pos = cl_min(pos + length, size); return end_pos - pos; }
void CL_PixelFillRenderer::fill_rect(const CL_Rect &dest, const CL_Colorf &primary_color) { int dest_buffer_width = colorbuffer0.size.width; int dest_buffer_height = colorbuffer0.size.height; unsigned int *dest_data = colorbuffer0.data; int start_x = cl_max(dest.left, clip_rect.left); int end_x = cl_min(dest.right, clip_rect.right); int start_y = cl_max(dest.top, clip_rect.top); int end_y = cl_min(dest.bottom, clip_rect.bottom); if (start_x < end_x && start_y < end_y) { int dest_y = find_first_line_for_core(start_y, core, num_cores); int delta_x = start_x-dest.left; int delta_y = dest_y-dest.top; unsigned int *dest_line = dest_data+dest_y*dest_buffer_width+start_x; int line_length = end_x-start_x; int dest_line_incr = dest_buffer_width * num_cores; unsigned int sred = (unsigned int) (primary_color.r*255); unsigned int sgreen = (unsigned int) (primary_color.g*255); unsigned int sblue = (unsigned int) (primary_color.b*255); unsigned int salpha = (unsigned int) (primary_color.a*255); if (salpha == 255) { unsigned int color = (salpha<<24) + (sred<<16) + (sgreen<<8) + sblue; while (dest_y < end_y) { for (int x = 0; x < line_length; x++) dest_line[x] = color; dest_y += num_cores; dest_line += dest_line_incr; } } else { unsigned int pos_salpha = salpha*256/255; unsigned int neg_salpha = 256-salpha; while (dest_y < end_y) { for (int x = 0; x < line_length; x++) { #define alpha_component(a) (((a)&0xff000000)>>24) #define red_component(a) (((a)&0x00ff0000)>>16) #define green_component(a) (((a)&0x0000ff00)>>8) #define blue_component(a) ((a)&0x000000ff) unsigned int dest_color = dest_line[x]; unsigned int dred = red_component(dest_color); unsigned int dgreen = green_component(dest_color); unsigned int dblue = blue_component(dest_color); unsigned int dalpha = alpha_component(dest_color); unsigned red = (dred * neg_salpha + sred * pos_salpha) >> 8; unsigned green = (dgreen * neg_salpha + sgreen * pos_salpha) >> 8; unsigned blue = (dblue * neg_salpha + sblue * pos_salpha) >> 8; unsigned alpha = (dalpha * neg_salpha + salpha * pos_salpha) >> 8; dest_line[x] = (alpha<<24) + (red<<16) + (green<<8) + blue; } dest_y += num_cores; dest_line += dest_line_incr; } } }