From 837b9b863299bd05b5348b47f9c028091c70de61 Mon Sep 17 00:00:00 2001
From: scuri
Date: Tue, 1 Dec 2009 20:33:02 +0000
Subject: New: function CanvasYAxisMode to control the Y axis orientation.
---
html/en/func/coordinates.html | 20 ++-
html/en/history.html | 2 +
html/wb/wb_usr.lua | 4 +
html/wb_tree.html | 309 +++++++++++++++++++++---------------------
include/cd.h | 1 +
src/cd.c | 16 ++-
src/cd.def | 1 +
src/lua5/cdlua5_canvas.c | 7 +
8 files changed, 200 insertions(+), 160 deletions(-)
diff --git a/html/en/func/coordinates.html b/html/en/func/coordinates.html
index 9f119bb..a56b12d 100644
--- a/html/en/func/coordinates.html
+++ b/html/en/func/coordinates.html
@@ -18,6 +18,18 @@ canvas:GetSize() -> (width, height, mm_width, mm_height: number) [in Lua]Returns the canvas size in pixels and in millimeters. You can provide only
the desired values and NULL for the others.
+int cdCanvasYAxisMode(cdCanvas* canvas, int invert); [in C]
+
+canvas:YAxisMode(invert: number) -> (old_invert: number) [in Lua]
+
+ Controls the orientation of the Y axis. Internally in some drivers the
+ native axis orientation is top-bottom, so the CD primitives must invert the
+ Y axis since the CD orientation is bottom-top. Using CD_QUERY will return
+ the current Y axis mode, if needs to be invert or not. Using 1 or 0 you can
+ control if the Y axis should be inverted or not independent from the native
+ orientation, with that you can in fact invert the orientation of the CD
+ primitives.
+
int cdCanvasUpdateYAxis(cdCanvas* canvas, int *y); [in C]
double cdfCanvasUpdateYAxis(cdCanvas* canvas, double *y); [in C]
int cdCanvasInvertYAxis(cdCanvas* canvas, int y); [in C]
@@ -26,11 +38,9 @@ double cdfCanvasInvertYAxis(cdCanvas* canvas, double y); [in C]
canvas:UpdateYAxis(yc: number) -> (yr: number) [in Lua]
canvas:InvertYAxis(yc: number) -> (yr: number) [in Lua]
- In some graph systems, the origin is at the upper left corner of the
- canvas, with the direction of the Y axis pointing down. In this case, the
- function converts the coordinate system of the CD library into the internal
- system of the active canvas' driver, and the other way round. If this is not
- the case, nothing happens. This is just "y = height-1 -
+ Converts the coordinate system of the CD library into the internal
+ system of the active canvas' driver, and the other way round, if they are
+ invert, or else do nothing. This is just "y = height-1 -
y". It returns the changed value. The "Invert" will always invert
the given value, the "Update" function will invert only if the canvas has the
Y axis inverted.
diff --git a/html/en/history.html b/html/en/history.html
index ebecfbc..8a83f67 100644
--- a/html/en/history.html
+++ b/html/en/history.html
@@ -21,6 +21,8 @@
History of Changes
CVS (01/Dec/2009)
+ - New: function
+ CanvasYAxisMode to control the Y axis orientation.
- Changed:
Freetype updated to version 2.3.11.
- Changed:
diff --git a/html/wb/wb_usr.lua b/html/wb/wb_usr.lua
index 4f09919..eee41ec 100644
--- a/html/wb/wb_usr.lua
+++ b/html/wb/wb_usr.lua
@@ -243,6 +243,10 @@ wb_usr.tree =
name= {nl= "GetSize"},
link= "func/coordinates.html#cdGetCanvasSize"
},
+ {
+ name= {nl= "YAxisMode"},
+ link= "func/coordinates.html#cdYAxisMode"
+ },
{
name= {nl= "UpdateYAxis"},
link= "func/coordinates.html#cdUpdateYAxis"
diff --git a/html/wb_tree.html b/html/wb_tree.html
index 19d0fe6..b83fa8d 100644
--- a/html/wb_tree.html
+++ b/html/wb_tree.html
@@ -287,255 +287,256 @@
Coordinate System
- World Coordinates
+ World Coordinates
General Attributes
- Clipping
+ Clipping
Primitives
Other
- Drivers
+ Drivers
diff --git a/include/cd.h b/include/cd.h
index 5b13f1e..d87975a 100644
--- a/include/cd.h
+++ b/include/cd.h
@@ -76,6 +76,7 @@ int cdCanvasPlay(cdCanvas* canvas, cdContext *context, int xmin, int xmax, int
void cdCanvasGetSize(cdCanvas* canvas, int *width, int *height, double *width_mm, double *height_mm);
int cdCanvasUpdateYAxis(cdCanvas* canvas, int* y);
double cdfCanvasUpdateYAxis(cdCanvas* canvas, double* y);
+int cdCanvasYAxisMode(cdCanvas* canvas, int invert);
int cdCanvasInvertYAxis(cdCanvas* canvas, int y);
double cdfCanvasInvertYAxis(cdCanvas* canvas, double y);
void cdCanvasMM2Pixel(cdCanvas* canvas, double mm_dx, double mm_dy, int *dx, int *dy);
diff --git a/src/cd.c b/src/cd.c
index b88cc1b..6435d0a 100644
--- a/src/cd.c
+++ b/src/cd.c
@@ -586,6 +586,20 @@ void cdCanvasClear(cdCanvas* canvas)
canvas->cxClear(canvas->ctxcanvas);
}
+int cdCanvasYAxisMode(cdCanvas* canvas, int invert)
+{
+ int old_invert_yaxis;
+ assert(canvas);
+ if (!_cdCheckCanvas(canvas)) return CD_ERROR;
+
+ if (invert == CD_QUERY)
+ return canvas->invert_yaxis;
+
+ old_invert_yaxis = canvas->invert_yaxis;
+ canvas->invert_yaxis = invert;
+ return old_invert_yaxis;
+}
+
int cdCanvasUpdateYAxis(cdCanvas* canvas, int* y)
{
assert(canvas);
@@ -609,7 +623,7 @@ double cdfCanvasUpdateYAxis(cdCanvas* canvas, double* y)
assert(y);
if (!_cdCheckCanvas(canvas)) return CD_ERROR;
- if(canvas->invert_yaxis)
+ if (canvas->invert_yaxis)
{
*y = _cdInvertYAxis(canvas, *y);
diff --git a/src/cd.def b/src/cd.def
index dd2f7ed..0aa2c35 100644
--- a/src/cd.def
+++ b/src/cd.def
@@ -297,6 +297,7 @@ EXPORTS
cdCanvasInvertYAxis
cdfCanvasUpdateYAxis
cdfCanvasInvertYAxis
+ cdCanvasYAxisMode
cdContextRegisterCallback
cdCanvasBackground
cdCanvasForeground
diff --git a/src/lua5/cdlua5_canvas.c b/src/lua5/cdlua5_canvas.c
index eeecc6d..7fb5402 100644
--- a/src/lua5/cdlua5_canvas.c
+++ b/src/lua5/cdlua5_canvas.c
@@ -273,6 +273,12 @@ static int cdlua5_updateyaxis(lua_State *L)
return 1;
}
+static int cdlua5_yaxismode(lua_State *L)
+{
+ lua_pushnumber(L, cdCanvasYAxisMode(cdlua_checkcanvas(L, 1), luaL_checkint(L, 2)));
+ return 1;
+}
+
static int cdlua5_invertyaxis(lua_State *L)
{
lua_pushnumber(L, cdfCanvasInvertYAxis(cdlua_checkcanvas(L, 1), luaL_checknumber(L, 2)));
@@ -2192,6 +2198,7 @@ static const struct luaL_reg cdlib_canvas_meta[] = {
/* Coordinate System */
{"GetSize" , cdlua5_getcanvassize},
{"UpdateYAxis" , cdlua5_updateyaxis},
+ {"YAxisMode" , cdlua5_yaxismode},
{"InvertYAxis" , cdlua5_invertyaxis},
{"MM2Pixel" , cdlua5_mm2pixel},
{"Pixel2MM" , cdlua5_pixel2mm},
--
cgit v1.2.3