1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
/* -*- 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 <sal/main.h>
#include <tools/extendapplicationenvironment.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <vcl/event.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/gradient.hxx>
#include <vcl/lineinfo.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/bmpacc.hxx>
#include <vcl/metric.hxx>
#include <rtl/ustrbuf.hxx>
#include <math.h>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace cppu;
// Forward declaration
void Main();
SAL_IMPLEMENT_MAIN()
{
tools::extendApplicationEnvironment();
Reference< XComponentContext > xContext = defaultBootstrap_InitialComponentContext();
Reference< XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), UNO_QUERY );
if( !xServiceManager.is() )
Application::Abort( "Failed to bootstrap" );
comphelper::setProcessServiceFactory( xServiceManager );
InitVCL();
::Main();
DeInitVCL();
return 0;
}
class MyWin : public WorkWindow
{
Bitmap m_aBitmap;
public:
MyWin( Window* pParent, WinBits nWinStyle );
virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
virtual void KeyUp( const KeyEvent& rKEvt ) SAL_OVERRIDE;
virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
virtual void Resize() SAL_OVERRIDE;
};
void Main()
{
MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
aMainWin.SetText( OUString( "VCL - Workbench" ) );
aMainWin.Show();
Application::Execute();
}
MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
WorkWindow( pParent, nWinStyle ),
m_aBitmap( Size( 256, 256 ), 32 )
{
// prepare an alpha mask
BitmapWriteAccess* pAcc = m_aBitmap.AcquireWriteAccess();
for( int nX = 0; nX < 256; nX++ )
{
for( int nY = 0; nY < 256; nY++ )
{
double fRed = 255.0-1.5*sqrt((double)(nX*nX+nY*nY));
if( fRed < 0.0 )
fRed = 0.0;
double fGreen = 255.0-1.5*sqrt((double)(((255-nX)*(255-nX)+nY*nY)));
if( fGreen < 0.0 )
fGreen = 0.0;
double fBlue = 255.0-1.5*sqrt((double)((128-nX)*(128-nX)+(255-nY)*(255-nY)));
if( fBlue < 0.0 )
fBlue = 0.0;
pAcc->SetPixel( nY, nX, BitmapColor( sal_uInt8(fRed), sal_uInt8(fGreen), sal_uInt8(fBlue) ) );
}
}
m_aBitmap.ReleaseAccess( pAcc );
}
void MyWin::MouseMove( const MouseEvent& rMEvt )
{
WorkWindow::MouseMove( rMEvt );
}
void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
{
WorkWindow::MouseButtonDown( rMEvt );
}
void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
{
WorkWindow::MouseButtonUp( rMEvt );
}
void MyWin::KeyInput( const KeyEvent& rKEvt )
{
WorkWindow::KeyInput( rKEvt );
}
void MyWin::KeyUp( const KeyEvent& rKEvt )
{
WorkWindow::KeyUp( rKEvt );
}
static Point project( const Point& rPoint )
{
const double angle_x = M_PI / 6.0;
const double angle_z = M_PI / 6.0;
// transform planar coordinates to 3d
double x = rPoint.X();
double y = rPoint.Y();
// rotate around X axis
double x1 = x;
double y1 = y * cos( angle_x );
double z1 = y * sin( angle_x );
// rotate around Z axis
double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
//double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
double z2 = z1;
return Point( (sal_Int32)x2, (sal_Int32)z2 );
}
static Color approachColor( const Color& rFrom, const Color& rTo )
{
Color aColor;
sal_uInt8 nDiff;
// approach red
if( rFrom.GetRed() < rTo.GetRed() )
{
nDiff = rTo.GetRed() - rFrom.GetRed();
aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
}
else if( rFrom.GetRed() > rTo.GetRed() )
{
nDiff = rFrom.GetRed() - rTo.GetRed();
aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
}
else
aColor.SetRed( rFrom.GetRed() );
// approach Green
if( rFrom.GetGreen() < rTo.GetGreen() )
{
nDiff = rTo.GetGreen() - rFrom.GetGreen();
aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
}
else if( rFrom.GetGreen() > rTo.GetGreen() )
{
nDiff = rFrom.GetGreen() - rTo.GetGreen();
aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
}
else
aColor.SetGreen( rFrom.GetGreen() );
// approach blue
if( rFrom.GetBlue() < rTo.GetBlue() )
{
nDiff = rTo.GetBlue() - rFrom.GetBlue();
aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
}
else if( rFrom.GetBlue() > rTo.GetBlue() )
{
nDiff = rFrom.GetBlue() - rTo.GetBlue();
aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
}
else
aColor.SetBlue( rFrom.GetBlue() );
return aColor;
}
#define DELTA 5.0
void MyWin::Paint( const Rectangle& rRect )
{
WorkWindow::Paint( rRect );
Push( PUSH_ALL );
MapMode aMapMode( MAP_100TH_MM );
SetMapMode( aMapMode );
Size aPaperSize = GetOutputSize();
Point aCenter( aPaperSize.Width()/2-300,
(aPaperSize.Height() - 8400)/2 + 8400 );
Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
DrawRect( Rectangle( Point( 100,100 ),
Size( aPaperSize.Width()-200,
aPaperSize.Height()-200 ) ) );
DrawRect( Rectangle( Point( 200,200 ),
Size( aPaperSize.Width()-400,
aPaperSize.Height()-400 ) ) );
DrawRect( Rectangle( Point( 300,300 ),
Size( aPaperSize.Width()-600,
aPaperSize.Height()-600 ) ) );
const int nFontCount = GetDevFontCount();
const int nFontSamples = (nFontCount<15) ? nFontCount : 15;
for( int i = 0; i < nFontSamples; ++i )
{
FontInfo aFont = GetDevFont( (i*nFontCount) / nFontSamples );
aFont.SetHeight( 400 + (i%7) * 100 );
aFont.SetOrientation( i * (3600 / nFontSamples) );
SetFont( aFont );
sal_uInt8 nRed = (i << 6) & 0xC0;
sal_uInt8 nGreen = (i << 4) & 0xC0;
sal_uInt8 nBlue = (i << 2) & 0xC0;
SetTextColor( Color( nRed, nGreen, nBlue ) );
OUStringBuffer aPrintText(1024);
long nMaxWidth = 0;
aPrintText.appendAscii( "SVP test program" );
DrawText( Rectangle( Point( (aPaperSize.Width() - 4000) / 2, 2000 ),
Size( aPaperSize.Width() - 2100 - nMaxWidth,
aPaperSize.Height() - 4000 ) ),
aPrintText.makeStringAndClear(),
TEXT_DRAW_MULTILINE );
}
SetFillColor();
DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
Size( 3000,3000 ) ) );
DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
Size( 3000,3000 ),
m_aBitmap );
Color aWhite( 0xff, 0xff, 0xff );
Color aBlack( 0, 0, 0 );
Color aLightRed( 0xff, 0, 0 );
Color aDarkRed( 0x40, 0, 0 );
Color aLightBlue( 0, 0, 0xff );
Color aDarkBlue( 0,0,0x40 );
Color aLightGreen( 0, 0xff, 0 );
Color aDarkGreen( 0, 0x40, 0 );
Gradient aGradient( GradientStyle_LINEAR, aBlack, aWhite );
aGradient.SetAngle( 900 );
DrawGradient( Rectangle( Point( 1000, 4500 ),
Size( aPaperSize.Width() - 2000,
500 ) ), aGradient );
aGradient.SetStartColor( aDarkRed );
aGradient.SetEndColor( aLightBlue );
DrawGradient( Rectangle( Point( 1000, 5300 ),
Size( aPaperSize.Width() - 2000,
500 ) ), aGradient );
aGradient.SetStartColor( aDarkBlue );
aGradient.SetEndColor( aLightGreen );
DrawGradient( Rectangle( Point( 1000, 6100 ),
Size( aPaperSize.Width() - 2000,
500 ) ), aGradient );
aGradient.SetStartColor( aDarkGreen );
aGradient.SetEndColor( aLightRed );
DrawGradient( Rectangle( Point( 1000, 6900 ),
Size( aPaperSize.Width() - 2000,
500 ) ), aGradient );
LineInfo aLineInfo( LINE_SOLID, 200 );
double sind = sin( DELTA*M_PI/180.0 );
double cosd = cos( DELTA*M_PI/180.0 );
double factor = 1 + (DELTA/1000.0);
int n=0;
Color aLineColor( 0, 0, 0 );
Color aApproachColor( 0, 0, 200 );
while ( aP2.X() < aCenter.X() && n++ < 680 )
{
aLineInfo.SetWidth( n/3 );
aLineColor = approachColor( aLineColor, aApproachColor );
SetLineColor( aLineColor );
// switch aproach color
if( aApproachColor.IsRGBEqual( aLineColor ) )
{
if( aApproachColor.GetRed() )
aApproachColor = Color( 0, 0, 200 );
else if( aApproachColor.GetGreen() )
aApproachColor = Color( 200, 0, 0 );
else
aApproachColor = Color( 0, 200, 0 );
}
DrawLine( project( aP1 ) + aCenter,
project( aP2 ) + aCenter,
aLineInfo );
aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
aP1 = aPoint;
aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
aP2 = aPoint;
}
Pop();
}
void MyWin::Resize()
{
WorkWindow::Resize();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|