* Removed PI, and PI2 from math.h.
* Replaced all occurences with the standard macros M_PI, and M_PI_2. * Some coding style cleanup on the touched files, no other changes besides adding a missing check for a failed memory allocation. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31250 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+149
-152
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku.
|
* Copyright 2001-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _MATH_H_
|
#ifndef _MATH_H_
|
||||||
@@ -20,9 +20,6 @@
|
|||||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||||
|
|
||||||
#define PI M_PI
|
|
||||||
#define PI2 M_PI_2
|
|
||||||
|
|
||||||
/* platform independent IEEE floating point special values */
|
/* platform independent IEEE floating point special values */
|
||||||
#define __HUGE_VAL_v 0x7ff0000000000000LL
|
#define __HUGE_VAL_v 0x7ff0000000000000LL
|
||||||
#define __huge_val_t union { unsigned char __c[8]; long long __ll; double __d; }
|
#define __huge_val_t union { unsigned char __c[8]; long long __ll; double __d; }
|
||||||
@@ -34,7 +31,7 @@
|
|||||||
#define __huge_valf_t union { unsigned char __c[4]; long __l; float __f; }
|
#define __huge_valf_t union { unsigned char __c[4]; long __l; float __f; }
|
||||||
#define HUGE_VALF (((__huge_valf_t) { __l: __HUGE_VALF_v }).__f)
|
#define HUGE_VALF (((__huge_valf_t) { __l: __HUGE_VALF_v }).__f)
|
||||||
|
|
||||||
/* ToDo: define HUGE_VALL for long doubles */
|
/* TODO: define HUGE_VALL for long doubles */
|
||||||
|
|
||||||
#define __NAN_VALF_v 0x7fc00000L
|
#define __NAN_VALF_v 0x7fc00000L
|
||||||
#define NAN (((__huge_valf_t) { __l: __NAN_VALF_v }).__f)
|
#define NAN (((__huge_valf_t) { __l: __NAN_VALF_v }).__f)
|
||||||
@@ -79,149 +76,149 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* float math functions */
|
/* float math functions */
|
||||||
extern float acosf(float x);
|
extern float acosf(float x);
|
||||||
extern float acoshf(float x);
|
extern float acoshf(float x);
|
||||||
extern float asinf(float x);
|
extern float asinf(float x);
|
||||||
extern float asinhf(float x);
|
extern float asinhf(float x);
|
||||||
extern float atan2f(float y, float x);
|
extern float atan2f(float y, float x);
|
||||||
extern float atanf(float x);
|
extern float atanf(float x);
|
||||||
extern float atanhf(float x);
|
extern float atanhf(float x);
|
||||||
extern float cbrtf(float x);
|
extern float cbrtf(float x);
|
||||||
extern float ceilf(float x);
|
extern float ceilf(float x);
|
||||||
extern float cosf(float x);
|
extern float cosf(float x);
|
||||||
extern float coshf(float x);
|
extern float coshf(float x);
|
||||||
extern float expf(float x);
|
extern float expf(float x);
|
||||||
extern float expm1f(float x);
|
extern float expm1f(float x);
|
||||||
extern float fabsf(float x);
|
extern float fabsf(float x);
|
||||||
extern float floorf(float x);
|
extern float floorf(float x);
|
||||||
extern float fmodf(float x, float y);
|
extern float fmodf(float x, float y);
|
||||||
extern float frexpf(float x, int *_exponent);
|
extern float frexpf(float x, int *_exponent);
|
||||||
extern float gammaf(float x);
|
extern float gammaf(float x);
|
||||||
extern float hypotf(float x, float y);
|
extern float hypotf(float x, float y);
|
||||||
extern float ldexpf(float x, int exponent);
|
extern float ldexpf(float x, int exponent);
|
||||||
extern float lgammaf(float x);
|
extern float lgammaf(float x);
|
||||||
extern long long llrintf(float x);
|
extern long long llrintf(float x);
|
||||||
extern float log10f(float x);
|
extern float log10f(float x);
|
||||||
extern float log1pf(float x);
|
extern float log1pf(float x);
|
||||||
extern float logbf(float x);
|
extern float logbf(float x);
|
||||||
extern float logf(float x);
|
extern float logf(float x);
|
||||||
extern long lrintf(float x);
|
extern long lrintf(float x);
|
||||||
extern long lroundf(float x);
|
extern long lroundf(float x);
|
||||||
extern float modff(float x, float *y);
|
extern float modff(float x, float *y);
|
||||||
extern float nearbyintf(float x);
|
extern float nearbyintf(float x);
|
||||||
extern float powf(float x, float y);
|
extern float powf(float x, float y);
|
||||||
extern float remquof(float x, float y, int *quo);
|
extern float remquof(float x, float y, int *quo);
|
||||||
extern float roundf(float x);
|
extern float roundf(float x);
|
||||||
extern float sinf(float x);
|
extern float sinf(float x);
|
||||||
extern float sinhf(float x);
|
extern float sinhf(float x);
|
||||||
extern float sqrtf(float x);
|
extern float sqrtf(float x);
|
||||||
extern float tanf(float x);
|
extern float tanf(float x);
|
||||||
extern float tanhf(float x);
|
extern float tanhf(float x);
|
||||||
|
|
||||||
/* double math functions */
|
/* double math functions */
|
||||||
extern double acos(double x);
|
extern double acos(double x);
|
||||||
extern double acosh(double x);
|
extern double acosh(double x);
|
||||||
extern double asin(double x);
|
extern double asin(double x);
|
||||||
extern double asinh(double x);
|
extern double asinh(double x);
|
||||||
extern double atan(double x);
|
extern double atan(double x);
|
||||||
extern double atan2(double x, double y);
|
extern double atan2(double x, double y);
|
||||||
extern double atanh(double x);
|
extern double atanh(double x);
|
||||||
extern double ceil(double x);
|
extern double ceil(double x);
|
||||||
extern double cos(double x);
|
extern double cos(double x);
|
||||||
extern double cosh(double x);
|
extern double cosh(double x);
|
||||||
extern double exp(double x);
|
extern double exp(double x);
|
||||||
extern double fabs(double x);
|
extern double fabs(double x);
|
||||||
extern double floor(double x);
|
extern double floor(double x);
|
||||||
extern double fmod(double x, double y);
|
extern double fmod(double x, double y);
|
||||||
extern double frexp(double x, int *_exponent);
|
extern double frexp(double x, int *_exponent);
|
||||||
extern double gamma(double x);
|
extern double gamma(double x);
|
||||||
extern double ldexp(double x, int exponent);
|
extern double ldexp(double x, int exponent);
|
||||||
extern double lgamma(double x);
|
extern double lgamma(double x);
|
||||||
extern long long llrint(double x);
|
extern long long llrint(double x);
|
||||||
extern double log(double x);
|
extern double log(double x);
|
||||||
extern double log10(double x);
|
extern double log10(double x);
|
||||||
extern long lrint(double x);
|
extern long lrint(double x);
|
||||||
extern long lround(double x);
|
extern long lround(double x);
|
||||||
extern double modf(double x, double *y);
|
extern double modf(double x, double *y);
|
||||||
extern double nearbyint(double x);
|
extern double nearbyint(double x);
|
||||||
extern double pow(double x, double y);
|
extern double pow(double x, double y);
|
||||||
extern double remquo(double x, double y, int *quo);
|
extern double remquo(double x, double y, int *quo);
|
||||||
extern double round(double x);
|
extern double round(double x);
|
||||||
extern double sin(double x);
|
extern double sin(double x);
|
||||||
extern double sinh(double x);
|
extern double sinh(double x);
|
||||||
extern double sqrt(double x);
|
extern double sqrt(double x);
|
||||||
extern double tan(double x);
|
extern double tan(double x);
|
||||||
extern double tanh(double x);
|
extern double tanh(double x);
|
||||||
extern double trunc(double x);
|
extern double trunc(double x);
|
||||||
|
|
||||||
/* long double math functions */
|
/* long double math functions */
|
||||||
extern long double acosl(long double x);
|
extern long double acosl(long double x);
|
||||||
extern long double acoshl(long double x);
|
extern long double acoshl(long double x);
|
||||||
extern long double asinl(long double x);
|
extern long double asinl(long double x);
|
||||||
extern long double atanl(long double x);
|
extern long double atanl(long double x);
|
||||||
extern long double atanhl(long double x);
|
extern long double atanhl(long double x);
|
||||||
extern long double atan2l(long double y, long double x);
|
extern long double atan2l(long double y, long double x);
|
||||||
extern long double lgammal(long double x);
|
extern long double lgammal(long double x);
|
||||||
extern long double nearbyintl(long double x);
|
extern long double nearbyintl(long double x);
|
||||||
extern long long llrintl(long double x);
|
extern long long llrintl(long double x);
|
||||||
extern long lrintl(long double x);
|
extern long lrintl(long double x);
|
||||||
extern long lroundl(long double x);
|
extern long lroundl(long double x);
|
||||||
extern long double remquol(long double x, long double y, int *quo);
|
extern long double remquol(long double x, long double y, int *quo);
|
||||||
extern long double roundl(long double x);
|
extern long double roundl(long double x);
|
||||||
|
|
||||||
/* some BSD non-ANSI or POSIX math functions */
|
/* some BSD non-ANSI or POSIX math functions */
|
||||||
extern double cbrt(double x);
|
extern double cbrt(double x);
|
||||||
extern double erf(double x);
|
extern double erf(double x);
|
||||||
extern double erfc(double x);
|
extern double erfc(double x);
|
||||||
extern double expm1(double x);
|
extern double expm1(double x);
|
||||||
extern double gamma_r(double x, int *y);
|
extern double gamma_r(double x, int *y);
|
||||||
extern double hypot(double x, double y);
|
extern double hypot(double x, double y);
|
||||||
extern int ilogb(double x);
|
extern int ilogb(double x);
|
||||||
extern double j0(double x);
|
extern double j0(double x);
|
||||||
extern double j1(double x);
|
extern double j1(double x);
|
||||||
extern double jn(int x, double y);
|
extern double jn(int x, double y);
|
||||||
extern double lgamma_r(double x, int *y);
|
extern double lgamma_r(double x, int *y);
|
||||||
extern double log1p(double x);
|
extern double log1p(double x);
|
||||||
extern double logb(double x);
|
extern double logb(double x);
|
||||||
extern double nextafter(double x, double y);
|
extern double nextafter(double x, double y);
|
||||||
extern double nexttoward(double x, long double y);
|
extern double nexttoward(double x, long double y);
|
||||||
extern double remainder(double x, double y);
|
extern double remainder(double x, double y);
|
||||||
extern double rint(double x);
|
extern double rint(double x);
|
||||||
extern double scalb (double x, double y);
|
extern double scalb (double x, double y);
|
||||||
extern double y0(double x);
|
extern double y0(double x);
|
||||||
extern double y1(double x);
|
extern double y1(double x);
|
||||||
extern double yn(int x, double y);
|
extern double yn(int x, double y);
|
||||||
|
|
||||||
/* other stuff as defined in BeOS */
|
/* other stuff as defined in BeOS */
|
||||||
extern int isinff(float value);
|
extern int isinff(float value);
|
||||||
extern int finitef(float value);
|
extern int finitef(float value);
|
||||||
extern float dremf(float x, float y);
|
extern float dremf(float x, float y);
|
||||||
extern float significandf(float x);
|
extern float significandf(float x);
|
||||||
extern float copysignf(float x, float y);
|
extern float copysignf(float x, float y);
|
||||||
extern int isnanf(float value);
|
extern int isnanf(float value);
|
||||||
extern double significand(double x);
|
extern double significand(double x);
|
||||||
extern double copysign(double x, double y);
|
extern double copysign(double x, double y);
|
||||||
extern double scalbln(double x, long n);
|
extern double scalbln(double x, long n);
|
||||||
extern double scalbn(double x, int y);
|
extern double scalbn(double x, int y);
|
||||||
extern double drem(double x, double y);
|
extern double drem(double x, double y);
|
||||||
extern int finite(double x);
|
extern int finite(double x);
|
||||||
extern float j0f(float x);
|
extern float j0f(float x);
|
||||||
extern float j1f(float x);
|
extern float j1f(float x);
|
||||||
extern float jnf(int x, float y);
|
extern float jnf(int x, float y);
|
||||||
extern float y0f(float x);
|
extern float y0f(float x);
|
||||||
extern float y1f(float x);
|
extern float y1f(float x);
|
||||||
extern float ynf(int x, float y);
|
extern float ynf(int x, float y);
|
||||||
extern float erff(float x);
|
extern float erff(float x);
|
||||||
extern float erfcf(float x);
|
extern float erfcf(float x);
|
||||||
extern float gammaf_r(float x, int *y);
|
extern float gammaf_r(float x, int *y);
|
||||||
extern float lgammaf_r(float x, int *y);
|
extern float lgammaf_r(float x, int *y);
|
||||||
extern float rintf(float x);
|
extern float rintf(float x);
|
||||||
extern float nextafterf(float x, float y);
|
extern float nextafterf(float x, float y);
|
||||||
extern float nexttowardf(float x, long double y);
|
extern float nexttowardf(float x, long double y);
|
||||||
extern float remainderf(float x, float y);
|
extern float remainderf(float x, float y);
|
||||||
extern float scalbf(float x, float n);
|
extern float scalbf(float x, float n);
|
||||||
extern float scalbnf(float x, int n);
|
extern float scalbnf(float x, int n);
|
||||||
extern int ilogbf(float x);
|
extern int ilogbf(float x);
|
||||||
|
|
||||||
extern long double nextafterl(long double x, long double y);
|
extern long double nextafterl(long double x, long double y);
|
||||||
extern long double nexttowardl(long double x, long double y);
|
extern long double nexttowardl(long double x, long double y);
|
||||||
@@ -231,23 +228,23 @@ extern long double scalbnl(long double x, int n);
|
|||||||
extern long double scalblnl(long double x, long n);
|
extern long double scalblnl(long double x, long n);
|
||||||
|
|
||||||
/* prototypes for functions used in the macros below */
|
/* prototypes for functions used in the macros below */
|
||||||
extern int __fpclassifyf(float value);
|
extern int __fpclassifyf(float value);
|
||||||
extern int __signbitf(float value);
|
extern int __signbitf(float value);
|
||||||
extern int __finitef(float value);
|
extern int __finitef(float value);
|
||||||
extern int __isnanf(float value);
|
extern int __isnanf(float value);
|
||||||
extern int __isinff(float value);
|
extern int __isinff(float value);
|
||||||
|
|
||||||
extern int __fpclassifyl(long double value);
|
extern int __fpclassifyl(long double value);
|
||||||
extern int __signbitl(long double value);
|
extern int __signbitl(long double value);
|
||||||
extern int __finitel(long double value);
|
extern int __finitel(long double value);
|
||||||
extern int __isnanl(long double value);
|
extern int __isnanl(long double value);
|
||||||
extern int __isinfl(long double value);
|
extern int __isinfl(long double value);
|
||||||
|
|
||||||
extern int __fpclassify(double value);
|
extern int __fpclassify(double value);
|
||||||
extern int __signbit(double value);
|
extern int __signbit(double value);
|
||||||
extern int __finite(double value);
|
extern int __finite(double value);
|
||||||
extern int __isnan(double value);
|
extern int __isnan(double value);
|
||||||
extern int __isinf(double value);
|
extern int __isinf(double value);
|
||||||
|
|
||||||
/* returns number of classification appropriate for 'value' */
|
/* returns number of classification appropriate for 'value' */
|
||||||
#define fpclassify(value) \
|
#define fpclassify(value) \
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -109,14 +109,15 @@ update_coefficients(int32 taps, double filterCutOff, bool horizontal, bool isY,
|
|||||||
int32 num = taps * 16;
|
int32 num = taps * 16;
|
||||||
for (int32 i = 0; i < num * 2; i++) {
|
for (int32 i = 0; i < num * 2; i++) {
|
||||||
double sinc;
|
double sinc;
|
||||||
double value = (1.0 / filterCutOff) * taps * PI * (i - num) / (2 * num);
|
double value = (1.0 / filterCutOff) * taps * M_PI * (i - num)
|
||||||
|
/ (2 * num);
|
||||||
if (value == 0.0)
|
if (value == 0.0)
|
||||||
sinc = 1.0;
|
sinc = 1.0;
|
||||||
else
|
else
|
||||||
sinc = sin(value) / value;
|
sinc = sin(value) / value;
|
||||||
|
|
||||||
// Hamming window
|
// Hamming window
|
||||||
double window = (0.5 - 0.5 * cos(i * PI / num));
|
double window = (0.5 - 0.5 * cos(i * M_PI / num));
|
||||||
rawCoefficients[i] = sinc * window;
|
rawCoefficients[i] = sinc * window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,10 +347,10 @@ intel_allocate_overlay_buffer(color_space colorSpace, uint16 width,
|
|||||||
bytesPerPixel = 2;
|
bytesPerPixel = 2;
|
||||||
break;
|
break;
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
bytesPerPixel = 2;
|
bytesPerPixel = 2;
|
||||||
break;
|
break;
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
bytesPerPixel = 4;
|
bytesPerPixel = 4;
|
||||||
break;
|
break;
|
||||||
case B_YCbCr422:
|
case B_YCbCr422:
|
||||||
bytesPerPixel = 2;
|
bytesPerPixel = 2;
|
||||||
|
|||||||
@@ -1,36 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
|
||||||
PDF Writer printer driver.
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
Copyright (c) 2001, 2002 OpenBeOS.
|
* Authors:
|
||||||
|
* Philippe Houdoin
|
||||||
Authors:
|
* Simon Gauvin
|
||||||
Philippe Houdoin
|
* Michael Pfeiffer
|
||||||
Simon Gauvin
|
*/
|
||||||
Michael Pfeiffer
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@@ -47,28 +26,26 @@ THE SOFTWARE.
|
|||||||
#include "Report.h"
|
#include "Report.h"
|
||||||
#include "pdflib.h"
|
#include "pdflib.h"
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
typedef struct {
|
||||||
uint16 from;
|
uint16 from;
|
||||||
uint16 to;
|
uint16 to;
|
||||||
int16 length;
|
int16 length;
|
||||||
uint16 *unicodes;
|
uint16 *unicodes;
|
||||||
} unicode_to_encoding;
|
} unicode_to_encoding;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint16 unicode;
|
uint16 unicode;
|
||||||
uint16 cid;
|
uint16 cid;
|
||||||
} unicode_to_cid;
|
} unicode_to_cid;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint16 length;
|
uint16 length;
|
||||||
unicode_to_cid *table;
|
unicode_to_cid *table;
|
||||||
} cid_table;
|
} cid_table;
|
||||||
|
|
||||||
#ifdef UNICODE5_FROM
|
#ifdef UNICODE5_FROM
|
||||||
#error check code!
|
# error check code!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ELEMS(v, e) sizeof(v) / sizeof(e)
|
#define ELEMS(v, e) sizeof(v) / sizeof(e)
|
||||||
@@ -81,8 +58,8 @@ typedef struct
|
|||||||
#include "unicode3.h"
|
#include "unicode3.h"
|
||||||
#include "unicode4.h"
|
#include "unicode4.h"
|
||||||
|
|
||||||
static unicode_to_encoding encodings[] =
|
|
||||||
{
|
static unicode_to_encoding encodings[] = {
|
||||||
{UNICODE0_FROM, UNICODE0_TO, ELEMS(unicode0, uint16), unicode0},
|
{UNICODE0_FROM, UNICODE0_TO, ELEMS(unicode0, uint16), unicode0},
|
||||||
{UNICODE1_FROM, UNICODE1_TO, ELEMS(unicode1, uint16), unicode1},
|
{UNICODE1_FROM, UNICODE1_TO, ELEMS(unicode1, uint16), unicode1},
|
||||||
{UNICODE2_FROM, UNICODE2_TO, ELEMS(unicode2, uint16), unicode2},
|
{UNICODE2_FROM, UNICODE2_TO, ELEMS(unicode2, uint16), unicode2},
|
||||||
@@ -97,18 +74,40 @@ static unicode_to_encoding encodings[] =
|
|||||||
#include "korean.h"
|
#include "korean.h"
|
||||||
|
|
||||||
|
|
||||||
static cid_table cid_tables[] =
|
static cid_table cid_tables[] = {
|
||||||
{
|
|
||||||
{ELEMS(japanese, unicode_to_cid), japanese},
|
{ELEMS(japanese, unicode_to_cid), japanese},
|
||||||
{ELEMS(CNS1, unicode_to_cid), CNS1},
|
{ELEMS(CNS1, unicode_to_cid), CNS1},
|
||||||
{ELEMS(GB1, unicode_to_cid), GB1},
|
{ELEMS(GB1, unicode_to_cid), GB1},
|
||||||
{ELEMS(korean, unicode_to_cid), korean}
|
{ELEMS(korean, unicode_to_cid), korean}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char* encoding_names[] = {
|
||||||
|
"macroman",
|
||||||
|
// TrueType
|
||||||
|
"ttenc0",
|
||||||
|
"ttenc1",
|
||||||
|
"ttenc2",
|
||||||
|
"ttenc3",
|
||||||
|
"ttenc4",
|
||||||
|
// Type 1
|
||||||
|
"t1enc0",
|
||||||
|
"t1enc1",
|
||||||
|
"t1enc2",
|
||||||
|
"t1enc3",
|
||||||
|
"t1enc4",
|
||||||
|
// CJK
|
||||||
|
"UniJIS-UCS2-H",
|
||||||
|
"UniCNS-UCS2-H",
|
||||||
|
"UniGB-UCS2-H",
|
||||||
|
"UniKS-UCS2-H"
|
||||||
|
};
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
static bool
|
// #pragma mark -
|
||||||
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < ELEMS(encodings, unicode_to_encoding); i++) {
|
for (unsigned int i = 0; i < ELEMS(encodings, unicode_to_encoding); i++) {
|
||||||
if (encodings[i].from <= unicode && unicode <= encodings[i].to) {
|
if (encodings[i].from <= unicode && unicode <= encodings[i].to) {
|
||||||
@@ -128,15 +127,15 @@ find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
static bool
|
||||||
static bool
|
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index,
|
||||||
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_encoding* order)
|
font_encoding* order)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < ELEMS(cid_tables, cid_table); i++) {
|
for (unsigned int i = 0; i < ELEMS(cid_tables, cid_table); i++) {
|
||||||
encoding = order[i];
|
encoding = order[i];
|
||||||
@@ -161,9 +160,9 @@ find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
|
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index)
|
||||||
|
{
|
||||||
if (fUserDefinedEncodings.Get(unicode, enc, index)) {
|
if (fUserDefinedEncodings.Get(unicode, enc, index)) {
|
||||||
BString s("user");
|
BString s("user");
|
||||||
s << (int)enc;
|
s << (int)enc;
|
||||||
@@ -171,24 +170,25 @@ PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::RecordFont(const char* family, const char* style, float size) {
|
PDFWriter::RecordFont(const char* family, const char* style, float size)
|
||||||
|
{
|
||||||
const int32 n = fUsedFonts.CountItems();
|
const int32 n = fUsedFonts.CountItems();
|
||||||
for (int32 i = 0; i < n; i ++) {
|
for (int32 i = 0; i < n; i ++) {
|
||||||
if (fUsedFonts.ItemAt(i)->Equals(family, style, size)) return;
|
if (fUsedFonts.ItemAt(i)->Equals(family, style, size)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UsedFont* font;
|
UsedFont* font;
|
||||||
font = new UsedFont(family, style, size);
|
font = new UsedFont(family, style, size);
|
||||||
fUsedFonts.AddItem(font);
|
fUsedFonts.AddItem(font);
|
||||||
|
|
||||||
REPORT(kInfo, -1, "Used font: \"%s\" \"%s\" %f", family, style, size);
|
REPORT(kInfo, -1, "Used font: \"%s\" \"%s\" %f", family, style, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::GetFontName(BFont *font, char *fontname)
|
PDFWriter::GetFontName(BFont *font, char *fontname)
|
||||||
{
|
{
|
||||||
font_family family;
|
font_family family;
|
||||||
font_style style;
|
font_style style;
|
||||||
@@ -199,9 +199,10 @@ PDFWriter::GetFontName(BFont *font, char *fontname)
|
|||||||
RecordFont(family, style, font->Size());
|
RecordFont(family, style, font->Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed, font_encoding encoding)
|
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed,
|
||||||
|
font_encoding encoding)
|
||||||
{
|
{
|
||||||
GetFontName(font, fontname);
|
GetFontName(font, fontname);
|
||||||
|
|
||||||
@@ -219,38 +220,15 @@ PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed, font_encoding e
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* encoding_names[] =
|
int
|
||||||
{
|
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
|
||||||
"macroman",
|
|
||||||
// TrueType
|
|
||||||
"ttenc0",
|
|
||||||
"ttenc1",
|
|
||||||
"ttenc2",
|
|
||||||
"ttenc3",
|
|
||||||
"ttenc4",
|
|
||||||
// Type 1
|
|
||||||
"t1enc0",
|
|
||||||
"t1enc1",
|
|
||||||
"t1enc2",
|
|
||||||
"t1enc3",
|
|
||||||
"t1enc4",
|
|
||||||
// CJK
|
|
||||||
"UniJIS-UCS2-H",
|
|
||||||
"UniCNS-UCS2-H",
|
|
||||||
"UniGB-UCS2-H",
|
|
||||||
"UniKS-UCS2-H"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
int
|
|
||||||
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
|
|
||||||
{
|
{
|
||||||
static Font* cache = NULL;
|
static Font* cache = NULL;
|
||||||
if (cache && cache->encoding == encoding && strcmp(cache->name.String(), fontName) == 0)
|
if (cache && cache->encoding == encoding
|
||||||
|
&& strcmp(cache->name.String(), fontName) == 0)
|
||||||
return cache->font;
|
return cache->font;
|
||||||
|
|
||||||
REPORT(kDebug, fPage, "FindFont %s", fontName);
|
REPORT(kDebug, fPage, "FindFont %s", fontName);
|
||||||
Font *f = NULL;
|
Font *f = NULL;
|
||||||
const int n = fFontCache.CountItems();
|
const int n = fFontCache.CountItems();
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@@ -260,33 +238,34 @@ PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
|
|||||||
return f->font;
|
return f->font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embed) embed = EmbedFont(fontName);
|
if (embed) embed = EmbedFont(fontName);
|
||||||
|
|
||||||
BString s;
|
BString s;
|
||||||
const char* encoding_name;
|
const char* encoding_name;
|
||||||
if (encoding < user_defined_encoding_start) {
|
if (encoding < user_defined_encoding_start) {
|
||||||
encoding_name = encoding_names[encoding];
|
encoding_name = encoding_names[encoding];
|
||||||
} else {
|
} else {
|
||||||
s = "user";
|
s = "user";
|
||||||
s << (int)(encoding - user_defined_encoding_start);
|
s << (int)(encoding - user_defined_encoding_start);
|
||||||
encoding_name = s.String();
|
encoding_name = s.String();
|
||||||
}
|
}
|
||||||
REPORT(kDebug, fPage, "Create new font, %sembed, encoding %s", embed ? "" : "do not ", encoding_name);
|
REPORT(kDebug, fPage, "Create new font, %sembed, encoding %s",
|
||||||
|
embed ? "" : "do not ", encoding_name);
|
||||||
int font = PDF_findfont(fPdf, fontName, encoding_name, embed);
|
int font = PDF_findfont(fPdf, fontName, encoding_name, embed);
|
||||||
if (font != -1) {
|
if (font != -1) {
|
||||||
REPORT(kDebug, fPage, "font created");
|
REPORT(kDebug, fPage, "font created");
|
||||||
cache = new Font(fontName, font, encoding);
|
cache = new Font(fontName, font, encoding);
|
||||||
fFontCache.AddItem(cache);
|
fFontCache.AddItem(cache);
|
||||||
} else {
|
} else {
|
||||||
REPORT(kError, fPage, "Could not create font '%s': %s", fontName, PDF_get_errmsg(fPdf));
|
REPORT(kError, fPage, "Could not create font '%s': %s", fontName,
|
||||||
|
PDF_get_errmsg(fPdf));
|
||||||
}
|
}
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
void
|
||||||
void
|
|
||||||
PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
|
PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
|
||||||
{
|
{
|
||||||
int32 len = strlen(string);
|
int32 len = strlen(string);
|
||||||
@@ -296,19 +275,19 @@ PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
|
|||||||
int32 srcStart = 0;
|
int32 srcStart = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen, &state);
|
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen,
|
||||||
|
&state);
|
||||||
srcStart += srcLen;
|
srcStart += srcLen;
|
||||||
len -= srcLen;
|
len -= srcLen;
|
||||||
srcLen = len;
|
srcLen = len;
|
||||||
|
|
||||||
utf8.Append(buffer, destLen);
|
utf8.Append(buffer, destLen);
|
||||||
destLen = 255;
|
destLen = 255;
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
void
|
||||||
void
|
|
||||||
PDFWriter::ToUnicode(const char *string, BString &unicode)
|
PDFWriter::ToUnicode(const char *string, BString &unicode)
|
||||||
{
|
{
|
||||||
int32 len = strlen(string);
|
int32 len = strlen(string);
|
||||||
@@ -318,87 +297,90 @@ PDFWriter::ToUnicode(const char *string, BString &unicode)
|
|||||||
int32 srcStart = 0;
|
int32 srcStart = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
unicode = "";
|
unicode = "";
|
||||||
if (len == 0) return;
|
if (len == 0) return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen, buffer, &destLen, &state);
|
convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen,
|
||||||
|
buffer, &destLen, &state);
|
||||||
srcStart += srcLen;
|
srcStart += srcLen;
|
||||||
len -= srcLen;
|
len -= srcLen;
|
||||||
srcLen = len;
|
srcLen = len;
|
||||||
|
|
||||||
char *b = unicode.LockBuffer(i + destLen);
|
char *b = unicode.LockBuffer(i + destLen);
|
||||||
memcpy(&b[i], buffer, destLen);
|
memcpy(&b[i], buffer, destLen);
|
||||||
unicode.UnlockBuffer(i + destLen);
|
unicode.UnlockBuffer(i + destLen);
|
||||||
i += destLen;
|
i += destLen;
|
||||||
destLen = 255;
|
destLen = 255;
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
void
|
||||||
void
|
|
||||||
PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
|
PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
|
||||||
{
|
{
|
||||||
// PDFlib requires BOM at begin and two 0 at end of string
|
// PDFlib requires BOM at begin and two 0 at end of string
|
||||||
char marker[3] = { 0xfe, 0xff, 0}; // byte order marker
|
char marker[3] = { 0xfe, 0xff, 0}; // byte order marker
|
||||||
BString s;
|
BString s;
|
||||||
ToUnicode(string, s);
|
ToUnicode(string, s);
|
||||||
unicode << marker;
|
unicode << marker;
|
||||||
int32 len = s.Length()+2;
|
int32 len = s.Length()+2;
|
||||||
char* buf = unicode.LockBuffer(len + 2); // reserve space for two additional '\0'
|
char* buf = unicode.LockBuffer(len + 2);
|
||||||
|
// reserve space for two additional '\0'
|
||||||
memcpy(&buf[2], s.String(), s.Length());
|
memcpy(&buf[2], s.String(), s.Length());
|
||||||
buf[len] = buf[len+1] = 0;
|
buf[len] = buf[len+1] = 0;
|
||||||
unicode.UnlockBuffer(len + 2);
|
unicode.UnlockBuffer(len + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
uint16
|
||||||
uint16
|
|
||||||
PDFWriter::CodePointSize(const char* s)
|
PDFWriter::CodePointSize(const char* s)
|
||||||
{
|
{
|
||||||
uint16 i = 1;
|
uint16 i = 1;
|
||||||
for (s++; !BeginsChar(*s); s++) i++;
|
for (s++; !BeginsChar(*s); s++) i++;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PDFWriter::RecordDests(const char* s) {
|
void
|
||||||
|
PDFWriter::RecordDests(const char* s)
|
||||||
|
{
|
||||||
::RecordDests record(fXRefDests, &fTextLine, fPage);
|
::RecordDests record(fXRefDests, &fTextLine, fPage);
|
||||||
fXRefs->Matches(s, &record, true);
|
fXRefs->Matches(s, &record, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
||||||
{
|
{
|
||||||
// try to convert from utf8 to MacRoman encoding schema...
|
// try to convert from utf8 to MacRoman encoding schema...
|
||||||
int32 srcLen = size;
|
int32 srcLen = size;
|
||||||
int32 destLen = 1;
|
int32 destLen = 1;
|
||||||
char dest[3] = "\0\0";
|
char dest[3] = "\0\0";
|
||||||
int32 state = 0;
|
int32 state = 0;
|
||||||
bool embed = true;
|
bool embed = true;
|
||||||
font_encoding encoding = macroman_encoding;
|
font_encoding encoding = macroman_encoding;
|
||||||
char fontName[B_FONT_FAMILY_LENGTH+B_FONT_STYLE_LENGTH+1];
|
char fontName[B_FONT_FAMILY_LENGTH+B_FONT_STYLE_LENGTH+1];
|
||||||
|
|
||||||
if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, utf8, &srcLen, dest, &destLen, &state, 0) != B_OK || dest[0] == 0 ) {
|
if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, utf8, &srcLen, dest, &destLen,
|
||||||
|
&state, 0) != B_OK || dest[0] == 0) {
|
||||||
// could not convert to MacRoman
|
// could not convert to MacRoman
|
||||||
uint8 enc;
|
|
||||||
uint16 index = 0;
|
|
||||||
font_encoding fenc;
|
font_encoding fenc;
|
||||||
|
uint16 index = 0;
|
||||||
|
uint8 enc;
|
||||||
|
|
||||||
GetFontName(&fState->beFont, fontName);
|
GetFontName(&fState->beFont, fontName);
|
||||||
embed = EmbedFont(fontName);
|
embed = EmbedFont(fontName);
|
||||||
|
|
||||||
REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode);
|
REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode);
|
||||||
if (find_encoding(unicode, enc, index)) {
|
if (find_encoding(unicode, enc, index)) {
|
||||||
// is code point in the Adobe Glyph List?
|
// is code point in the Adobe Glyph List?
|
||||||
// Note if rendering the glyphs only would be desired, we could always use
|
// Note if rendering the glyphs only would be desired, we could
|
||||||
// the second method below (MakeUserDefinedEncoding), but extracting text
|
// always use the second method below (MakeUserDefinedEncoding),
|
||||||
// from the generated PDF would be almost impossible (OCR!)
|
// but extracting text from the generated PDF would be almost
|
||||||
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc, (int)index);
|
// impossible (OCR!)
|
||||||
|
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc,
|
||||||
|
(int)index);
|
||||||
// use one of the user pre-defined encodings
|
// use one of the user pre-defined encodings
|
||||||
if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
|
if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
|
||||||
encoding = font_encoding(enc + tt_encoding0);
|
encoding = font_encoding(enc + tt_encoding0);
|
||||||
@@ -415,8 +397,8 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
|||||||
} else if (find_in_cid_tables(unicode, fenc, index, fFontSearchOrder)) {
|
} else if (find_in_cid_tables(unicode, fenc, index, fFontSearchOrder)) {
|
||||||
// font is not embedded use one of the CJK fonts for substitution
|
// font is not embedded use one of the CJK fonts for substitution
|
||||||
REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index);
|
REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index);
|
||||||
dest[0] = unicode / 256;
|
dest[0] = unicode / 256;
|
||||||
dest[1] = unicode % 256;
|
dest[1] = unicode % 256;
|
||||||
destLen = 2;
|
destLen = 2;
|
||||||
encoding = fenc;
|
encoding = fenc;
|
||||||
embed = false;
|
embed = false;
|
||||||
@@ -425,33 +407,40 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
|||||||
REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode);
|
REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
found = true;
|
found = true;
|
||||||
REPORT(kError, fPage, "Could not find an encoding for character with unicode %d! Message is not repeated for other unicode values.", (int)unicode);
|
REPORT(kError, fPage, "Could not find an encoding for character "
|
||||||
|
"with unicode %d! Message is not repeated for other unicode "
|
||||||
|
"values.", (int)unicode);
|
||||||
}
|
}
|
||||||
*dest = 0; // paint a box (is 0 a box in MacRoman) or
|
*dest = 0; // paint a box (is 0 a box in MacRoman) or
|
||||||
return; // simply skip character
|
return; // simply skip character
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen, destLen, (int)dest[0], (int)dest[1]);
|
REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen,
|
||||||
|
destLen, (int)dest[0], (int)dest[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note we have to build the user defined encoding before it is used in PDF_find_font!
|
// Note we have to build the user defined encoding before it is used in
|
||||||
|
// PDF_find_font!
|
||||||
if (!MakesPDF()) return;
|
if (!MakesPDF()) return;
|
||||||
|
|
||||||
int font;
|
int font;
|
||||||
|
|
||||||
GetFontName(&fState->beFont, fontName, embed, encoding);
|
GetFontName(&fState->beFont, fontName, embed, encoding);
|
||||||
font = FindFont(fontName, embed, encoding);
|
font = FindFont(fontName, embed, encoding);
|
||||||
if (font < 0) {
|
if (font < 0) {
|
||||||
REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default font", fontName);
|
REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default "
|
||||||
|
"font", fontName);
|
||||||
font = PDF_findfont(fPdf, "Helvetica", "macroman", 0);
|
font = PDF_findfont(fPdf, "Helvetica", "macroman", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fState->font = font;
|
fState->font = font;
|
||||||
|
|
||||||
uint16 face = fState->beFont.Face();
|
uint16 face = fState->beFont.Face();
|
||||||
PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0 ? "true" : "false");
|
PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0
|
||||||
PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0 ? "true" : "false");
|
? "true" : "false");
|
||||||
PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0);
|
PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0
|
||||||
|
? "true" : "false");
|
||||||
|
PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0);
|
||||||
|
|
||||||
PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size()));
|
PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size()));
|
||||||
|
|
||||||
@@ -465,7 +454,7 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
|||||||
PDF_translate(fPdf, x, y);
|
PDF_translate(fPdf, x, y);
|
||||||
PDF_rotate(fPdf, rotation);
|
PDF_rotate(fPdf, rotation);
|
||||||
PDF_set_text_pos(fPdf, 0, 0);
|
PDF_set_text_pos(fPdf, 0, 0);
|
||||||
} else
|
} else
|
||||||
PDF_set_text_pos(fPdf, x, y);
|
PDF_set_text_pos(fPdf, x, y);
|
||||||
|
|
||||||
PDF_show2(fPdf, dest, destLen);
|
PDF_show2(fPdf, dest, destLen);
|
||||||
@@ -476,9 +465,9 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 size, float width)
|
PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8,
|
||||||
|
int16 size, float width)
|
||||||
{
|
{
|
||||||
BShape glyph;
|
BShape glyph;
|
||||||
bool hasGlyph[1];
|
bool hasGlyph[1];
|
||||||
@@ -506,12 +495,12 @@ PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 si
|
|||||||
glyph.LineTo(BPoint(o.right, o.bottom));
|
glyph.LineTo(BPoint(o.right, o.bottom));
|
||||||
glyph.LineTo(BPoint(o.left, o.bottom));
|
glyph.LineTo(BPoint(o.left, o.bottom));
|
||||||
glyph.Close();
|
glyph.Close();
|
||||||
|
|
||||||
glyph.MoveTo(BPoint(i.left, i.top));
|
glyph.MoveTo(BPoint(i.left, i.top));
|
||||||
glyph.LineTo(BPoint(i.left, i.bottom));
|
glyph.LineTo(BPoint(i.left, i.bottom));
|
||||||
glyph.LineTo(BPoint(i.right, i.bottom));
|
glyph.LineTo(BPoint(i.right, i.bottom));
|
||||||
glyph.LineTo(BPoint(i.right, i.top));
|
glyph.LineTo(BPoint(i.right, i.top));
|
||||||
glyph.Close();
|
glyph.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
BPoint p(fState->penX, fState->penY);
|
BPoint p(fState->penX, fState->penY);
|
||||||
@@ -523,12 +512,14 @@ PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 si
|
|||||||
PopInternalState();
|
PopInternalState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
void
|
void
|
||||||
PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_space)
|
PDFWriter::DrawString(char *string, float escapementNoSpace,
|
||||||
|
float escapementSpace)
|
||||||
{
|
{
|
||||||
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapement_nospace=%f, escapement_space=%f, at %f, %f", \
|
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, "
|
||||||
string, escapement_nospace, escapement_space, fState->penX, fState->penY);
|
"escapementSpace=%f, at %f, %f", string, escapementNoSpace,
|
||||||
|
escapementSpace, fState->penX, fState->penY);
|
||||||
|
|
||||||
if (IsDrawing()) {
|
if (IsDrawing()) {
|
||||||
// text color is always the high color and not the pattern!
|
// text color is always the high color and not the pattern!
|
||||||
@@ -541,14 +532,14 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
|
|||||||
} else {
|
} else {
|
||||||
ToUtf8(fState->beFont.Encoding()-1, string, utf8);
|
ToUtf8(fState->beFont.Encoding()-1, string, utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert string in UTF8 to unicode UCS2
|
// convert string in UTF8 to unicode UCS2
|
||||||
BString unicode;
|
BString unicode;
|
||||||
ToUnicode(utf8.String(), unicode);
|
ToUnicode(utf8.String(), unicode);
|
||||||
// need font object to calculate width of utf8 code point
|
// need font object to calculate width of utf8 code point
|
||||||
BFont font = fState->beFont;
|
BFont font = fState->beFont;
|
||||||
font.SetEncoding(B_UNICODE_UTF8);
|
font.SetEncoding(B_UNICODE_UTF8);
|
||||||
// constants to calculate position of next character
|
// constants to calculate position of next character
|
||||||
const double rotation = DEGREE2RAD(fState->beFont.Rotation());
|
const double rotation = DEGREE2RAD(fState->beFont.Rotation());
|
||||||
const bool rotate = rotation != 0.0;
|
const bool rotate = rotation != 0.0;
|
||||||
const double cos1 = rotate ? cos(rotation) : 1;
|
const double cos1 = rotate ? cos(rotation) : 1;
|
||||||
@@ -569,14 +560,14 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
|
|||||||
if (MakesPDF() && IsClipping()) {
|
if (MakesPDF() && IsClipping()) {
|
||||||
ClipChar(&font, (char*)u, c, s, w);
|
ClipChar(&font, (char*)u, c, s, w);
|
||||||
} else {
|
} else {
|
||||||
DrawChar(u[0]*256+u[1], c, s);
|
DrawChar(u[0]*256+u[1], c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// position of next character
|
// position of next character
|
||||||
if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space!
|
if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space!
|
||||||
w += escapement_space;
|
w += escapementSpace;
|
||||||
} else {
|
} else {
|
||||||
w += escapement_nospace;
|
w += escapementNoSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
fState->penX += w * cos1;
|
fState->penX += w * cos1;
|
||||||
@@ -588,36 +579,30 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
|
|||||||
EndTransparency();
|
EndTransparency();
|
||||||
|
|
||||||
// text line processing (for non rotated text only!)
|
// text line processing (for non rotated text only!)
|
||||||
BPoint end(fState->penX, fState->penY);
|
BPoint end(fState->penX, fState->penY);
|
||||||
BRect bounds;
|
BRect bounds;
|
||||||
font_height height;
|
font_height height;
|
||||||
|
|
||||||
font.GetHeight(&height);
|
font.GetHeight(&height);
|
||||||
|
|
||||||
bounds.left = start.x;
|
bounds.left = start.x;
|
||||||
bounds.right = end.x;
|
bounds.right = end.x;
|
||||||
bounds.top = start.y - height.ascent;
|
bounds.top = start.y - height.ascent;
|
||||||
bounds.bottom = end.y + height.descent;
|
bounds.bottom = end.y + height.descent;
|
||||||
|
|
||||||
TextSegment* segment = new TextSegment(
|
TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace,
|
||||||
utf8.String(), start,
|
escapementNoSpace, &bounds, &font, pdfSystem());
|
||||||
escapement_space, escapement_nospace,
|
|
||||||
&bounds, &font, pdfSystem());
|
|
||||||
|
|
||||||
fTextLine.Add(segment);
|
fTextLine.Add(segment);
|
||||||
|
|
||||||
if (IsDrawing()) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
bool
|
bool
|
||||||
PDFWriter::EmbedFont(const char* name)
|
PDFWriter::EmbedFont(const char* name)
|
||||||
{
|
{
|
||||||
static FontFile* cache = NULL;
|
static FontFile* cache = NULL;
|
||||||
if (cache && strcmp(cache->Name(), name) == 0) return cache->Embed();
|
if (cache && strcmp(cache->Name(), name) == 0) return cache->Embed();
|
||||||
|
|
||||||
const int n = fFonts->Length();
|
const int n = fFonts->Length();
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
FontFile* f = fFonts->At(i);
|
FontFile* f = fFonts->At(i);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
|
||||||
PDF Writer printer driver.
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
Copyright (c) 2001 OpenBeOS.
|
* Authors:
|
||||||
|
* Philippe Houdoin
|
||||||
Authors:
|
* Simon Gauvin
|
||||||
Philippe Houdoin
|
* Michael Pfeiffer
|
||||||
Simon Gauvin
|
*/
|
||||||
Michael Pfeiffer
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PDFWRITER_H
|
#ifndef PDFWRITER_H
|
||||||
#define PDFWRITER_H
|
#define PDFWRITER_H
|
||||||
|
|
||||||
@@ -37,7 +15,7 @@ THE SOFTWARE.
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
#include "math.h"
|
#include <math.h>
|
||||||
|
|
||||||
#include "PrinterDriver.h"
|
#include "PrinterDriver.h"
|
||||||
#include "PictureIterator.h"
|
#include "PictureIterator.h"
|
||||||
@@ -52,8 +30,8 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#define USE_IMAGE_CACHE 1
|
#define USE_IMAGE_CACHE 1
|
||||||
|
|
||||||
#define RAD2DEGREE(r) (180.0 * r / PI)
|
#define RAD2DEGREE(r) (180.0 * r / M_PI)
|
||||||
#define DEGREE2RAD(d) (PI * d / 180.0)
|
#define DEGREE2RAD(d) (M_PI * d / 180.0)
|
||||||
|
|
||||||
class DrawShape;
|
class DrawShape;
|
||||||
class WebLink;
|
class WebLink;
|
||||||
@@ -61,9 +39,7 @@ class Bookmark;
|
|||||||
class XRefDefs;
|
class XRefDefs;
|
||||||
class XRefDests;
|
class XRefDests;
|
||||||
|
|
||||||
class PDFWriter : public PrinterDriver, public PictureIterator
|
class PDFWriter : public PrinterDriver, public PictureIterator {
|
||||||
{
|
|
||||||
|
|
||||||
friend class DrawShape;
|
friend class DrawShape;
|
||||||
friend class PDFLinePathBuilder;
|
friend class PDFLinePathBuilder;
|
||||||
friend class WebLink;
|
friend class WebLink;
|
||||||
@@ -71,12 +47,12 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
friend class Bookmark;
|
friend class Bookmark;
|
||||||
friend class LocalLink;
|
friend class LocalLink;
|
||||||
friend class TextLine;
|
friend class TextLine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructors / destructor
|
// constructors / destructor
|
||||||
PDFWriter();
|
PDFWriter();
|
||||||
~PDFWriter();
|
~PDFWriter();
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
status_t BeginJob();
|
status_t BeginJob();
|
||||||
status_t PrintPage(int32 pageNumber, int32 pageCount);
|
status_t PrintPage(int32 pageNumber, int32 pageCount);
|
||||||
@@ -89,11 +65,11 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
bool LoadBookmarkDefinitions(const char* name);
|
bool LoadBookmarkDefinitions(const char* name);
|
||||||
bool LoadXRefsDefinitions(const char* name);
|
bool LoadXRefsDefinitions(const char* name);
|
||||||
void RecordDests(const char* s);
|
void RecordDests(const char* s);
|
||||||
|
|
||||||
// PDFLib callbacks
|
// PDFLib callbacks
|
||||||
size_t WriteData(void *data, size_t size);
|
size_t WriteData(void *data, size_t size);
|
||||||
void ErrorHandler(int type, const char *msg);
|
void ErrorHandler(int type, const char *msg);
|
||||||
|
|
||||||
// Image support
|
// Image support
|
||||||
int32 BytesPerPixel(int32 pixelFormat);
|
int32 BytesPerPixel(int32 pixelFormat);
|
||||||
|
|
||||||
@@ -198,19 +174,19 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
void SetFontFlags(int32 flags);
|
void SetFontFlags(int32 flags);
|
||||||
void SetFontShear(float shear);
|
void SetFontShear(float shear);
|
||||||
void SetFontFace(int32 flags);
|
void SetFontFace(int32 flags);
|
||||||
|
|
||||||
static inline bool IsSame(const pattern &p1, const pattern &p2);
|
static inline bool IsSame(const pattern &p1, const pattern &p2);
|
||||||
static inline bool IsSame(const rgb_color &c1, const rgb_color &c2);
|
static inline bool IsSame(const rgb_color &c1, const rgb_color &c2);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum PDFVersion {
|
enum PDFVersion {
|
||||||
kPDF13,
|
kPDF13,
|
||||||
kPDF14,
|
kPDF14,
|
||||||
kPDF15
|
kPDF15
|
||||||
};
|
};
|
||||||
|
|
||||||
class State
|
class State
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
State *prev;
|
State *prev;
|
||||||
@@ -229,9 +205,9 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
float penSize;
|
float penSize;
|
||||||
pattern pattern0;
|
pattern pattern0;
|
||||||
int32 fontSpacing;
|
int32 fontSpacing;
|
||||||
|
|
||||||
// initialize with defalt values
|
// initialize with defalt values
|
||||||
State(float h = a4_height, float x = 0, float y = 0)
|
State(float h = a4_height, float x = 0, float y = 0)
|
||||||
{
|
{
|
||||||
static rgb_color white = {255, 255, 255, 255};
|
static rgb_color white = {255, 255, 255, 255};
|
||||||
static rgb_color black = {0, 0, 0, 255};
|
static rgb_color black = {0, 0, 0, 255};
|
||||||
@@ -241,26 +217,26 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
pdfSystem.SetOrigin(x, y);
|
pdfSystem.SetOrigin(x, y);
|
||||||
penX = 0;
|
penX = 0;
|
||||||
penY = 0;
|
penY = 0;
|
||||||
drawingMode = B_OP_COPY;
|
drawingMode = B_OP_COPY;
|
||||||
foregroundColor = white;
|
foregroundColor = white;
|
||||||
backgroundColor = black;
|
backgroundColor = black;
|
||||||
currentColor = black;
|
currentColor = black;
|
||||||
capMode = B_BUTT_CAP;
|
capMode = B_BUTT_CAP;
|
||||||
joinMode = B_MITER_JOIN;
|
joinMode = B_MITER_JOIN;
|
||||||
miterLimit = B_DEFAULT_MITER_LIMIT;
|
miterLimit = B_DEFAULT_MITER_LIMIT;
|
||||||
penSize = 1;
|
penSize = 1;
|
||||||
pattern0 = B_SOLID_HIGH;
|
pattern0 = B_SOLID_HIGH;
|
||||||
fontSpacing = B_STRING_SPACING;
|
fontSpacing = B_STRING_SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
State(State *prev)
|
State(State *prev)
|
||||||
{
|
{
|
||||||
*this = *prev;
|
*this = *prev;
|
||||||
this->prev = prev;
|
this->prev = prev;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Font
|
class Font
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Font(char *n, int f, font_encoding e) : name(n), font(f), encoding(e) { }
|
Font(char *n, int f, font_encoding e) : name(n), font(f), encoding(e) { }
|
||||||
@@ -275,14 +251,14 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
pattern pat;
|
pattern pat;
|
||||||
rgb_color lowColor, highColor;
|
rgb_color lowColor, highColor;
|
||||||
int patternId;
|
int patternId;
|
||||||
|
|
||||||
Pattern(const pattern &p, rgb_color low, rgb_color high, int id)
|
Pattern(const pattern &p, rgb_color low, rgb_color high, int id)
|
||||||
: pat(p)
|
: pat(p)
|
||||||
, lowColor(low)
|
, lowColor(low)
|
||||||
, highColor(high)
|
, highColor(high)
|
||||||
, patternId(id)
|
, patternId(id)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
inline bool Matches(const pattern &p, rgb_color low, rgb_color high) const {
|
inline bool Matches(const pattern &p, rgb_color low, rgb_color high) const {
|
||||||
return IsSame(pat, p) && IsSame(lowColor, low) && IsSame(highColor, high);
|
return IsSame(pat, p) && IsSame(lowColor, low) && IsSame(highColor, high);
|
||||||
};
|
};
|
||||||
@@ -292,19 +268,19 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
{
|
{
|
||||||
uint8 alpha;
|
uint8 alpha;
|
||||||
int handle;
|
int handle;
|
||||||
public:
|
public:
|
||||||
Transparency(uint8 alpha, int handle)
|
Transparency(uint8 alpha, int handle)
|
||||||
: alpha(alpha)
|
: alpha(alpha)
|
||||||
, handle(handle)
|
, handle(handle)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
inline bool Matches(uint8 alpha) const {
|
inline bool Matches(uint8 alpha) const {
|
||||||
return this->alpha == alpha;
|
return this->alpha == alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int Handle() const { return handle; }
|
inline int Handle() const { return handle; }
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFVersion fPDFVersion;
|
PDFVersion fPDFVersion;
|
||||||
FILE *fLog;
|
FILE *fLog;
|
||||||
PDF *fPdf;
|
PDF *fPdf;
|
||||||
@@ -329,8 +305,8 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
TextLine fTextLine;
|
TextLine fTextLine;
|
||||||
TList<UsedFont> fUsedFonts;
|
TList<UsedFont> fUsedFonts;
|
||||||
UserDefinedEncodings fUserDefinedEncodings;
|
UserDefinedEncodings fUserDefinedEncodings;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kDrawingMode,
|
kDrawingMode,
|
||||||
kClippingMode
|
kClippingMode
|
||||||
@@ -362,7 +338,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
inline cap_mode LineCapMode() const { return fState->capMode; }
|
inline cap_mode LineCapMode() const { return fState->capMode; }
|
||||||
inline join_mode LineJoinMode() const { return fState->joinMode; }
|
inline join_mode LineJoinMode() const { return fState->joinMode; }
|
||||||
inline float LineMiterLimit() const { return fState->miterLimit; }
|
inline float LineMiterLimit() const { return fState->miterLimit; }
|
||||||
|
|
||||||
bool StoreTranslatorBitmap(BBitmap *bitmap, const char *filename, uint32 type);
|
bool StoreTranslatorBitmap(BBitmap *bitmap, const char *filename, uint32 type);
|
||||||
|
|
||||||
void GetFontName(BFont *font, char *fontname);
|
void GetFontName(BFont *font, char *fontname);
|
||||||
@@ -383,7 +359,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
void CreatePattern();
|
void CreatePattern();
|
||||||
int FindPattern();
|
int FindPattern();
|
||||||
void SetPattern();
|
void SetPattern();
|
||||||
|
|
||||||
void StrokeOrClip();
|
void StrokeOrClip();
|
||||||
void FillOrClip();
|
void FillOrClip();
|
||||||
void Paint(bool stroke);
|
void Paint(bool stroke);
|
||||||
@@ -394,9 +370,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
// --------------------------------------------------
|
|
||||||
inline bool
|
|
||||||
PDFWriter::IsSame(const pattern &p1, const pattern &p2)
|
PDFWriter::IsSame(const pattern &p1, const pattern &p2)
|
||||||
{
|
{
|
||||||
char *a = (char*)p1.data;
|
char *a = (char*)p1.data;
|
||||||
@@ -405,8 +379,7 @@ PDFWriter::IsSame(const pattern &p1, const pattern &p2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
inline bool
|
||||||
inline bool
|
|
||||||
PDFWriter::IsSame(const rgb_color &c1, const rgb_color &c2)
|
PDFWriter::IsSame(const rgb_color &c1, const rgb_color &c2)
|
||||||
{
|
{
|
||||||
char *a = (char*)&c1;
|
char *a = (char*)&c1;
|
||||||
@@ -419,4 +392,4 @@ PDFWriter::IsSame(const rgb_color &c1, const rgb_color &c2)
|
|||||||
size_t _WriteData(PDF *p, void *data, size_t size);
|
size_t _WriteData(PDF *p, void *data, size_t size);
|
||||||
void _ErrorHandler(PDF *p, int type, const char *msg);
|
void _ErrorHandler(PDF *p, int type, const char *msg);
|
||||||
|
|
||||||
#endif // #if PDFWRITER_H
|
#endif // PDFWRITER_H
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -8,17 +8,18 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "FontDemoView.h"
|
#include "FontDemoView.h"
|
||||||
#include "messages.h"
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include "messages.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
FontDemoView::FontDemoView(BRect rect)
|
FontDemoView::FontDemoView(BRect rect)
|
||||||
@@ -54,7 +55,8 @@ FontDemoView::~FontDemoView()
|
|||||||
void
|
void
|
||||||
FontDemoView::FrameResized(float width, float height)
|
FontDemoView::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
// TODO: We shouldnt invalidate the whole view when bounding boxes are working as wanted
|
// TODO: We shouldnt invalidate the whole view when bounding boxes are
|
||||||
|
// working as wanted
|
||||||
Invalidate(/*fBoxRegion.Frame()*/);
|
Invalidate(/*fBoxRegion.Frame()*/);
|
||||||
BView::FrameResized(width, height);
|
BView::FrameResized(width, height);
|
||||||
}
|
}
|
||||||
@@ -78,9 +80,9 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
{
|
{
|
||||||
if (!view)
|
if (!view)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
view->SetDrawingMode(B_OP_COPY);
|
view->SetDrawingMode(B_OP_COPY);
|
||||||
|
|
||||||
|
|
||||||
BRect rect = view->Bounds();
|
BRect rect = view->Bounds();
|
||||||
view->SetHighColor(255, 255, 255);
|
view->SetHighColor(255, 255, 255);
|
||||||
@@ -114,18 +116,18 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
font_height fh;
|
font_height fh;
|
||||||
fFont.GetHeight(&fh);
|
fFont.GetHeight(&fh);
|
||||||
|
|
||||||
float xCoordArray[size];
|
float xCoordArray[size];
|
||||||
float yCoordArray[size];
|
float yCoordArray[size];
|
||||||
|
|
||||||
float yCoord = (rect.Height() + fh.ascent - fh.descent) / 2;
|
float yCoord = (rect.Height() + fh.ascent - fh.descent) / 2;
|
||||||
float xCoord = -rect.Width() / 2;
|
float xCoord = -rect.Width() / 2;
|
||||||
const float xCenter = xCoord * -1;
|
const float xCenter = xCoord * -1;
|
||||||
const float r = Rotation() * (PI/180.0);
|
const float r = Rotation() * (M_PI / 180.0);
|
||||||
const float cosinus = cos(r);
|
const float cosinus = cos(r);
|
||||||
const float sinus = -sin(r);
|
const float sinus = -sin(r);
|
||||||
|
|
||||||
// When the bounding boxes workes properly we will invalidate only the
|
// When the bounding boxes workes properly we will invalidate only the
|
||||||
// region area instead of the whole view.
|
// region area instead of the whole view.
|
||||||
|
|
||||||
fBoxRegion.MakeEmpty();
|
fBoxRegion.MakeEmpty();
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ FontDemoView::_DrawView(BView* view)
|
|||||||
|
|
||||||
yCoordArray[i] = sinus * (xCoord - xCoordArray[i]);
|
yCoordArray[i] = sinus * (xCoord - xCoordArray[i]);
|
||||||
xCoordArray[i] = cosinus * xCoord;
|
xCoordArray[i] = cosinus * xCoord;
|
||||||
|
|
||||||
xCoordArray[i] += xCenter;
|
xCoordArray[i] += xCenter;
|
||||||
yCoordArray[i] += yCoord;
|
yCoordArray[i] += yCoord;
|
||||||
|
|
||||||
@@ -234,7 +236,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
case FONTSHEAR_MSG:
|
case FONTSHEAR_MSG:
|
||||||
{
|
{
|
||||||
float shear = 90.0;
|
float shear = 90.0;
|
||||||
if (msg->FindFloat("_shear", &shear) == B_OK) {
|
if (msg->FindFloat("_shear", &shear) == B_OK) {
|
||||||
SetFontShear(shear);
|
SetFontShear(shear);
|
||||||
Invalidate(/*&fBoxRegion*/);
|
Invalidate(/*&fBoxRegion*/);
|
||||||
@@ -244,7 +246,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
case ROTATION_MSG:
|
case ROTATION_MSG:
|
||||||
{
|
{
|
||||||
float rotation = 0.0;
|
float rotation = 0.0;
|
||||||
if (msg->FindFloat("_rotation", &rotation) == B_OK) {
|
if (msg->FindFloat("_rotation", &rotation) == B_OK) {
|
||||||
SetFontRotation(rotation);
|
SetFontRotation(rotation);
|
||||||
Invalidate(/*&fBoxRegion*/);
|
Invalidate(/*&fBoxRegion*/);
|
||||||
@@ -254,7 +256,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
case SPACING_MSG:
|
case SPACING_MSG:
|
||||||
{
|
{
|
||||||
float space = 0.0;
|
float space = 0.0;
|
||||||
if (msg->FindFloat("_spacing", &space) == B_OK) {
|
if (msg->FindFloat("_spacing", &space) == B_OK) {
|
||||||
SetSpacing(space);
|
SetSpacing(space);
|
||||||
Invalidate(/*&fBoxRegion*/);
|
Invalidate(/*&fBoxRegion*/);
|
||||||
@@ -264,13 +266,13 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
case OUTLINE_MSG:
|
case OUTLINE_MSG:
|
||||||
{
|
{
|
||||||
int8 outline = 0;
|
int8 outline = 0;
|
||||||
if (msg->FindInt8("_outline", &outline) == B_OK) {
|
if (msg->FindInt8("_outline", &outline) == B_OK) {
|
||||||
SetOutlineLevel(outline);
|
SetOutlineLevel(outline);
|
||||||
Invalidate(/*&fBoxRegion*/);
|
Invalidate(/*&fBoxRegion*/);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ALIASING_MSG:
|
case ALIASING_MSG:
|
||||||
{
|
{
|
||||||
@@ -281,7 +283,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case DRAWINGMODE_CHANGED_MSG:
|
case DRAWINGMODE_CHANGED_MSG:
|
||||||
{
|
{
|
||||||
if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) {
|
if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) {
|
||||||
@@ -289,7 +291,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BOUNDING_BOX_MSG:
|
case BOUNDING_BOX_MSG:
|
||||||
{
|
{
|
||||||
bool boundingbox = false;
|
bool boundingbox = false;
|
||||||
@@ -299,7 +301,7 @@ FontDemoView::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -16,17 +16,18 @@
|
|||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
// point_line_distance
|
// point_line_distance
|
||||||
double
|
double
|
||||||
point_line_distance(double x1, double y1,
|
point_line_distance(double x1, double y1, double x2, double y2, double x,
|
||||||
double x2, double y2,
|
double y)
|
||||||
double x, double y)
|
|
||||||
{
|
{
|
||||||
double dx = x2 - x1;
|
double dx = x2 - x1;
|
||||||
double dy = y2 - y1;
|
double dy = y2 - y1;
|
||||||
return ((x - x2) * dy - (y - y2) * dx) / sqrt(dx * dx + dy * dy);
|
return ((x - x2) * dy - (y - y2) * dx) / sqrt(dx * dx + dy * dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// point_line_distance
|
// point_line_distance
|
||||||
double
|
double
|
||||||
point_line_distance(BPoint point, BPoint pa, BPoint pb)
|
point_line_distance(BPoint point, BPoint pa, BPoint pb)
|
||||||
@@ -42,41 +43,42 @@ point_line_distance(BPoint point, BPoint pa, BPoint pb)
|
|||||||
double alpha = acos((b*b + c*c - a*a) / (2*b*c));
|
double alpha = acos((b*b + c*c - a*a) / (2*b*c));
|
||||||
double beta = acos((a*a + c*c - b*b) / (2*a*c));
|
double beta = acos((a*a + c*c - b*b) / (2*a*c));
|
||||||
|
|
||||||
if (alpha <= PI2 && beta <= PI2) {
|
if (alpha <= M_PI_2 && beta <= M_PI_2) {
|
||||||
currentDist = fabs(point_line_distance(pa.x, pa.y, pb.x, pb.y,
|
currentDist = fabs(point_line_distance(pa.x, pa.y, pb.x, pb.y,
|
||||||
point.x, point.y));
|
point.x, point.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentDist;
|
return currentDist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// calc_angle
|
// calc_angle
|
||||||
double
|
double
|
||||||
calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
|
calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
|
||||||
{
|
{
|
||||||
double angle = 0.0;
|
double angle = 0.0;
|
||||||
|
|
||||||
double d = point_line_distance(from.x, from.y,
|
double d = point_line_distance(from.x, from.y, origin.x, origin.y,
|
||||||
origin.x, origin.y,
|
to.x, to.y);
|
||||||
to.x, to.y);
|
|
||||||
if (d != 0.0) {
|
if (d != 0.0) {
|
||||||
double a = point_point_distance(from, to);
|
double a = point_point_distance(from, to);
|
||||||
double b = point_point_distance(from, origin);
|
double b = point_point_distance(from, origin);
|
||||||
double c = point_point_distance(to, origin);
|
double c = point_point_distance(to, origin);
|
||||||
if (a > 0.0 && b > 0.0 && c > 0.0) {
|
if (a > 0.0 && b > 0.0 && c > 0.0) {
|
||||||
angle = acos((b*b + c*c - a*a) / (2.0*b*c));
|
angle = acos((b*b + c*c - a*a) / (2.0*b*c));
|
||||||
|
|
||||||
if (d < 0.0)
|
if (d < 0.0)
|
||||||
angle = -angle;
|
angle = -angle;
|
||||||
|
|
||||||
if (degree)
|
if (degree)
|
||||||
angle = angle * 180.0 / PI;
|
angle = angle * 180.0 / M_PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// write_string
|
// write_string
|
||||||
status_t
|
status_t
|
||||||
write_string(BPositionIO* stream, BString& string)
|
write_string(BPositionIO* stream, BString& string)
|
||||||
@@ -91,6 +93,7 @@ write_string(BPositionIO* stream, BString& string)
|
|||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// append_float
|
// append_float
|
||||||
void
|
void
|
||||||
append_float(BString& string, float n, int32 maxDigits)
|
append_float(BString& string, float n, int32 maxDigits)
|
||||||
@@ -127,10 +130,11 @@ append_float(BString& string, float n, int32 maxDigits)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// gauss
|
//// gauss
|
||||||
//double
|
//double
|
||||||
//gauss(double f)
|
//gauss(double f)
|
||||||
//{
|
//{
|
||||||
// // this aint' a real gauss function
|
// // this aint' a real gauss function
|
||||||
///* if (f >= -1.0 && f <= 1.0) {
|
///* if (f >= -1.0 && f <= 1.0) {
|
||||||
// if (f < -0.5) {
|
// if (f < -0.5) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -10,20 +10,24 @@
|
|||||||
|
|
||||||
#include "CanvasView.h"
|
#include "CanvasView.h"
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
CanvasTransformBox::CanvasTransformBox(CanvasView* view)
|
CanvasTransformBox::CanvasTransformBox(CanvasView* view)
|
||||||
: TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
|
:
|
||||||
|
TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
|
||||||
|
|
||||||
fCanvasView(view),
|
fCanvasView(view),
|
||||||
fParentTransform()
|
fParentTransform()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
CanvasTransformBox::~CanvasTransformBox()
|
CanvasTransformBox::~CanvasTransformBox()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformFromCanvas
|
// TransformFromCanvas
|
||||||
void
|
void
|
||||||
CanvasTransformBox::TransformFromCanvas(BPoint& point) const
|
CanvasTransformBox::TransformFromCanvas(BPoint& point) const
|
||||||
@@ -32,6 +36,7 @@ CanvasTransformBox::TransformFromCanvas(BPoint& point) const
|
|||||||
fCanvasView->ConvertFromCanvas(&point);
|
fCanvasView->ConvertFromCanvas(&point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformToCanvas
|
// TransformToCanvas
|
||||||
void
|
void
|
||||||
CanvasTransformBox::TransformToCanvas(BPoint& point) const
|
CanvasTransformBox::TransformToCanvas(BPoint& point) const
|
||||||
@@ -40,6 +45,7 @@ CanvasTransformBox::TransformToCanvas(BPoint& point) const
|
|||||||
fParentTransform.Transform(&point);
|
fParentTransform.Transform(&point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ZoomLevel
|
// ZoomLevel
|
||||||
float
|
float
|
||||||
CanvasTransformBox::ZoomLevel() const
|
CanvasTransformBox::ZoomLevel() const
|
||||||
@@ -47,11 +53,12 @@ CanvasTransformBox::ZoomLevel() const
|
|||||||
return fCanvasView->ZoomLevel();
|
return fCanvasView->ZoomLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ViewSpaceRotation
|
// ViewSpaceRotation
|
||||||
double
|
double
|
||||||
CanvasTransformBox::ViewSpaceRotation() const
|
CanvasTransformBox::ViewSpaceRotation() const
|
||||||
{
|
{
|
||||||
Transformable t(*this);
|
Transformable t(*this);
|
||||||
t.Multiply(fParentTransform);
|
t.Multiply(fParentTransform);
|
||||||
return t.rotation() * 180.0 / PI;
|
return t.rotation() * 180.0 / M_PI;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -11,33 +11,38 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
ChannelTransform::ChannelTransform()
|
ChannelTransform::ChannelTransform()
|
||||||
: Transformable(),
|
:
|
||||||
fPivot(0.0, 0.0),
|
Transformable(),
|
||||||
fTranslation(0.0, 0.0),
|
fPivot(0.0, 0.0),
|
||||||
fRotation(0.0),
|
fTranslation(0.0, 0.0),
|
||||||
fXScale(1.0),
|
fRotation(0.0),
|
||||||
fYScale(1.0)
|
fXScale(1.0),
|
||||||
|
fYScale(1.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor
|
// copy constructor
|
||||||
ChannelTransform::ChannelTransform(const ChannelTransform& other)
|
ChannelTransform::ChannelTransform(const ChannelTransform& other)
|
||||||
: Transformable(other),
|
:
|
||||||
fPivot(other.fPivot),
|
Transformable(other),
|
||||||
fTranslation(other.fTranslation),
|
fPivot(other.fPivot),
|
||||||
fRotation(other.fRotation),
|
fTranslation(other.fTranslation),
|
||||||
fXScale(other.fXScale),
|
fRotation(other.fRotation),
|
||||||
fYScale(other.fYScale)
|
fXScale(other.fXScale),
|
||||||
|
fYScale(other.fYScale)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
ChannelTransform::~ChannelTransform()
|
ChannelTransform::~ChannelTransform()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetTransformation
|
// SetTransformation
|
||||||
void
|
void
|
||||||
ChannelTransform::SetTransformation(const Transformable& other)
|
ChannelTransform::SetTransformation(const Transformable& other)
|
||||||
@@ -63,13 +68,11 @@ ChannelTransform::SetTransformation(const Transformable& other)
|
|||||||
SetTransformation(B_ORIGIN, BPoint(tx, ty), rotation, scaleX, scaleY);
|
SetTransformation(B_ORIGIN, BPoint(tx, ty), rotation, scaleX, scaleY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetTransformation
|
// SetTransformation
|
||||||
void
|
void
|
||||||
ChannelTransform::SetTransformation(BPoint pivot,
|
ChannelTransform::SetTransformation(BPoint pivot, BPoint translation,
|
||||||
BPoint translation,
|
double rotation, double xScale, double yScale)
|
||||||
double rotation,
|
|
||||||
double xScale,
|
|
||||||
double yScale)
|
|
||||||
{
|
{
|
||||||
//printf("SetTransformation(BPoint(%.1f, %.1f), BPoint(%.1f, %.1f), "
|
//printf("SetTransformation(BPoint(%.1f, %.1f), BPoint(%.1f, %.1f), "
|
||||||
//"%.2f, %.2f, %.2f)\n", pivot.x, pivot.y, translation.x, translation.y,
|
//"%.2f, %.2f, %.2f)\n", pivot.x, pivot.y, translation.x, translation.y,
|
||||||
@@ -86,11 +89,12 @@ ChannelTransform::SetTransformation(BPoint pivot,
|
|||||||
fRotation = rotation;
|
fRotation = rotation;
|
||||||
fXScale = xScale;
|
fXScale = xScale;
|
||||||
fYScale = yScale;
|
fYScale = yScale;
|
||||||
|
|
||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetPivot
|
// SetPivot
|
||||||
void
|
void
|
||||||
ChannelTransform::SetPivot(BPoint pivot)
|
ChannelTransform::SetPivot(BPoint pivot)
|
||||||
@@ -103,6 +107,7 @@ ChannelTransform::SetPivot(BPoint pivot)
|
|||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TranslateBy
|
// TranslateBy
|
||||||
void
|
void
|
||||||
ChannelTransform::TranslateBy(BPoint offset)
|
ChannelTransform::TranslateBy(BPoint offset)
|
||||||
@@ -115,10 +120,11 @@ ChannelTransform::TranslateBy(BPoint offset)
|
|||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// RotateBy
|
// RotateBy
|
||||||
//
|
/*! Converts a rotation in world coordinates into
|
||||||
// converts a rotation in world coordinates into
|
a combined local rotation and a translation.
|
||||||
// a combined local rotation and a translation
|
*/
|
||||||
void
|
void
|
||||||
ChannelTransform::RotateBy(BPoint origin, double degrees)
|
ChannelTransform::RotateBy(BPoint origin, double degrees)
|
||||||
{
|
{
|
||||||
@@ -133,7 +139,7 @@ ChannelTransform::RotateBy(BPoint origin, double degrees)
|
|||||||
double xOffset = fTranslation.x - origin.x;
|
double xOffset = fTranslation.x - origin.x;
|
||||||
double yOffset = fTranslation.y - origin.y;
|
double yOffset = fTranslation.y - origin.y;
|
||||||
|
|
||||||
agg::trans_affine_rotation m(degrees * PI / 180.0);
|
agg::trans_affine_rotation m(degrees * M_PI / 180.0);
|
||||||
m.transform(&xOffset, &yOffset);
|
m.transform(&xOffset, &yOffset);
|
||||||
|
|
||||||
fTranslation.x = origin.x + xOffset;
|
fTranslation.x = origin.x + xOffset;
|
||||||
@@ -155,6 +161,7 @@ ChannelTransform::RotateBy(double degrees)
|
|||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// ScaleBy
|
//// ScaleBy
|
||||||
////
|
////
|
||||||
//// converts a scalation in world coordinates into
|
//// converts a scalation in world coordinates into
|
||||||
@@ -191,10 +198,11 @@ ChannelTransform::ScaleBy(double xScale, double yScale)
|
|||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetTranslationAndScale
|
// SetTranslationAndScale
|
||||||
void
|
void
|
||||||
ChannelTransform::SetTranslationAndScale(BPoint offset,
|
ChannelTransform::SetTranslationAndScale(BPoint offset, double xScale,
|
||||||
double xScale, double yScale)
|
double yScale)
|
||||||
{
|
{
|
||||||
if (fTranslation == offset && fXScale == xScale && fYScale == yScale)
|
if (fTranslation == offset && fXScale == xScale && fYScale == yScale)
|
||||||
return;
|
return;
|
||||||
@@ -207,6 +215,7 @@ ChannelTransform::SetTranslationAndScale(BPoint offset,
|
|||||||
_UpdateMatrix();
|
_UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
void
|
void
|
||||||
ChannelTransform::Reset()
|
ChannelTransform::Reset()
|
||||||
@@ -214,6 +223,7 @@ ChannelTransform::Reset()
|
|||||||
SetTransformation(B_ORIGIN, B_ORIGIN, 0.0, 1.0, 1.0);
|
SetTransformation(B_ORIGIN, B_ORIGIN, 0.0, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =
|
// =
|
||||||
ChannelTransform&
|
ChannelTransform&
|
||||||
ChannelTransform::operator=(const ChannelTransform& other)
|
ChannelTransform::operator=(const ChannelTransform& other)
|
||||||
@@ -228,6 +238,7 @@ ChannelTransform::operator=(const ChannelTransform& other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _UpdateMatrix
|
// _UpdateMatrix
|
||||||
void
|
void
|
||||||
ChannelTransform::_UpdateMatrix()
|
ChannelTransform::_UpdateMatrix()
|
||||||
@@ -246,10 +257,10 @@ ChannelTransform::_UpdateMatrix()
|
|||||||
// coordinate system and is the center for rotation and scale
|
// coordinate system and is the center for rotation and scale
|
||||||
multiply(agg::trans_affine_translation(-fPivot.x, -fPivot.y));
|
multiply(agg::trans_affine_translation(-fPivot.x, -fPivot.y));
|
||||||
multiply(agg::trans_affine_scaling(xScale, yScale));
|
multiply(agg::trans_affine_scaling(xScale, yScale));
|
||||||
multiply(agg::trans_affine_rotation(fRotation * PI / 180.0));
|
multiply(agg::trans_affine_rotation(fRotation * M_PI / 180.0));
|
||||||
|
|
||||||
multiply(agg::trans_affine_translation(fPivot.x + fTranslation.x,
|
multiply(agg::trans_affine_translation(fPivot.x + fTranslation.x,
|
||||||
fPivot.y + fTranslation.y));
|
fPivot.y + fTranslation.y));
|
||||||
|
|
||||||
// call hook function
|
// call hook function
|
||||||
Update();
|
Update();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -21,55 +21,66 @@
|
|||||||
#include "StateView.h"
|
#include "StateView.h"
|
||||||
#include "TransformCommand.h"
|
#include "TransformCommand.h"
|
||||||
|
|
||||||
|
|
||||||
#define INSET 8.0
|
#define INSET 8.0
|
||||||
|
|
||||||
TransformBoxListener::TransformBoxListener() {}
|
|
||||||
TransformBoxListener::~TransformBoxListener() {}
|
TransformBoxListener::TransformBoxListener()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TransformBoxListener::~TransformBoxListener()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
TransformBox::TransformBox(StateView* view, BRect box)
|
TransformBox::TransformBox(StateView* view, BRect box)
|
||||||
: ChannelTransform(),
|
:
|
||||||
Manipulator(NULL),
|
ChannelTransform(),
|
||||||
fOriginalBox(box),
|
Manipulator(NULL),
|
||||||
|
fOriginalBox(box),
|
||||||
|
|
||||||
fLeftTop(box.LeftTop()),
|
fLeftTop(box.LeftTop()),
|
||||||
fRightTop(box.RightTop()),
|
fRightTop(box.RightTop()),
|
||||||
fLeftBottom(box.LeftBottom()),
|
fLeftBottom(box.LeftBottom()),
|
||||||
fRightBottom(box.RightBottom()),
|
fRightBottom(box.RightBottom()),
|
||||||
|
|
||||||
fPivot((fLeftTop.x + fRightBottom.x) / 2.0,
|
fPivot((fLeftTop.x + fRightBottom.x) / 2.0,
|
||||||
(fLeftTop.y + fRightBottom.y) / 2.0),
|
(fLeftTop.y + fRightBottom.y) / 2.0),
|
||||||
fPivotOffset(B_ORIGIN),
|
fPivotOffset(B_ORIGIN),
|
||||||
|
fCurrentCommand(NULL),
|
||||||
|
fCurrentState(NULL),
|
||||||
|
|
||||||
fCurrentCommand(NULL),
|
fDragging(false),
|
||||||
fCurrentState(NULL),
|
fMousePos(-10000.0, -10000.0),
|
||||||
|
fModifiers(0),
|
||||||
|
|
||||||
fDragging(false),
|
fNudging(false),
|
||||||
fMousePos(-10000.0, -10000.0),
|
|
||||||
fModifiers(0),
|
|
||||||
|
|
||||||
fNudging(false),
|
fView(view),
|
||||||
|
|
||||||
fView(view),
|
fDragLTState(new DragCornerState(this, DragCornerState::LEFT_TOP_CORNER)),
|
||||||
|
fDragRTState(new DragCornerState(this, DragCornerState::RIGHT_TOP_CORNER)),
|
||||||
|
fDragLBState(new DragCornerState(this, DragCornerState::LEFT_BOTTOM_CORNER)),
|
||||||
|
fDragRBState(new DragCornerState(this, DragCornerState::RIGHT_BOTTOM_CORNER)),
|
||||||
|
|
||||||
fDragLTState(new DragCornerState(this, DragCornerState::LEFT_TOP_CORNER)),
|
fDragLState(new DragSideState(this, DragSideState::LEFT_SIDE)),
|
||||||
fDragRTState(new DragCornerState(this, DragCornerState::RIGHT_TOP_CORNER)),
|
fDragRState(new DragSideState(this, DragSideState::RIGHT_SIDE)),
|
||||||
fDragLBState(new DragCornerState(this, DragCornerState::LEFT_BOTTOM_CORNER)),
|
fDragTState(new DragSideState(this, DragSideState::TOP_SIDE)),
|
||||||
fDragRBState(new DragCornerState(this, DragCornerState::RIGHT_BOTTOM_CORNER)),
|
fDragBState(new DragSideState(this, DragSideState::BOTTOM_SIDE)),
|
||||||
|
|
||||||
fDragLState(new DragSideState(this, DragSideState::LEFT_SIDE)),
|
fRotateState(new RotateBoxState(this)),
|
||||||
fDragRState(new DragSideState(this, DragSideState::RIGHT_SIDE)),
|
fTranslateState(new DragBoxState(this)),
|
||||||
fDragTState(new DragSideState(this, DragSideState::TOP_SIDE)),
|
fOffsetCenterState(new OffsetCenterState(this))
|
||||||
fDragBState(new DragSideState(this, DragSideState::BOTTOM_SIDE)),
|
|
||||||
|
|
||||||
fRotateState(new RotateBoxState(this)),
|
|
||||||
fTranslateState(new DragBoxState(this)),
|
|
||||||
fOffsetCenterState(new OffsetCenterState(this))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
TransformBox::~TransformBox()
|
TransformBox::~TransformBox()
|
||||||
{
|
{
|
||||||
@@ -92,6 +103,7 @@ TransformBox::~TransformBox()
|
|||||||
delete fOffsetCenterState;
|
delete fOffsetCenterState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
void
|
void
|
||||||
TransformBox::Draw(BView* into, BRect updateRect)
|
TransformBox::Draw(BView* into, BRect updateRect)
|
||||||
@@ -131,8 +143,10 @@ TransformBox::Draw(BView* into, BRect updateRect)
|
|||||||
into->SetDrawingMode(B_OP_COPY);
|
into->SetDrawingMode(B_OP_COPY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// MouseDown
|
// MouseDown
|
||||||
bool
|
bool
|
||||||
TransformBox::MouseDown(BPoint where)
|
TransformBox::MouseDown(BPoint where)
|
||||||
@@ -147,12 +161,13 @@ TransformBox::MouseDown(BPoint where)
|
|||||||
|
|
||||||
delete fCurrentCommand;
|
delete fCurrentCommand;
|
||||||
fCurrentCommand = MakeCommand(fCurrentState->ActionName(),
|
fCurrentCommand = MakeCommand(fCurrentState->ActionName(),
|
||||||
fCurrentState->ActionNameIndex());
|
fCurrentState->ActionNameIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MouseMoved
|
// MouseMoved
|
||||||
void
|
void
|
||||||
TransformBox::MouseMoved(BPoint where)
|
TransformBox::MouseMoved(BPoint where)
|
||||||
@@ -170,6 +185,7 @@ TransformBox::MouseMoved(BPoint where)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MouseUp
|
// MouseUp
|
||||||
Command*
|
Command*
|
||||||
TransformBox::MouseUp()
|
TransformBox::MouseUp()
|
||||||
@@ -178,6 +194,7 @@ TransformBox::MouseUp()
|
|||||||
return FinishTransaction();
|
return FinishTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MouseOver
|
// MouseOver
|
||||||
bool
|
bool
|
||||||
TransformBox::MouseOver(BPoint where)
|
TransformBox::MouseOver(BPoint where)
|
||||||
@@ -193,6 +210,7 @@ TransformBox::MouseOver(BPoint where)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DoubleClicked
|
// DoubleClicked
|
||||||
bool
|
bool
|
||||||
TransformBox::DoubleClicked(BPoint where)
|
TransformBox::DoubleClicked(BPoint where)
|
||||||
@@ -200,8 +218,10 @@ TransformBox::DoubleClicked(BPoint where)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// Bounds
|
// Bounds
|
||||||
BRect
|
BRect
|
||||||
TransformBox::Bounds()
|
TransformBox::Bounds()
|
||||||
@@ -227,6 +247,7 @@ TransformBox::Bounds()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TrackingBounds
|
// TrackingBounds
|
||||||
BRect
|
BRect
|
||||||
TransformBox::TrackingBounds(BView* withinView)
|
TransformBox::TrackingBounds(BView* withinView)
|
||||||
@@ -234,8 +255,10 @@ TransformBox::TrackingBounds(BView* withinView)
|
|||||||
return withinView->Bounds();
|
return withinView->Bounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// ModifiersChanged
|
// ModifiersChanged
|
||||||
void
|
void
|
||||||
TransformBox::ModifiersChanged(uint32 modifiers)
|
TransformBox::ModifiersChanged(uint32 modifiers)
|
||||||
@@ -246,6 +269,7 @@ TransformBox::ModifiersChanged(uint32 modifiers)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HandleKeyDown
|
// HandleKeyDown
|
||||||
bool
|
bool
|
||||||
TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
|
TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
|
||||||
@@ -270,7 +294,7 @@ TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
|
|||||||
case B_RIGHT_ARROW:
|
case B_RIGHT_ARROW:
|
||||||
translation.x = offset;
|
translation.x = offset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
handled = false;
|
handled = false;
|
||||||
break;
|
break;
|
||||||
@@ -288,6 +312,7 @@ TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HandleKeyUp
|
// HandleKeyUp
|
||||||
bool
|
bool
|
||||||
TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
|
TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
|
||||||
@@ -299,6 +324,7 @@ TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateCursor
|
// UpdateCursor
|
||||||
bool
|
bool
|
||||||
TransformBox::UpdateCursor()
|
TransformBox::UpdateCursor()
|
||||||
@@ -310,8 +336,10 @@ TransformBox::UpdateCursor()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// AttachedToView
|
// AttachedToView
|
||||||
void
|
void
|
||||||
TransformBox::AttachedToView(BView* view)
|
TransformBox::AttachedToView(BView* view)
|
||||||
@@ -319,6 +347,7 @@ TransformBox::AttachedToView(BView* view)
|
|||||||
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
|
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DetachedFromView
|
// DetachedFromView
|
||||||
void
|
void
|
||||||
TransformBox::DetachedFromView(BView* view)
|
TransformBox::DetachedFromView(BView* view)
|
||||||
@@ -326,8 +355,10 @@ TransformBox::DetachedFromView(BView* view)
|
|||||||
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
|
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pragma mark -
|
// pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
void
|
void
|
||||||
TransformBox::Update(bool deep)
|
TransformBox::Update(bool deep)
|
||||||
@@ -352,6 +383,7 @@ TransformBox::Update(bool deep)
|
|||||||
Transform(&fPivot);
|
Transform(&fPivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OffsetCenter
|
// OffsetCenter
|
||||||
void
|
void
|
||||||
TransformBox::OffsetCenter(BPoint offset)
|
TransformBox::OffsetCenter(BPoint offset)
|
||||||
@@ -362,6 +394,7 @@ TransformBox::OffsetCenter(BPoint offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Center
|
// Center
|
||||||
BPoint
|
BPoint
|
||||||
TransformBox::Center() const
|
TransformBox::Center() const
|
||||||
@@ -369,6 +402,7 @@ TransformBox::Center() const
|
|||||||
return fPivot;
|
return fPivot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetBox
|
// SetBox
|
||||||
void
|
void
|
||||||
TransformBox::SetBox(BRect box)
|
TransformBox::SetBox(BRect box)
|
||||||
@@ -379,22 +413,21 @@ TransformBox::SetBox(BRect box)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FinishTransaction
|
// FinishTransaction
|
||||||
Command*
|
Command*
|
||||||
TransformBox::FinishTransaction()
|
TransformBox::FinishTransaction()
|
||||||
{
|
{
|
||||||
Command* command = fCurrentCommand;
|
Command* command = fCurrentCommand;
|
||||||
if (fCurrentCommand) {
|
if (fCurrentCommand) {
|
||||||
fCurrentCommand->SetNewTransformation(Pivot(),
|
fCurrentCommand->SetNewTransformation(Pivot(), Translation(),
|
||||||
Translation(),
|
LocalRotation(), LocalXScale(), LocalYScale());
|
||||||
LocalRotation(),
|
|
||||||
LocalXScale(),
|
|
||||||
LocalYScale());
|
|
||||||
fCurrentCommand = NULL;
|
fCurrentCommand = NULL;
|
||||||
}
|
}
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NudgeBy
|
// NudgeBy
|
||||||
void
|
void
|
||||||
TransformBox::NudgeBy(BPoint offset)
|
TransformBox::NudgeBy(BPoint offset)
|
||||||
@@ -408,6 +441,7 @@ TransformBox::NudgeBy(BPoint offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FinishNudging
|
// FinishNudging
|
||||||
Command*
|
Command*
|
||||||
TransformBox::FinishNudging()
|
TransformBox::FinishNudging()
|
||||||
@@ -416,18 +450,21 @@ TransformBox::FinishNudging()
|
|||||||
return FinishTransaction();
|
return FinishTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformFromCanvas
|
// TransformFromCanvas
|
||||||
void
|
void
|
||||||
TransformBox::TransformFromCanvas(BPoint& point) const
|
TransformBox::TransformFromCanvas(BPoint& point) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformToCanvas
|
// TransformToCanvas
|
||||||
void
|
void
|
||||||
TransformBox::TransformToCanvas(BPoint& point) const
|
TransformBox::TransformToCanvas(BPoint& point) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ZoomLevel
|
// ZoomLevel
|
||||||
float
|
float
|
||||||
TransformBox::ZoomLevel() const
|
TransformBox::ZoomLevel() const
|
||||||
@@ -435,6 +472,7 @@ TransformBox::ZoomLevel() const
|
|||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ViewSpaceRotation
|
// ViewSpaceRotation
|
||||||
double
|
double
|
||||||
TransformBox::ViewSpaceRotation() const
|
TransformBox::ViewSpaceRotation() const
|
||||||
@@ -443,8 +481,10 @@ TransformBox::ViewSpaceRotation() const
|
|||||||
return LocalRotation();
|
return LocalRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// AddListener
|
// AddListener
|
||||||
bool
|
bool
|
||||||
TransformBox::AddListener(TransformBoxListener* listener)
|
TransformBox::AddListener(TransformBoxListener* listener)
|
||||||
@@ -454,6 +494,7 @@ TransformBox::AddListener(TransformBoxListener* listener)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// RemoveListener
|
// RemoveListener
|
||||||
bool
|
bool
|
||||||
TransformBox::RemoveListener(TransformBoxListener* listener)
|
TransformBox::RemoveListener(TransformBoxListener* listener)
|
||||||
@@ -461,30 +502,29 @@ TransformBox::RemoveListener(TransformBoxListener* listener)
|
|||||||
return fListeners.RemoveItem((void*)listener);
|
return fListeners.RemoveItem((void*)listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// TODO: why another version?
|
// TODO: why another version?
|
||||||
// point_line_dist
|
// point_line_dist
|
||||||
float
|
float
|
||||||
point_line_dist(BPoint start, BPoint end, BPoint p, float radius)
|
point_line_dist(BPoint start, BPoint end, BPoint p, float radius)
|
||||||
{
|
{
|
||||||
BRect r(min_c(start.x, end.x),
|
BRect r(min_c(start.x, end.x), min_c(start.y, end.y), max_c(start.x, end.x),
|
||||||
min_c(start.y, end.y),
|
max_c(start.y, end.y));
|
||||||
max_c(start.x, end.x),
|
|
||||||
max_c(start.y, end.y));
|
|
||||||
r.InsetBy(-radius, -radius);
|
r.InsetBy(-radius, -radius);
|
||||||
if (r.Contains(p)) {
|
if (r.Contains(p)) {
|
||||||
return fabs(agg::calc_line_point_distance(start.x, start.y,
|
return fabs(agg::calc_line_point_distance(start.x, start.y, end.x, end.y,
|
||||||
end.x, end.y,
|
p.x, p.y));
|
||||||
p.x, p.y));
|
|
||||||
}
|
}
|
||||||
return min_c(point_point_distance(start, p),
|
|
||||||
point_point_distance(end, p));
|
return min_c(point_point_distance(start, p), point_point_distance(end, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _DragStateFor
|
// _DragStateFor
|
||||||
//
|
//! where is expected in canvas view coordinates
|
||||||
// where is expected in canvas view coordinates
|
|
||||||
DragState*
|
DragState*
|
||||||
TransformBox::_DragStateFor(BPoint where, float canvasZoom)
|
TransformBox::_DragStateFor(BPoint where, float canvasZoom)
|
||||||
{
|
{
|
||||||
@@ -586,6 +626,7 @@ TransformBox::_DragStateFor(BPoint where, float canvasZoom)
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _StrokeBWLine
|
// _StrokeBWLine
|
||||||
void
|
void
|
||||||
TransformBox::_StrokeBWLine(BView* into, BPoint from, BPoint to) const
|
TransformBox::_StrokeBWLine(BView* into, BPoint from, BPoint to) const
|
||||||
@@ -617,6 +658,7 @@ TransformBox::_StrokeBWLine(BView* into, BPoint from, BPoint to) const
|
|||||||
into->StrokeLine(from, to, B_SOLID_HIGH);
|
into->StrokeLine(from, to, B_SOLID_HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _StrokeBWPoint
|
// _StrokeBWPoint
|
||||||
void
|
void
|
||||||
TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
|
TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
|
||||||
@@ -638,7 +680,7 @@ TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
|
|||||||
double xOffset = -x;
|
double xOffset = -x;
|
||||||
double yOffset = -y;
|
double yOffset = -y;
|
||||||
|
|
||||||
agg::trans_affine_rotation r(angle * PI / 180.0);
|
agg::trans_affine_rotation r(angle * M_PI / 180.0);
|
||||||
|
|
||||||
r.transform(&xOffset, &yOffset);
|
r.transform(&xOffset, &yOffset);
|
||||||
xOffset = x + xOffset;
|
xOffset = x + xOffset;
|
||||||
@@ -666,8 +708,10 @@ TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
|
|||||||
into->StrokeLine(p[3], p[0], B_SOLID_LOW);
|
into->StrokeLine(p[3], p[0], B_SOLID_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// _NotifyDeleted
|
// _NotifyDeleted
|
||||||
void
|
void
|
||||||
TransformBox::_NotifyDeleted() const
|
TransformBox::_NotifyDeleted() const
|
||||||
@@ -681,8 +725,10 @@ TransformBox::_NotifyDeleted() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// _SetState
|
// _SetState
|
||||||
void
|
void
|
||||||
TransformBox::_SetState(DragState* state)
|
TransformBox::_SetState(DragState* state)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -19,15 +19,17 @@
|
|||||||
#include "support.h"
|
#include "support.h"
|
||||||
|
|
||||||
#include "TransformBox.h"
|
#include "TransformBox.h"
|
||||||
//#include "Strings.h"
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
DragState::DragState(TransformBox* parent)
|
DragState::DragState(TransformBox* parent)
|
||||||
: fOrigin(0.0, 0.0),
|
:
|
||||||
fParent(parent)
|
fOrigin(0.0, 0.0),
|
||||||
|
fParent(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
DragState::SetOrigin(BPoint origin)
|
DragState::SetOrigin(BPoint origin)
|
||||||
@@ -35,6 +37,7 @@ DragState::SetOrigin(BPoint origin)
|
|||||||
fOrigin = origin;
|
fOrigin = origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
DragState::ActionName() const
|
DragState::ActionName() const
|
||||||
@@ -42,6 +45,7 @@ DragState::ActionName() const
|
|||||||
return "Transformation";
|
return "Transformation";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
DragState::ActionNameIndex() const
|
DragState::ActionNameIndex() const
|
||||||
@@ -49,6 +53,7 @@ DragState::ActionNameIndex() const
|
|||||||
return TRANSFORMATION;
|
return TRANSFORMATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _SetViewCursor
|
// _SetViewCursor
|
||||||
void
|
void
|
||||||
DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
|
DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
|
||||||
@@ -57,15 +62,19 @@ DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
|
|||||||
view->SetViewCursor(&cursor);
|
view->SetViewCursor(&cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - DragCornerState
|
// #pragma mark - DragCornerState
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
DragCornerState::DragCornerState(TransformBox* parent, uint32 corner)
|
DragCornerState::DragCornerState(TransformBox* parent, uint32 corner)
|
||||||
: DragState(parent),
|
:
|
||||||
fCorner(corner)
|
DragState(parent),
|
||||||
|
fCorner(corner)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
DragCornerState::SetOrigin(BPoint origin)
|
DragCornerState::SetOrigin(BPoint origin)
|
||||||
@@ -78,9 +87,10 @@ DragCornerState::SetOrigin(BPoint origin)
|
|||||||
// copy the matrix at the start of the drag procedure
|
// copy the matrix at the start of the drag procedure
|
||||||
fMatrix.reset();
|
fMatrix.reset();
|
||||||
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
|
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
|
||||||
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation() * PI / 180.0));
|
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation()
|
||||||
|
* M_PI / 180.0));
|
||||||
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
|
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
|
||||||
fParent->Translation().y));
|
fParent->Translation().y));
|
||||||
|
|
||||||
double x = origin.x;
|
double x = origin.x;
|
||||||
double y = origin.y;
|
double y = origin.y;
|
||||||
@@ -125,6 +135,8 @@ DragCornerState::SetOrigin(BPoint origin)
|
|||||||
}
|
}
|
||||||
DragState::SetOrigin(origin);
|
DragState::SetOrigin(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DragTo
|
// DragTo
|
||||||
void
|
void
|
||||||
DragCornerState::DragTo(BPoint current, uint32 modifiers)
|
DragCornerState::DragTo(BPoint current, uint32 modifiers)
|
||||||
@@ -164,11 +176,11 @@ DragCornerState::DragTo(BPoint current, uint32 modifiers)
|
|||||||
translation.x = x;
|
translation.x = x;
|
||||||
translation.y = y;
|
translation.y = y;
|
||||||
|
|
||||||
fParent->SetTranslationAndScale(translation,
|
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
|
||||||
xScale * fOldXScale,
|
yScale * fOldYScale);
|
||||||
yScale * fOldYScale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateViewCursor
|
// UpdateViewCursor
|
||||||
void
|
void
|
||||||
DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
|
DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
|
||||||
@@ -180,91 +192,98 @@ DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
switch (fCorner) {
|
switch (fCorner) {
|
||||||
case LEFT_TOP_CORNER:
|
case LEFT_TOP_CORNER:
|
||||||
case RIGHT_BOTTOM_CORNER:
|
case RIGHT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftBottomRightTopCursor);
|
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftTopRightBottomCursor);
|
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT_TOP_CORNER:
|
case RIGHT_TOP_CORNER:
|
||||||
case LEFT_BOTTOM_CORNER:
|
case LEFT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftTopRightBottomCursor);
|
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftBottomRightTopCursor);
|
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (rotation < 90.0) {
|
} else if (rotation < 90.0) {
|
||||||
switch (fCorner) {
|
switch (fCorner) {
|
||||||
case LEFT_TOP_CORNER:
|
case LEFT_TOP_CORNER:
|
||||||
case RIGHT_BOTTOM_CORNER:
|
case RIGHT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftRightCursor
|
_SetViewCursor(view,
|
||||||
: kUpDownCursor);
|
flipY ? kLeftRightCursor : kUpDownCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kUpDownCursor
|
_SetViewCursor(view,
|
||||||
: kLeftRightCursor);
|
flipY ? kUpDownCursor : kLeftRightCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT_TOP_CORNER:
|
case RIGHT_TOP_CORNER:
|
||||||
case LEFT_BOTTOM_CORNER:
|
case LEFT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kUpDownCursor
|
_SetViewCursor(view,
|
||||||
: kLeftRightCursor);
|
flipY ? kUpDownCursor : kLeftRightCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftRightCursor
|
_SetViewCursor(view,
|
||||||
: kUpDownCursor);
|
flipY ? kLeftRightCursor : kUpDownCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (rotation < 135.0) {
|
} else if (rotation < 135.0) {
|
||||||
switch (fCorner) {
|
switch (fCorner) {
|
||||||
case LEFT_TOP_CORNER:
|
case LEFT_TOP_CORNER:
|
||||||
case RIGHT_BOTTOM_CORNER:
|
case RIGHT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftTopRightBottomCursor);
|
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftBottomRightTopCursor);
|
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
|
||||||
break;
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT_TOP_CORNER:
|
case RIGHT_TOP_CORNER:
|
||||||
case LEFT_BOTTOM_CORNER:
|
case LEFT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftBottomRightTopCursor);
|
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
|
_SetViewCursor(view, flipY
|
||||||
: kLeftTopRightBottomCursor);
|
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
|
||||||
break;
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (fCorner) {
|
switch (fCorner) {
|
||||||
case LEFT_TOP_CORNER:
|
case LEFT_TOP_CORNER:
|
||||||
case RIGHT_BOTTOM_CORNER:
|
case RIGHT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kUpDownCursor
|
_SetViewCursor(view,
|
||||||
: kLeftRightCursor);
|
flipY ? kUpDownCursor : kLeftRightCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kLeftRightCursor
|
_SetViewCursor(view,
|
||||||
: kUpDownCursor);
|
flipY ? kLeftRightCursor : kUpDownCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT_TOP_CORNER:
|
case RIGHT_TOP_CORNER:
|
||||||
case LEFT_BOTTOM_CORNER:
|
case LEFT_BOTTOM_CORNER:
|
||||||
if (flipX)
|
if (flipX) {
|
||||||
_SetViewCursor(view, flipY ? kLeftRightCursor
|
_SetViewCursor(view,
|
||||||
: kUpDownCursor);
|
flipY ? kLeftRightCursor : kUpDownCursor);
|
||||||
else
|
} else {
|
||||||
_SetViewCursor(view, flipY ? kUpDownCursor
|
_SetViewCursor(view,
|
||||||
: kLeftRightCursor);
|
flipY ? kUpDownCursor : kLeftRightCursor);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
DragCornerState::ActionName() const
|
DragCornerState::ActionName() const
|
||||||
@@ -272,6 +291,7 @@ DragCornerState::ActionName() const
|
|||||||
return "Scale";
|
return "Scale";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
DragCornerState::ActionNameIndex() const
|
DragCornerState::ActionNameIndex() const
|
||||||
@@ -282,12 +302,15 @@ DragCornerState::ActionNameIndex() const
|
|||||||
|
|
||||||
// #pragma mark - DragSideState
|
// #pragma mark - DragSideState
|
||||||
|
|
||||||
|
|
||||||
DragSideState::DragSideState(TransformBox* parent, uint32 side)
|
DragSideState::DragSideState(TransformBox* parent, uint32 side)
|
||||||
: DragState(parent),
|
:
|
||||||
fSide(side)
|
DragState(parent),
|
||||||
|
fSide(side)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
DragSideState::SetOrigin(BPoint origin)
|
DragSideState::SetOrigin(BPoint origin)
|
||||||
@@ -300,9 +323,10 @@ DragSideState::SetOrigin(BPoint origin)
|
|||||||
// copy the matrix at the start of the drag procedure
|
// copy the matrix at the start of the drag procedure
|
||||||
fMatrix.reset();
|
fMatrix.reset();
|
||||||
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
|
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
|
||||||
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation() * PI / 180.0));
|
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation()
|
||||||
|
* M_PI / 180.0));
|
||||||
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
|
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
|
||||||
fParent->Translation().y));
|
fParent->Translation().y));
|
||||||
|
|
||||||
double x = origin.x;
|
double x = origin.x;
|
||||||
double y = origin.y;
|
double y = origin.y;
|
||||||
@@ -336,6 +360,7 @@ DragSideState::SetOrigin(BPoint origin)
|
|||||||
DragState::SetOrigin(origin);
|
DragState::SetOrigin(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DragTo
|
// DragTo
|
||||||
void
|
void
|
||||||
DragSideState::DragTo(BPoint current, uint32 modifiers)
|
DragSideState::DragTo(BPoint current, uint32 modifiers)
|
||||||
@@ -369,11 +394,11 @@ DragSideState::DragTo(BPoint current, uint32 modifiers)
|
|||||||
translation.x = x;
|
translation.x = x;
|
||||||
translation.y = y;
|
translation.y = y;
|
||||||
|
|
||||||
fParent->SetTranslationAndScale(translation,
|
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
|
||||||
xScale * fOldXScale,
|
yScale * fOldYScale);
|
||||||
yScale * fOldYScale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateViewCursor
|
// UpdateViewCursor
|
||||||
void
|
void
|
||||||
DragSideState::UpdateViewCursor(BView* view, BPoint current) const
|
DragSideState::UpdateViewCursor(BView* view, BPoint current) const
|
||||||
@@ -426,6 +451,7 @@ DragSideState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
DragSideState::ActionName() const
|
DragSideState::ActionName() const
|
||||||
@@ -433,6 +459,7 @@ DragSideState::ActionName() const
|
|||||||
return "Scale";
|
return "Scale";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
DragSideState::ActionNameIndex() const
|
DragSideState::ActionNameIndex() const
|
||||||
@@ -443,6 +470,7 @@ DragSideState::ActionNameIndex() const
|
|||||||
|
|
||||||
// #pragma mark - DragBoxState
|
// #pragma mark - DragBoxState
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
DragBoxState::SetOrigin(BPoint origin)
|
DragBoxState::SetOrigin(BPoint origin)
|
||||||
@@ -451,6 +479,7 @@ DragBoxState::SetOrigin(BPoint origin)
|
|||||||
DragState::SetOrigin(origin);
|
DragState::SetOrigin(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DragTo
|
// DragTo
|
||||||
void
|
void
|
||||||
DragBoxState::DragTo(BPoint current, uint32 modifiers)
|
DragBoxState::DragTo(BPoint current, uint32 modifiers)
|
||||||
@@ -466,6 +495,7 @@ DragBoxState::DragTo(BPoint current, uint32 modifiers)
|
|||||||
fParent->TranslateBy(newTranslation - fParent->Translation());
|
fParent->TranslateBy(newTranslation - fParent->Translation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateViewCursor
|
// UpdateViewCursor
|
||||||
void
|
void
|
||||||
DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
||||||
@@ -473,6 +503,7 @@ DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
_SetViewCursor(view, kMoveCursor);
|
_SetViewCursor(view, kMoveCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
DragBoxState::ActionName() const
|
DragBoxState::ActionName() const
|
||||||
@@ -480,6 +511,7 @@ DragBoxState::ActionName() const
|
|||||||
return "Move";
|
return "Move";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
DragBoxState::ActionNameIndex() const
|
DragBoxState::ActionNameIndex() const
|
||||||
@@ -490,13 +522,16 @@ DragBoxState::ActionNameIndex() const
|
|||||||
|
|
||||||
// #pragma mark - RotateBoxState
|
// #pragma mark - RotateBoxState
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
RotateBoxState::RotateBoxState(TransformBox* parent)
|
RotateBoxState::RotateBoxState(TransformBox* parent)
|
||||||
: DragState(parent),
|
:
|
||||||
fOldAngle(0.0)
|
DragState(parent),
|
||||||
|
fOldAngle(0.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
RotateBoxState::SetOrigin(BPoint origin)
|
RotateBoxState::SetOrigin(BPoint origin)
|
||||||
@@ -505,6 +540,7 @@ RotateBoxState::SetOrigin(BPoint origin)
|
|||||||
fOldAngle = fParent->LocalRotation();
|
fOldAngle = fParent->LocalRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DragTo
|
// DragTo
|
||||||
void
|
void
|
||||||
RotateBoxState::DragTo(BPoint current, uint32 modifiers)
|
RotateBoxState::DragTo(BPoint current, uint32 modifiers)
|
||||||
@@ -524,6 +560,7 @@ RotateBoxState::DragTo(BPoint current, uint32 modifiers)
|
|||||||
fParent->RotateBy(fParent->Center(), newAngle - fParent->LocalRotation());
|
fParent->RotateBy(fParent->Center(), newAngle - fParent->LocalRotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateViewCursor
|
// UpdateViewCursor
|
||||||
void
|
void
|
||||||
RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
||||||
@@ -531,8 +568,8 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
BPoint origin(fParent->Center());
|
BPoint origin(fParent->Center());
|
||||||
fParent->TransformToCanvas(origin);
|
fParent->TransformToCanvas(origin);
|
||||||
fParent->TransformToCanvas(current);
|
fParent->TransformToCanvas(current);
|
||||||
BPoint from = origin + BPoint(sinf(22.5 * 180.0 / PI) * 50.0,
|
BPoint from = origin + BPoint(sinf(22.5 * 180.0 / M_PI) * 50.0,
|
||||||
-cosf(22.5 * 180.0 / PI) * 50.0);
|
-cosf(22.5 * 180.0 / M_PI) * 50.0);
|
||||||
|
|
||||||
float rotation = calc_angle(origin, from, current) + 180.0;
|
float rotation = calc_angle(origin, from, current) + 180.0;
|
||||||
|
|
||||||
@@ -555,6 +592,7 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
RotateBoxState::ActionName() const
|
RotateBoxState::ActionName() const
|
||||||
@@ -562,6 +600,7 @@ RotateBoxState::ActionName() const
|
|||||||
return "Rotate";
|
return "Rotate";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
RotateBoxState::ActionNameIndex() const
|
RotateBoxState::ActionNameIndex() const
|
||||||
@@ -570,9 +609,9 @@ RotateBoxState::ActionNameIndex() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - OffsetCenterState
|
// #pragma mark - OffsetCenterState
|
||||||
|
|
||||||
|
|
||||||
// SetOrigin
|
// SetOrigin
|
||||||
void
|
void
|
||||||
OffsetCenterState::SetOrigin(BPoint origin)
|
OffsetCenterState::SetOrigin(BPoint origin)
|
||||||
@@ -591,6 +630,7 @@ OffsetCenterState::DragTo(BPoint current, uint32 modifiers)
|
|||||||
fOrigin = current;
|
fOrigin = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UpdateViewCursor
|
// UpdateViewCursor
|
||||||
void
|
void
|
||||||
OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
|
OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
|
||||||
@@ -598,6 +638,7 @@ OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
|
|||||||
_SetViewCursor(view, kPathMoveCursor);
|
_SetViewCursor(view, kPathMoveCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionName
|
// ActionName
|
||||||
const char*
|
const char*
|
||||||
OffsetCenterState::ActionName() const
|
OffsetCenterState::ActionName() const
|
||||||
@@ -605,11 +646,10 @@ OffsetCenterState::ActionName() const
|
|||||||
return "Move Pivot";
|
return "Move Pivot";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ActionNameIndex
|
// ActionNameIndex
|
||||||
uint32
|
uint32
|
||||||
OffsetCenterState::ActionNameIndex() const
|
OffsetCenterState::ActionNameIndex() const
|
||||||
{
|
{
|
||||||
return MOVE_PIVOT;
|
return MOVE_PIVOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -20,16 +20,17 @@
|
|||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
TransformGradientBox::TransformGradientBox(CanvasView* view,
|
TransformGradientBox::TransformGradientBox(CanvasView* view, Gradient* gradient,
|
||||||
Gradient* gradient,
|
Shape* parentShape)
|
||||||
Shape* parentShape)
|
:
|
||||||
: TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
|
TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
|
||||||
|
|
||||||
fCanvasView(view),
|
fCanvasView(view),
|
||||||
|
|
||||||
fShape(parentShape),
|
fShape(parentShape),
|
||||||
fGradient(gradient)
|
fGradient(gradient)
|
||||||
{
|
{
|
||||||
if (fShape) {
|
if (fShape) {
|
||||||
fShape->Acquire();
|
fShape->Acquire();
|
||||||
@@ -43,6 +44,7 @@ TransformGradientBox::TransformGradientBox(CanvasView* view,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
TransformGradientBox::~TransformGradientBox()
|
TransformGradientBox::~TransformGradientBox()
|
||||||
{
|
{
|
||||||
@@ -54,6 +56,7 @@ TransformGradientBox::~TransformGradientBox()
|
|||||||
fGradient->RemoveObserver(this);
|
fGradient->RemoveObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
void
|
void
|
||||||
TransformGradientBox::Update(bool deep)
|
TransformGradientBox::Update(bool deep)
|
||||||
@@ -87,6 +90,7 @@ TransformGradientBox::Update(bool deep)
|
|||||||
fGradient->AddObserver(this);
|
fGradient->AddObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ObjectChanged
|
// ObjectChanged
|
||||||
void
|
void
|
||||||
TransformGradientBox::ObjectChanged(const Observable* object)
|
TransformGradientBox::ObjectChanged(const Observable* object)
|
||||||
@@ -112,6 +116,7 @@ TransformGradientBox::ObjectChanged(const Observable* object)
|
|||||||
fView->UnlockLooper();
|
fView->UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Perform
|
// Perform
|
||||||
Command*
|
Command*
|
||||||
TransformGradientBox::Perform()
|
TransformGradientBox::Perform()
|
||||||
@@ -119,6 +124,7 @@ TransformGradientBox::Perform()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Cancel
|
// Cancel
|
||||||
Command*
|
Command*
|
||||||
TransformGradientBox::Cancel()
|
TransformGradientBox::Cancel()
|
||||||
@@ -128,6 +134,7 @@ TransformGradientBox::Cancel()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformFromCanvas
|
// TransformFromCanvas
|
||||||
void
|
void
|
||||||
TransformGradientBox::TransformFromCanvas(BPoint& point) const
|
TransformGradientBox::TransformFromCanvas(BPoint& point) const
|
||||||
@@ -137,6 +144,7 @@ TransformGradientBox::TransformFromCanvas(BPoint& point) const
|
|||||||
fCanvasView->ConvertFromCanvas(&point);
|
fCanvasView->ConvertFromCanvas(&point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TransformToCanvas
|
// TransformToCanvas
|
||||||
void
|
void
|
||||||
TransformGradientBox::TransformToCanvas(BPoint& point) const
|
TransformGradientBox::TransformToCanvas(BPoint& point) const
|
||||||
@@ -146,6 +154,7 @@ TransformGradientBox::TransformToCanvas(BPoint& point) const
|
|||||||
fShape->Transform(&point);
|
fShape->Transform(&point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ZoomLevel
|
// ZoomLevel
|
||||||
float
|
float
|
||||||
TransformGradientBox::ZoomLevel() const
|
TransformGradientBox::ZoomLevel() const
|
||||||
@@ -153,6 +162,7 @@ TransformGradientBox::ZoomLevel() const
|
|||||||
return fCanvasView->ZoomLevel();
|
return fCanvasView->ZoomLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ViewSpaceRotation
|
// ViewSpaceRotation
|
||||||
double
|
double
|
||||||
TransformGradientBox::ViewSpaceRotation() const
|
TransformGradientBox::ViewSpaceRotation() const
|
||||||
@@ -160,25 +170,19 @@ TransformGradientBox::ViewSpaceRotation() const
|
|||||||
Transformable t(*this);
|
Transformable t(*this);
|
||||||
if (fShape)
|
if (fShape)
|
||||||
t.Multiply(*fShape);
|
t.Multiply(*fShape);
|
||||||
return t.rotation() * 180.0 / PI;
|
return t.rotation() * 180.0 / M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MakeCommand
|
// MakeCommand
|
||||||
TransformCommand*
|
TransformCommand*
|
||||||
TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex)
|
TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex)
|
||||||
{
|
{
|
||||||
Transformable* objects[1];
|
Transformable* objects[1];
|
||||||
objects[0] = fGradient;
|
objects[0] = fGradient;
|
||||||
|
|
||||||
return new TransformObjectsCommand(this, objects, fOriginals, 1,
|
|
||||||
|
|
||||||
Pivot(),
|
return new TransformObjectsCommand(this, objects, fOriginals, 1, Pivot(),
|
||||||
Translation(),
|
Translation(), LocalRotation(), LocalXScale(), LocalYScale(), commandName,
|
||||||
LocalRotation(),
|
nameIndex);
|
||||||
LocalXScale(),
|
|
||||||
LocalYScale(),
|
|
||||||
|
|
||||||
commandName,
|
|
||||||
nameIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+253
-254
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -185,7 +185,7 @@ Transformable::Transform(BPoint* point) const
|
|||||||
double y = point->y;
|
double y = point->y;
|
||||||
|
|
||||||
transform(&x, &y);
|
transform(&x, &y);
|
||||||
|
|
||||||
point->x = x;
|
point->x = x;
|
||||||
point->y = y;
|
point->y = y;
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ Transformable::InverseTransform(BPoint* point) const
|
|||||||
double y = point->y;
|
double y = point->y;
|
||||||
|
|
||||||
inverse_transform(&x, &y);
|
inverse_transform(&x, &y);
|
||||||
|
|
||||||
point->x = x;
|
point->x = x;
|
||||||
point->y = y;
|
point->y = y;
|
||||||
}
|
}
|
||||||
@@ -235,13 +235,13 @@ inline float
|
|||||||
min4(float a, float b, float c, float d)
|
min4(float a, float b, float c, float d)
|
||||||
{
|
{
|
||||||
return min_c(a, min_c(b, min_c(c, d)));
|
return min_c(a, min_c(b, min_c(c, d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float
|
inline float
|
||||||
max4(float a, float b, float c, float d)
|
max4(float a, float b, float c, float d)
|
||||||
{
|
{
|
||||||
return max_c(a, max_c(b, max_c(c, d)));
|
return max_c(a, max_c(b, max_c(c, d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransformBounds
|
// TransformBounds
|
||||||
BRect
|
BRect
|
||||||
@@ -252,12 +252,12 @@ Transformable::TransformBounds(BRect bounds) const
|
|||||||
BPoint rt(bounds.right, bounds.top);
|
BPoint rt(bounds.right, bounds.top);
|
||||||
BPoint lb(bounds.left, bounds.bottom);
|
BPoint lb(bounds.left, bounds.bottom);
|
||||||
BPoint rb(bounds.right, bounds.bottom);
|
BPoint rb(bounds.right, bounds.bottom);
|
||||||
|
|
||||||
Transform(<);
|
Transform(<);
|
||||||
Transform(&rt);
|
Transform(&rt);
|
||||||
Transform(&lb);
|
Transform(&lb);
|
||||||
Transform(&rb);
|
Transform(&rb);
|
||||||
|
|
||||||
return BRect(floorf(min4(lt.x, rt.x, lb.x, rb.x)),
|
return BRect(floorf(min4(lt.x, rt.x, lb.x, rb.x)),
|
||||||
floorf(min4(lt.y, rt.y, lb.y, rb.y)),
|
floorf(min4(lt.y, rt.y, lb.y, rb.y)),
|
||||||
ceilf(max4(lt.x, rt.x, lb.x, rb.x)),
|
ceilf(max4(lt.x, rt.x, lb.x, rb.x)),
|
||||||
@@ -282,7 +282,7 @@ Transformable::RotateBy(BPoint origin, double degrees)
|
|||||||
{
|
{
|
||||||
if (degrees != 0.0) {
|
if (degrees != 0.0) {
|
||||||
multiply(agg::trans_affine_translation(-origin.x, -origin.y));
|
multiply(agg::trans_affine_translation(-origin.x, -origin.y));
|
||||||
multiply(agg::trans_affine_rotation(degrees * (PI / 180.0)));
|
multiply(agg::trans_affine_rotation(degrees * (M_PI / 180.0)));
|
||||||
multiply(agg::trans_affine_translation(origin.x, origin.y));
|
multiply(agg::trans_affine_translation(origin.x, origin.y));
|
||||||
TransformationChanged();
|
TransformationChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2006, Haiku.
|
* Copyright 2003-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -28,7 +28,8 @@ static const float kStopSize = 15.0f;
|
|||||||
|
|
||||||
ScreenCornerSelector::ScreenCornerSelector(BRect frame, const char *name,
|
ScreenCornerSelector::ScreenCornerSelector(BRect frame, const char *name,
|
||||||
BMessage* message, uint32 resizingMode)
|
BMessage* message, uint32 resizingMode)
|
||||||
: BControl(frame, name, NULL, message, resizingMode, B_WILL_DRAW | B_NAVIGABLE),
|
: BControl(frame, name, NULL, message, resizingMode,
|
||||||
|
B_WILL_DRAW | B_NAVIGABLE),
|
||||||
fCurrentCorner(NO_CORNER),
|
fCurrentCorner(NO_CORNER),
|
||||||
fPreviousCorner(-1)
|
fPreviousCorner(-1)
|
||||||
{
|
{
|
||||||
@@ -47,7 +48,8 @@ ScreenCornerSelector::_MonitorFrame() const
|
|||||||
else if (height * kAspectRatio > width)
|
else if (height * kAspectRatio > width)
|
||||||
height = width / kAspectRatio;
|
height = width / kAspectRatio;
|
||||||
|
|
||||||
return BRect((Bounds().Width() - width) / 2, (Bounds().Height() - height) / 2,
|
return BRect((Bounds().Width() - width) / 2,
|
||||||
|
(Bounds().Height() - height) / 2,
|
||||||
(Bounds().Width() + width) / 2, (Bounds().Height() + height) / 2);
|
(Bounds().Width() + width) / 2, (Bounds().Height() + height) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +70,7 @@ ScreenCornerSelector::_CenterFrame(BRect innerFrame) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::Draw(BRect update)
|
ScreenCornerSelector::Draw(BRect update)
|
||||||
{
|
{
|
||||||
rgb_color darkColor = {160, 160, 160, 255};
|
rgb_color darkColor = {160, 160, 160, 255};
|
||||||
rgb_color blackColor = {0, 0, 0, 255};
|
rgb_color blackColor = {0, 0, 0, 255};
|
||||||
@@ -82,36 +84,39 @@ ScreenCornerSelector::Draw(BRect update)
|
|||||||
|
|
||||||
if (!_InnerFrame(outerRect).Contains(update)) {
|
if (!_InnerFrame(outerRect).Contains(update)) {
|
||||||
// frame & background
|
// frame & background
|
||||||
|
|
||||||
// if the focus is changing, we don't redraw the whole view, but only
|
// if the focus is changing, we don't redraw the whole view, but only
|
||||||
// the part that's affected by the change
|
// the part that's affected by the change
|
||||||
if (!IsFocusChanging()) {
|
if (!IsFocusChanging()) {
|
||||||
SetHighColor(darkColor);
|
SetHighColor(darkColor);
|
||||||
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
|
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
|
||||||
|
kMonitorBorderSize * 3 / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsFocus() && Window()->IsActive())
|
if (IsFocus() && Window()->IsActive())
|
||||||
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
||||||
else
|
else
|
||||||
SetHighColor(blackColor);
|
SetHighColor(blackColor);
|
||||||
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
|
|
||||||
|
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
|
||||||
|
kMonitorBorderSize * 3 / 2);
|
||||||
|
|
||||||
if (!IsFocusChanging()) {
|
if (!IsFocusChanging()) {
|
||||||
SetHighColor(210, 210, 255);
|
SetHighColor(210, 210, 255);
|
||||||
FillRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
|
FillRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsFocus() && Window()->IsActive())
|
if (IsFocus() && Window()->IsActive())
|
||||||
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
||||||
else
|
else
|
||||||
SetHighColor(blackColor);
|
SetHighColor(blackColor);
|
||||||
StrokeRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
|
StrokeRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
|
||||||
|
|
||||||
if (IsFocusChanging())
|
if (IsFocusChanging())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// power light
|
// power light
|
||||||
|
|
||||||
SetHighColor(redColor);
|
SetHighColor(redColor);
|
||||||
BPoint powerPos(outerRect.left + kMonitorBorderSize * 2, outerRect.bottom
|
BPoint powerPos(outerRect.left + kMonitorBorderSize * 2, outerRect.bottom
|
||||||
- kMonitorBorderSize);
|
- kMonitorBorderSize);
|
||||||
@@ -175,7 +180,7 @@ ScreenCornerSelector::SetCorner(screen_corner corner)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::_DrawStop(BRect innerFrame)
|
ScreenCornerSelector::_DrawStop(BRect innerFrame)
|
||||||
{
|
{
|
||||||
BRect centerRect = _CenterFrame(innerFrame);
|
BRect centerRect = _CenterFrame(innerFrame);
|
||||||
float size = kStopSize;
|
float size = kStopSize;
|
||||||
@@ -188,13 +193,13 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
|
|||||||
rect.left = centerRect.left + (centerRect.Width() - size) / 2;
|
rect.left = centerRect.left + (centerRect.Width() - size) / 2;
|
||||||
}
|
}
|
||||||
rect.right = rect.left + size - 1;
|
rect.right = rect.left + size - 1;
|
||||||
rect.bottom = rect.top + size - 1;
|
rect.bottom = rect.top + size - 1;
|
||||||
|
|
||||||
SetHighColor(255, 0, 0);
|
SetHighColor(255, 0, 0);
|
||||||
SetPenSize(2);
|
SetPenSize(2);
|
||||||
StrokeEllipse(rect);
|
StrokeEllipse(rect);
|
||||||
|
|
||||||
size -= ceilf(sin(PI / 4) * size + 2);
|
size -= ceilf(sin(M_PI / 4) * size + 2);
|
||||||
rect.InsetBy(size, size);
|
rect.InsetBy(size, size);
|
||||||
StrokeLine(rect.RightTop(), rect.LeftBottom());
|
StrokeLine(rect.RightTop(), rect.LeftBottom());
|
||||||
|
|
||||||
@@ -203,11 +208,13 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::_DrawArrow(BRect innerFrame)
|
ScreenCornerSelector::_DrawArrow(BRect innerFrame)
|
||||||
{
|
{
|
||||||
float size = kArrowSize;
|
float size = kArrowSize;
|
||||||
float sizeX = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
|
float sizeX = fCurrentCorner == UP_LEFT_CORNER
|
||||||
float sizeY = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
|
|| fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
|
||||||
|
float sizeY = fCurrentCorner == UP_LEFT_CORNER
|
||||||
|
|| fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
|
||||||
|
|
||||||
innerFrame.InsetBy(2, 2);
|
innerFrame.InsetBy(2, 2);
|
||||||
BPoint origin(sizeX < 0 ? innerFrame.right : innerFrame.left,
|
BPoint origin(sizeX < 0 ? innerFrame.right : innerFrame.left,
|
||||||
@@ -220,7 +227,8 @@ ScreenCornerSelector::_DrawArrow(BRect innerFrame)
|
|||||||
|
|
||||||
|
|
||||||
screen_corner
|
screen_corner
|
||||||
ScreenCornerSelector::_ScreenCorner(BPoint point, screen_corner previousCorner) const
|
ScreenCornerSelector::_ScreenCorner(BPoint point,
|
||||||
|
screen_corner previousCorner) const
|
||||||
{
|
{
|
||||||
BRect innerFrame = _InnerFrame(_MonitorFrame());
|
BRect innerFrame = _InnerFrame(_MonitorFrame());
|
||||||
|
|
||||||
@@ -240,7 +248,7 @@ ScreenCornerSelector::_ScreenCorner(BPoint point, screen_corner previousCorner)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::MouseDown(BPoint where)
|
ScreenCornerSelector::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
fPreviousCorner = Value();
|
fPreviousCorner = Value();
|
||||||
|
|
||||||
@@ -250,14 +258,15 @@ ScreenCornerSelector::MouseDown(BPoint where)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::MouseUp(BPoint where)
|
ScreenCornerSelector::MouseUp(BPoint where)
|
||||||
{
|
{
|
||||||
fPreviousCorner = -1;
|
fPreviousCorner = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit,
|
||||||
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
if (fPreviousCorner == -1)
|
if (fPreviousCorner == -1)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -10,73 +10,70 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AnalogClock.h"
|
#include "AnalogClock.h"
|
||||||
#include "TimeMessages.h"
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include "TimeMessages.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define DRAG_DELTA_PHI 0.2
|
#define DRAG_DELTA_PHI 0.2
|
||||||
|
|
||||||
|
|
||||||
class OffscreenClock : public BView {
|
class OffscreenClock : public BView {
|
||||||
public:
|
public:
|
||||||
OffscreenClock(BRect frame, const char *name);
|
OffscreenClock(BRect frame, const char *name);
|
||||||
~OffscreenClock();
|
virtual ~OffscreenClock();
|
||||||
|
|
||||||
void SetTime(int32 hour, int32 minute, int32 second);
|
void SetTime(int32 hour, int32 minute, int32 second);
|
||||||
void GetTime(int32 *hour, int32 *minute, int32 *second);
|
void GetTime(int32 *hour, int32 *minute, int32 *second);
|
||||||
bool IsDirty() const { return fDirty; }
|
bool IsDirty() const { return fDirty; }
|
||||||
void DrawClock();
|
void DrawClock();
|
||||||
|
|
||||||
bool InHourHand(BPoint point);
|
bool InHourHand(BPoint point);
|
||||||
bool InMinuteHand(BPoint point);
|
bool InMinuteHand(BPoint point);
|
||||||
|
|
||||||
void SetHourHand(BPoint point);
|
|
||||||
void SetMinuteHand(BPoint point);
|
|
||||||
|
|
||||||
void SetHourDragging(bool val) {
|
void SetHourHand(BPoint point);
|
||||||
fHourDragging = val;
|
void SetMinuteHand(BPoint point);
|
||||||
fDirty = true;
|
|
||||||
}
|
|
||||||
void SetMinuteDragging(bool val) {
|
|
||||||
fMinuteDragging = val;
|
|
||||||
fDirty = true;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
float _GetPhi(BPoint point);
|
|
||||||
bool _InHand(BPoint point, int32 ticks, float radius);
|
|
||||||
void _DrawHands(float x, float y, float radius,
|
|
||||||
rgb_color hourHourColor,
|
|
||||||
rgb_color hourMinuteColor,
|
|
||||||
rgb_color secondsColor,
|
|
||||||
rgb_color knobColor);
|
|
||||||
|
|
||||||
int32 fHours;
|
void SetHourDragging(bool dragging);
|
||||||
int32 fMinutes;
|
void SetMinuteDragging(bool dragging);
|
||||||
int32 fSeconds;
|
|
||||||
bool fDirty;
|
|
||||||
|
|
||||||
float fCenterX;
|
private:
|
||||||
float fCenterY;
|
float _GetPhi(BPoint point);
|
||||||
float fRadius;
|
bool _InHand(BPoint point, int32 ticks, float radius);
|
||||||
|
void _DrawHands(float x, float y, float radius,
|
||||||
|
rgb_color hourHourColor,
|
||||||
|
rgb_color hourMinuteColor,
|
||||||
|
rgb_color secondsColor, rgb_color knobColor);
|
||||||
|
|
||||||
bool fHourDragging;
|
int32 fHours;
|
||||||
bool fMinuteDragging;
|
int32 fMinutes;
|
||||||
|
int32 fSeconds;
|
||||||
|
bool fDirty;
|
||||||
|
|
||||||
|
float fCenterX;
|
||||||
|
float fCenterY;
|
||||||
|
float fRadius;
|
||||||
|
|
||||||
|
bool fHourDragging;
|
||||||
|
bool fMinuteDragging;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
OffscreenClock::OffscreenClock(BRect frame, const char *name)
|
OffscreenClock::OffscreenClock(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
|
:
|
||||||
fHours(0),
|
BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
|
||||||
fMinutes(0),
|
fHours(0),
|
||||||
fSeconds(0),
|
fMinutes(0),
|
||||||
fDirty(true),
|
fSeconds(0),
|
||||||
fHourDragging(false),
|
fDirty(true),
|
||||||
fMinuteDragging(false)
|
fHourDragging(false),
|
||||||
|
fMinuteDragging(false)
|
||||||
{
|
{
|
||||||
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
|
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
|
||||||
|
|
||||||
@@ -131,9 +128,9 @@ OffscreenClock::DrawClock()
|
|||||||
SetHighColor(background);
|
SetHighColor(background);
|
||||||
FillRect(bounds);
|
FillRect(bounds);
|
||||||
|
|
||||||
|
|
||||||
bounds.Set(fCenterX - fRadius, fCenterY - fRadius,
|
bounds.Set(fCenterX - fRadius, fCenterY - fRadius,
|
||||||
fCenterX + fRadius, fCenterY + fRadius);
|
fCenterX + fRadius, fCenterY + fRadius);
|
||||||
|
|
||||||
SetPenSize(2.0);
|
SetPenSize(2.0);
|
||||||
|
|
||||||
@@ -148,7 +145,7 @@ OffscreenClock::DrawClock()
|
|||||||
|
|
||||||
SetLowColor(255, 255, 255);
|
SetLowColor(255, 255, 255);
|
||||||
FillEllipse(bounds, B_SOLID_LOW);
|
FillEllipse(bounds, B_SOLID_LOW);
|
||||||
|
|
||||||
SetHighColor(tint_color(HighColor(), B_DARKEN_2_TINT));
|
SetHighColor(tint_color(HighColor(), B_DARKEN_2_TINT));
|
||||||
|
|
||||||
// minutes
|
// minutes
|
||||||
@@ -157,10 +154,10 @@ OffscreenClock::DrawClock()
|
|||||||
for (int32 minute = 1; minute < 60; minute++) {
|
for (int32 minute = 1; minute < 60; minute++) {
|
||||||
if (minute % 5 == 0)
|
if (minute % 5 == 0)
|
||||||
continue;
|
continue;
|
||||||
float x1 = fCenterX + sinf(minute * PI / 30.0) * fRadius;
|
float x1 = fCenterX + sinf(minute * M_PI / 30.0) * fRadius;
|
||||||
float y1 = fCenterY + cosf(minute * PI / 30.0) * fRadius;
|
float y1 = fCenterY + cosf(minute * M_PI / 30.0) * fRadius;
|
||||||
float x2 = fCenterX + sinf(minute * PI / 30.0) * (fRadius * 0.95);
|
float x2 = fCenterX + sinf(minute * M_PI / 30.0) * (fRadius * 0.95);
|
||||||
float y2 = fCenterY + cosf(minute * PI / 30.0) * (fRadius * 0.95);
|
float y2 = fCenterY + cosf(minute * M_PI / 30.0) * (fRadius * 0.95);
|
||||||
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
|
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,10 +167,10 @@ OffscreenClock::DrawClock()
|
|||||||
SetPenSize(2.0);
|
SetPenSize(2.0);
|
||||||
SetLineMode(B_ROUND_CAP, B_MITER_JOIN);
|
SetLineMode(B_ROUND_CAP, B_MITER_JOIN);
|
||||||
for (int32 hour = 0; hour < 12; hour++) {
|
for (int32 hour = 0; hour < 12; hour++) {
|
||||||
float x1 = fCenterX + sinf(hour * PI / 6.0) * fRadius;
|
float x1 = fCenterX + sinf(hour * M_PI / 6.0) * fRadius;
|
||||||
float y1 = fCenterY + cosf(hour * PI / 6.0) * fRadius;
|
float y1 = fCenterY + cosf(hour * M_PI / 6.0) * fRadius;
|
||||||
float x2 = fCenterX + sinf(hour * PI / 6.0) * (fRadius * 0.9);
|
float x2 = fCenterX + sinf(hour * M_PI / 6.0) * (fRadius * 0.9);
|
||||||
float y2 = fCenterY + cosf(hour * PI / 6.0) * (fRadius * 0.9);
|
float y2 = fCenterY + cosf(hour * M_PI / 6.0) * (fRadius * 0.9);
|
||||||
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
|
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,19 +180,21 @@ OffscreenClock::DrawClock()
|
|||||||
hourColor = (rgb_color){ 0, 0, 255, 255 };
|
hourColor = (rgb_color){ 0, 0, 255, 255 };
|
||||||
else
|
else
|
||||||
hourColor = tint_color(HighColor(), B_DARKEN_2_TINT);
|
hourColor = tint_color(HighColor(), B_DARKEN_2_TINT);
|
||||||
|
|
||||||
rgb_color minuteColor;
|
rgb_color minuteColor;
|
||||||
if (fMinuteDragging)
|
if (fMinuteDragging)
|
||||||
minuteColor = (rgb_color){ 0, 0, 255, 255 };
|
minuteColor = (rgb_color){ 0, 0, 255, 255 };
|
||||||
else
|
else
|
||||||
minuteColor = tint_color(HighColor(), B_DARKEN_2_TINT);
|
minuteColor = tint_color(HighColor(), B_DARKEN_2_TINT);
|
||||||
|
|
||||||
rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 };
|
rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 };
|
||||||
rgb_color shadowColor = tint_color(LowColor(),
|
rgb_color shadowColor = tint_color(LowColor(),
|
||||||
(B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2);
|
(B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2);
|
||||||
|
|
||||||
_DrawHands(fCenterX + 1.5, fCenterY + 1.5, fRadius,
|
_DrawHands(fCenterX + 1.5, fCenterY + 1.5, fRadius,
|
||||||
shadowColor, shadowColor, shadowColor, shadowColor);
|
shadowColor, shadowColor, shadowColor, shadowColor);
|
||||||
_DrawHands(fCenterX, fCenterY, fRadius,
|
_DrawHands(fCenterX, fCenterY, fRadius,
|
||||||
hourColor, minuteColor, secondsColor, knobColor);
|
hourColor, minuteColor, secondsColor, knobColor);
|
||||||
|
|
||||||
Sync();
|
Sync();
|
||||||
|
|
||||||
@@ -231,7 +230,7 @@ OffscreenClock::SetHourHand(BPoint point)
|
|||||||
point.y -= fCenterY;
|
point.y -= fCenterY;
|
||||||
|
|
||||||
float pointPhi = _GetPhi(point);
|
float pointPhi = _GetPhi(point);
|
||||||
float hoursExact = 6.0 * pointPhi / PI;
|
float hoursExact = 6.0 * pointPhi / M_PI;
|
||||||
if (fHours >= 12)
|
if (fHours >= 12)
|
||||||
fHours = 12;
|
fHours = 12;
|
||||||
else
|
else
|
||||||
@@ -249,50 +248,67 @@ OffscreenClock::SetMinuteHand(BPoint point)
|
|||||||
point.y -= fCenterY;
|
point.y -= fCenterY;
|
||||||
|
|
||||||
float pointPhi = _GetPhi(point);
|
float pointPhi = _GetPhi(point);
|
||||||
float minutesExact = 30.0 * pointPhi / PI;
|
float minutesExact = 30.0 * pointPhi / M_PI;
|
||||||
fMinutes = int32(ceilf(minutesExact));
|
fMinutes = int32(ceilf(minutesExact));
|
||||||
|
|
||||||
SetTime(fHours, fMinutes, fSeconds);
|
SetTime(fHours, fMinutes, fSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
OffscreenClock::SetHourDragging(bool dragging)
|
||||||
|
{
|
||||||
|
fHourDragging = dragging;
|
||||||
|
fDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
OffscreenClock::SetMinuteDragging(bool dragging)
|
||||||
|
{
|
||||||
|
fMinuteDragging = dragging;
|
||||||
|
fDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
OffscreenClock::_GetPhi(BPoint point)
|
OffscreenClock::_GetPhi(BPoint point)
|
||||||
{
|
{
|
||||||
if (point.x == 0 && point.y < 0)
|
if (point.x == 0 && point.y < 0)
|
||||||
return 2 * PI;
|
return 2 * M_PI;
|
||||||
if (point.x == 0 && point.y > 0)
|
if (point.x == 0 && point.y > 0)
|
||||||
return PI;
|
return M_PI;
|
||||||
if (point.y == 0 && point.x < 0)
|
if (point.y == 0 && point.x < 0)
|
||||||
return PI * 3 / 2;
|
return M_PI * 3 / 2;
|
||||||
if (point.y == 0 && point.x > 0)
|
if (point.y == 0 && point.x > 0)
|
||||||
return PI / 2;
|
return M_PI / 2;
|
||||||
|
|
||||||
float pointPhi = atanf(-1. * point.y / point.x);
|
float pointPhi = atanf(-1. * point.y / point.x);
|
||||||
if (point.y < 0. && point.x > 0.) // right upper corner
|
if (point.y < 0. && point.x > 0.) // right upper corner
|
||||||
pointPhi = PI / 2. - pointPhi;
|
pointPhi = M_PI / 2. - pointPhi;
|
||||||
if (point.y > 0. && point.x > 0.) // right lower corner
|
if (point.y > 0. && point.x > 0.) // right lower corner
|
||||||
pointPhi = PI / 2 - pointPhi;
|
pointPhi = M_PI / 2 - pointPhi;
|
||||||
if (point.y > 0. && point.x < 0.) // left lower corner
|
if (point.y > 0. && point.x < 0.) // left lower corner
|
||||||
pointPhi = (PI * 3. / 2. - pointPhi);
|
pointPhi = (M_PI * 3. / 2. - pointPhi);
|
||||||
if (point.y < 0. && point.x < 0.) // left upper corner
|
if (point.y < 0. && point.x < 0.) // left upper corner
|
||||||
pointPhi = 3. / 2. * PI - pointPhi;
|
pointPhi = 3. / 2. * M_PI - pointPhi;
|
||||||
return pointPhi;
|
return pointPhi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
|
OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
|
||||||
{
|
{
|
||||||
point.x -= fCenterX;
|
point.x -= fCenterX;
|
||||||
point.y -= fCenterY;
|
point.y -= fCenterY;
|
||||||
|
|
||||||
float pRadius = sqrt(pow(point.x, 2) + pow(point.y, 2));
|
float pRadius = sqrt(pow(point.x, 2) + pow(point.y, 2));
|
||||||
|
|
||||||
if (radius < pRadius)
|
if (radius < pRadius)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float pointPhi = _GetPhi(point);
|
float pointPhi = _GetPhi(point);
|
||||||
float handPhi = PI / 30.0 * ticks;
|
float handPhi = M_PI / 30.0 * ticks;
|
||||||
float delta = pointPhi - handPhi;
|
float delta = pointPhi - handPhi;
|
||||||
if (fabs(delta) > DRAG_DELTA_PHI)
|
if (fabs(delta) > DRAG_DELTA_PHI)
|
||||||
return false;
|
return false;
|
||||||
@@ -315,23 +331,23 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
|
|||||||
SetHighColor(hourColor);
|
SetHighColor(hourColor);
|
||||||
SetPenSize(4.0);
|
SetPenSize(4.0);
|
||||||
float hours = fHours + float(fMinutes) / 60.0;
|
float hours = fHours + float(fMinutes) / 60.0;
|
||||||
offsetX = (radius * 0.7) * sinf((hours * PI) / 6.0);
|
offsetX = (radius * 0.7) * sinf((hours * M_PI) / 6.0);
|
||||||
offsetY = (radius * 0.7) * cosf((hours * PI) / 6.0);
|
offsetY = (radius * 0.7) * cosf((hours * M_PI) / 6.0);
|
||||||
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
||||||
|
|
||||||
// calc, draw minute hand
|
// calc, draw minute hand
|
||||||
SetHighColor(minuteColor);
|
SetHighColor(minuteColor);
|
||||||
SetPenSize(3.0);
|
SetPenSize(3.0);
|
||||||
float minutes = fMinutes + float(fSeconds) / 60.0;
|
float minutes = fMinutes + float(fSeconds) / 60.0;
|
||||||
offsetX = (radius * 0.9) * sinf((minutes * PI) / 30.0);
|
offsetX = (radius * 0.9) * sinf((minutes * M_PI) / 30.0);
|
||||||
offsetY = (radius * 0.9) * cosf((minutes * PI) / 30.0);
|
offsetY = (radius * 0.9) * cosf((minutes * M_PI) / 30.0);
|
||||||
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
||||||
|
|
||||||
// calc, draw second hand
|
// calc, draw second hand
|
||||||
SetHighColor(secondsColor);
|
SetHighColor(secondsColor);
|
||||||
SetPenSize(1.0);
|
SetPenSize(1.0);
|
||||||
offsetX = (radius * 0.95) * sinf((fSeconds * PI) / 30.0);
|
offsetX = (radius * 0.95) * sinf((fSeconds * M_PI) / 30.0);
|
||||||
offsetY = (radius * 0.95) * cosf((fSeconds * PI) / 30.0);
|
offsetY = (radius * 0.95) * cosf((fSeconds * M_PI) / 30.0);
|
||||||
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
|
||||||
|
|
||||||
// draw the center knob
|
// draw the center knob
|
||||||
@@ -344,7 +360,8 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
|
|||||||
|
|
||||||
|
|
||||||
TAnalogClock::TAnalogClock(BRect frame, const char *name)
|
TAnalogClock::TAnalogClock(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
|
:
|
||||||
|
BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
|
||||||
fBitmap(NULL),
|
fBitmap(NULL),
|
||||||
fClock(NULL),
|
fClock(NULL),
|
||||||
fDraggingHourHand(false),
|
fDraggingHourHand(false),
|
||||||
@@ -429,6 +446,7 @@ TAnalogClock::MouseDown(BPoint point)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TAnalogClock::MouseUp(BPoint point)
|
TAnalogClock::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -452,7 +470,7 @@ TAnalogClock::MouseUp(BPoint point)
|
|||||||
void
|
void
|
||||||
TAnalogClock::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
|
TAnalogClock::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fDraggingMinuteHand)
|
if (fDraggingMinuteHand)
|
||||||
fClock->SetMinuteHand(point);
|
fClock->SetMinuteHand(point);
|
||||||
if (fDraggingHourHand)
|
if (fDraggingHourHand)
|
||||||
@@ -482,7 +500,7 @@ TAnalogClock::SetTime(int32 hour, int32 minute, int32 second)
|
|||||||
|
|
||||||
if (fClock)
|
if (fClock)
|
||||||
fClock->SetTime(hour, minute, second);
|
fClock->SetTime(hour, minute, second);
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2008, Haiku.
|
* Copyright 2001-2009, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -881,8 +881,8 @@ ServerFont::EmbeddedTransformation() const
|
|||||||
// TODO: cache this?
|
// TODO: cache this?
|
||||||
Transformable transform;
|
Transformable transform;
|
||||||
|
|
||||||
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * PI / 180.0, 0.0);
|
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * M_PI / 180.0, 0.0);
|
||||||
transform.RotateBy(B_ORIGIN, -fRotation * PI / 180.0);
|
transform.RotateBy(B_ORIGIN, -fRotation * M_PI / 180.0);
|
||||||
|
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ AGGTextRenderer::SetFont(const ServerFont& font)
|
|||||||
// construct an embedded transformation (rotate & shear)
|
// construct an embedded transformation (rotate & shear)
|
||||||
fEmbeddedTransformation.Reset();
|
fEmbeddedTransformation.Reset();
|
||||||
fEmbeddedTransformation.ShearBy(B_ORIGIN,
|
fEmbeddedTransformation.ShearBy(B_ORIGIN,
|
||||||
(90.0 - font.Shear()) * PI / 180.0, 0.0);
|
(90.0 - font.Shear()) * M_PI / 180.0, 0.0);
|
||||||
fEmbeddedTransformation.RotateBy(B_ORIGIN,
|
fEmbeddedTransformation.RotateBy(B_ORIGIN,
|
||||||
-font.Rotation() * PI / 180.0);
|
-font.Rotation() * M_PI / 180.0);
|
||||||
|
|
||||||
fContour.width(font.FalseBoldWidth() * 2.0);
|
fContour.width(font.FalseBoldWidth() * 2.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ using std::nothrow;
|
|||||||
#define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1);
|
#define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1);
|
||||||
#define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return;
|
#define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return;
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
Painter::Painter()
|
Painter::Painter()
|
||||||
:
|
:
|
||||||
@@ -1222,7 +1223,7 @@ Painter::DrawEllipse(BRect r, bool fill) const
|
|||||||
float yRadius = r.Height() / 2.0;
|
float yRadius = r.Height() / 2.0;
|
||||||
BPoint center(r.left + xRadius, r.top + yRadius);
|
BPoint center(r.left + xRadius, r.top + yRadius);
|
||||||
|
|
||||||
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * PI / 2);
|
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * M_PI / 2);
|
||||||
if (divisions < 12)
|
if (divisions < 12)
|
||||||
divisions = 12;
|
divisions = 12;
|
||||||
if (divisions > 4096)
|
if (divisions > 4096)
|
||||||
@@ -1295,7 +1296,7 @@ Painter::FillEllipse(BRect r, const BGradient& gradient) const
|
|||||||
float yRadius = r.Height() / 2.0;
|
float yRadius = r.Height() / 2.0;
|
||||||
BPoint center(r.left + xRadius, r.top + yRadius);
|
BPoint center(r.left + xRadius, r.top + yRadius);
|
||||||
|
|
||||||
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * PI / 2);
|
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * M_PI / 2);
|
||||||
if (divisions < 12)
|
if (divisions < 12)
|
||||||
divisions = 12;
|
divisions = 12;
|
||||||
if (divisions > 4096)
|
if (divisions > 4096)
|
||||||
@@ -1316,8 +1317,8 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius, float angle,
|
|||||||
|
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
|
|
||||||
double angleRad = (angle * PI) / 180.0;
|
double angleRad = (angle * M_PI) / 180.0;
|
||||||
double spanRad = (span * PI) / 180.0;
|
double spanRad = (span * M_PI) / 180.0;
|
||||||
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
||||||
-spanRad);
|
-spanRad);
|
||||||
|
|
||||||
@@ -1337,8 +1338,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
|
|||||||
|
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
|
|
||||||
double angleRad = (angle * PI) / 180.0;
|
double angleRad = (angle * M_PI) / 180.0;
|
||||||
double spanRad = (span * PI) / 180.0;
|
double spanRad = (span * M_PI) / 180.0;
|
||||||
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
||||||
-spanRad);
|
-spanRad);
|
||||||
|
|
||||||
@@ -1374,8 +1375,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
|
|||||||
|
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
|
|
||||||
double angleRad = (angle * PI) / 180.0;
|
double angleRad = (angle * M_PI) / 180.0;
|
||||||
double spanRad = (span * PI) / 180.0;
|
double spanRad = (span * M_PI) / 180.0;
|
||||||
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
|
||||||
-spanRad);
|
-spanRad);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user