|
From: Mapi B. <ma...@us...> - 2011-02-28 22:08:18
|
Update of /cvsroot/easycalc/PPCport/discarded
In directory vz-cvs-4.sog:/tmp/cvs-serv3683
Added Files:
graph.rcp.in grcalc.cpp grcalc.h grtaps.c grtaps.h
Log Message:
1.25g
--- NEW FILE: graph.rcp.in ---
//
// $Id: graph.rcp.in,v 1.1 2011/02/28 22:08:16 mapibid Exp $
//
#ifdef SUPPORT_DIA
//Dana AlphaSmart support
HEX "wTap" ID 1000
0x00 0x00 0x00 0x01
#endif
FORM ID frmGrcSel AT (2 50 156 108)
MODAL
DEFAULTBTNID btnGrcSelCancel
BEGIN
TITLE "$$SELECT A FUNCTION"
BUTTON "$$OK" ID btnGrcSelOK AT (5 92 40 12)
BUTTON "$$CANCEL" ID btnGrcSelCancel AT (PREVRIGHT+5 PREVTOP AUTO 12)
LIST "" ID lstGrcSel AT (50 15 50 60) VISIBLEITEMS 6
END
FORM ID grTableForm AT (2 2 156 156)
MODAL
BEGIN
TITLE "$$TABLE MODE"
BUTTON "<" ID grTableLeft AT (52 140 12 12)
BUTTON ">" ID grTableRight AT (PREVRIGHT+4 PREVTOP 12 12)
BUTTON "$$STEP" ID grTableStep AT (PREVRIGHT+6 PREVTOP 30 12)
BUTTON "$$GOTO" ID grTableGoto AT (PREVRIGHT+6 PREVTOP 30 12)
TABLE ID grTableTable AT (5 15 150 110) ROWS 10 COLUMNS 3 COLUMNWIDTHS 50 50 50
BUTTON "$$DONE" ID grTableDone AT (5 140 40 12)
END
FORM ID grSetupForm AT (2 43-11 156 115+11)
MODAL
HELPID hlpGrSetup
BEGIN
TITLE "$$SETUP GRAPHS"
BUTTON " " ID grAxes AT (5 17 6 6) RECTFRAME NONUSABLE
CHECKBOX "Axes" ID ckbGrAxes AT (12 14 AUTO AUTO)
CHECKBOX "Axes labels" ID ckbGrAxesLabels AT (12 25 AUTO AUTO)
BUTTON " " ID grGrid AT (90 17 6 6) RECTFRAME NONUSABLE
CHECKBOX "Grid" ID ckbGrGrid AT (97 14 AUTO AUTO)
BUTTON " " ID grBgnd AT (90 28 6 6) RECTFRAME NONUSABLE
LABEL "Bgnd" ID grBgndLbl AT (104 25) NONUSABLE
BUTTON " " ID grColor1 AT (5 32+11 6 6) RECTFRAME NONUSABLE
BUTTON " " ID grColor2 AT (5 43+11 6 6) RECTFRAME NONUSABLE
BUTTON " " ID grColor3 AT (5 54+11 6 6) RECTFRAME NONUSABLE
BUTTON " " ID grColor4 AT (5 65+11 6 6) RECTFRAME NONUSABLE
BUTTON " " ID grColor5 AT (5 76+11 6 6) RECTFRAME NONUSABLE
BUTTON " " ID grColor6 AT (5 87+11 6 6) RECTFRAME NONUSABLE
CHECKBOX "" ID ckbGrfun1 AT (12 29+11 AUTO AUTO)
CHECKBOX "" ID ckbGrfun2 AT (12 40+11 AUTO AUTO) NONUSABLE
CHECKBOX "" ID ckbGrfun3 AT (12 51+11 AUTO AUTO)
CHECKBOX "" ID ckbGrfun4 AT (12 62+11 AUTO AUTO) NONUSABLE
CHECKBOX "" ID ckbGrfun5 AT (12 73+11 AUTO AUTO)
CHECKBOX "" ID ckbGrfun6 AT (12 84+11 AUTO AUTO) NONUSABLE
TABLE ID grSetupTable AT (25 29+11 112 67) ROWS 6 COLUMNS 2 COLUMNWIDTHS 16 94
BUTTON " " ID grType1 AT (139 31+11 13 7) NOFRAME
BUTTON " " ID grType2 AT (139 42+11 13 7) NOFRAME NONUSABLE
BUTTON " " ID grType3 AT (139 53+11 13 7) NOFRAME
BUTTON " " ID grType4 AT (139 64+11 13 7) NOFRAME NONUSABLE
BUTTON " " ID grType5 AT (139 75+11 13 7) NOFRAME
BUTTON " " ID grType6 AT (139 86+11 13 7) NOFRAME NONUSABLE
BUTTON "$$DONE" ID grSetupDone AT (5 100+11 40 12)
BUTTON "\001" ID grSetupUp AT (140 98+11 12 8) FONT 5 NONUSABLE NOFRAME
BUTTON "\002" ID grSetupDown AT (140 106+11 12 8) FONT 5 NONUSABLE NOFRAME
LIST "" ID grSetupList AT (1 1 62 10) VISIBLEITEMS 10 NONUSABLE DISABLED
POPUPLIST ID grSetupPopup grSetupList
END
FORM ID grPrefForm AT (2 2 156 156)
MODAL
MENUID sysEditMenuID
HELPID hlpGrPref
BEGIN
TITLE "$$GRAPH PREFERENCES"
BUTTON "$$OK" ID prefOK AT (5 140 40 12)
BUTTON "$$CANCEL" ID prefCancel AT (PREVRIGHT+5 PREVTOP AUTO 12)
LABEL "xmin:" AUTOID AT (3 14)
FIELD ID grPrefXmin AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL "xmax:" AUTOID AT (3 PREVTOP+14)
FIELD ID grPrefXmax AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL "xscale:" AUTOID AT (3 PREVTOP+14)
FIELD ID grPrefXscale AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL "ymin:" AUTOID AT (3 PREVTOP+14)
FIELD ID grPrefYmin AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL "ymax:" AUTOID AT (3 PREVTOP+14)
FIELD ID grPrefYmax AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL "yscale:" AUTOID AT (3 PREVTOP+14)
FIELD ID grPrefYscale AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 USABLE
LABEL " " grPrefLabel1 AT (3 PREVTOP+14) NONUSABLE
FIELD ID grPrefField1 AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 NONUSABLE
LABEL "Rad" grPrefLabel1u AT (PREVRIGHT PREVTOP) NONUSABLE
LABEL " " grPrefLabel2 AT (3 PREVTOP+14) NONUSABLE
FIELD ID grPrefField2 AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 NONUSABLE
LABEL "Rad" grPrefLabel2u AT (PREVRIGHT PREVTOP) NONUSABLE
LABEL " " grPrefLabel3 AT (3 PREVTOP+14) NONUSABLE
FIELD ID grPrefField3 AT (33 PREVTOP 57 12) EDITABLE UNDERLINED SINGLELINE MAXCHARS 20 NONUSABLE
LABEL "Rad" grPrefLabel3u AT (PREVRIGHT PREVTOP) NONUSABLE
BUTTON "$$DEFAULT" ID grPrefDefault AT (100 20 50 12)
BUTTON "$$TRIGONO" ID grPrefTrig AT (100 35 50 12)
PUSHBUTTON "$$FUNCMODE" ID grPrefFunc AT (100 55 54 12) GROUP 1
PUSHBUTTON "$$POLARMODE" ID grPrefPol AT (PREVLEFT PREVBOTTOM+1 PREVWIDTH 12) GROUP 1
PUSHBUTTON "$$PARAMMODE" ID grPrefPar AT (PREVLEFT PREVBOTTOM+1 PREVWIDTH 12) GROUP 1
CHECKBOX "Log X" ckbGrPrefLogX AT (PREVLEFT+13 PREVBOTTOM+16 AUTO AUTO)
CHECKBOX "Log Y" ckbGrPrefLogY AT (PREVLEFT PREVBOTTOM AUTO AUTO)
GRAFFITISTATEINDICATOR AT (143 PREVBOTTOM+2)
END
STRINGTABLE grColorElem "Pick color for " "fun1" "fun2" "fun3" "fun4" "fun5" "fun6" "$$AXIS" "$$GRID" "$$BACKGRND"
FORM ID frmGraph AT (0 0 160 160)
MENUID graphMenu
BEGIN
TITLE "$$GRAPH"
BUTTON " " ID btnPrefMode AT (56 1 17 12) RECTFRAME
SELECTORTRIGGER "P" ID btnGraphPref AT (PREVRIGHT+11 1 10 11)
SELECTORTRIGGER "S" ID btnGraphSetup AT (PREVRIGHT+1 1 10 11)
PUSHBUTTON "B" ID btnBasic AT (116 1 10 12) GROUP 1
PUSHBUTTON "S" ID btnScientific AT (PREVRIGHT+1 1 10 12) GROUP 1
PUSHBUTTON "I" ID btnInteger AT (PREVRIGHT+1 1 10 12) GROUP 1
PUSHBUTTON "G" ID btnGraph AT (PREVRIGHT+1 1 10 12) GROUP 1
GADGET ID graphGadget AT (1 17 140 140)
SELECTORTRIGGER "C " ID btnGraphCalc AT (147 22 10 12)
LIST "$$GRZERO" "$$GRVALUE" "$$GRMIN" "$$GRMAX" "$$GRDDX" "d2/dx" "$$GRINTEG" "$$GRINTERSECT" ID lstGraphCalcFunc AT (100 22 55 50) NONUSABLE DISABLED VISIBLEITEMS 8
POPUPLIST AUTOID lstGraphCalcFunc
LIST "dy/dx" "dy/dt" "dx/dt" ID lstGraphCalcParam AT (PREVLEFT PREVTOP PREVWIDTH PREVHEIGHT) NONUSABLE DISABLED VISIBLEITEMS 3
POPUPLIST AUTOID lstGraphCalcParam
LIST "dr/dfi" ID lstGraphCalcPolar AT (PREVLEFT PREVTOP PREVWIDTH PREVHEIGHT) NONUSABLE DISABLED VISIBLEITEMS 1
POPUPLIST AUTOID lstGraphCalcPolar
PUSHBUTTON "T" ID btnGraphTrack AT (147 50 10 12)
LIST "" ID graphTrackList AT (120 50 30 50) NONUSABLE DISABLED VISIBLEITEMS 3
POPUPLIST ID graphTrackPopup graphTrackList
BUTTON "$$GO" ID btnGraphTrackGoto AT (145 65 14 12) NONUSABLE
PUSHBUTTON "+" ID btnGraphZoomIn AT (147 90 10 12)
BUTTON "-" ID btnGraphZoomOut AT (147 105 10 12)
SELECTORTRIGGER "Sp" ID btnGraphSpeed AT (145 120 14 12)
LIST "1x" "2x" "4x" "7x" lstGraphSpeed AT (140 100 15 44) VISIBLEITEMS 4 NONUSABLE DISABLED
//BUTTON "" ID btnGraphColor AT (148 146 8 8) NOFRAME NONUSABLE
END
#ifdef SUPPORT_DIA
WORDLIST ID frmGraph
BEGIN
DIA_FORM_USE_BIN // formFlags
0 // bin
DIA_STATE_MAX // preferred state
// Object data
0 DIA_H_PLUS_DH+DIA_W_PLUS_DW 0 // the form itself
btnBasic DIA_X_RIGHT 0
btnScientific DIA_X_RIGHT 0
btnInteger DIA_X_RIGHT 0
btnGraph DIA_X_RIGHT 0
graphGadget DIA_H_PLUS_DH+DIA_W_PLUS_DW 0
btnGraphZoomIn DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
btnGraphZoomOut DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
btnPrefMode DIA_X_PLUS_1_2_DW 0
btnGraphPref DIA_X_PLUS_3_4_DW 0
btnGraphSetup DIA_X_PLUS_3_4_DW 0
btnGraphTrack DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
btnGraphTrackGoto DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
graphTrackList DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
// graphTrackPopup DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
btnGraphCalc DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
lstGraphCalcFunc DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
lstGraphCalcParam DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
lstGraphCalcPolar DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
btnGraphSpeed DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
lstGraphSpeed DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
// btnGraphColor DIA_X_RIGHT+DIA_Y_PLUS_1_2_DH 0
END
#endif
MENU ID graphMenu
BEGIN
PULLDOWN "$$LAYOUT"
BEGIN
MENUITEM "$$BASIC" btnBasic "B"
MENUITEM "$$SCIENTIFIC" btnScientific "S"
MENUITEM "$$INTEGER" btnInteger "I"
MENUITEM "$$GRAPH" btnGraph "G"
MENUITEM SEPARATOR
MENUITEM "$$PREFERENCES..." tdBPref "R"
END
PULLDOWN "$$GRAPH"
BEGIN
MENUITEM "$$PREFERENCES..." btnGraphPref
MENUITEM "$$SETUP GRAPHS..." btnGraphSetup
MENUITEM "$$TABLE MODE..." btnGraphTable "T"
END
PULLDOWN "$$INFO"
BEGIN
MENUITEM "$$ABOUT..." mitAbout "A"
MENUITEM "$$HELP" hlpMain2 "H"
END
END
ALERT altGraphBadVal
ERROR
BEGIN
TITLE "$$ERROR"
MESSAGE "$$BAD VALUES"
BUTTONS "$$OK"
END
ALERT altGrcSelectLeft
INFORMATION
DEFAULTBUTTON 1
BEGIN
TITLE "$$GRAPH COMPUTING"
MESSAGE "$$LEFTBOUND"
BUTTONS "$$OK" "$$CANCEL"
END
ALERT altGrcSelectRight
INFORMATION
DEFAULTBUTTON 1
BEGIN
TITLE "$$GRAPH COMPUTING"
MESSAGE "$$RIGHTBOUND"
BUTTONS "$$OK" "$$CANCEL"
END
ALERT altGrcSelectValue
INFORMATION
DEFAULTBUTTON 1
BEGIN
TITLE "$$GRAPH COMPUTING"
MESSAGE "$$POINTONGRAPH"
BUTTONS "$$OK" "$$CANCEL"
END
ALERT altComputeResult
INFORMATION
BEGIN
TITLE "$$GRAPH COMPUTING RESULT"
MESSAGE "$$COMPRESULT"
BUTTONS "$$OK"
END
ALERT altComputeCofirm
WARNING
DEFAULTBUTTON 1
BEGIN
TITLE "$$COMPUTING"
MESSAGE "$$COMPCONFIRM"
BUTTONS "$$OK" "$$CANCEL"
END
ALERT altGrcBoundsErr
ERROR
BEGIN
TITLE "$$ERROR"
MESSAGE "$$GRCBOUNDERR"
BUTTONS "$$OK"
END
ALERT altGrcFuncErr
ERROR
BEGIN
TITLE "$$ERROR"
MESSAGE "$$GRCFUNCERR"
BUTTONS "$$OK"
END
STRING hlpGrPref "$$GRPREF HELP"
STRING hlpGrSetup "$$GRSETUP HELP"
STRINGTABLE strGrcDescription "" "$$GRZERO" "$$GRVALUE" "$$GRMIN" "$$GRMAX" "$$GRDDX" "d2/dx" "$$GRINTEG" "$$GRINTERSECT" "dy/dx" "dy/dt" "dx/dt" "dr/dfi"
--- NEW FILE: grcalc.cpp ---
/*
* $Id: grcalc.cpp,v 1.1 2011/02/28 22:08:16 mapibid Exp $
*
* Scientific Calculator for Palms.
* Copyright (C) 2001 Ondrej Palkovsky
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* You can contact me at 'on...@pe...'.
*/
#include "stdafx.h"
#include "compat/PalmOS.h"
//#include "calcrsc.h"
#include "compat/segment.h"
#include "core/mlib/konvert.h"
#include "core/calc.h"
#include "core/mlib/funcs.h"
#include "core/mlib/integ.h"
#include "core/varmgr.h"
#include "core/mlib/mathem.h"
#include "core/mlib/display.h"
#include "compat/MathLib.h"
#include "core/mlib/stack.h"
#include "core/grcalc.h"
//#include "core/graph.h"
#include "core/grsetup.h"
#include "core/grprefs.h"
//#include "grtaps.h"
#ifdef HANDERA_SDK
#include "Vga.h"
#endif
static enum {
cl_none,
cl_min,
cl_max,
cl_value
}grState;
static enum {
cp_zero = 0,
cp_value,
cp_min,
cp_max,
cp_dydx1,
cp_dydx2,
cp_integ,
cp_intersect,
cp_pdydx,
cp_pdydt,
cp_pdxdt,
cp_odrdfi
}grFuncType;
static const Int16 grcFunc[] = {cp_zero,cp_value,cp_min,cp_max,
cp_dydx1,cp_dydx2,cp_integ,cp_intersect};
static const Int16 grcParam[] = {cp_pdydx,cp_pdydt,cp_pdxdt};
static const Int16 grcPolar[] = {cp_odrdfi};
static Int16 grSelFunction,grSelFunction2;
static double grFuncMin;
static double grFuncMax;
static double grFuncValue;
/***********************************************************************
*
* FUNCTION: grcalc_select_funcname
*
* DESCRIPTION: Present to user list of functions and let him select
*
* PARAMETERS: Nothing
*
* RETURN: -1 - error, user pressed cancel or no function on graph
* 0-MAX_GRFUNCS - index to graphCurves table
*
***********************************************************************/
static Int16 grcalc_select_funcname(void) GRAPH;
static Int16
grcalc_select_funcname(void)
{
FormPtr frm;
ListPtr list;
Int16 button;
char *descr[MAX_GRFUNCS];
Int16 nums[MAX_GRFUNCS];
Int16 count,i;
count = grsetup_fn_descr_arr(descr,nums);
if (count == 0)
return -1;
frm = FrmInitForm(frmGrcSel);
#ifdef HANDERA_SDK
if (handera)
VgaFormModify(frm, vgaFormModify160To240);
#endif
list = FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,lstGrcSel));
LstSetListChoices(list,descr,count);
button = FrmDoDialog(frm);
i = LstGetSelection(list);
FrmDeleteForm(frm);
if (button == btnGrcSelCancel)
return -1;
if (i == noListSelection)
return -1;
return nums[i];
}
/***********************************************************************
*
* FUNCTION: grcalc_select_func
*
* DESCRIPTION: The initial step when the user presses the 'C' button
* and the function type 'Func' is displayed
*
* PARAMETERS: Nothing
*
* RETURN: true - user selected everything ok
* false - action cancelled
*
***********************************************************************/
static Boolean grcalc_select(void) GRAPH;
static Boolean
grcalc_select(void)
{
Int16 i;
Int16 list;
const Int16 *ccs;
if (graphPrefs.functype == graph_func) {
list = lstGraphCalcFunc;
ccs = grcFunc;
} else if (graphPrefs.functype == graph_polar) {
list = lstGraphCalcPolar;
ccs = grcPolar;
} else {
list = lstGraphCalcParam;
ccs = grcParam;
}
i = LstPopupList(GetObjectPtr(list));
if (i == noListSelection)
return false;
grFuncType = ccs[i];
if (CtlGetValue(GetObjectPtr(btnGraphTrack)))
grSelFunction=grtaps_trackSelected();
else{
grSelFunction = grcalc_select_funcname();
if (grSelFunction == -1)
return false;
grtaps_track_track(grSelFunction);
}
switch (grFuncType) {
case cp_value:
if (!varmgr_get_double(&grFuncValue,"Value of Function"))
return false;
case cp_integ:
case cp_zero:
case cp_min:
case cp_max:
case cp_intersect:
if (FrmAlert(altGrcSelectLeft) == 1)
return false;
grState = cl_min;
break;
case cp_dydx1:
case cp_dydx2:
case cp_pdydx:
case cp_pdydt:
case cp_pdxdt:
case cp_odrdfi:
if (FrmAlert(altGrcSelectValue) == 1)
return false;
grState = cl_value;
break;
}
return true;
}
/***********************************************************************
*
* FUNCTION: grcalc_calculate
*
* DESCRIPTION: This function is called when all necessary
* data is fetched from the user and calculates
* and displays result to the user.
*
* PARAMETERS: Nothing
*
* RETURN: Nothing
*
***********************************************************************/
static void grcalc_calculate(void) GRAPH;
static void
grcalc_calculate(void)
{
double result;
CodeStack *fcstack,*fcstack2;
char *text,acdescr[MAX_RSCLEN];
if (grState != cl_value && grFuncMin == grFuncMax) {
FrmAlert(altGrcBoundsErr);
return;
}
if (grState != cl_value && grFuncMin > grFuncMax) {
result = grFuncMin;
grFuncMin = grFuncMax;
grFuncMax = result;
}
if (grFuncType == cp_intersect) {
grSelFunction2 = grcalc_select_funcname();
if (grSelFunction2 == -1)
return;
if (grSelFunction == grSelFunction2) {
FrmAlert(altGrcFuncErr);
return;
}
}
/* I wonder if I should display it at all */
if (grFuncType == cp_zero || grFuncType == cp_min
|| grFuncType == cp_max || grFuncType == cp_value)
if (FrmAlert(altComputeCofirm) == 1)
return; /* User cancelled operation */
fcstack = graphCurves[grSelFunction].stack1;
if (grFuncType == cp_intersect)
fcstack2 = graphCurves[grSelFunction2].stack1;
else
fcstack2 = graphCurves[grSelFunction].stack2;
switch (grFuncType) {
case cp_intersect:
result = integ_intersect(grFuncMin,grFuncMax,fcstack,
fcstack2,DEFAULT_ERROR,NULL);
break;
case cp_zero:
result = integ_zero(grFuncMin,grFuncMax,0.0,fcstack,
DEFAULT_ERROR,MATH_FZERO,NULL);
break;
case cp_min:
result = integ_zero(grFuncMin,grFuncMax,0.0,fcstack,
DEFAULT_ERROR,MATH_FMIN,NULL);
break;
case cp_max:
result = integ_zero(grFuncMin,grFuncMax,0.0,fcstack,
DEFAULT_ERROR,MATH_FMAX,NULL);
break;
case cp_integ:
result = integ_romberg(grFuncMin,grFuncMax,fcstack,
DEFAULT_ROMBERG,NULL);
// result = integ_simps(grFuncMin,grFuncMax,fcstack,
// DEFAULT_ERROR);
break;
case cp_value:
result = integ_zero(grFuncMin,grFuncMax,grFuncValue,fcstack,
DEFAULT_ERROR,MATH_FVALUE,NULL);
break;
case cp_dydx2:
result = integ_derive2(grFuncValue,fcstack,DEFAULT_ERROR,NULL);
break;
case cp_dydx1:
case cp_pdxdt:
case cp_odrdfi:
result = integ_derive1(grFuncValue,fcstack,DEFAULT_ERROR,NULL);
break;
case cp_pdydx:
result = integ_derive1(grFuncValue,fcstack2,DEFAULT_ERROR,NULL);
result /= integ_derive1(grFuncValue,fcstack,DEFAULT_ERROR,NULL);
break;
case cp_pdydt:
result = integ_derive1(grFuncValue,fcstack2,DEFAULT_ERROR,NULL);
break;
default:
result = NaN;
break;
}
if (finite(result)) {
/* The default error is lower, but this may
display better values */
/* Save the result as 'graphres' variable */
db_save_real("graphres", result);
/* Round the result with respect to computing error */
result /= 1E-5;
result = round(result) * 1E-5;
/* Set the cross to result where applicable */
switch (grFuncType) {
case cp_intersect:
case cp_zero:
case cp_min:
case cp_max:
case cp_value:
grtaps_track_manual(result, track_set);
break;
}
text = display_real(result);
/* Fetch description of a function */
SysStringByIndex(strGrcDescription, grFuncType,
acdescr, MAX_RSCLEN - 1);
FrmCustomAlert(altComputeResult, acdescr, text, NULL);
MemPtrFree(text);
} else
FrmAlert(altCompute);
}
/***********************************************************************
*
* FUNCTION: grcalc_init
*
* DESCRIPTION: Initialize/reset this module
*
* PARAMETERS: Nothing
*
* RETURN: Nothing
*
***********************************************************************/
void
grcalc_init(void)
{
grState = cl_none;
}
/***********************************************************************
*
* FUNCTION: grcalc_control
*
* DESCRIPTION: This things gets called when the 'C' button on the graph
* screen is pressed.
*
* PARAMETERS: Nothing
*
* RETURN: true - this module waits for some more input
* false - this module is inactive
*
***********************************************************************/
Boolean
grcalc_control(void)
{
switch (grState) {
case cl_none:
grcalc_select();
break;
case cl_min:
grFuncMin = grtaps_track_last_value();
if (FrmAlert(altGrcSelectRight) == 0)
grState = cl_max;
else {
grState = cl_none;
//grtaps_track_pause();
}
break;
case cl_max:
grFuncMax = grtaps_track_last_value();
grcalc_calculate();
grState = cl_none;
//grtaps_track_pause();
break;
case cl_value:
grFuncValue = grtaps_track_last_value();
grcalc_calculate();
grState = cl_none;
//grtaps_track_pause();
break;
}
return grState != cl_none;
}
--- NEW FILE: grtaps.c ---
/*
* $Id: grtaps.c,v 1.1 2011/02/28 22:08:16 mapibid Exp $
*
* Scientific Calculator for Palms.
* Copyright (C) 1999,2000,2001 Ondrej Palkovsky
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* You can contact me at 'on...@pe...'.
*/
#include <PalmOS.h>
#ifdef SONY_SDK
#include <SonyCLIE.h>
#endif
#ifdef SUPPORT_DIA
#include "DIA.h"
#else
#define HanderaCoord( x ) ( x )
#define HanderaAdjustFont( font ) ( font )
#endif
#include "clie.h"
#include "MathLib.h"
#include "grtaps.h"
#include "calcrsc.h"
#include "grprefs.h"
#include "graph.h"
#include "calc.h"
#include "mathem.h"
#include "display.h"
#include "fp.h"
#include "grsetup.h"
#include "funcs.h"
#define BOLDRES 1
static Int16 trackSelected = 0;
static double lastParam = 0.0;
static Coord crossX = -1, crossY = -1;
static double oldr = NaN;
static double oldangle = NaN;
static double oldparam = NaN;
static double oldrealx = NaN;
static double oldrealy = NaN;
//static const TdispPrefs grNumPrefs = { 5, true, disp_normal, disp_decimal, false, false};
/***********************************************************************
*
* FUNCTION: EvtGetPenNat
*
* DESCRIPTION: As EvtGetPen, but returns native screen coordinates.
*
* PARAMETERS: Same as EvtGetPen().
*
* RETURN: Nothing.
*
***********************************************************************/
static void
EvtGetPenNat(Coord *x, Coord *y, Boolean *penDown)
{
EvtGetPen(x, y, penDown);
if (gHrMode == hrPalm) {
UInt16 save = WinSetCoordinateSystem(kCoordinatesNative);
*x = WinScaleCoord(*x, true);
*y = WinScaleCoord(*y, true);
WinSetCoordinateSystem(save);
}
else {
*x *= gSonyFactor;
*y *= gSonyFactor;
}
}
/***********************************************************************
*
* FUNCTION: grtaps_rectangle
*
* DESCRIPTION: Draws a rectangle for use with 'Zoom in' operation
*
* PARAMETERS: corners of the rectangle
*
* RETURN: Nothing
*
***********************************************************************/
static void
grtaps_rectangle(Int16 x1,Int16 y1,Int16 x2,Int16 y2) GRAPH;
static void
grtaps_rectangle(Int16 x1,Int16 y1,Int16 x2,Int16 y2)
{
if (x1<0 || x2<0 || y1<0 || y2<0)
return;
clie_invertline(x1,y1,x2,y1);
clie_invertline(x1,y2,x2,y2);
clie_invertline(x1,y1,x1,y2);
clie_invertline(x2,y1,x2,y2);
clie_invertline(x1,y1,x2,y2);
clie_invertline(x2,y1,x1,y2);
}
/***********************************************************************
*
* FUNCTION: grtaps_clear_edges
*
* DESCRIPTION: Used when moving screen, clears the edges, that should
* be left empty, when the contents of the screen is moved
*
* PARAMETERS: bounds - bounds of draw area
* mx,my - coordinates, where the contents is moved
*
* RETURN: Nothing
*
***********************************************************************/
static void
grtaps_clear_edges(Coord mx,Coord my,RectangleType *bounds) GRAPH;
static void
grtaps_clear_edges(Coord mx,Coord my,RectangleType *bounds)
{
RectangleType tmp,tmp2;
tmp = *bounds;
tmp.topLeft.x+=mx;
tmp.topLeft.y+=my;
clie_cliprectangle(&tmp);
tmp2 = *bounds;
tmp2.extent.x = tmp.topLeft.x - bounds->topLeft.x;
clie_eraserectangle(&tmp2,0);
tmp2 = *bounds;
tmp2.extent.y = tmp.topLeft.y - bounds->topLeft.y;
clie_eraserectangle(&tmp2,0);
tmp2 = *bounds;
tmp2.topLeft.x = tmp.topLeft.x+tmp.extent.x;
clie_eraserectangle(&tmp2,0);
tmp2 = *bounds;
tmp2.topLeft.y = tmp.topLeft.y+tmp.extent.y;
clie_eraserectangle(&tmp2,0);
}
/***********************************************************************
*
* FUNCTION: grtaps_move
*
* DESCRIPTION: Started to fetch pen moves and move the drawing screen
* contents accordingly
*
* PARAMETERS: begx,begy - the original user tap
* bounds - bounds of the drawing area
*
* RETURN: true/false - if the user ended within the bounds
* and the screen should be moved
*
***********************************************************************/
static Boolean
grtaps_move(Coord begx,Coord begy,RectangleType *bounds) GRAPH;
static Boolean
grtaps_move(Coord begx,Coord begy,RectangleType *bounds)
{
Boolean penDown,moved;
Coord x,y,dx,dy;
Coord oldx=begx,oldy=begy;
WinHandle orgwindow;
UInt16 err;
RectangleType orgbounds,rs;
double xmin,ymin;
orgwindow = clie_createoffscreenwindow(bounds->extent.x,bounds->extent.y,
nativeFormat,&err);
/* Note: orgwindow may be NULL if there is insufficient memory for the
offscreen window. Then we need to copy inside the screen window */
if (orgwindow)
clie_copyrectangle(NULL,orgwindow,bounds,0,0,winPaint);
clie_getclip(&rs);
clie_setclip(bounds);
orgbounds = *bounds;
if (orgwindow)
orgbounds.topLeft.x = orgbounds.topLeft.y = 0;
graph_setcolor(-1);
do {
EvtGetPenNat(&x, &y, &penDown);
if ((oldx!=x || oldy!=y) && RctPtInRectangle(x,y,bounds)) {
dx = (orgwindow ? x-begx : x-oldx);
dy = (orgwindow ? y-begy : y-oldy);
clie_copyrectangle(orgwindow,NULL,&orgbounds,
bounds->topLeft.x + dx,
bounds->topLeft.y + dy,winPaint);
grtaps_clear_edges(dx,dy,bounds);
oldx=x;oldy=y;
}
} while(penDown);
graph_unsetcolor();
xmin = graph_xscr2gr((bounds->topLeft.x)-(x-begx));
ymin = graph_yscr2gr((bounds->topLeft.y+bounds->extent.y-1)-(y-begy));
if (!RctPtInRectangle(x,y,bounds)
|| (graphPrefs.logx && xmin <= 0.0)
|| (graphPrefs.logy && ymin <= 0.0)) {
/* Restore original plot from offscreen window if possible,
otherwise force a redraw by setting moved to true */
if (orgwindow) {
clie_copyrectangle(orgwindow,NULL,&orgbounds,bounds->topLeft.x,
bounds->topLeft.y,winPaint);
moved = false;
}
else {
moved = true;
}
}
else {
graphPrefs.xmax=graph_xscr2gr((bounds->topLeft.x+bounds->extent.x-1)-(x-begx));
graphPrefs.ymax=graph_yscr2gr((bounds->topLeft.y)-(y-begy));
graphPrefs.xmin = xmin;
graphPrefs.ymin = ymin;
moved = true;
}
clie_setclip(&rs);
if (orgwindow)
WinDeleteWindow(orgwindow,false);
return moved;
}
/***********************************************************************
*
* FUNCTION: grtaps_zoom_in
*
* DESCRIPTION: Fetch pen moves, draw a rectangle on the screen
* according to pen moves and zoom in, if the user
* lift the pen within bounds
*
* PARAMETERS: begx,begy - first tap, one of the corners
* bounds - bounds of drawing area
*
* RETURN: true - zoom ok
* false - did not zoom
*
***********************************************************************/
static Boolean
grtaps_zoom_in(Coord begx,Coord begy,RectangleType *bounds) GRAPH;
static Boolean
grtaps_zoom_in(Coord begx,Coord begy,RectangleType *bounds)
{
Boolean penDown;
Coord x,y;
Coord oldx=-1,oldy=-1;
double tmp;
do {
EvtGetPenNat(&x, &y, &penDown);
if ((oldx != x || oldy != y) && RctPtInRectangle(x, y, bounds)) {
grtaps_rectangle(begx, begy, x, y);
grtaps_rectangle(begx, begy, oldx, oldy);
oldx = x; oldy = y;
}
} while(penDown);
/* Remove the rectangle from screen */
grtaps_rectangle(begx, begy, oldx, oldy);
if (!RctPtInRectangle(x,y,bounds)) {
/* User wanted to cancel the zoom */
return false;
}
if (oldx==begx || oldy==begy)
return false;
if (begx > oldx) {
tmp = begx; begx = oldx; oldx = tmp;
}
/* The Y axis is inversed on the screen */
if (begy < oldy) {
tmp = begy; begy = oldy; oldy = tmp;
}
/* begx - Left corner of the box, oldx - right */
/* begy - bottom corner, oldy - top corner */
graphPrefs.xmax=graph_xscr2gr(oldx);
graphPrefs.xmin=graph_xscr2gr(begx);
graphPrefs.ymax=graph_yscr2gr(oldy);
graphPrefs.ymin=graph_yscr2gr(begy);
return true;
}
/***********************************************************************
*
* FUNCTION: grtaps_track_but
*
* DESCRIPTION: The handler for the 'T' button, popups a list of
* functions, that can be tracked
*
* PARAMETERS: Nothing
*
* RETURN: true - user selected the func, tracking should begin
* false - user canceled operation
*
***********************************************************************/
Boolean
grtaps_track_but(void)
{
ListPtr list;
char *descr[MAX_GRFUNCS];
Int16 nums[MAX_GRFUNCS];
Int16 count,i;
count = grsetup_fn_descr_arr(descr,nums);
if (count==0)
return false;
list = GetObjectPtr(graphTrackList);
LstSetListChoices(list,descr,count);
LstSetHeight(list,count);
for (i=0;i<count;i++)
if (nums[i] == trackSelected)
break;
if (i == count)
i = noListSelection;
LstSetSelection(list,i);
i = LstPopupList(list);
if (i == noListSelection)
return false;
trackSelected = nums[i];
return true;
}
/***********************************************************************
*
* FUNCTION: grtaps_cross
*
* DESCRIPTION: Draw a tracking cross on the screen
*
* PARAMETERS: x,y - coordinates of the center of cross
* bounds - bounds of drawing area
*
* RETURN: Nothing
*
***********************************************************************/
static void
grtaps_cross(Int16 x,Int16 y,RectangleType *bounds) GRAPH;
static void
grtaps_cross(Int16 x,Int16 y,RectangleType *bounds)
{
if (x != -1)
clie_invertline(x, bounds->topLeft.y,
x, bounds->topLeft.y + bounds->extent.y - 1);
if (y != -1)
clie_invertline(bounds->topLeft.x, y,
bounds->topLeft.x + bounds->extent.x - 1, y);
}
/***********************************************************************
*
* FUNCTION: grtaps_print_val
*
* DESCRIPTION: Print a specified 'double' on the location, clear
* the location before printing
*
* PARAMETERS: name - text, that should precede the number
* value - number to be drawn
* x,y - coordinates
* xmin,xmax - keep text between xmin and xmax
* align - alignment w.r.t. coordinates
* mode - drawing mode
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_print_val(char *name, double value, Coord x, Coord y, Coord xmin, Coord xmax,
Ttxtalign align, WinDrawOperation mode)
{
char text[MAX_FP_NUMBER+10];
Char *numtxt;
Coord txtwidth;
WinDrawOperation oldmode;
#ifdef SUPPORT_DIA
FntSetFont(HanderaAdjustFont(FntGetFont()));
#endif
StrCopy(text,name);
numtxt = text + StrLen(text);
//if (finite(value)) {
fp_print_g_double(numtxt, value, 4);
txtwidth = FntCharsWidth(text, StrLen(text));
if (align == align_center) {
x -= txtwidth / 2;
}
else if (align == align_right) {
x -= txtwidth;
}
if (x < xmin)
x = xmin;
if ((x + txtwidth) > xmax)
x = xmax - txtwidth;
oldmode = WinSetDrawMode(mode);
WinPaintChars(text, StrLen(text), x, y);
WinSetDrawMode(oldmode);
//}
}
/***********************************************************************
*
* FUNCTION: grtaps_print_pol, grtaps_print_param, grtaps_print_coords
*
* DESCRIPTION: Prints r & angle or x & y respectively on
* given places of the screen
*
* PARAMETERS: r,angle,x,y - values
* bounds - bounds of drawing area
*
* RETURN: Nothing
*
***********************************************************************/
static void
grtaps_print_pol(double r, double angle,RectangleType *bounds) GRAPH;
static void
grtaps_print_pol(double r, double angle,RectangleType *bounds)
{
Coord dx1 = HanderaCoord(1);
Coord dy = HanderaCoord(11);
if (graphPrefs.grEnable[8])
dy += HanderaCoord(7);
grtaps_print_val("r:", r, bounds->topLeft.x + dx1,
bounds->topLeft.y + bounds->extent.y - dy,
bounds->topLeft.x,
bounds->topLeft.x + bounds->extent.x,
align_left, winInvert);
grtaps_print_val("fi:", angle, bounds->topLeft.x + bounds->extent.x,
bounds->topLeft.y + bounds->extent.y - dy,
bounds->topLeft.x,
bounds->topLeft.x + bounds->extent.x,
align_right, winInvert);
}
static void
grtaps_print_param(double t,RectangleType *bounds) GRAPH;
static void
grtaps_print_param(double t,RectangleType *bounds)
{
Coord dx1 = HanderaCoord(1), dy = HanderaCoord(11);
if (graphPrefs.grEnable[8])
dy += HanderaCoord(7);
grtaps_print_val("T:", t, bounds->topLeft.x + dx1,
bounds->topLeft.y + bounds->extent.y - dy,
bounds->topLeft.x,
bounds->topLeft.x + bounds->extent.x,
align_left, winInvert);
}
static void
grtaps_print_coords(double realx, double realy,RectangleType *bounds) GRAPH;
static void
grtaps_print_coords(double realx, double realy,RectangleType *bounds)
{
Coord dx1 = HanderaCoord(1);
Coord dy7 = HanderaCoord(7);
Coord y;
y = bounds->topLeft.y;
if (graphPrefs.grEnable[8])
y += dy7;
grtaps_print_val("x:", realx, bounds->topLeft.x + dx1, y,
bounds->topLeft.x,
bounds->topLeft.x + bounds->extent.x,
align_left, winInvert);
grtaps_print_val("y:", realy, bounds->topLeft.x + bounds->extent.x, y,
bounds->topLeft.x,
bounds->topLeft.x + bounds->extent.x,
align_right, winInvert);
}
/***********************************************************************
*
* FUNCTION: grtaps_track_manual
*
* DESCRIPTION: manually (not by pen-tap) set the tracking cross
*
* PARAMETERS: value - value to which set the cross
* action - track_reset - the screen was redrawn,
* reset the coordinates so
* the next track will not clear
* the lastly drawn cross
* track_set - set a cross to a value and
* draw it
* track_add - moves a cross by value
* track_redraw - redraws cross and labels after
* screen resize
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_track_manual(double value, TtrackAction action)
{
double realx, realy, r;
RectangleType natbounds;
RectangleType stdbounds;
if (graphPrefs.functype == graph_polar) {
value = math_user_to_rad(value);
}
if (action == track_reset) {
lastParam = value;
crossX = crossY = -1;
oldr = oldangle = oldparam = oldrealx = oldrealy = NaN;
return;
}
else {
FontID oldfont;
#ifdef SONY_SDK
if (gHrMode == hrSony)
oldfont = HRFntSetFont(gHrLibRefNum, hrStdFont+BOLDRES);
else
#endif
oldfont = FntSetFont(HanderaAdjustFont(stdFont+BOLDRES));
gadget_bounds(FrmGetActiveForm(), graphGadget, &natbounds, &stdbounds);
if (action == track_set)
lastParam = value;
else if (action == track_add)
lastParam += value;
if (action != track_redraw) {
/* Erase previously drawn cross + text */
grtaps_cross(crossX, crossY, &natbounds);
grtaps_print_coords(oldrealx, oldrealy, &stdbounds);
if (graphPrefs.functype == graph_param)
grtaps_print_param(oldparam, &stdbounds);
else if (graphPrefs.functype == graph_polar)
grtaps_print_pol(oldr, oldangle, &stdbounds);
}
graph_get_vals(trackSelected, lastParam, &realx, &realy);
crossX = finite(realx) ? graph_xgr2scr(realx) : -1;
crossY = finite(realy) ? graph_ygr2scr(realy) : -1;
if (crossX < natbounds.topLeft.x
|| crossX > natbounds.topLeft.x + natbounds.extent.x)
crossX = -1;
if (crossY < natbounds.topLeft.y
|| crossY > natbounds.topLeft.y + natbounds.extent.y)
crossY = -1;
grtaps_cross(crossX, crossY, &natbounds);
grtaps_print_coords(realx, realy, &stdbounds);
oldrealx = realx; oldrealy = realy;
if (graphPrefs.functype == graph_param) {
grtaps_print_param(lastParam, &stdbounds);
oldparam = lastParam;
}
else if (graphPrefs.functype == graph_polar) {
// func_get_value(graphCurves[trackSelected].stack1,
// lastParam,&r,NULL);
r = sqrt(realx * realx + realy * realy);
grtaps_print_pol(r, math_rad_to_user(lastParam), &stdbounds);
oldr = r;
oldangle = math_rad_to_user(lastParam);
}
#ifdef SONY_SDK
if(gHrMode == hrSony)
HRFntSetFont(gHrLibRefNum, oldfont);
else
#endif
FntSetFont(oldfont);
}
}
/***********************************************************************
*
* FUNCTION: grtaps_track_pol
*
* DESCRIPTION: Tracking of a polar graph
*
* PARAMETERS: x,y - first tap
* bounds
*
* RETURN: true - user lifted pen within bounds
* false - outside bounds
*
***********************************************************************/
static Boolean
grtaps_track_pol(Coord x, Coord y,
RectangleType *natbounds, RectangleType *stdbounds) GRAPH;
static Boolean
grtaps_track_pol(Coord x, Coord y,
RectangleType *natbounds, RectangleType *stdbounds)
{
double realx, realy;
double r;
double angle_rad; /* angle in radians */
double angle_usr; /* angle in user units: rad/deg/grad */
Coord oldx, oldy, dx, dy;
CodeStack *stack;
Boolean penDown;
stack = graphCurves[trackSelected].stack1;
if (!stack)
return false;
oldx = oldy = -1;
realx = realy = r = angle_rad = angle_usr = NaN;
do {
EvtGetPenNat(&x, &y, &penDown);
if ((oldx != x || oldy != y) && RctPtInRectangle(x, y, natbounds)) {
realx = graph_xscr2gr(x);
realy = graph_yscr2gr(y);
angle_rad = angle_usr = NaN;
r = hypot(realx, realy);
if (r != 0.0) {
if (realx >= 0.0 && realy >= 0.0)
angle_rad = asin(realy / r);
else if (realx <= 0.0)
angle_rad = M_PIl - asin(realy / r);
else
angle_rad = 2 * M_PIl + asin(realy / r);
angle_usr = math_rad_to_user(angle_rad);
func_get_value(stack, angle_usr, &r, NULL);
realx = r * cos(angle_rad);
realy = r * sin(angle_rad);
dx = graph_xgr2scr(realx);
dy = graph_ygr2scr(realy);
if (!finite(angle_rad) || !RctPtInRectangle(dx, dy, natbounds)) {
dy = -1;
dx = -1;
}
}
else {
dx = dy = -1;
realx = realy = NaN;
}
grtaps_cross(dx, dy, natbounds);
grtaps_cross(crossX, crossY, natbounds);
grtaps_print_coords(oldrealx, oldrealy, stdbounds);
grtaps_print_coords(realx, realy, stdbounds);
grtaps_print_pol(oldr, oldangle, stdbounds);
grtaps_print_pol(r, angle_usr, stdbounds);
oldx = x; oldy = y;
crossX = dx; crossY = dy;
oldrealx = realx; oldrealy = realy;
oldr = r; oldangle = angle_usr;
}
} while(penDown);
if (RctPtInRectangle(x, y, natbounds)) {
lastParam = angle_rad;
return true;
}
else
return false;
}
/***********************************************************************
*
* FUNCTION: grtaps_track_param
*
* DESCRIPTION: Tracking of a parametric graph
*
* PARAMETERS: x,y - first tap
* bounds
*
* RETURN: true - user lifted pen within bounds
* false - outside bounds
*
***********************************************************************/
static Boolean
grtaps_track_param(Coord x, Coord y,
RectangleType *natbounds, RectangleType *stdbounds) GRAPH;
static Boolean
grtaps_track_param(Coord x, Coord y,
RectangleType *natbounds, RectangleType *stdbounds)
{
double realx, realy;
double param;
Coord oldx, oldy, dx, dy;
CodeStack *stack1, *stack2;
double x2param;
Boolean penDown;
stack1 = graphCurves[trackSelected].stack1;
stack2 = graphCurves[trackSelected].stack2;
if (!stack1 || !stack2)
return false;
oldx = oldy = -1;
realx = realy = param = NaN;
x2param = (graphPrefs.tmax - graphPrefs.tmin) / (double)natbounds->extent.x;
do {
EvtGetPenNat(&x, &y, &penDown);
if (oldx != x && RctPtInRectangle(x, y, natbounds)) {
param = (double)(x - natbounds->topLeft.x) * x2param;
param = graphPrefs.tmin
+ round(param / graphPrefs.tstep) * graphPrefs.tstep;
if (finite(param)) {
func_get_value(stack1, param, &realx, NULL);
func_get_value(stack2, param, &realy, NULL);
dx = graph_xgr2scr(realx);
dy = graph_ygr2scr(realy);
if (dx < natbounds->topLeft.x ||
dx > natbounds->topLeft.x + natbounds->extent.x)
dx = -1;
if (dy < natbounds->topLeft.y ||
dy > natbounds->topLeft.y + natbounds->extent.y)
dy = -1;
}
else {
dx = dy = -1;
realx = realy = NaN;
}
grtaps_cross(dx, dy, natbounds);
grtaps_cross(crossX, crossY, natbounds);
grtaps_print_coords(oldrealx, oldrealy, stdbounds);
grtaps_print_coords(realx, realy, stdbounds);
grtaps_print_param(oldparam, stdbounds);
grtaps_print_param(param, stdbounds);
oldx = x; oldy = y;
crossX = dx; crossY = dy;
oldrealx = realx; oldrealy = realy;
oldparam = param;
}
} while (penDown);
if (RctPtInRectangle(x, y, natbounds)) {
lastParam = param;
return true;
}
else
return false;
}
/***********************************************************************
*
* FUNCTION: grtaps_track_func
*
* DESCRIPTION: Tracking of a normal function
*
* PARAMETERS: x,y - first tap
* bounds
*
* RETURN: true/false - user lifted inside/outside of bounds
*
***********************************************************************/
static Boolean
grtaps_track_func(Coord x, Coord y,
RectangleType *natbounds, RectangleType *stdbounds) GRAPH;
static Boolean
grtaps_track_func(Coord x,Coord y,
RectangleType *natbounds, RectangleType *stdbounds)
{
double realx, realy;
CodeStack *stack;
Boolean penDown;
stack = graphCurves[trackSelected].stack1;
if (!stack)
return false;
realx = realy = NaN;
do {
EvtGetPenNat(&x, &y, &penDown);
if (crossX != x && RctPtInRectangle(x, y, natbounds)) {
realx = graph_xscr2gr(x);
func_get_value(stack, realx, &realy, NULL);
y = graph_ygr2scr(realy);
if (!finite(realy) || !RctPtInRectangle(x, y, natbounds))
y = -1;
grtaps_cross(x, y, natbounds);
grtaps_cross(crossX, crossY, natbounds);
grtaps_print_coords(oldrealx, oldrealy, stdbounds);
grtaps_print_coords(realx, realy, stdbounds);
crossX = x; crossY = y;
oldrealx = realx; oldrealy = realy;
}
} while(penDown);
if (RctPtInRectangle(x, y, natbounds)) {
lastParam = realx;
return true;
}
else
return false;
}
/***********************************************************************
*
* FUNCTION: grtaps_tap
*
* DESCRIPTION: Generic handler started when user taps on the drawing
* gadget.
*
* PARAMETERS: x,y - coords, where user tapped
*
* RETURN: true - handled, user tapped inside gadget
* false - should be handled by somone else
*
***********************************************************************/
Boolean
grtaps_tap(Int16 x,Int16 y)
{
RectangleType natbounds;
RectangleType stdbounds;
if (gHrMode == hrPalm) {
UInt16 save = WinSetCoordinateSystem(kCoordinatesNative);
x = WinScaleCoord(x, true);
y = WinScaleCoord(y, true);
WinSetCoordinateSystem(save);
}
else {
x *= gSonyFactor; y *= gSonyFactor;
}
gadget_bounds(FrmGetActiveForm(), graphGadget, &natbounds, &stdbounds);
if (RctPtInRectangle(x, y, &natbounds)) {
/* Is zoom-in checked? */
if (CtlGetValue(GetObjectPtr(btnGraphZoomIn))) {
if (grtaps_zoom_in(x, y, &natbounds)) {
CtlSetValue(GetObjectPtr(btnGraphZoomIn), 0);
FrmUpdateForm(frmGraph, frmUpdateVars);
}
}
/* Is tracking checked? */
else if (CtlGetValue(GetObjectPtr(btnGraphTrack))) {
FontID oldfont;
#ifdef SONY_SDK
if (gHrMode == hrSony)
oldfont = HRFntSetFont(gHrLibRefNum, hrStdFont+BOLDRES);
else
#endif
oldfont = FntSetFont(HanderaAdjustFont(stdFont+BOLDRES));
if (graphPrefs.functype == graph_func)
grtaps_track_func(x, y, &natbounds, &stdbounds);
else if (graphPrefs.functype == graph_polar)
grtaps_track_pol(x, y, &natbounds, &stdbounds);
else if (graphPrefs.functype == graph_param)
grtaps_track_param(x, y, &natbounds, &stdbounds);
#ifdef SONY_SDK
if(gHrMode == hrSony)
HRFntSetFont(gHrLibRefNum, oldfont);
else
#endif
FntSetFont(oldfont);
}
else /* Move the graph */
if (grtaps_move(x, y, &natbounds))
FrmUpdateForm(frmGraph, frmUpdateVars);
return true;
}
return false;
}
/***********************************************************************
*
* FUNCTION: grtaps_start
*
* DESCRIPTION: Start tracking a function, show a cross
*
* PARAMETERS: Nothing
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_track_start(void)
{
FormPtr frm = FrmGetActiveForm();
grtaps_track_manual(0, track_redraw);
FrmShowObject(frm, FrmGetObjectIndex(frm, btnGraphTrackGoto));
}
/***********************************************************************
*
* FUNCTION: grtaps_track_pause
*
* DESCRIPTION: Pause tracking, although the cross is still displayed
*
* PARAMETERS: Nothing
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_track_pause(void)
{
FormPtr frm = FrmGetActiveForm();
CtlSetValue(GetObjectPtr(btnGraphTrack), false);
FrmHideObject(frm, FrmGetObjectIndex(frm, btnGraphTrackGoto));
}
/***********************************************************************
*
* FUNCTION: grtaps_track_reset
*
* DESCRIPTION: There was probably a forced screen redraw, reset internal
* tracking variables and stop tracking
*
* PARAMETERS: start - where should the tracking start (where should
* the cross appear when grtaps_track_start() is
* called)
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_track_reset(double start)
{
FormPtr frm = FrmGetActiveForm();
grtaps_track_manual(start, track_reset);
CtlSetValue(GetObjectPtr(btnGraphTrack), false);
FrmHideObject(frm, FrmGetObjectIndex(frm, btnGraphTrackGoto));
}
/***********************************************************************
*
* FUNCTION: grtaps_track_track
*
* DESCRIPTION: Start tracking of a particular function
*
* PARAMETERS: track - index to graphCurves table
*
* RETURN: Nothing
*
***********************************************************************/
void
grtaps_track_track(Int16 track)
{
trackSelected = track;
CtlSetValue(GetObjectPtr(btnGraphTrack), true);
grtaps_track_start();
}
/***********************************************************************
*
* FUNCTION: grtaps_track_last_value
*
* DESCRIPTION: Return the last position of a cross
*
* PARAMETERS: Nothing
*
* RETURN: The parameter value on the last cross position
*
***********************************************************************/
double
grtaps_track_last_value(void)
{
return lastParam;
}
/***********************************************************************
*
* FUNCTION: grtaps_trackSelected
*
* PARAMETERS: Nothing
*
* RETURN: The index of the function selected for tracking
*
***********************************************************************/
Int16
grtaps_trackSelected(void)
{
return trackSelected;
}
--- NEW FILE: grcalc.h ---
/*
* $Id: grcalc.h,v 1.1 2011/02/28 22:08:16 mapibid Exp $
*
* Scientific Calculator for Palms.
* Copyright (C) 2001 Ondrej Palkovsky
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* You can contact me at 'on...@pe...'.
*/
#ifndef _GRCALC_H_
#define _GRCALC_H_
void grcalc_init(void) GRAPH;
Boolean grcalc_control(void) GRAPH;
#endif
--- NEW FILE: grtaps.h ---
/*
* $Id: grtaps.h,v 1.1 2011/02/28 22:08:16 mapibid Exp $
*
* Scientific Calculator for Palms.
* Copyright (C) 1999,2000 Ondrej Palkovsky
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* You can contact me at 'on...@pe...'.
*/
#ifndef _GRTAPS_H_
#define _GRTAPS_H_
typedef enum {
track_reset,
track_add,
track_set,
track_redraw
}TtrackAction;
typedef enum {
align_left,
align_center,
align_right
} Ttxtalign;
Boolean grtaps_tap(Int16 x,Int16 y) GRAPH;
Boolean grtaps_track_but(void) GRAPH;
void grtaps_print_val(char *name, double value,
Coord x, Coord y, Coord xmin, Coord xmax,
Ttxtalign align, WinDrawOperation mode) GRAPH;
void grtaps_track_manual(double value,TtrackAction action) GRAPH;
void grtaps_track_pause(void) GRAPH;
void grtaps_track_start(void) GRAPH;
void grtaps_track_reset(double start) GRAPH;
void grtaps_track_track(Int16 track) GRAPH;
double grtaps_track_last_value(void) GRAPH;
Int16 grtaps_trackSelected(void) GRAPH;
#endif
|