mousewheel scrollbar in mods menu
This commit is contained in:
parent
ae003836c3
commit
f841df34bb
|
@ -333,7 +333,7 @@ void GraphicComponent::init(int x, int y, int w, int h) {
|
||||||
enabled= true;
|
enabled= true;
|
||||||
}
|
}
|
||||||
bool GraphicComponent::eventMouseWheel(int x, int y,int zDelta){
|
bool GraphicComponent::eventMouseWheel(int x, int y,int zDelta){
|
||||||
return false;
|
return mouseMove(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicComponent::mouseMove(int x, int y) {
|
bool GraphicComponent::mouseMove(int x, int y) {
|
||||||
|
@ -918,13 +918,7 @@ void GraphicComboBox::togglePopupVisibility(){
|
||||||
|
|
||||||
bool GraphicComboBox::eventMouseWheel(int x, int y, int zDelta) {
|
bool GraphicComboBox::eventMouseWheel(int x, int y, int zDelta) {
|
||||||
if (popupShowing == true) {
|
if (popupShowing == true) {
|
||||||
int newVisibleStart = scrollBar.getVisibleStart() - zDelta/60;
|
scrollBar.eventMouseWheel(x,y,zDelta,true);
|
||||||
if (newVisibleStart < 0)
|
|
||||||
newVisibleStart = 0;
|
|
||||||
if (newVisibleStart > scrollBar.getLength() - scrollBar.getVisibleSize())
|
|
||||||
newVisibleStart = scrollBar.getLength() - scrollBar.getVisibleSize();
|
|
||||||
|
|
||||||
scrollBar.setVisibleStart(newVisibleStart);
|
|
||||||
layoutButtons();
|
layoutButtons();
|
||||||
mouseMoveOverButtons(x,y);
|
mouseMoveOverButtons(x,y);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1316,6 +1310,23 @@ bool GraphicScrollBar::mouseClick(int x, int y){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GraphicScrollBar::eventMouseWheel(int x, int y, int zDelta) {
|
||||||
|
return eventMouseWheel(x,y,zDelta,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GraphicScrollBar::eventMouseWheel(int x, int y, int zDelta,bool ignorePos) {
|
||||||
|
if(ignorePos|| GraphicComponent::mouseMove(x, y)){
|
||||||
|
int newVisibleStart = this->getVisibleStart() - zDelta/60;
|
||||||
|
if (newVisibleStart < 0)
|
||||||
|
newVisibleStart = 0;
|
||||||
|
if (newVisibleStart > this->getLength() - this->getVisibleSize())
|
||||||
|
newVisibleStart = this->getLength() - this->getVisibleSize();
|
||||||
|
|
||||||
|
this->setVisibleStart(newVisibleStart);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool GraphicScrollBar::mouseMove(int x, int y){
|
bool GraphicScrollBar::mouseMove(int x, int y){
|
||||||
if(this->getVisible() == false) {
|
if(this->getVisible() == false) {
|
||||||
|
|
|
@ -270,6 +270,8 @@ public:
|
||||||
GraphicScrollBar(const std::string &containerName="", const std::string &objName="");
|
GraphicScrollBar(const std::string &containerName="", const std::string &objName="");
|
||||||
void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness);
|
void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness);
|
||||||
virtual bool mouseDown(int x, int y);
|
virtual bool mouseDown(int x, int y);
|
||||||
|
virtual bool eventMouseWheel(int x, int y,int zDelta);
|
||||||
|
virtual bool eventMouseWheel(int x, int y,int zDelta,bool ignorePos);
|
||||||
virtual bool mouseMove(int x, int y);
|
virtual bool mouseMove(int x, int y);
|
||||||
virtual void mouseUp(int x, int y);
|
virtual void mouseUp(int x, int y);
|
||||||
virtual bool mouseClick(int x, int y);
|
virtual bool mouseClick(int x, int y);
|
||||||
|
|
|
@ -2105,6 +2105,38 @@ void MenuStateMods::mouseMove(int x, int y, const MouseState *ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MenuStateMods::eventMouseWheel( GraphicScrollBar* scrollBar, UserButtons* buttons, int x, int y, int zDelta) {
|
||||||
|
int result=false;
|
||||||
|
int overButton=false;
|
||||||
|
if(scrollBar->getElementCount() !=0) {
|
||||||
|
for(int i = scrollBar->getVisibleStart(); i <= scrollBar->getVisibleEnd(); ++i) {
|
||||||
|
if((*buttons)[i]->mouseMove(x, y)) {
|
||||||
|
overButton=true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result= scrollBar->eventMouseWheel(x, y, zDelta,overButton);
|
||||||
|
if(result) layoutButtons(scrollBar,buttons,NULL);
|
||||||
|
|
||||||
|
if(scrollBar->getElementCount() !=0) {
|
||||||
|
for(int i = scrollBar->getVisibleStart(); i <= scrollBar->getVisibleEnd(); ++i) {
|
||||||
|
(*buttons)[i]->mouseMove(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuStateMods::eventMouseWheel(int x, int y, int zDelta) {
|
||||||
|
bool result = eventMouseWheel(&keyMapScrollBar, &keyMapButtons, x, y, zDelta);
|
||||||
|
if (!result)
|
||||||
|
result = eventMouseWheel(&keyTechScrollBar, &keyTechButtons, x, y, zDelta);
|
||||||
|
if (!result)
|
||||||
|
result = eventMouseWheel(&keyScenarioScrollBar, &keyScenarioButtons, x, y, zDelta);
|
||||||
|
if (!result)
|
||||||
|
result = eventMouseWheel(&keyTilesetScrollBar, &keyTilesetButtons, x, y, zDelta);
|
||||||
|
}
|
||||||
|
|
||||||
void MenuStateMods::cleanupPreviewTexture() {
|
void MenuStateMods::cleanupPreviewTexture() {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogoTexture [%p]\n",__FILE__,__FUNCTION__,__LINE__,modPreviewImage);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] scenarioLogoTexture [%p]\n",__FILE__,__FUNCTION__,__LINE__,modPreviewImage);
|
||||||
|
|
||||||
|
@ -2441,77 +2473,31 @@ void MenuStateMods::render() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuStateMods::layoutButtons(GraphicScrollBar * scrollBar,UserButtons* buttons, GraphicLabels* labels){
|
||||||
|
if (scrollBar->getElementCount() != 0) {
|
||||||
|
for (int i = scrollBar->getVisibleStart();
|
||||||
|
i <= scrollBar->getVisibleEnd(); ++i) {
|
||||||
|
if(i >= (int)buttons->size()) {
|
||||||
|
char szBuf[8096]="";
|
||||||
|
snprintf(szBuf,8096,"i >= buttons->size(), i = %d, buttons->size() = %d",i,(int)buttons->size());
|
||||||
|
throw megaglest_runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
(*buttons)[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i - scrollBar->getVisibleStart()));
|
||||||
|
if (labels != NULL) {
|
||||||
|
(*labels)[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i - scrollBar->getVisibleStart()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MenuStateMods::update() {
|
void MenuStateMods::update() {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
//Lang &lang= Lang::getInstance();
|
layoutButtons(&keyMapScrollBar, &keyMapButtons, &labelsMap);
|
||||||
|
layoutButtons(&keyTechScrollBar, &keyTechButtons, &labelsTech);
|
||||||
// Tech List
|
layoutButtons(&keyTilesetScrollBar, &keyTilesetButtons, NULL);
|
||||||
if (keyTechScrollBar.getElementCount() != 0) {
|
layoutButtons(&keyScenarioScrollBar, &keyScenarioButtons, NULL);
|
||||||
for (int i = keyTechScrollBar.getVisibleStart();
|
|
||||||
i <= keyTechScrollBar.getVisibleEnd(); ++i) {
|
|
||||||
if(i >= (int)keyTechButtons.size()) {
|
|
||||||
char szBuf[8096]="";
|
|
||||||
snprintf(szBuf,8096,"i >= keyTechButtons.size(), i = %d, keyTechButtons.size() = %d",i,(int)keyTechButtons.size());
|
|
||||||
throw megaglest_runtime_error(szBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
keyTechButtons[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i
|
|
||||||
- keyTechScrollBar.getVisibleStart()));
|
|
||||||
labelsTech[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i
|
|
||||||
- keyTechScrollBar.getVisibleStart()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tileset List
|
|
||||||
if (keyTilesetScrollBar.getElementCount() != 0) {
|
|
||||||
for (int i = keyTilesetScrollBar.getVisibleStart();
|
|
||||||
i <= keyTilesetScrollBar.getVisibleEnd(); ++i) {
|
|
||||||
if(i >= (int)keyTilesetButtons.size()) {
|
|
||||||
char szBuf[8096]="";
|
|
||||||
snprintf(szBuf,8096,"i >= keyTilesetButtons.size(), i = %d, keyTilesetButtons.size() = %d",i,(int)keyTilesetButtons.size());
|
|
||||||
throw megaglest_runtime_error(szBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
int yPos = keyButtonsYBase - keyButtonsLineHeight *
|
|
||||||
(i - keyTilesetScrollBar.getVisibleStart());
|
|
||||||
keyTilesetButtons[i]->setY(yPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map List
|
|
||||||
if (keyMapScrollBar.getElementCount() != 0) {
|
|
||||||
for (int i = keyMapScrollBar.getVisibleStart();
|
|
||||||
i <= keyMapScrollBar.getVisibleEnd(); ++i) {
|
|
||||||
if(i >= (int)keyMapButtons.size()) {
|
|
||||||
char szBuf[8096]="";
|
|
||||||
snprintf(szBuf,8096,"i >= keyMapButtons.size(), i = %d, keyMapButtons.size() = %d",i,(int)keyMapButtons.size());
|
|
||||||
throw megaglest_runtime_error(szBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
keyMapButtons[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i
|
|
||||||
- keyMapScrollBar.getVisibleStart()));
|
|
||||||
labelsMap[i]->setY(keyButtonsYBase - keyButtonsLineHeight * (i
|
|
||||||
- keyMapScrollBar.getVisibleStart()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scenario List
|
|
||||||
if (keyScenarioScrollBar.getElementCount() != 0) {
|
|
||||||
for (int i = keyScenarioScrollBar.getVisibleStart();
|
|
||||||
i <= keyScenarioScrollBar.getVisibleEnd(); ++i) {
|
|
||||||
if(i >= (int)keyScenarioButtons.size()) {
|
|
||||||
char szBuf[8096]="";
|
|
||||||
snprintf(szBuf,8096,"i >= keyScenarioButtons.size(), i = %d, keyScenarioButtons.size() = %d",i,(int)keyScenarioButtons.size());
|
|
||||||
throw megaglest_runtime_error(szBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
int yPos = keyButtonsYBase - keyButtonsLineHeight *
|
|
||||||
(i - keyScenarioScrollBar.getVisibleStart());
|
|
||||||
keyScenarioButtons[i]->setY(yPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.update();
|
console.update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,7 @@ public:
|
||||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||||
void mouseUp(int x, int y, const MouseButton mouseButton);
|
void mouseUp(int x, int y, const MouseButton mouseButton);
|
||||||
void mouseMove(int x, int y, const MouseState *mouseState);
|
void mouseMove(int x, int y, const MouseState *mouseState);
|
||||||
|
void eventMouseWheel(int x, int y,int zDelta);
|
||||||
void render();
|
void render();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
@ -203,6 +204,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool eventMouseWheel(GraphicScrollBar* scrollBar, UserButtons* buttons,int x, int y,int zDelta);
|
||||||
|
void layoutButtons(GraphicScrollBar * scrollBar,UserButtons* buttons, GraphicLabels* labels);
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
MapInfo loadMapInfo(string file);
|
MapInfo loadMapInfo(string file);
|
||||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user