// tilewin.cpp -- the tile import window // // Written by Frederic Bouvier, started April 2002. // // Copyright (C) 2002 Frederic Bouvier - fredb@users.sourceforge.net // // 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., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: tilewin.cpp,v 1.11 2005/05/09 07:02:16 fredb Exp $ #include "tilewin.hpp" #include #include #include #include "sdutil.hpp" FGSD_TileWindow::FGSD_TileWindow( double __minx, double __miny, double __maxx, double __maxy ) : _minBucket( __minx, __miny ) , _maxBucket( __maxx, __maxy ) { int dx = 0, dy = 0; if ( _maxBucket.get_chunk_lon() + _maxBucket.get_x() * _maxBucket.get_width() == __maxx ) dx = 1; if ( _maxBucket.get_chunk_lat() + _maxBucket.get_y() * _maxBucket.get_height() == __maxy ) dy = 1; if ( dx || dy ) _maxBucket.set_bucket( _maxBucket.get_chunk_lon() + ( _maxBucket.get_x() - dx ) * _maxBucket.get_width(), _maxBucket.get_chunk_lat() + ( _maxBucket.get_y() - dy ) * _maxBucket.get_height() ); _window = new FGSD_Window( 600, 300, "Import scenery tiles..." ); _window->begin(); new Fl_Box( FL_BORDER_BOX, 120, 60, 360, 140, 0 ); _top = new Fl_Input( 240, 45, 120, 30, "North" ); _top->align( FL_ALIGN_TOP ); _topUp = new Fl_Button( 360, 45, 30, 30, "@8>" ); _topUp->labeltype( FL_SYMBOL_LABEL ); _topUp->callback( FGSD_TileWindow::topUp_cb, this ); _topDown = new Fl_Button( 210, 45, 30, 30, "@2>" ); _topDown->labeltype( FL_SYMBOL_LABEL ); _topDown->callback( FGSD_TileWindow::topDown_cb, this ); std::string val = FGSD_Util::positionToString( _maxBucket.get_chunk_lat() + ( _maxBucket.get_y() + 1 ) * _maxBucket.get_height(), false ); _top->value( val.c_str() ); _left = new Fl_Input( 60, 115, 120, 30, "West" ); _left->align( FL_ALIGN_TOP | FL_ALIGN_LEFT ); _leftUp = new Fl_Button( 180, 115, 30, 30, "@>" ); _leftUp->labeltype( FL_SYMBOL_LABEL ); _leftUp->callback( FGSD_TileWindow::leftUp_cb, this ); _leftDown = new Fl_Button( 30, 115, 30, 30, "@<" ); _leftDown->labeltype( FL_SYMBOL_LABEL ); _leftDown->callback( FGSD_TileWindow::leftDown_cb, this ); val = FGSD_Util::positionToString( _minBucket.get_chunk_lon() + _minBucket.get_x() * _minBucket.get_width(), true ); _left->value( val.c_str() ); _right = new Fl_Input( 420, 115, 120, 30, "East" ); _right->align( FL_ALIGN_TOP | FL_ALIGN_RIGHT ); _rightUp = new Fl_Button( 540, 115, 30, 30, "@>" ); _rightUp->labeltype( FL_SYMBOL_LABEL ); _rightUp->callback( FGSD_TileWindow::rightUp_cb, this ); _rightDown = new Fl_Button( 390, 115, 30, 30, "@<" ); _rightDown->labeltype( FL_SYMBOL_LABEL ); _rightDown->callback( FGSD_TileWindow::rightDown_cb, this ); val = FGSD_Util::positionToString( _maxBucket.get_chunk_lon() + ( _maxBucket.get_x() + 1 ) * _maxBucket.get_width(), true ); _right->value( val.c_str() ); _bottom = new Fl_Input( 240, 185, 120, 30, "South" ); _bottom->align( FL_ALIGN_TOP ); _bottomUp = new Fl_Button( 360, 185, 30, 30, "@8>" ); _bottomUp->labeltype( FL_SYMBOL_LABEL ); _bottomUp->callback( FGSD_TileWindow::bottomUp_cb, this ); _bottomDown = new Fl_Button( 210, 185, 30, 30, "@2>" ); _bottomDown->labeltype( FL_SYMBOL_LABEL ); _bottomDown->callback( FGSD_TileWindow::bottomDown_cb, this ); val = FGSD_Util::positionToString( _minBucket.get_chunk_lat() + _minBucket.get_y() * _minBucket.get_height(), false ); _bottom->value( val.c_str() ); _ok = new Fl_Button( 10, 260, 40, 30, "Ok" ); _ok->callback( FGSD_TileWindow::ok_cb, this ); _cancel = new Fl_Button( 60, 260, 60, 30, "Cancel" ); _cancel->callback( FGSD_TileWindow::cancel_cb, this ); _window->end(); } FGSD_TileWindow::~FGSD_TileWindow() { delete _window; } void FGSD_TileWindow::topUp_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_top; Fl_Input *o = ((FGSD_TileWindow *)v)->_right; ((FGSD_TileWindow *)v)->button_cb( b, true, true, false, o ); } void FGSD_TileWindow::topDown_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_top; Fl_Input *o = ((FGSD_TileWindow *)v)->_right; ((FGSD_TileWindow *)v)->button_cb( b, false, true, false, o ); } void FGSD_TileWindow::leftUp_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_left; Fl_Input *o = ((FGSD_TileWindow *)v)->_bottom; ((FGSD_TileWindow *)v)->button_cb( b, true, false, true, o ); } void FGSD_TileWindow::leftDown_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_left; Fl_Input *o = ((FGSD_TileWindow *)v)->_bottom; ((FGSD_TileWindow *)v)->button_cb( b, false, false, true, o ); } void FGSD_TileWindow::rightUp_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_right; Fl_Input *o = ((FGSD_TileWindow *)v)->_top; ((FGSD_TileWindow *)v)->button_cb( b, true, true, true, o ); } void FGSD_TileWindow::rightDown_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_right; Fl_Input *o = ((FGSD_TileWindow *)v)->_top; ((FGSD_TileWindow *)v)->button_cb( b, false, true, true, o ); } void FGSD_TileWindow::bottomUp_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_bottom; Fl_Input *o = ((FGSD_TileWindow *)v)->_left; ((FGSD_TileWindow *)v)->button_cb( b, true, false, false, o ); } void FGSD_TileWindow::bottomDown_cb(Fl_Widget *, void *v) { Fl_Input *b = ((FGSD_TileWindow *)v)->_bottom; Fl_Input *o = ((FGSD_TileWindow *)v)->_left; ((FGSD_TileWindow *)v)->button_cb( b, false, false, false, o ); } void FGSD_TileWindow::button_cb( Fl_Input *b, bool up, bool __max, bool __lon, Fl_Input *o ) { std::string val = b->value(); bool error; double pos = FGSD_Util::parsePosition( val.c_str(), error ); if ( !error ) { if ( __max && __lon ) { } else if ( __max && !__lon ) { } else if ( !__max && __lon ) { } else { } val = o->value(); double pos2 = FGSD_Util::parsePosition( val.c_str(), error ); if ( !error ) { SGBucket bucket; if ( __lon ) bucket.set_bucket( pos, pos2 ); else bucket.set_bucket( pos2, pos ); if ( up && __lon ) pos = bucket.get_chunk_lon() + ( bucket.get_x() + 1 ) * bucket.get_width(); else if ( up && !__lon ) pos = bucket.get_chunk_lat() + ( bucket.get_y() + 1 ) * bucket.get_height(); else if ( !up && __lon ) pos = bucket.get_chunk_lon() + ( bucket.get_x() - 1 ) * bucket.get_width(); else pos = bucket.get_chunk_lat() + ( bucket.get_y() - 1 ) * bucket.get_height(); val = FGSD_Util::positionToString( pos, __lon ); b->value( val.c_str() ); } else { } } else { } } void FGSD_TileWindow::ok_cb( Fl_Widget *o, void *v ) { ((FGSD_TileWindow *)v)->button_cb( true ); } void FGSD_TileWindow::cancel_cb( Fl_Widget *o, void *v ) { ((FGSD_TileWindow *)v)->button_cb( false ); } void FGSD_TileWindow::button_cb( bool __ok ) { if ( __ok ) { bool error; double minx, miny, maxx, maxy; minx = FGSD_Util::parsePosition( _left->value(), error ); if ( !error ) miny = FGSD_Util::parsePosition( _bottom->value(), error ); if ( !error ) maxx = FGSD_Util::parsePosition( _right->value(), error ); if ( !error ) maxy = FGSD_Util::parsePosition( _top->value(), error ); if ( !error ) { _minBucket.set_bucket( minx, miny ); SGBucket b( maxx, maxy ); _maxBucket.set_bucket( b.get_chunk_lon() + ( b.get_x() - 1 ) * b.get_width(), b.get_chunk_lat() + ( b.get_y() - 1 ) * b.get_height() ); _window->set_value(); } else _window->clear_value(); } else _window->clear_value(); _window->hide(); }