Coffe break: so here's my hack at this suggestion.
Seems to work OK, tested on WinXP with mingw and fltk-1.1.x svn.

-------------------------
// implementation of the generic drag  banner window
/* Standard headers */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

// FLTK headers
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <Fl/fl_draw.H>

/***********************************************************************
******/
class drag_banner : public Fl_Double_Window {
private:
        int x1, y1;     // click posn., used for dragging and docking
checks
        int xoff, yoff; // origin used for dragging calcs
        int scroll_pos; // origin for scrolled text banner
        char *msg;      // banner message
        int len, ht, desc; // banner string dimensions

protected:
        // override handle method to catch drag operations
        int handle(int event);
        void draw(void);

public:
        // basic constructor
        drag_banner(int X, int Y, int W, int H, const char *L = 0);
        // text scroll method
        void do_scroll(void) {scroll_pos -= 1; redraw();};
        // set the banner message
        void set_msg(const char *m);
};
/***********************************************************************
******/
drag_banner::drag_banner(int x, int y, int W, int h, const char *l)
 : Fl_Double_Window(x, y, W, h, l){
        this->box(FL_FLAT_BOX);
        this->color(FL_BACKGROUND_COLOR);
        this->clear_border();
        scroll_pos = W / 2;
        msg = NULL;
} // constructor

int drag_banner::handle(int event) {
        int ret = Fl_Double_Window::handle(event);
        switch (event) {
        case FL_PUSH: // downclick in banner creates cursor offsets
                x1 = Fl::event_x_root();
                y1 = Fl::event_y_root();
                xoff = x() - x1;
                yoff = y() - y1;
                ret = 1;
                break;

        case FL_DRAG: // drag the banner around the screen
                position(xoff + Fl::event_x_root(), yoff +
Fl::event_y_root());
                redraw();
                ret = 1;
                break;

        case FL_RELEASE:
                ret = 1;
                break;

        default:
                break;
        }
        return ret;
} // drag_banner::handle

void drag_banner::draw(void){
        Fl_Double_Window::draw(); // draw the base window
        fl_font(FL_COURIER, 40); // set the font size
        fl_color(FL_BLUE); // set the message colour
        if((scroll_pos + len) < 0) scroll_pos = w();
        fl_draw(msg, scroll_pos, (h() - desc));
} // draw string method

void drag_banner::set_msg(const char *m){
        if(msg) free(msg);
        msg = strdup(m);
        // measure our string
        fl_font(FL_COURIER, 40); // set the font size
        len = ht = 0;
        fl_measure(msg, len, ht, 0);
        desc = fl_descent();
} // set message
/***********************************************************************
******/
drag_banner *banner = NULL;

/***** animation timeout callback ***********/
static void anim_timer(void*) {
        banner->do_scroll();
        Fl::repeat_timeout(0.03, anim_timer);
} // anim_timer

/***********************************************************************
******/
int main(int argc, char **argv) {
        int screen_width = Fl::w();
        int screen_height = Fl::h();

        banner = new drag_banner(0, (screen_height - 50), screen_width,
50);
        banner->set_msg("This is the Banner Message!");
        banner->end();
        banner->show(argc, argv);

        /* Start a timer to run the text scrolling */
        Fl::add_timeout(0.1, anim_timer);
    /* Run the main event loop */
    return Fl::run();
} // main
// end of file

----------------- 





SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to