2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* mouse.cpp - A small mouse-controlled drawing program *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-03 07:36:18 +01:00
|
|
|
* Copyright 2017-2019 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-03-17 23:22:13 +01:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class ColorChooser
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class ColorChooser : public finalcut::FWidget
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit ColorChooser (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
ColorChooser (const ColorChooser&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
~ColorChooser();
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
ColorChooser& operator = (const ColorChooser&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor getForeground();
|
|
|
|
FColor getBackground();
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Method
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void draw() override;
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void onMouseDown (finalcut::FMouseEvent*) override;
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Data Members
|
2018-12-03 03:22:36 +01:00
|
|
|
FColor fg_color{finalcut::fc::White};
|
|
|
|
FColor bg_color{finalcut::fc::Black};
|
|
|
|
finalcut::FLabel headline{this};
|
2017-03-19 17:18:07 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
ColorChooser::ColorChooser (finalcut::FWidget* parent)
|
2017-03-19 17:18:07 +01:00
|
|
|
: FWidget(parent)
|
|
|
|
{
|
|
|
|
setSize (8, 12);
|
|
|
|
setFixedSize (8, 12);
|
|
|
|
unsetFocusable();
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
{
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg = parent->getForegroundColor();
|
|
|
|
FColor bg = parent->getBackgroundColor();
|
2018-10-03 22:23:55 +02:00
|
|
|
setForegroundColor(fg);
|
|
|
|
setBackgroundColor(bg);
|
|
|
|
headline.setForegroundColor(fg);
|
|
|
|
headline.setBackgroundColor(bg);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Text label
|
2018-10-03 22:23:55 +02:00
|
|
|
headline.setGeometry (1, 1, 8, 1);
|
|
|
|
headline.setEmphasis();
|
|
|
|
headline.setAlignment (finalcut::fc::alignCenter);
|
|
|
|
headline << "Color";
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ColorChooser::~ColorChooser()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void ColorChooser::onMouseDown (finalcut::FMouseEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( ev->getButton() == finalcut::fc::MiddleButton )
|
2017-03-19 17:18:07 +01:00
|
|
|
return;
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int c = 0; c < 16; c++)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
int xmin = 2 + (c / 8) * 3;
|
|
|
|
int xmax = 4 + (c / 8) * 3;
|
|
|
|
int y = 3 + c % 8;
|
|
|
|
|
|
|
|
if ( mouse_x >= xmin && mouse_x <= xmax && mouse_y == y )
|
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( ev->getButton() == finalcut::fc::LeftButton )
|
2018-11-13 02:51:41 +01:00
|
|
|
bg_color = FColor(c);
|
2018-09-20 23:59:01 +02:00
|
|
|
else if ( ev->getButton() == finalcut::fc::RightButton )
|
2018-11-13 02:51:41 +01:00
|
|
|
fg_color = FColor(c);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
emitCallback("clicked");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void ColorChooser::draw()
|
|
|
|
{
|
|
|
|
setColor();
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FWidget::drawBorder (1, 2, 8, 11);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-11-13 02:51:41 +01:00
|
|
|
for (FColor c = 0; c < 16; c++)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
setPrintPos (2 + (c / 8) * 3, 3 + c % 8);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
if ( c < 6 )
|
2018-09-20 23:59:01 +02:00
|
|
|
setColor (finalcut::fc::LightGray, c);
|
2017-03-19 17:18:07 +01:00
|
|
|
else if ( c > 8 )
|
2018-09-20 23:59:01 +02:00
|
|
|
setColor (finalcut::fc::DarkGray, c);
|
2017-03-19 17:18:07 +01:00
|
|
|
else
|
2018-09-20 23:59:01 +02:00
|
|
|
setColor (finalcut::fc::White, c);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
if ( c == bg_color )
|
|
|
|
{
|
|
|
|
print (' ');
|
2018-09-20 23:59:01 +02:00
|
|
|
print (finalcut::fc::Times);
|
2017-03-19 17:18:07 +01:00
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print (" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-13 02:51:41 +01:00
|
|
|
inline FColor ColorChooser::getForeground()
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
return fg_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-13 02:51:41 +01:00
|
|
|
inline FColor ColorChooser::getBackground()
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
return bg_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Brushes
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class Brushes : public finalcut::FWidget
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Brushes (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
Brushes (const Brushes&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
~Brushes();
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
Brushes& operator = (const Brushes&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessor
|
|
|
|
wchar_t getBrush();
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Mutators
|
2018-11-13 02:51:41 +01:00
|
|
|
void setForeground (FColor);
|
|
|
|
void setBackground (FColor);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Method
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void draw() override;
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handler
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void onMouseDown (finalcut::FMouseEvent*) override;
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Data Members
|
2018-12-03 03:22:36 +01:00
|
|
|
wchar_t brush{L' '};
|
|
|
|
FColor fg_color{finalcut::fc::White};
|
|
|
|
FColor bg_color{finalcut::fc::Black};
|
|
|
|
finalcut::FLabel headline{this};
|
2017-03-19 17:18:07 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Brushes::Brushes (finalcut::FWidget* parent)
|
2017-03-19 17:18:07 +01:00
|
|
|
: FWidget(parent)
|
|
|
|
{
|
|
|
|
setSize (8, 4);
|
|
|
|
setFixedSize (8, 4);
|
|
|
|
unsetFocusable();
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
{
|
2018-11-13 02:51:41 +01:00
|
|
|
FColor fg = parent->getForegroundColor();
|
|
|
|
FColor bg = parent->getBackgroundColor();
|
2018-10-03 22:23:55 +02:00
|
|
|
setForegroundColor(fg);
|
|
|
|
setBackgroundColor(bg);
|
|
|
|
headline.setForegroundColor(fg);
|
|
|
|
headline.setBackgroundColor(bg);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Text label
|
2018-10-03 22:23:55 +02:00
|
|
|
headline.setGeometry(1, 1, 8, 1);
|
|
|
|
headline.setEmphasis();
|
|
|
|
headline.setAlignment (finalcut::fc::alignCenter);
|
|
|
|
headline << "Brush";
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Brushes::~Brushes()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Brushes::draw()
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
setColor();
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FWidget::drawBorder (1, 2, 8, 4);
|
2017-03-19 17:18:07 +01:00
|
|
|
setColor (fg_color, bg_color);
|
|
|
|
setPrintPos (2, 3);
|
|
|
|
print(" ");
|
2018-12-06 02:28:24 +01:00
|
|
|
print(finalcut::FString(3, finalcut::fc::MediumShade));
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
if ( brush == L' ' )
|
|
|
|
pos = 0;
|
|
|
|
else
|
|
|
|
pos = 3;
|
|
|
|
|
|
|
|
setColor();
|
|
|
|
setPrintPos (3 + pos, 2);
|
2018-12-06 02:28:24 +01:00
|
|
|
print(finalcut::fc::BlackDownPointingTriangle);
|
2017-03-19 17:18:07 +01:00
|
|
|
setPrintPos (3 + pos, 4);
|
2018-12-06 02:28:24 +01:00
|
|
|
print(finalcut::fc::BlackUpPointingTriangle);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Brushes::onMouseDown (finalcut::FMouseEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
int mouse_x = ev->getX();
|
|
|
|
int mouse_y = ev->getY();
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( ev->getButton() != finalcut::fc::LeftButton )
|
2017-03-19 17:18:07 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( mouse_x >= 2 && mouse_x <= 4 && mouse_y == 3 )
|
|
|
|
{
|
|
|
|
brush = L' ';
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
else if ( mouse_x >= 5 && mouse_x <= 7 && mouse_y == 3 )
|
|
|
|
{
|
2018-12-06 02:28:24 +01:00
|
|
|
brush = finalcut::fc::MediumShade;
|
2017-03-19 17:18:07 +01:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline wchar_t Brushes::getBrush()
|
|
|
|
{
|
|
|
|
return brush;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-13 02:51:41 +01:00
|
|
|
inline void Brushes::setForeground (FColor color)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
fg_color = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-13 02:51:41 +01:00
|
|
|
inline void Brushes::setBackground (FColor color)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
bg_color = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class MouseDraw
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
class MouseDraw : public finalcut::FDialog
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit MouseDraw (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
MouseDraw (const MouseDraw&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
~MouseDraw();
|
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
MouseDraw& operator = (const MouseDraw&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2019-01-03 07:36:18 +01:00
|
|
|
void setGeometry (int, int, std::size_t, std::size_t, bool = true) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void onAccel (finalcut::FAccelEvent*) override;
|
|
|
|
virtual void onClose (finalcut::FCloseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void draw() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
void drawBrush (int, int, bool = false);
|
|
|
|
void drawCanvas();
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void adjustSize() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handler
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void onMouseDown (finalcut::FMouseEvent*) override;
|
|
|
|
virtual void onMouseMove (finalcut::FMouseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2018-12-27 00:14:46 +01:00
|
|
|
void cb_colorChanged (finalcut::FWidget*, FDataPtr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Members
|
2018-12-10 01:48:26 +01:00
|
|
|
term_area* canvas{nullptr};
|
2018-12-03 03:22:36 +01:00
|
|
|
ColorChooser c_chooser{this};
|
|
|
|
Brushes brush{this};
|
2017-03-19 17:18:07 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
MouseDraw::MouseDraw (finalcut::FWidget* parent)
|
|
|
|
: finalcut::FDialog(parent)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
setText ("Drawing with the mouse");
|
2018-10-03 22:23:55 +02:00
|
|
|
c_chooser.setPos (1, 1);
|
|
|
|
c_chooser.addCallback
|
2017-03-19 17:18:07 +01:00
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &MouseDraw::cb_colorChanged)
|
2017-03-19 17:18:07 +01:00
|
|
|
);
|
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
brush.setPos (1, 12);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-11-20 21:11:04 +01:00
|
|
|
finalcut::FPoint no_shadow(0, 0);
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FRect scroll_geometry(0, 0, 1, 1);
|
2017-03-19 17:18:07 +01:00
|
|
|
createArea (scroll_geometry, no_shadow, canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
MouseDraw::~MouseDraw()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-11-20 21:11:04 +01:00
|
|
|
void MouseDraw::setGeometry ( int x, int y
|
|
|
|
, std::size_t w, std::size_t h
|
|
|
|
, bool adjust )
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
int old_w, old_h;
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::setGeometry (x, y, w, h, adjust);
|
2018-11-20 21:11:04 +01:00
|
|
|
finalcut::FPoint no_shadow(0, 0);
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FRect scroll_geometry (0, 0, w - 11, h - 3);
|
2017-03-19 17:18:07 +01:00
|
|
|
old_w = canvas->width;
|
|
|
|
old_h = canvas->height;
|
|
|
|
resizeArea (scroll_geometry, no_shadow, canvas);
|
|
|
|
|
|
|
|
if ( old_w != canvas->width || old_h != canvas->height )
|
|
|
|
{
|
|
|
|
setColor(getForegroundColor(), getBackgroundColor());
|
|
|
|
clearArea (canvas, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MouseDraw::onAccel (finalcut::FAccelEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MouseDraw::onClose (finalcut::FCloseEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MouseDraw::draw()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
int y_max = int(getHeight());
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::draw();
|
2017-03-19 17:18:07 +01:00
|
|
|
setColor();
|
2017-11-18 02:34:41 +01:00
|
|
|
|
2017-11-03 05:04:27 +01:00
|
|
|
if ( isNewFont() )
|
|
|
|
{
|
|
|
|
for (int y = 2; y < y_max; y++)
|
|
|
|
{
|
|
|
|
setPrintPos (10, y);
|
2018-12-06 02:28:24 +01:00
|
|
|
print (finalcut::fc::NF_rev_border_line_right);
|
2017-11-03 05:04:27 +01:00
|
|
|
}
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-11-03 05:04:27 +01:00
|
|
|
setPrintPos (10, y_max);
|
2018-12-06 02:28:24 +01:00
|
|
|
print (finalcut::fc::NF_rev_border_corner_lower_right);
|
2017-11-03 05:04:27 +01:00
|
|
|
}
|
|
|
|
else
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2017-11-03 05:04:27 +01:00
|
|
|
setPrintPos (10, 2);
|
2018-12-06 02:28:24 +01:00
|
|
|
print (finalcut::fc::BoxDrawingsDownAndHorizontal);
|
2017-11-03 05:04:27 +01:00
|
|
|
|
|
|
|
for (int y = 3; y < y_max; y++)
|
|
|
|
{
|
|
|
|
setPrintPos (10, y);
|
2018-12-06 02:28:24 +01:00
|
|
|
print (finalcut::fc::BoxDrawingsVertical);
|
2017-11-03 05:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setPrintPos (10, y_max);
|
2018-12-06 02:28:24 +01:00
|
|
|
print (finalcut::fc::BoxDrawingsUpAndHorizontal);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
drawCanvas();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MouseDraw::drawBrush (int x, int y, bool swap_color)
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
int Cols = int(getWidth());
|
|
|
|
int Lines = int(getHeight());
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
if ( x > 10 && x < Cols && y > 2 && y < Lines )
|
|
|
|
{
|
|
|
|
if ( swap_color )
|
2018-10-03 22:23:55 +02:00
|
|
|
setColor (c_chooser.getBackground(), c_chooser.getForeground());
|
2017-03-19 17:18:07 +01:00
|
|
|
else
|
2018-10-03 22:23:55 +02:00
|
|
|
setColor (c_chooser.getForeground(), c_chooser.getBackground());
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
// set canvas print cursor position
|
|
|
|
canvas->cursor_x = x - canvas->offset_left - 10;
|
|
|
|
canvas->cursor_y = y - canvas->offset_top - 2;
|
|
|
|
// print on canvas
|
2018-10-03 22:23:55 +02:00
|
|
|
print (canvas, brush.getBrush());
|
2017-03-19 17:18:07 +01:00
|
|
|
// copy canvas to the dialog
|
|
|
|
drawCanvas();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MouseDraw::drawCanvas()
|
|
|
|
{
|
|
|
|
if ( ! hasPrintArea() )
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FVTerm::getPrintArea();
|
2017-03-19 17:18:07 +01:00
|
|
|
|
|
|
|
if ( ! (hasPrintArea() && canvas) )
|
|
|
|
return;
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
int ax = 9 + getTermX() - print_area->offset_left
|
|
|
|
, ay = 1 + getTermY() - print_area->offset_top
|
|
|
|
, y_end = canvas->height
|
|
|
|
, x_end = canvas->width
|
|
|
|
, w_line_len = print_area->width + print_area->right_shadow;
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int y = 0; y < y_end; y++) // line loop
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2018-09-02 03:57:57 +02:00
|
|
|
charData* canvaschar; // canvas character
|
|
|
|
charData* winchar; // window character
|
|
|
|
canvaschar = &canvas->text[y * x_end];
|
|
|
|
winchar = &print_area->text[(ay + y) * w_line_len + ax];
|
|
|
|
std::memcpy (winchar, canvaschar, sizeof(charData) * unsigned(x_end));
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-12-28 22:57:43 +01:00
|
|
|
if ( int(print_area->changes[ay + y].xmin) > ax )
|
2017-08-27 09:50:30 +02:00
|
|
|
print_area->changes[ay + y].xmin = uInt(ax);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-12-28 22:57:43 +01:00
|
|
|
if ( int(print_area->changes[ay + y].xmax) < ax + x_end - 1 )
|
2017-08-27 09:50:30 +02:00
|
|
|
print_area->changes[ay + y].xmax = uInt(ax + x_end - 1);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
print_area->has_changes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void MouseDraw::adjustSize()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t w = 60, h = 18;
|
|
|
|
int x = 1 + int((getParentWidget()->getWidth() - w) / 2);
|
|
|
|
int y = 1 + int((getParentWidget()->getHeight() - h) / 2);
|
2017-03-19 17:18:07 +01:00
|
|
|
setGeometry (x, y, w, h, false);
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::adjustSize();
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MouseDraw::onMouseDown (finalcut::FMouseEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::onMouseDown(ev);
|
2017-03-19 17:18:07 +01:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( ev->getButton() != finalcut::fc::LeftButton
|
|
|
|
&& ev->getButton() != finalcut::fc::RightButton )
|
2017-03-19 17:18:07 +01:00
|
|
|
return;
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
drawBrush ( ev->getX()
|
|
|
|
, ev->getY()
|
|
|
|
, ev->getButton() == finalcut::fc::RightButton );
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void MouseDraw::onMouseMove (finalcut::FMouseEvent* ev)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
|
|
|
FDialog::onMouseMove(ev);
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( ev->getButton() != finalcut::fc::LeftButton
|
|
|
|
&& ev->getButton() != finalcut::fc::RightButton )
|
2017-03-19 17:18:07 +01:00
|
|
|
return;
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
drawBrush ( ev->getX()
|
|
|
|
, ev->getY()
|
|
|
|
, ev->getButton() == finalcut::fc::RightButton);
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
void MouseDraw::cb_colorChanged (finalcut::FWidget*, FDataPtr)
|
2017-03-19 17:18:07 +01:00
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
brush.setForeground (c_chooser.getForeground());
|
|
|
|
brush.setBackground (c_chooser.getBackground());
|
|
|
|
brush.redraw();
|
2017-03-19 17:18:07 +01:00
|
|
|
}
|
|
|
|
|
2017-03-17 23:22:13 +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-03-17 23:22:13 +01:00
|
|
|
|
|
|
|
// Create a simple dialog box
|
2017-03-19 17:18:07 +01:00
|
|
|
MouseDraw mouse_draw(&app);
|
2017-03-17 23:22:13 +01:00
|
|
|
mouse_draw.setGeometry (12, 4, 60, 18);
|
2017-03-19 17:18:07 +01:00
|
|
|
mouse_draw.addAccelerator('q'); // press 'q' to quit
|
2017-03-17 23:22:13 +01:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog object mouse_draw as main widget
|
2017-03-17 23:22:13 +01:00
|
|
|
app.setMainWidget(&mouse_draw);
|
2017-09-19 06:18:03 +02:00
|
|
|
|
|
|
|
// Show and start the application
|
2017-03-17 23:22:13 +01:00
|
|
|
mouse_draw.show();
|
|
|
|
return app.exec();
|
|
|
|
}
|