#include "ToolTip.h" #include "AlphaField.h" #include "Image.h" #include "Screen.h" #include "MouseEvent.h" #include "Border.h" #include "Font.h" #include "Scroll.h" #include "Text.h" #include "TextField.h" using namespace Framework; // Contents of the ToolTip class from ToolTip.h // Constructor ToolTip::ToolTip(Screen* zScreen) : DrawableBackground(), size(0, 0), animationSpeed(250), warten(1), wartenCount(0), tval(0), mausIn(0), alpha(0), sichtbar(0), zeichnen(0), mausIn2(0), bildschirm(zScreen), onShow(0), onHide(0) { style = Style::MEIgnoreInside | Style::MEIgnoreParentInside | Style::MEIgnoreSichtbar | Style::MEIgnoreVerarbeitet | Style::Erlaubt; members = new RCArray(); bildschirm->addToolTip(dynamic_cast(this->getThis())); setMouseEvent(_ret1ME); } // Destructor ToolTip::~ToolTip() { members->release(); } void ToolTip::doMouseEvent(MouseEvent& me, bool userRet) { if (!sichtbar) pos.x += me.mx, pos.y += me.my + 15; if (hatStyleNicht(Style::Sichtbar) || !me.insideParent || me.verarbeitet || me.mx < 0 || me.my < 0 || me.mx >= gr.x || me.my >= gr.y || !userRet) { mausIn2 = 0; if (!mausIn && sichtbar) { if (onHide && sichtbar) onHide(this); sichtbar = 0; } bool verarbeitet = me.verarbeitet; me.verarbeitet |= hatStyleNicht(Style::Sichtbar); bool insideParent = me.insideParent; me.insideParent = 0; int rbr = 0; if (hatStyle(Style::Border) && rahmen) rbr = rahmen->getRBreite(); me.mx -= rbr; me.my -= rbr; if (hatStyle(Style::VScroll) && vertikalScrollBar) me.my += vertikalScrollBar->getScroll(); if (hatStyle(Style::HScroll) && horizontalScrollBar) me.mx += horizontalScrollBar->getScroll(); if (me.id != ME_Betritt && me.id != ME_Leaves) { for (int i = members->getEntryCount() - 1; i >= 0; i--) members->z(i)->doPublicMouseEvent(me); } me.mx += rbr; me.my += rbr; if (hatStyle(Style::VScroll) && vertikalScrollBar) me.my -= vertikalScrollBar->getScroll(); if (hatStyle(Style::HScroll) && horizontalScrollBar) me.mx -= horizontalScrollBar->getScroll(); me.insideParent = insideParent; if (hatStyleNicht(Style::Sichtbar)) me.verarbeitet = verarbeitet; return; } mausIn2 = 1; if (sichtbar) { int rbr = 0; if (hatStyle(Style::Border) && rahmen) rbr = rahmen->getRBreite(); me.mx -= rbr; me.my -= rbr; if (hatStyle(Style::VScroll) && vertikalScrollBar) me.my += vertikalScrollBar->getScroll(); if (hatStyle(Style::HScroll) && horizontalScrollBar) me.mx += horizontalScrollBar->getScroll(); for (auto z : *members) z->doPublicMouseEvent(me); me.mx += rbr; me.my += rbr; if (hatStyle(Style::VScroll) && vertikalScrollBar) me.my -= vertikalScrollBar->getScroll(); if (hatStyle(Style::HScroll) && horizontalScrollBar) me.mx -= horizontalScrollBar->getScroll(); } if (sichtbar) me.verarbeitet = 1; if (alpha) rend = 1; } // Adds a drawing to the tooltip // m: the new drawing void ToolTip::addMember(Drawable* m) { members->add(m); } void ToolTip::removeMember(Drawable* zM) { int index = 0; for (auto i : *members) { if (i == zM) { members->remove(index); return; } index++; } } // Removes a drawing from the tooltip // i: the index of the drawing void ToolTip::removeMember(int i) { members->remove(i); } // sets a function that is called when the tooltip is shown // onShow: The function void ToolTip::setShowEvent(std::function onShow) { this->onShow = onShow; } // sets a function that is called when the tooltip is no longer // shown // onShow: The function void ToolTip::setHideEvent(std::function onHide) { this->onHide = onHide; } void ToolTip::setWarten(double warten) { this->warten = warten; } void ToolTip::setAnimationSpeed(double speed) { animationSpeed = speed; } void ToolTip::setMausIn(bool mausIn) { if (this->mausIn != mausIn) rend = 1; this->mausIn = mausIn; if (!mausIn && !mausIn2 && sichtbar) { if (sichtbar && onHide) onHide(this); sichtbar = 0; } } void ToolTip::wartenReset() { wartenCount = 0; } void ToolTip::setZeichnen() { zeichnen = 1; } bool ToolTip::tick(double tickVal) { for (auto z : *members) { size.x = MAX(size.x, z->getX() + z->getBreite() + 2 * getBorderWidth()); size.y = MAX(size.y, z->getY() + z->getHeight() + 2 * getBorderWidth()); } this->tval += tickVal * animationSpeed; int val = (int)this->tval; if (val < 1) { bool ret = rend; rend = 0; return ret; } this->tval -= val; if (!sichtbar) { if (alpha) { if (alpha - val < 0) alpha = 0; else alpha = (unsigned char)(alpha - val); rend = 1; } if (mausIn) { wartenCount += tickVal; if (wartenCount >= warten) { if (onShow) onShow(this); sichtbar = 1; wartenCount = 0; alpha = 0xFF; DrawableBackground::setSize(0, 0); } } else wartenCount = 0; } else { if (getBreite() < size.x) { DrawableBackground::setSize(getBreite() + val, getHeight()); if (getBreite() > size.x) DrawableBackground::setSize(size.x, getHeight()); rend = 1; } if (getHeight() < size.y) { DrawableBackground::setSize(getBreite(), getHeight() + val); if (getHeight() > size.y) DrawableBackground::setSize(getBreite(), size.y); rend = 1; } } return DrawableBackground::tick(tickVal); } void ToolTip::render(Image& zRObj) { if (alpha && (zeichnen || mausIn2)) { zRObj.setAlpha(alpha); setPosition(pos); if (getX() + getBreite() > zRObj.getBreite()) setPosition( getX() - (getX() + getBreite() - zRObj.getBreite()), getY()); if (getY() + getHeight() > zRObj.getHeight()) setPosition( getX(), getY() - (getY() + getHeight() - zRObj.getHeight())); DrawableBackground::render(zRObj); Punkt p = pos; Punkt s = gr; if (hatStyle(DrawableBackground::Style::Border)) { p += Punkt(getBorderWidth(), getBorderWidth()); s -= Punkt(getBorderWidth(), getBorderWidth()) * 2; } if (!zRObj.setDrawOptions(p, s)) { zRObj.releaseAlpha(); zeichnen = 0; return; } bool vSc = hatStyle(Style::VScroll) && vertikalScrollBar; bool hSc = hatStyle(Style::HScroll) && horizontalScrollBar; zRObj.addScrollOffset(hSc ? horizontalScrollBar->getScroll() : 0, vSc ? vertikalScrollBar->getScroll() : 0); for (auto z : *members) z->render(zRObj); zRObj.releaseDrawOptions(); zRObj.releaseAlpha(); zeichnen = 0; } } // constant Screen* ToolTip::zScreen() const { return bildschirm; } // Returns a specific member (without increased reference counter) // i: the index of the member Drawable* ToolTip::zMember(int i) const { return members->z(i); } // Returns a specific member // i: the index of the member Drawable* ToolTip::getMember(int i) const { return members->get(i); } // Returns the number of drawings that belong to the tooltip int ToolTip::getMemberAnzahl() const { return members->getEntryCount(); } // Creates a complete copy of a tooltip Drawable* ToolTip::dublizieren() const { ToolTip* ret = new ToolTip(bildschirm); ret->size = size; ret->animationSpeed = animationSpeed; ret->warten = warten; ret->wartenCount = wartenCount; ret->tval = tval; ret->mausIn = mausIn; ret->alpha = alpha; ret->sichtbar = sichtbar; ret->zeichnen = zeichnen; ret->mausIn2 = mausIn2; for (auto z : *members) ret->addMember(dynamic_cast(z->getThis())); return ret; } //! Checks whether the tooltip is currently being shown DLLEXPORT bool ToolTip::isVisible() const { return sichtbar; }