* 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
+2 -5
View File
@@ -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)
@@ -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;
} }
+99 -114
View File
@@ -1,32 +1,11 @@
/* /*
* 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>
@@ -47,22 +26,20 @@ 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;
@@ -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,16 +74,38 @@ 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"
};
// #pragma mark -
// --------------------------------------------------
static bool static bool
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index) find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
{ {
@@ -134,9 +133,9 @@ find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
} }
// --------------------------------------------------
static bool static bool
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_encoding* order) 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++) { 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,9 +170,10 @@ 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;
@@ -186,7 +186,7 @@ PDFWriter::RecordFont(const char* family, const char* style, float size) {
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)
{ {
@@ -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,35 +220,12 @@ 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 int
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding) 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);
@@ -272,20 +250,21 @@ PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
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)
{ {
@@ -296,7 +275,8 @@ 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;
@@ -307,7 +287,6 @@ PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
}; };
// --------------------------------------------------
void void
PDFWriter::ToUnicode(const char *string, BString &unicode) PDFWriter::ToUnicode(const char *string, BString &unicode)
{ {
@@ -322,7 +301,8 @@ PDFWriter::ToUnicode(const char *string, BString &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;
@@ -336,7 +316,6 @@ PDFWriter::ToUnicode(const char *string, BString &unicode)
} }
// --------------------------------------------------
void void
PDFWriter::ToPDFUnicode(const char *string, BString &unicode) PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
{ {
@@ -346,14 +325,14 @@ PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
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)
{ {
@@ -363,14 +342,14 @@ PDFWriter::CodePointSize(const char* s)
} }
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)
{ {
@@ -383,11 +362,12 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
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);
@@ -395,10 +375,12 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
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);
@@ -425,16 +407,20 @@ 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;
@@ -442,15 +428,18 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
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_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0
? "true" : "false");
PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0); 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()));
@@ -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];
@@ -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!
@@ -574,9 +565,9 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_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;
@@ -599,19 +590,13 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
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)
{ {
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;
@@ -394,8 +370,6 @@ 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)
{ {
@@ -405,7 +379,6 @@ 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)
{ {
@@ -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
+18 -20
View File
@@ -1510,32 +1510,30 @@ void FlangerNode::filterBuffer(
} }
} }
// figure the rate at which the (radial) read offset changes,
// based on the given sweep rate (in Hz)
float calc_sweep_delta( /*! Figure the rate at which the (radial) read offset changes,
const media_raw_audio_format& format, based on the given sweep rate (in Hz)
float fRate) { */
float
return 2*PI * fRate / format.frame_rate; calc_sweep_delta(const media_raw_audio_format& format, float fRate)
{
return 2 * M_PI * fRate / format.frame_rate;
} }
// figure the base delay (in frames) based on the given /*! Figure the base delay (in frames) based on the given
// sweep delay/depth (in msec) sweep delay/depth (in msec)
*/
float calc_sweep_base( float
const media_raw_audio_format& format, calc_sweep_base(const media_raw_audio_format& format, float delay, float depth)
float fDelay, float fDepth) { {
return (format.frame_rate * (delay + depth)) / 1000.0;
return
(format.frame_rate * (fDelay + fDepth)) / 1000.0;
} }
float calc_sweep_factor(
const media_raw_audio_format& format,
float fDepth) {
return (format.frame_rate * fDepth) / 1000.0; float
calc_sweep_factor(const media_raw_audio_format& format, float depth)
{
return (format.frame_rate * depth) / 1000.0;
} }
+10 -8
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. * 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);
} }
@@ -120,7 +122,7 @@ FontDemoView::_DrawView(BView* view)
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);
@@ -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,7 +43,7 @@ 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));
} }
@@ -51,14 +52,14 @@ point_line_distance(BPoint point, BPoint pa, BPoint pb)
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);
@@ -71,12 +72,13 @@ calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
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,6 +130,7 @@ append_float(BString& string, float n, int32 maxDigits)
} }
} }
//// gauss //// gauss
//double //double
//gauss(double f) //gauss(double f)
@@ -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,9 +11,11 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
// constructor // constructor
ChannelTransform::ChannelTransform() ChannelTransform::ChannelTransform()
: Transformable(), :
Transformable(),
fPivot(0.0, 0.0), fPivot(0.0, 0.0),
fTranslation(0.0, 0.0), fTranslation(0.0, 0.0),
fRotation(0.0), fRotation(0.0),
@@ -24,7 +26,8 @@ ChannelTransform::ChannelTransform()
// copy constructor // copy constructor
ChannelTransform::ChannelTransform(const ChannelTransform& other) ChannelTransform::ChannelTransform(const ChannelTransform& other)
: Transformable(other), :
Transformable(other),
fPivot(other.fPivot), fPivot(other.fPivot),
fTranslation(other.fTranslation), fTranslation(other.fTranslation),
fRotation(other.fRotation), fRotation(other.fRotation),
@@ -33,11 +36,13 @@ ChannelTransform::ChannelTransform(const ChannelTransform& other)
{ {
} }
// 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,
@@ -91,6 +94,7 @@ ChannelTransform::SetTransformation(BPoint pivot,
} }
} }
// 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,7 +257,7 @@ 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));
@@ -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,16 +21,27 @@
#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(), :
ChannelTransform(),
Manipulator(NULL), Manipulator(NULL),
fOriginalBox(box), fOriginalBox(box),
@@ -42,7 +53,6 @@ TransformBox::TransformBox(StateView* view, BRect box)
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), fCurrentCommand(NULL),
fCurrentState(NULL), fCurrentState(NULL),
@@ -70,6 +80,7 @@ TransformBox::TransformBox(StateView* view, BRect box)
{ {
} }
// 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)
@@ -153,6 +167,7 @@ TransformBox::MouseDown(BPoint where)
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)
@@ -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.x, end.x),
max_c(start.y, end.y)); 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), :
fOrigin(0.0, 0.0),
fParent(parent) 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), :
DragState(parent),
fCorner(corner) fCorner(corner)
{ {
} }
// SetOrigin // SetOrigin
void void
DragCornerState::SetOrigin(BPoint origin) DragCornerState::SetOrigin(BPoint origin)
@@ -78,7 +87,8 @@ 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));
@@ -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), :
DragState(parent),
fSide(side) fSide(side)
{ {
} }
// SetOrigin // SetOrigin
void void
DragSideState::SetOrigin(BPoint origin) DragSideState::SetOrigin(BPoint origin)
@@ -300,7 +323,8 @@ 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));
@@ -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), :
DragState(parent),
fOldAngle(0.0) 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,11 +20,12 @@
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),
@@ -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,9 +170,10 @@ 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)
@@ -170,15 +181,8 @@ 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, return new TransformObjectsCommand(this, objects, fOriginals, 1, Pivot(),
Translation(), LocalRotation(), LocalXScale(), LocalYScale(), commandName,
Pivot(),
Translation(),
LocalRotation(),
LocalXScale(),
LocalYScale(),
commandName,
nameIndex); nameIndex);
} }
+183 -184
View File
@@ -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:
@@ -38,37 +38,32 @@
#include "Transformable.h" #include "Transformable.h"
#define obj_new(type, n) ((type *)malloc ((n) * sizeof(type))) #define obj_new(type, n) ((type *)malloc ((n) * sizeof(type)))
#define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type))) #define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type)))
#define obj_free free #define obj_free free
#define ALLOC_CHUNKS 20 #define ALLOC_CHUNKS 20
// get_path_storage
bool bool
get_path_storage(agg::path_storage& path, get_path_storage(agg::path_storage& path, const control_point* points,
const control_point* points, int32 count, bool closed) int32 count, bool closed)
{ {
if (count > 1) { if (count > 1) {
path.move_to(points[0].point.x, path.move_to(points[0].point.x, points[0].point.y);
points[0].point.y);
for (int32 i = 1; i < count; i++) { for (int32 i = 1; i < count; i++) {
path.curve4(points[i - 1].point_out.x, path.curve4(points[i - 1].point_out.x, points[i - 1].point_out.y,
points[i - 1].point_out.y, points[i].point_in.x, points[i].point_in.y,
points[i].point_in.x, points[i].point.x, points[i].point.y);
points[i].point_in.y,
points[i].point.x,
points[i].point.y);
} }
if (closed) { if (closed) {
// curve from last to first control point // curve from last to first control point
path.curve4(points[count - 1].point_out.x, path.curve4(
points[count - 1].point_out.y, points[count - 1].point_out.x, points[count - 1].point_out.y,
points[0].point_in.x, points[0].point_in.x, points[0].point_in.y,
points[0].point_in.y, points[0].point.x, points[0].point.y);
points[0].point.x,
points[0].point.y);
path.close_polygon(); path.close_polygon();
} }
@@ -77,23 +72,31 @@ get_path_storage(agg::path_storage& path,
return false; return false;
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
PathListener::PathListener() {} PathListener::PathListener()
PathListener::~PathListener() {} {
}
PathListener::~PathListener()
{
}
#endif #endif
// #pragma mark - // #pragma mark -
// constructor
VectorPath::VectorPath() VectorPath::VectorPath()
:
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
: BArchivable(), BArchivable(),
IconObject("<path>"), IconObject("<path>"),
fListeners(20), fListeners(20),
#else
:
#endif #endif
fPath(NULL), fPath(NULL),
fClosed(false), fClosed(false),
@@ -103,14 +106,13 @@ VectorPath::VectorPath()
{ {
} }
// constructor
VectorPath::VectorPath(const VectorPath& from) VectorPath::VectorPath(const VectorPath& from)
:
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
: BArchivable(), BArchivable(),
IconObject(from), IconObject(from),
fListeners(20), fListeners(20),
#else
:
#endif #endif
fPath(NULL), fPath(NULL),
fClosed(false), fClosed(false),
@@ -121,14 +123,13 @@ VectorPath::VectorPath(const VectorPath& from)
*this = from; *this = from;
} }
// constructor
VectorPath::VectorPath(BMessage* archive) VectorPath::VectorPath(BMessage* archive)
:
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
: BArchivable(), BArchivable(),
IconObject(archive), IconObject(archive),
fListeners(20), fListeners(20),
#else
:
#endif #endif
fPath(NULL), fPath(NULL),
fClosed(false), fClosed(false),
@@ -144,7 +145,6 @@ VectorPath::VectorPath(BMessage* archive)
if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK
&& typeFound == B_POINT_TYPE && typeFound == B_POINT_TYPE
&& _SetPointCount(countFound)) { && _SetPointCount(countFound)) {
memset(fPath, 0, fAllocCount * sizeof(control_point)); memset(fPath, 0, fAllocCount * sizeof(control_point));
BPoint point; BPoint point;
@@ -167,7 +167,7 @@ VectorPath::VectorPath(BMessage* archive)
} }
// destructor
VectorPath::~VectorPath() VectorPath::~VectorPath()
{ {
if (fPath) if (fPath)
@@ -185,11 +185,12 @@ VectorPath::~VectorPath()
#endif #endif
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// MakePropertyObject
PropertyObject* PropertyObject*
VectorPath::MakePropertyObject() const VectorPath::MakePropertyObject() const
{ {
@@ -204,27 +205,22 @@ VectorPath::MakePropertyObject() const
BMessage* archive = new BMessage(); BMessage* archive = new BMessage();
if (Archive(archive) == B_OK) { if (Archive(archive) == B_OK) {
object->AddProperty(new IconProperty(PROPERTY_PATH, object->AddProperty(new IconProperty(PROPERTY_PATH,
kPathPropertyIconBits, kPathPropertyIconBits, kPathPropertyIconWidth,
kPathPropertyIconWidth, kPathPropertyIconHeight, kPathPropertyIconFormat, archive));
kPathPropertyIconHeight,
kPathPropertyIconFormat,
archive));
} }
return object; return object;
} }
// SetToPropertyObject
bool bool
VectorPath::SetToPropertyObject(const PropertyObject* object) VectorPath::SetToPropertyObject(const PropertyObject* object)
{ {
AutoNotificationSuspender _(this); AutoNotificationSuspender _(this);
IconObject::SetToPropertyObject(object); IconObject::SetToPropertyObject(object);
// closed
SetClosed(object->Value(PROPERTY_CLOSED, fClosed)); SetClosed(object->Value(PROPERTY_CLOSED, fClosed));
// archived path
IconProperty* pathProperty = dynamic_cast<IconProperty*>( IconProperty* pathProperty = dynamic_cast<IconProperty*>(
object->FindProperty(PROPERTY_PATH)); object->FindProperty(PROPERTY_PATH));
if (pathProperty && pathProperty->Message()) { if (pathProperty && pathProperty->Message()) {
@@ -235,12 +231,12 @@ VectorPath::SetToPropertyObject(const PropertyObject* object)
return HasPendingNotifications(); return HasPendingNotifications();
} }
// Archive
status_t status_t
VectorPath::Archive(BMessage* into, bool deep) const VectorPath::Archive(BMessage* into, bool deep) const
{ {
status_t ret = IconObject::Archive(into, deep); status_t ret = IconObject::Archive(into, deep);
if (ret < B_OK) if (ret != B_OK)
return ret; return ret;
if (fPointCount > 0) { if (fPointCount > 0) {
@@ -248,48 +244,59 @@ VectorPath::Archive(BMessage* into, bool deep) const
// with the first call // with the first call
ret = into->AddData("point", B_POINT_TYPE, &fPath[0].point, ret = into->AddData("point", B_POINT_TYPE, &fPath[0].point,
sizeof(BPoint), true, fPointCount); sizeof(BPoint), true, fPointCount);
if (ret >= B_OK) if (ret >= B_OK) {
ret = into->AddData("point in", B_POINT_TYPE, &fPath[0].point_in, ret = into->AddData("point in", B_POINT_TYPE, &fPath[0].point_in,
sizeof(BPoint), true, fPointCount); sizeof(BPoint), true, fPointCount);
if (ret >= B_OK) }
if (ret >= B_OK) {
ret = into->AddData("point out", B_POINT_TYPE, &fPath[0].point_out, ret = into->AddData("point out", B_POINT_TYPE, &fPath[0].point_out,
sizeof(BPoint), true, fPointCount); sizeof(BPoint), true, fPointCount);
if (ret >= B_OK) }
if (ret >= B_OK) {
ret = into->AddData("connected", B_BOOL_TYPE, &fPath[0].connected, ret = into->AddData("connected", B_BOOL_TYPE, &fPath[0].connected,
sizeof(bool), true, fPointCount); sizeof(bool), true, fPointCount);
}
// add the rest of the points // add the rest of the points
for (int32 i = 1; i < fPointCount && ret >= B_OK; i++) { for (int32 i = 1; i < fPointCount && ret >= B_OK; i++) {
ret = into->AddData("point", B_POINT_TYPE, &fPath[i].point, sizeof(BPoint)); ret = into->AddData("point", B_POINT_TYPE, &fPath[i].point,
if (ret >= B_OK) sizeof(BPoint));
ret = into->AddData("point in", B_POINT_TYPE, &fPath[i].point_in, sizeof(BPoint)); if (ret >= B_OK) {
if (ret >= B_OK) ret = into->AddData("point in", B_POINT_TYPE, &fPath[i].point_in,
ret = into->AddData("point out", B_POINT_TYPE, &fPath[i].point_out, sizeof(BPoint)); sizeof(BPoint));
if (ret >= B_OK) }
ret = into->AddData("connected", B_BOOL_TYPE, &fPath[i].connected, sizeof(bool)); if (ret >= B_OK) {
ret = into->AddData("point out", B_POINT_TYPE,
&fPath[i].point_out, sizeof(BPoint));
}
if (ret >= B_OK) {
ret = into->AddData("connected", B_BOOL_TYPE,
&fPath[i].connected, sizeof(bool));
}
} }
} }
if (ret >= B_OK) { if (ret >= B_OK)
ret = into->AddBool("path closed", fClosed); ret = into->AddBool("path closed", fClosed);
} else { else
fprintf(stderr, "failed adding points!\n"); fprintf(stderr, "failed adding points!\n");
}
if (ret < B_OK) { if (ret < B_OK)
fprintf(stderr, "failed adding close!\n"); fprintf(stderr, "failed adding close!\n");
}
// finish off // finish off
if (ret < B_OK) { if (ret < B_OK)
ret = into->AddString("class", "VectorPath"); ret = into->AddString("class", "VectorPath");
}
return ret; return ret;
} }
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
// #pragma mark - // #pragma mark -
// operator=
VectorPath& VectorPath&
VectorPath::operator=(const VectorPath& from) VectorPath::operator=(const VectorPath& from)
{ {
@@ -309,16 +316,17 @@ VectorPath::operator=(const VectorPath& from)
return *this; return *this;
} }
// MakeEmpty
void void
VectorPath::MakeEmpty() VectorPath::MakeEmpty()
{ {
_SetPointCount(0); _SetPointCount(0);
} }
// #pragma mark - // #pragma mark -
// AddPoint
bool bool
VectorPath::AddPoint(BPoint point) VectorPath::AddPoint(BPoint point)
{ {
@@ -333,12 +341,10 @@ VectorPath::AddPoint(BPoint point)
return false; return false;
} }
// AddPoint
bool bool
VectorPath::AddPoint(const BPoint& point, VectorPath::AddPoint(const BPoint& point, const BPoint& pointIn,
const BPoint& pointIn, const BPoint& pointOut, bool connected)
const BPoint& pointOut,
bool connected)
{ {
int32 index = fPointCount; int32 index = fPointCount;
@@ -351,7 +357,7 @@ VectorPath::AddPoint(const BPoint& point,
return false; return false;
} }
// AddPoint
bool bool
VectorPath::AddPoint(BPoint point, int32 index) VectorPath::AddPoint(BPoint point, int32 index)
{ {
@@ -377,12 +383,11 @@ VectorPath::AddPoint(BPoint point, int32 index)
return false; return false;
} }
// RemovePoint
bool bool
VectorPath::RemovePoint(int32 index) VectorPath::RemovePoint(int32 index)
{ {
if (index >= 0 && index < fPointCount) { if (index >= 0 && index < fPointCount) {
if (index < fPointCount - 1) { if (index < fPointCount - 1) {
// move points // move points
for (int32 i = index; i < fPointCount - 1; i++) { for (int32 i = index; i < fPointCount - 1; i++) {
@@ -402,7 +407,7 @@ VectorPath::RemovePoint(int32 index)
return false; return false;
} }
// SetPoint
bool bool
VectorPath::SetPoint(int32 index, BPoint point) VectorPath::SetPoint(int32 index, BPoint point)
{ {
@@ -422,10 +427,9 @@ VectorPath::SetPoint(int32 index, BPoint point)
return false; return false;
} }
// SetPoint
bool bool
VectorPath::SetPoint(int32 index, BPoint point, VectorPath::SetPoint(int32 index, BPoint point, BPoint pointIn, BPoint pointOut,
BPoint pointIn, BPoint pointOut,
bool connected) bool connected)
{ {
if (index == fPointCount) if (index == fPointCount)
@@ -444,7 +448,7 @@ VectorPath::SetPoint(int32 index, BPoint point,
return false; return false;
} }
// SetPointIn
bool bool
VectorPath::SetPointIn(int32 i, BPoint point) VectorPath::SetPointIn(int32 i, BPoint point)
{ {
@@ -459,7 +463,8 @@ VectorPath::SetPointIn(int32 i, BPoint point)
BPoint v = fPath[i].point - fPath[i].point_in; BPoint v = fPath[i].point - fPath[i].point_in;
float distIn = sqrtf(v.x * v.x + v.y * v.y); float distIn = sqrtf(v.x * v.x + v.y * v.y);
if (distIn > 0.0) { if (distIn > 0.0) {
float distOut = agg::calc_distance(fPath[i].point.x, fPath[i].point.y, float distOut = agg::calc_distance(
fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y); fPath[i].point_out.x, fPath[i].point_out.y);
float scale = (distIn + distOut) / distIn; float scale = (distIn + distOut) / distIn;
v.x *= scale; v.x *= scale;
@@ -476,7 +481,7 @@ VectorPath::SetPointIn(int32 i, BPoint point)
return false; return false;
} }
// SetPointOut
bool bool
VectorPath::SetPointOut(int32 i, BPoint point, bool mirrorDist) VectorPath::SetPointOut(int32 i, BPoint point, bool mirrorDist)
{ {
@@ -495,7 +500,8 @@ VectorPath::SetPointOut(int32 i, BPoint point, bool mirrorDist)
BPoint v = fPath[i].point - fPath[i].point_out; BPoint v = fPath[i].point - fPath[i].point_out;
float distOut = sqrtf(v.x * v.x + v.y * v.y); float distOut = sqrtf(v.x * v.x + v.y * v.y);
if (distOut > 0.0) { if (distOut > 0.0) {
float distIn = agg::calc_distance(fPath[i].point.x, fPath[i].point.y, float distIn = agg::calc_distance(
fPath[i].point.x, fPath[i].point.y,
fPath[i].point_in.x, fPath[i].point_in.y); fPath[i].point_in.x, fPath[i].point_in.y);
float scale = (distIn + distOut) / distOut; float scale = (distIn + distOut) / distOut;
v.x *= scale; v.x *= scale;
@@ -512,7 +518,7 @@ VectorPath::SetPointOut(int32 i, BPoint point, bool mirrorDist)
return false; return false;
} }
// SetInOutConnected
bool bool
VectorPath::SetInOutConnected(int32 index, bool connected) VectorPath::SetInOutConnected(int32 index, bool connected)
{ {
@@ -524,9 +530,10 @@ VectorPath::SetInOutConnected(int32 index, bool connected)
return false; return false;
} }
// #pragma mark - // #pragma mark -
// GetPointAt
bool bool
VectorPath::GetPointAt(int32 index, BPoint& point) const VectorPath::GetPointAt(int32 index, BPoint& point) const
{ {
@@ -539,7 +546,7 @@ VectorPath::GetPointAt(int32 index, BPoint& point) const
return false; return false;
} }
// GetPointInAt
bool bool
VectorPath::GetPointInAt(int32 index, BPoint& point) const VectorPath::GetPointInAt(int32 index, BPoint& point) const
{ {
@@ -552,7 +559,7 @@ VectorPath::GetPointInAt(int32 index, BPoint& point) const
return false; return false;
} }
// GetPointOutAt
bool bool
VectorPath::GetPointOutAt(int32 index, BPoint& point) const VectorPath::GetPointOutAt(int32 index, BPoint& point) const
{ {
@@ -565,10 +572,10 @@ VectorPath::GetPointOutAt(int32 index, BPoint& point) const
return false; return false;
} }
// GetPointsAt
bool bool
VectorPath::GetPointsAt(int32 index, BPoint& point, VectorPath::GetPointsAt(int32 index, BPoint& point, BPoint& pointIn,
BPoint& pointIn, BPoint& pointOut, bool* connected) const BPoint& pointOut, bool* connected) const
{ {
if (index >= 0 && index < fPointCount) { if (index >= 0 && index < fPointCount) {
point = fPath[index].point; point = fPath[index].point;
@@ -583,23 +590,24 @@ VectorPath::GetPointsAt(int32 index, BPoint& point,
return false; return false;
} }
// CountPoints
int32 int32
VectorPath::CountPoints() const VectorPath::CountPoints() const
{ {
return fPointCount; return fPointCount;
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// distance_to_curve
static float static float
distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BPoint& bIn, const BPoint& b) distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut,
const BPoint& bIn, const BPoint& b)
{ {
agg::curve4_inc curve(a.x, a.y, aOut.x, aOut.y, agg::curve4_inc curve(a.x, a.y, aOut.x, aOut.y, bIn.x, bIn.y, b.x, b.y);
bIn.x, bIn.y, b.x, b.y);
float segDist = FLT_MAX; float segDist = FLT_MAX;
double x1, y1, x2, y2; double x1, y1, x2, y2;
@@ -618,22 +626,22 @@ distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BP
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(agg::calc_line_point_distance( currentDist = fabs(agg::calc_line_point_distance(x1, y1, x2, y2,
x1, y1, x2, y2, p.x, p.y)); p.x, p.y));
} }
} }
if (currentDist < segDist) { if (currentDist < segDist)
segDist = currentDist; segDist = currentDist;
}
x1 = x2; x1 = x2;
y1 = y2; y1 = y2;
} }
return segDist; return segDist;
} }
// GetDistance
bool bool
VectorPath::GetDistance(BPoint p, float* distance, int32* index) const VectorPath::GetDistance(BPoint p, float* distance, int32* index) const
{ {
@@ -643,21 +651,16 @@ VectorPath::GetDistance(BPoint p, float* distance, int32* index) const
*distance = FLT_MAX; *distance = FLT_MAX;
for (int32 i = 0; i < fPointCount - 1; i++) { for (int32 i = 0; i < fPointCount - 1; i++) {
float segDist = distance_to_curve(p, float segDist = distance_to_curve(p, fPath[i].point,
fPath[i].point, fPath[i].point_out, fPath[i + 1].point_in, fPath[i + 1].point);
fPath[i].point_out,
fPath[i + 1].point_in,
fPath[i + 1].point);
if (segDist < *distance) { if (segDist < *distance) {
*distance = segDist; *distance = segDist;
*index = i + 1; *index = i + 1;
} }
} }
if (fClosed) { if (fClosed) {
float segDist = distance_to_curve(p, float segDist = distance_to_curve(p, fPath[fPointCount - 1].point,
fPath[fPointCount - 1].point, fPath[fPointCount - 1].point_out, fPath[0].point_in,
fPath[fPointCount - 1].point_out,
fPath[0].point_in,
fPath[0].point); fPath[0].point);
if (segDist < *distance) { if (segDist < *distance) {
*distance = segDist; *distance = segDist;
@@ -669,12 +672,11 @@ VectorPath::GetDistance(BPoint p, float* distance, int32* index) const
return false; return false;
} }
// FindBezierScale
bool bool
VectorPath::FindBezierScale(int32 index, BPoint point, double* scale) const VectorPath::FindBezierScale(int32 index, BPoint point, double* scale) const
{ {
if (index >= 0 && index < fPointCount && scale) { if (index >= 0 && index < fPointCount && scale) {
int maxStep = 1000; int maxStep = 1000;
double t = 0.0; double t = 0.0;
@@ -701,37 +703,32 @@ VectorPath::FindBezierScale(int32 index, BPoint point, double* scale) const
return false; return false;
} }
// GetPoint
bool bool
VectorPath::GetPoint(int32 index, double t, BPoint& point) const VectorPath::GetPoint(int32 index, double t, BPoint& point) const
{ {
if (index >= 0 && index < fPointCount) { if (index >= 0 && index < fPointCount) {
double t1 = (1 - t) * (1 - t) * (1 - t); double t1 = (1 - t) * (1 - t) * (1 - t);
double t2 = (1 - t) * (1 - t) * t * 3; double t2 = (1 - t) * (1 - t) * t * 3;
double t3 = (1 - t) * t * t * 3; double t3 = (1 - t) * t * t * 3;
double t4 = t * t * t; double t4 = t * t * t;
if (index < fPointCount - 1) { if (index < fPointCount - 1) {
point.x = fPath[index].point.x * t1 + point.x = fPath[index].point.x * t1 + fPath[index].point_out.x * t2
fPath[index].point_out.x * t2 + + fPath[index + 1].point_in.x * t3
fPath[index + 1].point_in.x * t3 + + fPath[index + 1].point.x * t4;
fPath[index + 1].point.x * t4;
point.y = fPath[index].point.y * t1 + point.y = fPath[index].point.y * t1 + fPath[index].point_out.y * t2
fPath[index].point_out.y * t2 + + fPath[index + 1].point_in.y * t3
fPath[index + 1].point_in.y * t3 + + fPath[index + 1].point.y * t4;
fPath[index + 1].point.y * t4;
} else if (fClosed) { } else if (fClosed) {
point.x = fPath[fPointCount - 1].point.x * t1 + point.x = fPath[fPointCount - 1].point.x * t1
fPath[fPointCount - 1].point_out.x * t2 + + fPath[fPointCount - 1].point_out.x * t2
fPath[0].point_in.x * t3 + + fPath[0].point_in.x * t3 + fPath[0].point.x * t4;
fPath[0].point.x * t4;
point.y = fPath[fPointCount - 1].point.y * t1 + point.y = fPath[fPointCount - 1].point.y * t1
fPath[fPointCount - 1].point_out.y * t2 + + fPath[fPointCount - 1].point_out.y * t2
fPath[0].point_in.y * t3 + + fPath[0].point_in.y * t3 + fPath[0].point.y * t4;
fPath[0].point.y * t4;
} }
return true; return true;
@@ -741,7 +738,7 @@ VectorPath::GetPoint(int32 index, double t, BPoint& point) const
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
// SetClosed
void void
VectorPath::SetClosed(bool closed) VectorPath::SetClosed(bool closed)
{ {
@@ -752,7 +749,7 @@ VectorPath::SetClosed(bool closed)
} }
} }
// Bounds
BRect BRect
VectorPath::Bounds() const VectorPath::Bounds() const
{ {
@@ -762,7 +759,7 @@ VectorPath::Bounds() const
return fCachedBounds; return fCachedBounds;
} }
// Bounds
BRect BRect
VectorPath::_Bounds() const VectorPath::_Bounds() const
{ {
@@ -770,7 +767,6 @@ VectorPath::_Bounds() const
BRect b; BRect b;
if (get_path_storage(path, fPath, fPointCount, fClosed)) { if (get_path_storage(path, fPath, fPointCount, fClosed)) {
agg::conv_curve<agg::path_storage> curve(path); agg::conv_curve<agg::path_storage> curve(path);
uint32 pathID[1]; uint32 pathID[1];
@@ -781,14 +777,15 @@ VectorPath::_Bounds() const
b.Set(left, top, right, bottom); b.Set(left, top, right, bottom);
} else if (fPointCount == 1) { } else if (fPointCount == 1) {
b.Set(fPath[0].point.x, fPath[0].point.y, fPath[0].point.x, fPath[0].point.y); b.Set(fPath[0].point.x, fPath[0].point.y, fPath[0].point.x,
fPath[0].point.y);
} else { } else {
b.Set(0.0, 0.0, -1.0, -1.0); b.Set(0.0, 0.0, -1.0, -1.0);
} }
return b; return b;
} }
// ControlPointBounds
BRect BRect
VectorPath::ControlPointBounds() const VectorPath::ControlPointBounds() const
{ {
@@ -816,7 +813,7 @@ VectorPath::ControlPointBounds() const
return BRect(0.0, 0.0, -1.0, -1.0); return BRect(0.0, 0.0, -1.0, -1.0);
} }
// Iterate
void void
VectorPath::Iterate(Iterator* iterator, float smoothScale) const VectorPath::Iterate(Iterator* iterator, float smoothScale) const
{ {
@@ -843,8 +840,10 @@ iterator->MoveTo(fPath[i].point);
} }
if (fClosed) { if (fClosed) {
iterator->MoveTo(fPath[fPointCount - 1].point); iterator->MoveTo(fPath[fPointCount - 1].point);
curve.init(fPath[fPointCount - 1].point.x, fPath[fPointCount - 1].point.y, curve.init(fPath[fPointCount - 1].point.x,
fPath[fPointCount - 1].point_out.x, fPath[fPointCount - 1].point_out.y, fPath[fPointCount - 1].point.y,
fPath[fPointCount - 1].point_out.x,
fPath[fPointCount - 1].point_out.y,
fPath[0].point_in.x, fPath[0].point_in.y, fPath[0].point_in.x, fPath[0].point_in.y,
fPath[0].point.x, fPath[0].point.y); fPath[0].point.x, fPath[0].point.y);
@@ -859,7 +858,7 @@ iterator->MoveTo(fPath[fPointCount - 1].point);
} }
} }
// CleanUp
void void
VectorPath::CleanUp() VectorPath::CleanUp()
{ {
@@ -880,9 +879,9 @@ VectorPath::CleanUp()
for (int32 i = 0; i < fPointCount; i++) { for (int32 i = 0; i < fPointCount; i++) {
// check for unnecessary, duplicate points // check for unnecessary, duplicate points
if (i > 0) { if (i > 0) {
if (fPath[i - 1].point == fPath[i].point && if (fPath[i - 1].point == fPath[i].point
fPath[i - 1].point == fPath[i - 1].point_out && && fPath[i - 1].point == fPath[i - 1].point_out
fPath[i].point == fPath[i].point_in) { && fPath[i].point == fPath[i].point_in) {
// the previous point can be removed // the previous point can be removed
BPoint in = fPath[i - 1].point_in; BPoint in = fPath[i - 1].point_in;
if (RemovePoint(i - 1)) { if (RemovePoint(i - 1)) {
@@ -894,18 +893,15 @@ VectorPath::CleanUp()
} }
// re-establish connections of in-out control points if // re-establish connections of in-out control points if
// they line up with the main control point // they line up with the main control point
if (fPath[i].point_in == fPath[i].point_out || if (fPath[i].point_in == fPath[i].point_out
fPath[i].point == fPath[i].point_out || || fPath[i].point == fPath[i].point_out
fPath[i].point == fPath[i].point_in || || fPath[i].point == fPath[i].point_in
(fabs(agg::calc_line_point_distance( || (fabs(agg::calc_line_point_distance(fPath[i].point_in.x,
fPath[i].point_in.x, fPath[i].point_in.y, fPath[i].point_in.y, fPath[i].point.x, fPath[i].point.y,
fPath[i].point.x, fPath[i].point.y, fPath[i].point_out.x, fPath[i].point_out.y)) < 0.01
fPath[i].point_out.x, fPath[i].point_out.y)) < 0.01 && && fabs(agg::calc_line_point_distance(fPath[i].point_out.x,
fabs(agg::calc_line_point_distance( fPath[i].point_out.y, fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y,
fPath[i].point.x, fPath[i].point.y,
fPath[i].point_in.x, fPath[i].point_in.y)) < 0.01)) { fPath[i].point_in.x, fPath[i].point_in.y)) < 0.01)) {
fPath[i].connected = true; fPath[i].connected = true;
notify = true; notify = true;
} }
@@ -915,17 +911,15 @@ VectorPath::CleanUp()
_NotifyPathChanged(); _NotifyPathChanged();
} }
// Reverse
void void
VectorPath::Reverse() VectorPath::Reverse()
{ {
VectorPath temp(*this); VectorPath temp(*this);
int32 index = 0; int32 index = 0;
for (int32 i = fPointCount - 1; i >= 0; i--) { for (int32 i = fPointCount - 1; i >= 0; i--) {
temp.SetPoint(index, fPath[i].point, temp.SetPoint(index, fPath[i].point, fPath[i].point_out,
fPath[i].point_out, fPath[i].point_in, fPath[i].connected);
fPath[i].point_in,
fPath[i].connected);
index++; index++;
} }
*this = temp; *this = temp;
@@ -933,7 +927,7 @@ VectorPath::Reverse()
_NotifyPathReversed(); _NotifyPathReversed();
} }
// ApplyTransform
void void
VectorPath::ApplyTransform(const Transformable& transform) VectorPath::ApplyTransform(const Transformable& transform)
{ {
@@ -949,7 +943,7 @@ VectorPath::ApplyTransform(const Transformable& transform)
_NotifyPathChanged(); _NotifyPathChanged();
} }
// PrintToStream
void void
VectorPath::PrintToStream() const VectorPath::PrintToStream() const
{ {
@@ -957,23 +951,23 @@ VectorPath::PrintToStream() const
printf("point %ld: (%f, %f) -> (%f, %f) -> (%f, %f) (%d)\n", i, printf("point %ld: (%f, %f) -> (%f, %f) -> (%f, %f) (%d)\n", i,
fPath[i].point_in.x, fPath[i].point_in.y, fPath[i].point_in.x, fPath[i].point_in.y,
fPath[i].point.x, fPath[i].point.y, fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y, fPath[i].point_out.x, fPath[i].point_out.y, fPath[i].connected);
fPath[i].connected);
} }
} }
// GetAGGPathStorage
bool bool
VectorPath::GetAGGPathStorage(agg::path_storage& path) const VectorPath::GetAGGPathStorage(agg::path_storage& path) const
{ {
return get_path_storage(path, fPath, fPointCount, fClosed); return get_path_storage(path, fPath, fPointCount, fClosed);
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// AddListener
bool bool
VectorPath::AddListener(PathListener* listener) VectorPath::AddListener(PathListener* listener)
{ {
@@ -982,21 +976,21 @@ VectorPath::AddListener(PathListener* listener)
return false; return false;
} }
// RemoveListener
bool bool
VectorPath::RemoveListener(PathListener* listener) VectorPath::RemoveListener(PathListener* listener)
{ {
return fListeners.RemoveItem((void*)listener); return fListeners.RemoveItem((void*)listener);
} }
// CountListeners
int32 int32
VectorPath::CountListeners() const VectorPath::CountListeners() const
{ {
return fListeners.CountItems(); return fListeners.CountItems();
} }
// ListenerAtFast
PathListener* PathListener*
VectorPath::ListenerAtFast(int32 index) const VectorPath::ListenerAtFast(int32 index) const
{ {
@@ -1005,9 +999,10 @@ VectorPath::ListenerAtFast(int32 index) const
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
// #pragma mark - // #pragma mark -
// _SetPoint
void void
VectorPath::_SetPoint(int32 index, BPoint point) VectorPath::_SetPoint(int32 index, BPoint point)
{ {
@@ -1020,13 +1015,10 @@ VectorPath::_SetPoint(int32 index, BPoint point)
fCachedBounds.Set(0.0, 0.0, -1.0, -1.0); fCachedBounds.Set(0.0, 0.0, -1.0, -1.0);
} }
// _SetPoint
void void
VectorPath::_SetPoint(int32 index, VectorPath::_SetPoint(int32 index, const BPoint& point, const BPoint& pointIn,
const BPoint& point, const BPoint& pointOut, bool connected)
const BPoint& pointIn,
const BPoint& pointOut,
bool connected)
{ {
fPath[index].point = point; fPath[index].point = point;
fPath[index].point_in = pointIn; fPath[index].point_in = pointIn;
@@ -1037,22 +1029,27 @@ VectorPath::_SetPoint(int32 index,
fCachedBounds.Set(0.0, 0.0, -1.0, -1.0); fCachedBounds.Set(0.0, 0.0, -1.0, -1.0);
} }
// #pragma mark - // #pragma mark -
// _SetPointCount
bool bool
VectorPath::_SetPointCount(int32 count) VectorPath::_SetPointCount(int32 count)
{ {
// handle reallocation if we run out of room // handle reallocation if we run out of room
if (count >= fAllocCount) { if (count >= fAllocCount) {
fAllocCount = ((count) / ALLOC_CHUNKS + 1) * ALLOC_CHUNKS; fAllocCount = ((count) / ALLOC_CHUNKS + 1) * ALLOC_CHUNKS;
if (fPath) { if (fPath)
fPath = obj_renew(fPath, control_point, fAllocCount); fPath = obj_renew(fPath, control_point, fAllocCount);
} else { else
fPath = obj_new(control_point, fAllocCount); fPath = obj_new(control_point, fAllocCount);
if (fPath != NULL) {
memset(fPath + fPointCount, 0,
(fAllocCount - fPointCount) * sizeof(control_point));
} }
memset(fPath + fPointCount, 0, (fAllocCount - fPointCount) * sizeof(control_point));
} }
// update point count // update point count
if (fPath) { if (fPath) {
fPointCount = count; fPointCount = count;
@@ -1060,7 +1057,8 @@ VectorPath::_SetPointCount(int32 count)
// reallocation might have failed // reallocation might have failed
fPointCount = 0; fPointCount = 0;
fAllocCount = 0; fAllocCount = 0;
fprintf(stderr, "VectorPath::_SetPointCount(%ld) - allocation failed!\n", count); fprintf(stderr, "VectorPath::_SetPointCount(%ld) - allocation failed!\n",
count);
} }
fCachedBounds.Set(0.0, 0.0, -1.0, -1.0); fCachedBounds.Set(0.0, 0.0, -1.0, -1.0);
@@ -1068,11 +1066,12 @@ VectorPath::_SetPointCount(int32 count)
return fPath != NULL; return fPath != NULL;
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// _NotifyPointAdded
void void
VectorPath::_NotifyPointAdded(int32 index) const VectorPath::_NotifyPointAdded(int32 index) const
{ {
@@ -1084,7 +1083,7 @@ VectorPath::_NotifyPointAdded(int32 index) const
} }
} }
// _NotifyPointChanged
void void
VectorPath::_NotifyPointChanged(int32 index) const VectorPath::_NotifyPointChanged(int32 index) const
{ {
@@ -1096,7 +1095,7 @@ VectorPath::_NotifyPointChanged(int32 index) const
} }
} }
// _NotifyPointRemoved
void void
VectorPath::_NotifyPointRemoved(int32 index) const VectorPath::_NotifyPointRemoved(int32 index) const
{ {
@@ -1108,7 +1107,7 @@ VectorPath::_NotifyPointRemoved(int32 index) const
} }
} }
// _NotifyPathChanged
void void
VectorPath::_NotifyPathChanged() const VectorPath::_NotifyPathChanged() const
{ {
@@ -1120,7 +1119,7 @@ VectorPath::_NotifyPathChanged() const
} }
} }
// _NotifyClosedChanged
void void
VectorPath::_NotifyClosedChanged() const VectorPath::_NotifyClosedChanged() const
{ {
@@ -1132,7 +1131,7 @@ VectorPath::_NotifyClosedChanged() const
} }
} }
// _NotifyPathReversed
void void
VectorPath::_NotifyPathReversed() const VectorPath::_NotifyPathReversed() const
{ {
@@ -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:
@@ -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);
} }
@@ -87,14 +89,17 @@ ScreenCornerSelector::Draw(BRect update)
// 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);
@@ -194,7 +199,7 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
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());
@@ -206,8 +211,10 @@ 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());
@@ -257,7 +265,8 @@ ScreenCornerSelector::MouseUp(BPoint where)
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;
+60 -42
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -10,14 +10,16 @@
*/ */
#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
@@ -25,7 +27,7 @@
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);
@@ -38,22 +40,16 @@ class OffscreenClock : public BView {
void SetHourHand(BPoint point); void SetHourHand(BPoint point);
void SetMinuteHand(BPoint point); void SetMinuteHand(BPoint point);
void SetHourDragging(bool val) { void SetHourDragging(bool dragging);
fHourDragging = val; void SetMinuteDragging(bool dragging);
fDirty = true;
}
void SetMinuteDragging(bool val) {
fMinuteDragging = val;
fDirty = true;
}
private: private:
float _GetPhi(BPoint point); float _GetPhi(BPoint point);
bool _InHand(BPoint point, int32 ticks, float radius); bool _InHand(BPoint point, int32 ticks, float radius);
void _DrawHands(float x, float y, float radius, void _DrawHands(float x, float y, float radius,
rgb_color hourHourColor, rgb_color hourHourColor,
rgb_color hourMinuteColor, rgb_color hourMinuteColor,
rgb_color secondsColor, rgb_color secondsColor, rgb_color knobColor);
rgb_color knobColor);
int32 fHours; int32 fHours;
int32 fMinutes; int32 fMinutes;
@@ -70,7 +66,8 @@ class OffscreenClock : public BView {
OffscreenClock::OffscreenClock(BRect frame, const char *name) OffscreenClock::OffscreenClock(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW), :
BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fHours(0), fHours(0),
fMinutes(0), fMinutes(0),
fSeconds(0), fSeconds(0),
@@ -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,11 +180,13 @@ 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);
@@ -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,37 +248,54 @@ 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)
{ {
@@ -292,7 +308,7 @@ OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
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)
{ {
+3 -3
View File
@@ -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);
} }
+9 -8
View File
@@ -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(&center); _Transform(&center);
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(&center); _Transform(&center);
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(&center); _Transform(&center);
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);