* 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.
*/
#ifndef _MATH_H_
@@ -20,9 +20,6 @@
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#define PI M_PI
#define PI2 M_PI_2
/* platform independent IEEE floating point special values */
#define __HUGE_VAL_v 0x7ff0000000000000LL
#define __huge_val_t union { unsigned char __c[8]; long long __ll; double __d; }
@@ -34,7 +31,7 @@
#define __huge_valf_t union { unsigned char __c[4]; long __l; float __f; }
#define HUGE_VALF (((__huge_valf_t) { __l: __HUGE_VALF_v }).__f)
/* ToDo: define HUGE_VALL for long doubles */
/* TODO: define HUGE_VALL for long doubles */
#define __NAN_VALF_v 0x7fc00000L
#define NAN (((__huge_valf_t) { __l: __NAN_VALF_v }).__f)
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -109,14 +109,15 @@ update_coefficients(int32 taps, double filterCutOff, bool horizontal, bool isY,
int32 num = taps * 16;
for (int32 i = 0; i < num * 2; i++) {
double sinc;
double value = (1.0 / filterCutOff) * taps * PI * (i - num) / (2 * num);
double value = (1.0 / filterCutOff) * taps * M_PI * (i - num)
/ (2 * num);
if (value == 0.0)
sinc = 1.0;
else
sinc = sin(value) / value;
// Hamming window
double window = (0.5 - 0.5 * cos(i * PI / num));
double window = (0.5 - 0.5 * cos(i * M_PI / num));
rawCoefficients[i] = sinc * window;
}
+101 -116
View File
@@ -1,33 +1,12 @@
/*
PDF Writer printer driver.
Copyright (c) 2001, 2002 OpenBeOS.
Authors:
Philippe Houdoin
Simon Gauvin
Michael Pfeiffer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#include <stdio.h>
#include <string.h>
@@ -47,28 +26,26 @@ THE SOFTWARE.
#include "Report.h"
#include "pdflib.h"
typedef struct
{
typedef struct {
uint16 from;
uint16 to;
int16 length;
uint16 *unicodes;
} unicode_to_encoding;
typedef struct
{
typedef struct {
uint16 unicode;
uint16 cid;
} unicode_to_cid;
typedef struct
{
typedef struct {
uint16 length;
unicode_to_cid *table;
} cid_table;
#ifdef UNICODE5_FROM
#error check code!
# error check code!
#endif
#define ELEMS(v, e) sizeof(v) / sizeof(e)
@@ -81,8 +58,8 @@ typedef struct
#include "unicode3.h"
#include "unicode4.h"
static unicode_to_encoding encodings[] =
{
static unicode_to_encoding encodings[] = {
{UNICODE0_FROM, UNICODE0_TO, ELEMS(unicode0, uint16), unicode0},
{UNICODE1_FROM, UNICODE1_TO, ELEMS(unicode1, uint16), unicode1},
{UNICODE2_FROM, UNICODE2_TO, ELEMS(unicode2, uint16), unicode2},
@@ -97,16 +74,38 @@ static unicode_to_encoding encodings[] =
#include "korean.h"
static cid_table cid_tables[] =
{
static cid_table cid_tables[] = {
{ELEMS(japanese, unicode_to_cid), japanese},
{ELEMS(CNS1, unicode_to_cid), CNS1},
{ELEMS(GB1, unicode_to_cid), GB1},
{ELEMS(korean, unicode_to_cid), korean}
};
static const char* encoding_names[] = {
"macroman",
// TrueType
"ttenc0",
"ttenc1",
"ttenc2",
"ttenc3",
"ttenc4",
// Type 1
"t1enc0",
"t1enc1",
"t1enc2",
"t1enc3",
"t1enc4",
// CJK
"UniJIS-UCS2-H",
"UniCNS-UCS2-H",
"UniGB-UCS2-H",
"UniKS-UCS2-H"
};
// #pragma mark -
// --------------------------------------------------
static bool
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
{
@@ -134,9 +133,9 @@ find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
}
// --------------------------------------------------
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++) {
encoding = order[i];
@@ -161,9 +160,9 @@ find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index, font_
}
// --------------------------------------------------
void
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index)
{
if (fUserDefinedEncodings.Get(unicode, enc, index)) {
BString s("user");
s << (int)enc;
@@ -171,9 +170,10 @@ PDFWriter::MakeUserDefinedEncoding(uint16 unicode, uint8 &enc, uint8 &index) {
}
}
// --------------------------------------------------
void
PDFWriter::RecordFont(const char* family, const char* style, float size) {
PDFWriter::RecordFont(const char* family, const char* style, float size)
{
const int32 n = fUsedFonts.CountItems();
for (int32 i = 0; i < n; i ++) {
if (fUsedFonts.ItemAt(i)->Equals(family, style, size)) return;
@@ -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);
}
// --------------------------------------------------
void
PDFWriter::GetFontName(BFont *font, char *fontname)
{
@@ -199,9 +199,10 @@ PDFWriter::GetFontName(BFont *font, char *fontname)
RecordFont(family, style, font->Size());
}
// --------------------------------------------------
void
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed, font_encoding encoding)
PDFWriter::GetFontName(BFont *font, char *fontname, bool &embed,
font_encoding encoding)
{
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
PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
{
static Font* cache = NULL;
if (cache && cache->encoding == encoding && strcmp(cache->name.String(), fontName) == 0)
if (cache && cache->encoding == encoding
&& strcmp(cache->name.String(), fontName) == 0)
return cache->font;
REPORT(kDebug, fPage, "FindFont %s", fontName);
@@ -272,20 +250,21 @@ PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
s << (int)(encoding - user_defined_encoding_start);
encoding_name = s.String();
}
REPORT(kDebug, fPage, "Create new font, %sembed, encoding %s", embed ? "" : "do not ", encoding_name);
REPORT(kDebug, fPage, "Create new font, %sembed, encoding %s",
embed ? "" : "do not ", encoding_name);
int font = PDF_findfont(fPdf, fontName, encoding_name, embed);
if (font != -1) {
REPORT(kDebug, fPage, "font created");
cache = new Font(fontName, font, encoding);
fFontCache.AddItem(cache);
} else {
REPORT(kError, fPage, "Could not create font '%s': %s", fontName, PDF_get_errmsg(fPdf));
REPORT(kError, fPage, "Could not create font '%s': %s", fontName,
PDF_get_errmsg(fPdf));
}
return font;
}
// --------------------------------------------------
void
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;
do {
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen, &state);
convert_to_utf8(encoding, &string[srcStart], &srcLen, buffer, &destLen,
&state);
srcStart += srcLen;
len -= srcLen;
srcLen = len;
@@ -307,7 +287,6 @@ PDFWriter::ToUtf8(uint32 encoding, const char *string, BString &utf8)
};
// --------------------------------------------------
void
PDFWriter::ToUnicode(const char *string, BString &unicode)
{
@@ -322,7 +301,8 @@ PDFWriter::ToUnicode(const char *string, BString &unicode)
if (len == 0) return;
do {
convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen, buffer, &destLen, &state);
convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen,
buffer, &destLen, &state);
srcStart += srcLen;
len -= srcLen;
srcLen = len;
@@ -336,7 +316,6 @@ PDFWriter::ToUnicode(const char *string, BString &unicode)
}
// --------------------------------------------------
void
PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
{
@@ -346,14 +325,14 @@ PDFWriter::ToPDFUnicode(const char *string, BString &unicode)
ToUnicode(string, s);
unicode << marker;
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());
buf[len] = buf[len+1] = 0;
unicode.UnlockBuffer(len + 2);
}
// --------------------------------------------------
uint16
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);
fXRefs->Matches(s, &record, true);
}
// --------------------------------------------------
void
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;
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
uint8 enc;
uint16 index = 0;
font_encoding fenc;
uint16 index = 0;
uint8 enc;
GetFontName(&fState->beFont, 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);
if (find_encoding(unicode, enc, index)) {
// is code point in the Adobe Glyph List?
// Note if rendering the glyphs only would be desired, we could always use
// the second method below (MakeUserDefinedEncoding), but extracting text
// from the generated PDF would be almost impossible (OCR!)
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc, (int)index);
// Note if rendering the glyphs only would be desired, we could
// always use the second method below (MakeUserDefinedEncoding),
// but extracting text from the generated PDF would be almost
// impossible (OCR!)
REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc,
(int)index);
// use one of the user pre-defined encodings
if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
encoding = font_encoding(enc + tt_encoding0);
@@ -425,16 +407,20 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode);
if (!found) {
found = true;
REPORT(kError, fPage, "Could not find an encoding for character with unicode %d! Message is not repeated for other unicode values.", (int)unicode);
REPORT(kError, fPage, "Could not find an encoding for character "
"with unicode %d! Message is not repeated for other unicode "
"values.", (int)unicode);
}
*dest = 0; // paint a box (is 0 a box in MacRoman) or
return; // simply skip character
}
} else {
REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen, destLen, (int)dest[0], (int)dest[1]);
REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen,
destLen, (int)dest[0], (int)dest[1]);
}
// Note we have to build the user defined encoding before it is used in PDF_find_font!
// Note we have to build the user defined encoding before it is used in
// PDF_find_font!
if (!MakesPDF()) return;
int font;
@@ -442,15 +428,18 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
GetFontName(&fState->beFont, fontName, embed, encoding);
font = FindFont(fontName, embed, encoding);
if (font < 0) {
REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default font", fontName);
REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default "
"font", fontName);
font = PDF_findfont(fPdf, "Helvetica", "macroman", 0);
}
fState->font = font;
uint16 face = fState->beFont.Face();
PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0 ? "true" : "false");
PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0 ? "true" : "false");
PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0
? "true" : "false");
PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0
? "true" : "false");
PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0);
PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size()));
@@ -476,9 +465,9 @@ PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
}
// --------------------------------------------------
void
PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 size, float width)
PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8,
int16 size, float width)
{
BShape glyph;
bool hasGlyph[1];
@@ -523,12 +512,14 @@ PDFWriter::ClipChar(BFont* font, const char* unicode, const char* utf8, int16 si
PopInternalState();
}
// --------------------------------------------------
void
PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_space)
PDFWriter::DrawString(char *string, float escapementNoSpace,
float escapementSpace)
{
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapement_nospace=%f, escapement_space=%f, at %f, %f", \
string, escapement_nospace, escapement_space, fState->penX, fState->penY);
REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, "
"escapementSpace=%f, at %f, %f", string, escapementNoSpace,
escapementSpace, fState->penX, fState->penY);
if (IsDrawing()) {
// text color is always the high color and not the pattern!
@@ -574,9 +565,9 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
// position of next character
if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space!
w += escapement_space;
w += escapementSpace;
} else {
w += escapement_nospace;
w += escapementNoSpace;
}
fState->penX += w * cos1;
@@ -599,19 +590,13 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s
bounds.top = start.y - height.ascent;
bounds.bottom = end.y + height.descent;
TextSegment* segment = new TextSegment(
utf8.String(), start,
escapement_space, escapement_nospace,
&bounds, &font, pdfSystem());
TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace,
escapementNoSpace, &bounds, &font, pdfSystem());
fTextLine.Add(segment);
if (IsDrawing()) {
}
}
// --------------------------------------------------
bool
PDFWriter::EmbedFont(const char* name)
{
File diff suppressed because it is too large Load Diff
@@ -1,34 +1,12 @@
/*
PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS.
Authors:
Philippe Houdoin
Simon Gauvin
Michael Pfeiffer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
* Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#ifndef PDFWRITER_H
#define PDFWRITER_H
@@ -37,7 +15,7 @@ THE SOFTWARE.
#include <String.h>
#include <List.h>
#include "math.h"
#include <math.h>
#include "PrinterDriver.h"
#include "PictureIterator.h"
@@ -52,8 +30,8 @@ THE SOFTWARE.
#define USE_IMAGE_CACHE 1
#define RAD2DEGREE(r) (180.0 * r / PI)
#define DEGREE2RAD(d) (PI * d / 180.0)
#define RAD2DEGREE(r) (180.0 * r / M_PI)
#define DEGREE2RAD(d) (M_PI * d / 180.0)
class DrawShape;
class WebLink;
@@ -61,9 +39,7 @@ class Bookmark;
class XRefDefs;
class XRefDests;
class PDFWriter : public PrinterDriver, public PictureIterator
{
class PDFWriter : public PrinterDriver, public PictureIterator {
friend class DrawShape;
friend class PDFLinePathBuilder;
friend class WebLink;
@@ -394,8 +370,6 @@ class PDFWriter : public PrinterDriver, public PictureIterator
};
// --------------------------------------------------
inline bool
PDFWriter::IsSame(const pattern &p1, const pattern &p2)
{
@@ -405,7 +379,6 @@ PDFWriter::IsSame(const pattern &p1, const pattern &p2)
}
// --------------------------------------------------
inline bool
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);
void _ErrorHandler(PDF *p, int type, const char *msg);
#endif // #if PDFWRITER_H
#endif // PDFWRITER_H
+20 -22
View File
@@ -1496,8 +1496,8 @@ void FlangerNode::filterBuffer(
// advance read offset ('LFO')
m_fTheta += m_fThetaInc;
if(m_fTheta > 2*M_PI)
m_fTheta -= 2*M_PI;
if(m_fTheta > 2 * M_PI)
m_fTheta -= 2 * M_PI;
// if(m_fDelayReadDelta < 0.0) {
// if(m_fDelayReadOffset < m_fDelay)
@@ -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(
const media_raw_audio_format& format,
float fRate) {
return 2*PI * fRate / format.frame_rate;
/*! Figure the rate at which the (radial) read offset changes,
based on the given sweep rate (in Hz)
*/
float
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
// sweep delay/depth (in msec)
float calc_sweep_base(
const media_raw_audio_format& format,
float fDelay, float fDepth) {
return
(format.frame_rate * (fDelay + fDepth)) / 1000.0;
/*! Figure the base delay (in frames) based on the given
sweep delay/depth (in msec)
*/
float
calc_sweep_base(const media_raw_audio_format& format, float delay, float depth)
{
return (format.frame_rate * (delay + depth)) / 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.
*
* Authors:
@@ -8,17 +8,18 @@
#include "FontDemoView.h"
#include "messages.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <Bitmap.h>
#include <Font.h>
#include <Message.h>
#include <Shape.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "messages.h"
FontDemoView::FontDemoView(BRect rect)
@@ -54,7 +55,8 @@ FontDemoView::~FontDemoView()
void
FontDemoView::FrameResized(float width, float height)
{
// TODO: We shouldnt invalidate the whole view when bounding boxes are working as wanted
// TODO: We shouldnt invalidate the whole view when bounding boxes are
// working as wanted
Invalidate(/*fBoxRegion.Frame()*/);
BView::FrameResized(width, height);
}
@@ -120,7 +122,7 @@ FontDemoView::_DrawView(BView* view)
float yCoord = (rect.Height() + fh.ascent - fh.descent) / 2;
float xCoord = -rect.Width() / 2;
const float xCenter = xCoord * -1;
const float r = Rotation() * (PI/180.0);
const float r = Rotation() * (M_PI / 180.0);
const float cosinus = cos(r);
const float sinus = -sin(r);
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -16,17 +16,18 @@
#include <Point.h>
#include <String.h>
// point_line_distance
double
point_line_distance(double x1, double y1,
double x2, double y2,
double x, double y)
point_line_distance(double x1, double y1, double x2, double y2, double x,
double y)
{
double dx = x2 - x1;
double dy = y2 - y1;
return ((x - x2) * dy - (y - y2) * dx) / sqrt(dx * dx + dy * dy);
}
// point_line_distance
double
point_line_distance(BPoint point, BPoint pa, BPoint pb)
@@ -42,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 beta = acos((a*a + c*c - b*b) / (2*a*c));
if (alpha <= PI2 && beta <= PI2) {
if (alpha <= M_PI_2 && beta <= M_PI_2) {
currentDist = fabs(point_line_distance(pa.x, pa.y, pb.x, pb.y,
point.x, point.y));
}
@@ -51,14 +52,14 @@ point_line_distance(BPoint point, BPoint pa, BPoint pb)
return currentDist;
}
// calc_angle
double
calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
{
double angle = 0.0;
double d = point_line_distance(from.x, from.y,
origin.x, origin.y,
double d = point_line_distance(from.x, from.y, origin.x, origin.y,
to.x, to.y);
if (d != 0.0) {
double a = point_point_distance(from, to);
@@ -71,12 +72,13 @@ calc_angle(BPoint origin, BPoint from, BPoint to, bool degree)
angle = -angle;
if (degree)
angle = angle * 180.0 / PI;
angle = angle * 180.0 / M_PI;
}
}
return angle;
}
// write_string
status_t
write_string(BPositionIO* stream, BString& string)
@@ -91,6 +93,7 @@ write_string(BPositionIO* stream, BString& string)
return written;
}
// append_float
void
append_float(BString& string, float n, int32 maxDigits)
@@ -127,6 +130,7 @@ append_float(BString& string, float n, int32 maxDigits)
}
}
//// gauss
//double
//gauss(double f)
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -10,20 +10,24 @@
#include "CanvasView.h"
// constructor
CanvasTransformBox::CanvasTransformBox(CanvasView* view)
: TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
:
TransformBox(view, BRect(0.0, 0.0, 1.0, 1.0)),
fCanvasView(view),
fParentTransform()
{
}
// destructor
CanvasTransformBox::~CanvasTransformBox()
{
}
// TransformFromCanvas
void
CanvasTransformBox::TransformFromCanvas(BPoint& point) const
@@ -32,6 +36,7 @@ CanvasTransformBox::TransformFromCanvas(BPoint& point) const
fCanvasView->ConvertFromCanvas(&point);
}
// TransformToCanvas
void
CanvasTransformBox::TransformToCanvas(BPoint& point) const
@@ -40,6 +45,7 @@ CanvasTransformBox::TransformToCanvas(BPoint& point) const
fParentTransform.Transform(&point);
}
// ZoomLevel
float
CanvasTransformBox::ZoomLevel() const
@@ -47,11 +53,12 @@ CanvasTransformBox::ZoomLevel() const
return fCanvasView->ZoomLevel();
}
// ViewSpaceRotation
double
CanvasTransformBox::ViewSpaceRotation() const
{
Transformable t(*this);
t.Multiply(fParentTransform);
return t.rotation() * 180.0 / PI;
return t.rotation() * 180.0 / M_PI;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -11,9 +11,11 @@
#include <math.h>
#include <stdio.h>
// constructor
ChannelTransform::ChannelTransform()
: Transformable(),
:
Transformable(),
fPivot(0.0, 0.0),
fTranslation(0.0, 0.0),
fRotation(0.0),
@@ -24,7 +26,8 @@ ChannelTransform::ChannelTransform()
// copy constructor
ChannelTransform::ChannelTransform(const ChannelTransform& other)
: Transformable(other),
:
Transformable(other),
fPivot(other.fPivot),
fTranslation(other.fTranslation),
fRotation(other.fRotation),
@@ -33,11 +36,13 @@ ChannelTransform::ChannelTransform(const ChannelTransform& other)
{
}
// destructor
ChannelTransform::~ChannelTransform()
{
}
// SetTransformation
void
ChannelTransform::SetTransformation(const Transformable& other)
@@ -63,13 +68,11 @@ ChannelTransform::SetTransformation(const Transformable& other)
SetTransformation(B_ORIGIN, BPoint(tx, ty), rotation, scaleX, scaleY);
}
// SetTransformation
void
ChannelTransform::SetTransformation(BPoint pivot,
BPoint translation,
double rotation,
double xScale,
double yScale)
ChannelTransform::SetTransformation(BPoint pivot, BPoint translation,
double rotation, double xScale, double yScale)
{
//printf("SetTransformation(BPoint(%.1f, %.1f), BPoint(%.1f, %.1f), "
//"%.2f, %.2f, %.2f)\n", pivot.x, pivot.y, translation.x, translation.y,
@@ -91,6 +94,7 @@ ChannelTransform::SetTransformation(BPoint pivot,
}
}
// SetPivot
void
ChannelTransform::SetPivot(BPoint pivot)
@@ -103,6 +107,7 @@ ChannelTransform::SetPivot(BPoint pivot)
_UpdateMatrix();
}
// TranslateBy
void
ChannelTransform::TranslateBy(BPoint offset)
@@ -115,10 +120,11 @@ ChannelTransform::TranslateBy(BPoint offset)
_UpdateMatrix();
}
// RotateBy
//
// converts a rotation in world coordinates into
// a combined local rotation and a translation
/*! Converts a rotation in world coordinates into
a combined local rotation and a translation.
*/
void
ChannelTransform::RotateBy(BPoint origin, double degrees)
{
@@ -133,7 +139,7 @@ ChannelTransform::RotateBy(BPoint origin, double degrees)
double xOffset = fTranslation.x - origin.x;
double yOffset = fTranslation.y - origin.y;
agg::trans_affine_rotation m(degrees * PI / 180.0);
agg::trans_affine_rotation m(degrees * M_PI / 180.0);
m.transform(&xOffset, &yOffset);
fTranslation.x = origin.x + xOffset;
@@ -155,6 +161,7 @@ ChannelTransform::RotateBy(double degrees)
_UpdateMatrix();
}
//// ScaleBy
////
//// converts a scalation in world coordinates into
@@ -191,10 +198,11 @@ ChannelTransform::ScaleBy(double xScale, double yScale)
_UpdateMatrix();
}
// SetTranslationAndScale
void
ChannelTransform::SetTranslationAndScale(BPoint offset,
double xScale, double yScale)
ChannelTransform::SetTranslationAndScale(BPoint offset, double xScale,
double yScale)
{
if (fTranslation == offset && fXScale == xScale && fYScale == yScale)
return;
@@ -207,6 +215,7 @@ ChannelTransform::SetTranslationAndScale(BPoint offset,
_UpdateMatrix();
}
// Reset
void
ChannelTransform::Reset()
@@ -214,6 +223,7 @@ ChannelTransform::Reset()
SetTransformation(B_ORIGIN, B_ORIGIN, 0.0, 1.0, 1.0);
}
// =
ChannelTransform&
ChannelTransform::operator=(const ChannelTransform& other)
@@ -228,6 +238,7 @@ ChannelTransform::operator=(const ChannelTransform& other)
return *this;
}
// _UpdateMatrix
void
ChannelTransform::_UpdateMatrix()
@@ -246,7 +257,7 @@ ChannelTransform::_UpdateMatrix()
// coordinate system and is the center for rotation and scale
multiply(agg::trans_affine_translation(-fPivot.x, -fPivot.y));
multiply(agg::trans_affine_scaling(xScale, yScale));
multiply(agg::trans_affine_rotation(fRotation * PI / 180.0));
multiply(agg::trans_affine_rotation(fRotation * M_PI / 180.0));
multiply(agg::trans_affine_translation(fPivot.x + fTranslation.x,
fPivot.y + fTranslation.y));
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -21,16 +21,27 @@
#include "StateView.h"
#include "TransformCommand.h"
#define INSET 8.0
TransformBoxListener::TransformBoxListener() {}
TransformBoxListener::~TransformBoxListener() {}
TransformBoxListener::TransformBoxListener()
{
}
TransformBoxListener::~TransformBoxListener()
{
}
// #pragma mark -
// constructor
TransformBox::TransformBox(StateView* view, BRect box)
: ChannelTransform(),
:
ChannelTransform(),
Manipulator(NULL),
fOriginalBox(box),
@@ -42,7 +53,6 @@ TransformBox::TransformBox(StateView* view, BRect box)
fPivot((fLeftTop.x + fRightBottom.x) / 2.0,
(fLeftTop.y + fRightBottom.y) / 2.0),
fPivotOffset(B_ORIGIN),
fCurrentCommand(NULL),
fCurrentState(NULL),
@@ -70,6 +80,7 @@ TransformBox::TransformBox(StateView* view, BRect box)
{
}
// destructor
TransformBox::~TransformBox()
{
@@ -92,6 +103,7 @@ TransformBox::~TransformBox()
delete fOffsetCenterState;
}
// Draw
void
TransformBox::Draw(BView* into, BRect updateRect)
@@ -131,8 +143,10 @@ TransformBox::Draw(BView* into, BRect updateRect)
into->SetDrawingMode(B_OP_COPY);
}
// #pragma mark -
// MouseDown
bool
TransformBox::MouseDown(BPoint where)
@@ -153,6 +167,7 @@ TransformBox::MouseDown(BPoint where)
return true;
}
// MouseMoved
void
TransformBox::MouseMoved(BPoint where)
@@ -170,6 +185,7 @@ TransformBox::MouseMoved(BPoint where)
}
}
// MouseUp
Command*
TransformBox::MouseUp()
@@ -178,6 +194,7 @@ TransformBox::MouseUp()
return FinishTransaction();
}
// MouseOver
bool
TransformBox::MouseOver(BPoint where)
@@ -193,6 +210,7 @@ TransformBox::MouseOver(BPoint where)
return false;
}
// DoubleClicked
bool
TransformBox::DoubleClicked(BPoint where)
@@ -200,8 +218,10 @@ TransformBox::DoubleClicked(BPoint where)
return false;
}
// #pragma mark -
// Bounds
BRect
TransformBox::Bounds()
@@ -227,6 +247,7 @@ TransformBox::Bounds()
return r;
}
// TrackingBounds
BRect
TransformBox::TrackingBounds(BView* withinView)
@@ -234,8 +255,10 @@ TransformBox::TrackingBounds(BView* withinView)
return withinView->Bounds();
}
// #pragma mark -
// ModifiersChanged
void
TransformBox::ModifiersChanged(uint32 modifiers)
@@ -246,6 +269,7 @@ TransformBox::ModifiersChanged(uint32 modifiers)
}
}
// HandleKeyDown
bool
TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
@@ -288,6 +312,7 @@ TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
return true;
}
// HandleKeyUp
bool
TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
@@ -299,6 +324,7 @@ TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command)
return false;
}
// UpdateCursor
bool
TransformBox::UpdateCursor()
@@ -310,8 +336,10 @@ TransformBox::UpdateCursor()
return false;
}
// #pragma mark -
// AttachedToView
void
TransformBox::AttachedToView(BView* view)
@@ -319,6 +347,7 @@ TransformBox::AttachedToView(BView* view)
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
}
// DetachedFromView
void
TransformBox::DetachedFromView(BView* view)
@@ -326,8 +355,10 @@ TransformBox::DetachedFromView(BView* view)
view->Invalidate(Bounds().InsetByCopy(-INSET, -INSET));
}
// pragma mark -
// Update
void
TransformBox::Update(bool deep)
@@ -352,6 +383,7 @@ TransformBox::Update(bool deep)
Transform(&fPivot);
}
// OffsetCenter
void
TransformBox::OffsetCenter(BPoint offset)
@@ -362,6 +394,7 @@ TransformBox::OffsetCenter(BPoint offset)
}
}
// Center
BPoint
TransformBox::Center() const
@@ -369,6 +402,7 @@ TransformBox::Center() const
return fPivot;
}
// SetBox
void
TransformBox::SetBox(BRect box)
@@ -379,22 +413,21 @@ TransformBox::SetBox(BRect box)
}
}
// FinishTransaction
Command*
TransformBox::FinishTransaction()
{
Command* command = fCurrentCommand;
if (fCurrentCommand) {
fCurrentCommand->SetNewTransformation(Pivot(),
Translation(),
LocalRotation(),
LocalXScale(),
LocalYScale());
fCurrentCommand->SetNewTransformation(Pivot(), Translation(),
LocalRotation(), LocalXScale(), LocalYScale());
fCurrentCommand = NULL;
}
return command;
}
// NudgeBy
void
TransformBox::NudgeBy(BPoint offset)
@@ -408,6 +441,7 @@ TransformBox::NudgeBy(BPoint offset)
}
}
// FinishNudging
Command*
TransformBox::FinishNudging()
@@ -416,18 +450,21 @@ TransformBox::FinishNudging()
return FinishTransaction();
}
// TransformFromCanvas
void
TransformBox::TransformFromCanvas(BPoint& point) const
{
}
// TransformToCanvas
void
TransformBox::TransformToCanvas(BPoint& point) const
{
}
// ZoomLevel
float
TransformBox::ZoomLevel() const
@@ -435,6 +472,7 @@ TransformBox::ZoomLevel() const
return 1.0;
}
// ViewSpaceRotation
double
TransformBox::ViewSpaceRotation() const
@@ -443,8 +481,10 @@ TransformBox::ViewSpaceRotation() const
return LocalRotation();
}
// #pragma mark -
// AddListener
bool
TransformBox::AddListener(TransformBoxListener* listener)
@@ -454,6 +494,7 @@ TransformBox::AddListener(TransformBoxListener* listener)
return false;
}
// RemoveListener
bool
TransformBox::RemoveListener(TransformBoxListener* listener)
@@ -461,30 +502,29 @@ TransformBox::RemoveListener(TransformBoxListener* listener)
return fListeners.RemoveItem((void*)listener);
}
// #pragma mark -
// TODO: why another version?
// point_line_dist
float
point_line_dist(BPoint start, BPoint end, BPoint p, float radius)
{
BRect r(min_c(start.x, end.x),
min_c(start.y, end.y),
max_c(start.x, end.x),
BRect r(min_c(start.x, end.x), min_c(start.y, end.y), max_c(start.x, end.x),
max_c(start.y, end.y));
r.InsetBy(-radius, -radius);
if (r.Contains(p)) {
return fabs(agg::calc_line_point_distance(start.x, start.y,
end.x, end.y,
return fabs(agg::calc_line_point_distance(start.x, start.y, end.x, end.y,
p.x, p.y));
}
return min_c(point_point_distance(start, p),
point_point_distance(end, p));
return min_c(point_point_distance(start, p), point_point_distance(end, p));
}
// _DragStateFor
//
// where is expected in canvas view coordinates
//! where is expected in canvas view coordinates
DragState*
TransformBox::_DragStateFor(BPoint where, float canvasZoom)
{
@@ -586,6 +626,7 @@ TransformBox::_DragStateFor(BPoint where, float canvasZoom)
return state;
}
// _StrokeBWLine
void
TransformBox::_StrokeBWLine(BView* into, BPoint from, BPoint to) const
@@ -617,6 +658,7 @@ TransformBox::_StrokeBWLine(BView* into, BPoint from, BPoint to) const
into->StrokeLine(from, to, B_SOLID_HIGH);
}
// _StrokeBWPoint
void
TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
@@ -638,7 +680,7 @@ TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
double xOffset = -x;
double yOffset = -y;
agg::trans_affine_rotation r(angle * PI / 180.0);
agg::trans_affine_rotation r(angle * M_PI / 180.0);
r.transform(&xOffset, &yOffset);
xOffset = x + xOffset;
@@ -666,8 +708,10 @@ TransformBox::_StrokeBWPoint(BView* into, BPoint point, double angle) const
into->StrokeLine(p[3], p[0], B_SOLID_LOW);
}
// #pragma mark -
// _NotifyDeleted
void
TransformBox::_NotifyDeleted() const
@@ -681,8 +725,10 @@ TransformBox::_NotifyDeleted() const
}
}
// #pragma mark -
// _SetState
void
TransformBox::_SetState(DragState* state)
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -19,15 +19,17 @@
#include "support.h"
#include "TransformBox.h"
//#include "Strings.h"
// constructor
DragState::DragState(TransformBox* parent)
: fOrigin(0.0, 0.0),
:
fOrigin(0.0, 0.0),
fParent(parent)
{
}
// SetOrigin
void
DragState::SetOrigin(BPoint origin)
@@ -35,6 +37,7 @@ DragState::SetOrigin(BPoint origin)
fOrigin = origin;
}
// ActionName
const char*
DragState::ActionName() const
@@ -42,6 +45,7 @@ DragState::ActionName() const
return "Transformation";
}
// ActionNameIndex
uint32
DragState::ActionNameIndex() const
@@ -49,6 +53,7 @@ DragState::ActionNameIndex() const
return TRANSFORMATION;
}
// _SetViewCursor
void
DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
@@ -57,15 +62,19 @@ DragState::_SetViewCursor(BView* view, const uchar* cursorData) const
view->SetViewCursor(&cursor);
}
// #pragma mark - DragCornerState
// constructor
DragCornerState::DragCornerState(TransformBox* parent, uint32 corner)
: DragState(parent),
:
DragState(parent),
fCorner(corner)
{
}
// SetOrigin
void
DragCornerState::SetOrigin(BPoint origin)
@@ -78,7 +87,8 @@ DragCornerState::SetOrigin(BPoint origin)
// copy the matrix at the start of the drag procedure
fMatrix.reset();
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation() * PI / 180.0));
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation()
* M_PI / 180.0));
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
fParent->Translation().y));
@@ -125,6 +135,8 @@ DragCornerState::SetOrigin(BPoint origin)
}
DragState::SetOrigin(origin);
}
// DragTo
void
DragCornerState::DragTo(BPoint current, uint32 modifiers)
@@ -164,11 +176,11 @@ DragCornerState::DragTo(BPoint current, uint32 modifiers)
translation.x = x;
translation.y = y;
fParent->SetTranslationAndScale(translation,
xScale * fOldXScale,
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
yScale * fOldYScale);
}
// UpdateViewCursor
void
DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
@@ -180,91 +192,98 @@ DragCornerState::UpdateViewCursor(BView* view, BPoint current) const
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
else
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
if (flipX) {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
} else {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
else
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
if (flipX) {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
} else {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
}
break;
}
} else if (rotation < 90.0) {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
else
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
} else {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
else
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
} else {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
}
break;
}
} else if (rotation < 135.0) {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
else
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
break;
if (flipX) {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
} else {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftTopRightBottomCursor
: kLeftBottomRightTopCursor);
else
_SetViewCursor(view, flipY ? kLeftBottomRightTopCursor
: kLeftTopRightBottomCursor);
break;
if (flipX) {
_SetViewCursor(view, flipY
? kLeftTopRightBottomCursor : kLeftBottomRightTopCursor);
} else {
_SetViewCursor(view, flipY
? kLeftBottomRightTopCursor : kLeftTopRightBottomCursor);
}
break;
}
} else {
switch (fCorner) {
case LEFT_TOP_CORNER:
case RIGHT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
else
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
} else {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
}
break;
case RIGHT_TOP_CORNER:
case LEFT_BOTTOM_CORNER:
if (flipX)
_SetViewCursor(view, flipY ? kLeftRightCursor
: kUpDownCursor);
else
_SetViewCursor(view, flipY ? kUpDownCursor
: kLeftRightCursor);
if (flipX) {
_SetViewCursor(view,
flipY ? kLeftRightCursor : kUpDownCursor);
} else {
_SetViewCursor(view,
flipY ? kUpDownCursor : kLeftRightCursor);
}
break;
}
}
}
// ActionName
const char*
DragCornerState::ActionName() const
@@ -272,6 +291,7 @@ DragCornerState::ActionName() const
return "Scale";
}
// ActionNameIndex
uint32
DragCornerState::ActionNameIndex() const
@@ -282,12 +302,15 @@ DragCornerState::ActionNameIndex() const
// #pragma mark - DragSideState
DragSideState::DragSideState(TransformBox* parent, uint32 side)
: DragState(parent),
:
DragState(parent),
fSide(side)
{
}
// SetOrigin
void
DragSideState::SetOrigin(BPoint origin)
@@ -300,7 +323,8 @@ DragSideState::SetOrigin(BPoint origin)
// copy the matrix at the start of the drag procedure
fMatrix.reset();
fMatrix.multiply(agg::trans_affine_scaling(fOldXScale, fOldYScale));
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation() * PI / 180.0));
fMatrix.multiply(agg::trans_affine_rotation(fParent->LocalRotation()
* M_PI / 180.0));
fMatrix.multiply(agg::trans_affine_translation(fParent->Translation().x,
fParent->Translation().y));
@@ -336,6 +360,7 @@ DragSideState::SetOrigin(BPoint origin)
DragState::SetOrigin(origin);
}
// DragTo
void
DragSideState::DragTo(BPoint current, uint32 modifiers)
@@ -369,11 +394,11 @@ DragSideState::DragTo(BPoint current, uint32 modifiers)
translation.x = x;
translation.y = y;
fParent->SetTranslationAndScale(translation,
xScale * fOldXScale,
fParent->SetTranslationAndScale(translation, xScale * fOldXScale,
yScale * fOldYScale);
}
// UpdateViewCursor
void
DragSideState::UpdateViewCursor(BView* view, BPoint current) const
@@ -426,6 +451,7 @@ DragSideState::UpdateViewCursor(BView* view, BPoint current) const
}
}
// ActionName
const char*
DragSideState::ActionName() const
@@ -433,6 +459,7 @@ DragSideState::ActionName() const
return "Scale";
}
// ActionNameIndex
uint32
DragSideState::ActionNameIndex() const
@@ -443,6 +470,7 @@ DragSideState::ActionNameIndex() const
// #pragma mark - DragBoxState
// SetOrigin
void
DragBoxState::SetOrigin(BPoint origin)
@@ -451,6 +479,7 @@ DragBoxState::SetOrigin(BPoint origin)
DragState::SetOrigin(origin);
}
// DragTo
void
DragBoxState::DragTo(BPoint current, uint32 modifiers)
@@ -466,6 +495,7 @@ DragBoxState::DragTo(BPoint current, uint32 modifiers)
fParent->TranslateBy(newTranslation - fParent->Translation());
}
// UpdateViewCursor
void
DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
@@ -473,6 +503,7 @@ DragBoxState::UpdateViewCursor(BView* view, BPoint current) const
_SetViewCursor(view, kMoveCursor);
}
// ActionName
const char*
DragBoxState::ActionName() const
@@ -480,6 +511,7 @@ DragBoxState::ActionName() const
return "Move";
}
// ActionNameIndex
uint32
DragBoxState::ActionNameIndex() const
@@ -490,13 +522,16 @@ DragBoxState::ActionNameIndex() const
// #pragma mark - RotateBoxState
// constructor
RotateBoxState::RotateBoxState(TransformBox* parent)
: DragState(parent),
:
DragState(parent),
fOldAngle(0.0)
{
}
// SetOrigin
void
RotateBoxState::SetOrigin(BPoint origin)
@@ -505,6 +540,7 @@ RotateBoxState::SetOrigin(BPoint origin)
fOldAngle = fParent->LocalRotation();
}
// DragTo
void
RotateBoxState::DragTo(BPoint current, uint32 modifiers)
@@ -524,6 +560,7 @@ RotateBoxState::DragTo(BPoint current, uint32 modifiers)
fParent->RotateBy(fParent->Center(), newAngle - fParent->LocalRotation());
}
// UpdateViewCursor
void
RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
@@ -531,8 +568,8 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
BPoint origin(fParent->Center());
fParent->TransformToCanvas(origin);
fParent->TransformToCanvas(current);
BPoint from = origin + BPoint(sinf(22.5 * 180.0 / PI) * 50.0,
-cosf(22.5 * 180.0 / PI) * 50.0);
BPoint from = origin + BPoint(sinf(22.5 * 180.0 / M_PI) * 50.0,
-cosf(22.5 * 180.0 / M_PI) * 50.0);
float rotation = calc_angle(origin, from, current) + 180.0;
@@ -555,6 +592,7 @@ RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
}
}
// ActionName
const char*
RotateBoxState::ActionName() const
@@ -562,6 +600,7 @@ RotateBoxState::ActionName() const
return "Rotate";
}
// ActionNameIndex
uint32
RotateBoxState::ActionNameIndex() const
@@ -570,9 +609,9 @@ RotateBoxState::ActionNameIndex() const
}
// #pragma mark - OffsetCenterState
// SetOrigin
void
OffsetCenterState::SetOrigin(BPoint origin)
@@ -591,6 +630,7 @@ OffsetCenterState::DragTo(BPoint current, uint32 modifiers)
fOrigin = current;
}
// UpdateViewCursor
void
OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
@@ -598,6 +638,7 @@ OffsetCenterState::UpdateViewCursor(BView* view, BPoint current) const
_SetViewCursor(view, kPathMoveCursor);
}
// ActionName
const char*
OffsetCenterState::ActionName() const
@@ -605,11 +646,10 @@ OffsetCenterState::ActionName() const
return "Move Pivot";
}
// ActionNameIndex
uint32
OffsetCenterState::ActionNameIndex() const
{
return MOVE_PIVOT;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -20,11 +20,12 @@
using std::nothrow;
// constructor
TransformGradientBox::TransformGradientBox(CanvasView* view,
Gradient* gradient,
TransformGradientBox::TransformGradientBox(CanvasView* view, Gradient* gradient,
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),
@@ -43,6 +44,7 @@ TransformGradientBox::TransformGradientBox(CanvasView* view,
}
}
// destructor
TransformGradientBox::~TransformGradientBox()
{
@@ -54,6 +56,7 @@ TransformGradientBox::~TransformGradientBox()
fGradient->RemoveObserver(this);
}
// Update
void
TransformGradientBox::Update(bool deep)
@@ -87,6 +90,7 @@ TransformGradientBox::Update(bool deep)
fGradient->AddObserver(this);
}
// ObjectChanged
void
TransformGradientBox::ObjectChanged(const Observable* object)
@@ -112,6 +116,7 @@ TransformGradientBox::ObjectChanged(const Observable* object)
fView->UnlockLooper();
}
// Perform
Command*
TransformGradientBox::Perform()
@@ -119,6 +124,7 @@ TransformGradientBox::Perform()
return NULL;
}
// Cancel
Command*
TransformGradientBox::Cancel()
@@ -128,6 +134,7 @@ TransformGradientBox::Cancel()
return NULL;
}
// TransformFromCanvas
void
TransformGradientBox::TransformFromCanvas(BPoint& point) const
@@ -137,6 +144,7 @@ TransformGradientBox::TransformFromCanvas(BPoint& point) const
fCanvasView->ConvertFromCanvas(&point);
}
// TransformToCanvas
void
TransformGradientBox::TransformToCanvas(BPoint& point) const
@@ -146,6 +154,7 @@ TransformGradientBox::TransformToCanvas(BPoint& point) const
fShape->Transform(&point);
}
// ZoomLevel
float
TransformGradientBox::ZoomLevel() const
@@ -153,6 +162,7 @@ TransformGradientBox::ZoomLevel() const
return fCanvasView->ZoomLevel();
}
// ViewSpaceRotation
double
TransformGradientBox::ViewSpaceRotation() const
@@ -160,9 +170,10 @@ TransformGradientBox::ViewSpaceRotation() const
Transformable t(*this);
if (fShape)
t.Multiply(*fShape);
return t.rotation() * 180.0 / PI;
return t.rotation() * 180.0 / M_PI;
}
// MakeCommand
TransformCommand*
TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex)
@@ -170,15 +181,8 @@ TransformGradientBox::MakeCommand(const char* commandName, uint32 nameIndex)
Transformable* objects[1];
objects[0] = fGradient;
return new TransformObjectsCommand(this, objects, fOriginals, 1,
Pivot(),
Translation(),
LocalRotation(),
LocalXScale(),
LocalYScale(),
commandName,
return new TransformObjectsCommand(this, objects, fOriginals, 1, Pivot(),
Translation(), LocalRotation(), LocalXScale(), LocalYScale(), commandName,
nameIndex);
}
+189 -190
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -19,8 +19,8 @@
#include <agg_math.h>
#ifdef ICON_O_MATIC
#include <debugger.h>
#include <typeinfo>
# include <debugger.h>
# include <typeinfo>
#endif // ICON_O_MATIC
#include <Message.h>
@@ -38,37 +38,32 @@
#include "Transformable.h"
#define obj_new(type, n) ((type *)malloc ((n) * sizeof(type)))
#define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type)))
#define obj_free free
#define ALLOC_CHUNKS 20
// get_path_storage
bool
get_path_storage(agg::path_storage& path,
const control_point* points, int32 count, bool closed)
get_path_storage(agg::path_storage& path, const control_point* points,
int32 count, bool closed)
{
if (count > 1) {
path.move_to(points[0].point.x,
points[0].point.y);
path.move_to(points[0].point.x, points[0].point.y);
for (int32 i = 1; i < count; i++) {
path.curve4(points[i - 1].point_out.x,
points[i - 1].point_out.y,
points[i].point_in.x,
points[i].point_in.y,
points[i].point.x,
points[i].point.y);
path.curve4(points[i - 1].point_out.x, points[i - 1].point_out.y,
points[i].point_in.x, points[i].point_in.y,
points[i].point.x, points[i].point.y);
}
if (closed) {
// curve from last to first control point
path.curve4(points[count - 1].point_out.x,
points[count - 1].point_out.y,
points[0].point_in.x,
points[0].point_in.y,
points[0].point.x,
points[0].point.y);
path.curve4(
points[count - 1].point_out.x, points[count - 1].point_out.y,
points[0].point_in.x, points[0].point_in.y,
points[0].point.x, points[0].point.y);
path.close_polygon();
}
@@ -77,23 +72,31 @@ get_path_storage(agg::path_storage& path,
return false;
}
// #pragma mark -
#ifdef ICON_O_MATIC
PathListener::PathListener() {}
PathListener::~PathListener() {}
PathListener::PathListener()
{
}
PathListener::~PathListener()
{
}
#endif
// #pragma mark -
// constructor
VectorPath::VectorPath()
:
#ifdef ICON_O_MATIC
: BArchivable(),
BArchivable(),
IconObject("<path>"),
fListeners(20),
#else
:
#endif
fPath(NULL),
fClosed(false),
@@ -103,14 +106,13 @@ VectorPath::VectorPath()
{
}
// constructor
VectorPath::VectorPath(const VectorPath& from)
:
#ifdef ICON_O_MATIC
: BArchivable(),
BArchivable(),
IconObject(from),
fListeners(20),
#else
:
#endif
fPath(NULL),
fClosed(false),
@@ -121,14 +123,13 @@ VectorPath::VectorPath(const VectorPath& from)
*this = from;
}
// constructor
VectorPath::VectorPath(BMessage* archive)
:
#ifdef ICON_O_MATIC
: BArchivable(),
BArchivable(),
IconObject(archive),
fListeners(20),
#else
:
#endif
fPath(NULL),
fClosed(false),
@@ -144,7 +145,6 @@ VectorPath::VectorPath(BMessage* archive)
if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK
&& typeFound == B_POINT_TYPE
&& _SetPointCount(countFound)) {
memset(fPath, 0, fAllocCount * sizeof(control_point));
BPoint point;
@@ -167,7 +167,7 @@ VectorPath::VectorPath(BMessage* archive)
}
// destructor
VectorPath::~VectorPath()
{
if (fPath)
@@ -185,11 +185,12 @@ VectorPath::~VectorPath()
#endif
}
// #pragma mark -
#ifdef ICON_O_MATIC
// MakePropertyObject
PropertyObject*
VectorPath::MakePropertyObject() const
{
@@ -204,27 +205,22 @@ VectorPath::MakePropertyObject() const
BMessage* archive = new BMessage();
if (Archive(archive) == B_OK) {
object->AddProperty(new IconProperty(PROPERTY_PATH,
kPathPropertyIconBits,
kPathPropertyIconWidth,
kPathPropertyIconHeight,
kPathPropertyIconFormat,
archive));
kPathPropertyIconBits, kPathPropertyIconWidth,
kPathPropertyIconHeight, kPathPropertyIconFormat, archive));
}
return object;
}
// SetToPropertyObject
bool
VectorPath::SetToPropertyObject(const PropertyObject* object)
{
AutoNotificationSuspender _(this);
IconObject::SetToPropertyObject(object);
// closed
SetClosed(object->Value(PROPERTY_CLOSED, fClosed));
// archived path
IconProperty* pathProperty = dynamic_cast<IconProperty*>(
object->FindProperty(PROPERTY_PATH));
if (pathProperty && pathProperty->Message()) {
@@ -235,12 +231,12 @@ VectorPath::SetToPropertyObject(const PropertyObject* object)
return HasPendingNotifications();
}
// Archive
status_t
VectorPath::Archive(BMessage* into, bool deep) const
{
status_t ret = IconObject::Archive(into, deep);
if (ret < B_OK)
if (ret != B_OK)
return ret;
if (fPointCount > 0) {
@@ -248,48 +244,59 @@ VectorPath::Archive(BMessage* into, bool deep) const
// with the first call
ret = into->AddData("point", B_POINT_TYPE, &fPath[0].point,
sizeof(BPoint), true, fPointCount);
if (ret >= B_OK)
if (ret >= B_OK) {
ret = into->AddData("point in", B_POINT_TYPE, &fPath[0].point_in,
sizeof(BPoint), true, fPointCount);
if (ret >= B_OK)
}
if (ret >= B_OK) {
ret = into->AddData("point out", B_POINT_TYPE, &fPath[0].point_out,
sizeof(BPoint), true, fPointCount);
if (ret >= B_OK)
}
if (ret >= B_OK) {
ret = into->AddData("connected", B_BOOL_TYPE, &fPath[0].connected,
sizeof(bool), true, fPointCount);
}
// add the rest of the points
for (int32 i = 1; i < fPointCount && ret >= B_OK; i++) {
ret = into->AddData("point", B_POINT_TYPE, &fPath[i].point, sizeof(BPoint));
if (ret >= B_OK)
ret = into->AddData("point in", B_POINT_TYPE, &fPath[i].point_in, sizeof(BPoint));
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));
ret = into->AddData("point", B_POINT_TYPE, &fPath[i].point,
sizeof(BPoint));
if (ret >= B_OK) {
ret = into->AddData("point in", B_POINT_TYPE, &fPath[i].point_in,
sizeof(BPoint));
}
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);
} else {
else
fprintf(stderr, "failed adding points!\n");
}
if (ret < B_OK) {
if (ret < B_OK)
fprintf(stderr, "failed adding close!\n");
}
// finish off
if (ret < B_OK) {
if (ret < B_OK)
ret = into->AddString("class", "VectorPath");
}
return ret;
}
#endif // ICON_O_MATIC
// #pragma mark -
// operator=
VectorPath&
VectorPath::operator=(const VectorPath& from)
{
@@ -309,16 +316,17 @@ VectorPath::operator=(const VectorPath& from)
return *this;
}
// MakeEmpty
void
VectorPath::MakeEmpty()
{
_SetPointCount(0);
}
// #pragma mark -
// AddPoint
bool
VectorPath::AddPoint(BPoint point)
{
@@ -333,12 +341,10 @@ VectorPath::AddPoint(BPoint point)
return false;
}
// AddPoint
bool
VectorPath::AddPoint(const BPoint& point,
const BPoint& pointIn,
const BPoint& pointOut,
bool connected)
VectorPath::AddPoint(const BPoint& point, const BPoint& pointIn,
const BPoint& pointOut, bool connected)
{
int32 index = fPointCount;
@@ -351,7 +357,7 @@ VectorPath::AddPoint(const BPoint& point,
return false;
}
// AddPoint
bool
VectorPath::AddPoint(BPoint point, int32 index)
{
@@ -377,12 +383,11 @@ VectorPath::AddPoint(BPoint point, int32 index)
return false;
}
// RemovePoint
bool
VectorPath::RemovePoint(int32 index)
{
if (index >= 0 && index < fPointCount) {
if (index < fPointCount - 1) {
// move points
for (int32 i = index; i < fPointCount - 1; i++) {
@@ -402,7 +407,7 @@ VectorPath::RemovePoint(int32 index)
return false;
}
// SetPoint
bool
VectorPath::SetPoint(int32 index, BPoint point)
{
@@ -422,10 +427,9 @@ VectorPath::SetPoint(int32 index, BPoint point)
return false;
}
// SetPoint
bool
VectorPath::SetPoint(int32 index, BPoint point,
BPoint pointIn, BPoint pointOut,
VectorPath::SetPoint(int32 index, BPoint point, BPoint pointIn, BPoint pointOut,
bool connected)
{
if (index == fPointCount)
@@ -444,7 +448,7 @@ VectorPath::SetPoint(int32 index, BPoint point,
return false;
}
// SetPointIn
bool
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;
float distIn = sqrtf(v.x * v.x + v.y * v.y);
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);
float scale = (distIn + distOut) / distIn;
v.x *= scale;
@@ -476,7 +481,7 @@ VectorPath::SetPointIn(int32 i, BPoint point)
return false;
}
// SetPointOut
bool
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;
float distOut = sqrtf(v.x * v.x + v.y * v.y);
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);
float scale = (distIn + distOut) / distOut;
v.x *= scale;
@@ -512,7 +518,7 @@ VectorPath::SetPointOut(int32 i, BPoint point, bool mirrorDist)
return false;
}
// SetInOutConnected
bool
VectorPath::SetInOutConnected(int32 index, bool connected)
{
@@ -524,9 +530,10 @@ VectorPath::SetInOutConnected(int32 index, bool connected)
return false;
}
// #pragma mark -
// GetPointAt
bool
VectorPath::GetPointAt(int32 index, BPoint& point) const
{
@@ -539,7 +546,7 @@ VectorPath::GetPointAt(int32 index, BPoint& point) const
return false;
}
// GetPointInAt
bool
VectorPath::GetPointInAt(int32 index, BPoint& point) const
{
@@ -552,7 +559,7 @@ VectorPath::GetPointInAt(int32 index, BPoint& point) const
return false;
}
// GetPointOutAt
bool
VectorPath::GetPointOutAt(int32 index, BPoint& point) const
{
@@ -565,10 +572,10 @@ VectorPath::GetPointOutAt(int32 index, BPoint& point) const
return false;
}
// GetPointsAt
bool
VectorPath::GetPointsAt(int32 index, BPoint& point,
BPoint& pointIn, BPoint& pointOut, bool* connected) const
VectorPath::GetPointsAt(int32 index, BPoint& point, BPoint& pointIn,
BPoint& pointOut, bool* connected) const
{
if (index >= 0 && index < fPointCount) {
point = fPath[index].point;
@@ -583,23 +590,24 @@ VectorPath::GetPointsAt(int32 index, BPoint& point,
return false;
}
// CountPoints
int32
VectorPath::CountPoints() const
{
return fPointCount;
}
// #pragma mark -
#ifdef ICON_O_MATIC
// distance_to_curve
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,
bIn.x, bIn.y, b.x, b.y);
agg::curve4_inc curve(a.x, a.y, aOut.x, aOut.y, bIn.x, bIn.y, b.x, b.y);
float segDist = FLT_MAX;
double x1, y1, x2, y2;
@@ -615,25 +623,25 @@ distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BP
if (a > 0.0 && b > 0.0) {
double c = agg::calc_distance(x1, y1, x2, y2);
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 alpha = acos((b * b + c * c - a * a) / (2 * b * c));
double beta = acos((a * a + c * c - b * b) / (2 * a * c));
if (alpha <= PI2 && beta <= PI2) {
currentDist = fabs(agg::calc_line_point_distance(
x1, y1, x2, y2, p.x, p.y));
if (alpha <= M_PI_2 && beta <= M_PI_2) {
currentDist = fabs(agg::calc_line_point_distance(x1, y1, x2, y2,
p.x, p.y));
}
}
if (currentDist < segDist) {
if (currentDist < segDist)
segDist = currentDist;
}
x1 = x2;
y1 = y2;
}
return segDist;
}
// GetDistance
bool
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;
for (int32 i = 0; i < fPointCount - 1; i++) {
float segDist = distance_to_curve(p,
fPath[i].point,
fPath[i].point_out,
fPath[i + 1].point_in,
fPath[i + 1].point);
float segDist = distance_to_curve(p, fPath[i].point,
fPath[i].point_out, fPath[i + 1].point_in, fPath[i + 1].point);
if (segDist < *distance) {
*distance = segDist;
*index = i + 1;
}
}
if (fClosed) {
float segDist = distance_to_curve(p,
fPath[fPointCount - 1].point,
fPath[fPointCount - 1].point_out,
fPath[0].point_in,
float segDist = distance_to_curve(p, fPath[fPointCount - 1].point,
fPath[fPointCount - 1].point_out, fPath[0].point_in,
fPath[0].point);
if (segDist < *distance) {
*distance = segDist;
@@ -669,12 +672,11 @@ VectorPath::GetDistance(BPoint p, float* distance, int32* index) const
return false;
}
// FindBezierScale
bool
VectorPath::FindBezierScale(int32 index, BPoint point, double* scale) const
{
if (index >= 0 && index < fPointCount && scale) {
int maxStep = 1000;
double t = 0.0;
@@ -701,37 +703,32 @@ VectorPath::FindBezierScale(int32 index, BPoint point, double* scale) const
return false;
}
// GetPoint
bool
VectorPath::GetPoint(int32 index, double t, BPoint& point) const
{
if (index >= 0 && index < fPointCount) {
double t1 = (1 - t) * (1 - t) * (1 - t);
double t2 = (1 - t) * (1 - t) * t * 3;
double t3 = (1 - t) * t * t * 3;
double t4 = t * t * t;
if (index < fPointCount - 1) {
point.x = fPath[index].point.x * t1 +
fPath[index].point_out.x * t2 +
fPath[index + 1].point_in.x * t3 +
fPath[index + 1].point.x * t4;
point.x = fPath[index].point.x * t1 + fPath[index].point_out.x * t2
+ fPath[index + 1].point_in.x * t3
+ fPath[index + 1].point.x * t4;
point.y = fPath[index].point.y * t1 +
fPath[index].point_out.y * t2 +
fPath[index + 1].point_in.y * t3 +
fPath[index + 1].point.y * t4;
point.y = fPath[index].point.y * t1 + fPath[index].point_out.y * t2
+ fPath[index + 1].point_in.y * t3
+ fPath[index + 1].point.y * t4;
} else if (fClosed) {
point.x = fPath[fPointCount - 1].point.x * t1 +
fPath[fPointCount - 1].point_out.x * t2 +
fPath[0].point_in.x * t3 +
fPath[0].point.x * t4;
point.x = fPath[fPointCount - 1].point.x * t1
+ fPath[fPointCount - 1].point_out.x * t2
+ fPath[0].point_in.x * t3 + fPath[0].point.x * t4;
point.y = fPath[fPointCount - 1].point.y * t1 +
fPath[fPointCount - 1].point_out.y * t2 +
fPath[0].point_in.y * t3 +
fPath[0].point.y * t4;
point.y = fPath[fPointCount - 1].point.y * t1
+ fPath[fPointCount - 1].point_out.y * t2
+ fPath[0].point_in.y * t3 + fPath[0].point.y * t4;
}
return true;
@@ -741,7 +738,7 @@ VectorPath::GetPoint(int32 index, double t, BPoint& point) const
#endif // ICON_O_MATIC
// SetClosed
void
VectorPath::SetClosed(bool closed)
{
@@ -752,7 +749,7 @@ VectorPath::SetClosed(bool closed)
}
}
// Bounds
BRect
VectorPath::Bounds() const
{
@@ -762,7 +759,7 @@ VectorPath::Bounds() const
return fCachedBounds;
}
// Bounds
BRect
VectorPath::_Bounds() const
{
@@ -770,7 +767,6 @@ VectorPath::_Bounds() const
BRect b;
if (get_path_storage(path, fPath, fPointCount, fClosed)) {
agg::conv_curve<agg::path_storage> curve(path);
uint32 pathID[1];
@@ -781,14 +777,15 @@ VectorPath::_Bounds() const
b.Set(left, top, right, bottom);
} 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 {
b.Set(0.0, 0.0, -1.0, -1.0);
}
return b;
}
// ControlPointBounds
BRect
VectorPath::ControlPointBounds() const
{
@@ -816,7 +813,7 @@ VectorPath::ControlPointBounds() const
return BRect(0.0, 0.0, -1.0, -1.0);
}
// Iterate
void
VectorPath::Iterate(Iterator* iterator, float smoothScale) const
{
@@ -827,7 +824,7 @@ VectorPath::Iterate(Iterator* iterator, float smoothScale) const
curve.approximation_scale(smoothScale);
for (int32 i = 0; i < fPointCount - 1; i++) {
iterator->MoveTo(fPath[i].point);
iterator->MoveTo(fPath[i].point);
curve.init(fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y,
fPath[i + 1].point_in.x, fPath[i + 1].point_in.y,
@@ -842,9 +839,11 @@ iterator->MoveTo(fPath[i].point);
}
}
if (fClosed) {
iterator->MoveTo(fPath[fPointCount - 1].point);
curve.init(fPath[fPointCount - 1].point.x, fPath[fPointCount - 1].point.y,
fPath[fPointCount - 1].point_out.x, fPath[fPointCount - 1].point_out.y,
iterator->MoveTo(fPath[fPointCount - 1].point);
curve.init(fPath[fPointCount - 1].point.x,
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.x, fPath[0].point.y);
@@ -859,7 +858,7 @@ iterator->MoveTo(fPath[fPointCount - 1].point);
}
}
// CleanUp
void
VectorPath::CleanUp()
{
@@ -880,9 +879,9 @@ VectorPath::CleanUp()
for (int32 i = 0; i < fPointCount; i++) {
// check for unnecessary, duplicate points
if (i > 0) {
if (fPath[i - 1].point == fPath[i].point &&
fPath[i - 1].point == fPath[i - 1].point_out &&
fPath[i].point == fPath[i].point_in) {
if (fPath[i - 1].point == fPath[i].point
&& fPath[i - 1].point == fPath[i - 1].point_out
&& fPath[i].point == fPath[i].point_in) {
// the previous point can be removed
BPoint in = fPath[i - 1].point_in;
if (RemovePoint(i - 1)) {
@@ -894,18 +893,15 @@ VectorPath::CleanUp()
}
// re-establish connections of in-out control points if
// they line up with the main control point
if (fPath[i].point_in == fPath[i].point_out ||
fPath[i].point == fPath[i].point_out ||
fPath[i].point == fPath[i].point_in ||
(fabs(agg::calc_line_point_distance(
fPath[i].point_in.x, fPath[i].point_in.y,
fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y)) < 0.01 &&
fabs(agg::calc_line_point_distance(
fPath[i].point_out.x, fPath[i].point_out.y,
fPath[i].point.x, fPath[i].point.y,
if (fPath[i].point_in == fPath[i].point_out
|| fPath[i].point == fPath[i].point_out
|| fPath[i].point == fPath[i].point_in
|| (fabs(agg::calc_line_point_distance(fPath[i].point_in.x,
fPath[i].point_in.y, fPath[i].point.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y)) < 0.01
&& fabs(agg::calc_line_point_distance(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].connected = true;
notify = true;
}
@@ -915,17 +911,15 @@ VectorPath::CleanUp()
_NotifyPathChanged();
}
// Reverse
void
VectorPath::Reverse()
{
VectorPath temp(*this);
int32 index = 0;
for (int32 i = fPointCount - 1; i >= 0; i--) {
temp.SetPoint(index, fPath[i].point,
fPath[i].point_out,
fPath[i].point_in,
fPath[i].connected);
temp.SetPoint(index, fPath[i].point, fPath[i].point_out,
fPath[i].point_in, fPath[i].connected);
index++;
}
*this = temp;
@@ -933,7 +927,7 @@ VectorPath::Reverse()
_NotifyPathReversed();
}
// ApplyTransform
void
VectorPath::ApplyTransform(const Transformable& transform)
{
@@ -949,7 +943,7 @@ VectorPath::ApplyTransform(const Transformable& transform)
_NotifyPathChanged();
}
// PrintToStream
void
VectorPath::PrintToStream() const
{
@@ -957,23 +951,23 @@ VectorPath::PrintToStream() const
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.x, fPath[i].point.y,
fPath[i].point_out.x, fPath[i].point_out.y,
fPath[i].connected);
fPath[i].point_out.x, fPath[i].point_out.y, fPath[i].connected);
}
}
// GetAGGPathStorage
bool
VectorPath::GetAGGPathStorage(agg::path_storage& path) const
{
return get_path_storage(path, fPath, fPointCount, fClosed);
}
// #pragma mark -
#ifdef ICON_O_MATIC
// AddListener
bool
VectorPath::AddListener(PathListener* listener)
{
@@ -982,21 +976,21 @@ VectorPath::AddListener(PathListener* listener)
return false;
}
// RemoveListener
bool
VectorPath::RemoveListener(PathListener* listener)
{
return fListeners.RemoveItem((void*)listener);
}
// CountListeners
int32
VectorPath::CountListeners() const
{
return fListeners.CountItems();
}
// ListenerAtFast
PathListener*
VectorPath::ListenerAtFast(int32 index) const
{
@@ -1005,9 +999,10 @@ VectorPath::ListenerAtFast(int32 index) const
#endif // ICON_O_MATIC
// #pragma mark -
// _SetPoint
void
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);
}
// _SetPoint
void
VectorPath::_SetPoint(int32 index,
const BPoint& point,
const BPoint& pointIn,
const BPoint& pointOut,
bool connected)
VectorPath::_SetPoint(int32 index, const BPoint& point, const BPoint& pointIn,
const BPoint& pointOut, bool connected)
{
fPath[index].point = point;
fPath[index].point_in = pointIn;
@@ -1037,22 +1029,27 @@ VectorPath::_SetPoint(int32 index,
fCachedBounds.Set(0.0, 0.0, -1.0, -1.0);
}
// #pragma mark -
// _SetPointCount
bool
VectorPath::_SetPointCount(int32 count)
{
// handle reallocation if we run out of room
if (count >= fAllocCount) {
fAllocCount = ((count) / ALLOC_CHUNKS + 1) * ALLOC_CHUNKS;
if (fPath) {
if (fPath)
fPath = obj_renew(fPath, control_point, fAllocCount);
} else {
else
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
if (fPath) {
fPointCount = count;
@@ -1060,7 +1057,8 @@ VectorPath::_SetPointCount(int32 count)
// reallocation might have failed
fPointCount = 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);
@@ -1068,11 +1066,12 @@ VectorPath::_SetPointCount(int32 count)
return fPath != NULL;
}
// #pragma mark -
#ifdef ICON_O_MATIC
// _NotifyPointAdded
void
VectorPath::_NotifyPointAdded(int32 index) const
{
@@ -1084,7 +1083,7 @@ VectorPath::_NotifyPointAdded(int32 index) const
}
}
// _NotifyPointChanged
void
VectorPath::_NotifyPointChanged(int32 index) const
{
@@ -1096,7 +1095,7 @@ VectorPath::_NotifyPointChanged(int32 index) const
}
}
// _NotifyPointRemoved
void
VectorPath::_NotifyPointRemoved(int32 index) const
{
@@ -1108,7 +1107,7 @@ VectorPath::_NotifyPointRemoved(int32 index) const
}
}
// _NotifyPathChanged
void
VectorPath::_NotifyPathChanged() const
{
@@ -1120,7 +1119,7 @@ VectorPath::_NotifyPathChanged() const
}
}
// _NotifyClosedChanged
void
VectorPath::_NotifyClosedChanged() const
{
@@ -1132,7 +1131,7 @@ VectorPath::_NotifyClosedChanged() const
}
}
// _NotifyPathReversed
void
VectorPath::_NotifyPathReversed() const
{
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -282,7 +282,7 @@ Transformable::RotateBy(BPoint origin, double degrees)
{
if (degrees != 0.0) {
multiply(agg::trans_affine_translation(-origin.x, -origin.y));
multiply(agg::trans_affine_rotation(degrees * (PI / 180.0)));
multiply(agg::trans_affine_rotation(degrees * (M_PI / 180.0)));
multiply(agg::trans_affine_translation(origin.x, origin.y));
TransformationChanged();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2006, Haiku.
* Copyright 2003-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -28,7 +28,8 @@ static const float kStopSize = 15.0f;
ScreenCornerSelector::ScreenCornerSelector(BRect frame, const char *name,
BMessage* message, uint32 resizingMode)
: BControl(frame, name, NULL, message, resizingMode, B_WILL_DRAW | B_NAVIGABLE),
: BControl(frame, name, NULL, message, resizingMode,
B_WILL_DRAW | B_NAVIGABLE),
fCurrentCorner(NO_CORNER),
fPreviousCorner(-1)
{
@@ -47,7 +48,8 @@ ScreenCornerSelector::_MonitorFrame() const
else if (height * kAspectRatio > width)
height = width / kAspectRatio;
return BRect((Bounds().Width() - width) / 2, (Bounds().Height() - height) / 2,
return BRect((Bounds().Width() - width) / 2,
(Bounds().Height() - height) / 2,
(Bounds().Width() + width) / 2, (Bounds().Height() + height) / 2);
}
@@ -87,14 +89,17 @@ ScreenCornerSelector::Draw(BRect update)
// the part that's affected by the change
if (!IsFocusChanging()) {
SetHighColor(darkColor);
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
FillRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
kMonitorBorderSize * 3 / 2);
}
if (IsFocus() && Window()->IsActive())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(blackColor);
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2, kMonitorBorderSize * 3 / 2);
StrokeRoundRect(outerRect, kMonitorBorderSize * 3 / 2,
kMonitorBorderSize * 3 / 2);
if (!IsFocusChanging()) {
SetHighColor(210, 210, 255);
@@ -194,7 +199,7 @@ ScreenCornerSelector::_DrawStop(BRect innerFrame)
SetPenSize(2);
StrokeEllipse(rect);
size -= ceilf(sin(PI / 4) * size + 2);
size -= ceilf(sin(M_PI / 4) * size + 2);
rect.InsetBy(size, size);
StrokeLine(rect.RightTop(), rect.LeftBottom());
@@ -206,8 +211,10 @@ void
ScreenCornerSelector::_DrawArrow(BRect innerFrame)
{
float size = kArrowSize;
float sizeX = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
float sizeY = fCurrentCorner == UP_LEFT_CORNER || fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
float sizeX = fCurrentCorner == UP_LEFT_CORNER
|| fCurrentCorner == DOWN_LEFT_CORNER ? size : -size;
float sizeY = fCurrentCorner == UP_LEFT_CORNER
|| fCurrentCorner == UP_RIGHT_CORNER ? size : -size;
innerFrame.InsetBy(2, 2);
BPoint origin(sizeX < 0 ? innerFrame.right : innerFrame.left,
@@ -220,7 +227,8 @@ ScreenCornerSelector::_DrawArrow(BRect innerFrame)
screen_corner
ScreenCornerSelector::_ScreenCorner(BPoint point, screen_corner previousCorner) const
ScreenCornerSelector::_ScreenCorner(BPoint point,
screen_corner previousCorner) const
{
BRect innerFrame = _InnerFrame(_MonitorFrame());
@@ -257,7 +265,8 @@ ScreenCornerSelector::MouseUp(BPoint where)
void
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
ScreenCornerSelector::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
if (fPreviousCorner == -1)
return;
+62 -44
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
* Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -10,22 +10,24 @@
*/
#include "AnalogClock.h"
#include "TimeMessages.h"
#include <math.h>
#include <stdio.h>
#include <Bitmap.h>
#include <Message.h>
#include <Window.h>
#include <cmath>
#include <stdio.h>
#include "TimeMessages.h"
#define DRAG_DELTA_PHI 0.2
class OffscreenClock : public BView {
public:
public:
OffscreenClock(BRect frame, const char *name);
~OffscreenClock();
virtual ~OffscreenClock();
void SetTime(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 SetMinuteHand(BPoint point);
void SetHourDragging(bool val) {
fHourDragging = val;
fDirty = true;
}
void SetMinuteDragging(bool val) {
fMinuteDragging = val;
fDirty = true;
}
private:
void SetHourDragging(bool dragging);
void SetMinuteDragging(bool dragging);
private:
float _GetPhi(BPoint point);
bool _InHand(BPoint point, int32 ticks, float radius);
void _DrawHands(float x, float y, float radius,
rgb_color hourHourColor,
rgb_color hourMinuteColor,
rgb_color secondsColor,
rgb_color knobColor);
rgb_color secondsColor, rgb_color knobColor);
int32 fHours;
int32 fMinutes;
@@ -70,7 +66,8 @@ class OffscreenClock : public BView {
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),
fMinutes(0),
fSeconds(0),
@@ -157,10 +154,10 @@ OffscreenClock::DrawClock()
for (int32 minute = 1; minute < 60; minute++) {
if (minute % 5 == 0)
continue;
float x1 = fCenterX + sinf(minute * PI / 30.0) * fRadius;
float y1 = fCenterY + cosf(minute * PI / 30.0) * fRadius;
float x2 = fCenterX + sinf(minute * PI / 30.0) * (fRadius * 0.95);
float y2 = fCenterY + cosf(minute * PI / 30.0) * (fRadius * 0.95);
float x1 = fCenterX + sinf(minute * M_PI / 30.0) * fRadius;
float y1 = fCenterY + cosf(minute * M_PI / 30.0) * fRadius;
float x2 = fCenterX + sinf(minute * M_PI / 30.0) * (fRadius * 0.95);
float y2 = fCenterY + cosf(minute * M_PI / 30.0) * (fRadius * 0.95);
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
}
@@ -170,10 +167,10 @@ OffscreenClock::DrawClock()
SetPenSize(2.0);
SetLineMode(B_ROUND_CAP, B_MITER_JOIN);
for (int32 hour = 0; hour < 12; hour++) {
float x1 = fCenterX + sinf(hour * PI / 6.0) * fRadius;
float y1 = fCenterY + cosf(hour * PI / 6.0) * fRadius;
float x2 = fCenterX + sinf(hour * PI / 6.0) * (fRadius * 0.9);
float y2 = fCenterY + cosf(hour * PI / 6.0) * (fRadius * 0.9);
float x1 = fCenterX + sinf(hour * M_PI / 6.0) * fRadius;
float y1 = fCenterY + cosf(hour * M_PI / 6.0) * fRadius;
float x2 = fCenterX + sinf(hour * M_PI / 6.0) * (fRadius * 0.9);
float y2 = fCenterY + cosf(hour * M_PI / 6.0) * (fRadius * 0.9);
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
}
@@ -183,11 +180,13 @@ OffscreenClock::DrawClock()
hourColor = (rgb_color){ 0, 0, 255, 255 };
else
hourColor = tint_color(HighColor(), B_DARKEN_2_TINT);
rgb_color minuteColor;
if (fMinuteDragging)
minuteColor = (rgb_color){ 0, 0, 255, 255 };
else
minuteColor = tint_color(HighColor(), B_DARKEN_2_TINT);
rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 };
rgb_color shadowColor = tint_color(LowColor(),
(B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2);
@@ -231,7 +230,7 @@ OffscreenClock::SetHourHand(BPoint point)
point.y -= fCenterY;
float pointPhi = _GetPhi(point);
float hoursExact = 6.0 * pointPhi / PI;
float hoursExact = 6.0 * pointPhi / M_PI;
if (fHours >= 12)
fHours = 12;
else
@@ -249,37 +248,54 @@ OffscreenClock::SetMinuteHand(BPoint point)
point.y -= fCenterY;
float pointPhi = _GetPhi(point);
float minutesExact = 30.0 * pointPhi / PI;
float minutesExact = 30.0 * pointPhi / M_PI;
fMinutes = int32(ceilf(minutesExact));
SetTime(fHours, fMinutes, fSeconds);
}
void
OffscreenClock::SetHourDragging(bool dragging)
{
fHourDragging = dragging;
fDirty = true;
}
void
OffscreenClock::SetMinuteDragging(bool dragging)
{
fMinuteDragging = dragging;
fDirty = true;
}
float
OffscreenClock::_GetPhi(BPoint point)
{
if (point.x == 0 && point.y < 0)
return 2 * PI;
return 2 * M_PI;
if (point.x == 0 && point.y > 0)
return PI;
return M_PI;
if (point.y == 0 && point.x < 0)
return PI * 3 / 2;
return M_PI * 3 / 2;
if (point.y == 0 && point.x > 0)
return PI / 2;
return M_PI / 2;
float pointPhi = atanf(-1. * point.y / point.x);
if (point.y < 0. && point.x > 0.) // right upper corner
pointPhi = PI / 2. - pointPhi;
pointPhi = M_PI / 2. - pointPhi;
if (point.y > 0. && point.x > 0.) // right lower corner
pointPhi = PI / 2 - pointPhi;
pointPhi = M_PI / 2 - pointPhi;
if (point.y > 0. && point.x < 0.) // left lower corner
pointPhi = (PI * 3. / 2. - pointPhi);
pointPhi = (M_PI * 3. / 2. - pointPhi);
if (point.y < 0. && point.x < 0.) // left upper corner
pointPhi = 3. / 2. * PI - pointPhi;
pointPhi = 3. / 2. * M_PI - pointPhi;
return pointPhi;
}
bool
OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
{
@@ -292,7 +308,7 @@ OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)
return false;
float pointPhi = _GetPhi(point);
float handPhi = PI / 30.0 * ticks;
float handPhi = M_PI / 30.0 * ticks;
float delta = pointPhi - handPhi;
if (fabs(delta) > DRAG_DELTA_PHI)
return false;
@@ -315,23 +331,23 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
SetHighColor(hourColor);
SetPenSize(4.0);
float hours = fHours + float(fMinutes) / 60.0;
offsetX = (radius * 0.7) * sinf((hours * PI) / 6.0);
offsetY = (radius * 0.7) * cosf((hours * PI) / 6.0);
offsetX = (radius * 0.7) * sinf((hours * M_PI) / 6.0);
offsetY = (radius * 0.7) * cosf((hours * M_PI) / 6.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// calc, draw minute hand
SetHighColor(minuteColor);
SetPenSize(3.0);
float minutes = fMinutes + float(fSeconds) / 60.0;
offsetX = (radius * 0.9) * sinf((minutes * PI) / 30.0);
offsetY = (radius * 0.9) * cosf((minutes * PI) / 30.0);
offsetX = (radius * 0.9) * sinf((minutes * M_PI) / 30.0);
offsetY = (radius * 0.9) * cosf((minutes * M_PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// calc, draw second hand
SetHighColor(secondsColor);
SetPenSize(1.0);
offsetX = (radius * 0.95) * sinf((fSeconds * PI) / 30.0);
offsetY = (radius * 0.95) * cosf((fSeconds * PI) / 30.0);
offsetX = (radius * 0.95) * sinf((fSeconds * M_PI) / 30.0);
offsetY = (radius * 0.95) * cosf((fSeconds * M_PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// draw the center knob
@@ -344,7 +360,8 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
TAnalogClock::TAnalogClock(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
:
BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
fBitmap(NULL),
fClock(NULL),
fDraggingHourHand(false),
@@ -429,6 +446,7 @@ TAnalogClock::MouseDown(BPoint point)
}
}
void
TAnalogClock::MouseUp(BPoint point)
{
+3 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Haiku.
* Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -881,8 +881,8 @@ ServerFont::EmbeddedTransformation() const
// TODO: cache this?
Transformable transform;
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * PI / 180.0, 0.0);
transform.RotateBy(B_ORIGIN, -fRotation * PI / 180.0);
transform.ShearBy(B_ORIGIN, (90.0 - fShear) * M_PI / 180.0, 0.0);
transform.RotateBy(B_ORIGIN, -fRotation * M_PI / 180.0);
return transform;
}
@@ -76,9 +76,9 @@ AGGTextRenderer::SetFont(const ServerFont& font)
// construct an embedded transformation (rotate & shear)
fEmbeddedTransformation.Reset();
fEmbeddedTransformation.ShearBy(B_ORIGIN,
(90.0 - font.Shear()) * PI / 180.0, 0.0);
(90.0 - font.Shear()) * M_PI / 180.0, 0.0);
fEmbeddedTransformation.RotateBy(B_ORIGIN,
-font.Rotation() * PI / 180.0);
-font.Rotation() * M_PI / 180.0);
fContour.width(font.FalseBoldWidth() * 2.0);
}
+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_NO_RETURN if (!fValidClipping) return;
// constructor
Painter::Painter()
:
@@ -1222,7 +1223,7 @@ Painter::DrawEllipse(BRect r, bool fill) const
float yRadius = r.Height() / 2.0;
BPoint center(r.left + xRadius, r.top + yRadius);
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * PI / 2);
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * M_PI / 2);
if (divisions < 12)
divisions = 12;
if (divisions > 4096)
@@ -1295,7 +1296,7 @@ Painter::FillEllipse(BRect r, const BGradient& gradient) const
float yRadius = r.Height() / 2.0;
BPoint center(r.left + xRadius, r.top + yRadius);
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * PI / 2);
int32 divisions = (int32)((xRadius + yRadius + 2 * fPenSize) * M_PI / 2);
if (divisions < 12)
divisions = 12;
if (divisions > 4096)
@@ -1316,8 +1317,8 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);
@@ -1337,8 +1338,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);
@@ -1374,8 +1375,8 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius, float angle,
_Transform(&center);
double angleRad = (angle * PI) / 180.0;
double spanRad = (span * PI) / 180.0;
double angleRad = (angle * M_PI) / 180.0;
double spanRad = (span * M_PI) / 180.0;
agg::bezier_arc arc(center.x, center.y, xRadius, yRadius, -angleRad,
-spanRad);