Mercurial > hg > aimc
diff trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc @ 398:3ee03a6b95a0
- All \t to two spaces (style guide compliance)
author | tomwalters |
---|---|
date | Fri, 15 Oct 2010 05:46:53 +0000 |
parents | 7a573750b186 |
children | 7bfed53caacf |
line wrap: on
line diff
--- a/trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc Fri Oct 15 05:40:53 2010 +0000 +++ b/trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc Fri Oct 15 05:46:53 2010 +0000 @@ -36,31 +36,31 @@ #include "Output/GraphicsOutputDeviceCairo.h" GraphicsOutputDeviceCairo::GraphicsOutputDeviceCairo(Parameters *pParam) - : GraphicsOutputDevice(pParam) { - m_bOutputFile = false; - m_iFileNumber = 0; - m_iVertexType = VertexTypeNone; - m_bUseMemoryBuffer=false; + : GraphicsOutputDevice(pParam) { + m_bOutputFile = false; + m_iFileNumber = 0; + m_iVertexType = VertexTypeNone; + m_bUseMemoryBuffer=false; } bool GraphicsOutputDeviceCairo::Initialize(const char *sDir) { Init(); - //! \todo Output to file if sDir is a file, to directory with + //! \todo Output to file if sDir is a file, to directory with //! multiple images if it's a directory. - strncpy(m_sDir, sDir, sizeof(m_sDir)/sizeof(m_sDir[0])); + strncpy(m_sDir, sDir, sizeof(m_sDir)/sizeof(m_sDir[0])); - /* Try to open an image to see if everything is allright. We want to avoid - * errors in the main Process()ing loop. */ - if ( !OpenFile(0) ) { - //! \todo Better error message that is more specific about the cause. - AIM_ERROR(_T("Could not open output directory '%s' using graphics format '%s'."), - m_sDir, m_pParam->GetString("output.img.format") ); - return false; - } - CloseFile(); + /* Try to open an image to see if everything is allright. We want to avoid + * errors in the main Process()ing loop. */ + if ( !OpenFile(0) ) { + //! \todo Better error message that is more specific about the cause. + AIM_ERROR(_T("Could not open output directory '%s' using graphics format '%s'."), + m_sDir, m_pParam->GetString("output.img.format") ); + return false; + } + CloseFile(); - return true; + return true; } bool GraphicsOutputDeviceCairo::Initialize() { @@ -70,17 +70,17 @@ } void GraphicsOutputDeviceCairo::Init() { - AIM_ASSERT(m_pParam); - /* - * Set parameters - */ - m_pParam->GetString("output.img.color.background"); + AIM_ASSERT(m_pParam); + /* + * Set parameters + */ + m_pParam->GetString("output.img.color.background"); - m_bInvertColors = m_pParam->GetBool("output.img.color.invert"); + m_bInvertColors = m_pParam->GetBool("output.img.color.invert"); - // Output size! - m_iWidth = m_pParam->GetUInt("output.img.width"); - m_iHeight = m_pParam->GetUInt("output.img.height"); + // Output size! + m_iWidth = m_pParam->GetUInt("output.img.width"); + m_iHeight = m_pParam->GetUInt("output.img.height"); } unsigned char* GraphicsOutputDeviceCairo::GetBuffer() { @@ -136,42 +136,42 @@ m_iHeight); m_cCr = cairo_create (m_cSurface); cairo_scale(m_cCr, (float)m_iWidth, (float)m_iHeight); - // Now setup things for this plotter. - cairo_select_font_face(m_cCr, + // Now setup things for this plotter. + cairo_select_font_face(m_cCr, m_pParam->GetString("output.img.fontname"), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (m_cCr, 0.015); - return true; + return true; } void GraphicsOutputDeviceCairo::CloseFile() { - // Plotting library - if (m_iPlotHandle>0) { - cairo_destroy(m_cCr); - m_iPlotHandle = 0; - } - // And the output file - if (m_bOutputFile) { - cairo_surface_write_to_png(m_cSurface, m_sFilename); - m_bOutputFile = false; - } - cairo_surface_destroy(m_cSurface); + // Plotting library + if (m_iPlotHandle>0) { + cairo_destroy(m_cCr); + m_iPlotHandle = 0; + } + // And the output file + if (m_bOutputFile) { + cairo_surface_write_to_png(m_cSurface, m_sFilename); + m_bOutputFile = false; + } + cairo_surface_destroy(m_cSurface); } GraphicsOutputDeviceCairo::~GraphicsOutputDeviceCairo() { - AIM_ASSERT(!m_iPlotHandle); - CloseFile(); + AIM_ASSERT(!m_iPlotHandle); + CloseFile(); } void GraphicsOutputDeviceCairo::gGrab() { // Open file. - if (!OpenFile(m_iFileNumber)) { - return; + if (!OpenFile(m_iFileNumber)) { + return; } - // Setup plotting area. - cairo_set_line_width (m_cCr, 0.001f); - gColor3f (0.0f, 0.0f, 0.0f); + // Setup plotting area. + cairo_set_line_width (m_cCr, 0.001f); + gColor3f (0.0f, 0.0f, 0.0f); cairo_paint (m_cCr); gColor3f(1.0f, 1.0f, 0.0f); } @@ -181,80 +181,80 @@ } void GraphicsOutputDeviceCairo::gBeginLineStrip() { - m_bIsFirstVertex = true; - m_iVertexType = VertexTypeLine; - //! \todo Make line width user-settable - cairo_set_line_width (m_cCr, 0.001f); + m_bIsFirstVertex = true; + m_iVertexType = VertexTypeLine; + //! \todo Make line width user-settable + cairo_set_line_width (m_cCr, 0.001f); } void GraphicsOutputDeviceCairo::gBeginQuadStrip() { - m_bIsFirstVertex = true; - m_iVertexType = VertexTypeQuad; - m_iPrevVertexCount = 0; + m_bIsFirstVertex = true; + m_iVertexType = VertexTypeQuad; + m_iPrevVertexCount = 0; cairo_set_line_width (m_cCr, 0.001f); } void GraphicsOutputDeviceCairo::gColor3f(float r, float g, float b) { if (m_bInvertColors) { - r = 1-r; - g = 1-g; - b = 1-b; - } + r = 1-r; + g = 1-g; + b = 1-b; + } cairo_set_source_rgb (m_cCr, r, g, b); } void GraphicsOutputDeviceCairo::gVertex3f(float x, float y, float z) { - switch(m_iVertexType) { - case VertexTypeLine: - if (m_bIsFirstVertex) { - m_bIsFirstVertex = false; - //pl_fmove(x, y); - cairo_move_to(m_cCr, x, 1-y); - } else { - //pl_fcont(x, y); - cairo_line_to(m_cCr, x, 1-y); - } - break; - case VertexTypeQuad: - /* Store vertices until we got four in a row. - * The order of vertices when processing quads is: - * 1-----3-----5 - * | | | - * 0-----2-----4 - */ - if (m_iPrevVertexCount >= 3) { - // Plot this quad - cairo_move_to(m_cCr, m_aPrevX[0], 1-m_aPrevY[0]); - cairo_line_to(m_cCr, m_aPrevX[1], 1-m_aPrevY[1]); - cairo_line_to(m_cCr, x, y); - cairo_line_to(m_cCr, m_aPrevX[2], 1-m_aPrevY[2]); - cairo_close_path (m_cCr); + switch(m_iVertexType) { + case VertexTypeLine: + if (m_bIsFirstVertex) { + m_bIsFirstVertex = false; + //pl_fmove(x, y); + cairo_move_to(m_cCr, x, 1-y); + } else { + //pl_fcont(x, y); + cairo_line_to(m_cCr, x, 1-y); + } + break; + case VertexTypeQuad: + /* Store vertices until we got four in a row. + * The order of vertices when processing quads is: + * 1-----3-----5 + * | | | + * 0-----2-----4 + */ + if (m_iPrevVertexCount >= 3) { + // Plot this quad + cairo_move_to(m_cCr, m_aPrevX[0], 1-m_aPrevY[0]); + cairo_line_to(m_cCr, m_aPrevX[1], 1-m_aPrevY[1]); + cairo_line_to(m_cCr, x, y); + cairo_line_to(m_cCr, m_aPrevX[2], 1-m_aPrevY[2]); + cairo_close_path (m_cCr); - // Last vertices of this quad are the first of the next - m_aPrevX[0] = m_aPrevX[2]; - m_aPrevY[0] = m_aPrevY[2]; - m_aPrevX[1] = x; - m_aPrevY[1] = y; - m_iPrevVertexCount = 2; - } else { - // Not at the fourth, keep storing - m_aPrevX[m_iPrevVertexCount] = x; - m_aPrevY[m_iPrevVertexCount] = y; - m_iPrevVertexCount++; - } - break; - default: - // Should not happen - AIM_ASSERT(0); - } + // Last vertices of this quad are the first of the next + m_aPrevX[0] = m_aPrevX[2]; + m_aPrevY[0] = m_aPrevY[2]; + m_aPrevX[1] = x; + m_aPrevY[1] = y; + m_iPrevVertexCount = 2; + } else { + // Not at the fourth, keep storing + m_aPrevX[m_iPrevVertexCount] = x; + m_aPrevY[m_iPrevVertexCount] = y; + m_iPrevVertexCount++; + } + break; + default: + // Should not happen + AIM_ASSERT(0); + } } void GraphicsOutputDeviceCairo::gEnd() { - if(m_iVertexType==VertexTypeLine) + if(m_iVertexType==VertexTypeLine) cairo_stroke (m_cCr); else cairo_fill (m_cCr); - m_iVertexType = VertexTypeNone; + m_iVertexType = VertexTypeNone; } void GraphicsOutputDeviceCairo::gText3f(float x, @@ -263,21 +263,21 @@ const char *sStr, bool bRotated) { cairo_text_extents_t te; - if (bRotated) { - cairo_rotate(m_cCr, M_PI/2); - cairo_move_to(m_cCr, x ,1-y); - cairo_show_text(m_cCr, sStr); - //cairo_identity_matrix(m_cCr); - cairo_rotate(m_cCr, -M_PI/2); - } else { - cairo_move_to(m_cCr, x ,1-y); - cairo_show_text(m_cCr, sStr); - } + if (bRotated) { + cairo_rotate(m_cCr, M_PI/2); + cairo_move_to(m_cCr, x ,1-y); + cairo_show_text(m_cCr, sStr); + //cairo_identity_matrix(m_cCr); + cairo_rotate(m_cCr, -M_PI/2); + } else { + cairo_move_to(m_cCr, x ,1-y); + cairo_show_text(m_cCr, sStr); + } } void GraphicsOutputDeviceCairo::gRelease() { - AIM_ASSERT(m_iPlotHandle>0); - CloseFile(); - // Finished this one, up to the next! - m_iFileNumber++; + AIM_ASSERT(m_iPlotHandle>0); + CloseFile(); + // Finished this one, up to the next! + m_iFileNumber++; }