On Sun, 6 Nov 2022 at 18:03, Damiano Rocchi wrote:
>
> My problem start when I zoom the image, because the position of button inside are changed. I try to reposition the button, but the coordinates and the result change based on the part of image I see. For exaple if i see the upper part of image, the button position will be in the upper part of image. Same thing with lower.
I'm sorry, but I do not understand what effect you are hoping to achieve here.
Given the size of your map image tile, I'd be inclined to render it
once, zoomed large, to an offscreen surface, and then just extract the
specific region I wanted and zoom that down to the required
resolution.
The actual boxes within the scroll would not then have to change size
at all, making the rest of your calculations much simpler.
But, as I said, I am not sure what effect you hope to achieve...
> I post the code for fltk 1.4
>
There are some issues with your code - I will point them out here, in
case any of them are contributing to your difficulties.
>
> #include <stdlib.h>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Box.H>
> #include <FL/Fl_SVG_Image.H>
> #include <FL/fl_message.H>
> #include <Fl/Fl_Scroll.H>
I assume you are on WIndows?
Many of these say "Fl" but they ought to say "FL" - Windows is less
case sensitive so you can get away with that, but it is still wrong...
> #include <Fl/Fl_Multiline_Output.H>
> #include <Fl/Fl_PNG_Image.H>
> #include <FL/fl_ask.H>
> #include <FL/Fl_Tabs.H>
> #include <FL/Fl_Group.H>
> #include <FL/Fl_Button.H>
>
> Fl_SVG_Image *imm_villaggio = new Fl_SVG_Image("villaggio.svg");
Assigning the image types in the declaration is not wrong as such, but
it will affect the order of initialisation, since this will happen
before main() is called, in effect - it is probably better to assign
the images to the image pointers in main rather than in the
declaration.
> double i = 0, l = 0;
By convention, I think most (old!) programmers expect "i" and "l" to
name integer types....!
> int a = 20, b = 2000, c = 5, d = 2, z = 0, x = 0;
> char buffer[200];
>
> class Imm : public Fl_Box{
>
> protected:
>
> int handle( int v )
> {
>
> int ret = Fl_Box::handle(v);
> if( v == FL_PUSH )
> {
>
> fl_alert("Popolazione 3000\nCiviltà 5\nBrutalità 5\nComportamento 0\nCommercio 2\n ");
> return(0);
This should return 1, not 0
>
> }
> else if( v == FL_RELEASE )
> return(0);
This should return 1, not 0
>
>
> return(0);
This should return "ret", not 0
> }
>
> public:
>
> Imm( int X, int Y, int W, int H, const char *L = 0) : Fl_Box(X, Y, W, H, L){
>
> image(imm_villaggio);
> box(FL_NO_BOX);
It seems extremely unlikely this is the correct box type. You probably
want FL_FLAT_BOX here. The NO_BOX type will not be redrawn after
damage, since there *is* no box to draw; that will not be what you
want. The NO_BOX type is for very special cases that I do not think
you want.
>
> }
>
> };
>
> void p_zoom();
> void m_zoom();
>
> Fl_SVG_Image *svg = new Fl_SVG_Image("Mappa.svg");
See comment above about initialisation...
> Fl_Box *box;
> Imm *ins, *insd;
> Fl_Scroll *scroll;
> Fl_Window *win;
> Fl_Tabs *tab;
> Fl_Button *più;
Using accented characters in variable names *still* causes portability
issues, so be aware his might choke on some systems.
> Fl_Button *meno;
>
> int main(int argc, char **argv)
> {
>
> win = new Fl_Window(0, 0, 1440, 880, "Progetto");
> scroll = new Fl_Scroll(0, 120, 1456, 768);
These sizes look wrong - the scroll is larger than the window that
contains it. This is not allowed.
>
> win->begin();
>
> tab = new Fl_Tabs(0, 0, 1440, 120);
>
> Fl_Group generale(20, 30, 1440, 120, "Generale");
This group is too large for the tab that contains it (all the groups
look to be too big for the tab, in fact)
>
> Fl_Button fine_turno(30, 40, 100, 40, "Fine turno");
> più = new Fl_Button(200, 50, 30, 20, "+");
> più->callback( (Fl_Callback *)p_zoom);
> meno = new Fl_Button(200, 80, 30, 20, "-");
> meno->callback( (Fl_Callback *)m_zoom);
>
> generale.end();
>
> Fl_Group reclutamento(20, 30, 1440, 120, "Reclutamento");
>
>
> reclutamento.end();
>
> Fl_Group personale(20, 30, 1440, 120, "Personale");
>
>
> personale.end();
>
> Fl_Group missione(20, 30, 1440, 120, "Missione");
>
>
>
> missione.end();
>
> Fl_Group diplomazia(20, 30, 1440, 120, "Diplomazia");
>
> diplomazia.end();
>
>
> tab->end();
>
> tab->clear_visible_focus();
I do not think that clear_visible_focus() does what you think that it does.
What *do* you think that setting / clearing the visible focus is
doing? You do it a lot in the callbacks, but...
>
>
>
>
> scroll->begin();
>
> box = new Fl_Box(120, 60, 3500, 3500 );
> ins = new Imm(1127, 2860, 50, 50);
It seems unlikely these are the correct coordinates - these two
widgets will overlap, which will not behave as intended.
> //insd = new Imm(0, 3500, 50, 50);
>
> scroll->end();
>
> win->end();
>
>
> box->image(svg);
> box->set_visible_focus();
> win->resizable(box);
> sprintf(buffer, "Giocatore\n\nZona %d\nAbitanti %d\nCiviltà %d\nBrutalità %d\nCommercio %d", a, b, c, c, d);
>
> win->show();
> return(Fl::run());
>
> }
>
> /* zoom + ( not tested ) */
> void p_zoom()
> {
>
> i = box->h();
> i = i / 100;
> i = i * 120;
> box->size( i, i );
> svg->resize(i, i);
> l = i;
> i = (1127 * i)/3500;
> l = (2860 * l)/3500;
> l = l * 81.714285714;
> Imm ins(i, l, 50, 50);
This looks like an error: This is an extra declaration of "ins" that
will shadow the original global declaration above, this is certainly
not what you want. It also means that the "ins" seen in the "m_zoom"
callback is a different widget, since it will still be seeing the
original global version of "ins" not this shadow declaration.
> box->image(svg);
> box->redraw();
> i = 0;
> l = 0;
> più->clear_visible_focus();
> box->set_visible_focus();
>
> }
>
> /* zoom - */
> void m_zoom()
> {
>
> i = box->h();
> i = i / 100;
> i = i * 80;
> box->size( i, i );
> svg->resize(i, i);
> i = ins->x();
> l = ins->y();
> i = i / 100;
> i = i * 80;
> l = l / -6.8;
> z = i;
> x = l;
>
> box->image(svg);
> box->redraw();
>
> scroll->begin();
>
> ins->position(z, x);
At this point the global instance of "ins" may not be allocated the
way you expect, due to the shadow declaration in "p_zoom" above.