Moved Fl_File_Btn,Fl_Vert_Progress to libcmpp.

Inserted devious ptr trick in kcApp::_setDeviceMenuButton().
This commit is contained in:
kevin 2013-03-17 14:58:10 -07:00
parent 0f5c8b5897
commit bc2e66ed98
6 changed files with 2 additions and 244 deletions

View File

@ -66,8 +66,6 @@ src_kc_kc_SOURCES = $(tlCtlSRC)
src_kc_kc_SOURCES += src/kc/kcMain.cpp src_kc_kc_SOURCES += src/kc/kcMain.cpp
src_kc_kc_SOURCES += src/kc/kcApp.h src/kc/kcApp.cpp src_kc_kc_SOURCES += src/kc/kcApp.h src/kc/kcApp.cpp
src_kc_kc_SOURCES += src/kc/Fl_File_Btn.h src/kc/Fl_Vert_Progress.h
src_kc_kc_SOURCES += src/kc/Fl_File_Btn.cpp src/kc/Fl_Vert_Progress.cpp
src_kc_kc_LDADD = $(CMLIBS) $(MYLIBS) src_kc_kc_LDADD = $(CMLIBS) $(MYLIBS)
bin_PROGRAMS += src/kc/kc bin_PROGRAMS += src/kc/kc

View File

@ -1,103 +0,0 @@
#include <Fl/Fl.H>
#include <Fl/Fl_Button.H>
#include <Fl/Fl_File_Chooser.H>
#include <Fl/Fl_Output.H>
#include <Fl/Fl_Group.H>
#include "Fl_File_Btn.h"
Fl_File_Btn::Fl_File_Btn( int xx, int yy, int ww, int hh, const char* l )
: Fl_Group(xx,yy,ww,hh,l),
_patStr(NULL),_typeId(kFile_Type_Id),_btn(NULL),_out(NULL)
{
_init();
}
Fl_File_Btn::Fl_File_Btn( unsigned typeId, const char* patStr, int xx, int yy, int ww, int hh, const char* l )
: Fl_Group(xx,yy,ww,hh,l),
_patStr(NULL),_typeId(typeId),_btn(NULL),_out(NULL)
{
_init();
type(typeId);
pattern_string(patStr);
}
Fl_File_Btn::~Fl_File_Btn()
{ delete[] _patStr; }
unsigned Fl_File_Btn::type()
{ return _typeId; }
void Fl_File_Btn::type( unsigned typeId )
{
switch(typeId)
{
case kFile_Type_Id:
_btn->label("File");
_typeId = typeId;
break;
case kDir_Type_Id:
_btn->label("Dir");
_typeId = typeId;
break;
}
}
const char* Fl_File_Btn::pattern_string()
{ return _patStr; }
void Fl_File_Btn::pattern_string( const char* pat)
{
delete[] _patStr;
if( pat != NULL )
{
_patStr = new char[ strlen(pat) + 1];
strcpy(_patStr,pat);
}
}
void Fl_File_Btn::btn_width( int ww )
{
_btn->resize(_btn->x(),_btn->y(),ww,_btn->h());
_out->resize(_btn->x() + _btn->w() + 2, _out->y(), w() - _btn->w() - 2, _out->h());
}
int Fl_File_Btn::btn_width()
{ return _btn->w(); }
void Fl_File_Btn::filename( const char* fn )
{ _out->value(fn); _out->redraw(); }
const char* Fl_File_Btn::filename() const
{ return _out->value(); }
void Fl_File_Btn::_s_btn_cb(Fl_Widget* w, void* data)
{ ((Fl_File_Btn*)data)->_btn_cb(); }
void Fl_File_Btn::_btn_cb()
{
char* fn;
if( _typeId == kFile_Type_Id )
fn = fl_file_chooser("Select a file",_patStr,_out->value(),0);
else
fn = fl_dir_chooser("Select a directory",_out->value(),0);
if( fn != NULL )
{
_out->value(fn);
do_callback(this,user_data());
}
}
void Fl_File_Btn::_init()
{
_btn = new Fl_Button(x(),y(),40,h(),_typeId==kFile_Type_Id ? "File" : "Dir");
_btn->callback(_s_btn_cb,this);
_out = new Fl_Output(x() + _btn->w() + 2, y(), w() - _btn->w(), h());
}

