Course list http://www.c-jump.com/bcc/

Lab 6: Fl_Box, Fl_Image, Fl_JPEG_Image


  1. Description
  2. Copying Visual Studio Project
  3. Adding widgets in FLUID
  4. Adding button callback function
  5. How to submit

Description



Copying Visual Studio Project



Adding widgets in FLUID



Adding button callback function


  1. Open solution

    
        c255labs\labs\c255_lab06_jpeg\c255_lab06.sln
    
    

    in Visual Studio.

  2. Open CMainWindow.h in text editor. Add NEW callback code as shown:

    
    // CMainWindow.h
    
    #ifndef _CMAINWINDOW_H_INCLUDED_
    #define _CMAINWINDOW_H_INCLUDED_
    
    #include "../fluid_project/CFluidWindow.h"
    
    // NEW
    #include <FL/Fl_Shared_Image.H>
    #include <FL/Fl_JPEG_Image.H>
    
    class CMainWindow : public CFluidWindow {
        Fl_Image* jpeg_image;       // NEW
    public:
        CMainWindow();              // NEW
    
        void show();
        void click_btn_show_jpeg(); // NEW
    
        // callback functions
        static void callback_window_closing(Fl_Widget* widg, void* userdata_);
    
        // NEW
        static void callback_btn_show_jpeg(Fl_Widget* widg, void* userdata_);
    };//class CMainWindow
    
    #endif // _CMAINWINDOW_H_INCLUDED_
    
    
  3. Notice that the CMainWindow class has the data member

    
        Fl_Image* jpeg_image;
    
    
  4. Open CMainWindow.cpp in the text editor.

  5. Download the new version of CMainWindow.cpp , or add NEW code manually:

    
    // Lab 6: Fl_Box, Fl_Image, Fl_JPEG_Image
    // CMainWindow.cpp
    
    #include "CMainWindow.h"
    
    // NEW
    CMainWindow::CMainWindow()
        : jpeg_image( nullptr )
    {
    }
    
    void CMainWindow::show()
    {
        // Window callbacks:
        win_app->callback( (Fl_Callback*)CMainWindow::callback_window_closing, (void*)(this) );
    
        // NEW
        btn_show_jpeg->callback( (Fl_Callback*)CMainWindow::callback_btn_show_jpeg, (void*)(this) );
    
        // Make the window visible:
        win_app->show();
    }
    
    // callback functions
    void CMainWindow::callback_window_closing(Fl_Widget* widg, void* userdata_) {
        std::cout << "X button clicked -- exiting the program\n";
        while( Fl::first_window() ) {
            Fl::first_window()->hide();
        }
    }
    
    // NEW
    void CMainWindow::callback_btn_show_jpeg(Fl_Widget* widg, void* userdata_)
    {
        CMainWindow* win = static_cast< CMainWindow* > ( userdata_ );
        win->click_btn_show_jpeg();
    }
    
    // NEW
    void CMainWindow::click_btn_show_jpeg()
    {
        std::cout << "btn_show_jpeg click\n";
        Fl_JPEG_Image* jpeg_image_orig = new Fl_JPEG_Image( "../../JPEG/bird.JPG" );
        // copy allow us to resize the image:
        jpeg_image = jpeg_image_orig->copy( box_jpeg_image->w(), box_jpeg_image->h() );
        delete jpeg_image_orig;
        box_jpeg_image->image( jpeg_image );
        win_app->redraw();
    }
    
    
  6. Compile and test the program.

     


How to submit