* 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:
Axel Dörfler 2009-06-26 11:58:43 +00:00
parent 29aec87efb
commit 7f5bbbdc56
20 changed files with 1840 additions and 1849 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License.
*/
#ifndef _MATH_H_
@ -20,9 +20,6 @@
#define M_SQRT2 1.41421356237309504880 /* 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 */
#define __HUGE_VAL_v 0x7ff0000000000000LL
#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 (((__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 (((__huge_valf_t) { __l: __NAN_VALF_v }).__f)
@ -79,149 +76,149 @@ extern "C" {
#endif
/* float math functions */
extern float acosf(float x);
extern float acoshf(float x);
extern float asinf(float x);
extern float asinhf(float x);
extern float atan2f(float y, float x);
extern float atanf(float x);
extern float atanhf(float x);
extern float cbrtf(float x);
extern float ceilf(float x);
extern float cosf(float x);
extern float coshf(float x);
extern float expf(float x);
extern float expm1f(float x);
extern float fabsf(float x);
extern float floorf(float x);
extern float fmodf(float x, float y);
extern float frexpf(float x, int *_exponent);
extern float gammaf(float x);
extern float hypotf(float x, float y);
extern float ldexpf(float x, int exponent);
extern float lgammaf(float x);
extern long long llrintf(float x);
extern float log10f(float x);
extern float log1pf(float x);
extern float logbf(float x);
extern float logf(float x);
extern long lrintf(float x);
extern long lroundf(float x);
extern float modff(float x, float *y);
extern float nearbyintf(float x);
extern float powf(float x, float y);
extern float remquof(float x, float y, int *quo);
extern float roundf(float x);
extern float sinf(float x);
extern float sinhf(float x);
extern float sqrtf(float x);
extern float tanf(float x);
extern float tanhf(float x);
extern float acosf(float x);
extern float acoshf(float x);
extern float asinf(float x);
extern float asinhf(float x);
extern float atan2f(float y, float x);
extern float atanf(float x);
extern float atanhf(float x);
extern float cbrtf(float x);
extern float ceilf(float x);
extern float cosf(float x);
extern float coshf(float x);
extern float expf(float x);
extern float expm1f(float x);
extern float fabsf(float x);
extern float floorf(float x);
extern float fmodf(float x, float y);
extern float frexpf(float x, int *_exponent);
extern float gammaf(float x);
extern float hypotf(float x, float y);
extern float ldexpf(float x, int exponent);
extern float lgammaf(float x);
extern long long llrintf(float x);
extern float log10f(float x);
extern float log1pf(float x);
extern float logbf(float x);
extern float logf(float x);
extern long lrintf(float x);
extern long lroundf(float x);
extern float modff(float x, float *y);
extern float nearbyintf(float x);
extern float powf(float x, float y);
extern float remquof(float x, float y, int *quo);
extern float roundf(float x);
extern float sinf(float x);
extern float sinhf(float x);
extern float sqrtf(float x);
extern float tanf(float x);
extern float tanhf(float x);
/* double math functions */
extern double acos(double x);
extern double acosh(double x);
extern double asin(double x);
extern double asinh(double x);
extern double atan(double x);
extern double atan2(double x, double y);
extern double atanh(double x);
extern double ceil(double x);
extern double cos(double x);
extern double cosh(double x);
extern double exp(double x);
extern double fabs(double x);
extern double floor(double x);
extern double fmod(double x, double y);
extern double frexp(double x, int *_exponent);
extern double gamma(double x);
extern double ldexp(double x, int exponent);
extern double lgamma(double x);
extern long long llrint(double x);
extern double log(double x);
extern double log10(double x);
extern long lrint(double x);
extern long lround(double x);
extern double modf(double x, double *y);
extern double nearbyint(double x);
extern double pow(double x, double y);
extern double remquo(double x, double y, int *quo);
extern double round(double x);
extern double sin(double x);
extern double sinh(double x);
extern double sqrt(double x);
extern double tan(double x);
extern double tanh(double x);
extern double trunc(double x);
extern double acos(double x);
extern double acosh(double x);
extern double asin(double x);
extern double asinh(double x);
extern double atan(double x);
extern double atan2(double x, double y);
extern double atanh(double x);
extern double ceil(double x);
extern double cos(double x);
extern double cosh(double x);
extern double exp(double x);
extern double fabs(double x);
extern double floor(double x);
extern double fmod(double x, double y);
extern double frexp(double x, int *_exponent);
extern double gamma(double x);
extern double ldexp(double x, int exponent);
extern double lgamma(double x);
extern long long llrint(double x);
extern double log(double x);
extern double log10(double x);
extern long lrint(double x);
extern long lround(double x);
extern double modf(double x, double *y);
extern double nearbyint(double x);
extern double pow(double x, double y);
extern double remquo(double x, double y, int *quo);
extern double round(double x);
extern double sin(double x);
extern double sinh(double x);
extern double sqrt(double x);
extern double tan(double x);
extern double tanh(double x);
extern double trunc(double x);
/* long double math functions */
extern long double acosl(long double x);
extern long double acoshl(long double x);
extern long double asinl(long double x);
extern long double atanl(long double x);
extern long double atanhl(long double x);
extern long double atan2l(long double y, long double x);
extern long double acosl(long double x);
extern long double acoshl(long double x);
extern long double asinl(long double x);
extern long double atanl(long double x);
extern long double atanhl(long double x);
extern long double atan2l(long double y, 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 lrintl(long double x);
extern long lroundl(long double x);
extern long double remquol(long double x, long double y, int *quo);
extern long lrintl(long double x);
extern long lroundl(long double x);
extern long double remquol(long double x, long double y, int *quo);
extern long double roundl(long double x);
/* some BSD non-ANSI or POSIX math functions */
extern double cbrt(double x);
extern double erf(double x);
extern double erfc(double x);
extern double expm1(double x);
extern double gamma_r(double x, int *y);
extern double hypot(double x, double y);
extern int ilogb(double x);
extern double j0(double x);
extern double j1(double x);
extern double jn(int x, double y);
extern double lgamma_r(double x, int *y);
extern double log1p(double x);
extern double logb(double x);
extern double nextafter(double x, double y);
extern double nexttoward(double x, long double y);
extern double remainder(double x, double y);
extern double rint(double x);
extern double scalb (double x, double y);
extern double y0(double x);
extern double y1(double x);
extern double yn(int x, double y);
extern double cbrt(double x);
extern double erf(double x);
extern double erfc(double x);
extern double expm1(double x);
extern double gamma_r(double x, int *y);
extern double hypot(double x, double y);
extern int ilogb(double x);
extern double j0(double x);
extern double j1(double x);
extern double jn(int x, double y);
extern double lgamma_r(double x, int *y);
extern double log1p(double x);
extern double logb(double x);
extern double nextafter(double x, double y);
extern double nexttoward(double x, long double y);
extern double remainder(double x, double y);
extern double rint(double x);
extern double scalb (double x, double y);
extern double y0(double x);
extern double y1(double x);
extern double yn(int x, double y);
/* other stuff as defined in BeOS */
extern int isinff(float value);
extern int finitef(float value);
extern float dremf(float x, float y);
extern float significandf(float x);
extern float copysignf(float x, float y);
extern int isnanf(float value);
extern double significand(double x);
extern double copysign(double x, double y);
extern double scalbln(double x, long n);
extern double scalbn(double x, int y);
extern double drem(double x, double y);
extern int finite(double x);
extern float j0f(float x);
extern float j1f(float x);
extern float jnf(int x, float y);
extern float y0f(float x);
extern float y1f(float x);
extern float ynf(int x, float y);
extern float erff(float x);
extern float erfcf(float x);
extern float gammaf_r(float x, int *y);
extern float lgammaf_r(float x, int *y);
extern float rintf(float x);
extern float nextafterf(float x, float y);
extern float nexttowardf(float x, long double y);
extern float remainderf(float x, float y);
extern float scalbf(float x, float n);
extern float scalbnf(float x, int n);
extern int ilogbf(float x);
extern int isinff(float value);
extern int finitef(float value);
extern float dremf(float x, float y);
extern float significandf(float x);
extern float copysignf(float x, float y);
extern int isnanf(float value);
extern double significand(double x);
extern double copysign(double x, double y);
extern double scalbln(double x, long n);
extern double scalbn(double x, int y);
extern double drem(double x, double y);
extern int finite(double x);
extern float j0f(float x);
extern float j1f(float x);
extern float jnf(int x, float y);
extern float y0f(float x);
extern float y1f(float x);
extern float ynf(int x, float y);
extern float erff(float x);
extern float erfcf(float x);
extern float gammaf_r(float x, int *y);
extern float lgammaf_r(float x, int *y);
extern float rintf(float x);
extern float nextafterf(float x, float y);
extern float nexttowardf(float x, long double y);
extern float remainderf(float x, float y);
extern float scalbf(float x, float n);
extern float scalbnf(float x, int n);
extern int ilogbf(float x);
extern long double nextafterl(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);
/* prototypes for functions used in the macros below */
extern int __fpclassifyf(float value);
extern int __signbitf(float value);
extern int __finitef(float value);
extern int __isnanf(float value);
extern int __isinff(float value);
extern int __fpclassifyf(float value);
extern int __signbitf(float value);
extern int __finitef(float value);
extern int __isnanf(float value);
extern int __isinff(float value);
extern int __fpclassifyl(long double value);
extern int __signbitl(long double value);
extern int __finitel(long double value);
extern int __isnanl(long double value);
extern int __isinfl(long double value);
extern int __fpclassifyl(long double value);
extern int __signbitl(long double value);
extern int __finitel(long double value);
extern int __isnanl(long double value);
extern int __isinfl(long double value);
extern int __fpclassify(double value);
extern int __signbit(double value);
extern int __finite(double value);
extern int __isnan(double value);
extern int __isinf(double value);
extern int __fpclassify(double value);
extern int __signbit(double value);
extern int __finite(double value);
extern int __isnan(double value);
extern int __isinf(double value);
/* returns number of classification appropriate for 'value' */
#define fpclassify(value) \

View File

@ -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.
*
* Authors:
@ -109,14 +109,15 @@ update_coefficients(int32 taps, double filterCutOff, bool horizontal, bool isY,
int32 num = taps * 16;
for (int32 i = 0; i < num * 2; i++) {
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)
sinc = 1.0;
else
sinc = sin(value) / value;
// 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;
}
@ -346,10 +347,10 @@ intel_allocate_overlay_buffer(color_space colorSpace, uint16 width,
bytesPerPixel = 2;
break;
case B_RGB16:
bytesPerPixel = 2;
bytesPerPixel = 2;
break;
case B_RGB32:
bytesPerPixel = 4;
bytesPerPixel = 4;
break;
case B_YCbCr422:
bytesPerPixel = 2;

View File

@ -1,36 +1,15 @@
/*
PDF Writer printer driver.
Copyright (c) 2001, 2002 OpenBeOS.
Authors:
Philippe Houdoin
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.
*/
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <math.h>
#include <Debug.h>
@ -47,28 +26,26 @@ THE SOFTWARE.
#include "Report.h"
#include "pdflib.h"
typedef struct
{
typedef struct {
uint16 from;
uint16 to;
int16 length;
uint16 *unicodes;
} unicode_to_encoding;
typedef struct
{
typedef struct {
uint16 unicode;
uint16 cid;
} unicode_to_cid;
typedef struct
{
typedef struct {
uint16 length;
unicode_to_cid *table;
unicode_to_cid *table;
} cid_table;
#ifdef UNICODE5_FROM
#error check code!
# error check code!
#endif
#define ELEMS(v, e) sizeof(v) / sizeof(e)
@ -81,8 +58,8 @@ typedef struct
#include "unicode3.h"
#include "unicode4.h"
static unicode_to_encoding encodings[] =
{
static unicode_to_encoding encodings[] = {
{UNICODE0_FROM, UNICODE0_TO, ELEMS(unicode0, uint16), unicode0},
{UNICODE1_FROM, UNICODE1_TO, ELEMS(unicode1, uint16), unicode1},
{UNICODE2_FROM, UNICODE2_TO, ELEMS(unicode2, uint16), unicode2},
@ -97,18 +74,40 @@ static unicode_to_encoding encodings[] =
#include "korean.h"
static cid_table cid_tables[] =
{
static cid_table cid_tables[] = {
{ELEMS(japanese, unicode_to_cid), japanese},
{ELEMS(CNS1, unicode_to_cid), CNS1},
{ELEMS(GB1, unicode_to_cid), GB1},
{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
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
// #pragma mark -
static bool
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
{
for (unsigned int i = 0; i < ELEMS(encodings, unicode_to_encoding); i++) {
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;
}
// --------------------------------------------------
static bool
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_encoding* order)
static bool
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index,
font_encoding* order)
{
for (unsigned int i = 0; i < ELEMS(cid_tables, cid_table); i++) {
encoding = order[i];
@ -161,9 +160,9 @@ find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_
}
// --------------------------------------------------
void
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index)
{
if (fUserDefinedEncodings.Get(unicode, enc, index)) {
BString s("user");
s << (int)enc;
@ -171,24 +170,25 @@ PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
}
}
// --------------------------------------------------
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();
for (int32 i = 0; i < n; i ++) {
if (fUsedFonts.ItemAt(i)->Equals(family, style, size)) return;
}
UsedFont* font;
font = new UsedFont(family, style, size);
fUsedFonts.AddItem(font);
REPORT(kInfo, -1, "Used font: \"%s\" \"%s\" %f", family, style, size);
}
// --------------------------------------------------
void
PDFWriter::GetFontName(BFont *font, char *fontname)
void
PDFWriter::GetFontName(BFont *font, char *fontname)
{
font_family family;
font_style style;
@ -199,9 +199,10 @@ PDFWriter::GetFontName(BFont *font, char *fontname)
RecordFont(family, style, font->Size());
}
// --------------------------------------------------
void
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed, font_encoding encoding)
void
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed,
font_encoding encoding)
{
GetFontName(font, fontname);
@ -219,38 +220,15 @@ PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed, font_encoding e
}
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"
};
// --------------------------------------------------
int
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
int
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
{
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;
REPORT(kDebug, fPage, "FindFont %s", fontName);
REPORT(kDebug, fPage, "FindFont %s", fontName);
Font *f = NULL;
const int n = fFontCache.CountItems();
for (int i = 0; i < n; i++) {
@ -260,33 +238,34 @@ PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
return f->font;
}
}
if (embed) embed = EmbedFont(fontName);
BString s;
const char* encoding_name;
if (encoding < user_defined_encoding_start) {
if (encoding < user_defined_encoding_start) {
encoding_name = encoding_names[encoding];
} else {
s = "user";
s << (int)(encoding - user_defined_encoding_start);
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);
if (font != -1) {
REPORT(kDebug, fPage, "font created");
cache = new Font(fontName, font, encoding);
fFontCache.AddItem(cache);
} 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;
}
// --------------------------------------------------
void
void
PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
{
int32 len = strlen(string);
@ -296,19 +275,19 @@ PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
int32 srcStart = 0;
do {
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen, &state);
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen,
&state);
srcStart += srcLen;
len -= srcLen;
srcLen = len;
utf8.Append(buffer, destLen);
destLen = 255;
} while (len > 0);
};
// --------------------------------------------------
void
void
PDFWriter::ToUnicode(const char *string, BString &unicode)
{
int32 len = strlen(string);
@ -318,87 +297,90 @@ PDFWriter::ToUnicode(const char *string, BString &unicode)
int32 srcStart = 0;
int i = 0;
unicode = "";
unicode = "";
if (len == 0) return;
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;
len -= srcLen;
srcLen = len;
char *b = unicode.LockBuffer(i + destLen);
memcpy(&b[i], buffer, destLen);
unicode.UnlockBuffer(i + destLen);
unicode.UnlockBuffer(i + destLen);
i += destLen;
destLen = 255;
} while (len > 0);
}
// --------------------------------------------------
void
void
PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
{
// PDFlib requires BOM at begin and two 0 at end of string
char marker[3] = { 0xfe, 0xff, 0}; // byte order marker
BString s;
ToUnicode(string, s);
unicode << marker;
int32 len = s.Length()+2;
char* buf = unicode.LockBuffer(len + 2); // reserve space for two additional '\0'
unicode << marker;
int32 len = s.Length()+2;
char* buf = unicode.LockBuffer(len + 2);
// reserve space for two additional '\0'
memcpy(&buf[2], s.String(), s.Length());
buf[len] = buf[len+1] = 0;
unicode.UnlockBuffer(len + 2);
}
// --------------------------------------------------
uint16
uint16
PDFWriter::CodePointSize(const char* s)
{
uint16 i = 1;
for (s++; !BeginsChar(*s); s++) i++;
for (s++; !BeginsChar(*s); s++) i++;
return i;
}
void PDFWriter::RecordDests(const char* s) {
void
PDFWriter::RecordDests(const char* s)
{
::RecordDests record(fXRefDests, &fTextLine, fPage);
fXRefs->Matches(s, &record, true);
}
// --------------------------------------------------
void
PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
{
// try to convert from utf8 to MacRoman encoding schema...
int32 srcLen = size;
int32 destLen = 1;
char dest[3] = "\0\0";
int32 state = 0;
char dest[3] = "\0\0";
int32 state = 0;
bool embed = true;
font_encoding encoding = macroman_encoding;
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 ) {
font_encoding encoding = macroman_encoding;
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) {
// could not convert to MacRoman
uint8 enc;
uint16 index = 0;
font_encoding fenc;
uint16 index = 0;
uint8 enc;
GetFontName(&fState->beFont, fontName);
embed = EmbedFont(fontName);
REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode);
if (find_encoding(unicode, enc, index)) {
// is code point in the Adobe Glyph List?
// Note if rendering the glyphs only would be desired, we could always use
// the second method below (MakeUserDefinedEncoding), but extracting text
// from the generated PDF would be almost impossible (OCR!)
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc, (int)index);
// Note if rendering the glyphs only would be desired, we could
// always use the second method below (MakeUserDefinedEncoding),
// but extracting text from the generated PDF would be almost
// impossible (OCR!)
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc,
(int)index);
// use one of the user pre-defined encodings
if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
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)) {
// font is not embedded use one of the CJK fonts for substitution
REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index);
dest[0] = unicode / 256;
dest[1] = unicode % 256;
dest[0] = unicode / 256;
dest[1] = unicode % 256;
destLen = 2;
encoding = fenc;
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);
if (!found) {
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
return; // simply skip character
return; // simply skip character
}
} 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;
int font;
GetFontName(&fState->beFont, fontName, embed, encoding);
font = FindFont(fontName, embed, encoding);
font = FindFont(fontName, embed, encoding);
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);
}
fState->font = font;
uint16 face = fState->beFont.Face();
PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0 ? "true" : "false");
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_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0
? "true" : "false");
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()));
@ -465,7 +454,7 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
PDF_translate(fPdf, x, y);
PDF_rotate(fPdf, rotation);
PDF_set_text_pos(fPdf, 0, 0);
} else
} else
PDF_set_text_pos(fPdf, x, y);
PDF_show2(fPdf, dest, destLen);
@ -476,9 +465,9 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
}
// --------------------------------------------------
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;
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.left, o.bottom));
glyph.Close();
glyph.MoveTo(BPoint(i.left, i.top));
glyph.LineTo(BPoint(i.left, i.bottom));
glyph.LineTo(BPoint(i.right, i.bottom));
glyph.LineTo(BPoint(i.right, i.top));
glyph.Close();
glyph.Close();
}
BPoint p(fState->penX, fState->penY);
@ -523,12 +512,14 @@ PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 si
PopInternalState();
}
// --------------------------------------------------
void
PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_space)
void
PDFWriter::DrawString(char *string, float escapementNoSpace,
float escapementSpace)
{
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapement_nospace=%f, escapement_space=%f, at %f, %f", \
string, escapement_nospace, escapement_space, fState->penX, fState->penY);
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, "
"escapementSpace=%f, at %f, %f", string, escapementNoSpace,
escapementSpace, fState->penX, fState->penY);
if (IsDrawing()) {
// 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 {
ToUtf8(fState->beFont.Encoding()-1, string, utf8);
}
// convert string in UTF8 to unicode UCS2
BString unicode;
ToUnicode(utf8.String(), unicode);
ToUnicode(utf8.String(), unicode);
// need font object to calculate width of utf8 code point
BFont font = fState->beFont;
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 bool rotate = rotation != 0.0;
const double cos1 = rotate ? cos(rotation) : 1;
@ -569,14 +560,14 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
if (MakesPDF() && IsClipping()) {
ClipChar(&font, (char*)u, c, s, w);
} else {
DrawChar(u[0]*256+u[1], c, s);
DrawChar(u[0]*256+u[1], c, s);
}
// position of next character
if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space!
w += escapement_space;
w += escapementSpace;
} else {
w += escapement_nospace;
w += escapementNoSpace;
}
fState->penX += w * cos1;
@ -588,36 +579,30 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
EndTransparency();
// text line processing (for non rotated text only!)
BPoint end(fState->penX, fState->penY);
BRect bounds;
font_height height;
BPoint end(fState->penX, fState->penY);
BRect bounds;
font_height height;
font.GetHeight(&height);
bounds.left = start.x;
bounds.right = end.x;
bounds.top = start.y - height.ascent;
bounds.left = start.x;
bounds.right = end.x;
bounds.top = start.y - height.ascent;
bounds.bottom = end.y + height.descent;
TextSegment* segment = new TextSegment(
utf8.String(), start,
escapement_space, escapement_nospace,
&bounds, &font, pdfSystem());
TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace,
escapementNoSpace, &bounds, &font, pdfSystem());
fTextLine.Add(segment);
if (IsDrawing()) {
}
}
// --------------------------------------------------
bool
PDFWriter::EmbedFont(const char* name)
{
static FontFile* cache = NULL;
if (cache && strcmp(cache->Name(), name) == 0) return cache->Embed();
const int n = fFonts->Length();
for (int i = 0; i < n; i++) {
FontFile* f = fFonts->At(i);

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,12 @@
/*
PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS.
Authors:
Philippe Houdoin
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.
*/
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#ifndef PDFWRITER_H
#define PDFWRITER_H
@ -37,7 +15,7 @@ THE SOFTWARE.
#include <String.h>
#include <List.h>
#include "math.h"
#include <math.h>
#include "PrinterDriver.h"
#include "PictureIterator.h"
@ -52,8 +30,8 @@ THE SOFTWARE.
#define USE_IMAGE_CACHE 1
#define RAD2DEGREE(r) (180.0 * r / PI)
#define DEGREE2RAD(d) (PI * d / 180.0)
#define RAD2DEGREE(r) (180.0 * r / M_PI)
#define DEGREE2RAD(d) (M_PI * d / 180.0)
class DrawShape;
class WebLink;
@ -61,9 +39,7 @@ class Bookmark;
class XRefDefs;
class XRefDests;
class PDFWriter : public PrinterDriver, public PictureIterator
{
class PDFWriter : public PrinterDriver, public PictureIterator {
friend class DrawShape;
friend class PDFLinePathBuilder;
friend class WebLink;
@ -71,12 +47,12 @@ class PDFWriter : public PrinterDriver, public PictureIterator
friend class Bookmark;
friend class LocalLink;
friend class TextLine;
public:
// constructors / destructor
PDFWriter();
~PDFWriter();
// public methods
status_t BeginJob();
status_t PrintPage(int32 pageNumber, int32 pageCount);
@ -89,11 +65,11 @@ class PDFWriter : public PrinterDriver, public PictureIterator
bool LoadBookmarkDefinitions(const char* name);
bool LoadXRefsDefinitions(const char* name);
void RecordDests(const char* s);
// PDFLib callbacks
size_t WriteData(void *data, size_t size);
void ErrorHandler(int type, const char *msg);
// Image support
int32 BytesPerPixel(int32 pixelFormat);
@ -198,19 +174,19 @@ class PDFWriter : public PrinterDriver, public PictureIterator
void SetFontFlags(int32 flags);
void SetFontShear(float shear);
void SetFontFace(int32 flags);
static inline bool IsSame(const pattern &p1, const pattern &p2);
static inline bool IsSame(const rgb_color &c1, const rgb_color &c2);
private:
enum PDFVersion {
kPDF13,
kPDF14,
kPDF15
};
class State
class State
{
public:
State *prev;
@ -229,9 +205,9 @@ class PDFWriter : public PrinterDriver, public PictureIterator
float penSize;
pattern pattern0;
int32 fontSpacing;
// 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 black = {0, 0, 0, 255};
@ -241,26 +217,26 @@ class PDFWriter : public PrinterDriver, public PictureIterator
pdfSystem.SetOrigin(x, y);
penX = 0;
penY = 0;
drawingMode = B_OP_COPY;
drawingMode = B_OP_COPY;
foregroundColor = white;
backgroundColor = black;
currentColor = black;
capMode = B_BUTT_CAP;
joinMode = B_MITER_JOIN;
miterLimit = B_DEFAULT_MITER_LIMIT;
penSize = 1;
pattern0 = B_SOLID_HIGH;
fontSpacing = B_STRING_SPACING;
capMode = B_BUTT_CAP;
joinMode = B_MITER_JOIN;
miterLimit = B_DEFAULT_MITER_LIMIT;
penSize = 1;
pattern0 = B_SOLID_HIGH;
fontSpacing = B_STRING_SPACING;
}
State(State *prev)
State(State *prev)
{
*this = *prev;
this->prev = prev;
}
};
class Font
class Font
{
public:
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;
rgb_color lowColor, highColor;
int patternId;
Pattern(const pattern &p, rgb_color low, rgb_color high, int id)
: pat(p)
, lowColor(low)
, highColor(high)
, patternId(id)
{};
inline bool Matches(const pattern &p, rgb_color low, rgb_color high) const {
return IsSame(pat, p) && IsSame(lowColor, low) && IsSame(highColor, high);
};
@ -292,19 +268,19 @@ class PDFWriter : public PrinterDriver, public PictureIterator
{
uint8 alpha;
int handle;
public:
public:
Transparency(uint8 alpha, int handle)
: alpha(alpha)
, handle(handle)
{};
inline bool Matches(uint8 alpha) const {
return this->alpha == alpha;
};
inline int Handle() const { return handle; }
};
PDFVersion fPDFVersion;
FILE *fLog;
PDF *fPdf;
@ -329,8 +305,8 @@ class PDFWriter : public PrinterDriver, public PictureIterator
TextLine fTextLine;
TList<UsedFont> fUsedFonts;
UserDefinedEncodings fUserDefinedEncodings;
enum
enum
{
kDrawingMode,
kClippingMode
@ -362,7 +338,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator
inline cap_mode LineCapMode() const { return fState->capMode; }
inline join_mode LineJoinMode() const { return fState->joinMode; }
inline float LineMiterLimit() const { return fState->miterLimit; }
bool StoreTranslatorBitmap(BBitmap *bitmap, const char *filename, uint32 type);
void GetFontName(BFont *font, char *fontname);
@ -383,7 +359,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator
void CreatePattern();
int FindPattern();
void SetPattern();
void StrokeOrClip();
void FillOrClip();
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)
{
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)
{
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);
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

View File

@ -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.
*
* Authors:
@ -8,17 +8,18 @@
#include "FontDemoView.h"
#include "messages.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <Bitmap.h>
#include <Font.h>
#include <Message.h>
#include <Shape.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "messages.h"
FontDemoView::FontDemoView(BRect rect)
@ -54,7 +55,8 @@ FontDemoView::~FontDemoView()
void
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()*/);
BView::FrameResized(width, height);
}
@ -78,9 +80,9 @@ FontDemoView::_DrawView(BView* view)
{
if (!view)
return;
view->SetDrawingMode(B_OP_COPY);
BRect rect = view->Bounds();
view->SetHighColor(255, 255, 255);
@ -114,18 +116,18 @@ FontDemoView::_DrawView(BView* view)
font_height fh;
fFont.GetHeight(&fh);
float xCoordArray[size];
float xCoordArray[size];
float yCoordArray[size];
float yCoord = (rect.Height() + fh.ascent - fh.descent) / 2;
float xCoord = -rect.Width() / 2;
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 sinus = -sin(r);
// 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();
@ -135,7 +137,7 @@ FontDemoView::_DrawView(BView* view)
yCoordArray[i] = sinus * (xCoord - xCoordArray[i]);
xCoordArray[i] = cosinus * xCoord;
xCoordArray[i] += xCenter;
yCoordArray[i] += yCoord;
@ -234,7 +236,7 @@ FontDemoView::MessageReceived(BMessage* msg)
case FONTSHEAR_MSG:
{
float shear = 90.0;
float shear = 90.0;
if (msg->FindFloat("_shear", &shear) == B_OK) {
SetFontShear(shear);
Invalidate(/*&fBoxRegion*/);
@ -244,7 +246,7 @@ FontDemoView::MessageReceived(BMessage* msg)
case ROTATION_MSG:
{
float rotation = 0.0;
float rotation = 0.0;
if (msg->FindFloat("_rotation", &rotation) == B_OK) {
SetFontRotation(rotation);
Invalidate(/*&fBoxRegion*/);
@ -254,7 +256,7 @@ FontDemoView::MessageReceived(BMessage* msg)
case SPACING_MSG:
{
float space = 0.0;
float space = 0.0;
if (msg->FindFloat("_spacing", &space) == B_OK) {
SetSpacing(space);
Invalidate(/*&fBoxRegion*/);
@ -264,13 +266,13 @@ FontDemoView::MessageReceived(BMessage* msg)
case OUTLINE_MSG:
{
int8 outline = 0;
int8 outline = 0;
if (msg->FindInt8("_outline", &outline) == B_OK) {
SetOutlineLevel(outline);
Invalidate(/*&fBoxRegion*/);
}
break;
}
}
case ALIASING_MSG:
{
@ -281,7 +283,7 @@ FontDemoView::MessageReceived(BMessage* msg)
}
break;
}
case DRAWINGMODE_CHANGED_MSG:
{
if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) {
@ -289,7 +291,7 @@ FontDemoView::MessageReceived(BMessage* msg)
}
break;
}
case BOUNDING_BOX_MSG:
{
bool boundingbox = false;
@ -299,7 +301,7 @@ FontDemoView::MessageReceived(BMessage* msg)
}
break;
}
default:
BView::MessageReceived(msg);
break;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -16,17 +16,18 @@
#include <Point.h>
#include <String.h>
// point_line_distance
double
point_line_distance(double x1, double y1,
double x2, double y2,
double x, double y)
point_line_distance(double x1, double y1, double x2, double y2, double x,
double y)
{
double dx = x2 - x1;
double dy = y2 - y1;
return ((x - x2) * dy - (y - y2) * dx) / sqrt(dx * dx + dy * dy);
}
// point_line_distance
double
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 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,
point.x, point.y));
point.x, point.y));
}
}
return currentDist;
}
// calc_angle
double
calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
{
double angle = 0.0;
double d = point_line_distance(from.x, from.y,
origin.x, origin.y,
to.x, to.y);
double d = point_line_distance(from.x, from.y, origin.x, origin.y,
to.x, to.y);
if (d != 0.0) {
double a = point_point_distance(from, to);
double b = point_point_distance(from, origin);
double c = point_point_distance(to, origin);
if (a > 0.0 && b > 0.0 && c > 0.0) {
angle = acos((b*b + c*c - a*a) / (2.0*b*c));
if (d < 0.0)
angle = -angle;
if (degree)
angle = angle * 180.0 / PI;
angle = angle * 180.0 / M_PI;
}
}
return angle;
}
// write_string
status_t
write_string(BPositionIO* stream, BString& string)
@ -91,6 +93,7 @@ write_string(BPositionIO* stream, BString& string)
return written;
}
// append_float
void
append_float(BString& string, float n, int32 maxDigits)
@ -127,10 +130,11 @@ append_float(BString& string, float n, int32 maxDigits)
}
}
//// gauss
//double
//gauss(double f)
//{
//{
// // this aint' a real gauss function
///* if (f >= -1.0 && f <= 1.0) {
// if (f < -0.5) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -10,20 +10,24 @@
#include "CanvasView.h"
// constructor
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),
fParentTransform()
fCanvasView(view),
fParentTransform()
{
}
// destructor
CanvasTransformBox::~CanvasTransformBox()
{
}
// TransformFromCanvas
void
CanvasTransformBox::TransformFromCanvas(BPoint& point) const
@ -32,6 +36,7 @@ CanvasTransformBox::TransformFromCanvas(BPoint& point) const
fCanvasView->ConvertFromCanvas(&point);
}
// TransformToCanvas
void
CanvasTransformBox::TransformToCanvas(BPoint& point) const
@ -40,6 +45,7 @@ CanvasTransformBox::TransformToCanvas(BPoint& point) const
fParentTransform.Transform(&point);
}
// ZoomLevel
float
CanvasTransformBox::ZoomLevel() const
@ -47,11 +53,12 @@ CanvasTransformBox::ZoomLevel() const
return fCanvasView->ZoomLevel();
}
// ViewSpaceRotation
double
CanvasTransformBox::ViewSpaceRotation() const
{
Transformable t(*this);
t.Multiply(fParentTransform);
return t.rotation() * 180.0 / PI;
return t.rotation() * 180.0 / M_PI;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -11,33 +11,38 @@
#include <math.h>
#include <stdio.h>
// constructor
ChannelTransform::ChannelTransform()
: Transformable(),
fPivot(0.0, 0.0),
fTranslation(0.0, 0.0),
fRotation(0.0),
fXScale(1.0),
fYScale(1.0)
:
Transformable(),
fPivot(0.0, 0.0),
fTranslation(0.0, 0.0),
fRotation(0.0),
fXScale(1.0),
fYScale(1.0)
{
}
// copy constructor
ChannelTransform::ChannelTransform(const ChannelTransform& other)
: Transformable(other),
fPivot(other.fPivot),
fTranslation(other.fTranslation),
fRotation(other.fRotation),
fXScale(other.fXScale),
fYScale(other.fYScale)
:
Transformable(other),
fPivot(other.fPivot),
fTranslation(other.fTranslation),
fRotation(other.fRotation),
fXScale(other.fXScale),
fYScale(other.fYScale)
{
}
// destructor
ChannelTransform::~ChannelTransform()
{
}
// SetTransformation
void
ChannelTransform::SetTransformation(const Transformable& other)
@ -63,13 +68,11 @@ ChannelTransform::SetTransformation(const Transformable& other)
SetTransformation(B_ORIGIN, BPoint(tx, ty), rotation, scaleX, scaleY);
}
// SetTransformation
void
ChannelTransform::SetTransformation(BPoint pivot,
BPoint translation,
double rotation,
double xScale,
double yScale)
ChannelTransform::SetTransformation(BPoint pivot, BPoint translation,
double rotation, double xScale, double yScale)
{
//printf("SetTransformation(BPoint(%.1f, %.1f), BPoint(%.1f, %.1f), "
//"%.2f, %.2f, %.2f)\n", pivot.x, pivot.y, translation.x, translation.y,
@ -86,11 +89,12 @@ ChannelTransform::SetTransformation(BPoint pivot,
fRotation = rotation;
fXScale = xScale;
fYScale = yScale;
_UpdateMatrix();
}
}
// SetPivot
void
ChannelTransform::SetPivot(BPoint pivot)
@ -103,6 +107,7 @@ ChannelTransform::SetPivot(BPoint pivot)
_UpdateMatrix();
}
// TranslateBy
void
ChannelTransform::TranslateBy(BPoint offset)
@ -115,10 +120,11 @@ ChannelTransform::TranslateBy(BPoint offset)
_UpdateMatrix();
}
// RotateBy
//
// converts a rotation in world coordinates into
// a combined local rotation and a translation
/*! Converts a rotation in world coordinates into
a combined local rotation and a translation.
*/
void
ChannelTransform::RotateBy(BPoint origin, double degrees)
{
@ -133,7 +139,7 @@ ChannelTransform::RotateBy(BPoint origin, double degrees)
double xOffset = fTranslation.x - origin.x;
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);
fTranslation.x = origin.x + xOffset;
@ -155,6 +161,7 @@ ChannelTransform::RotateBy(double degrees)
_UpdateMatrix();
}
//// ScaleBy
////
//// converts a scalation in world coordinates into
@ -191,10 +198,11 @@ ChannelTransform::ScaleBy(double xScale, double yScale)
_UpdateMatrix();
}
// SetTranslationAndScale
void
ChannelTransform::SetTranslationAndScale(BPoint offset,
double xScale, double yScale)
ChannelTransform::SetTranslationAndScale(BPoint offset, double xScale,
double yScale)
{
if (fTranslation == offset && fXScale == xScale && fYScale == yScale)
return;
@ -207,6 +215,7 @@ ChannelTransform::SetTranslationAndScale(BPoint offset,
_UpdateMatrix();
}
// Reset
void
ChannelTransform::Reset()
@ -214,6 +223,7 @@ ChannelTransform::Reset()
SetTransformation(B_ORIGIN, B_ORIGIN, 0.0, 1.0, 1.0);
}
// =
ChannelTransform&
ChannelTransform::operator=(const ChannelTransform& other)
@ -228,6 +238,7 @@ ChannelTransform::operator=(const ChannelTransform& other)
return *this;
}
// _UpdateMatrix
void
ChannelTransform::_UpdateMatrix()
@ -246,10 +257,10 @@ ChannelTransform::_UpdateMatrix()
// coordinate system and is the center for rotation and scale
multiply(agg::trans_affine_translation(-fPivot.x, -fPivot.y));
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,
fPivot.y + fTranslation.y));
fPivot.y + fTranslation.y));
// call hook function
Update();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006-2007, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -21,55 +21,66 @@
#include "StateView.h"
#include "TransformCommand.h"
#define INSET 8.0
TransformBoxListener::TransformBoxListener() {}
TransformBoxListener::~TransformBoxListener() {}
TransformBoxListener::TransformBoxListener()
{
}
TransformBoxListener::~TransformBoxListener()
{
}
// #pragma mark -
// constructor
TransformBox::TransformBox(StateView* view, BRect box)
: ChannelTransform(),
Manipulator(NULL),
fOriginalBox(box),
:
ChannelTransform(),
Manipulator(NULL),
fOriginalBox(box),
fLeftTop(box.LeftTop()),
fRightTop(box.RightTop()),
fLeftBottom(box.LeftBottom()),
fRightBottom(box.RightBottom()),
fLeftTop(box.LeftTop()),
fRightTop(box.RightTop()),
fLeftBottom(box.LeftBottom()),
fRightBottom(box.RightBottom()),
fPivot((fLeftTop.x + fRightBottom.x) / 2.0,
(fLeftTop.y + fRightBottom.y) / 2.0),
fPivotOffset(B_ORIGIN),
fPivot((fLeftTop.x + fRightBottom.x) / 2.0,
(fLeftTop.y + fRightBottom.y) / 2.0),
fPivotOffset(B_ORIGIN),
fCurrentCommand(NULL),
fCurrentState(NULL),
fCurrentCommand(NULL),
fCurrentState(NULL),
fDragging(false),
fMousePos(-10000.0, -10000.0),
fModifiers(0),
fDragging(false),
fMousePos(-10000.0, -10000.0),
fModifiers(0),
fNudging(false),
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)),
fDragRTState(new DragCornerState(this, DragCornerState::RIGHT_TOP_CORNER)),
fDragLBState(new DragCornerState(this, DragCornerState::LEFT_BOTTOM_CORNER)),
fDragRBState(new DragCornerState(this, DragCornerState::RIGHT_BOTTOM_CORNER)),
fDragLState(new DragSideState(this, DragSideState::LEFT_SIDE)),
fDragRState(new DragSideState(this, DragSideState::RIGHT_SIDE)),
fDragTState(new DragSideState(this, DragSideState::TOP_SIDE)),
fDragBState(new DragSideState(this, DragSideState::BOTTOM_SIDE)),
fDragLState(new DragSideState(this, DragSideState::LEFT_SIDE)),
fDragRState(new DragSideState(this, DragSideState::RIGHT_SIDE)),
fDragTState(new DragSideState(this, DragSideState::TOP_SIDE)),
fDragBState(new DragSideState(this, DragSideState::BOTTOM_SIDE)),
fRotateState(new RotateBoxState(this)),
fTranslateState(new DragBoxState(this)),
fOffsetCenterState(new OffsetCenterState(this))
fRotateState(new RotateBoxState(this)),
fTranslateState(new DragBoxState(this)),
fOffsetCenterState(new OffsetCenterState(this))
{
}
// destructor
TransformBox::~TransformBox()
{
@ -92,6 +103,7 @@ TransformBox::~TransformBox()
delete fOffsetCenterState;
}
// Draw
void
TransformBox::Draw(BView* into, BRect updateRect)
@ -131,8 +143,10 @@ TransformBox::Draw(BView* into, BRect updateRect)
into->SetDrawingMode(B_OP_COPY);
}
// #pragma mark -
// MouseDown
bool
TransformBox::MouseDown(BPoint where)
@ -147,12 +161,13 @@ TransformBox::MouseDown(BPoint where)
delete fCurrentCommand;
fCurrentCommand = MakeCommand(fCurrentState->ActionName(),
fCurrentState->ActionNameIndex());
fCurrentState->ActionNameIndex());
}
return true;
}
// MouseMoved
void
TransformBox::MouseMoved(BPoint where)
@ -170,6 +185,7 @@ TransformBox::MouseMoved(BPoint where)
}
}
// MouseUp
Command*
TransformBox::MouseUp()
@ -178,6 +194,7 @@ TransformBox::MouseUp()
return FinishTransaction();
}
// MouseOver
bool
TransformBox::MouseOver(BPoint where)
@ -193,6 +210,7 @@ TransformBox::MouseOver(BPoint where)
return false;
}
// DoubleClicked
bool
TransformBox::DoubleClicked(BPoint where)
@ -200,8 +218,10 @@ TransformBox::DoubleClicked(BPoint where)
return false;
}
// #pragma mark -
// Bounds
BRect
TransformBox::Bounds()
@ -227,6 +247,7 @@ TransformBox::Bounds()
return r;
}
// TrackingBounds
BRect
TransformBox::TrackingBounds(BView* withinView)
@ -234,8 +255,10 @@ TransformBox::TrackingBounds(BView* withinView)
return withinView->Bounds();
}
// #pragma mark -
// ModifiersChanged
void
TransformBox::ModifiersChanged(uint32 modifiers)
@ -246,6 +269,7 @@ TransformBox::ModifiersChanged(uint32 modifiers)
}
}
// HandleKeyDown
bool
TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
@ -270,7 +294,7 @@ TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
case B_RIGHT_ARROW:
translation.x = offset;
break;
default:
handled = false;
break;
@ -288,6 +312,7 @@ TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
return true;
}
// HandleKeyUp
bool
TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
@ -299,6 +324,7 @@ TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
return false;
}
// UpdateCursor
bool
TransformBox::UpdateCursor()
@ -310,8 +336,10 @@ TransformBox::UpdateCursor()
return false;
}
// #pragma mark -
// AttachedToView
void
TransformBox::AttachedToView(BView* view)
@ -319,6 +347,7 @@ TransformBox::AttachedToView(BView* view)
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
}
// DetachedFromView
void
TransformBox::DetachedFromView(BView* view)
@ -326,8 +355,10 @@ TransformBox::DetachedFromView(BView* view)
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
}
// pragma mark -
// Update
void
TransformBox::Update(bool deep)
@ -352,6 +383,7 @@ TransformBox::Update(bool deep)
Transform(&fPivot);
}
// OffsetCenter
void
TransformBox::OffsetCenter(BPoint offset)
@ -362,6 +394,7 @@ TransformBox::OffsetCenter(BPoint offset)
}
}
// Center
BPoint
TransformBox::Center() const
@ -369,6 +402,7 @@ TransformBox::Center() const
return fPivot;
}
// SetBox
void
TransformBox::SetBox(BRect box)
@ -379,22 +413,21 @@ TransformBox::SetBox(BRect box)
}
}
// FinishTransaction
Command*
TransformBox::FinishTransaction()
{
Command* command = fCurrentCommand;
if (fCurrentCommand) {
fCurrentCommand->SetNewTransformation(Pivot(),
Translation(),
LocalRotation(),
LocalXScale(),
LocalYScale());
fCurrentCommand->SetNewTransformation(Pivot(), Translation(),
LocalRotation(), LocalXScale(), LocalYScale());
fCurrentCommand = NULL;
}
return command;
}
// NudgeBy
void
TransformBox::NudgeBy(BPoint offset)
@ -408,6 +441,7 @@ TransformBox::NudgeBy(BPoint offset)
}
}
// FinishNudging
Command*
TransformBox::FinishNudging()
@ -416,18 +450,21 @@ TransformBox::FinishNudging()
return FinishTransaction();
}
// TransformFromCanvas
void
TransformBox::TransformFromCanvas(BPoint& point) const
{
}
// TransformToCanvas
void
TransformBox::TransformToCanvas(BPoint& point) const
{
}
// ZoomLevel
float
TransformBox::ZoomLevel() const
@ -435,6 +472,7 @@ TransformBox::ZoomLevel() const
return 1.0;
}
// ViewSpaceRotation
double
TransformBox::ViewSpaceRotation() const
@ -443,8 +481,10 @@ TransformBox::ViewSpaceRotation() const
return LocalRotation();
}
// #pragma mark -
// AddListener
bool
TransformBox::AddListener(TransformBoxListener* listener)
@ -454,6 +494,7 @@ TransformBox::AddListener(TransformBoxListener* listener)
return false;
}
// RemoveListener
bool
TransformBox::RemoveListener(TransformBoxListener* listener)
@ -461,30 +502,29 @@ TransformBox::RemoveListener(TransformBoxListener* listener)
return fListeners.RemoveItem((void*)listener);
}
// #pragma mark -
// TODO: why another version?
// point_line_dist
float
point_line_dist(BPoint start, BPoint end, BPoint p, float radius)
{
BRect r(min_c(start.x, end.x),
min_c(start.y, end.y),
max_c(start.x, end.x),
max_c(start.y, end.y));
BRect r(min_c(start.x, end.x), min_c(start.y, end.y), max_c(start.x, end.x),
max_c(start.y, end.y));
r.InsetBy(-radius, -radius);
if (r.Contains(p)) {
return fabs(agg::calc_line_point_distance(start.x, start.y,
end.x, end.y,
p.x, p.y));
return fabs(agg::calc_line_point_distance(start.x, start.y, end.x, end.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
//
// where is expected in canvas view coordinates
//! where is expected in canvas view coordinates
DragState*
TransformBox::_DragStateFor(BPoint where, float canvasZoom)
{
@ -586,6 +626,7 @@ TransformBox::_DragStateFor(BPoint where, float canvasZoom)
return state;
}
// _StrokeBWLine
void
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);
}
// _StrokeBWPoint
void
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 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);
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);
}
// #pragma mark -
// _NotifyDeleted
void
TransformBox::_NotifyDeleted() const
@ -681,8 +725,10 @@ TransformBox::_NotifyDeleted() const
}
}
// #pragma mark -
// _SetState
void
TransformBox::_SetState(DragState* state)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -19,15 +19,17 @@
#include "support.h"
#include "TransformBox.h"
//#include "Strings.h"
// constructor
DragState::DragState(TransformBox* parent)
: fOrigin(0.0, 0.0),
fParent(parent)
:
fOrigin(0.0, 0.0),
fParent(parent)
{
}
// SetOrigin
void
DragState::SetOrigin(BPoint origin)
@ -35,6 +37,7 @@ DragState::SetOrigin(BPoint origin)
fOrigin = origin;
}
// ActionName
const char*
DragState::ActionName() const
@ -42,6 +45,7 @@ DragState::ActionName() const
return "Transformation";
}
// ActionNameIndex
uint32
DragState::ActionNameIndex() const
@ -49,6 +53,7 @@ DragState::ActionNameIndex() const
return TRANSFORMATION;
}
// _SetViewCursor
void
DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
@ -57,15 +62,19 @@ DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
view->SetViewCursor(&cursor);
}
// #pragma mark - DragCornerState
// constructor
DragCornerState::DragCornerState(TransformBox* parent, uint32 corner)
: DragState(parent),
fCorner(corner)
:
DragState(parent),
fCorner(corner)
{
}
// SetOrigin
void
DragCornerState::SetOrigin(BPoint origin)
@ -78,9 +87,10 @@ DragCornerState::SetOrigin(BPoint origin)
// copy the matrix at the start of the drag procedure
fMatrix.reset();
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,
fParent->Translation().y));
fParent->Translation().y));
double x = origin.x;
double y = origin.y;
@ -125,6 +135,8 @@ DragCornerState::SetOrigin(BPoint origin)
}
DragState::SetOrigin(origin);
}
// DragTo
void
DragCornerState::DragTo(BPoint current, uint32 modifiers)
@ -164,11 +176,11 @@ DragCornerState::DragTo(BPoint current, uint32 modifiers)
translation.x = x;
translation.y = y;
fParent->SetTranslationAndScale(translation,
xScale * fOldXScale,
yScale * fOldYScale);
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
yScale * fOldYScale);
}
// UpdateViewCursor
void
DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
@ -180,91 +192,98 @@ DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
else
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
if (flipX) {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
} else {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
else
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
if (flipX) {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
} else {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
}
break;
}
} else if (rotation < 90.0) {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
else
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
} else {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
else
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
} else {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
}
break;
}
} else if (rotation < 135.0) {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
else
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
break;
if (flipX) {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
} else {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
else
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
break;
if (flipX) {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
} else {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
}
break;
}
} else {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
else
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
} else {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
else
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
} else {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
}
break;
}
}
}
// ActionName
const char*
DragCornerState::ActionName() const
@ -272,6 +291,7 @@ DragCornerState::ActionName() const
return "Scale";
}
// ActionNameIndex
uint32
DragCornerState::ActionNameIndex() const
@ -282,12 +302,15 @@ DragCornerState::ActionNameIndex() const
// #pragma mark - DragSideState
DragSideState::DragSideState(TransformBox* parent, uint32 side)
: DragState(parent),
fSide(side)
:
DragState(parent),
fSide(side)
{
}
// SetOrigin
void
DragSideState::SetOrigin(BPoint origin)
@ -300,9 +323,10 @@ DragSideState::SetOrigin(BPoint origin)
// copy the matrix at the start of the drag procedure
fMatrix.reset();
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,
fParent->Translation().y));
fParent->Translation().y));
double x = origin.x;
double y = origin.y;
@ -336,6 +360,7 @@ DragSideState::SetOrigin(BPoint origin)
DragState::SetOrigin(origin);
}
// DragTo
void
DragSideState::DragTo(BPoint current, uint32 modifiers)
@ -369,11 +394,11 @@ DragSideState::DragTo(BPoint current, uint32 modifiers)
translation.x = x;
translation.y = y;
fParent->SetTranslationAndScale(translation,
xScale * fOldXScale,
yScale * fOldYScale);
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
yScale * fOldYScale);
}
// UpdateViewCursor
void
DragSideState::UpdateViewCursor(BView* view, BPoint current) const
@ -426,6 +451,7 @@ DragSideState::UpdateViewCursor(BView* view, BPoint current) const
}
}
// ActionName
const char*
DragSideState::ActionName() const
@ -433,6 +459,7 @@ DragSideState::ActionName() const
return "Scale";
}
// ActionNameIndex
uint32
DragSideState::ActionNameIndex() const
@ -443,6 +470,7 @@ DragSideState::ActionNameIndex() const
// #pragma mark - DragBoxState
// SetOrigin
void
DragBoxState::SetOrigin(BPoint origin)
@ -451,6 +479,7 @@ DragBoxState::SetOrigin(BPoint origin)
DragState::SetOrigin(origin);
}
// DragTo
void
DragBoxState::DragTo(BPoint current, uint32 modifiers)
@ -466,6 +495,7 @@ DragBoxState::DragTo(BPoint current, uint32 modifiers)
fParent->TranslateBy(newTranslation - fParent->Translation());
}
// UpdateViewCursor
void
DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
@ -473,6 +503,7 @@ DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
_SetViewCursor(view, kMoveCursor);
}
// ActionName
const char*
DragBoxState::ActionName() const
@ -480,6 +511,7 @@ DragBoxState::ActionName() const
return "Move";
}
// ActionNameIndex
uint32
DragBoxState::ActionNameIndex() const
@ -490,13 +522,16 @@ DragBoxState::ActionNameIndex() const
// #pragma mark - RotateBoxState
// constructor
RotateBoxState::RotateBoxState(TransformBox* parent)
: DragState(parent),
fOldAngle(0.0)
:
DragState(parent),
fOldAngle(0.0)
{
}
// SetOrigin
void
RotateBoxState::SetOrigin(BPoint origin)
@ -505,6 +540,7 @@ RotateBoxState::SetOrigin(BPoint origin)
fOldAngle = fParent->LocalRotation();
}
// DragTo
void
RotateBoxState::DragTo(BPoint current, uint32 modifiers)
@ -524,6 +560,7 @@ RotateBoxState::DragTo(BPoint current, uint32 modifiers)
fParent->RotateBy(fParent->Center(), newAngle - fParent->LocalRotation());
}
// UpdateViewCursor
void
RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
@ -531,8 +568,8 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
BPoint origin(fParent->Center());
fParent->TransformToCanvas(origin);
fParent->TransformToCanvas(current);
BPoint from = origin + BPoint(sinf(22.5 * 180.0 / PI) * 50.0,
-cosf(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 / M_PI) * 50.0);
float rotation = calc_angle(origin, from, current) + 180.0;
@ -555,6 +592,7 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
}
}
// ActionName
const char*
RotateBoxState::ActionName() const
@ -562,6 +600,7 @@ RotateBoxState::ActionName() const
return "Rotate";
}
// ActionNameIndex
uint32
RotateBoxState::ActionNameIndex() const
@ -570,9 +609,9 @@ RotateBoxState::ActionNameIndex() const
}
// #pragma mark - OffsetCenterState
// SetOrigin
void
OffsetCenterState::SetOrigin(BPoint origin)
@ -591,6 +630,7 @@ OffsetCenterState::DragTo(BPoint current, uint32 modifiers)
fOrigin = current;
}
// UpdateViewCursor
void
OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
@ -598,6 +638,7 @@ OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
_SetViewCursor(view, kPathMoveCursor);
}
// ActionName
const char*
OffsetCenterState::ActionName() const
@ -605,11 +646,10 @@ OffsetCenterState::ActionName() const
return "Move Pivot";
}
// ActionNameIndex
uint32
OffsetCenterState::ActionNameIndex() const
{
return MOVE_PIVOT;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -20,16 +20,17 @@
using std::nothrow;
// constructor
TransformGradientBox::TransformGradientBox(CanvasView* view,
Gradient* gradient,
Shape* parentShape)
: TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
TransformGradientBox::TransformGradientBox(CanvasView* view, Gradient* gradient,
Shape* parentShape)
:
TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
fCanvasView(view),
fCanvasView(view),
fShape(parentShape),
fGradient(gradient)
fShape(parentShape),
fGradient(gradient)
{
if (fShape) {
fShape->Acquire();
@ -43,6 +44,7 @@ TransformGradientBox::TransformGradientBox(CanvasView* view,
}
}
// destructor
TransformGradientBox::~TransformGradientBox()
{
@ -54,6 +56,7 @@ TransformGradientBox::~TransformGradientBox()
fGradient->RemoveObserver(this);
}
// Update
void
TransformGradientBox::Update(bool deep)
@ -87,6 +90,7 @@ TransformGradientBox::Update(bool deep)
fGradient->AddObserver(this);
}
// ObjectChanged
void
TransformGradientBox::ObjectChanged(const Observable* object)
@ -112,6 +116,7 @@ TransformGradientBox::ObjectChanged(const Observable* object)
fView->UnlockLooper();
}
// Perform
Command*
TransformGradientBox::Perform()
@ -119,6 +124,7 @@ TransformGradientBox::Perform()
return NULL;
}
// Cancel
Command*
TransformGradientBox::Cancel()
@ -128,6 +134,7 @@ TransformGradientBox::Cancel()
return NULL;
}
// TransformFromCanvas
void
TransformGradientBox::TransformFromCanvas(BPoint& point) const
@ -137,6 +144,7 @@ TransformGradientBox::TransformFromCanvas(BPoint& point) const
fCanvasView->ConvertFromCanvas(&point);
}
// TransformToCanvas
void
TransformGradientBox::TransformToCanvas(BPoint& point) const
@ -146,6 +154,7 @@ TransformGradientBox::TransformToCanvas(BPoint& point) const
fShape->Transform(&point);
}
// ZoomLevel
float
TransformGradientBox::ZoomLevel() const
@ -153,6 +162,7 @@ TransformGradientBox::ZoomLevel() const
return fCanvasView->ZoomLevel();
}
// ViewSpaceRotation
double
TransformGradientBox::ViewSpaceRotation() const
@ -160,25 +170,19 @@ TransformGradientBox::ViewSpaceRotation() const
Transformable t(*this);
if (fShape)
t.Multiply(*fShape);
return t.rotation() * 180.0 / PI;
return t.rotation() * 180.0 / M_PI;
}
// MakeCommand
TransformCommand*
TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex)
{
Transformable* objects[1];
objects[0] = fGradient;
return new TransformObjectsCommand(this, objects, fOriginals, 1,
Pivot(),
Translation(),
LocalRotation(),
LocalXScale(),
LocalYScale(),
commandName,
nameIndex);
return new TransformObjectsCommand(this, objects, fOriginals, 1, Pivot(),
Translation(), LocalRotation(), LocalXScale(), LocalYScale(), commandName,
nameIndex);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -185,7 +185,7 @@ Transformable::Transform(BPoint* point) const
double y = point->y;
transform(&x, &y);
point->x = x;
point->y = y;
}
@ -216,7 +216,7 @@ Transformable::InverseTransform(BPoint* point) const
double y = point->y;
inverse_transform(&x, &y);
point->x = x;
point->y = y;
}
@ -235,13 +235,13 @@ inline float
min4(float a, float b, float c, float d)
{
return min_c(a, min_c(b, min_c(c, d)));
}
}
inline float
max4(float a, float b, float c, float d)
{
return max_c(a, max_c(b, max_c(c, d)));
}
}
// TransformBounds
BRect
@ -252,12 +252,12 @@ Transformable::TransformBounds(BRect bounds) const
BPoint rt(bounds.right, bounds.top);
BPoint lb(bounds.left, bounds.bottom);
BPoint rb(bounds.right, bounds.bottom);
Transform(&lt);
Transform(&rt);
Transform(&lb);
Transform(&rb);
return BRect(floorf(min4(lt.x, rt.x, lb.x, rb.x)),
floorf(min4(lt.y, rt.y, lb.y, rb.y)),
ceilf(max4(lt.x, rt.x, lb.x, rb.x)),
@ -282,7 +282,7 @@ Transformable::RotateBy(BPoint origin, double degrees)
{
if (degrees != 0.0) {
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));
TransformationChanged();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2006, Haiku.
* Copyright 2003-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -28,7 +28,8 @@ static const float kStopSize = 15.0f;
ScreenCornerSelector::ScreenCornerSelector(BRect frame, const char *name,
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),
fPreviousCorner(-1)
{
@ -47,7 +48,8 @@ ScreenCornerSelector::_MonitorFrame() const
else if (height * kAspectRatio > width)
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);
}
@ -68,7 +70,7 @@ ScreenCornerSelector::_CenterFrame(BRect innerFrame) const
void
ScreenCornerSelector::Draw(BRect update)
ScreenCornerSelector::Draw(BRect update)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
@ -82,36 +84,39 @@ ScreenCornerSelector::Draw(BRect update)
if (!_InnerFrame(outerRect).Contains(update)) {
// frame & background
// if the focus is changing, we don't redraw the whole view, but only
// the part that's affected by the change
if (!IsFocusChanging()) {
SetHighColor(darkColor);
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
kMonitorBorderSize * 3 / 2);
}
if (IsFocus() && Window()->IsActive())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(blackColor);
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
kMonitorBorderSize * 3 / 2);
if (!IsFocusChanging()) {
SetHighColor(210, 210, 255);
FillRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
}
if (IsFocus() && Window()->IsActive())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(blackColor);
StrokeRoundRect(innerRect, kMonitorBorderSize, kMonitorBorderSize);
if (IsFocusChanging())
return;
// power light
SetHighColor(redColor);
BPoint powerPos(outerRect.left + kMonitorBorderSize * 2, outerRect.bottom
- kMonitorBorderSize);
@ -175,7 +180,7 @@ ScreenCornerSelector::SetCorner(screen_corner corner)
void
ScreenCornerSelector::_DrawStop(BRect innerFrame)
ScreenCornerSelector::_DrawStop(BRect innerFrame)
{
BRect centerRect = _CenterFrame(innerFrame);
float size = kStopSize;
@ -188,13 +193,13 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
rect.left = centerRect.left + (centerRect.Width() - size) / 2;
}
rect.right = rect.left + size - 1;
rect.bottom = rect.top + size - 1;
rect.bottom = rect.top + size - 1;
SetHighColor(255, 0, 0);
SetPenSize(2);
StrokeEllipse(rect);
size -= ceilf(sin(PI / 4) * size + 2);
size -= ceilf(sin(M_PI / 4) * size + 2);
rect.InsetBy(size, size);
StrokeLine(rect.RightTop(), rect.LeftBottom());
@ -203,11 +208,13 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
void
ScreenCornerSelector::_DrawArrow(BRect innerFrame)
ScreenCornerSelector::_DrawArrow(BRect innerFrame)
{
float size = kArrowSize;
float sizeX = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
float sizeY = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
float sizeX = fCurrentCorner == UP_LEFT_CORNER
|| fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
float sizeY = fCurrentCorner == UP_LEFT_CORNER
|| fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
innerFrame.InsetBy(2, 2);
BPoint origin(sizeX < 0 ? innerFrame.right : innerFrame.left,
@ -220,7 +227,8 @@ ScreenCornerSelector::_DrawArrow(BRect innerFrame)
screen_corner
ScreenCornerSelector::_ScreenCorner(BPoint point, screen_corner previousCorner) const
ScreenCornerSelector::_ScreenCorner(BPoint point,
screen_corner previousCorner) const
{
BRect innerFrame = _InnerFrame(_MonitorFrame());
@ -240,7 +248,7 @@ ScreenCornerSelector::_ScreenCorner(BPoint point, screen_corner previousCorner)
void
ScreenCornerSelector::MouseDown(BPoint where)
ScreenCornerSelector::MouseDown(BPoint where)
{
fPreviousCorner = Value();
@ -250,14 +258,15 @@ ScreenCornerSelector::MouseDown(BPoint where)
void
ScreenCornerSelector::MouseUp(BPoint where)
ScreenCornerSelector::MouseUp(BPoint where)
{
fPreviousCorner = -1;
}
void
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
if (fPreviousCorner == -1)
return;

View File

@ -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.
*
* Authors:
@ -10,73 +10,70 @@
*/
#include "AnalogClock.h"
#include "TimeMessages.h"
#include <math.h>
#include <stdio.h>
#include <Bitmap.h>
#include <Message.h>
#include <Window.h>
#include <cmath>
#include <stdio.h>
#include "TimeMessages.h"
#define DRAG_DELTA_PHI 0.2
class OffscreenClock : public BView {
public:
OffscreenClock(BRect frame, const char *name);
~OffscreenClock();
public:
OffscreenClock(BRect frame, const char *name);
virtual ~OffscreenClock();
void SetTime(int32 hour, int32 minute, int32 second);
void GetTime(int32 *hour, int32 *minute, int32 *second);
bool IsDirty() const { return fDirty; }
void DrawClock();
void SetTime(int32 hour, int32 minute, int32 second);
void GetTime(int32 *hour, int32 *minute, int32 *second);
bool IsDirty() const { return fDirty; }
void DrawClock();
bool InHourHand(BPoint point);
bool InMinuteHand(BPoint point);
void SetHourHand(BPoint point);
void SetMinuteHand(BPoint point);
bool InHourHand(BPoint point);
bool InMinuteHand(BPoint point);
void SetHourDragging(bool val) {
fHourDragging = val;
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);
void SetHourHand(BPoint point);
void SetMinuteHand(BPoint point);
int32 fHours;
int32 fMinutes;
int32 fSeconds;
bool fDirty;
void SetHourDragging(bool dragging);
void SetMinuteDragging(bool dragging);
float fCenterX;
float fCenterY;
float fRadius;
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);
bool fHourDragging;
bool fMinuteDragging;
int32 fHours;
int32 fMinutes;
int32 fSeconds;
bool fDirty;
float fCenterX;
float fCenterY;
float fRadius;
bool fHourDragging;
bool fMinuteDragging;
};
OffscreenClock::OffscreenClock(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fHours(0),
fMinutes(0),
fSeconds(0),
fDirty(true),
fHourDragging(false),
fMinuteDragging(false)
:
BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fHours(0),
fMinutes(0),
fSeconds(0),
fDirty(true),
fHourDragging(false),
fMinuteDragging(false)
{
SetFlags(Flags() | B_SUBPIXEL_PRECISE);
@ -131,9 +128,9 @@ OffscreenClock::DrawClock()
SetHighColor(background);
FillRect(bounds);
bounds.Set(fCenterX - fRadius, fCenterY - fRadius,
fCenterX + fRadius, fCenterY + fRadius);
fCenterX + fRadius, fCenterY + fRadius);
SetPenSize(2.0);
@ -148,7 +145,7 @@ OffscreenClock::DrawClock()
SetLowColor(255, 255, 255);
FillEllipse(bounds, B_SOLID_LOW);
SetHighColor(tint_color(HighColor(), B_DARKEN_2_TINT));
// minutes
@ -157,10 +154,10 @@ OffscreenClock::DrawClock()
for (int32 minute = 1; minute < 60; minute++) {
if (minute % 5 == 0)
continue;
float x1 = fCenterX + sinf(minute * PI / 30.0) * fRadius;
float y1 = fCenterY + cosf(minute * PI / 30.0) * fRadius;
float x2 = fCenterX + sinf(minute * PI / 30.0) * (fRadius * 0.95);
float y2 = fCenterY + cosf(minute * PI / 30.0) * (fRadius * 0.95);
float x1 = fCenterX + sinf(minute * M_PI / 30.0) * fRadius;
float y1 = fCenterY + cosf(minute * M_PI / 30.0) * fRadius;
float x2 = fCenterX + sinf(minute * M_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));
}
@ -170,10 +167,10 @@ OffscreenClock::DrawClock()
SetPenSize(2.0);
SetLineMode(B_ROUND_CAP, B_MITER_JOIN);
for (int32 hour = 0; hour < 12; hour++) {
float x1 = fCenterX + sinf(hour * PI / 6.0) * fRadius;
float y1 = fCenterY + cosf(hour * PI / 6.0) * fRadius;
float x2 = fCenterX + sinf(hour * PI / 6.0) * (fRadius * 0.9);
float y2 = fCenterY + cosf(hour * PI / 6.0) * (fRadius * 0.9);
float x1 = fCenterX + sinf(hour * M_PI / 6.0) * fRadius;
float y1 = fCenterY + cosf(hour * M_PI / 6.0) * fRadius;
float x2 = fCenterX + sinf(hour * M_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));
}
@ -183,19 +180,21 @@ OffscreenClock::DrawClock()
hourColor = (rgb_color){ 0, 0, 255, 255 };
else
hourColor = tint_color(HighColor(), B_DARKEN_2_TINT);
rgb_color minuteColor;
if (fMinuteDragging)
minuteColor = (rgb_color){ 0, 0, 255, 255 };
else
minuteColor = tint_color(HighColor(), B_DARKEN_2_TINT);
rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 };
rgb_color shadowColor = tint_color(LowColor(),
(B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2);
_DrawHands(fCenterX + 1.5, fCenterY + 1.5, fRadius,
shadowColor, shadowColor, shadowColor, shadowColor);
shadowColor, shadowColor, shadowColor, shadowColor);
_DrawHands(fCenterX, fCenterY, fRadius,
hourColor, minuteColor, secondsColor, knobColor);
hourColor, minuteColor, secondsColor, knobColor);
Sync();
@ -231,7 +230,7 @@ OffscreenClock::SetHourHand(BPoint point)
point.y -= fCenterY;
float pointPhi = _GetPhi(point);
float hoursExact = 6.0 * pointPhi / PI;
float hoursExact = 6.0 * pointPhi / M_PI;
if (fHours >= 12)
fHours = 12;
else
@ -249,50 +248,67 @@ OffscreenClock::SetMinuteHand(BPoint point)
point.y -= fCenterY;
float pointPhi = _GetPhi(point);
float minutesExact = 30.0 * pointPhi / PI;
float minutesExact = 30.0 * pointPhi / M_PI;
fMinutes = int32(ceilf(minutesExact));
SetTime(fHours, fMinutes, fSeconds);
}
void
OffscreenClock::SetHourDragging(bool dragging)
{
fHourDragging = dragging;
fDirty = true;
}
void
OffscreenClock::SetMinuteDragging(bool dragging)
{
fMinuteDragging = dragging;
fDirty = true;
}
float
OffscreenClock::_GetPhi(BPoint point)
{
if (point.x == 0 && point.y < 0)
return 2 * PI;
return 2 * M_PI;
if (point.x == 0 && point.y > 0)
return PI;
return M_PI;
if (point.y == 0 && point.x < 0)
return PI * 3 / 2;
return M_PI * 3 / 2;
if (point.y == 0 && point.x > 0)
return PI / 2;
return M_PI / 2;
float pointPhi = atanf(-1. * point.y / point.x);
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
pointPhi = PI / 2 - pointPhi;
pointPhi = M_PI / 2 - pointPhi;
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
pointPhi = 3. / 2. * PI - pointPhi;
pointPhi = 3. / 2. * M_PI - pointPhi;
return pointPhi;
}
bool
OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
{
point.x -= fCenterX;
point.y -= fCenterY;
float pRadius = sqrt(pow(point.x, 2) + pow(point.y, 2));
if (radius < pRadius)
return false;
float pointPhi = _GetPhi(point);
float handPhi = PI / 30.0 * ticks;
float handPhi = M_PI / 30.0 * ticks;
float delta = pointPhi - handPhi;
if (fabs(delta) > DRAG_DELTA_PHI)
return false;
@ -315,23 +331,23 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
SetHighColor(hourColor);
SetPenSize(4.0);
float hours = fHours + float(fMinutes) / 60.0;
offsetX = (radius * 0.7) * sinf((hours * PI) / 6.0);
offsetY = (radius * 0.7) * cosf((hours * PI) / 6.0);
offsetX = (radius * 0.7) * sinf((hours * M_PI) / 6.0);
offsetY = (radius * 0.7) * cosf((hours * M_PI) / 6.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// calc, draw minute hand
SetHighColor(minuteColor);
SetPenSize(3.0);
float minutes = fMinutes + float(fSeconds) / 60.0;
offsetX = (radius * 0.9) * sinf((minutes * PI) / 30.0);
offsetY = (radius * 0.9) * cosf((minutes * PI) / 30.0);
offsetX = (radius * 0.9) * sinf((minutes * M_PI) / 30.0);
offsetY = (radius * 0.9) * cosf((minutes * M_PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// calc, draw second hand
SetHighColor(secondsColor);
SetPenSize(1.0);
offsetX = (radius * 0.95) * sinf((fSeconds * PI) / 30.0);
offsetY = (radius * 0.95) * cosf((fSeconds * PI) / 30.0);
offsetX = (radius * 0.95) * sinf((fSeconds * M_PI) / 30.0);
offsetY = (radius * 0.95) * cosf((fSeconds * M_PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// draw the center knob
@ -344,7 +360,8 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
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),
fClock(NULL),
fDraggingHourHand(false),
@ -429,6 +446,7 @@ TAnalogClock::MouseDown(BPoint point)
}
}
void
TAnalogClock::MouseUp(BPoint point)
{
@ -452,7 +470,7 @@ TAnalogClock::MouseUp(BPoint point)
void
TAnalogClock::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
if (fDraggingMinuteHand)
fClock->SetMinuteHand(point);
if (fDraggingHourHand)
@ -482,7 +500,7 @@ TAnalogClock::SetTime(int32 hour, int32 minute, int32 second)
if (fClock)
fClock->SetTime(hour, minute, second);
Invalidate();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Haiku.
* Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -881,8 +881,8 @@ ServerFont::EmbeddedTransformation() const
// TODO: cache this?
Transformable transform;
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * PI / 180.0, 0.0);
transform.RotateBy(B_ORIGIN, -fRotation * PI / 180.0);
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * M_PI / 180.0, 0.0);
transform.RotateBy(B_ORIGIN, -fRotation * M_PI / 180.0);
return transform;
}

View File

@ -76,9 +76,9 @@ AGGTextRenderer::SetFont(const ServerFont& font)
// construct an embedded transformation (rotate & shear)
fEmbeddedTransformation.Reset();
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,
-font.Rotation() * PI / 180.0);
-font.Rotation() * M_PI / 180.0);
fContour.width(font.FalseBoldWidth() * 2.0);
}

View File

@ -81,6 +81,7 @@ using std::nothrow;
#define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1);
#define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return;
// constructor
Painter::Painter()
:
@ -1222,7 +1223,7 @@ Painter::DrawEllipse(BRect r, bool fill) const
float yRadius = r.Height() / 2.0;
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)
divisions = 12;
if (divisions > 4096)
@ -1295,7 +1296,7 @@ Painter::FillEllipse(BRect r, const BGradient& gradient) const
float yRadius = r.Height() / 2.0;
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)
divisions = 12;
if (divisions > 4096)
@ -1316,8 +1317,8 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);
@ -1337,8 +1338,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);
@ -1374,8 +1375,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);