2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* scrollview.cpp - Shows client widgets in a scroll area *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-09-20 23:59:01 +02:00
|
|
|
* Copyright 2017-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The 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 *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut 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 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
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class Scrollview : public finalcut::FScrollView
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-09-20 23:59:01 +02:00
|
|
|
explicit Scrollview (finalcut::FWidget* = 0);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Destructor
|
2017-10-02 07:32:33 +02:00
|
|
|
~Scrollview ();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutator
|
|
|
|
void setScrollSize (int, int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
2017-10-02 07:32:33 +02:00
|
|
|
Scrollview (const Scrollview&);
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable assignment operator (=)
|
2017-10-02 07:32:33 +02:00
|
|
|
Scrollview& operator = (const Scrollview&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Method
|
|
|
|
void draw();
|
|
|
|
|
|
|
|
// Callback methods
|
2018-09-20 23:59:01 +02:00
|
|
|
void cb_go_east (finalcut::FWidget*, data_ptr);
|
|
|
|
void cb_go_south (finalcut::FWidget*, data_ptr);
|
|
|
|
void cb_go_west (finalcut::FWidget*, data_ptr);
|
|
|
|
void cb_go_north (finalcut::FWidget*, data_ptr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Members
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FButton* go_east;
|
|
|
|
finalcut::FButton* go_south;
|
|
|
|
finalcut::FButton* go_west;
|
|
|
|
finalcut::FButton* go_north;
|
2017-01-02 08:07:46 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Scrollview::Scrollview (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FScrollView(parent)
|
2017-03-08 23:48:30 +01:00
|
|
|
, go_east()
|
|
|
|
, go_south()
|
|
|
|
, go_west()
|
|
|
|
, go_north()
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the four navigation buttons
|
2018-09-20 23:59:01 +02:00
|
|
|
wchar_t pointer_right = wchar_t(finalcut::fc::BlackRightPointingPointer);
|
|
|
|
go_east = new finalcut::FButton(pointer_right, this);
|
2017-01-22 23:04:40 +01:00
|
|
|
go_east->setGeometry (1, 1, 5, 1);
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
wchar_t pointer_down = wchar_t(finalcut::fc::BlackDownPointingTriangle);
|
|
|
|
go_south = new finalcut::FButton(pointer_down, this);
|
2017-01-22 23:04:40 +01:00
|
|
|
go_south->setGeometry (getScrollWidth() - 5, 1, 5, 1);
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
wchar_t pointer_left = wchar_t(finalcut::fc::BlackLeftPointingPointer);
|
|
|
|
go_west = new finalcut::FButton(pointer_left, this);
|
2017-01-22 23:04:40 +01:00
|
|
|
go_west->setGeometry (getScrollWidth() - 5, getScrollHeight() - 2, 5, 1);
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
wchar_t pointer_up = wchar_t(finalcut::fc::BlackUpPointingTriangle);
|
|
|
|
go_north = new finalcut::FButton(pointer_up, this);
|
2017-01-22 23:04:40 +01:00
|
|
|
go_north->setGeometry (1, getScrollHeight() - 2, 5, 1);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Add scroll function callbacks to the buttons
|
2017-01-22 23:04:40 +01:00
|
|
|
go_east->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-10-02 07:32:33 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Scrollview::cb_go_east)
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
go_south->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-10-02 07:32:33 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Scrollview::cb_go_south)
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
go_west->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-10-02 07:32:33 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Scrollview::cb_go_west)
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
go_north->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-10-02 07:32:33 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Scrollview::cb_go_north)
|
2017-01-22 23:04:40 +01:00
|
|
|
);
|
|
|
|
}
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
Scrollview::~Scrollview()
|
2017-01-02 08:07:46 +01:00
|
|
|
{ }
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
void Scrollview::setScrollSize (int width, int height)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
FScrollView::setScrollSize (width, height);
|
|
|
|
go_south->setPos (width - 5, 1);
|
|
|
|
go_west->setPos (width - 5, height - 1);
|
|
|
|
go_north->setPos (1, height - 1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-01-28 23:20:38 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
setColor (wc.label_inactive_fg, wc.dialog_bg);
|
2017-01-02 08:07:46 +01:00
|
|
|
clearArea();
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int y = 0; y < getScrollHeight(); y++)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
setPrintPos (1, 1 + y);
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int x = 0; x < getScrollWidth(); x++)
|
2017-01-02 08:07:46 +01:00
|
|
|
print (32 + ((x + y) % 0x5f));
|
|
|
|
}
|
|
|
|
|
2017-01-28 23:20:38 +01:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
FScrollView::draw();
|
|
|
|
}
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollview::cb_go_east (finalcut::FWidget*, data_ptr)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToX (getScrollWidth() - getViewportWidth() + 1);
|
|
|
|
go_south->setFocus();
|
|
|
|
go_east->redraw();
|
|
|
|
go_south->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollview::cb_go_south (finalcut::FWidget*, data_ptr)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToY (getScrollHeight() - getViewportHeight() + 1);
|
|
|
|
go_west->setFocus();
|
|
|
|
go_south->redraw();
|
|
|
|
go_west->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollview::cb_go_west (finalcut::FWidget*, data_ptr)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToX (1);
|
|
|
|
go_north->setFocus();
|
|
|
|
go_west->redraw();
|
2017-01-28 22:03:15 +01:00
|
|
|
go_north->redraw();
|
|
|
|
}
|
2017-01-22 23:04:40 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollview::cb_go_north (finalcut::FWidget*, data_ptr)
|
2017-01-22 23:04:40 +01:00
|
|
|
{
|
|
|
|
scrollToY (1);
|
|
|
|
go_east->setFocus();
|
|
|
|
go_north->redraw();
|
|
|
|
go_east->redraw();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class Scrollviewdemo : public finalcut::FDialog
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-09-20 23:59:01 +02:00
|
|
|
explicit Scrollviewdemo (finalcut::FWidget* = 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2017-12-30 21:27:17 +01:00
|
|
|
~Scrollviewdemo();
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
2018-09-20 23:59:01 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Callback method
|
2018-09-20 23:59:01 +02:00
|
|
|
void cb_quit (finalcut::FWidget* = 0, data_ptr = 0);
|
2017-01-02 08:07:46 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FDialog(parent)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
setGeometry (16, 3, 50, 19);
|
|
|
|
setText ("Scrolling viewport example");
|
|
|
|
|
|
|
|
// The scrolling viewport widget
|
2017-10-02 07:32:33 +02:00
|
|
|
Scrollview* sview = new Scrollview (this);
|
2017-01-02 08:07:46 +01:00
|
|
|
sview->setGeometry(3, 2, 44, 12);
|
2017-01-22 23:04:40 +01:00
|
|
|
sview->setScrollSize(188, 124);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
// Quit button
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FButton* button = new finalcut::FButton("&Quit", this);
|
2017-01-02 08:07:46 +01:00
|
|
|
button->setGeometry(37, 15, 10, 1);
|
|
|
|
|
|
|
|
// Add function callback
|
|
|
|
button->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-10-02 07:32:33 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Scrollviewdemo::cb_quit)
|
2017-01-02 08:07:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Text label
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FLabel* label = new finalcut::FLabel (this);
|
2017-01-02 08:07:46 +01:00
|
|
|
label->setGeometry(2, 1, 46, 1);
|
|
|
|
label->setEmphasis();
|
2017-09-20 05:44:41 +02:00
|
|
|
*label << L"Use scrollbars to change the viewport position";
|
2017-01-02 08:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
Scrollviewdemo::~Scrollviewdemo()
|
2017-01-02 08:07:46 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Scrollviewdemo::cb_quit (finalcut::FWidget*, data_ptr)
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Create the application object
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication app(argc, argv);
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
// Create a simple dialog box
|
2017-10-02 07:32:33 +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
|
2017-01-02 08:07:46 +01:00
|
|
|
app.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();
|
|
|
|
}
|