123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- #include "Scroll.h"
- #include "Bild.h"
- #include "MausEreignis.h"
- using namespace Framework;
- // Inhalt der VScrollBar Klasse aus Scroll.h
- // Konstruktor
- ScrollBar::ScrollBar()
- : ReferenceCounter(),
- data( new ScrollData() ),
- knopfdruck( 0 ),
- farbe( 0xFF808080 ),
- bgFarbe( 0xFF000000 ),
- bg( 0 ),
- klickScroll( 10 ),
- mx( -1 ),
- my( -1 ),
- mp( 0 ),
- rend( 0 )
- {}
- // Destruktor
- ScrollBar::~ScrollBar()
- {
- delete data;
- }
- // nicht constant
- void ScrollBar::setFarbe( int fc )
- {
- farbe = fc;
- rend = 1;
- }
- void ScrollBar::setBgFarbe( int fc, bool bgF )
- {
- bgFarbe = fc;
- bg = bgF;
- rend = 1;
- }
- void ScrollBar::update( int maxGr, int anzeigeGr )
- {
- if( data->max != maxGr || data->anzeige != anzeigeGr )
- {
- data->max = maxGr, data->anzeige = anzeigeGr;
- rend = 1;
- }
- if( data->scrollPos > data->max - data->anzeige && data->max - data->anzeige >= 0 )
- {
- data->scrollPos = data->max - data->anzeige;
- rend = 1;
- }
- if( data->scrollPos < 0 )
- {
- data->scrollPos = 0;
- rend = 1;
- }
- }
- void ScrollBar::setKlickScroll( int ks )
- {
- klickScroll = ks;
- rend = 1;
- }
- void ScrollBar::scroll( int height )
- {
- data->scrollPos = height;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- }
- bool ScrollBar::getRend()
- {
- if( knopfdruck == 1 )
- {
- int tmp = data->scrollPos;
- data->scrollPos -= klickScroll;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- if( tmp != data->scrollPos )
- rend = 1;
- }
- if( knopfdruck == 2 )
- {
- int tmp = data->scrollPos;
- data->scrollPos += klickScroll;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- if( tmp != data->scrollPos )
- rend = 1;
- }
- bool ret = rend;
- rend = 0;
- return ret;
- }
- // const
- ScrollData *ScrollBar::getScrollData() const
- {
- return data;
- }
- int ScrollBar::getKlickScroll() const
- {
- return klickScroll;
- }
- int ScrollBar::getFarbe() const
- {
- return farbe;
- }
- int ScrollBar::getBgFarbe() const
- {
- return bg ? bgFarbe : 0;
- }
- int ScrollBar::getScroll() const
- {
- return data->scrollPos;
- }
- // Inhalt der VScrollBar Klasse
- VScrollBar::VScrollBar()
- : ScrollBar()
- {}
- // Destruktor
- VScrollBar::~VScrollBar()
- {}
- bool VScrollBar::doMausMessage( int x, int y, int br, int hi, MausEreignis &me )
- {
- if( me.id == ME_Leaves )
- {
- mp = 0;
- mx = -1;
- my = -1;
- }
- bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
- knopfdruck = 0;
- if( me.verarbeitet )
- {
- mx = -1, my = -1;
- mp = 0;
- return ret;
- }
- if( me.id == ME_UScroll )
- {
- data->scrollPos -= klickScroll;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- return ret;
- }
- if( me.id == ME_DScroll )
- {
- data->scrollPos += klickScroll;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- return ret;
- }
- if( ret )
- mx = me.mx - x, my = me.my - y;
- else
- mx = -1, my = -1;
- if( me.id == ME_PLinks )
- mp = 1;
- if( me.id == ME_RLinks )
- mp = 0;
- if( mp )
- {
- if( mx >= 0 && my >= 0 )
- {
- if( my < br )
- {
- knopfdruck = 1;
- data->scrollPos -= klickScroll;
- }
- else if( my > hi - br )
- {
- knopfdruck = 2;
- data->scrollPos += klickScroll;
- }
- else
- data->scrollPos = (int)( ( data->max / ( hi - 2.0 * br ) ) * ( my - br ) ) - data->anzeige / 2;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- }
- }
- return ret;
- }
- void VScrollBar::render( int x, int y, int br, int hi, Bild &zRObj ) const
- {
- if( bg )
- zRObj.alphaRegion( x, y, br, hi, bgFarbe );
- --br;
- --hi;
- zRObj.drawLinieH( x, y, br + 1, farbe );
- zRObj.drawLinieH( x, y + hi, br + 1, farbe );
- zRObj.drawLinieV( x, y + 1, hi - 1, farbe );
- zRObj.drawLinieV( x + br, y + 1, hi - 1, farbe );
- zRObj.drawLinieH( x + 1, y + br, br - 1, farbe );
- zRObj.drawLinieH( x + 1, y + hi - br, br - 1, farbe );
- ++br;
- ++hi;
- int st = (int)( data->scrollPos / ( data->max / ( hi - br * 2.0 ) ) );
- int end = (int)( ( hi - 2.0 * br ) / ( (double)data->max / data->anzeige ) );
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- {
- data->scrollPos = 0;
- end = hi - br * 2;
- }
- zRObj.fillRegion( x + 1, y + br + st, br - 1, end, farbe );
- }
- // Inhalt der HScrollBar Klasse aus Scroll.h
- // Konstruktor
- HScrollBar::HScrollBar()
- : ScrollBar()
- {}
- // Destruktor
- HScrollBar::~HScrollBar()
- {}
- // nicht constant
- bool HScrollBar::doMausMessage( int x, int y, int br, int hi, MausEreignis &me )
- {
- if( me.id == ME_Leaves )
- {
- mp = 0;
- mx = -1;
- my = -1;
- }
- bool ret = me.mx >= x && me.mx <= x + br && me.my >= y && me.my <= y + hi;
- knopfdruck = 0;
- if( me.verarbeitet )
- {
- mx = -1, my = -1;
- mp = 0;
- return ret;
- }
- if( me.id == ME_LScroll )
- {
- data->scrollPos -= klickScroll;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- return ret;
- }
- if( me.id == ME_RScroll )
- {
- data->scrollPos += klickScroll;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- return ret;
- }
- if( ret )
- mx = me.mx - x, my = me.my - y;
- else
- mx = -1, my = -1;
- if( me.id == ME_PLinks )
- mp = 1;
- if( me.id == ME_RLinks )
- mp = 0;
- if( mp )
- {
- if( mx >= 0 && my >= 0 )
- {
- if( mx < hi )
- {
- knopfdruck = 1;
- data->scrollPos -= klickScroll;
- }
- else if( mx > br - hi )
- {
- knopfdruck = 2;
- data->scrollPos += klickScroll;
- }
- else
- data->scrollPos = (int)( ( data->max / ( br - 2.0 * hi ) ) * ( mx - hi ) ) - data->anzeige / 2;
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- data->scrollPos = 0;
- rend = 1;
- }
- }
- return ret;
- }
- void HScrollBar::render( int x, int y, int br, int hi, Bild &zRObj ) const
- {
- if( bg )
- zRObj.alphaRegion( x, y, br, hi, bgFarbe );
- --br;
- --hi;
- zRObj.drawLinieV( x, y, hi + 1, farbe );
- zRObj.drawLinieV( x + br, y, hi + 1, farbe );
- zRObj.drawLinieH( x + 1, y, br - 1, farbe );
- zRObj.drawLinieH( x + 1, y + hi, br - 1, farbe );
- zRObj.drawLinieV( x + hi, y + 1, hi - 1, farbe );
- zRObj.drawLinieV( x + br - hi, y + 1, hi - 1, farbe );
- ++br;
- ++hi;
- int st = (int)( data->scrollPos / ( data->max / ( br - hi * 2.0 ) ) );
- int end = (int)( ( br - 2.0 * hi ) / ( (double)data->max / data->anzeige ) );
- if( data->scrollPos > data->max - data->anzeige )
- data->scrollPos = data->max - data->anzeige;
- if( data->scrollPos < 0 )
- {
- data->scrollPos = 0;
- end = br - hi * 2;
- }
- zRObj.fillRegion( x + hi + st, y + 1, end, hi - 1, farbe );
- }
|