void HUD_Lua_Class::draw_shape(Shape_Blitter *shape, float x, float y) { if (!m_drawing) return; Image_Rect r; r.x = x; r.y = y; r.w = shape->crop_rect.w; r.h = shape->crop_rect.h; if (!r.w || !r.h) return; apply_clip(); #ifdef HAVE_OPENGL if (m_opengl) { shape->OGL_Draw(r); } else #endif if (m_surface) { r.x += m_wr.x; r.y += m_wr.y; shape->SDL_Draw(SDL_GetVideoSurface(), r); } }
void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos ) { apply_clip((HDC) hdc); // draw left border if(borders.left.width.val() != 0 && borders.left.style > litehtml::border_style_hidden) { HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.left.color.red, borders.left.color.green, borders.left.color.blue)); HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen); for(int x = 0; x < borders.left.width.val(); x++) { MoveToEx((HDC) hdc, draw_pos.left() + x, draw_pos.top(), NULL); LineTo((HDC) hdc, draw_pos.left() + x, draw_pos.bottom()); } SelectObject((HDC) hdc, oldPen); DeleteObject(pen); } // draw right border if(borders.right.width.val() != 0 && borders.right.style > litehtml::border_style_hidden) { HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.right.color.red, borders.right.color.green, borders.right.color.blue)); HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen); for(int x = 0; x < borders.right.width.val(); x++) { MoveToEx((HDC) hdc, draw_pos.right() - x - 1, draw_pos.top(), NULL); LineTo((HDC) hdc, draw_pos.right() - x - 1, draw_pos.bottom()); } SelectObject((HDC) hdc, oldPen); DeleteObject(pen); } // draw top border if(borders.top.width.val() != 0 && borders.top.style > litehtml::border_style_hidden) { HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.top.color.red, borders.top.color.green, borders.top.color.blue)); HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen); for(int y = 0; y < borders.top.width.val(); y++) { MoveToEx((HDC) hdc, draw_pos.left(), draw_pos.top() + y, NULL); LineTo((HDC) hdc, draw_pos.right(), draw_pos.top() + y); } SelectObject((HDC) hdc, oldPen); DeleteObject(pen); } // draw bottom border if(borders.bottom.width.val() != 0 && borders.bottom.style > litehtml::border_style_hidden) { HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.bottom.color.red, borders.bottom.color.green, borders.bottom.color.blue)); HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen); for(int y = 0; y < borders.bottom.width.val(); y++) { MoveToEx((HDC) hdc, draw_pos.left(), draw_pos.bottom() - y - 1, NULL); LineTo((HDC) hdc, draw_pos.right(), draw_pos.bottom() - y - 1); } SelectObject((HDC) hdc, oldPen); DeleteObject(pen); } release_clip((HDC) hdc); }
void cairo_container::fill_ellipse( cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color ) { if(!cr) return; cairo_save(cr); apply_clip(cr); cairo_new_path(cr); cairo_translate (cr, x + width / 2.0, y + height / 2.0); cairo_scale (cr, width / 2.0, height / 2.0); cairo_arc (cr, 0, 0, 1, 0, 2 * M_PI); set_color(cr, color); cairo_fill(cr); cairo_restore(cr); }
void HUD_Lua_Class::draw_image(Image_Blitter *image, float x, float y) { if (!m_drawing) return; Image_Rect r = { x, y, image->crop_rect.w, image->crop_rect.h }; if (!r.w || !r.h) return; apply_clip(); if (m_surface) { r.x += m_wr.x; r.y += m_wr.y; } image->Draw(SDL_GetVideoSurface(), r); }
void cairo_container::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos ) { if(hFont) { cairo_font* fnt = (cairo_font*) hFont; cairo_t* cr = (cairo_t*) hdc; cairo_save(cr); apply_clip(cr); int x = pos.left(); int y = pos.bottom() - fnt->metrics().descent; set_color(cr, color); fnt->show_text(cr, x, y, text); cairo_restore(cr); } }
void cairo_container::draw_image( litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos ) { cairo_t* cr = (cairo_t*) hdc; cairo_save(cr); apply_clip(cr); std::wstring url; t_make_url(src, baseurl, url); lock_images_cache(); images_map::iterator img = m_images.find(url.c_str()); if(img != m_images.end()) { if(img->second) { draw_txdib(cr, img->second.get(), pos.x, pos.y, pos.width, pos.height); } } unlock_images_cache(); cairo_restore(cr); }
void HUD_Lua_Class::fill_rect(float x, float y, float w, float h, float r, float g, float b, float a) { if (!m_drawing) return; if (!w || !h) return; apply_clip(); #ifdef HAVE_OPENGL if (m_opengl) { glColor4f(r, g, b, a); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glVertex2f(x, y); glVertex2f(x + w, y); glVertex2f(x + w, y + h); glVertex2f(x, y + h); glEnd(); glEnable(GL_TEXTURE_2D); } else #endif if (m_surface) { SDL_Rect rect; rect.x = static_cast<Sint16>(x) + m_wr.x; rect.y = static_cast<Sint16>(y) + m_wr.y; rect.w = static_cast<Uint16>(w); rect.h = static_cast<Uint16>(h); SDL_FillRect(m_surface, &rect, SDL_MapRGBA(m_surface->format, static_cast<unsigned char>(r * 255), static_cast<unsigned char>(g * 255), static_cast<unsigned char>(b * 255), static_cast<unsigned char>(a * 255))); SDL_BlitSurface(m_surface, &rect, SDL_GetVideoSurface(), &rect); } }
void cairo_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root ) { cairo_t* cr = (cairo_t*) hdc; cairo_save(cr); apply_clip(cr); cairo_new_path(cr); int bdr_top = 0; int bdr_bottom = 0; int bdr_left = 0; int bdr_right = 0; if(borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden) { bdr_top = (int) borders.top.width; } if(borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden) { bdr_bottom = (int) borders.bottom.width; } if(borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden) { bdr_left = (int) borders.left.width; } if(borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden) { bdr_right = (int) borders.right.width; } // draw right border if (bdr_right) { set_color(cr, borders.right.color); double r_top = (double) borders.radius.top_right_x; double r_bottom = (double) borders.radius.bottom_right_x; if(r_top) { double end_angle = 2.0 * M_PI; double start_angle = end_angle - M_PI / 2.0 / ((double) bdr_top / (double) bdr_right + 0.5); if (!add_path_arc(cr, draw_pos.right() - r_top, draw_pos.top() + r_top, r_top - bdr_right, r_top - bdr_right + (bdr_right - bdr_top), end_angle, start_angle, true)) { cairo_move_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top); } if (!add_path_arc(cr, draw_pos.right() - r_top, draw_pos.top() + r_top, r_top, r_top, start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.right(), draw_pos.top()); } } else { cairo_move_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top); cairo_line_to(cr, draw_pos.right(), draw_pos.top()); } if(r_bottom) { cairo_line_to(cr, draw_pos.right(), draw_pos.bottom() - r_bottom); double start_angle = 0; double end_angle = start_angle + M_PI / 2.0 / ((double) bdr_bottom / (double) bdr_right + 0.5); if (!add_path_arc(cr, draw_pos.right() - r_bottom, draw_pos.bottom() - r_bottom, r_bottom, r_bottom, start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.right(), draw_pos.bottom()); } if (!add_path_arc(cr, draw_pos.right() - r_bottom, draw_pos.bottom() - r_bottom, r_bottom - bdr_right, r_bottom - bdr_right + (bdr_right - bdr_bottom), end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom); } } else { cairo_line_to(cr, draw_pos.right(), draw_pos.bottom()); cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom); } cairo_fill(cr); } // draw bottom border if(bdr_bottom) { set_color(cr, borders.bottom.color); double r_left = borders.radius.bottom_left_x; double r_right = borders.radius.bottom_right_x; if(r_left) { double start_angle = M_PI / 2.0; double end_angle = start_angle + M_PI / 2.0 / ((double) bdr_left / (double) bdr_bottom + 0.5); if (!add_path_arc(cr, draw_pos.left() + r_left, draw_pos.bottom() - r_left, r_left - bdr_bottom + (bdr_bottom - bdr_left), r_left - bdr_bottom, start_angle, end_angle, false)) { cairo_move_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom); } if (!add_path_arc(cr, draw_pos.left() + r_left, draw_pos.bottom() - r_left, r_left, r_left, end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.left(), draw_pos.bottom()); } } else { cairo_move_to(cr, draw_pos.left(), draw_pos.bottom()); cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom); } if(r_right) { cairo_line_to(cr, draw_pos.right() - r_right, draw_pos.bottom()); double end_angle = M_PI / 2.0; double start_angle = end_angle - M_PI / 2.0 / ((double) bdr_right / (double) bdr_bottom + 0.5); if (!add_path_arc(cr, draw_pos.right() - r_right, draw_pos.bottom() - r_right, r_right, r_right, end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.right(), draw_pos.bottom()); } if (!add_path_arc(cr, draw_pos.right() - r_right, draw_pos.bottom() - r_right, r_right - bdr_bottom + (bdr_bottom - bdr_right), r_right - bdr_bottom, start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom); } } else { cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom); cairo_line_to(cr, draw_pos.right(), draw_pos.bottom()); } cairo_fill(cr); } // draw top border if(bdr_top) { set_color(cr, borders.top.color); double r_left = borders.radius.top_left_x; double r_right = borders.radius.top_right_x; if(r_left) { double end_angle = M_PI * 3.0 / 2.0; double start_angle = end_angle - M_PI / 2.0 / ((double) bdr_left / (double) bdr_top + 0.5); if (!add_path_arc(cr, draw_pos.left() + r_left, draw_pos.top() + r_left, r_left, r_left, end_angle, start_angle, true)) { cairo_move_to(cr, draw_pos.left(), draw_pos.top()); } if (!add_path_arc(cr, draw_pos.left() + r_left, draw_pos.top() + r_left, r_left - bdr_top + (bdr_top - bdr_left), r_left - bdr_top, start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top); } } else { cairo_move_to(cr, draw_pos.left(), draw_pos.top()); cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top); } if(r_right) { cairo_line_to(cr, draw_pos.right() - r_right, draw_pos.top() + bdr_top); double start_angle = M_PI * 3.0 / 2.0; double end_angle = start_angle + M_PI / 2.0 / ((double) bdr_right / (double) bdr_top + 0.5); if (!add_path_arc(cr, draw_pos.right() - r_right, draw_pos.top() + r_right, r_right - bdr_top + (bdr_top - bdr_right), r_right - bdr_top, start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top); } if (!add_path_arc(cr, draw_pos.right() - r_right, draw_pos.top() + r_right, r_right, r_right, end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.right(), draw_pos.top()); } } else { cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top); cairo_line_to(cr, draw_pos.right(), draw_pos.top()); } cairo_fill(cr); } // draw left border if (bdr_left) { set_color(cr, borders.left.color); double r_top = borders.radius.top_left_x; double r_bottom = borders.radius.bottom_left_x; if(r_top) { double start_angle = M_PI; double end_angle = start_angle + M_PI / 2.0 / ((double) bdr_top / (double) bdr_left + 0.5); if (!add_path_arc(cr, draw_pos.left() + r_top, draw_pos.top() + r_top, r_top - bdr_left, r_top - bdr_left + (bdr_left - bdr_top), start_angle, end_angle, false)) { cairo_move_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top); } if (!add_path_arc(cr, draw_pos.left() + r_top, draw_pos.top() + r_top, r_top, r_top, end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.left(), draw_pos.top()); } } else { cairo_move_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top); cairo_line_to(cr, draw_pos.left(), draw_pos.top()); } if(r_bottom) { cairo_line_to(cr, draw_pos.left(), draw_pos.bottom() - r_bottom); double end_angle = M_PI; double start_angle = end_angle - M_PI / 2.0 / ((double) bdr_bottom / (double) bdr_left + 0.5); if (!add_path_arc(cr, draw_pos.left() + r_bottom, draw_pos.bottom() - r_bottom, r_bottom, r_bottom, end_angle, start_angle, true)) { cairo_line_to(cr, draw_pos.left(), draw_pos.bottom()); } if (!add_path_arc(cr, draw_pos.left() + r_bottom, draw_pos.bottom() - r_bottom, r_bottom - bdr_left, r_bottom - bdr_left + (bdr_left - bdr_bottom), start_angle, end_angle, false)) { cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom); } } else { cairo_line_to(cr, draw_pos.left(), draw_pos.bottom()); cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom); } cairo_fill(cr); } cairo_restore(cr); }
void cairo_container::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg ) { cairo_t* cr = (cairo_t*) hdc; cairo_save(cr); apply_clip(cr); rounded_rectangle(cr, bg.border_box, bg.border_radius); cairo_clip(cr); cairo_rectangle(cr, bg.clip_box.x, bg.clip_box.y, bg.clip_box.width, bg.clip_box.height); cairo_clip(cr); if(bg.color.alpha) { set_color(cr, bg.color); cairo_paint(cr); } std::wstring url; t_make_url(bg.image.c_str(), bg.baseurl.c_str(), url); lock_images_cache(); images_map::iterator img_i = m_images.find(url.c_str()); if(img_i != m_images.end() && img_i->second) { image_ptr bgbmp = img_i->second; image_ptr new_img; if(bg.image_size.width != bgbmp->getWidth() || bg.image_size.height != bgbmp->getHeight()) { new_img = image_ptr(new CTxDIB); bgbmp->resample(bg.image_size.width, bg.image_size.height, new_img.get()); bgbmp = new_img; } cairo_surface_t* img = cairo_image_surface_create_for_data((unsigned char*) bgbmp->getBits(), CAIRO_FORMAT_ARGB32, bgbmp->getWidth(), bgbmp->getHeight(), bgbmp->getWidth() * 4); cairo_pattern_t *pattern = cairo_pattern_create_for_surface(img); cairo_matrix_t flib_m; cairo_matrix_init(&flib_m, 1, 0, 0, -1, 0, 0); cairo_matrix_translate(&flib_m, -bg.position_x, -bg.position_y); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_pattern_set_matrix (pattern, &flib_m); switch(bg.repeat) { case litehtml::background_repeat_no_repeat: draw_txdib(cr, bgbmp.get(), bg.position_x, bg.position_y, bgbmp->getWidth(), bgbmp->getHeight()); break; case litehtml::background_repeat_repeat_x: cairo_set_source(cr, pattern); cairo_rectangle(cr, bg.clip_box.left(), bg.position_y, bg.clip_box.width, bgbmp->getHeight()); cairo_fill(cr); break; case litehtml::background_repeat_repeat_y: cairo_set_source(cr, pattern); cairo_rectangle(cr, bg.position_x, bg.clip_box.top(), bgbmp->getWidth(), bg.clip_box.height); cairo_fill(cr); break; case litehtml::background_repeat_repeat: cairo_set_source(cr, pattern); cairo_rectangle(cr, bg.clip_box.left(), bg.clip_box.top(), bg.clip_box.width, bg.clip_box.height); cairo_fill(cr); break; } cairo_pattern_destroy(pattern); cairo_surface_destroy(img); } unlock_images_cache(); cairo_restore(cr); }
void HUD_Lua_Class::draw_text(FontSpecifier *font, const char *text, float x, float y, float r, float g, float b, float a, float scale) { if (!m_drawing) return; if (!text || !strlen(text)) return; apply_clip(); #ifdef HAVE_OPENGL if (m_opengl) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(x, y + (font->Height * scale), 0); glScalef(scale, scale, 1.0); glColor4f(r, g, b, a); font->OGL_Render(text); glColor4f(1, 1, 1, 1); glPopMatrix(); } else #endif if (m_surface) { SDL_Rect rect; rect.x = static_cast<Sint16>(x) + m_wr.x; rect.y = static_cast<Sint16>(y) + m_wr.y; rect.w = font->TextWidth(text); rect.h = font->LineSpacing; // FIXME: draw_text doesn't support full RGBA transfer for proper scaling, // so draw blended but unscaled text instead #if 0 if (scale < 0.99 || scale > 1.01) { SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, m_surface->format->BitsPerPixel, m_surface->format->Rmask, m_surface->format->Gmask, m_surface->format->Bmask, m_surface->format->Amask); SDL_SetAlpha(s2, SDL_SRCALPHA, 0); font->Info->draw_text(s2, text, strlen(text), 0, font->Height, SDL_MapRGBA(m_surface->format, static_cast<unsigned char>(r * 255), static_cast<unsigned char>(g * 255), static_cast<unsigned char>(b * 255), static_cast<unsigned char>(a * 255)), font->Style); SDL_Rect srcrect; srcrect.x = 0; srcrect.y = 0; srcrect.w = ceilf(rect.w * scale); srcrect.h = ceilf(rect.h * scale); SDL_Surface *s3 = rescale_surface(s2, srcrect.w, srcrect.h); SDL_FreeSurface(s2); rect.w = srcrect.w; rect.h = srcrect.h; SDL_BlitSurface(s3, &srcrect, SDL_GetVideoSurface(), &rect); SDL_FreeSurface(s3); } else #endif { SDL_BlitSurface(SDL_GetVideoSurface(), &rect, m_surface, &rect); font->Info->draw_text(m_surface, text, strlen(text), rect.x, rect.y + font->Height, SDL_MapRGBA(m_surface->format, static_cast<unsigned char>(r * 255), static_cast<unsigned char>(g * 255), static_cast<unsigned char>(b * 255), static_cast<unsigned char>(a * 255)), font->Style); SDL_BlitSurface(m_surface, &rect, SDL_GetVideoSurface(), &rect); } } }