diff options
| -rw-r--r-- | plugingui/checkbox.cc | 2 | ||||
| -rw-r--r-- | plugingui/combobox.cc | 8 | ||||
| -rw-r--r-- | plugingui/filebrowser.cc | 359 | ||||
| -rw-r--r-- | plugingui/filebrowser.h | 48 | ||||
| -rw-r--r-- | plugingui/guievent.h | 26 | ||||
| -rw-r--r-- | plugingui/knob.cc | 12 | ||||
| -rw-r--r-- | plugingui/lineedit.cc | 410 | ||||
| -rw-r--r-- | plugingui/lineedit.h | 62 | ||||
| -rw-r--r-- | plugingui/listboxbasic.cc | 12 | ||||
| -rw-r--r-- | plugingui/nativewindow_pugl.cc | 18 | ||||
| -rw-r--r-- | plugingui/nativewindow_win32.cc | 26 | ||||
| -rw-r--r-- | plugingui/nativewindow_x11.cc | 28 | ||||
| -rw-r--r-- | plugingui/plugingui.cc | 110 | ||||
| -rw-r--r-- | plugingui/plugingui.h | 11 | 
14 files changed, 577 insertions, 555 deletions
| diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc index c085be9..6d85615 100644 --- a/plugingui/checkbox.cc +++ b/plugingui/checkbox.cc @@ -65,7 +65,7 @@ void CheckBox::setText(std::string text)  void CheckBox::keyEvent(KeyEvent *e)  { -	if(e->keycode == KeyEvent::KEY_CHARACTER && e->text == " ") +	if(e->keycode == KeyEvent::KeyCharacter && e->text == " ")  	{  		if(e->direction == KeyEvent::Up)  		{ diff --git a/plugingui/combobox.cc b/plugingui/combobox.cc index cae854a..4a6d2b5 100644 --- a/plugingui/combobox.cc +++ b/plugingui/combobox.cc @@ -173,7 +173,7 @@ void ComboBox::keyEvent(KeyEvent *e)  	/*  	switch(e->keycode) { -	case KeyEvent::KEY_UP: +	case KeyEvent::KeyUp:  		{  			selected--;  			if(selected < 0) @@ -190,7 +190,7 @@ void ComboBox::keyEvent(KeyEvent *e)  			}  		}  		break; -	case KeyEvent::KEY_DOWN: +	case KeyEvent::KeyDown:  		{  			// Number of items that can be displayed at a time.  			int numitems = height() / (font.textHeight() + padding); @@ -210,10 +210,10 @@ void ComboBox::keyEvent(KeyEvent *e)  			}  		}  		break; -	case KeyEvent::KEY_HOME: +	case KeyEvent::KeyHome:  		selected = 0;  		break; -	case KeyEvent::KEY_END: +	case KeyEvent::KeyEnd:  		selected = items.size() - 1;  		break;  	default: diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 4b35127..9635c94 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -45,239 +45,216 @@  #include <direct.h>  #endif -struct GUI::FileBrowser::private_data { -  GUI::LineEdit *lineedit; -  GUI::ListBox *listbox; -  void (*filesel_handler)(void *, std::string); -  void *ptr; -  Directory *dir; -#ifdef WIN32 -  bool above_root; -  bool in_root; -#endif -}; - -static void cancel(void *ptr) -{ -  GUI::FileBrowser *fp = (GUI::FileBrowser *)ptr; -  fp->hide(); -} - -static void changeDir(void *ptr) +namespace GUI { + +FileBrowser::FileBrowser(Widget *parent) +	: Widget(parent) +	, dir(Directory::cwd()) +	, lbl_path(this) +	, lineedit(this) +	, listbox(this) +	, btn_sel(this) +	, btn_esc(this) +	, back(":bg.png")  { -  struct GUI::FileBrowser::private_data *prv = -    (struct GUI::FileBrowser::private_data *) ptr; -   -  GUI::ListBox *lb = prv->listbox; -  GUI::LineEdit *le = prv->lineedit; -  std::string value = lb->selectedValue();  -  GUI::Directory* dir = prv->dir; - -//  if(!Directory::isDir(dir->path() + dir->seperator())) { -//    return; -//  } - -  lb->clear(); -   -  INFO(filebrowser, "Changing path to '%s'\n", -       (dir->path() + dir->seperator() + value).c_str()); -   #ifdef WIN32 -  if(prv->above_root && !value.empty()) { -    dir->setPath(value + dir->seperator()); -    value.clear(); -    prv->above_root = false; -  } +	above_root = false;  #endif -  if(value.empty() && !dir->isDir() && GUI::Directory::exists(dir->path())) { -    DEBUG(filebrowser, "Selecting file '%s'\n", dir->path().c_str()); -    if(prv->filesel_handler) prv->filesel_handler(prv->ptr, dir->path().c_str()); -    return; -  } +	lbl_path.setText("Path:"); -  if(!value.empty() && dir->fileExists(value)) { -    std::string file = dir->path() + dir->seperator() + value; -    DEBUG(filebrowser, "Selecting file '%s'\n", file.c_str()); -    if(prv->filesel_handler) prv->filesel_handler(prv->ptr, file); -    return; -  } +	//lineedit.setReadOnly(true); +	CONNECT(&lineedit, enterPressedNotifier, this, &FileBrowser::handleKeyEvent); +	CONNECT(&listbox, selectionNotifier, +	        this, &FileBrowser::listSelectionChanged); -  std::vector<GUI::ListBoxBasic::Item> items; +	btn_sel.setText("Select"); +	CONNECT(&btn_sel, clickNotifier, this, &FileBrowser::selectButtonClicked); -#ifdef WIN32 -  if(GUI::Directory::isRoot(dir->path()) && value == "..") { -   DEBUG(filebrowser, "Showing partitions...\n"); -   GUI::Directory::DriveList entries = dir->drives(); -   for(GUI::Directory::DriveList::iterator it = entries.begin(); -       it != entries.end(); it++) {   -      GUI::ListBoxBasic::Item item; -      std::string name = (*it).name; -      item.name = name; -      item.value = name; -      items.push_back(item); -    }  -    prv->above_root = true; -  } else { -#endif -     -    if(!value.empty() && !dir->cd(value)) { -      DEBUG(filebrowser, "Error changing to '%s'\n",  -            (dir->path() + dir->seperator() + value).c_str()); -      return; -    } -     -    GUI::Directory::EntryList entries = dir->entryList(); - -    if(entries.empty()) { -      dir->cdUp(); -      entries = dir->entryList(); -    } - -    DEBUG(filebrowser, "Setting path of lineedit to %s\n", -          dir->path().c_str());  -    le->setText(dir->path()); - -    for(GUI::Directory::EntryList::iterator it = entries.begin(); -        it != entries.end(); it++) {  -      GUI::ListBoxBasic::Item item; -      std::string name = *it; -      item.name = name; -      item.value = name; -      items.push_back(item); -    } -#ifdef WIN32 -  } -#endif -  lb->addItems(items); -} +	btn_esc.setText("Cancel"); +	CONNECT(&btn_esc, clickNotifier, this, &FileBrowser::cancelButtonClicked); -static void handleKeyEvent(void *ptr) { -  struct GUI::FileBrowser::private_data *prv = -    (struct GUI::FileBrowser::private_data *) ptr; - -  GUI::ListBox *lb = prv->listbox; -  lb->clearSelectedValue();   -  GUI::LineEdit *le = prv->lineedit; - -  std::string value = le->text(); -  if(value.size() > 1 && value[0] == '@') { -    DEBUG(filebrowser, "Selecting ref-file '%s'\n", value.c_str()); -    if(prv->filesel_handler) { -      prv->filesel_handler(prv->ptr, value); -    } -    return; -  } - -  prv->dir->setPath(le->text()); -  changeDir(ptr); +	changeDir();  } -GUI::FileBrowser::FileBrowser(GUI::Widget *parent) -  : GUI::Widget(parent), -    lbl_path(this), lineedit(this), listbox(this), btn_sel(this), btn_esc(this), -    back(":bg.png") +FileBrowser::~FileBrowser()  { -  prv = new struct GUI::FileBrowser::private_data(); -  prv->filesel_handler = NULL; - -  prv->dir = new Directory(Directory::cwd()); -#ifdef WIN32   -  prv->above_root = false; -#endif - -  lbl_path.setText("Path:"); - -//  lineedit.setReadOnly(true); -  prv->lineedit = &lineedit; -  prv->lineedit->registerEnterPressedHandler(handleKeyEvent, prv); - -  prv->listbox = &listbox; -  CONNECT(&listbox, selectionNotifier, this, &FileBrowser::listSelectionChanged); - -  btn_sel.setText("Select"); -  CONNECT(&btn_sel, clickNotifier, this, &FileBrowser::selectButtonClicked); - -  btn_esc.setText("Cancel"); -  CONNECT(&btn_esc, clickNotifier, this, &FileBrowser::cancelButtonClicked); - -  changeDir(prv); - -  resize(200, 190);  } -GUI::FileBrowser::~FileBrowser() +void FileBrowser::setPath(const std::string& path)  { -  //  delete prv->listbox; -  delete prv; -} +	INFO(filebrowser, "Setting path to '%s'\n", path.c_str()); -void GUI::FileBrowser::setPath(std::string path) -{ -  INFO(filebrowser, "Setting path to '%s'\n", path.c_str()); -  if(path.empty()) path = Directory::cwd(); +	if(!path.empty()) +	{ +		dir.setPath(Directory::pathDirectory(path)); +	} +	else +	{ +		dir.setPath(Directory::pathDirectory(Directory::cwd())); +	} -  prv->dir->setPath(Directory::pathDirectory(path)); -  prv->listbox->clear(); +	listbox.clear(); -  changeDir(prv); +	changeDir();  } -void GUI::FileBrowser::resize(int w, int h) +void FileBrowser::resize(int w, int h)  { -  GUI::Widget::resize(w,h); +	Widget::resize(w,h); + +	int offset = 0; +	int brd = 5; // border +	int btn_h = 30; -  int offset = 0; -  int brd = 5; // border -  int btn_h = 30; +	offset += brd; -  offset += brd; +	lbl_path.move(0, offset); +	lineedit.move(60, offset); -  lbl_path.move(0, offset); -  lineedit.move(60, offset); +	offset += btn_h; -  offset += btn_h; +	lbl_path.resize(60, btn_h); +	lineedit.resize(w - 60 - brd, btn_h); -  lbl_path.resize(60, btn_h); -  lineedit.resize(w - 60 - brd, btn_h); +	offset += brd; -  offset += brd; +	listbox.move(brd, offset); +	listbox.resize(w - 1 - 2*brd, h - btn_h - 2*brd - offset); -  listbox.move(brd, offset); -  listbox.resize(w - 1 - 2*brd, h - btn_h - 2*brd - offset); +	btn_esc.move(brd, h - btn_h - brd); +	btn_esc.resize((w - 1 - 2*brd) / 2 - brd / 2, btn_h); -  btn_esc.move(brd, h - btn_h - brd); -  btn_esc.resize((w - 1 - 2*brd) / 2 - brd / 2, btn_h); +	btn_sel.move(brd + w / 2 - brd / 2, h - btn_h - brd); +	btn_sel.resize((w - 1 - 2*brd) / 2, btn_h); +} -  btn_sel.move(brd + w / 2 - brd / 2, h - btn_h - brd); -  btn_sel.resize((w - 1 - 2*brd) / 2, btn_h); +void FileBrowser::repaintEvent(RepaintEvent *e) +{ +	Painter p(this); +	p.drawImageStretched(0,0, &back, width(), height());  } -void GUI::FileBrowser::registerFileSelectHandler(void (*handler)(void *, -                                                                 std::string), -                                                 void *ptr) +void FileBrowser::listSelectionChanged()  { -  prv->filesel_handler = handler; -  prv->ptr = ptr; +	changeDir();  } -void GUI::FileBrowser::repaintEvent(GUI::RepaintEvent *e) +void FileBrowser::selectButtonClicked()  { -  Painter p(this); -  p.drawImageStretched(0,0, &back, width(), height()); +	changeDir();  } -void GUI::FileBrowser::listSelectionChanged() +void FileBrowser::cancelButtonClicked()  { -	changeDir(prv); +	cancel();  } -void GUI::FileBrowser::selectButtonClicked() +void FileBrowser::handleKeyEvent()  { -	changeDir(prv); +	listbox.clearSelectedValue(); + +	std::string value = lineedit.text(); +	if((value.size() > 1) && (value[0] == '@')) +	{ +		DEBUG(filebrowser, "Selecting ref-file '%s'\n", value.c_str()); +		fileSelectNotifier(value); +		return; +	} + +	dir.setPath(lineedit.text()); +	changeDir();  } -void GUI::FileBrowser::cancelButtonClicked() +void FileBrowser::cancel()  { -	cancel(this); +	hide();  } + +void FileBrowser::changeDir() +{ +	std::string value = listbox.selectedValue(); + +//  if(!Directory::isDir(dir->path() + dir->seperator())) +//  { +//    return; +//  } + +	listbox.clear(); + +	INFO(filebrowser, "Changing path to '%s'\n", +	     (dir.path() + dir.seperator() + value).c_str()); + +#ifdef WIN32 +	if(above_root && !value.empty()) +	{ +		dir.setPath(value + dir.seperator()); +		value.clear(); +		above_root = false; +	} +#endif + +	if(value.empty() && !dir.isDir() && Directory::exists(dir.path())) +	{ +		DEBUG(filebrowser, "Selecting file '%s'\n", dir.path().c_str()); +		fileSelectNotifier(dir.path()); +		return; +	} + +	if(!value.empty() && dir.fileExists(value)) +	{ +	  std::string file = dir.path() + dir.seperator() + value; +	  DEBUG(filebrowser, "Selecting file '%s'\n", file.c_str()); +	  fileSelectNotifier(file); +	  return; +	} + +	std::vector<ListBoxBasic::Item> items; + +#ifdef WIN32 +	if(Directory::isRoot(dir.path()) && (value == "..")) +	{ +		DEBUG(filebrowser, "Showing partitions...\n"); +		for(auto drive : dir.drives()) +		{ +			ListBoxBasic::Item item; +			item.name = drive.name; +			item.value = drive.name; +			items.push_back(item); +		} +		above_root = true; +	} +	else +#endif +	{ +		if(!value.empty() && !dir.cd(value)) +		{ +			DEBUG(filebrowser, "Error changing to '%s'\n", +			      (dir.path() + dir.seperator() + value).c_str()); +			return; +		} + +		Directory::EntryList entries = dir.entryList(); + +		if(entries.empty()) +		{ +			dir.cdUp(); +			entries = dir.entryList(); +		} + +		DEBUG(filebrowser, "Setting path of lineedit to %s\n", dir.path().c_str()); +		lineedit.setText(dir.path()); + +		for(auto entry : entries) +		{ +			ListBoxBasic::Item item; +			item.name = entry; +			item.value = entry; +			items.push_back(item); +		} +	} + +	listbox.addItems(items); +} + +} // GUI:: diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index 93a745e..7edfaa2 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -24,8 +24,7 @@   *  along with DrumGizmo; if not, write to the Free Software   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.   */ -#ifndef __DRUMGIZMO_FILEBROWSER_H__ -#define __DRUMGIZMO_FILEBROWSER_H__ +#pragma once  #include "widget.h" @@ -35,45 +34,50 @@  #include "label.h"  #include "image.h"  #include "directory.h" +#include "notifier.h"  namespace GUI {  class FileBrowser : public Widget {  public: -  struct private_data; +	struct private_data; -  FileBrowser(Widget *parent); -  ~FileBrowser(); +	FileBrowser(Widget *parent); +	~FileBrowser(); -  void setPath(std::string path); +	void setPath(const std::string& path); -  bool isFocusable() { return true; } +	Notifier<const std::string&> fileSelectNotifier; // (const std::string& path) -  void registerFileSelectHandler(void (*handler)(void *, std::string), -                                 void *ptr); - -  virtual void repaintEvent(RepaintEvent *e); - -  virtual void resize(int w, int h); +	// From Widget: +	bool isFocusable() override { return true; } +	virtual void repaintEvent(RepaintEvent *e) override; +	virtual void resize(int w, int h) override;  private:  	void listSelectionChanged();  	void selectButtonClicked();  	void cancelButtonClicked(); +	void handleKeyEvent(); -  struct private_data *prv; +	Directory dir; +#ifdef WIN32 +	bool above_root; +	bool in_root; +#endif -  GUI::Label lbl_path; -  GUI::LineEdit lineedit; +	void cancel(); +	void changeDir(); -  GUI::ListBox listbox; +	Label lbl_path; -  GUI::Button btn_sel; -  GUI::Button btn_esc; +	LineEdit lineedit; +	ListBox listbox; -  Image back; -}; +	Button btn_sel; +	Button btn_esc; +	Image back;  }; -#endif/*__DRUMGIZMO_FILEBROWSER_H__*/ +} // GUI:: diff --git a/plugingui/guievent.h b/plugingui/guievent.h index 221e056..e92f2e2 100644 --- a/plugingui/guievent.h +++ b/plugingui/guievent.h @@ -119,19 +119,19 @@ public:  	std::string text;  	enum { -		KEY_UNKNOWN   =-1, -		KEY_LEFT      = 1, -		KEY_RIGHT     = 2, -		KEY_UP        = 3, -		KEY_DOWN      = 4, -		KEY_DELETE    = 5, -		KEY_BACKSPACE = 6, -		KEY_HOME      = 7, -		KEY_END       = 8, -		KEY_PGDOWN    = 9, -		KEY_PGUP      = 10, -		KEY_ENTER     = 11, -		KEY_CHARACTER = 0xffff // character data is stored in 'text' +		KeyUnknown   = -1, +		KeyLeft      =  1, +		KeyRight     =  2, +		KeyUp        =  3, +		KeyDown      =  4, +		KeyDelete    =  5, +		KeyBackspace =  6, +		KeyHome      =  7, +		KeyEnd       =  8, +		KeyPageDown  =  9, +		KeyPageUp    =  10, +		KeyEnter     =  11, +		KeyCharacter =  0xffff // character data is stored in 'text'  	};  }; diff --git a/plugingui/knob.cc b/plugingui/knob.cc index ec35af0..360766e 100644 --- a/plugingui/knob.cc +++ b/plugingui/knob.cc @@ -96,22 +96,22 @@ void Knob::keyEvent(KeyEvent *e)  	float value = currentValue;  	switch(e->keycode) { -	case KeyEvent::KEY_UP: +	case KeyEvent::KeyUp:  		value += 0.01;  		break; -	case KeyEvent::KEY_DOWN: +	case KeyEvent::KeyDown:  		value -= 0.01;  		break; -	case KeyEvent::KEY_RIGHT: +	case KeyEvent::KeyRight:  		value += 0.01;  		break; -	case KeyEvent::KEY_LEFT: +	case KeyEvent::KeyLeft:  		value -= 0.01;  		break; -	case KeyEvent::KEY_HOME: +	case KeyEvent::KeyHome:  		value = 0;  		break; -	case KeyEvent::KEY_END: +	case KeyEvent::KeyEnd:  		value = 1;  		break;  	default: diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc index 17d62bb..9c2420c 100644 --- a/plugingui/lineedit.cc +++ b/plugingui/lineedit.cc @@ -27,213 +27,265 @@  #include "lineedit.h"  #include <stdio.h> - -#include "window.h" - -#include <assert.h> -  #include <hugin.hpp>  #define BORDER 10 -GUI::LineEdit::LineEdit(Widget *parent) -  : GUI::Widget(parent) +namespace GUI { + +LineEdit::LineEdit(Widget *parent) +	: Widget(parent)  { -  pos = 0; -  offsetpos = 0; -  setReadOnly(false); - -  box.topLeft     = new Image(":widget_tl.png"); -  box.top         = new Image(":widget_t.png"); -  box.topRight    = new Image(":widget_tr.png"); -  box.left        = new Image(":widget_l.png"); -  box.right       = new Image(":widget_r.png"); -  box.bottomLeft  = new Image(":widget_bl.png"); -  box.bottom      = new Image(":widget_b.png"); -  box.bottomRight = new Image(":widget_br.png"); -  box.center      = new Image(":widget_c.png"); - -  handler = NULL; +	setReadOnly(false); + +	box.topLeft     = new Image(":widget_tl.png"); +	box.top         = new Image(":widget_t.png"); +	box.topRight    = new Image(":widget_tr.png"); +	box.left        = new Image(":widget_l.png"); +	box.right       = new Image(":widget_r.png"); +	box.bottomLeft  = new Image(":widget_bl.png"); +	box.bottom      = new Image(":widget_b.png"); +	box.bottomRight = new Image(":widget_br.png"); +	box.center      = new Image(":widget_c.png");  } -void GUI::LineEdit::registerEnterPressedHandler(void (*handler)(void *), void *ptr) +LineEdit::~LineEdit()  { -  this->handler = handler; -  this->ptr = ptr; +	delete box.topLeft; +	delete box.top; +	delete box.topRight; +	delete box.left; +	delete box.right; +	delete box.bottomLeft; +	delete box.bottom; +	delete box.bottomRight; +	delete box.center;  } -void GUI::LineEdit::setReadOnly(bool ro) +void LineEdit::setReadOnly(bool ro)  { -  readonly = ro; +	readonly = ro;  } -bool GUI::LineEdit::readOnly() +bool LineEdit::readOnly()  { -  return readonly; +	return readonly;  } -void GUI::LineEdit::setText(std::string text) +void LineEdit::setText(const std::string& text)  { -  _text = text; -  pos = text.size(); -   -  repaintEvent(NULL); -  textChanged(); +	_text = text; +	pos = text.size(); + +	visibleText = _text; +	offsetPos = 0; + +	repaintEvent(nullptr); +	textChanged();  } -std::string GUI::LineEdit::text() +std::string LineEdit::text()  { -  return _text; +	return _text;  } -void GUI::LineEdit::buttonEvent(ButtonEvent *e) +void LineEdit::buttonEvent(ButtonEvent *buttonEvent)  { -  if(readOnly()) return; - - -  if(e->direction == ButtonEvent::Down) { -    for(int i = 0; i < (int)_visibletext.length(); i++) { -      if(e->x < (int)(font.textWidth(_visibletext.substr(0, i)) + BORDER)) { -        pos = i + offsetpos; -        break; -      } -    } -    repaintEvent(NULL); -  } +	if(readOnly()) +	{ +		return; +	} + +	if(buttonEvent->direction == ButtonEvent::Down) +	{ +		for(int i = 0; i < (int)visibleText.length(); ++i) +		{ +			int textWidth = font.textWidth(visibleText.substr(0, i)); +			if(buttonEvent->x < (textWidth + BORDER)) +			{ +				pos = i + offsetPos; +				break; +			} +		} +		repaintEvent(nullptr); +	}  } -void GUI::LineEdit::keyEvent(GUI::KeyEvent *e) +void LineEdit::keyEvent(KeyEvent *keyEvent)  { -  if(readOnly()) return; - -  bool change = false; -   -  if(e->direction == KeyEvent::Up) { - -    if(e->keycode == GUI::KeyEvent::KEY_LEFT) { -      if(pos) pos--; -      if(offsetpos >= pos) walkstate = WALK_LEFT; -     -    } else if(e->keycode == GUI::KeyEvent::KEY_HOME) { -      pos = 0; - -    } else if(e->keycode == GUI::KeyEvent::KEY_END) { -      pos = _text.length(); - -    } else if(e->keycode == GUI::KeyEvent::KEY_RIGHT) { -      if(pos < _text.length()) pos++; -      if(offsetpos + _visibletext.length() <= pos && -         pos < _text.length()) walkstate = WALK_RIGHT; -     -    } else if(e->keycode == GUI::KeyEvent::KEY_DELETE) { -      if(pos < _text.length()) { -        std::string t = _text.substr(0, pos); -        t += _text.substr(pos + 1, std::string::npos); -        _text = t; -        change = true; -      } - -    } else if(e->keycode == GUI::KeyEvent::KEY_BACKSPACE) { -      if(pos > 0) { -        std::string t = _text.substr(0, pos - 1); -        t += _text.substr(pos, std::string::npos); -        _text = t; -        pos--; -        change = true; -      } - -    } else if(e->keycode == GUI::KeyEvent::KEY_CHARACTER) { -      std::string pre = _text.substr(0, pos); -      std::string post = _text.substr(pos, std::string::npos); -      _text = pre + e->text + post; -      change = true; -      pos++; - -    } else if(e->keycode == GUI::KeyEvent::KEY_ENTER) { -      if(handler) handler(ptr); -    } -    repaintEvent(NULL); -  } - -  if(change) textChanged(); +	if(readOnly()) +	{ +		return; +	} + +	bool change = false; + +	if(keyEvent->direction == KeyEvent::Up) +	{ +		switch(keyEvent->keycode) { +		case KeyEvent::KeyLeft: +			if(pos) +			{ +				pos--; +			} +			if(offsetPos >= pos) +			{ +				walkstate = WalkLeft; +			} +			break; + +		case KeyEvent::KeyHome: +			pos = 0; +			visibleText = _text; +			offsetPos = 0; +			break; + +		case KeyEvent::KeyEnd: +			pos = _text.length(); +			visibleText = _text; +			offsetPos = 0; +			break; + +		case KeyEvent::KeyRight: +			if(pos < _text.length()) +			{ +				pos++; +			} +			if((pos < _text.length()) && ((offsetPos + visibleText.length()) <= pos)) +			{ +				walkstate = WalkRight; +			} +			break; + +		case KeyEvent::KeyDelete: +			if(pos < _text.length()) +			{ +				std::string t = _text.substr(0, pos); +				t += _text.substr(pos + 1, std::string::npos); +				_text = t; +				change = true; +			} +			break; + +		case KeyEvent::KeyBackspace: +			if(pos > 0) +			{ +				std::string t = _text.substr(0, pos - 1); +				t += _text.substr(pos, std::string::npos); +				_text = t; +				pos--; +				change = true; +			} +			break; + +		case KeyEvent::KeyCharacter: +			{ +				std::string pre = _text.substr(0, pos); +				std::string post = _text.substr(pos, std::string::npos); +				_text = pre + keyEvent->text + post; +				change = true; +				pos++; +			} +			break; + +		case KeyEvent::KeyEnter: +			enterPressedNotifier(); +	    break; + +		default: +			break; +		} + +		repaintEvent(nullptr); +	} + +	if(change) +	{ +		textChanged(); +	}  } -void GUI::LineEdit::repaintEvent(GUI::RepaintEvent *e) +void LineEdit::repaintEvent(RepaintEvent *repaintEvent)  { -  Painter p(this); - -  p.clear(); - -  int w = width(); -  int h = height(); -  if(w == 0 || h == 0) return; -  p.drawBox(0, 0, &box, w, h); - -  p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); - -  if(walkstate == WALK_LEFT) { -    _visibletext = _text.substr(pos, std::string::npos); -    offsetpos = pos; -  } -  else if(walkstate == WALK_RIGHT) { -    int d = (offsetpos < _text.length()) ? 1 : 0; -    _visibletext = _text.substr(offsetpos + d); -    offsetpos = offsetpos + d; -  } -  else { -    _visibletext = _text; -    offsetpos = 0; -  } -  while(true) { -    int textwidth = font.textWidth(_visibletext); -    if(textwidth > w - BORDER - 4 + 3) { -      if(walkstate == WALK_LEFT) { -        _visibletext = _visibletext.substr(0, _visibletext.length()-1); -      } -      else if(walkstate == WALK_RIGHT) { -        _visibletext = _visibletext.substr(0, _visibletext.length()-1); -      } -      else { -        if(offsetpos < pos) { -          _visibletext = _visibletext.substr(1); -          offsetpos++; -        } -        else { -          _visibletext = _visibletext.substr(0, _visibletext.length() - 1); -        } -      } -    } -    else { -      break; -    } -  } - -  walkstate = NOOP; - -  p.drawText(BORDER - 4 + 3, height()/2+5 + 1 + 1 + 1, font, _visibletext); - -  if(readOnly()) return; - -  if(hasKeyboardFocus()) { -    size_t px = font.textWidth(_visibletext.substr(0, pos - offsetpos)); -    p.drawLine(px + BORDER - 1 - 4 + 3, 6, -               px + BORDER - 1 - 4 + 3, height() - 7); -  } +	Painter p(this); + +	p.clear(); + +	int w = width(); +	int h = height(); +	if((w == 0) || (h == 0)) +	{ +		return; +	} + +	p.drawBox(0, 0, &box, w, h); + +	p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + +	switch(walkstate) { +	case WalkLeft: +		visibleText = _text.substr(pos, std::string::npos); +		offsetPos = pos; +		break; + +	case WalkRight: +		{ +			int delta = (offsetPos < _text.length()) ? 1 : 0; +			visibleText = _text.substr(offsetPos + delta); +			offsetPos = offsetPos + delta; +		} +		break; + +	case Noop: +		break; +	} + +	while(true) +	{ +		int textWidth = font.textWidth(visibleText); +		if(textWidth <= (w - BORDER - 4 + 3)) +		{ +			break; +		} + +		switch(walkstate) { +		case WalkLeft: +			visibleText = visibleText.substr(0, visibleText.length() - 1); +			break; + +		case WalkRight: +			visibleText = visibleText.substr(0, visibleText.length() - 1); +			break; + +		case Noop: +			if(offsetPos < pos) +			{ +				visibleText = visibleText.substr(1); +				offsetPos++; +			} +			else +			{ +				visibleText = visibleText.substr(0, visibleText.length() - 1); +			} +			break; +		} +	} + +	walkstate = Noop; + +	p.drawText(BORDER - 4 + 3, height() / 2 + 5 + 1 + 1 + 1, font, visibleText); + +	if(readOnly()) +	{ +		return; +	} + +	if(hasKeyboardFocus()) +	{ +		size_t px = font.textWidth(visibleText.substr(0, pos - offsetPos)); +		p.drawLine(px + BORDER - 1 - 4 + 3, 6, +		           px + BORDER - 1 - 4 + 3, height() - 7); +	}  } -#ifdef TEST_LINEEDIT -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). - -TEST_END; - -#endif/*TEST_LINEEDIT*/ +} // GUI:: diff --git a/plugingui/lineedit.h b/plugingui/lineedit.h index f85e9bd..21e448b 100644 --- a/plugingui/lineedit.h +++ b/plugingui/lineedit.h @@ -24,9 +24,7 @@   *  along with DrumGizmo; if not, write to the Free Software   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.   */ -#ifndef __DRUMGIZMO_LINEEDIT_H__ -#define __DRUMGIZMO_LINEEDIT_H__ - +#pragma once  #include <string> @@ -38,49 +36,45 @@ namespace GUI {  class LineEdit : public Widget {  public: -  LineEdit(Widget *parent); +	LineEdit(Widget *parent); +	~LineEdit(); -  bool isFocusable() { return true; } +	bool isFocusable() override { return true; } -  std::string text(); -  void setText(std::string text); +	std::string text(); +	void setText(const std::string& text); -  void setReadOnly(bool readonly); -  bool readOnly(); +	void setReadOnly(bool readonly); +	bool readOnly(); -  void registerEnterPressedHandler(void (*handler)(void *), void *ptr); +	Notifier<> enterPressedNotifier; -  //protected: -  virtual void keyEvent(KeyEvent *e); -  virtual void repaintEvent(RepaintEvent *e); -  virtual void buttonEvent(ButtonEvent *e); +	//protected: +	virtual void keyEvent(KeyEvent *keyEvent); +	virtual void repaintEvent(RepaintEvent *repaintEvent); +	virtual void buttonEvent(ButtonEvent *buttonEvent);  protected: -  virtual void textChanged() {} +	virtual void textChanged() {}  private: -  Painter::Box box; - -  Font font; +	Painter::Box box; -  std::string _text; -  size_t pos; -  std::string _visibletext; -  size_t offsetpos; +	Font font; -  enum state_t { -    NOOP = 0, -    WALK_LEFT =  1,  -    WALK_RIGHT = 2 -  }; -  state_t walkstate; +	std::string _text; +	size_t pos = 0; +	std::string visibleText; +	size_t offsetPos = 0; -  bool readonly; - -  void (*handler)(void *); -  void *ptr; -}; +	enum state_t { +		Noop, +		WalkLeft, +		WalkRight, +	}; +	state_t walkstate; +	bool readonly;  }; -#endif/*__DRUMGIZMO_LINEEDIT_H__*/ +} // GUI:: diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index 2aae943..0bfde4c 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -201,7 +201,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  	}  	switch(e->keycode) { -	case KeyEvent::KEY_UP: +	case KeyEvent::KeyUp:  		marked--;  		if(marked < 0)  		{ @@ -214,7 +214,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  		}  		break; -	case KeyEvent::KEY_DOWN: +	case KeyEvent::KeyDown:  		{  			// Number of items that can be displayed at a time.  			int numitems = height() / (font.textHeight() + padding); @@ -232,7 +232,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  		}  		break; -	case KeyEvent::KEY_HOME: +	case KeyEvent::KeyHome:  		marked = 0;  		if(marked < scroll.value())  		{ @@ -240,7 +240,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  		}  		break; -	case KeyEvent::KEY_END: +	case KeyEvent::KeyEnd:  		{  			// Number of items that can be displayed at a time.  			int numitems = height() / (font.textHeight() + padding); @@ -253,7 +253,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  		}  		break; -	case KeyEvent::KEY_CHARACTER: +	case KeyEvent::KeyCharacter:  		if(e->text == " ")  		{  			setSelection(marked); @@ -261,7 +261,7 @@ void ListBoxBasic::keyEvent(KeyEvent *e)  		}  		break; -	case KeyEvent::KEY_ENTER: +	case KeyEvent::KeyEnter:  		setSelection(marked);  		selectionNotifier();  		break; diff --git a/plugingui/nativewindow_pugl.cc b/plugingui/nativewindow_pugl.cc index 45cddab..dadb724 100644 --- a/plugingui/nativewindow_pugl.cc +++ b/plugingui/nativewindow_pugl.cc @@ -97,18 +97,18 @@ static void onKeyboard(PuglView* view, bool press, uint32_t key)      printf("%d\n", key);      switch(key) { -      case PUGL_KEY_LEFT: e->keycode = GUI::KeyEvent::KEY_LEFT; break; -      case PUGL_KEY_RIGHT: e->keycode = GUI::KeyEvent::KEY_RIGHT; break; -      case PUGL_KEY_UP: e->keycode = GUI::KeyEvent::KEY_UP; break; -      case PUGL_KEY_DOWN: e->keycode = GUI::KeyEvent::KEY_DOWN; break; -      case PUGL_KEY_PAGE_UP: e->keycode = GUI::KeyEvent::KEY_PGDOWN; break; -      case PUGL_KEY_PAGE_DOWN: e->keycode = GUI::KeyEvent::KEY_PGUP; break; -      default: e->keycode = GUI::KeyEvent::KEY_UNKNOWN; break; +      case PUGL_KEY_LEFT: e->keycode = GUI::KeyEvent::KeyLeft; break; +      case PUGL_KEY_RIGHT: e->keycode = GUI::KeyEvent::KeyRight; break; +      case PUGL_KEY_UP: e->keycode = GUI::KeyEvent::KeyUp; break; +      case PUGL_KEY_DOWN: e->keycode = GUI::KeyEvent::KeyDown; break; +      case PUGL_KEY_PAGE_UP: e->keycode = GUI::KeyEvent::KeyPageDown; break; +      case PUGL_KEY_PAGE_DOWN: e->keycode = GUI::KeyEvent::KeyPageUp; break; +      default: e->keycode = GUI::KeyEvent::KeyUnknown; break;      }      // TODO: perform character type check -    if(e->keycode == GUI::KeyEvent::KEY_UNKNOWN) { -      e->keycode = GUI::KeyEvent::KEY_CHARACTER; +    if(e->keycode == GUI::KeyEvent::KeyUnknown) { +      e->keycode = GUI::KeyEvent::KeyCharacter;        e->text.assign(1, (char)key);       } diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index a68f656..6fc42f7 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -161,18 +161,18 @@ LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)        GUI::KeyEvent *e = new GUI::KeyEvent();        //printf("wp: %d\n", wp);        switch(wp) { -      case 37: e->keycode = GUI::KeyEvent::KEY_LEFT; break; -      case 39: e->keycode = GUI::KeyEvent::KEY_RIGHT; break; -      case 38: e->keycode = GUI::KeyEvent::KEY_UP; break; -      case 40: e->keycode = GUI::KeyEvent::KEY_DOWN; break; -      case 8: e->keycode = GUI::KeyEvent::KEY_BACKSPACE; break; -      case 46: e->keycode = GUI::KeyEvent::KEY_DELETE; break; -      case 36: e->keycode = GUI::KeyEvent::KEY_HOME; break; -      case 35: e->keycode = GUI::KeyEvent::KEY_END; break; -      case 33: e->keycode = GUI::KeyEvent::KEY_PGUP; break; -      case 34: e->keycode = GUI::KeyEvent::KEY_PGDOWN; break; -      case 13: e->keycode = GUI::KeyEvent::KEY_ENTER; break; -      default: e->keycode = GUI::KeyEvent::KEY_UNKNOWN; break; +      case 37: e->keycode = GUI::KeyEvent::KeyLeft; break; +      case 39: e->keycode = GUI::KeyEvent::KeyRight; break; +      case 38: e->keycode = GUI::KeyEvent::KeyUp; break; +      case 40: e->keycode = GUI::KeyEvent::KeyDown; break; +      case 8:  e->keycode = GUI::KeyEvent::KeyBackspace; break; +      case 46: e->keycode = GUI::KeyEvent::KeyDelete; break; +      case 36: e->keycode = GUI::KeyEvent::KeyHome; break; +      case 35: e->keycode = GUI::KeyEvent::KeyEnd; break; +      case 33: e->keycode = GUI::KeyEvent::KeyPageUp; break; +      case 34: e->keycode = GUI::KeyEvent::KeyPageDown; break; +      case 13: e->keycode = GUI::KeyEvent::KeyEnter; break; +      default: e->keycode = GUI::KeyEvent::KeyUnknown; break;        }        e->text = "";        e->direction = GUI::KeyEvent::Up; @@ -185,7 +185,7 @@ LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)        //printf("WM_CHAR %d %d\n", (int)lp, (int)wp);        if(wp >= ' ') { // Filter control chars.          GUI::KeyEvent *e = new GUI::KeyEvent(); -        e->keycode = GUI::KeyEvent::KEY_CHARACTER; +        e->keycode = GUI::KeyEvent::KeyCharacter;          e->text += (char)wp;          e->direction = GUI::KeyEvent::Up;          native->event = e; diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index f199a07..b1c8fa7 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -484,26 +484,26 @@ Event* NativeWindowX11::getNextEvent()  		keyEvent->window_id = xevent.xkey.window;  		switch(xevent.xkey.keycode) { -		case 113: keyEvent->keycode = KeyEvent::KEY_LEFT; break; -		case 114: keyEvent->keycode = KeyEvent::KEY_RIGHT; break; -		case 111: keyEvent->keycode = KeyEvent::KEY_UP; break; -		case 116: keyEvent->keycode = KeyEvent::KEY_DOWN; break; -		case 119: keyEvent->keycode = KeyEvent::KEY_DELETE; break; -		case 22:  keyEvent->keycode = KeyEvent::KEY_BACKSPACE; break; -		case 110: keyEvent->keycode = KeyEvent::KEY_HOME; break; -		case 115: keyEvent->keycode = KeyEvent::KEY_END; break; -		case 117: keyEvent->keycode = KeyEvent::KEY_PGDOWN; break; -		case 112: keyEvent->keycode = KeyEvent::KEY_PGUP; break; -		case 36:  keyEvent->keycode = KeyEvent::KEY_ENTER; break; -		default:  keyEvent->keycode = KeyEvent::KEY_UNKNOWN; break; +		case 113: keyEvent->keycode = KeyEvent::KeyLeft; break; +		case 114: keyEvent->keycode = KeyEvent::KeyRight; break; +		case 111: keyEvent->keycode = KeyEvent::KeyUp; break; +		case 116: keyEvent->keycode = KeyEvent::KeyDown; break; +		case 119: keyEvent->keycode = KeyEvent::KeyDelete; break; +		case 22:  keyEvent->keycode = KeyEvent::KeyBackspace; break; +		case 110: keyEvent->keycode = KeyEvent::KeyHome; break; +		case 115: keyEvent->keycode = KeyEvent::KeyEnd; break; +		case 117: keyEvent->keycode = KeyEvent::KeyPageDown; break; +		case 112: keyEvent->keycode = KeyEvent::KeyPageUp; break; +		case 36:  keyEvent->keycode = KeyEvent::KeyEnter; break; +		default:  keyEvent->keycode = KeyEvent::KeyUnknown; break;  		}  		char stringBuffer[1024];  		int size = XLookupString(&xevent.xkey, stringBuffer,  		                         sizeof(stringBuffer), nullptr, nullptr); -		if(size && keyEvent->keycode == KeyEvent::KEY_UNKNOWN) +		if(size && keyEvent->keycode == KeyEvent::KeyUnknown)  		{ -			keyEvent->keycode = KeyEvent::KEY_CHARACTER; +			keyEvent->keycode = KeyEvent::KeyCharacter;  		}  		keyEvent->text.append(stringBuffer, size); diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 9bb451d..deb1309 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -38,52 +38,6 @@  namespace GUI { -FileBrowser *fb; -static void selectKitFile(void *ptr, std::string filename) -{ -  PluginGUI *gui = (PluginGUI*)ptr; - -  gui->lineedit->setText(filename); - -  fb->hide(); - -  std::string drumkit = gui->lineedit->text(); - -  gui->config->lastkit = drumkit; -  gui->config->save(); - -  gui->progress->setProgress(0); -  gui->progress->setState(ProgressBar::blue); - -  LoadDrumKitMessage *msg = new LoadDrumKitMessage(); -  msg->drumkitfile = drumkit; - -  msghandler.sendMessage(MSGRCV_ENGINE, msg); -} - -static void selectMapFile(void *ptr, std::string filename) -{ -  PluginGUI *gui = (PluginGUI*)ptr; - -  gui->lineedit2->setText(filename); -  fb->hide(); - -  std::string midimap = gui->lineedit2->text(); - -  gui->config->lastmidimap = midimap; -  gui->config->save(); - -  LoadMidimapMessage *msg = new LoadMidimapMessage(); -  msg->midimapfile = midimap; -  msghandler.sendMessage(MSGRCV_ENGINE, msg); - -  /* -  if(gui->changeMidimapHandler) -    gui->changeMidimapHandler(gui->changeMidimapPtr, midimap.c_str()); -  gui->progress2->setState(ProgressBar::green); -  */ -} -  /*  void closeClick(void *ptr)  { @@ -229,6 +183,47 @@ void PluginGUI::closeEventHandler()  	closing = true;  } +void PluginGUI::selectKitFile(const std::string& filename) +{ +	lineedit->setText(filename); + +	fileBrowser->hide(); + +	std::string drumkit = lineedit->text(); + +	config->lastkit = drumkit; +	config->save(); + +	progress->setProgress(0); +	progress->setState(ProgressBar::blue); + +	LoadDrumKitMessage *msg = new LoadDrumKitMessage(); +	msg->drumkitfile = drumkit; + +	msghandler.sendMessage(MSGRCV_ENGINE, msg); +} + +void PluginGUI::selectMapFile(const std::string& filename) +{ +	lineedit2->setText(filename); +	fileBrowser->hide(); + +	std::string midimap = lineedit2->text(); + +	config->lastmidimap = midimap; +	config->save(); + +	LoadMidimapMessage *msg = new LoadMidimapMessage(); +	msg->midimapfile = midimap; +	msghandler.sendMessage(MSGRCV_ENGINE, msg); + +	/* +	  if(gui->changeMidimapHandler) +	  gui->changeMidimapHandler(gui->changeMidimapPtr, midimap.c_str()); +	  gui->progress2->setState(ProgressBar::green); +	*/ +} +  void PluginGUI::init()  {    DEBUG(gui, "init"); @@ -380,12 +375,11 @@ void PluginGUI::init()      cmb->resize(70, 30);    }    */ -  // Create filebrowser -  filebrowser = new FileBrowser(window); -  filebrowser->move(0, 0); -  filebrowser->resize(window->width() - 1, window->height() - 1); -  filebrowser->hide(); -  fb = filebrowser; +  // Create file browser +  fileBrowser = new FileBrowser(window); +  fileBrowser->move(0, 0); +  fileBrowser->resize(window->width() - 1, window->height() - 1); +  fileBrowser->hide();    // Enable quit button  //  Button *btn_quit = new Button(window); @@ -490,9 +484,9 @@ void PluginGUI::kitBrowseClick()  		path = lineedit2->text();  	} -	fb->setPath(path); -	fb->registerFileSelectHandler(selectKitFile, this); -	fb->show(); +	fileBrowser->setPath(path); +	CONNECT(fileBrowser, fileSelectNotifier, this, &PluginGUI::selectKitFile); +	fileBrowser->show();  }  void PluginGUI::midimapBrowseClick() @@ -508,9 +502,9 @@ void PluginGUI::midimapBrowseClick()  		path = lineedit->text();  	} -	fb->setPath(path); -	fb->registerFileSelectHandler(selectMapFile, this); -	fb->show(); +	fileBrowser->setPath(path); +	CONNECT(fileBrowser, fileSelectNotifier, this, &PluginGUI::selectMapFile); +	fileBrowser->show();  }  } // GUI:: diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index 52cd8d2..5e617dc 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -68,8 +68,6 @@ public:    Window *window;    EventHandler *eventhandler; -  FileBrowser *filebrowser; -    Label *lbl;    LineEdit *lineedit;    ProgressBar *progress; @@ -93,11 +91,14 @@ private:  	void kitBrowseClick();  	void midimapBrowseClick();  	void closeEventHandler(); +	void selectKitFile(const std::string& filename); +	void selectMapFile(const std::string& filename);    // Humanized velocity controls: -  CheckBox *velocityCheck; -  Knob *attackKnob; -  Knob *falloffKnob; +  CheckBox* velocityCheck; +  Knob* attackKnob; +  Knob* falloffKnob; +	FileBrowser* fileBrowser;    volatile bool running;    volatile bool closing; | 
