1 #include "../Common/Common.h"
5 #include "DasherControl.h"
7 #include "../DasherCore/DasherTypes.h"
11 //#define IGNAS_NODRAW
12 //#define IGNAS_RECTANGLE_PRINT
13 #define IGNAS_DRAW_MAIN_RECTANGLES true
14 // #define IGNAS_NORECTANGLE_DRAW
15 // #define IGNAS_NOFONT_DRAW
16 //#define IGNAS_FRAME_PRINT
17 //#define IGNAS_NO_BLANK
20 #define IGNAS_STOP_VOID return;
23 #define IGNAS_STOP_VOID ;
27 #define IGNAS_STOP_BLANK return;
29 #ifndef IGNAS_NO_BLANK
30 #define IGNAS_STOP_BLANK ;
34 #ifdef IGNAS_NORECTANGLE_DRAW
35 #define IGNAS_RECTANGLE_STOP_VOID return;
37 #ifndef IGNAS_NORECTANGLE_DRAW
38 #define IGNAS_RECTANGLE_STOP_VOID ;
40 #ifdef IGNAS_NOFONT_DRAW
41 #define IGNAS_FONT_STOP_VOID return;
43 #ifndef IGNAS_NOFONT_DRAW
44 #define IGNAS_FONT_STOP_VOID ;
46 using namespace Dasher
;
48 CCanvas::CCanvas(GtkWidget
*pCanvas
, CPangoCache
*pPangoCache
)
49 : CDasherScreen(pCanvas
->allocation
.width
, pCanvas
->allocation
.height
) {
52 m_bLoadBackground
= true;
53 m_bCaptureBackground
= true;
56 #ifdef FRAMERATE_DIAGNOSTICS
66 display_fontwidth
=m_pCanvas
->allocation
.width
;
67 display_fontheight
=m_pCanvas
->allocation
.height
;
78 m_pPangoCache
= pPangoCache
;
80 m_iWidth
= m_pCanvas
->allocation
.width
;
81 m_iHeight
= m_pCanvas
->allocation
.height
;
83 display_data
= (guchar
*) g_malloc(m_pCanvas
->allocation
.width
*m_pCanvas
->allocation
.height
*display_depth
* sizeof(guchar
));
84 display_backgrounddata
= (guchar
*) g_malloc(m_pCanvas
->allocation
.width
*m_pCanvas
->allocation
.height
*display_depth
* sizeof(guchar
));
86 display_fontdata
= (guchar
*) g_malloc(display_fontwidth
*display_fontheight
*display_fontdepth
* sizeof(guchar
));
89 point_id
= (gint
*) g_malloc(m_pCanvas
->allocation
.width
* sizeof(gint
));
90 point_amount
= (gint
*) g_malloc(m_pCanvas
->allocation
.width
* sizeof(gint
));
91 point_data
= (gint
*) g_malloc(m_pCanvas
->allocation
.width
* sizeof(gint
));
94 bg
.red
=0;bg
.green
=0;bg
.blue
=0;
96 display_pixbuf
=gdk_pixbuf_new_from_data (display_data
,
100 m_pCanvas
->allocation
.width
,
101 m_pCanvas
->allocation
.height
,
102 m_pCanvas
->allocation
.width
*display_depth
,
107 display_fontcairosurface
=cairo_image_surface_create_for_data (display_fontdata
,
109 display_fontwidth
,display_fontheight
,
110 display_fontwidth
*display_fontdepth
);
111 display_fontcairo
= cairo_create(display_fontcairosurface
);
114 display_fontgdk
= gdk_pixmap_create_from_data (m_pCanvas
->window
,
115 (gchar
*)display_fontdata
,
119 &m_pCanvas
->style
->fg
[GTK_STATE_NORMAL
],
120 &m_pCanvas
->style
->bg
[GTK_STATE_NORMAL
]);
122 gdk_drawable_set_colormap(display_fontgdk
, gdk_colormap_get_system());
124 if (display_fontgdk
==NULL
)
125 printf("No PIXMAP!!!\n");
129 m_pPangoInk
= new PangoRectangle
;
130 gtk_widget_add_events(m_pCanvas
, GDK_ALL_EVENTS_MASK
);
133 CCanvas::~CCanvas() {
134 // Free the buffer pixmaps
138 cairo_destroy(display_fontcairo
);
141 g_object_unref(display_fontgdk
);
143 free(display_fontdata
);
144 free(display_backgrounddata
);
145 g_object_unref(display_pixbuf
);
151 void CCanvas::Blank() {
157 _c
.red
=(int)(cairo_colours
[0].r
*255);
158 _c
.green
=(int)(cairo_colours
[0].g
*255);
159 _c
.blue
=(int)(cairo_colours
[0].b
*255);
161 _c
.red
=colours
[0].red
;
162 _c
.green
=colours
[0].green
;
163 _c
.blue
=colours
[0].blue
;
167 for(int i
=0;i
<m_iWidth
*m_iHeight
*display_depth
;i
+=display_depth
)
169 display_data
[i
]=_c
.red
;
170 display_data
[i
+1]=_c
.green
;
171 display_data
[i
+2]=_c
.blue
;
176 void CCanvas::Display() {
180 GdkGC
*graphics_context
;
182 graphics_context
= m_pCanvas
->style
->fg_gc
[GTK_WIDGET_STATE(m_pCanvas
)];
185 gdk_pixbuf_render_to_drawable(display_pixbuf
,m_pCanvas
->window
, graphics_context
,0, 0,0,0, m_iWidth
,m_iHeight
, GDK_RGB_DITHER_NORMAL
,0,0);
188 void CCanvas::DrawRectangle(int x1
, int y1
, int x2
, int y2
, int Color
, int iOutlineColour
, Opts::ColorSchemes ColorScheme
, bool bDrawOutline
, bool bFill
, int iThickness
) {
189 bFill
&=IGNAS_DRAW_MAIN_RECTANGLES
;
190 IGNAS_RECTANGLE_STOP_VOID
193 #ifdef FRAMERATE_DIAGNOSTICS
224 iBottom
=iTop
+iHeight
;
225 if (iBottom
> m_iHeight
) iBottom
=m_iHeight
;
227 if (iRight
> m_iWidth
) iRight
=m_iWidth
;
228 if (iLeft
<0) iLeft
=0;
232 _c
.red
=(int)(cairo_colours
[Color
].r
*255);
233 _c
.green
=(int)(cairo_colours
[Color
].g
*255);
234 _c
.blue
=(int)(cairo_colours
[Color
].b
*255);
236 _c
.red
=colours
[Color
].red
;
237 _c
.green
=colours
[Color
].green
;
238 _c
.blue
=colours
[Color
].blue
;
241 for (int i
=iTop
;i
<iBottom
;i
++)
242 for(int j
=iLeft
;j
<iRight
;j
++)
244 display_data
[i
*m_iWidth
*display_depth
+j
*display_depth
]=_c
.red
;
245 display_data
[i
*m_iWidth
*display_depth
+j
*display_depth
+1]=_c
.green
;
246 display_data
[i
*m_iWidth
*display_depth
+j
*display_depth
+2]=_c
.blue
;
251 if( iOutlineColour
== -1 )
256 _c
.red
=(int)(cairo_colours
[3].r
*255);
257 _c
.green
=(int)(cairo_colours
[3].g
*255);
258 _c
.blue
=(int)(cairo_colours
[3].b
*255);
260 _c
.red
=colours
[3].red
;
261 _c
.green
=colours
[3].green
;
262 _c
.blue
=colours
[3].blue
;
271 _c
.red
=(int)(cairo_colours
[iOutlineColour
].r
*255);
272 _c
.green
=(int)(cairo_colours
[iOutlineColour
].g
*255);
273 _c
.blue
=(int)(cairo_colours
[iOutlineColour
].b
*255);
275 _c
.red
=colours
[iOutlineColour
].red
;
276 _c
.green
=colours
[iOutlineColour
].green
;
277 _c
.blue
=colours
[iOutlineColour
].blue
;
283 for(int thickness
=0;thickness
<iThickness
;thickness
++)
285 if (iLeft
+thickness
<m_iWidth
)
286 for (i
=iTop
;i
<iBottom
;i
++)
290 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+thickness
)*display_depth
]=_c
.red
;
291 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+thickness
)*display_depth
+1]=_c
.green
;
292 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+thickness
)*display_depth
+2]=_c
.blue
;
295 if ((iRight
-thickness
>=0)&&(iRight
-thickness
<m_iWidth
))
296 for (i
=iTop
;i
<iBottom
;i
++)
298 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+iWidth
-thickness
)*display_depth
]=_c
.red
;
299 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+iWidth
-thickness
)*display_depth
+1]=_c
.green
;
300 display_data
[i
*m_iWidth
*display_depth
+(iLeft
+iWidth
-thickness
)*display_depth
+2]=_c
.blue
;
303 if (iTop
+thickness
<m_iHeight
)
304 for(j
=iLeft
;j
<iRight
;j
++)
307 display_data
[(iTop
+thickness
)*m_iWidth
*display_depth
+j
*display_depth
]=_c
.red
;
308 display_data
[(iTop
+thickness
)*m_iWidth
*display_depth
+j
*display_depth
+1]=_c
.green
;
309 display_data
[(iTop
+thickness
)*m_iWidth
*display_depth
+j
*display_depth
+2]=_c
.blue
;
311 if ((iBottom
-thickness
<m_iHeight
)&&(iBottom
-thickness
>=0))
312 for(j
=iLeft
;j
<iRight
;j
++)
314 display_data
[(iTop
+iHeight
-thickness
)*m_iWidth
*display_depth
+j
*display_depth
]=_c
.red
;
315 display_data
[(iTop
+iHeight
-thickness
)*m_iWidth
*display_depth
+j
*display_depth
+1]=_c
.green
;
316 display_data
[(iTop
+iHeight
-thickness
)*m_iWidth
*display_depth
+j
*display_depth
+2]=_c
.blue
;
323 void CCanvas::CirclePoints(int cx
, int cy
, int x
, int y
, int Colour
,int iWidth
)
325 //A circle drawing algorithm taken from
326 //http://www.cs.unc.edu/~mcmillan/comp136/
330 _c
.red
=(int)(cairo_colours
[Colour
].r
*255);
331 _c
.green
=(int)(cairo_colours
[Colour
].g
*255);
332 _c
.blue
=(int)(cairo_colours
[Colour
].b
*255);
334 _c
.red
=colours
[Colour
].red
;
335 _c
.green
=colours
[Colour
].green
;
336 _c
.blue
=colours
[Colour
].blue
;
340 SetPixel(&_c
, cx
, cy
+ y
,iWidth
); //act
341 SetPixel(&_c
, cx
, cy
- y
,iWidth
);
342 SetPixel(&_c
, cx
+ y
, cy
,iWidth
);
343 SetPixel(&_c
, cx
- y
, cy
,iWidth
);
347 SetPixel(&_c
, cx
+ x
, cy
+ y
,iWidth
);//act
348 SetPixel(&_c
, cx
- x
, cy
+ y
,iWidth
);
349 SetPixel(&_c
, cx
+ x
, cy
- y
,iWidth
);
350 SetPixel(&_c
, cx
- x
, cy
- y
,iWidth
);
353 SetPixel(&_c
, cx
+ x
, cy
+ y
,iWidth
);//act
354 SetPixel(&_c
, cx
- x
, cy
+ y
,iWidth
);
355 SetPixel(&_c
, cx
+ x
, cy
- y
,iWidth
);
356 SetPixel(&_c
, cx
- x
, cy
- y
,iWidth
);
357 SetPixel(&_c
, cx
+ y
, cy
+ x
,iWidth
);
358 SetPixel(&_c
, cx
- y
, cy
+ x
,iWidth
);
359 SetPixel(&_c
, cx
+ y
, cy
- x
,iWidth
);
360 SetPixel(&_c
, cx
- y
, cy
- x
,iWidth
);
363 void CCanvas::HVThinLine(int x0
,int y0
,int x1
,int y1
,int Colour
)
367 _c
.red
=(int)(cairo_colours
[Colour
].r
*255);
368 _c
.green
=(int)(cairo_colours
[Colour
].g
*255);
369 _c
.blue
=(int)(cairo_colours
[Colour
].b
*255);
371 _c
.red
=colours
[Colour
].red
;
372 _c
.green
=colours
[Colour
].green
;
373 _c
.blue
=colours
[Colour
].blue
;
388 if (start
<0) start
=0;
389 if (start
>=m_iWidth
) start
=m_iWidth
-1;
391 if ((y0
>=0)&&(y0
<m_iHeight
))
392 for(x
=start
;x
<end
;x
++)
394 display_data
[y0
*m_iWidth
*display_depth
+x
*display_depth
]=_c
.red
;
395 display_data
[y0
*m_iWidth
*display_depth
+x
*display_depth
+1]=_c
.green
;
396 display_data
[y0
*m_iWidth
*display_depth
+x
*display_depth
+2]=_c
.blue
;
413 if (start
<0) start
=0;
414 if (start
>=m_iHeight
) start
=m_iHeight
-1;
416 if ((x0
>=0)&&(x0
<m_iWidth
))
417 for(y
=start
;y
<end
;y
++)
419 display_data
[y
*m_iWidth
*display_depth
+x0
*display_depth
]=_c
.red
;
420 display_data
[y
*m_iWidth
*display_depth
+x0
*display_depth
+1]=_c
.green
;
421 display_data
[y
*m_iWidth
*display_depth
+x0
*display_depth
+2]=_c
.blue
;
427 void CCanvas::CircleMidpoint(int xCenter
, int yCenter
, int radius
, int Colour
,int iWidth
)
432 p
= (5 - radius
*4)/4;
433 CirclePoints(xCenter
, yCenter
, x
,y
, Colour
,iWidth
);
442 CirclePoints(xCenter
, yCenter
, x
, y
, Colour
,iWidth
);
446 void CCanvas::CircleFill(int xCenter
,int yCenter
,int radius
,int Colour
)
450 _c
.red
=(int)(cairo_colours
[Colour
].r
*255);
451 _c
.green
=(int)(cairo_colours
[Colour
].g
*255);
452 _c
.blue
=(int)(cairo_colours
[Colour
].b
*255);
454 _c
.red
=colours
[Colour
].red
;
455 _c
.green
=colours
[Colour
].green
;
456 _c
.blue
=colours
[Colour
].blue
;
460 int p
= (5 - radius
*4)/4;
471 HVThinLine(xCenter
-x
,yCenter
-y
,xCenter
-x
,yCenter
+y
,Colour
);
472 HVThinLine(xCenter
+x
,yCenter
-y
,xCenter
+x
,yCenter
+y
,Colour
);
473 HVThinLine(xCenter
-y
,yCenter
-x
,xCenter
-y
,yCenter
+x
,Colour
);
474 HVThinLine(xCenter
+y
,yCenter
-x
,xCenter
+y
,yCenter
+x
,Colour
);
477 void CCanvas::DrawCircle(screenint iCX
, screenint iCY
, screenint iR
, int iColour
, int iFillColour
, int iThickness
, bool bFill
) {
481 CircleFill(iCX
,iCY
,iR
,iFillColour
);
482 CircleMidpoint(iCX
,iCY
,iR
,iColour
,iThickness
);
484 bool CCanvas::HorizontalIntersectionPoint(int h
,int a
,int b
,int x0
,int y0
,int x1
,int y1
, int *p
)
486 if (x0
==x1
) return false;
487 if (((h
>y0
)&&(h
>y1
))||((h
<y0
)&&(h
<y1
))) return false;
509 if ((x0
>=a
)&&(x0
<=b
)) *p
=x0
;
512 if (x0
<a
) *p
=a
; else *p
=b
;
518 if ((x0
>=a
)&&(x0
<=b
)) *p
=x0
;
521 if (x0
<a
) *p
=a
; else *p
=b
;
529 if ((x1
>=a
)&&(x1
<=b
)) *p
=x1
;
532 if (x1
<a
) *p
=a
; else *p
=b
;
538 l
= (double)(h2
* X
)/(double)(h1
+h2
);
540 if ((x
>=a
)&&(x
<=b
)) *p
=x
;
543 if (x
<a
) *p
=a
; else *p
=b
;
550 void CCanvas::PolygonFill(Dasher::CDasherScreen::point
*Points
, int Number
, int Colour
)
554 _c
.red
=(int)(cairo_colours
[Colour
].r
*255);
555 _c
.green
=(int)(cairo_colours
[Colour
].g
*255);
556 _c
.blue
=(int)(cairo_colours
[Colour
].b
*255);
558 _c
.red
=colours
[Colour
].red
;
559 _c
.green
=colours
[Colour
].green
;
560 _c
.blue
=colours
[Colour
].blue
;
562 if (Number
>m_iWidth
) return; //The size of point_data
563 int minx
=m_iWidth
-1,maxx
=0,miny
=m_iHeight
-1,maxy
=0;
565 for (i
=0;i
<Number
;i
++)
567 if (Points
[i
].x
<minx
) minx
= Points
[i
].x
;
568 if (Points
[i
].x
>maxx
) maxx
= Points
[i
].x
;
569 if (Points
[i
].y
<miny
) miny
= Points
[i
].y
;
570 if (Points
[i
].y
>maxy
) maxy
= Points
[i
].y
;
574 if (maxx
>=m_iWidth
) maxx
=m_iWidth
-1;
575 if (maxy
>=m_iHeight
) maxy
=m_iHeight
-1;
578 for (i
=0;i
<m_iWidth
;i
++)
580 for(int scanline
=miny
;scanline
<=maxy
;scanline
++)
583 for(i
=1;i
<Number
;i
++)
585 if (HorizontalIntersectionPoint(scanline
,0,m_iWidth
-1,Points
[i
-1].x
,Points
[i
-1].y
,Points
[i
].x
,Points
[i
].y
,&p
))
591 if (HorizontalIntersectionPoint(scanline
,0,m_iWidth
-1,Points
[Number
-1].x
,Points
[Number
-1].y
,Points
[0].x
,Points
[0].y
,&p
))
596 for (i
=0;i
<found
;i
++)
598 if (point_id
[point_data
[i
]]!=scanline
)
600 point_amount
[point_data
[i
]]=1;
601 point_id
[point_data
[i
]]=scanline
;
603 else point_amount
[point_data
[i
]]++;
606 for (i
=0;i
<m_iWidth
;i
++)
608 if (point_id
[i
]!=scanline
)
612 display_data
[scanline
*m_iWidth
*display_depth
+i
*display_depth
]=_c
.red
;
613 display_data
[scanline
*m_iWidth
*display_depth
+i
*display_depth
+1]=_c
.green
;
614 display_data
[scanline
*m_iWidth
*display_depth
+i
*display_depth
]=_c
.blue
;
619 depth
+=point_amount
[i
];
624 void CCanvas::Polygon(Dasher::CDasherScreen::point
*Points
, int Number
, int Colour
, int iWidth
) {
627 for(int i
= 1; i
< Number
; i
++)
629 Line(Points
[i
].x
,Points
[i
].y
,Points
[i
-1].x
,Points
[i
-1].y
, iWidth
,Colour
);
631 Line(Points
[Number
-1].x
,Points
[Number
-1].y
,Points
[0].x
,Points
[0].y
,iWidth
,Colour
);
633 void CCanvas::SetPixel(GdkColor
*c
,int x
,int y
,int iWidth
)
637 for (int i
=0;i
<iWidth
;i
++)
638 for (int j
=0;j
<iWidth
;j
++)
643 if (((y
>=0)&&(y
<m_iHeight
))&&((x
>=0)&&(x
<m_iWidth
)))
646 display_data
[y
*m_iWidth
*display_depth
+x
*display_depth
]=c
->red
;
647 display_data
[y
*m_iWidth
*display_depth
+x
*display_depth
+1]=c
->green
;
648 display_data
[y
*m_iWidth
*display_depth
+x
*display_depth
+2]=c
->blue
;
657 void CCanvas::Line(int x0
,int y0
,int x1
,int y1
,int iWidth
, int Colour
)
659 //A Bresenham line drawing algorithm taken from
660 //http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html
664 _c
.red
=(int)(cairo_colours
[Colour
].r
*255);
665 _c
.green
=(int)(cairo_colours
[Colour
].g
*255);
666 _c
.blue
=(int)(cairo_colours
[Colour
].b
*255);
668 _c
.red
=colours
[Colour
].red
;
669 _c
.green
=colours
[Colour
].green
;
670 _c
.blue
=colours
[Colour
].blue
;
676 if (dy
< 0) { dy
= -dy
; stepy
= -1; } else { stepy
= 1; }
677 if (dx
< 0) { dx
= -dx
; stepx
= -1; } else { stepx
= 1; }
678 dy
<<= 1; // dy is now 2*dy
679 dx
<<= 1; // dx is now 2*dx
681 SetPixel(&_c
, x0
, y0
,iWidth
);
683 int fraction
= dy
- (dx
>> 1); // same as 2*dy - dx
687 fraction
-= dx
; // same as fraction -= 2*dx
690 fraction
+= dy
; // same as fraction -= 2*dy
691 SetPixel(&_c
, x0
, y0
,iWidth
);
694 int fraction
= dx
- (dy
>> 1);
702 SetPixel(&_c
, x0
, y0
,iWidth
);
708 void CCanvas::Polyline(Dasher::CDasherScreen::point
*Points
, int Number
, int iWidth
, int Colour
) {
714 for(int i
= 1; i
< Number
; i
++)
716 Line(Points
[i
].x
,Points
[i
].y
,Points
[i
-1].x
,Points
[i
-1].y
, iWidth
,Colour
);
720 void CCanvas::DrawString(const std::string
&String
, int x1
, int y1
, int size
) {
725 #if WITH_CAIRO //set color black
726 my_cairo_colour_t _c
= cairo_colours
[4];
727 cairo_set_source_rgb(display_fontcairo
, _c
.r
, _c
.g
, _c
.b
);
730 GdkGC
*graphics_context
;
731 graphics_context
= m_pCanvas
->style
->fg_gc
[GTK_WIDGET_STATE(m_pCanvas
)];
735 PangoLayout
*pLayout(m_pPangoCache
->GetLayout(display_fontcairo
, String
, size
));
738 PangoLayout
*pLayout(m_pPangoCache
->GetLayout(GTK_WIDGET(m_pCanvas
), String
, size
));
744 pango_layout_get_pixel_extents(pLayout
, m_pPangoInk
, NULL
);
746 int height
=m_pPangoInk
->height
/2;
750 for (int i
=m_pPangoInk
->y
;i
<m_pPangoInk
->y
+m_pPangoInk
->height
;i
++)
751 if ((i
+y1
-height
<m_iHeight
) &&(i
+y1
-height
>=0))
752 for(int j
=m_pPangoInk
->x
;j
<+m_pPangoInk
->x
+m_pPangoInk
->width
;j
++)
753 if ((j
+x1
>=0)&&(j
+x1
<m_iWidth
))
755 display_fontdata
[i
*display_fontwidth
*display_fontdepth
+j
*display_fontdepth
]=back
;
756 display_fontdata
[i
*display_fontwidth
*display_fontdepth
+j
*display_fontdepth
+1]=back
;
757 display_fontdata
[i
*display_fontwidth
*display_fontdepth
+j
*display_fontdepth
+2]=back
;
761 pango_cairo_show_layout(display_fontcairo
, pLayout
);
764 GdkColormap
* colormap
=gdk_colormap_get_system();
765 GdkColor _c
= colours
[4];
766 gdk_colormap_alloc_color(colormap
, &_c
, FALSE
, TRUE
);
767 gdk_gc_set_foreground (graphics_context
, &_c
);
768 gdk_draw_layout(display_fontgdk
, graphics_context
, 0,0, pLayout
);
773 for (int i
=m_pPangoInk
->y
;i
<m_pPangoInk
->y
+m_pPangoInk
->height
;i
++)
774 if ((i
+y1
-height
<m_iHeight
) &&(i
+y1
-height
>=0))
776 for(int j
=m_pPangoInk
->x
;j
<+m_pPangoInk
->x
+m_pPangoInk
->width
;j
++)
777 if ((j
+x1
>=0)&&(j
+x1
<m_iWidth
))
779 if (display_fontdata
[i
*display_fontwidth
*display_fontdepth
+j
*display_fontdepth
+0]!=back
)
781 value
= display_fontdata
[i
*display_fontwidth
*display_fontdepth
+j
*display_fontdepth
+0];
782 alpha
=(double)value
/256.0;
783 black
= (int )(value
* (1-alpha
));
785 display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
]=int (display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
]*alpha
)+black
;
787 display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
+1]=int (display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
+1]*alpha
)+black
;
789 display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
+2]=int (display_data
[(i
+y1
-height
)*m_iWidth
*display_depth
+(j
+x1
)*display_depth
+2]*alpha
)+black
;
797 void CCanvas::TextSize(const std::string
&String
, int *Width
, int *Height
, int size
) {
800 PangoLayout
*pLayout(m_pPangoCache
->GetLayout(display_fontcairo
, String
, size
));
802 PangoLayout
*pLayout(m_pPangoCache
->GetLayout(GTK_WIDGET(m_pCanvas
), String
, size
));
804 pango_layout_get_pixel_extents(pLayout
, m_pPangoInk
, NULL
);
806 *Width
= m_pPangoInk
->width
;
807 *Height
= m_pPangoInk
->height
;
811 void CCanvas::SendMarker(int iMarker
) {
814 case 0: // Switch to display buffer
818 case 1: // Switch to decorations buffer
821 #ifdef FRAMERATE_DIAGNOSTICS
828 void CCanvas::SetColourScheme(const CColourIO::ColourInfo
*pColourScheme
) {
829 int iNumColours(pColourScheme
->Reds
.size());
833 delete[] cairo_colours
;
834 cairo_colours
= new my_cairo_colour_t
[iNumColours
];
838 colours
= new GdkColor
[iNumColours
];
841 for(int i
= 0; i
< iNumColours
; i
++) {
843 cairo_colours
[i
].r
= pColourScheme
->Reds
[i
] / 255.0;
844 cairo_colours
[i
].g
= pColourScheme
->Greens
[i
] / 255.0;
845 cairo_colours
[i
].b
= pColourScheme
->Blues
[i
] / 255.0;
848 colours
[i
].red
=pColourScheme
->Reds
[i
]*257;
849 colours
[i
].green
=pColourScheme
->Greens
[i
]*257;
850 colours
[i
].blue
=pColourScheme
->Blues
[i
]*257;
854 void CCanvas::SetLoadBackground(bool value
)
857 m_bLoadBackground
=value
;
859 void CCanvas::SetCaptureBackground(bool value
)
861 m_bCaptureBackground
=value
;
863 void CCanvas::StoreBackground()
865 if (m_bCaptureBackground
)
867 for (int i
=0;i
<m_iWidth
*m_iHeight
*display_depth
;i
++)
868 display_backgrounddata
[i
]=display_data
[i
];
869 m_bCaptureBackground
=false;
874 void CCanvas::LoadBackground()
876 if (m_bLoadBackground
)
878 for (int i
=0;i
<m_iWidth
*m_iHeight
*display_depth
;i
++)
879 display_data
[i
]=display_backgrounddata
[i
];
884 bool CCanvas::GetCanvasSize(GdkRectangle
*pRectangle
)
886 if ((pRectangle
== NULL
) || (m_pCanvas
== NULL
))
889 // Using gtk_window_get_frame_extents() only seems to return the position
890 // and size of the parent Dasher window. So we'll get the widgets position
891 // and use its size to determine the bounding rectangle.
895 gdk_window_get_position(m_pCanvas
->window
, &iX
, &iY
);
899 pRectangle
->width
= m_iWidth
;
900 pRectangle
->height
= m_iHeight
;
904 void CCanvas::ChangeState(int value
)
909 #ifdef FRAMERATE_DIAGNOSTICS
910 void CCanvas::NewFrame()
913 time_t seconds
=time(NULL
);
915 if (lasttime
==-1) lasttime
=seconds
;
916 time_t temp
=seconds
-lasttime
;
923 total_frames
+=count_frames
;
924 average
=(float)total_frames
/(float)(count_time
-1);
926 printf("New second %ld had %d frames, the averages is %f, total frames=%ld\n ",count_time
,count_frames
,average
,total_frames
);
929 #ifdef IGNAS_FRAME_PRINT
930 printf("OLD FRAME%d\n",count_rectangles
);