Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Geom/PlotterCtrl fixed plot
Re: Geom/PlotterCtrl fixed plot [message #10492 is a reply to message #10490] Thu, 12 July 2007 10:29 Go to previous message
pap2k is currently offline  pap2k
Messages: 8
Registered: June 2007
Promising Member
Here it is a simple math draw sample :
#ifndef _Math_Math_h
#define _Math_Math_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Math/Math.lay>
#include <CtrlCore/lay.h>


#include <CtrlLib/CtrlLib.h>
#include <Geom/Ctrl/GeomCtrl.h>
#include <sstream>

struct MahtPlot : public PlotterCtrl
{

struct draw_point_pos
{
draw_point_pos( Plotter* _plotter) : plotter_(_plotter) {}
void operator()(const Pointf& _p)
{
//std::ostringstream msg;
//msg << "(" << _p.x <<"; "<< _p.y << ")";
//plotter_->GetDraw().DrawText( plotter_->LtoP(_p).x, plotter_->LtoP(_p).y, msg.str().c_str());
plotter_->GetDraw().DrawEllipse(plotter_->LtoP(_p).x, plotter_->LtoP(_p).y, 2,2);

}
Plotter* plotter_;
};

void Plot(Plotter& plotter)
{
plotter.GetDraw().DrawRect(
Rect(plotter.LtoP(Pointf(left_, top_)),plotter.LtoP(Pointf(rigth_, bottom_))), Yellow());

draw_point_pos point_plot(&plotter);
for(double x = left_; x <= rigth_; x += x_step_)
point_plot(Pointf(x, MathFunc(x)));
}

double MathFunc(const double& _x)
{
return _x*_x;
}

MahtPlot(const double& _left = -10.0,
const double& _top = 10.0,
const double& _rigth = 10.0,
const double& _bottom = -10.0,
const double& _x_step = 0.1) :
left_(_left), top_ (_top), rigth_(_rigth), bottom_(_bottom), x_step_(_x_step)
{
buffer_paint = true;
ShowScroll(false);
Rectf bonding_box(Pointf(left_, top_),Pointf(rigth_, bottom_));
SetExtent(bonding_box);
UserZoom(bonding_box, false);
}

double left_;
double top_ ;
double rigth_;
double bottom_;
double x_step_;
};



class MathGraph : public WithMathGraphLayout<TopWindow> {
public:
typedef MathGraph CLASSNAME;
MathGraph()
{
CtrlLayout(*this, "Window title");
AddFrame(status_);
this->Sizeable();
Add(plot_.SizePos());
}
StatusBar status_;
MahtPlot plot_;
};

#endif

What's wrong whith this simple code ?
(-> why there is no Yellow rectangle on sreen ?)
(-> why the userzoom isn't realy set to -10 -> 10 ?)


Is there somewhere sample of use of PlotterCtrl ?

Thank's in advance.

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to read from and write to a table in a file (CSV)?
Next Topic: Cross Compile UPP for armv5l arch
Goto Forum:
  


Current Time: Tue May 13 23:42:56 CEST 2025

Total time taken to generate the page: 0.02203 seconds