44cfc7cb65
linecap: Reintegrating finished LineCap feature Patch contributed by Regina Henschel http://svn.apache.org/viewvc?view=revision&revision=1232507 Patches contributed by Sven Jacobi impress212: #i81610# fixed animation export http://svn.apache.org/viewvc?view=revision&revision=1167620 impress212: drawinglayer gbuild environment changes http://svn.apache.org/viewvc?view=revision&revision=1167627 http://svn.apache.org/viewvc?view=revision&revision=1167628 impress212: DffPropSet -> minor code improvements, removing table http://svn.apache.org/viewvc?view=revision&revision=1167634 impress212: #158494# fixed excel import (text rotation) http://svn.apache.org/viewvc?view=revision&revision=1167638 Patches contributed by Armin Le Grand Svg: Reintegrated Svg replacement from /branches/alg/svgreplavement http://svn.apache.org/viewvc?view=revision&revision=1220836 #118728# changed indentifying definitions for Svg file detection http://svn.apache.org/viewvc?view=revision&revision=1229961 #118838# LineGeometry creation for complicated cases optimized to create single Polygons http://svn.apache.org/viewvc?view=revision&revision=1236232 #119176# corrected file type detection for SVG for svg files without xml header http://svn.apache.org/viewvc?view=revision&revision=1309445 #118728# Extended Svg file detection http://svn.apache.org/viewvc?view=revision&revision=1230531 #118529# solve break converters and convert commands for OLEs and images http://svn.apache.org/viewvc?view=revision&revision=1186168 svg: added WaE changes from branch svgreplacement to trunc http://svn.apache.org/viewvc?view=revision&revision=1222974 svg: corrected missing member initialization http://svn.apache.org/viewvc?view=revision&revision=1226134 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles to bitmapEx ... http://svn.apache.org/viewvc?view=revision&revision=1293316 fix for #118525#: removed no longer used variable maOriginalMapMode, one more exception eliminated http://svn.apache.org/viewvc?view=revision&revision=1227097 #16758# Added buffering to the VDev usages of the VclProcessor2D derivates... http://svn.apache.org/viewvc?view=revision&revision=1229521 #116758# Secured VDev buffer device to Vcl deinit http://svn.apache.org/viewvc?view=revision&revision=1230574 #116758# added remembering allocated VDevs for VDevBuffer to be able to also delete these when vcl goes down; it should never happen, but You never know http://svn.apache.org/viewvc?view=revision&revision=1230927 #118730# Changed SvgClipPathNode to use MaskPrimitive2D for primitive representation instead of TransparencePrimitive2D http://svn.apache.org/viewvc?view=revision&revision=1231198 #118822# secured 3D geometry creation (slices) by subdividing the 2D source polyPolygon early http://svn.apache.org/viewvc?view=revision&revision=1234749 #118829# enhanced Svg gradient quality, obstacles avoided http://svn.apache.org/viewvc?view=revision&revision=1235361 #118834# Unified usage of TextBreakupHelper as single tooling class for i18n text primitive breakup http://svn.apache.org/viewvc?view=revision&revision=1236110 #118853# added square pixel size limit to conversion of TransparencePrimitive2D to Metafile action http://svn.apache.org/viewvc?view=revision&revision=1237656 #118824# coreccted mirroring and boundrect when the graphicmanager is used for bitmap output http://svn.apache.org/viewvc?view=revision&revision=1240097 #115092# Corrected VclProcessor2D::RenderPolygonStrokePrimitive2D for various optimization scenarios http://svn.apache.org/viewvc?view=revision&revision=1241434 #118783# Corrected errors in ID strings, corrected Svg line/fill export, corrected polygon close state http://svn.apache.org/viewvc?view=revision&revision=1232006 #118796# corrected null-pointer usage in SVG text exporter http://svn.apache.org/viewvc?view=revision&revision=1240262 #118729# Use GraphicStreamUrl and GraphicUrl to allow multi image import with linked graphics, too http://svn.apache.org/viewvc?view=revision&revision=1229962 #118898# corrected error in GDIMetaFile::GetBoundRect in handling MetaFloatTransparentAction http://svn.apache.org/viewvc?view=revision&revision=1293349 #118855# Corrected handling of possibly created empty clipRegions after PolyPolygon clipping http://svn.apache.org/viewvc?view=revision&revision=1237725 #115962# Better (but not yet optimal, see comments in task) handling of MetaFloatTransparentAction in PDF export http://svn.apache.org/viewvc?view=revision&revision=1241078 IP clearance: #118466# This patch removes librsvg, libcroco, libgsf, ... http://svn.apache.org/viewvc?view=revision&revision=1200879 118779# Added svg content streaming in/out to ImpGraphic stream operators http://svn.apache.org/viewvc?view=revision&revision=1231908 linecap: correctons for WaE and mac drawing http://svn.apache.org/viewvc?view=revision&revision=1232793 svg: uses current system Dpi for Svg replacement image creation http://svn.apache.org/viewvc?view=revision&revision=1233948 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 http://svn.apache.org/viewvc?view=revision&revision=1394326 Remove duplicate header includes. cws mba34issues01: #i117720#: convert assertion into warning http://svn.apache.org/viewvc?view=revision&revision=1172352 118485 - Styles for OLEs are not saved. Submitted by Armin Le Grand. http://svn.apache.org/viewvc?view=revision&revision=1182166 cws mba34issues01: #i117714#: remove assertion http://svn.apache.org/viewvc?view=revision&revision=1172357 Patch contributed by Jurgen Schmidt add some additional checks to ensure proper reading operations http://svn.apache.org/viewvc?view=revision&revision=1209022 mostly prefer our stream / bounds checking work. Patches contributed by Herbert Duerr #i118816# add clarifying comment regarding Font::*Color*() methods http://svn.apache.org/viewvc?view=revision&revision=1233833 extend macro->string handling for empty strings http://svn.apache.org/viewvc?view=revision&revision=1175801 avoid magic constants for SALCOLOR_NONE http://svn.apache.org/viewvc?view=revision&revision=1177543 initialize slant properly in ImplFontMetricData constructor (author=iorsh) http://svn.apache.org/viewvc?view=revision&revision=1177551 #i118675# make check for extension updates more stable http://svn.apache.org/viewvc?view=revision&revision=1214797 #a118617# remove VBasicEventListener.dll binary There are no known users depending on its CLSID http://svn.apache.org/viewvc?view=revision&revision=1203697 Patches contributed by Ariel Constenla-Haile Fix build breaker on Linux/gcc http://svn.apache.org/viewvc?view=revision&revision=1221104 Fix crash when trying to instantiate css.graphic.GraphicRasterizer_RSVG http://svn.apache.org/viewvc?view=revision&revision=1215559 Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117962# - method <SwFlyFrm::IsPaint(..)> - consider instances of <SwFlyDrawObj> http://svn.apache.org/viewvc?view=revision&revision=1172120 sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 gnumake4 work variously from Hans-Joachim Lankenau http://svn.apache.org/viewvc?view=revision&revision=1397315 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1396782 http://svn.apache.org/viewvc?view=revision&revision=1394707 plus some amount of re-splitting of legacy headers. Patch contributed by Pavel Janik WaE: Remove unused variables. http://svn.apache.org/viewvc?view=revision&revision=1230697 Patches contributed by Takashi Ono mingwport35: i#117795: MinGW port fix for vcl2gnumake http://svn.apache.org/viewvc?view=revision&revision=1172091 mingwport35: i#117795: MinGW port fix for vcl2gnumake http://svn.apache.org/viewvc?view=revision&revision=1172091 Patch contributed by Christian Lippka impress212: #i98044# re enable Text menu for outline and title shapes http://svn.apache.org/viewvc?view=revision&revision=1167639 Patch contributed by Andre Fischer 118674: Made category B code optional and disabled by default. http://svn.apache.org/viewvc?view=revision&revision=1215131 118881: Ignore empty paragraphs after bullets. http://svn.apache.org/viewvc?view=revision&revision=1296205 Patches contributed by Philipp Lohmann ooo340fixes: #i117780# use rtl allocator http://svn.apache.org/viewvc?view=revision&revision=1172087 ooo34gsl02: #i117807# fix an off by one error (index actually inside the pfb section header) http://svn.apache.org/viewvc?view=revision&revision=1167576 various cleanups, related compilation fixes, warning cleanups, re-working of obsolete stl template pieces to use boost instead, changed string classes, re-adapt KDE about data, about dialog, fixing warnings, and other fixes & improvements. Disable svg import / render for about/ branding code-paths for now. Restore full icon theme set. Remove OS/2 conditionals and sources. Remove conflicting gtk/full-screen monitors support. Retain existing svg rasterizer files - temporarily disabled. Standardize stringificaiton and fixup dllpostfix issues. Rename SvgGradientHelper::== to equalTo to avoid overloading issues. Use the flat GdiPlus API for LineCaps calls.
600 lines
18 KiB
C++
600 lines
18 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
#include <grid.hrc>
|
|
#include <cstdio>
|
|
#include <math.h> // for M_LN10 and M_E
|
|
|
|
#define _USE_MATH_DEFINES
|
|
#include <cmath>
|
|
#undef _USE_MATH_DEFINES
|
|
|
|
#include <grid.hxx>
|
|
|
|
// for ::std::sort
|
|
#include <algorithm>
|
|
|
|
ResId SaneResId( sal_uInt32 );
|
|
|
|
/***********************************************************************
|
|
*
|
|
* GridWindow
|
|
*
|
|
***********************************************************************/
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
GridWindow::GridWindow(double* pXValues, double* pYValues, int nValues, Window* pParent, sal_Bool bCutValues )
|
|
: ModalDialog( pParent, SaneResId( GRID_DIALOG ) ),
|
|
m_aGridArea( 50, 15, 100, 100 ),
|
|
m_pXValues( pXValues ),
|
|
m_pOrigYValues( pYValues ),
|
|
m_nValues( nValues ),
|
|
m_pNewYValues( NULL ),
|
|
m_bCutValues( bCutValues ),
|
|
m_aHandles(),
|
|
m_nDragIndex( 0xffffffff ),
|
|
m_aMarkerBitmap( Bitmap( SaneResId( GRID_DIALOG_HANDLE_BMP ) ), Color( 255, 255, 255 ) ),
|
|
m_aOKButton( this, SaneResId( GRID_DIALOG_OK_BTN ) ),
|
|
m_aCancelButton( this, SaneResId( GRID_DIALOG_CANCEL_BTN ) ),
|
|
m_aResetTypeBox( this, SaneResId( GRID_DIALOG_TYPE_BOX ) ),
|
|
m_aResetButton( this, SaneResId( GRID_DIALOG_RESET_BTN ) )
|
|
{
|
|
sal_uInt16 nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_LINEAR_ASCENDING ) ) );
|
|
m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_LINEAR_ASCENDING );
|
|
|
|
nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_LINEAR_DESCENDING ) ) );
|
|
m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_LINEAR_DESCENDING );
|
|
|
|
nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_RESET ) ) );
|
|
m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_RESET );
|
|
|
|
nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_EXPONENTIAL ) ) );
|
|
m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_EXPONENTIAL );
|
|
|
|
m_aResetTypeBox.SelectEntryPos( 0 );
|
|
|
|
m_aResetButton.SetClickHdl( LINK( this, GridWindow, ClickButtonHdl ) );
|
|
|
|
SetMapMode( MapMode( MAP_PIXEL ) );
|
|
Size aSize = GetOutputSizePixel();
|
|
Size aBtnSize = m_aOKButton.GetOutputSizePixel();
|
|
m_aGridArea.setWidth( aSize.Width() - aBtnSize.Width() - 80 );
|
|
m_aGridArea.setHeight( aSize.Height() - 40 );
|
|
|
|
if( m_pOrigYValues && m_nValues )
|
|
{
|
|
m_pNewYValues = new double[ m_nValues ];
|
|
memcpy( m_pNewYValues, m_pOrigYValues, sizeof( double ) * m_nValues );
|
|
}
|
|
|
|
setBoundings( 0, 0, 1023, 1023 );
|
|
computeExtremes();
|
|
|
|
// create left and right marker as first and last entry
|
|
m_BmOffX = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Width() >> 1);
|
|
m_BmOffY = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Height() >> 1);
|
|
m_aHandles.push_back(impHandle(transform(findMinX(), findMinY()), m_BmOffX, m_BmOffY));
|
|
m_aHandles.push_back(impHandle(transform(findMaxX(), findMaxY()), m_BmOffX, m_BmOffY));
|
|
|
|
FreeResource();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
GridWindow::~GridWindow()
|
|
{
|
|
if( m_pNewYValues )
|
|
delete [] m_pNewYValues;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
double GridWindow::findMinX()
|
|
{
|
|
if( ! m_pXValues )
|
|
return 0.0;
|
|
double fMin = m_pXValues[0];
|
|
for( int i = 1; i < m_nValues; i++ )
|
|
if( m_pXValues[ i ] < fMin )
|
|
fMin = m_pXValues[ i ];
|
|
return fMin;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
double GridWindow::findMinY()
|
|
{
|
|
if( ! m_pNewYValues )
|
|
return 0.0;
|
|
double fMin = m_pNewYValues[0];
|
|
for( int i = 1; i < m_nValues; i++ )
|
|
if( m_pNewYValues[ i ] < fMin )
|
|
fMin = m_pNewYValues[ i ];
|
|
return fMin;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
double GridWindow::findMaxX()
|
|
{
|
|
if( ! m_pXValues )
|
|
return 0.0;
|
|
double fMax = m_pXValues[0];
|
|
for( int i = 1; i < m_nValues; i++ )
|
|
if( m_pXValues[ i ] > fMax )
|
|
fMax = m_pXValues[ i ];
|
|
return fMax;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
double GridWindow::findMaxY()
|
|
{
|
|
if( ! m_pNewYValues )
|
|
return 0.0;
|
|
double fMax = m_pNewYValues[0];
|
|
for( int i = 1; i < m_nValues; i++ )
|
|
if( m_pNewYValues[ i ] > fMax )
|
|
fMax = m_pNewYValues[ i ];
|
|
return fMax;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::computeExtremes()
|
|
{
|
|
if( m_nValues && m_pXValues && m_pOrigYValues )
|
|
{
|
|
m_fMaxX = m_fMinX = m_pXValues[0];
|
|
m_fMaxY = m_fMinY = m_pOrigYValues[0];
|
|
for( int i = 1; i < m_nValues; i++ )
|
|
{
|
|
if( m_pXValues[ i ] > m_fMaxX )
|
|
m_fMaxX = m_pXValues[ i ];
|
|
else if( m_pXValues[ i ] < m_fMinX )
|
|
m_fMinX = m_pXValues[ i ];
|
|
if( m_pOrigYValues[ i ] > m_fMaxY )
|
|
m_fMaxY = m_pOrigYValues[ i ];
|
|
else if( m_pOrigYValues[ i ] < m_fMinY )
|
|
m_fMinY = m_pOrigYValues[ i ];
|
|
}
|
|
setBoundings( m_fMinX, m_fMinY, m_fMaxX, m_fMaxY );
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
Point GridWindow::transform( double x, double y )
|
|
{
|
|
Point aRet;
|
|
|
|
aRet.X() = (long)( ( x - m_fMinX ) *
|
|
(double)m_aGridArea.GetWidth() / ( m_fMaxX - m_fMinX )
|
|
+ m_aGridArea.Left() );
|
|
aRet.Y() = (long)(
|
|
m_aGridArea.Bottom() -
|
|
( y - m_fMinY ) *
|
|
(double)m_aGridArea.GetHeight() / ( m_fMaxY - m_fMinY ) );
|
|
return aRet;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::transform( const Point& rOriginal, double& x, double& y )
|
|
{
|
|
x = ( rOriginal.X() - m_aGridArea.Left() ) * (m_fMaxX - m_fMinX) / (double)m_aGridArea.GetWidth() + m_fMinX;
|
|
y = ( m_aGridArea.Bottom() - rOriginal.Y() ) * (m_fMaxY - m_fMinY) / (double)m_aGridArea.GetHeight() + m_fMinY;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::drawLine( double x1, double y1, double x2, double y2 )
|
|
{
|
|
DrawLine( transform( x1, y1 ), transform( x2, y2 ) );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::computeChunk( double fMin, double fMax, double& fChunkOut, double& fMinChunkOut )
|
|
{
|
|
// get a nice chunk size like 10, 100, 25 or such
|
|
fChunkOut = ( fMax - fMin ) / 6.0;
|
|
int logchunk = (int)std::log10( fChunkOut );
|
|
int nChunk = (int)( fChunkOut / std::exp( (double)(logchunk-1) * M_LN10 ) );
|
|
if( nChunk >= 75 )
|
|
nChunk = 100;
|
|
else if( nChunk >= 35 )
|
|
nChunk = 50;
|
|
else if ( nChunk > 20 )
|
|
nChunk = 25;
|
|
else if ( nChunk >= 13 )
|
|
nChunk = 20;
|
|
else if( nChunk > 5 )
|
|
nChunk = 10;
|
|
else
|
|
nChunk = 5;
|
|
fChunkOut = (double) nChunk * exp( (double)(logchunk-1) * M_LN10 );
|
|
// compute whole chunks fitting into fMin
|
|
nChunk = (int)( fMin / fChunkOut );
|
|
fMinChunkOut = (double)nChunk * fChunkOut;
|
|
while( fMinChunkOut < fMin )
|
|
fMinChunkOut += fChunkOut;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::computeNew()
|
|
{
|
|
if(2L == m_aHandles.size())
|
|
{
|
|
// special case: only left and right markers
|
|
double xleft, yleft;
|
|
double xright, yright;
|
|
transform(m_aHandles[0L].maPos, xleft, yleft);
|
|
transform(m_aHandles[1L].maPos, xright, yright );
|
|
double factor = (yright-yleft)/(xright-xleft);
|
|
for( int i = 0; i < m_nValues; i++ )
|
|
{
|
|
m_pNewYValues[ i ] = yleft + ( m_pXValues[ i ] - xleft )*factor;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// sort markers
|
|
std::sort(m_aHandles.begin(), m_aHandles.end());
|
|
const int nSorted = m_aHandles.size();
|
|
int i;
|
|
|
|
// get node arrays
|
|
double* nodex = new double[ nSorted ];
|
|
double* nodey = new double[ nSorted ];
|
|
|
|
for( i = 0L; i < nSorted; i++ )
|
|
transform( m_aHandles[i].maPos, nodex[ i ], nodey[ i ] );
|
|
|
|
for( i = 0; i < m_nValues; i++ )
|
|
{
|
|
double x = m_pXValues[ i ];
|
|
m_pNewYValues[ i ] = interpolate( x, nodex, nodey, nSorted );
|
|
if( m_bCutValues )
|
|
{
|
|
if( m_pNewYValues[ i ] > m_fMaxY )
|
|
m_pNewYValues[ i ] = m_fMaxY;
|
|
else if( m_pNewYValues[ i ] < m_fMinY )
|
|
m_pNewYValues[ i ] = m_fMinY;
|
|
}
|
|
}
|
|
|
|
delete [] nodex;
|
|
delete [] nodey;
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
double GridWindow::interpolate(
|
|
double x,
|
|
double* pNodeX,
|
|
double* pNodeY,
|
|
int nNodes )
|
|
{
|
|
// compute Lagrange interpolation
|
|
double ret = 0;
|
|
for( int i = 0; i < nNodes; i++ )
|
|
{
|
|
double sum = pNodeY[ i ];
|
|
for( int n = 0; n < nNodes; n++ )
|
|
{
|
|
if( n != i )
|
|
{
|
|
sum *= x - pNodeX[ n ];
|
|
sum /= pNodeX[ i ] - pNodeX[ n ];
|
|
}
|
|
}
|
|
ret += sum;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::setBoundings( double fMinX, double fMinY, double fMaxX, double fMaxY )
|
|
{
|
|
m_fMinX = fMinX;
|
|
m_fMinY = fMinY;
|
|
m_fMaxX = fMaxX;
|
|
m_fMaxY = fMaxY;
|
|
|
|
computeChunk( m_fMinX, m_fMaxX, m_fChunkX, m_fMinChunkX );
|
|
computeChunk( m_fMinY, m_fMaxY, m_fChunkY, m_fMinChunkY );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::drawGrid()
|
|
{
|
|
char pBuf[256];
|
|
SetLineColor( Color( COL_BLACK ) );
|
|
// draw vertical lines
|
|
for( double fX = m_fMinChunkX; fX < m_fMaxX; fX += m_fChunkX )
|
|
{
|
|
drawLine( fX, m_fMinY, fX, m_fMaxY );
|
|
// draw tickmarks
|
|
Point aPt = transform( fX, m_fMinY );
|
|
std::sprintf( pBuf, "%g", fX );
|
|
String aMark( pBuf, osl_getThreadTextEncoding() );
|
|
Size aTextSize( GetTextWidth( aMark ), GetTextHeight() );
|
|
aPt.X() -= aTextSize.Width()/2;
|
|
aPt.Y() += aTextSize.Height()/2;
|
|
DrawText( aPt, aMark );
|
|
}
|
|
// draw horizontal lines
|
|
for( double fY = m_fMinChunkY; fY < m_fMaxY; fY += m_fChunkY )
|
|
{
|
|
drawLine( m_fMinX, fY, m_fMaxX, fY );
|
|
// draw tickmarks
|
|
Point aPt = transform( m_fMinX, fY );
|
|
std::sprintf( pBuf, "%g", fY );
|
|
String aMark( pBuf, osl_getThreadTextEncoding() );
|
|
Size aTextSize( GetTextWidth( aMark ), GetTextHeight() );
|
|
aPt.X() -= aTextSize.Width() + 2;
|
|
aPt.Y() -= aTextSize.Height()/2;
|
|
DrawText( aPt, aMark );
|
|
}
|
|
|
|
// draw boundings
|
|
drawLine( m_fMinX, m_fMinY, m_fMaxX, m_fMinY );
|
|
drawLine( m_fMinX, m_fMaxY, m_fMaxX, m_fMaxY );
|
|
drawLine( m_fMinX, m_fMinY, m_fMinX, m_fMaxY );
|
|
drawLine( m_fMaxX, m_fMinY, m_fMaxX, m_fMaxY );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::drawOriginal()
|
|
{
|
|
if( m_nValues && m_pXValues && m_pOrigYValues )
|
|
{
|
|
SetLineColor( Color( COL_RED ) );
|
|
for( int i = 0; i < m_nValues-1; i++ )
|
|
{
|
|
drawLine( m_pXValues[ i ], m_pOrigYValues[ i ],
|
|
m_pXValues[ i+1 ], m_pOrigYValues[ i+1 ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::drawNew()
|
|
{
|
|
if( m_nValues && m_pXValues && m_pNewYValues )
|
|
{
|
|
SetClipRegion( m_aGridArea );
|
|
SetLineColor( Color( COL_YELLOW ) );
|
|
for( int i = 0; i < m_nValues-1; i++ )
|
|
{
|
|
drawLine( m_pXValues[ i ], m_pNewYValues[ i ],
|
|
m_pXValues[ i+1 ], m_pNewYValues[ i+1 ] );
|
|
}
|
|
SetClipRegion();
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::drawHandles()
|
|
{
|
|
for(sal_uInt32 i(0L); i < m_aHandles.size(); i++)
|
|
{
|
|
m_aHandles[i].draw(*this, m_aMarkerBitmap);
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::Paint( const Rectangle& rRect )
|
|
{
|
|
ModalDialog::Paint( rRect );
|
|
drawGrid();
|
|
drawOriginal();
|
|
drawNew();
|
|
drawHandles();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::MouseMove( const MouseEvent& rEvt )
|
|
{
|
|
if( rEvt.GetButtons() == MOUSE_LEFT && m_nDragIndex != 0xffffffff )
|
|
{
|
|
Point aPoint( rEvt.GetPosPixel() );
|
|
|
|
if( m_nDragIndex == 0L || m_nDragIndex == m_aHandles.size() - 1L)
|
|
{
|
|
aPoint.X() = m_aHandles[m_nDragIndex].maPos.X();
|
|
}
|
|
else
|
|
{
|
|
if(aPoint.X() < m_aGridArea.Left())
|
|
aPoint.X() = m_aGridArea.Left();
|
|
else if(aPoint.X() > m_aGridArea.Right())
|
|
aPoint.X() = m_aGridArea.Right();
|
|
}
|
|
|
|
if( aPoint.Y() < m_aGridArea.Top() )
|
|
aPoint.Y() = m_aGridArea.Top();
|
|
else if( aPoint.Y() > m_aGridArea.Bottom() )
|
|
aPoint.Y() = m_aGridArea.Bottom();
|
|
|
|
if( aPoint != m_aHandles[m_nDragIndex].maPos )
|
|
{
|
|
m_aHandles[m_nDragIndex].maPos = aPoint;
|
|
Invalidate( m_aGridArea );
|
|
}
|
|
}
|
|
|
|
ModalDialog::MouseMove( rEvt );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::MouseButtonUp( const MouseEvent& rEvt )
|
|
{
|
|
if( rEvt.GetButtons() == MOUSE_LEFT )
|
|
{
|
|
if( m_nDragIndex != 0xffffffff )
|
|
{
|
|
m_nDragIndex = 0xffffffff;
|
|
computeNew();
|
|
Invalidate( m_aGridArea );
|
|
Paint( m_aGridArea );
|
|
}
|
|
}
|
|
|
|
ModalDialog::MouseButtonUp( rEvt );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
void GridWindow::MouseButtonDown( const MouseEvent& rEvt )
|
|
{
|
|
Point aPoint( rEvt.GetPosPixel() );
|
|
sal_uInt32 nMarkerIndex = 0xffffffff;
|
|
|
|
for(sal_uInt32 a(0L); nMarkerIndex == 0xffffffff && a < m_aHandles.size(); a++)
|
|
{
|
|
if(m_aHandles[a].isHit(*this, aPoint))
|
|
{
|
|
nMarkerIndex = a;
|
|
}
|
|
}
|
|
|
|
if( rEvt.GetButtons() == MOUSE_LEFT )
|
|
{
|
|
// user wants to drag a button
|
|
if( nMarkerIndex != 0xffffffff )
|
|
{
|
|
m_nDragIndex = nMarkerIndex;
|
|
}
|
|
}
|
|
else if( rEvt.GetButtons() == MOUSE_RIGHT )
|
|
{
|
|
// user wants to add/delete a button
|
|
if( nMarkerIndex != 0xffffffff )
|
|
{
|
|
if( nMarkerIndex != 0L && nMarkerIndex != m_aHandles.size() - 1L)
|
|
{
|
|
// delete marker under mouse
|
|
if( m_nDragIndex == nMarkerIndex )
|
|
m_nDragIndex = 0xffffffff;
|
|
|
|
m_aHandles.erase(m_aHandles.begin() + nMarkerIndex);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_BmOffX = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Width() >> 1);
|
|
m_BmOffY = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Height() >> 1);
|
|
m_aHandles.push_back(impHandle(aPoint, m_BmOffX, m_BmOffY));
|
|
}
|
|
|
|
computeNew();
|
|
Invalidate( m_aGridArea );
|
|
Paint( m_aGridArea );
|
|
}
|
|
|
|
ModalDialog::MouseButtonDown( rEvt );
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
IMPL_LINK( GridWindow, ClickButtonHdl, Button*, pButton )
|
|
{
|
|
if( pButton == &m_aResetButton )
|
|
{
|
|
int nType = (int)(sal_IntPtr)m_aResetTypeBox.GetEntryData( m_aResetTypeBox.GetSelectEntryPos() );
|
|
switch( nType )
|
|
{
|
|
case RESET_TYPE_LINEAR_ASCENDING:
|
|
{
|
|
for( int i = 0; i < m_nValues; i++ )
|
|
{
|
|
m_pNewYValues[ i ] = m_fMinY + (m_fMaxY-m_fMinY)/(m_fMaxX-m_fMinX)*(m_pXValues[i]-m_fMinX);
|
|
}
|
|
}
|
|
break;
|
|
case RESET_TYPE_LINEAR_DESCENDING:
|
|
{
|
|
for( int i = 0; i < m_nValues; i++ )
|
|
{
|
|
m_pNewYValues[ i ] = m_fMaxY - (m_fMaxY-m_fMinY)/(m_fMaxX-m_fMinX)*(m_pXValues[i]-m_fMinX);
|
|
}
|
|
}
|
|
break;
|
|
case RESET_TYPE_RESET:
|
|
{
|
|
if( m_pOrigYValues && m_pNewYValues && m_nValues )
|
|
memcpy( m_pNewYValues, m_pOrigYValues, m_nValues*sizeof(double) );
|
|
}
|
|
break;
|
|
case RESET_TYPE_EXPONENTIAL:
|
|
{
|
|
for( int i = 0; i < m_nValues; i++ )
|
|
{
|
|
m_pNewYValues[ i ] = m_fMinY + (m_fMaxY-m_fMinY)*(std::exp((m_pXValues[i]-m_fMinX)/(m_fMaxX-m_fMinX))-1.0)/(M_E-1.0);
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
for(sal_uInt32 i(0L); i < m_aHandles.size(); i++)
|
|
{
|
|
// find nearest xvalue
|
|
double x, y;
|
|
transform( m_aHandles[i].maPos, x, y );
|
|
int nIndex = 0;
|
|
double delta = std::fabs( x-m_pXValues[0] );
|
|
for( int n = 1; n < m_nValues; n++ )
|
|
{
|
|
if( delta > std::fabs( x - m_pXValues[ n ] ) )
|
|
{
|
|
delta = std::fabs( x - m_pXValues[ n ] );
|
|
nIndex = n;
|
|
}
|
|
}
|
|
if( 0 == i )
|
|
m_aHandles[i].maPos = transform( m_fMinX, m_pNewYValues[ nIndex ] );
|
|
else if( m_aHandles.size() - 1L == i )
|
|
m_aHandles[i].maPos = transform( m_fMaxX, m_pNewYValues[ nIndex ] );
|
|
else
|
|
m_aHandles[i].maPos = transform( m_pXValues[ nIndex ], m_pNewYValues[ nIndex ] );
|
|
}
|
|
|
|
Invalidate( m_aGridArea );
|
|
Paint(Rectangle());
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|