Course list http://www.c-jump.com/bcc/
Lab 6 demonstrates how to load, resize, and draw an image inside the Fl_Box. One serious flaw in the code is the hardcoded path to the JPEG file. FLTK class Fl_File_Chooser displays a customizable file selection dialog that supports various file selection modes.
In this lab we add a standard file selection to the application:
The prototype for this project is Lab 6:
c255labs\labs\c255_lab06_jpeg
Make a copy of Lab 6 subfolder, or download and unzip c255_lab06_jpeg.zip
Rename the new folder as Lab_07_file_chooser.
Open solution file in Visual Studio and finish the usual steps to rename the project.
Open CMainWindow.h in text editor. Make NEW changes to add the pointer to the Fl_File_Chooser object:
// CMainWindow.h #ifndef _CMAINWINDOW_H_INCLUDED_ #define _CMAINWINDOW_H_INCLUDED_ #include "../fluid_project/CFluidWindow.h" #include <FL/Fl_Shared_Image.H> #include <FL/Fl_JPEG_Image.H> #include <FL/Fl_File_Chooser.H> // NEW class CMainWindow : public CFluidWindow { Fl_Image* jpeg_image; Fl_File_Chooser *file_chooser; // NEW public: CMainWindow(); void show(); void click_btn_show_jpeg(); // callback functions static void callback_window_closing(Fl_Widget* widg, void* userdata_); static void callback_btn_show_jpeg(Fl_Widget* widg, void* userdata_); };//class CMainWindow #endif // _CMAINWINDOW_H_INCLUDED_
Download the new version of CMainWindow.cpp file. Compile and test the program. Use WinMerge to compare the old and the new versions of the file. Pay attention to the changes that took place in the new code:
DEFAULT_JPEG_FILE_PATH macro is defined to specify the default JPEG file
The implementation of CMainWindow::click_btn_show_jpeg() now includes support for the Fl_File_Chooser dialog. Program demonstrates how directory, file path, and other information is extracted from the file chooser dialog.
Fl_JPEG_Image constructor takes user-specified file path and loads the image from the specified file into memory.
This is a self-learning lab. There are no files to submit. Make sure to complete all required steps to build and test the project on your own home computer.