2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* scrollview.cpp - Shows client widgets in a scroll area *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2021-02-09 22:01:21 +01:00
|
|
|
* Copyright 2017-2021 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
// class Scrollview
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Scrollview final : public finalcut::FScrollView
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Scrollview (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Scrollview (const Scrollview&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~Scrollview() override = default;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
Scrollview& operator = (const Scrollview&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Mutator
|
2019-01-21 03:42:18 +01:00
|
|
|
void setScrollSize (const FSize&) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
2021-03-28 23:19:01 +02:00
|
|
|
// Methods
|
|
|
|
void initLayout() override;
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_goEast();
|
|
|
|
void cb_goSouth();
|
|
|
|
void cb_goWest();
|
|
|
|
void cb_goNorth();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2020-12-31 20:45:10 +01:00
|
|
|
finalcut::UniChar pointer_right{finalcut::UniChar::BlackRightPointingPointer};
|
|
|
|
finalcut::UniChar pointer_down{finalcut::UniChar::BlackDownPointingTriangle};
|
|
|
|
finalcut::UniChar pointer_left{finalcut::UniChar::BlackLeftPointingPointer};
|
|
|
|
finalcut::UniChar pointer_up{finalcut::UniChar::BlackUpPointingTriangle};
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FButton go_east{pointer_right, this};
|
|
|
|
finalcut::FButton go_south{pointer_down, this};
|
|
|
|
finalcut::FButton go_west{pointer_left, this};
|
|
|
|
finalcut::FButton go_north{pointer_up, this};
|
2017-01-02 08:07:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Scrollview::Scrollview (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FScrollView{parent}
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Add scroll function callbacks to the buttons
|
2018-10-03 22:23:55 +02:00
|
|
|
go_east.addCallback
|
2017-01-22 23:04:40 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Scrollview::cb_goEast
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
go_south.addCallback
|
2017-01-22 23:04:40 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Scrollview::cb_goSouth
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
go_west.addCallback
|
2017-01-22 23:04:40 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Scrollview::cb_goWest
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
go_north.addCallback
|
2017-01-22 23:04:40 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Scrollview::cb_goNorth
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2021-03-28 23:19:01 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Scrollview::initLayout()
|
|
|
|
{
|
|
|
|
// Sets the navigation button geometry
|
|
|
|
go_east.setGeometry (FPoint{1, 1}, FSize{5, 1});
|
|
|
|
go_south.setGeometry ( FPoint{int(getScrollWidth()) - 5, 1}
|
|
|
|
, FSize{5, 1} );
|
|
|
|
go_west.setGeometry ( FPoint{ int(getScrollWidth()) - 5
|
|
|
|
, int(getScrollHeight()) - 2 }
|
|
|
|
, FSize{5, 1} );
|
|
|
|
go_north.setGeometry ( FPoint{1, int(getScrollHeight()) - 2}
|
|
|
|
, FSize{5, 1} );
|
|
|
|
FScrollView::initLayout();
|
|
|
|
}
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void Scrollview::setScrollSize (const FSize& size)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
2019-01-21 03:42:18 +01:00
|
|
|
FScrollView::setScrollSize (size);
|
2020-10-04 02:55:15 +02:00
|
|
|
const auto width = int(size.getWidth());
|
|
|
|
const auto height = int(size.getHeight());
|
2020-05-02 00:07:35 +02:00
|
|
|
go_south.setPos (FPoint{width - 5, 1});
|
|
|
|
go_west.setPos (FPoint{width - 5, height - 1});
|
|
|
|
go_north.setPos (FPoint{1, height - 1});
|
2017-01-22 23:04:40 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
void Scrollview::draw()
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::isMonochron() )
|
2017-01-28 23:20:38 +01:00
|
|
|
setReverse(true);
|
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setColor (wc->label_inactive_fg, wc->dialog_bg);
|
2017-01-02 08:07:46 +01:00
|
|
|
clearArea();
|
|
|
|
|
2020-10-25 01:21:45 +02:00
|
|
|
for (auto y{0}; y < int(getScrollHeight()); y++)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1 + y};
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2020-10-25 01:21:45 +02:00
|
|
|
for (auto x{0}; x < int(getScrollWidth()); x++)
|
2017-01-02 08:07:46 +01:00
|
|
|
print (32 + ((x + y) % 0x5f));
|
|
|
|
}
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( finalcut::FTerm::isMonochron() )
|
2017-01-28 23:20:38 +01:00
|
|
|
setReverse(false);
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
FScrollView::draw();
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Scrollview::cb_goEast()
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
scrollToX (int(getScrollWidth() - getViewportWidth()) + 1);
|
2018-10-03 22:23:55 +02:00
|
|
|
go_south.setFocus();
|
|
|
|
go_east.redraw();
|
|
|
|
go_south.redraw();
|
2017-01-22 23:04:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Scrollview::cb_goSouth()
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
scrollToY (int(getScrollHeight() - getViewportHeight()) + 1);
|
2018-10-03 22:23:55 +02:00
|
|
|
go_west.setFocus();
|
|
|
|
go_south.redraw();
|
|
|
|
go_west.redraw();
|
2017-01-22 23:04:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Scrollview::cb_goWest()
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToX (1);
|
2018-10-03 22:23:55 +02:00
|
|
|
go_north.setFocus();
|
|
|
|
go_west.redraw();
|
|
|
|
go_north.redraw();
|
2017-01-28 22:03:15 +01:00
|
|
|
}
|
2017-01-22 23:04:40 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Scrollview::cb_goNorth()
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToY (1);
|
2018-10-03 22:23:55 +02:00
|
|
|
go_east.setFocus();
|
|
|
|
go_north.redraw();
|
|
|
|
go_east.redraw();
|
2017-01-22 23:04:40 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
// class Scrollviewdemo
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Scrollviewdemo final : public finalcut::FDialog
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Scrollviewdemo (finalcut::FWidget* = nullptr);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-11-24 21:06:39 +01:00
|
|
|
~Scrollviewdemo() override = default;
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2021-03-28 23:19:01 +02:00
|
|
|
private:
|
|
|
|
// Method
|
|
|
|
void initLayout() override;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
2019-08-06 23:45:28 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Callback method
|
2020-08-16 02:01:47 +02:00
|
|
|
void cb_quit();
|
2018-10-03 22:23:55 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
Scrollview sview{this};
|
|
|
|
finalcut::FButton quit_btn{"&Quit", this};
|
|
|
|
finalcut::FLabel label{this};
|
2017-01-02 08:07:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
// Quit button
|
2020-05-02 00:07:35 +02:00
|
|
|
quit_btn.setGeometry(FPoint{37, 15}, FSize{10, 1});
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
// Add function callback
|
2018-10-03 22:23:55 +02:00
|
|
|
quit_btn.addCallback
|
2017-01-02 08:07:46 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-16 02:01:47 +02:00
|
|
|
this,
|
|
|
|
&Scrollviewdemo::cb_quit
|
2017-01-02 08:07:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Text label
|
2020-05-02 00:07:35 +02:00
|
|
|
label.setGeometry(FPoint{2, 1}, FSize{46, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
label.setEmphasis();
|
|
|
|
label << L"Use scrollbars to change the viewport position";
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2021-03-28 23:19:01 +02:00
|
|
|
void Scrollviewdemo::initLayout()
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2021-03-28 23:19:01 +02:00
|
|
|
FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19});
|
|
|
|
FDialog::setText ("Scrolling viewport example");
|
|
|
|
|
|
|
|
// The scrolling viewport widget
|
|
|
|
sview.setGeometry(FPoint{3, 2}, FSize{44, 12});
|
|
|
|
sview.setScrollSize(FSize{188, 124});
|
|
|
|
FDialog::initLayout();
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollviewdemo::onClose (finalcut::FCloseEvent* ev)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
2021-03-28 23:19:01 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Scrollviewdemo::cb_quit()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Create the application object
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FApplication app{argc, argv};
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
// Create a simple dialog box
|
2020-05-02 00:07:35 +02:00
|
|
|
Scrollviewdemo svdemo{&app};
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog main_dlg as main widget
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget(&svdemo);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2017-01-02 08:07:46 +01:00
|
|
|
svdemo.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|