00001 /* 00002 00003 Widget for drawing graphs in realtime 00004 Copyright (C) 2003 Jussi Laako 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 */ 00021 00022 00023 #include <gdk/gdk.h> 00024 #include <gtk/gtk.h> 00025 00026 #include "GraphWidget.hh" 00027 00028 00029 void clGraphWidget::MapToDisplay (int *ipDisplayX, int *ipDisplayY, 00030 double dGraphX, double dGraphY) 00031 { 00032 double dXScale; 00033 double dYScale; 00034 00035 dXScale = (double) lGraphWidth / dXRange; 00036 dYScale = (double) lGraphHeight / dYRange; 00037 *ipDisplayX = lMarginLeft + 00038 (long) (dGraphX * dXScale + dXLeft + 0.5); 00039 *ipDisplayY = lMarginTop + (lHeight - lMarginBottom - 00040 (long) (dGraphY * dYScale + dYBottom + 0.5)); 00041 } 00042 00043 00044 clGraphWidget::clGraphWidget () 00045 { 00046 lMarginTop = GRAPHWIDGET_MARGIN_TOP; 00047 lMarginLeft = GRAPHWIDGET_MARGIN_LEFT; 00048 lMarginBottom = GRAPHWIDGET_MARGIN_BOTTOM; 00049 lMarginRight = GRAPHWIDGET_MARGIN_RIGHT; 00050 00051 gwParent = NULL; 00052 gwDrawingArea = NULL; 00053 } 00054 00055 00056 clGraphWidget::~clGraphWidget () 00057 { 00058 } 00059 00060 00061 GtkWidget * clGraphWidget::Create (GtkWidget *gwParentP) 00062 { 00063 gwParent = gwParentP; 00064 gwDrawingArea = gtk_drawing_area_new(); 00065 gtk_widget_show(gwDrawingArea); 00066 00067 return gwDrawingArea; 00068 } 00069 00070 00071 void clGraphWidget::SetSize (int iWidthP, int iHeightP) 00072 { 00073 lWidth = (iWidthP > (lMarginLeft + lMarginRight)) ? 00074 iWidthP : (lMarginLeft + lMarginRight); 00075 lHeight = (iHeightP > (lMarginTop + lMarginBottom)) ? 00076 iHeightP : (lMarginTop + lMarginBottom); 00077 gtk_drawing_area_set_size(GTK_DRAWING_AREA(gwDrawingArea), 00078 iWidth, iHeight); 00079 00080 lGraphWidth = lWidth - lMarginLeft - lMarginRight; 00081 lGraphHeight = lHeight - lMarginTop - lMarginBottom; 00082 }
1.3.3