View File

@ -1,47 +0,0 @@
#ifndef Fl_File_Btn_h
#define Fl_File_Btn_h
class Fl_Button;
class Fl_Output;
class Fl_File_Btn : public Fl_Group
{
public:
enum
{
kFile_Type_Id,
kDir_Type_Id
};
Fl_File_Btn( int x, int y, int w, int h, const char* l = 0 );
Fl_File_Btn( unsigned typeId, const char* patStr, int x, int y, int w, int h, const char* l = 0 );
virtual ~Fl_File_Btn();
unsigned type();
void type( unsigned typeId );
const char* pattern_string();
void pattern_string( const char* pat);
void btn_width( int w );
int btn_width();
void filename( const char* fn );
const char* filename() const;
private:
char* _patStr;
unsigned _typeId;
Fl_Button* _btn;
Fl_Output* _out;
static void _s_btn_cb(Fl_Widget* w, void* data);
void _btn_cb();
void _init();
};
#endif

View File

@ -1,77 +0,0 @@
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <Fl/Fl_Progress.H>
#include "Fl_Vert_Progress.h"
Fl_Vert_Progress::Fl_Vert_Progress(int x, int y, int w, int h, const char* l)
: Fl_Progress(x,y,w,h)
{
}
void Fl_Vert_Progress::draw()
{
int progress; // Size of progress bar...
int bx, by, bw, bh; // Box areas...
int tx, ty, tw, th; // Temporary X + width
float min_ = minimum();
float max_ = maximum();
float val_ = value();
// Get the box borders...
bx = Fl::box_dx(box());
by = Fl::box_dy(box());
bw = Fl::box_dw(box());
bh = Fl::box_dh(box());
tx = x() + bx;
ty = y() + by;
tw = w() - bw;
th = h() - bh;
// Draw the progress bar...
if (max_ > min_)
progress = (int)( th * (val_ - min_) / (max_ - min_) );
else
progress = 0;
// Draw the box and label...
if (progress > 0)
{
Fl_Color c = labelcolor();
labelcolor(fl_contrast(labelcolor(), selection_color()));
// draw the progress area
//fl_push_clip(x(), y() + h() - progress, w(), progress);
fl_push_clip(tx,ty + th - progress, tw, progress );
draw_box(box(), x(), y(), w(), h(), active_r() ? selection_color() : fl_inactive(selection_color()));
draw_label(tx, y() + by, tw, h() - bh);
fl_pop_clip();
labelcolor(c);
if (progress<w())
{
// draw the non-progress area
//fl_push_clip(x(), y(), w(), h() - progress );
fl_push_clip(tx,ty,tw,th-progress );
draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
draw_label(tx, y() + by, tw, h() - bh);
fl_pop_clip();
}
}
else
{
draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
draw_label(tx, y() + by, tw, h() - bh);
}
//fl_draw_box(FL_FLAT_BOX,x(),y(),w(),h(), FL_RED);
//fl_draw_box(FL_FLAT_BOX,tx,ty,tw,th, FL_GREEN);
//fl_draw_box(FL_FLAT_BOX,tx,ty,tw,th-progress, FL_BLACK); // non-prog
//fl_draw_box(FL_FLAT_BOX,tx,ty + th - progress,tw,progress,FL_BLUE); // prog
}

View File

@ -1,14 +0,0 @@
#ifndef Fl_Vert_Progress_h
#define Fl_Vert_Progress_h
class Fl_Vert_Progress : public Fl_Progress
{
protected:
virtual void draw();
public:
Fl_Vert_Progress(int x, int y, int w, int h, const char* l=0);
};
#endif

View File

@ -1370,7 +1370,8 @@ void kcApp::_setDeviceMenuButton( unsigned asSubIdx, bool inputFl, unsigned devI
const Fl_Menu_Item* map = mbp->menu(); const Fl_Menu_Item* map = mbp->menu();
unsigned n = mbp->size(); unsigned n = mbp->size();
unsigned i; unsigned i;
void* di = (void*)devIdx; char* di = 0; di += devIdx; // BEWARE: devious int to ptr trick
for(i=0; i<n; ++i) for(i=0; i<n; ++i)
if( map[i].user_data() == di ) if( map[i].user_data() == di )
break; break;