| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322 |
- #include "List.h"
- #include "AlphaField.h"
- #include "Array.h"
- #include "Image.h"
- #include "Globals.h"
- #include "MouseEvent.h"
- #include "Border.h"
- #include "Font.h"
- #include "Scroll.h"
- #include "KeyboardEvent.h"
- #include "Text.h"
- #include "TextField.h"
- using namespace Framework;
- // Contents of the SelectionList class from List.h
- // Constructor
- SelectionList::SelectionList()
- : DrawableBackground(),
- tfListe(0),
- selection(-1),
- ahColor(0xFF000000),
- ahImage(0),
- aBuffer(0),
- aBorder(0),
- styles(0),
- ahColorListe(0),
- ahImageListe(0),
- aBufferListe(0),
- aBorderList(0),
- font(0)
- {
- style = 0;
- this->setMouseEvent(_ret1ME);
- this->setKeyboardEvent(_ret1TE);
- }
- // Destructor
- SelectionList::~SelectionList()
- {
- if (tfListe) tfListe->release();
- if (ahImage) ahImage->release();
- if (aBuffer) aBuffer->release();
- if (aBorder) aBorder->release();
- if (styles) styles->release();
- if (ahColorListe) ahColorListe->release();
- if (ahImageListe) ahImageListe->release();
- if (aBufferListe) aBufferListe->release();
- if (aBorderList) aBorderList->release();
- if (font) font->release();
- }
- void SelectionList::doMouseEvent(MouseEvent& me, bool userRet)
- {
- if (!userRet || hasStyleNot(Style::Allowed)) return;
- if (DrawableBackground::hasStyle(Style::VScroll) && vertikalScrollBar)
- {
- int rbr = 0;
- if (border && DrawableBackground::hasStyle(Style::Border))
- rbr = border->getRWidth();
- if (((me.mx > gr.x - 15 - rbr) || me.id == ME_UScroll
- || me.id == ME_DScroll)
- && me.id != ME_Enter && me.id != ME_Leaves)
- {
- vertikalScrollBar->doMouseMessage(
- gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
- me.processed = 1;
- }
- }
- if (!me.processed && me.id == ME_RLeft)
- {
- int eintr = getClickEntry(me.my);
- if (eintr >= 0)
- {
- if (hasStyleNot(Style::MultiSelect))
- {
- selection = eintr;
- rend = 1;
- }
- else
- {
- bool shift = getKeyState(T_Shift);
- bool strg = getKeyState(T_Strg);
- if (strg)
- {
- setMsStyle(eintr,
- Style::Selected,
- hasMsStyleNot(eintr, Style::Selected));
- selection = eintr;
- }
- else if (shift && selection != -1)
- {
- deselect();
- int beg = selection, end = eintr;
- if (beg > end)
- {
- int tmp = end;
- end = beg;
- beg = tmp;
- }
- for (int i = beg; i <= end; ++i)
- {
- addMsStyle(i, Style::Selected);
- }
- }
- else
- {
- deselect();
- addMsStyle(eintr, Style::Selected);
- selection = eintr;
- }
- }
- }
- else
- deselect();
- }
- me.processed = 1;
- }
- bool SelectionList::hasStyle(int styleSet, int styleCheck) const
- {
- return (styleSet | styleCheck) == styleSet;
- }
- // non-constant
- void SelectionList::update() // updates the selection list
- {
- int rbr = 0;
- if (border)
- {
- rbr = border->getRWidth();
- border->setPosition(0, 0);
- border->setSize(gr.x, gr.y);
- }
- if (backgroundFeld)
- {
- backgroundFeld->setPosition(rbr, rbr);
- backgroundFeld->setSize(gr.x - rbr * 2, gr.y - rbr * 2);
- }
- if (hasStyleNot(Style::MultiStyled) && tfListe)
- {
- bool FieldBorder = DrawableBackground::hasStyle(Style::FieldBorder);
- bool FieldBackground
- = DrawableBackground::hasStyle(Style::FieldBackground);
- bool FieldHImage = DrawableBackground::hasStyle(Style::FieldHImage);
- bool FieldHAlpha = DrawableBackground::hasStyle(Style::FieldHAlpha);
- bool FieldBuffer = DrawableBackground::hasStyle(Style::FieldBuffer);
- for (TextField* tf : *tfListe)
- {
- tf->setStyle(TextField::Style::Border, FieldBorder);
- tf->setStyle(TextField::Style::Background, FieldBackground);
- tf->setStyle(TextField::Style::HImage, FieldHImage);
- tf->setStyle(TextField::Style::HAlpha, FieldHAlpha);
- tf->setStyle(TextField::Style::Buffered, FieldBuffer);
- if (font)
- tf->setFontZ(dynamic_cast<Font*>(font->getThis()));
- }
- }
- if (DrawableBackground::hasStyle(Style::MultiStyled) && tfListe && styles)
- {
- auto style = styles->begin();
- for (auto tf = tfListe->begin(); tf; tf++, style++)
- {
- tf->setStyle(
- TextField::Style::Border, hasStyle(style, Style::FieldBorder));
- tf->setStyle(TextField::Style::Background,
- hasStyle(style, Style::FieldBackground));
- tf->setStyle(
- TextField::Style::HImage, hasStyle(style, Style::FieldHImage));
- tf->setStyle(
- TextField::Style::HAlpha, hasStyle(style, Style::FieldHAlpha));
- tf->setStyle(
- TextField::Style::Buffered, hasStyle(style, Style::FieldBuffer));
- }
- }
- rend = 1;
- }
- void SelectionList::addEntry(Text* txt) // adds an entry
- {
- TextField* tf = new TextField();
- tf->setStyle(TextField::Style::Center | TextField::Style::Visible
- | TextField::Style::Border);
- tf->setFontColor(0xFFFFFFFF);
- tf->setBorderWidth(1);
- tf->setBorderColor(0xFFFFFFFF);
- tf->setTextZ(txt);
- tf->setSize(0, 20);
- addEntryZ(tf);
- rend = 1;
- }
- void SelectionList::addEntry(const char* txt)
- {
- Text* tx = new Text(txt);
- addEntry(tx);
- rend = 1;
- }
- void SelectionList::addEntryZ(TextField* tf)
- {
- if (!tfListe) tfListe = new RCArray<TextField>();
- if (font && (!tf->zFont() || hasStyleNot(Style::MultiStyled)))
- tf->setFontZ(dynamic_cast<Font*>(font->getThis()));
- tfListe->add(tf);
- rend = 1;
- }
- void SelectionList::addEntry(
- int pos, Text* txt) // inserts an entry at position pos
- {
- TextField* tf = new TextField();
- tf->setStyle(TextField::Style::Center | TextField::Style::Visible
- | TextField::Style::Border);
- tf->setFontColor(0xFFFFFFFF);
- tf->setBorderWidth(1);
- tf->setBorderColor(0xFFFFFFFF);
- tf->setTextZ(txt);
- tf->setSize(0, 20);
- addEntryZ(pos, tf);
- rend = 1;
- }
- void SelectionList::addEntry(int pos, const char* txt)
- {
- Text* tx = new Text(txt);
- addEntry(pos, tx);
- rend = 1;
- }
- void SelectionList::addEntryZ(int pos, TextField* tf)
- {
- if (!tfListe) tfListe = new RCArray<TextField>();
- if (font && (!tf->zFont() || hasStyleNot(Style::MultiStyled)))
- tf->setFontZ(dynamic_cast<Font*>(font->getThis()));
- tfListe->add(tf, pos);
- rend = 1;
- }
- void SelectionList::setEntry(
- int pos, Text* txt) // changes the entry at pos
- {
- TextField* tf = 0;
- if (tfListe) tf = tfListe->z(pos);
- if (!tf)
- {
- tf = new TextField();
- tf->setStyle(TextField::Style::Center | TextField::Style::Visible
- | TextField::Style::Border);
- tf->setFontColor(0xFFFFFFFF);
- tf->setBorderColor(0xFFFFFFFF);
- tf->setBorderWidth(1);
- tf->setTextZ(txt);
- tf->setSize(0, 20);
- setEntryZ(pos, tf);
- rend = 1;
- return;
- }
- tf->setTextZ(txt);
- rend = 1;
- }
- void SelectionList::setEntry(int pos, const char* txt)
- {
- Text* tx = new Text(txt);
- setEntry(pos, tx);
- rend = 1;
- }
- void SelectionList::setEntryZ(int pos, TextField* tf)
- {
- if (!tfListe) tfListe = new RCArray<TextField>();
- if (font && (!tf->zFont() || hasStyleNot(Style::MultiStyled)))
- tf->setFontZ(dynamic_cast<Font*>(font->getThis()));
- tfListe->set(tf, pos);
- rend = 1;
- }
- void SelectionList::swapEntryPos(
- int vpos, int npos) // swaps entry vpos with entry npos
- {
- if (tfListe)
- {
- tfListe->swap(vpos, npos);
- if (styles) styles->swap(vpos, npos);
- if (ahColorListe) ahColorListe->swap(vpos, npos);
- if (ahImageListe) ahImageListe->swap(vpos, npos);
- if (aBufferListe) aBufferListe->swap(vpos, npos);
- if (aBorderList) aBorderList->swap(vpos, npos);
- rend = 1;
- }
- }
- void Framework::SelectionList::setEntryPos(int vpos, int npos) {
- if (tfListe)
- {
- tfListe->setPosition(vpos, npos);
- if (styles) styles->setPosition(vpos, npos);
- if (ahColorListe) ahColorListe->setPosition(vpos, npos);
- if (ahImageListe) ahImageListe->setPosition(vpos, npos);
- if (aBufferListe) aBufferListe->setPosition(vpos, npos);
- if (aBorderList) aBorderList->setPosition(vpos, npos);
- rend = 1;
- }
- }
- void SelectionList::removeEntry(int pos) // deletes entry at pos
- {
- tfListe->remove(pos);
- rend = 1;
- }
- void SelectionList::setFontZ(
- Font* font) // sets the font for the entries
- {
- if (this->font) this->font->release();
- this->font = font;
- rend = 1;
- }
- void SelectionList::setVScrollToEntry(int entry) // scrolls to entry
- {
- if (vertikalScrollBar)
- {
- if (entry > tfListe->getLastIndex())
- entry = tfListe->getLastIndex();
- int y = 0;
- for (int i = 0; i < entry; i++)
- y += tfListe->z(i) ? tfListe->z(i)->getHeight() : 0;
- vertikalScrollBar->scroll(y);
- }
- }
- void SelectionList::updateVScroll() // scrolls to cursor position or
- // down
- {
- if (vertikalScrollBar)
- {
- int y = 0;
- for (TextField* tf : *tfListe)
- y += (TextField*)tf ? tf->getHeight() : 0;
- vertikalScrollBar->update(y,
- gr.y
- - ((border
- && DrawableBackground::hasStyle(
- TextField::Style::Border))
- ? border->getRWidth()
- : 0));
- }
- }
- void SelectionList::setALRZ(Border*
- border) // sets a pointer to the selection border (only without MultiStyled)
- {
- if (aBorder) aBorder->release();
- aBorder = border;
- rend = 1;
- }
- void SelectionList::setALRWidth(
- int br) // sets the width of the selection border (only without MultiStyled)
- {
- if (!aBorder) aBorder = new LBorder();
- aBorder->setBorderWidth(br);
- rend = 1;
- }
- void SelectionList::setALRColor(
- int fc) // sets the color of the selection border (only without MultiStyled)
- {
- if (!aBorder) aBorder = new LBorder();
- aBorder->setColor(fc);
- rend = 1;
- }
- void SelectionList::setAAFZ(AlphaField* buffer) // sets a pointer to the selection
- // AlphaField (only without MultiStyled)
- {
- if (aBuffer) aBuffer->release();
- aBuffer = buffer;
- rend = 1;
- }
- void SelectionList::setAAFStrength(
- int st) // sets the strength of the selection background buffer (only without
- // MultiStyled)
- {
- if (!aBuffer) aBuffer = new AlphaField();
- aBuffer->setStrength(st);
- rend = 1;
- }
- void SelectionList::setAAFColor(
- int fc) // sets the color of the selection background buffer (only without
- // MultiStyled)
- {
- if (!aBuffer) aBuffer = new AlphaField();
- aBuffer->setColor(fc);
- rend = 1;
- }
- void SelectionList::setAHImage(
- Image* bild) // sets the selection background image (only without MultiStyled)
- {
- if (!ahImage) ahImage = new Image();
- ahImage->newImage(bild->getWidth(), bild->getHeight(), 0);
- int* buff1 = ahImage->getBuffer();
- int* buff2 = bild->getBuffer();
- for (int i = 0; i < bild->getWidth() * bild->getHeight(); ++i)
- buff1[i] = buff2[i];
- bild->release();
- rend = 1;
- }
- void SelectionList::setAHColor(int f) // sets the selection
- // background color (only without MultiStyled)
- {
- ahColor = f;
- rend = 1;
- }
- void SelectionList::setAHImageZ(
- Image* b) // sets a pointer to the background image (only without MultiStyled)
- {
- if (ahImage) ahImage->release();
- ahImage = b;
- rend = 1;
- }
- void SelectionList::setALRZ(int pos,
- Border*
- border) // sets a pointer to the selection border (only with MultiStyled)
- {
- if (!aBorderList) aBorderList = new RCArray<Border>();
- aBorderList->set(border, pos);
- rend = 1;
- }
- void SelectionList::setALRWidth(int pos,
- int br) // sets the width of the selection border (only with MultiStyled)
- {
- if (!aBorderList) aBorderList = new RCArray<Border>();
- if (!aBorderList->z(pos)) aBorderList->set(new LBorder(), pos);
- aBorderList->z(pos)->setBorderWidth(br);
- rend = 1;
- }
- void SelectionList::setALRColor(int pos,
- int fc) // sets the color of the selection border (only with MultiStyled)
- {
- if (!aBorderList) aBorderList = new RCArray<Border>();
- if (!aBorderList->z(pos)) aBorderList->set(new LBorder(), pos);
- aBorderList->z(pos)->setColor(fc);
- rend = 1;
- }
- void SelectionList::setAAFZ(int pos,
- AlphaField*
- buffer) // sets a pointer to the selection AlphaField (only with MultiStyled)
- {
- if (!aBufferListe) aBufferListe = new RCArray<AlphaField>();
- aBufferListe->set(buffer, pos);
- rend = 1;
- }
- void SelectionList::setAAFStrength(
- int pos, int st) // sets the strength of the selection background buffer
- // (only with MultiStyled)
- {
- if (!aBufferListe) aBufferListe = new RCArray<AlphaField>();
- if (!aBufferListe->z(pos)) aBufferListe->set(new AlphaField(), pos);
- aBufferListe->z(pos)->setStrength(st);
- rend = 1;
- }
- void SelectionList::setAAFColor(
- int pos, int fc) // sets the color of the selection background buffer
- // (only with MultiStyled)
- {
- if (!aBufferListe) aBufferListe = new RCArray<AlphaField>();
- if (!aBufferListe->z(pos)) aBufferListe->set(new AlphaField(), pos);
- aBufferListe->z(pos)->setColor(fc);
- rend = 1;
- }
- void SelectionList::setAHImage(int pos,
- Image* bild) // sets the selection background image (only with MultiStyled)
- {
- if (ahImageListe) ahImageListe = new RCArray<Image>();
- if (!ahImageListe->z(pos)) ahImageListe->set(new Image(), pos);
- ahImageListe->z(pos)->newImage(bild->getWidth(), bild->getHeight(), 0);
- int* buff1 = ahImageListe->z(pos)->getBuffer();
- int* buff2 = bild->getBuffer();
- for (int i = 0; i < bild->getWidth() * bild->getHeight(); ++i)
- buff1[i] = buff2[i];
- bild->release();
- rend = 1;
- }
- void SelectionList::setAHColor(
- int pos, int f) // sets the selection background color
- // (only with MultiStyled)
- {
- if (ahColorListe) ahColorListe = new Array<int>();
- ahColorListe->set(f, pos);
- rend = 1;
- }
- void SelectionList::setAHImageZ(int pos,
- Image* b) // sets a pointer to the background image (only with MultiStyled)
- {
- if (ahImageListe) ahImageListe = new RCArray<Image>();
- ahImageListe->set(b, pos);
- rend = 1;
- }
- void SelectionList::setMsStyle(int pos,
- __int64 style) // sets the style of the entry (only with MultiStyled)
- {
- if (!styles) styles = new Array<__int64>();
- styles->set(style, pos);
- rend = 1;
- }
- void SelectionList::setMsStyle(int pos, __int64 style, bool add_remove)
- {
- if (!styles) styles = new Array<__int64>();
- if (add_remove)
- styles->set(styles->get(pos) | style, pos);
- else
- styles->set(styles->get(pos) & ~style, pos);
- rend = 1;
- }
- void SelectionList::addMsStyle(int pos, __int64 style)
- {
- if (!styles) styles = new Array<__int64>();
- styles->set(styles->get(pos) | style, pos);
- rend = 1;
- }
- void SelectionList::removeMsStyle(int pos, __int64 style)
- {
- if (!styles) styles = new Array<__int64>();
- styles->set(styles->get(pos) & ~style, pos);
- rend = 1;
- }
- void SelectionList::doKeyboardEvent(KeyboardEvent& te)
- {
- bool ntakc = !te.processed;
- if (hasStyleNot(Style::Focus) || !tak || te.processed) return;
- getThis();
- if (tak(takParam, this, te))
- {
- if (te.id == TE_Press)
- {
- if (hasStyleNot(Style::MultiSelect))
- {
- switch (te.virtualKey)
- {
- case T_Unten:
- ++selection;
- if (selection > tfListe->getEntryCount())
- selection = tfListe->getEntryCount();
- rend = 1;
- break;
- case T_Oben:
- --selection;
- if (selection < -1) selection = -1;
- rend = 1;
- break;
- }
- }
- else
- {
- switch (te.virtualKey)
- {
- case T_Unten:
- deselect();
- ++selection;
- if (selection > tfListe->getEntryCount())
- selection = tfListe->getEntryCount();
- if (selection >= 0) addMsStyle(selection, Style::Selected);
- rend = 1;
- break;
- case T_Oben:
- deselect();
- --selection;
- if (selection < -1) selection = -1;
- if (selection >= 0) addMsStyle(selection, Style::Selected);
- rend = 1;
- break;
- }
- }
- }
- te.processed = 1;
- }
- if (ntakc && te.processed && nTak)
- te.processed = nTak(ntakParam, this, te);
- release();
- }
- void SelectionList::render(Image& zRObj) // draws to zRObj
- {
- if (!DrawableBackground::hasStyle(Style::Visible)) return;
- removeStyle(Style::HScroll);
- DrawableBackground::render(zRObj);
- lockDrawable();
- if (!zRObj.setDrawOptions(innenPosition, innenSize))
- {
- unlockDrawable();
- return;
- }
- int rbr = 0;
- if (border && DrawableBackground::hasStyle(Style::Border))
- rbr = border->getRWidth();
- if (tfListe)
- {
- int maxHeight = 0;
- int dx = 0, dy = 0;
- if (vertikalScrollBar && DrawableBackground::hasStyle(Style::VScroll))
- dy -= vertikalScrollBar->getScroll();
- int mdy = innenSize.y + rbr;
- auto style = styles ? styles->begin() : Array<__int64>().begin();
- int i = 0;
- for (auto tf = tfListe->begin(); tf; tf++, style++, i++)
- {
- if (dy + tf->getHeight() > mdy
- && !(vertikalScrollBar
- && DrawableBackground::hasStyle(Style::VScroll)))
- break;
- tf->setPosition(dx, dy);
- tf->setSize(innenSize.x, tf->getHeight());
- maxHeight += tf->getHeight();
- bool selected = 0;
- if (DrawableBackground::hasStyle(Style::MultiSelect) && styles)
- selected = hasStyle(style, Style::Selected);
- else
- selected = selection == i;
- AlphaField* tmpBuffer = 0;
- bool tmpB = 0;
- int tmpHColor = 0;
- bool tmpH = 0;
- Image* tmpHImage = 0;
- bool tmpHB = 0;
- bool tmpHAlpha = 0;
- Border* tmpBorder = 0;
- bool tmpR = 0;
- if (selected)
- {
- if (hasStyleNot(Style::MultiStyled) || !styles)
- {
- if (DrawableBackground::hasStyle(Style::SelectionBuffer)
- && aBuffer)
- {
- tmpBuffer = tf->getAlphaField();
- tf->setAlphaFieldZ(
- dynamic_cast<AlphaField*>(aBuffer->getThis()));
- tmpB = tf->hasStyle(TextField::Style::Buffered);
- tf->setStyle(TextField::Style::Buffered,
- DrawableBackground::hasStyle(
- Style::SelectionBuffer));
- }
- if (DrawableBackground::hasStyle(
- Style::SelectionBackground))
- {
- tmpH = tf->hasStyle(TextField::Style::Background);
- tmpHColor = tf->getBackgroundColor();
- tf->setBackgroundColor(ahColor);
- tf->setStyle(TextField::Style::Background,
- DrawableBackground::hasStyle(Style::Background));
- if (DrawableBackground::hasStyle(Style::SelectionHImage)
- && ahImage)
- {
- tmpHImage = tf->getBackgroundImage();
- tf->setBackgroundImageZ(
- dynamic_cast<Image*>(ahImage->getThis()));
- tmpHB = tf->hasStyle(TextField::Style::HImage);
- tf->setStyle(TextField::Style::HImage,
- DrawableBackground::hasStyle(Style::HImage));
- }
- if (DrawableBackground::hasStyle(
- Style::SelectionHAlpha))
- {
- tmpHAlpha = tf->hasStyle(TextField::Style::HAlpha);
- tf->setStyle(TextField::Style::HAlpha,
- DrawableBackground::hasStyle(
- Style::SelectionHAlpha));
- }
- }
- if (DrawableBackground::hasStyle(Style::SelectionBorder)
- && aBorder)
- {
- tmpBorder = tf->getBorder();
- tf->setBorderZ(
- dynamic_cast<Border*>(aBorder->getThis()));
- tmpR = tf->hasStyle(TextField::Style::Border);
- tf->setStyle(TextField::Style::Border,
- DrawableBackground::hasStyle(
- Style::SelectionBorder));
- }
- }
- else
- {
- if (hasStyle(style, Style::SelectionBuffer) && aBufferListe)
- {
- tmpBuffer = tf->getAlphaField();
- tf->setAlphaFieldZ(aBufferListe->get(i));
- tmpB = tf->hasStyle(TextField::Style::Buffered);
- tf->setStyle(TextField::Style::Buffered,
- hasStyle(style, Style::SelectionBuffer));
- }
- if (hasStyle(style, Style::SelectionBackground))
- {
- tmpH = tf->hasStyle(Style::Background);
- tf->setStyle(TextField::Style::Background,
- hasStyle(style, Style::SelectionBackground));
- if (ahColorListe && ahColorListe->has(i))
- {
- tmpHColor = tf->getBackgroundColor();
- tf->setBackgroundColor(ahColorListe->get(i));
- }
- if (hasStyle(style, Style::SelectionHImage) && ahImageListe)
- {
- tmpHImage = tf->getBackgroundImage();
- tf->setBackgroundImageZ(ahImageListe->get(i));
- tmpHB = tf->hasStyle(TextField::Style::HImage);
- tf->setStyle(TextField::Style::HImage,
- hasStyle(style, Style::HImage));
- }
- if (hasStyle(style, Style::SelectionHAlpha))
- {
- tmpHAlpha = tf->hasStyle(TextField::Style::HAlpha);
- tf->setStyle(TextField::Style::HAlpha,
- hasStyle(style, Style::SelectionHAlpha));
- }
- }
- if (hasStyle(style, Style::SelectionBorder) && aBorderList)
- {
- tmpBorder = tf->getBorder();
- tf->setBorderZ(aBorderList->get(i));
- tmpR = tf->hasStyle(TextField::Style::Border);
- tf->setStyle(TextField::Style::Border,
- hasStyle(style, Style::SelectionBorder));
- }
- }
- }
- tf->render(zRObj);
- if (selected)
- {
- if (hasStyleNot(Style::MultiStyled) || !styles)
- {
- if (DrawableBackground::hasStyle(Style::SelectionBuffer))
- {
- tf->setAlphaFieldZ(tmpBuffer);
- tf->setStyle(TextField::Style::Buffered, tmpB);
- }
- if (DrawableBackground::hasStyle(
- Style::SelectionBackground))
- {
- tf->setBackgroundColor(tmpHColor);
- tf->setStyle(TextField::Style::Background, tmpH);
- if (DrawableBackground::hasStyle(Style::SelectionHImage))
- {
- tf->setBackgroundImageZ(tmpHImage);
- tf->setStyle(TextField::Style::HImage, tmpHB);
- }
- if (DrawableBackground::hasStyle(
- Style::SelectionHAlpha))
- tf->setStyle(TextField::Style::HAlpha, tmpHAlpha);
- }
- if (DrawableBackground::hasStyle(Style::SelectionBorder))
- {
- tf->setBorderZ(tmpBorder);
- tf->setStyle(TextField::Style::Border, tmpR);
- }
- }
- else
- {
- if (hasMsStyle(i, Style::SelectionBuffer) && aBufferListe)
- {
- tf->setAlphaFieldZ(tmpBuffer);
- tf->setStyle(TextField::Style::Buffered, tmpB);
- }
- if (hasMsStyle(i, Style::SelectionBackground))
- {
- tf->setStyle(TextField::Style::Background, tmpH);
- if (ahColorListe && ahColorListe->has(i))
- tf->setBackgroundColor(tmpHColor);
- if (hasMsStyle(i, Style::SelectionHImage) && ahImageListe)
- {
- tf->setBackgroundImageZ(tmpHImage);
- tf->setStyle(TextField::Style::HImage, tmpHB);
- }
- if (hasMsStyle(i, Style::SelectionHAlpha))
- tf->setStyle(TextField::Style::HAlpha, tmpHAlpha);
- }
- if (hasMsStyle(i, Style::SelectionBorder) && aBorderList)
- {
- tf->setBorderZ(tmpBorder);
- tf->setStyle(TextField::Style::Border, tmpR);
- }
- }
- }
- dy += tf->getHeight();
- }
- if (vertikalScrollBar)
- vertikalScrollBar->getScrollData()->max = maxHeight;
- }
- zRObj.releaseDrawOptions();
- unlockDrawable();
- }
- int SelectionList::getClickEntry(int my)
- {
- if (!tfListe) return -1;
- int y = 0;
- if (DrawableBackground::hasStyle(Style::VScroll) && vertikalScrollBar)
- y -= vertikalScrollBar->getScroll();
- int i = 0;
- for (auto tf = tfListe->begin(); tf; tf++, i++)
- {
- y += tf->getHeight();
- if (y > my) return i;
- }
- return -1;
- }
- void SelectionList::setSelection(int sel) // sets the selection
- {
- if (hasStyleNot(Style::MultiSelect))
- selection = sel;
- else if (styles)
- {
- for (int i = 0; i < styles->getEntryCount(); ++i)
- removeMsStyle(i, Style::Selected);
- addMsStyle(sel, Style::Selected);
- }
- }
- void SelectionList::deselect()
- {
- if (hasStyleNot(Style::MultiSelect))
- selection = -1;
- else if (styles)
- {
- for (int i = 0; i < styles->getEntryCount(); ++i)
- removeMsStyle(i, Style::Selected);
- }
- }
- // constant
- int SelectionList::getEntryCount()
- const // returns the number of entries
- {
- return tfListe ? tfListe->getEntryCount() : 0;
- }
- int SelectionList::getSelection()
- const // returns the first selected entry
- {
- return selection;
- }
- int SelectionList::getEntryPos(
- Text* entryText) // returns the position of the entry with the
- // corresponding text
- {
- int i = 0;
- for (auto tf = tfListe->begin(); tf; tf++, i++)
- {
- if (tf->zText()->isEqual(entryText->getText()))
- {
- entryText->release();
- return i;
- }
- }
- return -1;
- }
- TextField* SelectionList::getEntry(
- int pos) const // returns the entry at position pos
- {
- if (!tfListe) return 0;
- TextField* ret = (TextField*)tfListe->get(pos);
- if (ret) return dynamic_cast<TextField*>(ret->getThis());
- return 0;
- }
- TextField* SelectionList::zEntry(int pos) const
- {
- if (!tfListe) return 0;
- return (TextField*)tfListe->z(pos);
- }
- Border* SelectionList::getABorder()
- const // returns the selection border (without MultiStyled)
- {
- if (aBorder) return dynamic_cast<Border*>(aBorder->getThis());
- return 0;
- }
- Border* SelectionList::zABorder() const
- {
- return aBorder;
- }
- int SelectionList::getAHColor()
- const // returns the selection background color (without MultiStyled)
- {
- return ahColor;
- }
- Image* SelectionList::getAHImage()
- const // returns the selection background image (without MultiStyled)
- {
- if (ahImage) return dynamic_cast<Image*>(ahImage->getThis());
- return 0;
- }
- Image* SelectionList::zAHImage() const
- {
- return ahImage;
- }
- AlphaField* SelectionList::getABuffer()
- const // returns the selection buffer (without MultiStyled)
- {
- if (aBuffer) return dynamic_cast<AlphaField*>(aBuffer->getThis());
- return 0;
- }
- AlphaField* SelectionList::zABuffer() const
- {
- return aBuffer;
- }
- Border* SelectionList::getABorder(
- int pos) const // returns the selection border (with MultiStyled)
- {
- Border* ret = 0;
- if (aBorderList) ret = (Border*)aBorderList->get(pos);
- if (ret) return dynamic_cast<Border*>(ret->getThis());
- return 0;
- }
- Border* SelectionList::zABorder(int pos) const
- {
- Border* ret = 0;
- if (aBorderList) ret = (Border*)aBorderList->z(pos);
- return ret;
- }
- int SelectionList::getAHColor(int pos)
- const // returns the selection background color (with MultiStyled)
- {
- if (ahColorListe && ahColorListe->has(pos)) return ahColorListe->get(pos);
- return 0;
- }
- Image* SelectionList::getAHImage(
- int pos) const // returns the selection background image (with MultiStyled)
- {
- Image* ret = 0;
- if (ahImageListe) ret = (Image*)ahImageListe->get(pos);
- if (ret) return dynamic_cast<Image*>(ret->getThis());
- return 0;
- }
- Image* SelectionList::zAHImage(int pos) const
- {
- Image* ret = 0;
- if (ahImageListe) ret = (Image*)ahImageListe->z(pos);
- return ret;
- }
- AlphaField* SelectionList::getABuffer(
- int pos) const // returns the selection buffer (with MultiStyled)
- {
- AlphaField* ret = 0;
- if (aBufferListe) ret = (AlphaField*)aBufferListe->get(pos);
- if (ret) return dynamic_cast<AlphaField*>(ret->getThis());
- return 0;
- }
- AlphaField* SelectionList::zABuffer(int pos) const
- {
- AlphaField* ret = 0;
- if (aBufferListe) ret = (AlphaField*)aBufferListe->z(pos);
- return ret;
- }
- bool SelectionList::hasMsStyle(
- int pos, __int64 style) const // checks if style is present (with MultiStyled)
- {
- __int64 st = 0;
- if (styles) st = styles->get(pos);
- return (st | style) == st;
- }
- bool SelectionList::hasMsStyleNot(int pos,
- __int64 style) const // checks if style is not present (with MultiStyled)
- {
- __int64 st = 0;
- if (styles) st = styles->get(pos);
- return (st | style) != st;
- }
- //! Constructor
- DrawableList::DrawableList()
- : DrawableBackground()
- {
- entrySeperatorSize = 1;
- entrySeperatorColor = 0xFFFFFFFF;
- setBorderWidth(1);
- setBorderColor(0xFFFFFFFF);
- setBackgroundColor(0xFF000000);
- }
- //! Destructor
- DrawableList::~DrawableList() {}
- //! Processes mouse messages
- //! \param me The event triggered by the mouse input
- void DrawableList::doMouseEvent(MouseEvent& me, bool userRet)
- {
- if (DrawableBackground::hasStyle(Style::VScroll) && vertikalScrollBar)
- {
- int rbr = 0;
- if (border && DrawableBackground::hasStyle(Style::Border))
- rbr = border->getRWidth();
- if (((me.mx > gr.x - 15 - rbr) || me.id == ME_UScroll
- || me.id == ME_DScroll)
- && me.id != ME_Enter && me.id != ME_Leaves)
- {
- vertikalScrollBar->doMouseMessage(
- gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
- me.processed = 1;
- }
- me.my += vertikalScrollBar->getScroll();
- }
- me.my -= (border && DrawableBackground::hasStyle(TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0;
- me.mx -= (border && DrawableBackground::hasStyle(TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0;
- int ySum = 0;
- int index = 0;
- for (Drawable* entry : list)
- {
- entry->doPublicMouseEvent(me);
- ySum += entry->getHeight();
- me.my -= entry->getHeight();
- if (index < list.getLastIndex())
- {
- ySum
- += DrawableBackground::hasStyle(DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- me.my
- -= DrawableBackground::hasStyle(DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- }
- index++;
- }
- me.my
- += ySum
- + (border
- && DrawableBackground::hasStyle(TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0;
- me.mx += (border && DrawableBackground::hasStyle(TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0;
- if (DrawableBackground::hasStyle(Style::VScroll) && vertikalScrollBar)
- me.my -= vertikalScrollBar->getScroll();
- }
- //! Adds an entry
- //! \param entry The drawing to add
- void DrawableList::addEntry(Drawable* entry)
- {
- rend = 1;
- list.add(entry);
- }
- //! Changes an entry
- //! \param pos The index of the entry
- //! \param entry The new drawing
- void DrawableList::setEntry(int pos, Drawable* entry)
- {
- rend = 1;
- list.set(entry, pos);
- }
- //! Swaps the positions of two entries
- //! \param vpos The index of the first entry
- //! \param npos The index of the second entry
- void DrawableList::swapEntryPos(int vPos, int nPos)
- {
- rend = 1;
- list.swap(vPos, nPos);
- }
- void Framework::DrawableList::setEntryPos(int vpos, int npos)
- {
- list.setPosition(vpos, npos);
- }
- //! Deletes an entry
- //! pos: The index of the entry
- void DrawableList::removeEntry(int pos)
- {
- rend = 1;
- list.remove(pos);
- }
- //! Scrolls to a specific entry
- //! \param entry The index of the entry
- void DrawableList::setVScrollToEntry(int entry)
- {
- if (vertikalScrollBar)
- {
- if (entry > list.getLastIndex()) entry = list.getLastIndex();
- int y = 0;
- int index = 0;
- for (Drawable* entry : list)
- {
- y += entry->getHeight();
- if (index < list.getLastIndex())
- y += DrawableBackground::hasStyle(
- DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- index++;
- }
- vertikalScrollBar->scroll(y);
- }
- }
- //! Updates the maximum scroll height by adding the heights of all entries
- void DrawableList::updateVScroll()
- {
- if (vertikalScrollBar)
- {
- int y = 0;
- int index = 0;
- for (Drawable* entry : list)
- {
- y += entry->getHeight();
- if (index < list.getLastIndex())
- y += DrawableBackground::hasStyle(
- DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- index++;
- }
- vertikalScrollBar->update(y,
- gr.y
- - ((border
- && DrawableBackground::hasStyle(
- TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0));
- }
- }
- //! sets the size of the entry seperator
- void DrawableList::setEntrySeperatorSize(int size)
- {
- entrySeperatorSize = size;
- }
- //! sets the color of the entry seperator
- void DrawableList::setEntrySeperatorColor(int color)
- {
- entrySeperatorColor = color;
- }
- //! Processes a keyboard event. Called automatically by the framework
- //! \param te The event
- void DrawableList::doKeyboardEvent(KeyboardEvent& te)
- {
- for (Drawable* entry : list)
- entry->doKeyboardEvent(te);
- }
- //! Updates the drawing
- //! \param tickVal The elapsed time in seconds since the last call of this
- //! function \return 1 if the drawing has changed since the last call
- bool DrawableList::tick(double tickVal)
- {
- bool ret = DrawableBackground::tick(tickVal);
- for (Drawable* entry : list)
- ret |= entry->tick(tickVal);
- return ret;
- }
- //! Draws the object to zRObj if it is visible
- //! \param zRObj The image to draw into
- void DrawableList::render(Image& rObj)
- {
- DrawableBackground::render(rObj);
- int index = 0;
- int rbr = border && DrawableBackground::hasStyle(TextField::Style::Border)
- ? border->getRWidth()
- : 0;
- bool vs = vertikalScrollBar && hasStyle(Style::VScroll);
- if (rObj.setDrawOptions(pos + Point(rbr, rbr),
- gr - Point(rbr, rbr) * 2 - Point(vs ? 15 : 0, 0)))
- {
- if (vs) rObj.addScrollOffset(0, vertikalScrollBar->getScroll());
- for (Drawable* entry : list)
- {
- entry->setWidth(gr.x - rbr * 2 - (vs ? 15 : 0));
- entry->render(rObj);
- rObj.addScrollOffset(0, -entry->getHeight());
- if (index < list.getLastIndex()
- && DrawableBackground::hasStyle(
- DrawableList::Style::EntrySeperator))
- {
- for (int i = 0; i < entrySeperatorSize; i++)
- {
- rObj.drawLineHAlpha(
- 0, 0, gr.x - rbr - (vs ? 15 : 0), entrySeperatorColor);
- rObj.addScrollOffset(0, -1);
- }
- }
- index++;
- }
- rObj.releaseDrawOptions();
- }
- }
- //! Returns the index of an entry the mouse points to
- //! \param my The position of the mouse on the Y axis relative to the top
- //! edge of the list
- int DrawableList::getClickEntry(int my)
- {
- if (my < 0) return -1;
- int index = 0;
- int y = 0;
- for (Drawable* entry : list)
- {
- if (my < y) return index;
- y += entry->getHeight();
- if (index < list.getLastIndex())
- y += DrawableBackground::hasStyle(DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- index++;
- }
- return -1;
- }
- //! Returns the number of entries
- int DrawableList::getEntryCount() const
- {
- return list.getEntryCount();
- }
- //! Returns the index of an entry
- //! \param zEntry The drawing
- int DrawableList::getEntryPos(Drawable* zEntry)
- {
- int index = 0;
- for (Drawable* entry : list)
- {
- if (zEntry == entry) return index;
- index++;
- }
- return -1;
- }
- //! Returns an entry
- //! \param pos The index of the entry
- Drawable* DrawableList::getEntry(int pos) const
- {
- return list.get(pos);
- }
- //! Returns an entry without increased reference counter
- //! \param pos The index of the entry
- Drawable* DrawableList::zEntry(int pos) const
- {
- return list.get(pos);
- }
- //! Returns the needed height
- int DrawableList::getNeededHeight() const
- {
- int y = (border && DrawableBackground::hasStyle(TextField::Style::Border))
- ? border->getRWidth() * 2
- : 0;
- int index = 0;
- for (Drawable* entry : list)
- {
- y += entry->getHeight();
- if (index < list.getLastIndex())
- y += DrawableBackground::hasStyle(DrawableList::Style::EntrySeperator)
- ? entrySeperatorSize
- : 0;
- index++;
- }
- return y;
- }
- //! returns the size of the entry seperator
- int DrawableList::getEntrySeperatorSize() const
- {
- return entrySeperatorSize;
- }
- //! returns the color of the entry seperator
- int DrawableList::getEntrySeperatorColor() const
- {
- return entrySeperatorColor;
- }
|