FLTK logo

question about png in fltk1.3

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

question about png in fltk1.3 leowang May 17, 2012  
 
Dear All,
I have a question about draw png image in widget.

I have a widget, I want to put a 50% transparent png file as it's background picture, and the background picture can be changed to another 50% transparent png file, the problem is when I change to another png file, still can see the first png file in the below. If I only want to one png file any time, how to do?

My program is as below:

#include <stdio.h>
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/fl_draw.H>

class MyWindow : public Fl_Window {
    Fl_PNG_Image *left;
    Fl_PNG_Image *right;
    void GetFLTKVersion(char *s) {
        sprintf(s, "FLTK %d.%d.%d", FL_MAJOR_VERSION, FL_MINOR_VERSION, FL_PATCH_VERSION);
    }
public:
    void draw() {
        Fl_Window::draw();                    // Draw window widget first
        fl_font(FL_HELVETICA, 40);            // set font
        fl_color(FL_BLACK);                   // set color
        fl_draw("This is a test", 10, 150);   // draw a text string
        left->draw(0,0);                      // draw left alpha image over the above
        right->draw(0,0);                     // draw right alpha image over the above
    }
    MyWindow(int W, int H) : Fl_Window(W,H) {
        char s[80]; GetFLTKVersion(s); copy_label(s);
        left  = new Fl_PNG_Image("./1.png");        // assumes images in cwd
        right = new Fl_PNG_Image("./2.png");       // assumes images in cwd
        show();
    }
};
int main() {
    fl_register_images();
    Fl::scheme("plastic");
    MyWindow win(300,300);
    win.show();
    return(Fl::run());
}

in the above test, the 1.png and 2.png has same size, and both are 50% transparent, but I can see 1.png and 2.png at the same time, I only want the 2.png overwrite the 1.png, how to do?

Best regards,
Leo
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.