#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), auswahl(-1), ahFarbe(0xFF000000), ahImage(0), aBuffer(0), aBorder(0), styles(0), ahFarbeListe(0), ahImageListe(0), aBufferListe(0), aBorderList(0), schrift(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 (ahFarbeListe) ahFarbeListe->release(); if (ahImageListe) ahImageListe->release(); if (aBufferListe) aBufferListe->release(); if (aBorderList) aBorderList->release(); if (schrift) schrift->release(); } void SelectionList::doMouseEvent(MouseEvent& me, bool userRet) { if (!userRet || hatStyleNicht(Style::Erlaubt)) return; if (DrawableBackground::hatStyle(Style::VScroll) && vertikalScrollBar) { int rbr = 0; if (rahmen && DrawableBackground::hatStyle(Style::Border)) rbr = rahmen->getRBreite(); if (((me.mx > gr.x - 15 - rbr) || me.id == ME_UScroll || me.id == ME_DScroll) && me.id != ME_Betritt && me.id != ME_Leaves) { vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me); me.verarbeitet = 1; } } if (!me.verarbeitet && me.id == ME_RLinks) { int eintr = getKlickEintrag(me.my); if (eintr >= 0) { if (hatStyleNicht(Style::MultiSelect)) { auswahl = eintr; rend = 1; } else { bool shift = getTastenStand(T_Shift); bool strg = getTastenStand(T_Strg); if (strg) { setMsStyle(eintr, Style::Selected, hatMsStyleNicht(eintr, Style::Selected)); auswahl = eintr; } else if (shift && auswahl != -1) { deSelect(); int beg = auswahl, 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); auswahl = eintr; } } } else deSelect(); } me.verarbeitet = 1; } bool SelectionList::hatStyle(int styleSet, int styleCheck) const { return (styleSet | styleCheck) == styleSet; } // non-constant void SelectionList::update() // updates the selection list { int rbr = 0; if (rahmen) { rbr = rahmen->getRBreite(); rahmen->setPosition(0, 0); rahmen->setSize(gr.x, gr.y); } if (hintergrundFeld) { hintergrundFeld->setPosition(rbr, rbr); hintergrundFeld->setSize(gr.x - rbr * 2, gr.y - rbr * 2); } if (hatStyleNicht(Style::MultiStyled) && tfListe) { bool FieldBorder = DrawableBackground::hatStyle(Style::FieldBorder); bool FeldHintergrund = DrawableBackground::hatStyle(Style::FeldHintergrund); bool FeldHImage = DrawableBackground::hatStyle(Style::FeldHImage); bool FeldHAlpha = DrawableBackground::hatStyle(Style::FeldHAlpha); bool FeldBuffer = DrawableBackground::hatStyle(Style::FeldBuffer); for (TextField* tf : *tfListe) { tf->setStyle(TextField::Style::Border, FieldBorder); tf->setStyle(TextField::Style::Hintergrund, FeldHintergrund); tf->setStyle(TextField::Style::HImage, FeldHImage); tf->setStyle(TextField::Style::HAlpha, FeldHAlpha); tf->setStyle(TextField::Style::Buffered, FeldBuffer); if (schrift) tf->setFontZ(dynamic_cast(schrift->getThis())); } } if (DrawableBackground::hatStyle(Style::MultiStyled) && tfListe && styles) { auto style = styles->begin(); for (auto tf = tfListe->begin(); tf; tf++, style++) { tf->setStyle( TextField::Style::Border, hatStyle(style, Style::FieldBorder)); tf->setStyle(TextField::Style::Hintergrund, hatStyle(style, Style::FeldHintergrund)); tf->setStyle( TextField::Style::HImage, hatStyle(style, Style::FeldHImage)); tf->setStyle( TextField::Style::HAlpha, hatStyle(style, Style::FeldHAlpha)); tf->setStyle( TextField::Style::Buffered, hatStyle(style, Style::FeldBuffer)); } } rend = 1; } void SelectionList::addEintrag(Text* txt) // adds an entry { TextField* tf = new TextField(); tf->setStyle(TextField::Style::Center | TextField::Style::Sichtbar | TextField::Style::Border); tf->setSchriftFarbe(0xFFFFFFFF); tf->setBorderWidth(1); tf->setBorderColor(0xFFFFFFFF); tf->setTextZ(txt); tf->setSize(0, 20); addEintragZ(tf); rend = 1; } void SelectionList::addEintrag(const char* txt) { Text* tx = new Text(txt); addEintrag(tx); rend = 1; } void SelectionList::addEintragZ(TextField* tf) { if (!tfListe) tfListe = new RCArray(); if (schrift && (!tf->zFont() || hatStyleNicht(Style::MultiStyled))) tf->setFontZ(dynamic_cast(schrift->getThis())); tfListe->add(tf); rend = 1; } void SelectionList::addEintrag( int pos, Text* txt) // inserts an entry at position pos { TextField* tf = new TextField(); tf->setStyle(TextField::Style::Center | TextField::Style::Sichtbar | TextField::Style::Border); tf->setSchriftFarbe(0xFFFFFFFF); tf->setBorderWidth(1); tf->setBorderColor(0xFFFFFFFF); tf->setTextZ(txt); tf->setSize(0, 20); addEintragZ(pos, tf); rend = 1; } void SelectionList::addEintrag(int pos, const char* txt) { Text* tx = new Text(txt); addEintrag(pos, tx); rend = 1; } void SelectionList::addEintragZ(int pos, TextField* tf) { if (!tfListe) tfListe = new RCArray(); if (schrift && (!tf->zFont() || hatStyleNicht(Style::MultiStyled))) tf->setFontZ(dynamic_cast(schrift->getThis())); tfListe->add(tf, pos); rend = 1; } void SelectionList::setEintrag( 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::Sichtbar | TextField::Style::Border); tf->setSchriftFarbe(0xFFFFFFFF); tf->setBorderColor(0xFFFFFFFF); tf->setBorderWidth(1); tf->setTextZ(txt); tf->setSize(0, 20); setEintragZ(pos, tf); rend = 1; return; } tf->setTextZ(txt); rend = 1; } void SelectionList::setEintrag(int pos, const char* txt) { Text* tx = new Text(txt); setEintrag(pos, tx); rend = 1; } void SelectionList::setEintragZ(int pos, TextField* tf) { if (!tfListe) tfListe = new RCArray(); if (schrift && (!tf->zFont() || hatStyleNicht(Style::MultiStyled))) tf->setFontZ(dynamic_cast(schrift->getThis())); tfListe->set(tf, pos); rend = 1; } void SelectionList::tauschEintragPos( int vpos, int npos) // swaps entry vpos with entry npos { if (tfListe) { tfListe->tausch(vpos, npos); if (styles) styles->tausch(vpos, npos); if (ahFarbeListe) ahFarbeListe->tausch(vpos, npos); if (ahImageListe) ahImageListe->tausch(vpos, npos); if (aBufferListe) aBufferListe->tausch(vpos, npos); if (aBorderList) aBorderList->tausch(vpos, npos); rend = 1; } } void Framework::SelectionList::setEintragPos(int vpos, int npos) { if (tfListe) { tfListe->setPosition(vpos, npos); if (styles) styles->setPosition(vpos, npos); if (ahFarbeListe) ahFarbeListe->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::removeEintrag(int pos) // deletes entry at pos { tfListe->remove(pos); rend = 1; } void SelectionList::setFontZ( Font* schrift) // sets the font for the entries { if (this->schrift) this->schrift->release(); this->schrift = schrift; rend = 1; } void SelectionList::setVScrollZuEintrag(int eintrag) // scrolls to entry { if (vertikalScrollBar) { if (eintrag > tfListe->getLastIndex()) eintrag = tfListe->getLastIndex(); int y = 0; for (int i = 0; i < eintrag; 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 - ((rahmen && DrawableBackground::hatStyle( TextField::Style::Border)) ? rahmen->getRBreite() : 0)); } } void SelectionList::setALRZ(Border* rahmen) // sets a pointer to the selection border (only without MultiStyled) { if (aBorder) aBorder->release(); aBorder = rahmen; rend = 1; } void SelectionList::setALRBreite( int br) // sets the width of the selection border (only without MultiStyled) { if (!aBorder) aBorder = new LBorder(); aBorder->setRamenBreite(br); rend = 1; } void SelectionList::setALRFarbe( int fc) // sets the color of the selection border (only without MultiStyled) { if (!aBorder) aBorder = new LBorder(); aBorder->setFarbe(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::setAAFFarbe( int fc) // sets the color of the selection background buffer (only without // MultiStyled) { if (!aBuffer) aBuffer = new AlphaField(); aBuffer->setFarbe(fc); rend = 1; } void SelectionList::setAHImage( Image* bild) // sets the selection background image (only without MultiStyled) { if (!ahImage) ahImage = new Image(); ahImage->neuImage(bild->getBreite(), bild->getHeight(), 0); int* buff1 = ahImage->getBuffer(); int* buff2 = bild->getBuffer(); for (int i = 0; i < bild->getBreite() * bild->getHeight(); ++i) buff1[i] = buff2[i]; bild->release(); rend = 1; } void SelectionList::setAHFarbe(int f) // sets the selection // background color (only without MultiStyled) { ahFarbe = 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* rahmen) // sets a pointer to the selection border (only with MultiStyled) { if (!aBorderList) aBorderList = new RCArray(); aBorderList->set(rahmen, pos); rend = 1; } void SelectionList::setALRBreite(int pos, int br) // sets the width of the selection border (only with MultiStyled) { if (!aBorderList) aBorderList = new RCArray(); if (!aBorderList->z(pos)) aBorderList->set(new LBorder(), pos); aBorderList->z(pos)->setRamenBreite(br); rend = 1; } void SelectionList::setALRFarbe(int pos, int fc) // sets the color of the selection border (only with MultiStyled) { if (!aBorderList) aBorderList = new RCArray(); if (!aBorderList->z(pos)) aBorderList->set(new LBorder(), pos); aBorderList->z(pos)->setFarbe(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(); 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(); if (!aBufferListe->z(pos)) aBufferListe->set(new AlphaField(), pos); aBufferListe->z(pos)->setStrength(st); rend = 1; } void SelectionList::setAAFFarbe( int pos, int fc) // sets the color of the selection background buffer // (only with MultiStyled) { if (!aBufferListe) aBufferListe = new RCArray(); if (!aBufferListe->z(pos)) aBufferListe->set(new AlphaField(), pos); aBufferListe->z(pos)->setFarbe(fc); rend = 1; } void SelectionList::setAHImage(int pos, Image* bild) // sets the selection background image (only with MultiStyled) { if (ahImageListe) ahImageListe = new RCArray(); if (!ahImageListe->z(pos)) ahImageListe->set(new Image(), pos); ahImageListe->z(pos)->neuImage(bild->getBreite(), bild->getHeight(), 0); int* buff1 = ahImageListe->z(pos)->getBuffer(); int* buff2 = bild->getBuffer(); for (int i = 0; i < bild->getBreite() * bild->getHeight(); ++i) buff1[i] = buff2[i]; bild->release(); rend = 1; } void SelectionList::setAHFarbe( int pos, int f) // sets the selection background color // (only with MultiStyled) { if (ahFarbeListe) ahFarbeListe = new Array(); ahFarbeListe->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(); 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.verarbeitet; if (hatStyleNicht(Style::Fokus) || !tak || te.verarbeitet) return; getThis(); if (tak(takParam, this, te)) { if (te.id == TE_Press) { if (hatStyleNicht(Style::MultiSelect)) { switch (te.virtualKey) { case T_Unten: ++auswahl; if (auswahl > tfListe->getEntryCount()) auswahl = tfListe->getEntryCount(); rend = 1; break; case T_Oben: --auswahl; if (auswahl < -1) auswahl = -1; rend = 1; break; } } else { switch (te.virtualKey) { case T_Unten: deSelect(); ++auswahl; if (auswahl > tfListe->getEntryCount()) auswahl = tfListe->getEntryCount(); if (auswahl >= 0) addMsStyle(auswahl, Style::Selected); rend = 1; break; case T_Oben: deSelect(); --auswahl; if (auswahl < -1) auswahl = -1; if (auswahl >= 0) addMsStyle(auswahl, Style::Selected); rend = 1; break; } } } te.verarbeitet = 1; } if (ntakc && te.verarbeitet && nTak) te.verarbeitet = nTak(ntakParam, this, te); release(); } void SelectionList::render(Image& zRObj) // draws to zRObj { if (!DrawableBackground::hatStyle(Style::Sichtbar)) return; removeStyle(Style::HScroll); DrawableBackground::render(zRObj); lockDrawable(); if (!zRObj.setDrawOptions(innenPosition, innenSize)) { unlockDrawable(); return; } int rbr = 0; if (rahmen && DrawableBackground::hatStyle(Style::Border)) rbr = rahmen->getRBreite(); if (tfListe) { int maxHeight = 0; int dx = 0, dy = 0; if (vertikalScrollBar && DrawableBackground::hatStyle(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::hatStyle(Style::VScroll))) break; tf->setPosition(dx, dy); tf->setSize(innenSize.x, tf->getHeight()); maxHeight += tf->getHeight(); bool selected = 0; if (DrawableBackground::hatStyle(Style::MultiSelect) && styles) selected = hatStyle(style, Style::Selected); else selected = auswahl == i; AlphaField* tmpBuffer = 0; bool tmpB = 0; int tmpHFarbe = 0; bool tmpH = 0; Image* tmpHImage = 0; bool tmpHB = 0; bool tmpHAlpha = 0; Border* tmpBorder = 0; bool tmpR = 0; if (selected) { if (hatStyleNicht(Style::MultiStyled) || !styles) { if (DrawableBackground::hatStyle(Style::AuswahlBuffer) && aBuffer) { tmpBuffer = tf->getAlphaField(); tf->setAlphaFieldZ( dynamic_cast(aBuffer->getThis())); tmpB = tf->hatStyle(TextField::Style::Buffered); tf->setStyle(TextField::Style::Buffered, DrawableBackground::hatStyle( Style::AuswahlBuffer)); } if (DrawableBackground::hatStyle( Style::AuswahlHintergrund)) { tmpH = tf->hatStyle(TextField::Style::Hintergrund); tmpHFarbe = tf->getHintergrundFarbe(); tf->setHintergrundFarbe(ahFarbe); tf->setStyle(TextField::Style::Hintergrund, DrawableBackground::hatStyle(Style::Hintergrund)); if (DrawableBackground::hatStyle(Style::AuswahlHImage) && ahImage) { tmpHImage = tf->getHintergrundImage(); tf->setHintergrundImageZ( dynamic_cast(ahImage->getThis())); tmpHB = tf->hatStyle(TextField::Style::HImage); tf->setStyle(TextField::Style::HImage, DrawableBackground::hatStyle(Style::HImage)); } if (DrawableBackground::hatStyle( Style::AuswahlHAlpha)) { tmpHAlpha = tf->hatStyle(TextField::Style::HAlpha); tf->setStyle(TextField::Style::HAlpha, DrawableBackground::hatStyle( Style::AuswahlHAlpha)); } } if (DrawableBackground::hatStyle(Style::SelectionBorder) && aBorder) { tmpBorder = tf->getBorder(); tf->setBorderZ( dynamic_cast(aBorder->getThis())); tmpR = tf->hatStyle(TextField::Style::Border); tf->setStyle(TextField::Style::Border, DrawableBackground::hatStyle( Style::SelectionBorder)); } } else { if (hatStyle(style, Style::AuswahlBuffer) && aBufferListe) { tmpBuffer = tf->getAlphaField(); tf->setAlphaFieldZ(aBufferListe->get(i)); tmpB = tf->hatStyle(TextField::Style::Buffered); tf->setStyle(TextField::Style::Buffered, hatStyle(style, Style::AuswahlBuffer)); } if (hatStyle(style, Style::AuswahlHintergrund)) { tmpH = tf->hatStyle(Style::Hintergrund); tf->setStyle(TextField::Style::Hintergrund, hatStyle(style, Style::AuswahlHintergrund)); if (ahFarbeListe && ahFarbeListe->hat(i)) { tmpHFarbe = tf->getHintergrundFarbe(); tf->setHintergrundFarbe(ahFarbeListe->get(i)); } if (hatStyle(style, Style::AuswahlHImage) && ahImageListe) { tmpHImage = tf->getHintergrundImage(); tf->setHintergrundImageZ(ahImageListe->get(i)); tmpHB = tf->hatStyle(TextField::Style::HImage); tf->setStyle(TextField::Style::HImage, hatStyle(style, Style::HImage)); } if (hatStyle(style, Style::AuswahlHAlpha)) { tmpHAlpha = tf->hatStyle(TextField::Style::HAlpha); tf->setStyle(TextField::Style::HAlpha, hatStyle(style, Style::AuswahlHAlpha)); } } if (hatStyle(style, Style::SelectionBorder) && aBorderList) { tmpBorder = tf->getBorder(); tf->setBorderZ(aBorderList->get(i)); tmpR = tf->hatStyle(TextField::Style::Border); tf->setStyle(TextField::Style::Border, hatStyle(style, Style::SelectionBorder)); } } } tf->render(zRObj); if (selected) { if (hatStyleNicht(Style::MultiStyled) || !styles) { if (DrawableBackground::hatStyle(Style::AuswahlBuffer)) { tf->setAlphaFieldZ(tmpBuffer); tf->setStyle(TextField::Style::Buffered, tmpB); } if (DrawableBackground::hatStyle( Style::AuswahlHintergrund)) { tf->setHintergrundFarbe(tmpHFarbe); tf->setStyle(TextField::Style::Hintergrund, tmpH); if (DrawableBackground::hatStyle(Style::AuswahlHImage)) { tf->setHintergrundImageZ(tmpHImage); tf->setStyle(TextField::Style::HImage, tmpHB); } if (DrawableBackground::hatStyle( Style::AuswahlHAlpha)) tf->setStyle(TextField::Style::HAlpha, tmpHAlpha); } if (DrawableBackground::hatStyle(Style::SelectionBorder)) { tf->setBorderZ(tmpBorder); tf->setStyle(TextField::Style::Border, tmpR); } } else { if (hatMsStyle(i, Style::AuswahlBuffer) && aBufferListe) { tf->setAlphaFieldZ(tmpBuffer); tf->setStyle(TextField::Style::Buffered, tmpB); } if (hatMsStyle(i, Style::AuswahlHintergrund)) { tf->setStyle(TextField::Style::Hintergrund, tmpH); if (ahFarbeListe && ahFarbeListe->hat(i)) tf->setHintergrundFarbe(tmpHFarbe); if (hatMsStyle(i, Style::AuswahlHImage) && ahImageListe) { tf->setHintergrundImageZ(tmpHImage); tf->setStyle(TextField::Style::HImage, tmpHB); } if (hatMsStyle(i, Style::AuswahlHAlpha)) tf->setStyle(TextField::Style::HAlpha, tmpHAlpha); } if (hatMsStyle(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::getKlickEintrag(int my) { if (!tfListe) return -1; int y = 0; if (DrawableBackground::hatStyle(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::setAuswahl(int ausw) // sets the selection { if (hatStyleNicht(Style::MultiSelect)) auswahl = ausw; else if (styles) { for (int i = 0; i < styles->getEntryCount(); ++i) removeMsStyle(i, Style::Selected); addMsStyle(ausw, Style::Selected); } } void SelectionList::deSelect() { if (hatStyleNicht(Style::MultiSelect)) auswahl = -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::getAuswahl() const // returns the first selected entry { return auswahl; } int SelectionList::getEintragPos( Text* eintragText) // returns the position of the entry with the // corresponding text { int i = 0; for (auto tf = tfListe->begin(); tf; tf++, i++) { if (tf->zText()->istGleich(eintragText->getText())) { eintragText->release(); return i; } } return -1; } TextField* SelectionList::getEintrag( int pos) const // returns the entry at position pos { if (!tfListe) return 0; TextField* ret = (TextField*)tfListe->get(pos); if (ret) return dynamic_cast(ret->getThis()); return 0; } TextField* SelectionList::zEintrag(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(aBorder->getThis()); return 0; } Border* SelectionList::zABorder() const { return aBorder; } int SelectionList::getAHFarbe() const // returns the selection background color (without MultiStyled) { return ahFarbe; } Image* SelectionList::getAHImage() const // returns the selection background image (without MultiStyled) { if (ahImage) return dynamic_cast(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(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(ret->getThis()); return 0; } Border* SelectionList::zABorder(int pos) const { Border* ret = 0; if (aBorderList) ret = (Border*)aBorderList->z(pos); return ret; } int SelectionList::getAHFarbe(int pos) const // returns the selection background color (with MultiStyled) { if (ahFarbeListe && ahFarbeListe->hat(pos)) return ahFarbeListe->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(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(ret->getThis()); return 0; } AlphaField* SelectionList::zABuffer(int pos) const { AlphaField* ret = 0; if (aBufferListe) ret = (AlphaField*)aBufferListe->z(pos); return ret; } bool SelectionList::hatMsStyle( 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::hatMsStyleNicht(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); setHintergrundFarbe(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::hatStyle(Style::VScroll) && vertikalScrollBar) { int rbr = 0; if (rahmen && DrawableBackground::hatStyle(Style::Border)) rbr = rahmen->getRBreite(); if (((me.mx > gr.x - 15 - rbr) || me.id == ME_UScroll || me.id == ME_DScroll) && me.id != ME_Betritt && me.id != ME_Leaves) { vertikalScrollBar->doMausMessage( gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me); me.verarbeitet = 1; } me.my += vertikalScrollBar->getScroll(); } me.my -= (rahmen && DrawableBackground::hatStyle(TextField::Style::Border)) ? rahmen->getRBreite() * 2 : 0; me.mx -= (rahmen && DrawableBackground::hatStyle(TextField::Style::Border)) ? rahmen->getRBreite() * 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::hatStyle(DrawableList::Style::EntrySeperator) ? entrySeperatorSize : 0; me.my -= DrawableBackground::hatStyle(DrawableList::Style::EntrySeperator) ? entrySeperatorSize : 0; } index++; } me.my += ySum + (rahmen && DrawableBackground::hatStyle(TextField::Style::Border)) ? rahmen->getRBreite() * 2 : 0; me.mx += (rahmen && DrawableBackground::hatStyle(TextField::Style::Border)) ? rahmen->getRBreite() * 2 : 0; if (DrawableBackground::hatStyle(Style::VScroll) && vertikalScrollBar) me.my -= vertikalScrollBar->getScroll(); } //! Adds an entry //! \param entry The drawing to add void DrawableList::addEintrag(Drawable* entry) { rend = 1; list.add(entry); } //! Changes an entry //! \param pos The index of the entry //! \param entry The new drawing void DrawableList::setEintrag(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::tauschEintragPos(int vPos, int nPos) { rend = 1; list.tausch(vPos, nPos); } void Framework::DrawableList::setEintragPos(int vpos, int npos) { list.setPosition(vpos, npos); } //! Deletes an entry //! pos: The index of the entry void DrawableList::removeEintrag(int pos) { rend = 1; list.remove(pos); } //! Scrolls to a specific entry //! \param eintrag The index of the entry void DrawableList::setVScrollZuEintrag(int eintrag) { if (vertikalScrollBar) { if (eintrag > list.getLastIndex()) eintrag = list.getLastIndex(); int y = 0; int index = 0; for (Drawable* entry : list) { y += entry->getHeight(); if (index < list.getLastIndex()) y += DrawableBackground::hatStyle( 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::hatStyle( DrawableList::Style::EntrySeperator) ? entrySeperatorSize : 0; index++; } vertikalScrollBar->update(y, gr.y - ((rahmen && DrawableBackground::hatStyle( TextField::Style::Border)) ? rahmen->getRBreite() * 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 = rahmen && DrawableBackground::hatStyle(TextField::Style::Border) ? rahmen->getRBreite() : 0; bool vs = vertikalScrollBar && hatStyle(Style::VScroll); if (rObj.setDrawOptions(pos + Punkt(rbr, rbr), gr - Punkt(rbr, rbr) * 2 - Punkt(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::hatStyle( DrawableList::Style::EntrySeperator)) { for (int i = 0; i < entrySeperatorSize; i++) { rObj.drawLinieHAlpha( 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::getKlickEintrag(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::hatStyle(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::getEintragPos(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::getEintrag(int pos) const { return list.get(pos); } //! Returns an entry without increased reference counter //! \param pos The index of the entry Drawable* DrawableList::zEintrag(int pos) const { return list.get(pos); } //! Returns the needed height int DrawableList::getNeededHeight() const { int y = (rahmen && DrawableBackground::hatStyle(TextField::Style::Border)) ? rahmen->getRBreite() * 2 : 0; int index = 0; for (Drawable* entry : list) { y += entry->getHeight(); if (index < list.getLastIndex()) y += DrawableBackground::hatStyle(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; }