Well, just or "fun" I threw together a hack of Jens program that
stores the "ASIC cells" in a separate list, not as fltk widgets, then
scales and renders them only in the draw method.
This isn't a very clever bit of code, but it does show the alternate
approach I had in mind.
Unfortunately, it doesn't seem much (if any) quicker... I also tried
replacing the std:vector with a simple list array, but that didn't
seem to help much either.
I've not done scrolling or click selection, since this approach
didn't seem to be going anywhere.
Still, I'll post the code below for completeness sake. It's likely
the code is buggy as I just threw it together - there may also be
some easy trick I've missed!
Cheers,
--
Ian
--------------------------------------------------------
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
//#include <FL/Fl_Scroll.H>
#include <FL/Fl_Button.H>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE (32768) // zoom limit is ok for the moment
using namespace std;
static Fl_Double_Window *win;
//static Fl_Scroll *scroll;
const int diex = 9408000;
const int diey = 9408000; // real world chip size
static int gzoom = 1;
const int zoom_factor = 2;
class Cell {
public:
int x, y, w, h, xm, ym;
int c_;
Cell(int x0, int y0, int w0, int h0)
{
x = x0; y = y0; w = w0; h = h0;
xm = x + w; ym = y + h;
c_ = FL_WHITE;
}
};
//vector <Cell*> draw_Vector;
static Cell **cell_list;
static int last_cell = 0;
/
************************************************************************
/
class cell_box : public Fl_Box
{
protected:
void draw(void);
public:
cell_box(int X, int Y, int W, int H, const char *L=0) : Fl_Box
(X,Y,W,H,L) { }
};
/
************************************************************************
/
void cell_box::draw(void)
{
Cell * cp;
// how big is the viewable scene in world pixels?
int view_x = diex / gzoom;
int view_y = diey / gzoom;
int vx2 = view_x / 2;
int vy2 = view_y / 2;
// how big is our actual viewport?
int wo = w();
int ho = h();
double xscale = (double)view_x / (double)wo;
// double yscale = (double)view_y / (double)ho;
// what are the limits of the viewable area?
int min_x = diex / 2 - vx2;
int max_x = diex / 2 + vx2;
int min_y = diey / 2 - vy2;
int max_y = diey / 2 + vy2;
// ensure the view area is clipped and cleared
fl_push_clip(x(), y(), wo, ho);
fl_color(FL_RED);
fl_rectf(x(), y(), wo, ho);
// which cells are visible?
// for(unsigned int i = 0; i < draw_Vector.size(); i++)
for(unsigned int i = 0; i < last_cell; i++)
{
// cp = draw_Vector.at(i);
cp = cell_list[i];
if(cp->xm < min_x) continue;
if(cp->x > max_x) continue;
if(cp->ym < min_y) continue;
if(cp->y > max_y) continue;
// this cell should be visible, scale and draw it
int xd = (int)((double)(cp->x - min_x) / xscale);
int yd = (int)((double)(cp->y - min_y) / xscale);
int wd = (int)((double)cp->w / xscale);
int hd = (int)((double)cp->h / xscale);
fl_color(cp->c_);
fl_rectf(xd, yd, wd, hd);
fl_color(FL_BLACK);
fl_rect(xd, yd, wd, hd);
}
fl_pop_clip();
} /* end of draw() method */
static cell_box *cell_view;
/
************************************************************************
/
static void zoomincb(Fl_Widget *, void *)
{
gzoom = gzoom * zoom_factor;
if(gzoom > MAXSIZE) gzoom = MAXSIZE;
cell_view->redraw();
}
static void zoomoutcb(Fl_Widget *, void *)
{
gzoom = gzoom / zoom_factor;
if(gzoom < 1) gzoom = 1;
cell_view->redraw();
}
////////////////////////
int main()
{
int x = 0, y = 0, w = 0, h = 0;
int idx = 0;
cell_list = (Cell**)malloc(2000000 * sizeof(Cell*));
// Make the random list of test cells
for(x = 0; x < diex; x = x+w)
{
w = (1 + (int)(10.0*rand()/(RAND_MAX+1.0))) * diex/6000; //
6000 ~
1.2 Mio components, 600 ~ 11000 components
for(y = 0; y < diey; y = y+h)
{
h = (1 + (int)(10.0*rand()/(RAND_MAX+1.0))) *
diey/6000; // 6000 ~
1.2 Mio components, 600 ~ 11000 components
// draw_Vector.push_back(new Cell(x, y, w, h));
cell_list[idx] = new Cell(x, y, w, h);
idx++;
}
}
last_cell = idx;
// Create the fltk framework
win = new Fl_Double_Window(800, 800);
cell_view = new cell_box(5, 5, win->w()-10, win->h()-60);
Fl_Box box(0,win->h()-50,win->w(),50);
Fl_Button zoomin(0,win->h()-40,100,35,"Zoom in");
zoomin.callback(zoomincb);
Fl_Button zoomout(120,win->h()-40,100,35,"Zoom out");
zoomout.callback(zoomoutcb);
win->end();
win->resizable(cell_view);
win->show();
int res = Fl::run();
free(cell_list);
return res;
}
/* end of file */
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk