📄 mgpainter.cpp
字号:
#include <stdio.h>#include <string.h>#include <kdebug.h>#include <assert.h>#include "render_interface.h"#include "mgcolor.h"#include "mgpen.h"#include "mgbrush.h"#include "mgrect.h"#include "mgfontmetrics.h"#include "mgpoint.h"#include "mgpixmap.h"#include "mgbitmap.h"#include "mgpainter.h"#include "mghtml_part.h"#define USE_CLIP 0MGPainter::MGPainter(){ hdc = 0; cpart = NULL;}MGPainter::~MGPainter(){}void MGPainter::setBrush( int brush_style ){ cbrush.style = brush_style; SetBrushColor (hdc, MGColor::Rgb2Pixel (hdc, cbrush.cl)); }void MGPainter::setBrush (const MGBrush& br ){ cbrush = br;#ifdef PAINTER_DEBUG printf ("setBrush with brush: (%d, %d, %d)\n", br.cl.red(), br.cl.green(), br.cl.blue());#endif SetBrushColor( hdc, MGColor::Rgb2Pixel (hdc, br.cl));}void MGPainter::setBrush( const MGColor& color ){ cbrush.cl = color;#ifdef PAINTER_DEBUG printf ("setBrush with color: (%d, %d, %d)\n", color.red(), color.green(), color.blue());#endif SetBrushColor( hdc, MGColor::Rgb2Pixel (hdc, color));}void MGPainter::setFont( const MGFont& f ){ cfont = f; PLOGFONT font = cpart->getFont (f); SelectFont (hdc, font);} void MGPainter::setPen( const MGPen& pen ){ cpen = pen; gal_pixel pixel = MGColor::Rgb2Pixel (hdc, pen.cl);#ifdef PAINTER_DEBUG printf ("setPen with pen: (%d, %d, %d)\n", pen.cl.red(), pen.cl.green(), pen.cl.blue());#endif SetPenColor( hdc, pixel); SetTextColor( hdc, pixel);}void MGPainter::setPen( const MGColor& color ){ cpen.cl = color; gal_pixel pixel = MGColor::Rgb2Pixel (hdc, color);#ifdef PAINTER_DEBUG printf ("setPen with color: (%d, %d, %d)\n", color.red(), color.green(), color.blue());#endif SetPenColor (hdc, pixel); SetTextColor (hdc, pixel);}void MGPainter::setPen( int style ){ cpen.style = style; gal_pixel pixel = MGColor::Rgb2Pixel (hdc, cpen.cl); SetPenColor (hdc, pixel); SetTextColor (hdc, pixel);}const MGPen& MGPainter::pen() const{ return cpen;}MGFontMetrics MGPainter::fontMetrics() const{ return MGFontMetrics( this );}void MGPainter::drawRect( int x, int y, int w, int h ){#if USE_CLIP RECT rc; rc.left = x; rc.top = y; rc.right = x + w; rc.bottom = y + h; if (!RectVisible (hdc, &rc)) return;#endif Rectangle( hdc, x, y, x+w, y+h ); }void MGPainter::drawText( int x, int y, const MGString& str, int len ){ const char* s = str.ascii(); gal_pixel pixel = MGColor::Rgb2Pixel (hdc, cpen.cl); SetTextColor (hdc, pixel); int old = SetBkMode (hdc, BM_TRANSPARENT); TextOutLen (hdc, x, y, s, -1); SetBkMode (hdc, old);}void MGPainter::drawText( int x, int y, int w, int h, int flags, const MGString& str, int len, MGRect *br, char **internal ){ int format = 0; if( flags & MG::AlignLeft ) format |= DT_LEFT; if( flags & MG::AlignRight ) format |= DT_RIGHT; if( flags & MG::AlignHCenter ) format |= DT_CENTER; if( flags & MG::AlignTop ) format |= DT_TOP; if( flags & MG::AlignBottom ) format |= DT_BOTTOM; if( flags & MG::AlignVCenter ) format |= DT_VCENTER; if( flags & MG::SingleLine ) format |= DT_SINGLELINE; if( flags & MG::DontClip ) format |= DT_NOCLIP; if( flags & MG::ExpandTabs ) format |= DT_EXPANDTABS; if( flags & MG::WordBreak ) format |= DT_WORDBREAK; RECT rect; if( br ) { rect.left = br->left(); rect.top = br->top();; rect.right = br->right(); rect.bottom = br->bottom(); } else { rect.left = x; rect.top = y-h; rect.right = w; rect.bottom = y; } const char* s = str.ascii(); gal_pixel pixel = MGColor::Rgb2Pixel (hdc, cpen.cl); SetTextColor (hdc, pixel); int old = SetBkMode (hdc, BM_TRANSPARENT); DrawText( hdc, s, -1, &rect, format ); SetBkMode (hdc, old);} void MGPainter::drawLine( int x1, int y1, int x2, int y2 ){#if USE_CLIP RECT rc; rc.left = x1, rc.top = y1; rc.right = x2; rc.bottom = y2; NormalizeRect (&rc); if (!RectVisible (hdc, &rc)) return;#endif MoveTo( hdc, x1, y1 ); LineTo( hdc, x2, y2 );} void MGPainter::drawTiledPixmap( int x, int y, int w, int h, const MGPixmap& map, int sx, int sy ){#if USE_CLIP RECT rc; rc.left = x, rc.top = y; rc.right = x + w; rc.bottom = y + h; if (!RectVisible (hdc, &rc)) return;#endif if (!map.isNull()) FillBoxWithBitmap( hdc, x, y, w, h, (BITMAP*) &map.bmp );}void MGPainter::drawPixmap( const MGPoint& pt, const MGPixmap& pix ){ MGRect sr (0, 0, -1, -1); drawPixmap (pt, pix, sr); }void MGPainter::drawPixmap( const MGPoint& pt, const MGPixmap& pix, const MGRect& sr ){ drawPixmap (pt.x(), pt.y(), pix, sr.left(), sr.top(), sr.width(), sr.height()); }void MGPainter::drawPixmap( int x, int y, const MGPixmap& pix, int sx, int sy, int sw, int sh ) {#if USE_CLIP RECT rc; if (sw <= 0) sw = ((BITMAP*) &pix.bmp)->bmWidth; if (sh <= 0) sh = ((BITMAP*) &pix.bmp)->bmHeight; rc.left = x, rc.right = y; rc.right = x + sw; rc.bottom = y + sh; if (!RectVisible (hdc, &rc)) return;#endif if (!pix.isNull()) FillBoxWithBitmap (hdc, x, y, (sw>0)?sw:0, (sh>0)?sh:0, (BITMAP*) &pix.bmp);}void MGPainter::drawEllipse( int x, int y, int w, int h ){#if USE_CLIP RECT rc; rc.left = x, rc.top= y; rc.right = x + w; rc.bottom = y + h; if (!RectVisible (hdc, &rc)) return;#endif int cx = x + (w >> 1); int cy = y + (h >> 1); int r = MIN (w >> 1, h >> 1); Circle (hdc, cx, cy, r);}void MGPainter::drawArc( int x, int y, int w, int h, int a, int alen ){ // dont support fprintf (stderr, "drawArc: not supported.\n");}void MGPainter::drawPolyline( const MGPointArray&, int index, int npoints ){ // dont support fprintf (stderr, "drawPolyline: not supported.\n");}void MGPainter::fillRect( int x, int y, int w, int h, const MGColor& c ) {#if USE_CLIP RECT rc; rc.left = x, rc.top= y; rc.right = x + w; rc.bottom = y + h; if (!RectVisible (hdc, &rc)) { return; }#endif#ifdef PAINTER_DEBUG printf ("fillRect with color: (%d, %d, %d)\n", c.red(), c.green(), c.blue());#endif SetBrushColor (hdc, MGColor::Rgb2Pixel (hdc, c)); FillBox (hdc, x, y, w, h);}void MGPainter::fillRect( int x, int y, int w, int h, const MGBrush& brush){#if USE_CLIP RECT rc; rc.left = x, rc.top= y; rc.right = x + w; rc.bottom = y + h; if (!RectVisible (hdc, &rc)) { return; }#endif#ifdef PAINTER_DEBUG printf ("fillRect with brush: (%d, %d, %d)\n", brush.cl.red(), brush.cl.green(), brush.cl.blue());#endif SetBrushColor (hdc, MGColor::Rgb2Pixel (hdc, brush.cl)); FillBox (hdc, x, y, w, h);}void MGPainter::fillRect( const MGRect& crc, const MGBrush& brush){#if USE_CLIP RECT rc; rc.left = crc.left(); rc.right = crc.right(); rc.top = crc.top (); rc.bottom = crc.bottom(); if (!RectVisible (hdc, &rc)) { return; }#endif#ifdef PAINTER_DEBUG printf ("fillRect with brush: (%d, %d, %d)\n", brush.cl.red(), brush.cl.green(), brush.cl.blue());#endif SetBrushColor (hdc, MGColor::Rgb2Pixel (hdc, brush.cl)); FillBox (hdc, crc.left(), crc.top(), crc.width(), crc.height());}bool MGPainter::hasClipping() const{ // dont used return false;}void MGPainter::setClipping( bool ){}void MGPainter::setRasterOp( int ){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -