# data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cc}
comment {Copyright 2011, Alan Calvert
Copyright 2015-2021, Will Godfrey

This file is part of yoshimi, which 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.

yoshimi 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 yoshimi.  If not, see <http://www.gnu.org/licenses/>.

} {in_source in_header
}

decl {\#include <set>} {public local
}

decl {\#include <string>} {public local
}

decl {\#include "FL/Fl_Text_Display.H"} {public local
}

decl {\#include "UI/MiscGui.h"} {public local
}

decl {using namespace std;} {public local
}

decl {\#include "Misc/Config.h"} {private global
}

decl {\#include "MasterUI.h"} {private global
}

class ConsoleTextDisplay {: {public Fl_Text_Display}
} {
  Function {ConsoleTextDisplay(int x, int y, int w, int h, char* l = 0) : Fl_Text_Display(x,y,w,h,l)} {} {
    code {// empty //} {}
  }
  Function {scroll_to_last_line()} {return_type void
  } {
    code {//
   if (mVScrollBar->visible() &&
       mVScrollBar->value() > mNBufferLines - mNVisibleLines)
    {
        insert_position(mBuffer->length());
        show_insert_position();
    }} {}
  }
}

class ConsoleUI {open
} {
  Function {make_window(void)} {} {
    Fl_Window logConsole {
      label {yoshimi console}
      callback {//
    o->hide();}
      xywh {397 70 385 185} type Double color 54 selection_color 36 labelsize 13 align 0 when 1 hide resizable
      code0 {logDW = 385;logDH = 185;}
      code1 {o->size_range(logDW,logDH);}
    } {
      Fl_Text_Display logText {
        xywh {0 0 385 185} color 54 labeltype NO_LABEL labelsize 13 when 1 textfont 4 textsize 12 textcolor 35 resizable
        class ConsoleTextDisplay
      }
    }
  }
  Function {ConsoleUI(SynthEngine *_synth)} {open
  } {
    code {//
    synth = _synth;
    bufsize = 8192;
    make_window();
    txtbuf = new Fl_Text_Buffer(bufsize);
    lastlogW = 0;
    textSize = 12;
    logText->buffer(txtbuf);
    setLogText(synth->getRuntime().consoleTextSize);} {selected
    }
  }
  Function {~ConsoleUI()} {} {
    code {//
      if (logConsole->visible())
      {
          saveWin(synth, logConsole->w(), logConsole->h(), logConsole->x(), logConsole->y(), 1, "System-log");
      }
      else
      {
           int fetchW, fetchH, fetchX, fetchY, fetchO;
           loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "System-log");
           saveWin(synth, fetchW, fetchH, fetchX, fetchY, 0, "System-log");
      }
      logConsole->hide();
      delete logConsole;} {}
  }
  Function {log(string msg)} {} {
    code {//
    msg += "\\n";
    txtbuf->append(msg.c_str());
    //Scroll to show last line unless manually scrolled elsewhere before
    logText->scroll_to_last_line();
    if (txtbuf->length() > (bufsize - 256))
        txtbuf->remove(0, txtbuf->line_end(256));} {}
  }
  Function {Show(SynthEngine *synth)} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "System-log");
    if (fetchW < logDW || fetchH < logDH)
    {
        fetchW = logDW;
        fetchH = logDH;
    }

    // can't use checkSane() here w/h are independent
    int maxW = Fl::w() - 5; // wiggle room
    int maxH = Fl::h() - 30; // space for minimal titlebar

    if ((fetchX + fetchW) > maxW) // postion
        fetchX = maxW / 2;
    if ((fetchY + fetchH) > maxH)
        fetchY = maxH / 2;

    if(fetchW > maxW)
        fetchW = maxW;
    if(fetchH > maxH / 2) // sensible max height
        fetchH = maxH / 2;

    logConsole->resize(fetchX, fetchY, fetchW, fetchH);
    lastlogW = 0;
    logConsole->show();} {}
  }
  Function {Hide(SynthEngine *synth)} {} {
    code {//

      if (logConsole->visible())
      {
          saveWin(synth, logConsole->w(), logConsole->h(), logConsole->x(), logConsole->y(), 0, "System-log");
      }
      else
      {
           int fetchW, fetchH, fetchX, fetchY, fetchO;
           loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "System-log");
           saveWin(synth, fetchW, fetchH, fetchX, fetchY, 0, "System-log");
      }

      logConsole->hide();} {}
  }
  Function {setLogText(int size)} {} {
    code {//

            lastlogW = 0;
            textSize = size;} {}
  }
  Function {consoleRtext()} {} {
    code {//
    if (lastlogW == logConsole->w())
        return;
    lastlogW = logConsole->w();

    saveWin(synth, logConsole->w(), logConsole->h(), logConsole->x(), logConsole->y(), 1, "System-log");
    logText->textsize(textSize);
    logConsole->redraw();} {}
  }
  decl {Fl_Text_Buffer *txtbuf;} {private local
  }
  decl {int bufsize;} {private local
  }
  decl {float logDW;} {private local
  }
  decl {float logDH;} {private local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int lastlogW;} {public local
  }
  decl {int textSize;} {private local
  }
}
