Refactoring FListView::onMouseMove

This commit is contained in:
Markus Gans 2018-02-18 21:49:58 +01:00
parent 06423664c0
commit 0f16b51e04
10 changed files with 72 additions and 77 deletions

View File

@ -46,12 +46,11 @@ struct termcap_string
{ {
const std::string name; const std::string name;
const fc::termcaps cap; const fc::termcaps cap;
}; };
#pragma pack(pop) #pragma pack(pop)
// String data array // String data array
static termcap_string strings[] = static const termcap_string strings[] =
{ {
{ "t_bell", fc::t_bell }, { "t_bell", fc::t_bell },
{ "t_erase_chars", fc::t_erase_chars }, { "t_erase_chars", fc::t_erase_chars },

View File

@ -333,6 +333,9 @@ class FListView : public FWidget
void wheelDown (int); void wheelDown (int);
bool dragScrollUp (int); bool dragScrollUp (int);
bool dragScrollDown (int); bool dragScrollDown (int);
void dragUp (int);
void dragDown (int);
void stopDragScroll();
FObjectIterator appendItem (FListViewItem*); FObjectIterator appendItem (FListViewItem*);
void processClick(); void processClick();
void processChanged(); void processChanged();

View File

@ -355,14 +355,14 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev)
// private methods of FApplication // private methods of FApplication
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::init (long key_timeout, long dblclick_interval) void FApplication::init (long key_time, long dblclick_time)
{ {
// Initialize keyboard values // Initialize keyboard values
time_keypressed.tv_sec = 0; time_keypressed.tv_sec = 0;
time_keypressed.tv_usec = 0; time_keypressed.tv_usec = 0;
// Set the keyboard keypress timeout // Set the keyboard keypress timeout
setKeypressTimeout (key_timeout); setKeypressTimeout (key_time);
// Initialize mouse control // Initialize mouse control
mouse = getMouseControl(); mouse = getMouseControl();
@ -373,7 +373,7 @@ void FApplication::init (long key_timeout, long dblclick_interval)
// Set the default double click interval // Set the default double click interval
if ( mouse ) if ( mouse )
mouse->setDblclickInterval (dblclick_interval); mouse->setDblclickInterval (dblclick_time);
try try
{ {

View File

@ -511,7 +511,6 @@ void FButtonGroup::drawLabel()
FString txt = " " + text + " "; FString txt = " " + text + " ";
uInt length = txt.getLength(); uInt length = txt.getLength();
hotkeypos = -1;
try try
{ {

View File

@ -555,7 +555,6 @@ void FLabel::drawMultiLine()
align_offset = getAlignOffset (int(length - 1)); align_offset = getAlignOffset (int(length - 1));
printLine (label_text, length - 1, hotkeypos, align_offset); printLine (label_text, length - 1, hotkeypos, align_offset);
hotkey_printed = true; hotkey_printed = true;
hotkeypos = -1;
} }
else else
{ {

View File

@ -846,12 +846,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
void FListView::onMouseUp (FMouseEvent* ev) void FListView::onMouseUp (FMouseEvent* ev)
{ {
if ( drag_scroll != fc::noScroll ) if ( drag_scroll != fc::noScroll )
{ stopDragScroll();
delOwnTimer();
drag_scroll = fc::noScroll;
scroll_distance = 1;
scroll_timer = false;
}
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
@ -922,61 +917,11 @@ void FListView::onMouseMove (FMouseEvent* ev)
// auto-scrolling when dragging mouse outside the widget // auto-scrolling when dragging mouse outside the widget
if ( mouse_y < 2 ) if ( mouse_y < 2 )
{ dragUp (ev->getButton());
// drag up
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() > 0 )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( ev->getButton() == fc::RightButton )
drag_scroll = fc::scrollUpSelect;
else
drag_scroll = fc::scrollUp;
}
if ( current_iter.getPosition() == 0 )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
else if ( mouse_y >= getHeight() ) else if ( mouse_y >= getHeight() )
{ dragDown (ev->getButton());
// drag down
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() <= int(getCount()) )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( ev->getButton() == fc::RightButton )
drag_scroll = fc::scrollDownSelect;
else
drag_scroll = fc::scrollDown;
}
if ( current_iter.getPosition() - 1 == int(getCount()) )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
else else
{ stopDragScroll();
// no dragging
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1065,12 +1010,7 @@ void FListView::onWheel (FWheelEvent* ev)
, pagesize = 4; , pagesize = 4;
if ( drag_scroll != fc::noScroll ) if ( drag_scroll != fc::noScroll )
{ stopDragScroll();
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
switch ( ev->getWheel() ) switch ( ev->getWheel() )
{ {
@ -1746,6 +1686,65 @@ bool FListView::dragScrollDown (int position_before)
return true; return true;
} }
//----------------------------------------------------------------------
void FListView::dragUp (int mouse_button)
{
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() > 0 )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( mouse_button == fc::RightButton )
drag_scroll = fc::scrollUpSelect;
else
drag_scroll = fc::scrollUp;
}
if ( current_iter.getPosition() == 0 )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
//----------------------------------------------------------------------
void FListView::dragDown (int mouse_button)
{
if ( drag_scroll != fc::noScroll
&& scroll_distance < getClientHeight() )
scroll_distance++;
if ( ! scroll_timer && current_iter.getPosition() <= int(getCount()) )
{
scroll_timer = true;
addTimer(scroll_repeat);
if ( mouse_button == fc::RightButton )
drag_scroll = fc::scrollDownSelect;
else
drag_scroll = fc::scrollDown;
}
if ( current_iter.getPosition() - 1 == int(getCount()) )
{
delOwnTimer();
drag_scroll = fc::noScroll;
}
}
//----------------------------------------------------------------------
void FListView::stopDragScroll()
{
delOwnTimer();
scroll_timer = false;
scroll_distance = 1;
drag_scroll = fc::noScroll;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListView::appendItem (FListViewItem* item) FObject::FObjectIterator FListView::appendItem (FListViewItem* item)
{ {

View File

@ -1195,7 +1195,7 @@ inline void FOptiAttr::preProcessing_cygwin_quirks (char_data*& term)
{ {
// Cygwin bold color fix pre processing // Cygwin bold color fix pre processing
if ( ! cygwin_terminal ) if ( ! cygwin_terminal || ! term )
return; return;
if ( term->fg_color > 7 || term->bg_color > 7 ) if ( term->fg_color > 7 || term->bg_color > 7 )

View File

@ -194,7 +194,6 @@ bool FStatusBar::hasActivatedKey()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::hide() void FStatusBar::hide()
{ {
int screenWidth;
short fg, bg; short fg, bg;
char* blank; char* blank;

View File

@ -509,7 +509,6 @@ void FToggleButton::drawLabel()
return; return;
uInt length = text.getLength(); uInt length = text.getLength();
hotkeypos = -1;
try try
{ {

View File

@ -1876,8 +1876,6 @@ FVTerm::char_data FVTerm::generateCharacter (int x, int y)
// Generates characters for a given position considering all areas // Generates characters for a given position considering all areas
FWidget::widgetList::const_iterator iter, end; FWidget::widgetList::const_iterator iter, end;
char_data* sc; // shown character char_data* sc; // shown character
char_data s_ch; // shadow character
char_data i_ch; // inherit background character
FWidget* widget; FWidget* widget;
widget = static_cast<FWidget*>(vterm->widget); widget = static_cast<FWidget*>(vterm->widget);