diff options
| -rw-r--r-- | plugingui/Makefile.am | 2 | ||||
| -rw-r--r-- | plugingui/Makefile.am.plugingui | 4 | ||||
| -rw-r--r-- | plugingui/Makefile.mingw32 | 2 | ||||
| -rw-r--r-- | plugingui/lineedit.cc | 73 | ||||
| -rw-r--r-- | plugingui/lineedit.h | 9 | ||||
| -rw-r--r-- | plugingui/pluginconfig.cc | 165 | ||||
| -rw-r--r-- | plugingui/pluginconfig.h | 48 | ||||
| -rw-r--r-- | plugingui/plugingui.cc | 9 | 
8 files changed, 85 insertions, 227 deletions
| diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 32228f4..3d09bb2 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -26,7 +26,6 @@ EXTRA_DIST = \  	button.h \  	checkbox.h \  	colour.h \ -	pluginconfig.h \  	combobox.h \  	directory.h \  	eventhandler.h \ @@ -47,6 +46,7 @@ EXTRA_DIST = \  	nativewindow_x11.h \  	painter.h \  	pixelbuffer.h \ +	pluginconfig.h \  	plugingui.h \  	progressbar.h \  	resource.h \ diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index bd703b2..b1698e4 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -1,4 +1,6 @@ +puglsources = +  PLUGIN_GUI_SOURCES = \  	$(top_srcdir)/hugin/hugin.c \  	$(top_srcdir)/hugin/hugin_syslog.c \ @@ -26,11 +28,11 @@ PLUGIN_GUI_SOURCES = \  	$(top_srcdir)/plugingui/knob.cc \  	$(top_srcdir)/plugingui/filebrowser.cc \  	$(top_srcdir)/plugingui/directory.cc \ +	$(top_srcdir)/plugingui/pluginconfig.cc \  	$(top_srcdir)/plugingui/image.cc \  	$(top_srcdir)/plugingui/combobox.cc \  	$(top_srcdir)/plugingui/progressbar.cc \  	$(top_srcdir)/plugingui/verticalline.cc \ -	$(top_srcdir)/plugingui/pluginconfig.cc \  	$(top_srcdir)/plugingui/resource.cc \  	$(top_srcdir)/plugingui/resource_data.cc \  	$(top_srcdir)/plugingui/lodepng/lodepng.cpp diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32 index 7863463..b16535b 100644 --- a/plugingui/Makefile.mingw32 +++ b/plugingui/Makefile.mingw32 @@ -13,6 +13,7 @@ CXX_SOURCES = \  	$(top_srcdir)/plugingui/nativewindow_x11.cc \  	$(top_srcdir)/plugingui/nativewindow_win32.cc \  	$(top_srcdir)/plugingui/plugingui.cc \ +	$(top_srcdir)/plugingui/pluginconfig.cc \  	$(top_srcdir)/plugingui/label.cc \  	$(top_srcdir)/plugingui/eventhandler.cc \  	$(top_srcdir)/plugingui/font.cc \ @@ -40,7 +41,6 @@ CXX_SOURCES = \  	$(top_srcdir)/plugingui/resource.cc \  	$(top_srcdir)/plugingui/resource_data.cc \  	$(top_srcdir)/plugingui/lodepng/lodepng.cpp \ -	$(top_srcdir)/plugingui/pluginconfig.cc \  	$(top_srcdir)/src/thread.cc \  	$(top_srcdir)/src/semaphore.cc \  	$(top_srcdir)/src/mutex.cc \ diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc index d6e717a..46354bb 100644 --- a/plugingui/lineedit.cc +++ b/plugingui/lineedit.cc @@ -30,6 +30,8 @@  #include "window.h" +#include <assert.h> +  #include <hugin.hpp>  #define BORDER 10 @@ -38,6 +40,7 @@ GUI::LineEdit::LineEdit(Widget *parent)    : GUI::Widget(parent)  {    pos = 0; +  offsetpos = 0;    setReadOnly(false);    box.topLeft     = new Image(":widget_tl.png"); @@ -72,7 +75,8 @@ bool GUI::LineEdit::readOnly()  void GUI::LineEdit::setText(std::string text)  {    _text = text; -  if(_text.size() < pos) pos = text.size(); +  pos = text.size(); +//  if(_text.size() < pos) pos = text.size();    repaintEvent(NULL);    textChanged(); @@ -87,14 +91,16 @@ void GUI::LineEdit::buttonEvent(ButtonEvent *e)  {    if(readOnly()) return; +    if(e->direction == 1) { -    for(int i = 0; i < (int)_text.length(); i++) { -      if(e->x < (int)(font.textWidth(_text.substr(0, i)) + BORDER)) { -        pos = i; +    for(int i = 0; i < (int)_visibletext.length(); i++) { +      if(e->x < (int)(font.textWidth(_visibletext.substr(0, i)) + BORDER)) { +        printf("i, Offset: %d, %d\n", i, offsetpos); +        pos = i + offsetpos;          break;        }      } -    if(e->x >= (int)(font.textWidth(_text) + BORDER)) pos = _text.length(); +//    if(e->x >= (int)(font.textWidth(_visibletext) + BORDER)) pos = _visibletext.length();      repaintEvent(NULL);    }  } @@ -111,7 +117,9 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)      if(e->keycode == GUI::KeyEvent::KEY_LEFT) {        if(pos) pos--; - +      if(offsetpos >= pos) walkstate = WALK_LEFT; +//      else walkstate = NOOP; +          } else if(e->keycode == GUI::KeyEvent::KEY_HOME) {        pos = 0; @@ -120,7 +128,9 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)      } else if(e->keycode == GUI::KeyEvent::KEY_RIGHT) {        if(pos < _text.length()) pos++; - +      if(offsetpos + _visibletext.length() <= pos) walkstate = WALK_RIGHT; +//      else walkstate = NOOP; +          } else if(e->keycode == GUI::KeyEvent::KEY_DELETE) {        if(pos < _text.length()) {          std::string t = _text.substr(0, pos); @@ -144,6 +154,7 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)        _text = pre + e->text + post;        change = true;        pos++; +      } else if(e->keycode == GUI::KeyEvent::KEY_ENTER) {        if(handler) handler(ptr);      } @@ -165,12 +176,56 @@ void GUI::LineEdit::repaintEvent(GUI::RepaintEvent *e)    p.drawBox(0, 0, &box, w, h);    p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); -  p.drawText(BORDER - 4 + 3, height()/2+5 + 1 + 1 + 1, font, _text); + +  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 { +      DEBUG(lienedit, "Full text:              '%s'\n", _text.c_str()); +      DEBUG(lineedit, "Drawing text in lineedit '%s'\n", _visibletext.c_str()); +      DEBUG(lineedit, "Offset, pos: %d, %d\n", offsetpos, pos); +      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(_text.substr(0, pos)); +//    size_t px = font.textWidth(_text.substr(0, pos - offsetpos)); +    size_t px = font.textWidth(_visibletext.substr(0, pos - offsetpos));      //p.setColour(Colour(0.8));      p.drawLine(px + BORDER - 1 - 4 + 3, 6,                 px + BORDER - 1 - 4 + 3, height() - 7); diff --git a/plugingui/lineedit.h b/plugingui/lineedit.h index 2c37522..f85e9bd 100644 --- a/plugingui/lineedit.h +++ b/plugingui/lineedit.h @@ -65,6 +65,15 @@ private:    std::string _text;    size_t pos; +  std::string _visibletext; +  size_t offsetpos; + +  enum state_t { +    NOOP = 0, +    WALK_LEFT =  1,  +    WALK_RIGHT = 2 +  }; +  state_t walkstate;    bool readonly; diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc deleted file mode 100644 index d57d9df..0000000 --- a/plugingui/pluginconfig.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - *            config.cc - * - *  Tue Jun  3 13:54:05 CEST 2014 - *  Copyright 2014 Jonas Suhr Christensen - *  jsc@umbraculum.org - ****************************************************************************/ - -/* - *  This file is part of DrumGizmo. - * - *  DrumGizmo is free software; you can redistribute it and/or modify - *  it under the terms of the GNU General Public License as published by - *  the Free Software Foundation; either version 2 of the License, or - *  (at your option) any later version. - * - *  DrumGizmo is distributed in the hope that it will be useful, - *  but WITHOUT ANY WARRANTY; without even the implied warranty of - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - *  GNU General Public License for more details. - * - *  You should have received a copy of the GNU General Public License - *  along with DrumGizmo; if not, write to the Free Software - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. - */ -#include "pluginconfig.h" - -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -#include "directory.h" - -#ifdef WIN32 -#include <direct.h> -#include <windows.h> -#include <Shlobj.h> -#include <Shlwapi.h> -#else -#endif - -#include <hugin.hpp> -   -#define CONFIGFILENAME "plugingui.conf" - -#ifdef WIN32 -  #define SEP "\\" -  #define CONFIGDIRNAME ".drumgizmo" -#else -  #define SEP "/" -  #define CONFIGDIRNAME ".drumgizmo" -#endif - -Config::Config() -{ - -} - -Config::~Config() -{ - -} - -static std::string configPath() { - #ifdef WIN32 -  std::string configpath; -  TCHAR szPath[256]; -  if(SUCCEEDED(SHGetFolderPath(NULL, -                               CSIDL_APPDATA | CSIDL_FLAG_CREATE, -                               NULL, -                               0, -                               szPath))); { -    configpath = szPath; -  } -#else -  std::string configpath = strdup(getenv("HOME")); -#endif -  configpath += SEP; -  configpath += CONFIGDIRNAME; - -  return configpath; -} - -static bool createConfigPath() { -  std::string configpath = configPath(); - -  if(!Directory::exists(configpath)) { -    DEBUG(pluginconfig, "No configuration exists, creating directory '%s'\n", configpath.c_str()); -#ifdef WIN32 -    if( (mkdir(configpath.c_str())) < 0) {  -#else -    if( (mkdir(configpath.c_str(), 0755)) < 0) {  -#endif -      DEBUG(pluginconfig, "Could not create config directory\n"); -    } -    return false; -  } - -  return true; -} - -static FILE* openConfigFile(std::string mode) { - -  std::string configpath = configPath(); - -  FILE *fp; -  std::string configfile = configpath; -  configfile += SEP; -  configfile += CONFIGFILENAME; - -  DEBUG(pluginconfig, "Opening config file '%s'\n", configfile.c_str()); -  if(! (fp = fopen(configfile.c_str(), mode.c_str())) ) { -    return NULL; -  } - -  return fp; -} - -void Config::load() -{ -  DEBUG(pluginconfig, "Loading config file...\n"); -  FILE *fp = openConfigFile("r"); -  if(!fp) return; - -  lastkit.clear(); -  lastmidimap.clear(); - -  char buf[4096]; -  while( fgets(buf, 4096, fp) ) { -    if(!strncmp(buf, "lastkit:", 8)) { -      DEBUG(pluginconfig, "Loading last kit path\n"); -      // Dont copy newline -      if(strlen(buf) > 8 + 1) {  -        lastkit.append(buf+8, strlen(buf+8) - 1); -        DEBUG(pluginconfig, "\t path is %s\n", lastkit.c_str()); -      } -    } -    if(!strncmp(buf, "lastmidimap:", 12)) { -      DEBUG(pluginconfig, "Loading lastmidimap path\n"); -      // Dont copy newline -      if(strlen(buf) > 12+1) lastmidimap.append(buf+12, strlen(buf+12) - 1); -      DEBUG(pluginconfig, "\t path is %s\n", lastmidimap.c_str()); -    } -  } -} - -void Config::save() -{ -  DEBUG(pluginconfig, "Saving configuration...\n"); - -  createConfigPath(); - -  FILE *fp = openConfigFile("w"); -  if(!fp) return; - -  std::string buf; -  buf.append("lastkit:" + lastkit + '\n'); -  buf.append("lastmidimap:" + lastmidimap + '\n'); - -  fputs(buf.c_str(), fp); - -  fclose(fp); -} diff --git a/plugingui/pluginconfig.h b/plugingui/pluginconfig.h deleted file mode 100644 index d0e9bcd..0000000 --- a/plugingui/pluginconfig.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - *            config.h - * - *  Tue Jun  3 13:51:29 CEST 2014 - *  Copyright 2014 Jonas Suhr Christensen - *  jsc@umbraculum.org - ****************************************************************************/ - -/* - *  This file is part of DrumGizmo. - * - *  DrumGizmo is free software; you can redistribute it and/or modify - *  it under the terms of the GNU General Public License as published by - *  the Free Software Foundation; either version 2 of the License, or - *  (at your option) any later version. - * - *  DrumGizmo is distributed in the hope that it will be useful, - *  but WITHOUT ANY WARRANTY; without even the implied warranty of - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - *  GNU General Public License for more details. - * - *  You should have received a copy of the GNU General Public License - *  along with DrumGizmo; if not, write to the Free Software - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. - */ -#ifndef __DRUMGIZMO_CONFIG_H__ -#define __DRUMGIZMO_CONFIG_H__ - -#include <string> -#include <list> - -#define DIRECTORY_HIDDEN 1 - -class Config { - -  public: -    Config(); -    ~Config(); - -    void load(); -    void save(); - -    std::string lastkit; -    std::string lastmidimap; -}; - -#endif/*__DRUMGIZMO_CONFIG_H__*/ diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index b235af3..f345660 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -94,11 +94,13 @@ 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(GUI::ProgressBar::blue); @@ -132,6 +134,7 @@ static void selectMapFile(void *ptr, std::string filename)    std::string midimap = gui->lineedit2->text();    gui->config->lastmidimap = midimap; +  gui->config->save();    LoadMidimapMessage *msg = new LoadMidimapMessage();    msg->midimapfile = midimap; @@ -334,7 +337,8 @@ void PluginGUI::init()      lineedit = new GUI::LineEdit(window);      lineedit->move(XOFFSET, y);      lineedit->resize(243, 29); -     +    lineedit->setReadOnly(true); +      GUI::Button *btn_brw = new GUI::Button(window);      btn_brw->setText("Browse...");      btn_brw->move(266, y - 6 + 4); @@ -364,7 +368,8 @@ void PluginGUI::init()      lineedit2 = new GUI::LineEdit(window);      lineedit2->move(XOFFSET, y);      lineedit2->resize(243, 29); -     +    lineedit2->setReadOnly(true); +      GUI::Button *btn_brw = new GUI::Button(window);      btn_brw->setText("Browse...");      btn_brw->move(266, y - 6 + 4); | 
