Commit 4dee91bd authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

New static helper function. (double_line_draw): New function. Draw a

2000-06-11  Jon K Hellan  <hellan@acm.org>

	* gnumeric-dashed-canvas-line.c (hypothenuse): New static helper
	function.
	(double_line_draw): New function. Draw a double line. Even explain
	in nice ASCII art how we do it.
	(gnumeric_dashed_canvas_line_draw): Special case double lines by
	punting to double line draw.

2000-06-11  Jon K Hellan  <hellan@acm.org>

	* dialog-cell-format.c (line_info[]): Add explanatory comment.
	(draw_border_preview): Fix typos. Wrong symbolic define was being
	used, but the numbers were the same, so the result was correct.
parent 6d46eb34
2000-06-11 Jon K Hellan <hellan@acm.org>
* dialog-cell-format.c (line_info[]): Add explanatory comment.
(draw_border_preview): Fix typos. Wrong symbolic define was being
used, but the numbers were the same, so the result was correct.
2000-06-08 ERDI Gergo <cactus@cactus.rulez.org>
* src/dialogs/dialog-printer-setup.c (unit_editor_configure):
......
......@@ -1441,6 +1441,15 @@ draw_pattern_selected (FormatState *state)
/*****************************************************************************/
/*
* This is self-evident.
* I stared at it for 15 minutes before realizing that it's self-evident,
* but it is. - jon_kare
*
* @points: x, y coordinates for the endpoints of the line segment.
* @states: A bitmap of states the coordinates are valid for.
* @location: Location.
*/
#define L 10. /* Left */
#define R 140. /* Right */
#define T 10. /* Top */
......@@ -1660,9 +1669,9 @@ static void
draw_border_preview (FormatState *state)
{
static double const corners[12][6] = {
{ T-5., T, L, T, L, T-5. },
{ L-5., T, L, T, L, T-5. },
{ R+5., T, R, T, R, T-5 },
{ T-5., B, L, B, L, B+5. },
{ L-5., B, L, B, L, B+5. },
{ R+5., B, R, B, R, B+5. },
{ V-5., T-1., V, T-1., V, T-5. },
......
2000-06-11 Jon K Hellan <hellan@acm.org>
* gnumeric-dashed-canvas-line.c (hypothenuse): New static helper
function.
(double_line_draw): New function. Draw a double line. Even explain
in nice ASCII art how we do it.
(gnumeric_dashed_canvas_line_draw): Special case double lines by
punting to double line draw.
2000-06-08 Jon K Hellan <hellan@acm.org>
* gtk-combo-text.c (gtk_combo_text_set_text): Silence run-time
......
......@@ -7,6 +7,7 @@
* (C) 1999, 2000 Jody Goldberg
*/
#include <config.h>
#include <math.h>
#include "gnumeric-dashed-canvas-line.h"
/*
......@@ -63,15 +64,123 @@ gnumeric_dashed_canvas_line_init (GnumericDashedCanvasLine *line)
line->dash_style_index = STYLE_BORDER_THIN;
}
static inline double
hypothenuse (double xlength, double ylength)
{
/* A little optimisation for speed. Horizontal or vertical lines
* are a lot more common than slanted */
if (xlength == 0)
return fabs (ylength);
else if (ylength == 0)
return fabs (xlength);
else
return sqrt (xlength * xlength + ylength * ylength);
}
/*
* Draw a double line
* NOTE: We only support a single straight line segment here.
*
* This function is called when drawing to the preview canvas in the cell
* format dialog - not called when drawing the grid to the screen. It isn't
* time critical, so we use similar triangles. This is slower than table
* lookup, which is used in border.c, but correct for all angles of slope.
*
* y axis
* /
* /
* /
* /
* ~ /
* A +---/----------------------------------
* | /B~
* | / ~
* |/ ~
* (x0,y0) *************************************** (x1,y1)
* ~ /
* ~ /
* ~ /
* ------------------~---------------/----
* ~ /
* ~ /
* (x1,y0)~
* ~ x axis
*
* In this diagram, the lines we are going to draw are horizontal, the
* coordinate axes are slanted.
* The starred line connects the endpoint coordinates as passed in. We
* actually draw the two dashed lines shown on either side. The triangle
* (x0,y0) - (x1,y0) - (x1,y1) is similar to the triangle (x0,y0) - B - A.
* Note that B is supposed to be on the line of ~ through A parallell to the
* x axis - that's hard to show clearly in ASCII art.
* AB is the x offset from x0 of the start of the upper dashed line.
* (x0,y0) - B is the y offset from y0 of the start of this line.
*/
static void
gnumeric_dashed_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
double_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
double *coords;
double length, xdiff, ydiff, xoffs, yoffs;
double offsetcoords[4];
GnumericDashedCanvasLine *line = GNUMERIC_DASHED_CANVAS_LINE (item);
if (GNOME_CANVAS_LINE (line)->num_points != 2) {
g_warning ("file %s: line %d: \n%s", __FILE__, __LINE__,
"GnumericDashedCanvasLine only supports a "
"single line segment.");
line->dash_style_index = STYLE_BORDER_MEDIUM;
gnumeric_dashed_canvas_line_draw
(GNOME_CANVAS_ITEM (line), drawable,
x, y, width, height);
return;
}
coords = GNOME_CANVAS_LINE (line)->coords;
xdiff = coords[2] - coords[0];
ydiff = coords[3] - coords[1];
length = hypothenuse (xdiff, ydiff);
yoffs = xdiff/length;
xoffs = -ydiff/length;
style_border_set_gc_dash (GNOME_CANVAS_LINE (item)->gc,
line->dash_style_index);
STYLE_BORDER_THIN);
offsetcoords[0] = coords[0] + xoffs;
offsetcoords[1] = coords[1] + yoffs;
offsetcoords[2] = coords[2] + xoffs;
offsetcoords[3] = coords[3] + yoffs;
GNOME_CANVAS_LINE (line)->coords = offsetcoords;
gnumeric_dashed_canvas_line_class->
real_draw (item, drawable, x, y, width, height);
offsetcoords[0] = coords[0] - xoffs;
offsetcoords[1] = coords[1] - yoffs;
offsetcoords[2] = coords[2] - xoffs;
offsetcoords[3] = coords[3] - yoffs;
gnumeric_dashed_canvas_line_class->
real_draw (item, drawable, x, y, width, height);
real_draw (item, drawable, x, y, width, height);
GNOME_CANVAS_LINE (line)->coords = coords;
}
static void
gnumeric_dashed_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
GnumericDashedCanvasLine *line = GNUMERIC_DASHED_CANVAS_LINE (item);
if (line->dash_style_index == STYLE_BORDER_DOUBLE)
double_line_draw (item, drawable, x, y, width, height);
else {
style_border_set_gc_dash (GNOME_CANVAS_LINE (item)->gc,
line->dash_style_index);
gnumeric_dashed_canvas_line_class->
real_draw (item, drawable, x, y, width, height);
}
}
void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment