void CL_SpanLayout_Impl::layout_inline_block(CurrentLine ¤t_line, int max_width, std::vector<TextBlock> &blocks, std::vector<TextBlock>::size_type block_index) { CL_Size size; LineSegment segment; if (objects[current_line.object_index].type == object_image) { size = objects[current_line.object_index].image.get_size(); segment.type = object_image; segment.image = objects[current_line.object_index].image; } else if (objects[current_line.object_index].type == object_component) { size = objects[current_line.object_index].component->get_size(); segment.type = object_component; segment.component = objects[current_line.object_index].component; } if (current_line.x_position + size.width > max_width) next_line(current_line); segment.x_position = current_line.x_position; segment.width = size.width; segment.start = blocks[block_index].start; segment.end = blocks[block_index].end; segment.id = objects[current_line.object_index].id; segment.ascender = size.height - objects[current_line.object_index].baseline_offset; current_line.cur_line.segments.push_back(segment); current_line.cur_line.height = cl_max(current_line.cur_line.height, size.height+objects[current_line.object_index].baseline_offset); current_line.cur_line.ascender = cl_max(current_line.cur_line.ascender, segment.ascender); current_line.x_position += size.width; }
void CL_SpanLayout_Impl::layout_text(CL_GraphicContext & gc, std::vector<TextBlock> blocks, std::vector<TextBlock>::size_type block_index, CurrentLine ¤t_line, int max_width) { TextSizeResult text_size_result = find_text_size(gc, blocks[block_index], current_line.object_index); current_line.object_index += text_size_result.objects_traversed; current_line.cur_line.width = current_line.x_position; if (is_newline(blocks[block_index])) { current_line.cur_line.height = cl_max(current_line.cur_line.height, text_size_result.height); current_line.cur_line.ascender = cl_max(current_line.cur_line.ascender, text_size_result.ascender); next_line(current_line); } else { if (!fits_on_line(current_line.x_position, text_size_result, max_width) && !is_whitespace(blocks[block_index])) { if (larger_than_line(text_size_result, max_width)) { // force line breaks to make it fit force_place_line_segments(current_line, text_size_result, max_width); } else { next_line(current_line); place_line_segments(current_line, text_size_result); } } else { place_line_segments(current_line, text_size_result); } } }
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; }
int CL_GUIManager_Generic::find_highest_tab_id(const CL_Component *component) { int id = cl_max(0, component->get_tab_id()); const std::list<CL_Component *> &children = component->get_children(); std::list<CL_Component *>::const_iterator it; for (it = children.begin(); it != children.end(); it++) { id = cl_max(id, find_highest_tab_id(*it)); } return id; }
void CL_SpanLayout_Impl::place_line_segments(CurrentLine ¤t_line, TextSizeResult &text_size_result) { for (std::vector<LineSegment>::iterator it = text_size_result.segments.begin(); it != text_size_result.segments.end(); ++it) { LineSegment segment = *it; segment.x_position += current_line.x_position; current_line.cur_line.segments.push_back(segment); } current_line.x_position += text_size_result.width; current_line.cur_line.height = cl_max(current_line.cur_line.height, text_size_result.height); current_line.cur_line.ascender = cl_max(current_line.cur_line.ascender, text_size_result.ascender); }
void CL_ScrollBar::calculate_ranges(int view_size, int total_size) { if (view_size <= 0 || total_size <= 0) { set_ranges(0, 1, 1, 1); } else { int scroll_max = cl_max(1, total_size - view_size + 1); int page_step = cl_max(1, view_size); set_ranges(0, scroll_max, 1, page_step); } }
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; } }
void TileMap::draw(CL_GraphicContext &gc) { int screen_width = gc.get_width(); int screen_height = gc.get_height(); int start_tile_x = cl_max(0, current_map_position_x / tile_width); int start_tile_y = cl_max(0, current_map_position_y / tile_height); int scrolling_pixel_offset_x = current_map_position_x - start_tile_x * tile_width; int scrolling_pixel_offset_y = current_map_position_y - start_tile_y * tile_height; int tiles_on_screen_horizontally = screen_width / tile_width + 1; int tiles_on_screen_vertically = screen_height / tile_height + 1; // since we might show half tiles on edges, make sure we display one more tile to fill screen tiles_on_screen_horizontally++; tiles_on_screen_vertically++; // make sure we don't draw more than the level size if(tiles_on_screen_horizontally + start_tile_x > map_width) tiles_on_screen_horizontally = map_width - start_tile_x; if(tiles_on_screen_vertically + start_tile_y > map_height) tiles_on_screen_vertically = map_height - start_tile_y; for(size_t l = 0; l < layers.size(); ++l) { for(int current_tile_y = 0; current_tile_y < tiles_on_screen_vertically; ++current_tile_y) { for(int current_tile_x = 0; current_tile_x < tiles_on_screen_horizontally; ++current_tile_x) { int index = (start_tile_y + current_tile_y) * map_width + (start_tile_x + current_tile_x); int sprite_index = layers[l].map[index]; int tile_position_screen_x = current_tile_x * tile_width - scrolling_pixel_offset_x; int tile_position_screen_y = current_tile_y * tile_height - scrolling_pixel_offset_y; sprite_tiles.set_frame(sprite_index); sprite_tiles.draw(gc, tile_position_screen_x, tile_position_screen_y); } } } }
void GameViewBattle::on_timer_hide_expired() { if(attack_results.size() > 0 && defense_results.size() > 0) { current_dice_index++; int max_dice = cl_max(attack_results.size(), defense_results.size()); if(current_dice_index > max_dice + 2) close(); } }
CL_Size CL_SpanLayout_Impl::get_size() const { CL_Size size(0,0); int x = 0; int y = 0; for (std::vector<Line>::size_type line_index = 0; line_index < lines.size(); line_index++) { const Line &line = lines[line_index]; for (std::vector<LineSegment>::size_type segment_index = 0; segment_index < line.segments.size(); segment_index++) { const LineSegment &segment = line.segments[segment_index]; CL_Rect area(CL_Point(x + segment.x_position, y - line.height), CL_Size(segment.width, line.height)); size.width = cl_max(size.width, area.right); size.height = cl_max(size.height, area.bottom); } y += line.height; } size.height = cl_max(size.height, y); return size; }
static void change_precision(float_approx *approx, cl_object position, cl_object relativep) { cl_fixnum pos; if (Null(position)) return; pos = ecl_fixnum(position); if (!Null(relativep)) { cl_object k = ecl_make_fixnum(0); cl_object l = ecl_make_fixnum(1); while (ecl_lower(ecl_times(approx->s, l), ecl_plus(approx->r, approx->mp))) { k = ecl_one_plus(k); l = ecl_times(l, PRINT_BASE); } position = ecl_minus(k, position); { cl_object e1 = cl_expt(PRINT_BASE, position); cl_object e2 = ecl_divide(e1, ecl_make_fixnum(2)); cl_object e3 = cl_expt(PRINT_BASE, k); if (ecl_greatereq(ecl_plus(approx->r, ecl_times(approx->s, e1)), ecl_times(approx->s, e2))) position = ecl_one_minus(position); } } { cl_object x = ecl_times(approx->s, cl_expt(PRINT_BASE, position)); cl_object e = ecl_divide(x, ecl_make_fixnum(2)); cl_object low = cl_max(2, approx->mm, e); cl_object high = cl_max(2, approx->mp, e); if (ecl_lowereq(approx->mm, low)) { approx->mm = low; approx->low_ok = 1; } if (ecl_lowereq(approx->mp, high)) { approx->mp = high; approx->high_ok = 1; } } }
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_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_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<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<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); }
void TileMap::draw(CL_GraphicContext& gc) { int screen_width = gc.get_width(); int screen_height = gc.get_height(); int horiz_tiles = screen_width / tile_width + 1; int vert_tiles = screen_height / tile_height + 1; // avoid half tiles by increasing by one horiz_tiles++; vert_tiles++; int start_tilex = cl_max(0, cur_map_x / tile_width); int start_tiley = cl_max(0, cur_map_y / tile_height); int scroll_offsetx = cur_map_x - start_tilex * tile_width; int scroll_offsety = cur_map_y - start_tiley * tile_width; if (horiz_tiles + start_tilex > map_width) horiz_tiles = map_width - start_tilex; if (vert_tiles + start_tiley > map_height) vert_tiles = map_height - start_tiley; for (MapLayer& layer : layers) { for (int cur_y = 0; cur_y < vert_tiles; ++cur_y) { for (int cur_x = 0; cur_x < horiz_tiles; ++cur_x) { int idx = (start_tiley + cur_y) * map_width + start_tilex + cur_x; int sprite_idx = layer.map[idx]; int tile_xpos = cur_x * tile_width - scroll_offsetx; int tile_ypos = cur_y * tile_height - scroll_offsety; tiles.set_frame(sprite_idx); tiles.draw(gc, tile_xpos, tile_ypos); } } } }
void GameViewBattle::on_message(CL_GUIMessage &message) { if (message.is_type(CL_GUIMessage_Input::get_type_name())) { CL_GUIMessage_Input msg_input = message; CL_InputEvent e = msg_input.get_event(); if (e.type == CL_InputEvent::pressed) { int max_dice = cl_max(attack_results.size(), defense_results.size()); if(current_dice_index < max_dice) current_dice_index = max_dice; else close(); } } }
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_PixelPipeline::alloc_command(size_t s) { #if defined(WIN32) && defined(PROFILE_PIPELINE) unsigned __int64 start_time = __rdtsc(); #endif s += sizeof(unsigned int); s = ((s+63)/64)*64; // Place each command in its own cache line (is this really smart?) if (cur_block == 0 || cur_block->pos+s > cur_block->size) { if (cur_block) { cur_block->refcount--; if (cur_block->refcount == 0) delete[] (char*) cur_block; } cur_block = 0; size_t block_size = cl_max(s, (size_t)16*1024); char *data = new char[sizeof(AllocBlock) + block_size]; cur_block = (AllocBlock *)data; cur_block->size = block_size; cur_block->data = data + sizeof(AllocBlock); cur_block->pos = 0; cur_block->refcount = 1; } char *d = cur_block->data + cur_block->pos; unsigned int *p = (unsigned int *) d; d += sizeof(unsigned int); *p = (unsigned int) cur_block->pos; cur_block->pos += s; cur_block->refcount++; #if defined(WIN32) && defined(PROFILE_PIPELINE) unsigned __int64 end_time = __rdtsc(); profiler.alloc_time += end_time-start_time; #endif return d; }
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_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); }
void CL_CSSUsedValues::calc_noncontent_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); if (is_inline(properties) || is_inline_block(properties) || is_floating(properties)) { // Do nothing. Correct values already set by get_margin_width. } else if (is_block(properties)) { if (properties.margin_width_left.type == CL_CSSBoxMarginWidth::type_auto && properties.margin_width_right.type == CL_CSSBoxMarginWidth::type_auto) { margin.left = cl_max(0.0f, (containing.width-border.left-border.right-padding.left-padding.right-width)/2.0f); margin.right = cl_max(0.0f, containing.width-border.left-border.right-padding.left-padding.right-width-margin.left); } else if (properties.margin_width_left.type == CL_CSSBoxMarginWidth::type_auto) { margin.left = cl_max(0.0f, containing.width-margin.right-border.left-border.right-padding.left-padding.right-width); } else if (properties.margin_width_right.type == CL_CSSBoxMarginWidth::type_auto) { margin.right = cl_max(0.0f, containing.width-margin.left-border.left-border.right-padding.left-padding.right-width); } if (margin.left + border.left + width + border.right + padding.right + margin.right > containing.width) { if (properties.direction.type == CL_CSSBoxDirection::type_ltr) margin.right = cl_max(0.0f, containing.width-margin.left-border.left-border.right-padding.left-padding.right-width); else margin.left = cl_max(0.0f, containing.width-margin.right-border.left-border.right-padding.left-padding.right-width); } } else if (is_absolute(properties) && !replaced) { // Lots of annoying calculations here using 'left', 'right', 'width', 'direction' and the margin+border+padding+width=containing.width constraint } else if (is_absolute(properties) && replaced) { if (properties.margin_width_left.type == CL_CSSBoxMarginWidth::type_auto) { if (properties.left.type == CL_CSSBoxLeft::type_auto || properties.right.type == CL_CSSBoxRight::type_auto) { margin.left = 0; } else { // solve using margin+border+padding+width=containing.width constraint } } if (properties.margin_width_right.type == CL_CSSBoxMarginWidth::type_auto) { if (properties.left.type == CL_CSSBoxLeft::type_auto || properties.right.type == CL_CSSBoxRight::type_auto) { margin.right = 0; } else { // solve using margin+border+padding+width=containing.width constraint } } } }
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_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; } } }