Commit 3322e73d authored by claes's avatar claes

Time format added

parent ad1871e3
/* /*
* Proview $Id: glow_growaxis.cpp,v 1.6 2005-11-04 11:53:46 claes Exp $ * Proview $Id: glow_growaxis.cpp,v 1.7 2005-11-14 16:28:12 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -298,7 +298,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -298,7 +298,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
if ( draw_text) { if ( draw_text) {
for ( i = 0; i < lines; i++) { for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) { if ( i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, text_idx), &z_width, &z_height, &z_descent); max( 0, text_idx), &z_width, &z_height, &z_descent);
if ( max_z_width < z_width) if ( max_z_width < z_width)
...@@ -324,7 +324,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -324,7 +324,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
glow_draw_line( ctx, ur_x - int( 2.0 / 3 * line_length), y, glow_draw_line( ctx, ur_x - int( 2.0 / 3 * line_length), y,
ur_x, y, drawtype, idx, 0); ur_x, y, drawtype, idx, 0);
if ( draw_text) { if ( draw_text) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
if ( text_idx >= 0 && max_z_width < ur_x - ll_x && if ( text_idx >= 0 && max_z_width < ur_x - ll_x &&
i % valuequotient == 0) { i % valuequotient == 0) {
...@@ -369,7 +369,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -369,7 +369,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
ur_y, drawtype, idx, 0); ur_y, drawtype, idx, 0);
if ( draw_text && i % valuequotient == 0) { if ( draw_text && i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, text_idx), &z_width, &z_height, &z_descent); max( 0, text_idx), &z_width, &z_height, &z_descent);
...@@ -396,7 +396,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -396,7 +396,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
if ( draw_text) { if ( draw_text) {
for ( i = 0; i < lines; i++) { for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) { if ( i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, text_idx), &z_width, &z_height, &z_descent); max( 0, text_idx), &z_width, &z_height, &z_descent);
if ( max_z_width < z_width) if ( max_z_width < z_width)
...@@ -421,7 +421,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -421,7 +421,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
else else
glow_draw_line( ctx, ll_x, y, glow_draw_line( ctx, ll_x, y,
ll_x + int( 2.0 / 3 * line_length), y, drawtype, idx, 0); ll_x + int( 2.0 / 3 * line_length), y, drawtype, idx, 0);
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
if ( draw_text && if ( draw_text &&
text_idx >= 0 && max_z_width < ur_x - ll_x && text_idx >= 0 && max_z_width < ur_x - ll_x &&
...@@ -465,7 +465,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node, ...@@ -465,7 +465,7 @@ void GrowAxis::draw( GlowTransform *t, int highlight, int hot, void *node,
glow_draw_line( ctx, x, ll_y, x, glow_draw_line( ctx, x, ll_y, x,
ll_y + int( 2.0 / 3 * line_length), drawtype, idx, 0); ll_y + int( 2.0 / 3 * line_length), drawtype, idx, 0);
if ( draw_text && i % valuequotient == 0) { if ( draw_text && i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, text_idx), &z_width, &z_height, &z_descent); max( 0, text_idx), &z_width, &z_height, &z_descent);
...@@ -910,7 +910,7 @@ void GrowAxis::export_javabean( GlowTransform *t, void *node, ...@@ -910,7 +910,7 @@ void GrowAxis::export_javabean( GlowTransform *t, void *node,
if ( draw_text) { if ( draw_text) {
for ( i = 0; i < lines; i++) { for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) { if ( i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, idx), &z_width, &z_height, &z_descent); max( 0, idx), &z_width, &z_height, &z_descent);
if ( max_z_width < z_width) if ( max_z_width < z_width)
...@@ -938,7 +938,7 @@ void GrowAxis::export_javabean( GlowTransform *t, void *node, ...@@ -938,7 +938,7 @@ void GrowAxis::export_javabean( GlowTransform *t, void *node,
if ( draw_text) { if ( draw_text) {
for ( i = 0; i < lines; i++) { for ( i = 0; i < lines; i++) {
if ( i % valuequotient == 0) { if ( i % valuequotient == 0) {
sprintf( text, format, max_value - i * increment); format_text( text, format, max_value - i * increment);
draw_get_text_extent( ctx, text, strlen(text), text_drawtype, draw_get_text_extent( ctx, text, strlen(text), text_drawtype,
max( 0, idx), &z_width, &z_height, &z_descent); max( 0, idx), &z_width, &z_height, &z_descent);
if ( max_z_width < z_width) if ( max_z_width < z_width)
...@@ -998,6 +998,35 @@ void GrowAxis::set_axis_info( glow_sAxisInfo *info) ...@@ -998,6 +998,35 @@ void GrowAxis::set_axis_info( glow_sAxisInfo *info)
strcpy( format, info->format); strcpy( format, info->format);
} }
void GrowAxis::format_text( char *text, char *fmt, double value)
{
if ( strcmp( fmt, "%1t") == 0) {
// Hours, minutes and seconds, value in seconds
int val = (int) nearbyint(value);
int hours = val / 3600;
int minutes = (val - hours * 3600) / 60;
int seconds = (val - hours * 3600 - minutes * 60);
sprintf( text, "%d:%02d:%02d", hours, minutes, seconds);
}
else if ( strcmp( fmt, "%2t") == 0) {
// Hours and minutes, value in seconds
int val = (int) nearbyint(value);
int hours = val / 3600;
int minutes = (val - hours * 3600) / 60;
sprintf( text, "%d:%02d", hours, minutes);
}
else if ( strcmp( fmt, "%3t") == 0) {
// Days, hours and minues, value in seconds
int val = (int) nearbyint(value);
int days = val / (24 * 3600);
int hours = (val - days * 24 * 3600) / 3600;
int minutes = (val - days * 24 * 3600 - hours * 3600) / 60;
sprintf( text, "%d %02d:%02d", days, hours, minutes);
}
else
sprintf( text, fmt, value);
}
void GrowAxis::convert( glow_eConvert version) void GrowAxis::convert( glow_eConvert version)
{ {
switch ( version) { switch ( version) {
......
/* /*
* Proview $Id: glow_growaxis.h,v 1.3 2005-09-01 14:57:53 claes Exp $ * Proview $Id: glow_growaxis.h,v 1.4 2005-11-14 16:28:12 claes Exp $
* Copyright (C) 2005 SSAB Oxelösund AB. * Copyright (C) 2005 SSAB Oxelösund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -242,6 +242,14 @@ class GrowAxis : public GrowRect { ...@@ -242,6 +242,14 @@ class GrowAxis : public GrowRect {
*/ */
void set_original_text_color( glow_eDrawType drawtype) void set_original_text_color( glow_eDrawType drawtype)
{ text_color_drawtype = drawtype; draw();}; { text_color_drawtype = drawtype; draw();};
//! Format axis text.
/*!
\param text Formated text.
\param fmt Format specification, c syntax or %1t(h:m:s), %2t (d h:m) for time formats.
\param value Value to format.
*/
void format_text( char *text, char *fmt, double value);
}; };
......
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