2017-10-29 10:28:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2015 Dimok
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2018-06-21 20:44:58 +02:00
|
|
|
#include <gui/GuiFrame.h>
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiFrame::GuiFrame(GuiFrame *p) {
|
2017-10-29 10:28:14 +01:00
|
|
|
parent = p;
|
2022-02-05 14:28:08 +01:00
|
|
|
width = 0;
|
2017-10-29 10:28:14 +01:00
|
|
|
height = 0;
|
2022-02-05 14:28:08 +01:00
|
|
|
dim = false;
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 12:58:19 +02:00
|
|
|
if (parent) {
|
2017-10-29 10:28:14 +01:00
|
|
|
parent->append(this);
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiFrame::GuiFrame(float w, float h, GuiFrame *p) {
|
2017-10-29 10:28:14 +01:00
|
|
|
parent = p;
|
2022-02-05 14:28:08 +01:00
|
|
|
width = w;
|
2017-10-29 10:28:14 +01:00
|
|
|
height = h;
|
2022-02-05 14:28:08 +01:00
|
|
|
dim = false;
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 12:58:19 +02:00
|
|
|
if (parent) {
|
2017-10-29 10:28:14 +01:00
|
|
|
parent->append(this);
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiFrame::~GuiFrame() {
|
2017-10-29 10:28:14 +01:00
|
|
|
closing(this);
|
|
|
|
|
2020-08-13 12:58:19 +02:00
|
|
|
if (parent) {
|
2017-10-29 10:28:14 +01:00
|
|
|
parent->remove(this);
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiFrame::append(GuiElement *e) {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (e == NULL) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
remove(e);
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
elements.push_back(e);
|
|
|
|
e->setParent(this);
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiFrame::insert(GuiElement *e, uint32_t index) {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (e == NULL || (index >= elements.size())) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
remove(e);
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2020-08-13 12:38:07 +02:00
|
|
|
elements.insert(elements.begin() + index, e);
|
2017-10-29 10:28:14 +01:00
|
|
|
e->setParent(this);
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiFrame::remove(GuiElement *e) {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (e == NULL) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2020-08-13 12:38:07 +02:00
|
|
|
if (e == elements[i]) {
|
|
|
|
elements.erase(elements.begin() + i);
|
2017-10-29 10:28:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::removeAll() {
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
elements.clear();
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::close() {
|
2017-10-29 10:28:14 +01:00
|
|
|
//Application::instance()->pushForDelete(this);
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::dimBackground(bool d) {
|
2017-10-29 10:28:14 +01:00
|
|
|
dim = d;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
GuiElement *GuiFrame::getGuiElementAt(uint32_t index) const {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (index >= elements.size()) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return NULL;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
|
2017-10-29 10:28:14 +01:00
|
|
|
return elements[index];
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
uint32_t GuiFrame::getSize() {
|
2017-10-29 10:28:14 +01:00
|
|
|
return elements.size();
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::resetState() {
|
2017-10-29 10:28:14 +01:00
|
|
|
GuiElement::resetState();
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->resetState();
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::setState(int32_t s, int32_t c) {
|
2017-10-29 10:28:14 +01:00
|
|
|
GuiElement::setState(s, c);
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->setState(s, c);
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::clearState(int32_t s, int32_t c) {
|
2017-10-29 10:28:14 +01:00
|
|
|
GuiElement::clearState(s, c);
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->clearState(s, c);
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::setVisible(bool v) {
|
2017-10-29 10:28:14 +01:00
|
|
|
visible = v;
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->setVisible(v);
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
int32_t GuiFrame::getSelected() {
|
2017-10-29 10:28:14 +01:00
|
|
|
// find selected element
|
2018-06-21 20:44:58 +02:00
|
|
|
int32_t found = -1;
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < elements.size(); ++i) {
|
2020-08-13 12:38:07 +02:00
|
|
|
if (elements[i]->isStateSet(STATE_SELECTED | STATE_OVER)) {
|
2017-10-29 10:28:14 +01:00
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiFrame::draw(CVideo *v) {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (!this->isVisible() && parentElement) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (parentElement && dim == true) {
|
2017-10-29 10:28:14 +01:00
|
|
|
//GXColor dimColor = (GXColor){0, 0, 0, 0x70};
|
|
|
|
//Menu_DrawRectangle(0, 0, GetZPosition(), screenwidth,screenheight, &dimColor, false, true);
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
//! render appended items next frame but allow stop of render if size is reached
|
2018-06-21 20:44:58 +02:00
|
|
|
uint32_t size = elements.size();
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < size && i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->draw(v);
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::updateEffects() {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (!this->isVisible() && parentElement) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
GuiElement::updateEffects();
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
//! render appended items next frame but allow stop of render if size is reached
|
2018-06-21 20:44:58 +02:00
|
|
|
uint32_t size = elements.size();
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < size && i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->updateEffects();
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiFrame::process() {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (!this->isVisible() && parentElement) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
GuiElement::process();
|
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
//! render appended items next frame but allow stop of render if size is reached
|
2018-06-21 20:44:58 +02:00
|
|
|
uint32_t size = elements.size();
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < size && i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->process();
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
void GuiFrame::update(GuiController *c) {
|
2020-08-13 12:58:19 +02:00
|
|
|
if (isStateSet(STATE_DISABLED) && parentElement) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.lock();
|
2017-10-29 10:28:14 +01:00
|
|
|
//! update appended items next frame
|
2018-06-21 20:44:58 +02:00
|
|
|
uint32_t size = elements.size();
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
for (uint32_t i = 0; i < size && i < elements.size(); ++i) {
|
2017-10-29 10:28:14 +01:00
|
|
|
elements[i]->update(c);
|
|
|
|
}
|
2020-08-13 13:27:32 +02:00
|
|
|
mutex.unlock();
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|