Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Making A Slider Component Problem  (Read 2614 times)
0 Members and 1 Guest are viewing this topic.
Offline Dicee

Junior Member


Medals: 2



« Reply #30 - Posted 2013-12-19 12:59:13 »

There's nothing to test, the problem is in the computation for box, since multiplier returns correct value, 0.5 for 500.
Offline Dicee

Junior Member


Medals: 2



« Reply #31 - Posted 2013-12-19 13:23:35 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    public void setValue(float newValue) {
        if (this.value != newValue) {
            float multiplier;        
            this.value = Math.min(Math.max(this.minValue, newValue), this.maxValue);    
            multiplier = (this.value / this.maxValue);
            this.percentage = multiplier * 100.0f;  
            this.sliderBoxX = this.lineX + (this.lineWidth * ((this.value / (this.maxValue - this.minValue))))
                             - Math.round(sliderBoxWidth / 2)
                             - this.lineWidth;
        }
    }

I'm not sure is this correct way to compute slideboxx, but slider box does move now properly.

EDIT:
Just kidding, now it does not compute for case where we have for a minValue/maxValue 0/1000, but works for 500/1000...
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #32 - Posted 2013-12-19 13:31:59 »

It sounds like the line position and width variables might not be set correctly whenthe setValue(...) function is called. Huh Try changing the function to the following"
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void setValue(float newValue) {
   if(this.value != newValue) {
      float multiplier;
     
      System.out.println("Values before recalculation: sliderBoxWidth=" + this.sliderBoxWidth + ", lineWidth=" + this.lineWidth + ", lineX=" + this.lineX);

      // Make sure that these variables are set to the correct value before computing the handle position.
     this.sliderBoxWidth = Math.round(this.height / 2);
      this.lineWidth = Math.round(this.width - this.sliderBoxWidth);
      this.lineX = Math.round(this.x + (this.sliderBoxWidth / 2));
     
      System.out.println("Values after recalculation: sliderBoxWidth=" + this.sliderBoxWidth + ", lineWidth=" + this.lineWidth + ", lineX=" + this.lineX);

      this.value = Math.min(Math.max(this.minValue, newValue), this.maxValue);
      multiplier = (this.value/this.maxValue);
      this.percentage = multiplier * 100.0f;
      this.sliderBoxX = Math.round(this.lineX + (this.lineWidth * multiplier) - (this.sliderBoxWidth/2));
      // sets a slider value on the text field
     tempField.setText(String.valueOf(getValue()));
   }
}


This should dump the values to the console so they can be compared.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Dicee

Junior Member


Medals: 2



« Reply #33 - Posted 2013-12-19 13:45:06 »

1  
2  
Values before recalculation: sliderBoxWidth=13.0, lineWidth=192.0, lineX=262.0
Values after recalculation: sliderBoxWidth=13.0, lineWidth=192.0, lineX=262.0


I could here set the condition before initializing sliderBoxX variable, so if minValue is 0, then subtract sliderBox for lineWidth, else, don't subtract that lineWidth.
But I think this is dirty way...
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #34 - Posted 2013-12-19 13:48:06 »

Hmm, give me a bit of time to get the test harness set up again, and I will see if I can see what's going on with the positioning. Cheesy

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline Dicee

Junior Member


Medals: 2



« Reply #35 - Posted 2013-12-19 13:48:59 »

K, I will be here.

EDIT:

This was the idea.
Now, it works for both cases:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
    public void setValue(float newValue) {
        if (this.value != newValue) {
            float multiplier;        
            this.value = Math.min(Math.max(this.minValue, newValue), this.maxValue);    
            multiplier = (this.value / this.maxValue);
            this.percentage = multiplier * 100.0f;  
            float sBoxX = this.lineX + (this.lineWidth * ((this.value / Math.abs(this.maxValue - this.minValue))))
                                     - Math.round(sliderBoxWidth / 2);
            if (this.minValue != 0) {
                sBoxX = sBoxX - this.lineWidth;
            }
            this.sliderBoxX = sBoxX;
//            this.sliderBoxX = this.lineX + (this.lineWidth * ((this.value / Math.abs(this.maxValue - this.minValue))))
//                             - Math.round(sliderBoxWidth / 2)
//                             - this.lineWidth;
       }
    }


But don't you think it's dirty..? Smiley
I believe, now you can maybe see where's the problem.
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #36 - Posted 2013-12-19 16:41:12 »

Sorry I took a little bit to get back to you. I was getting ready to head out the door to work when I posted my last reply.

This was the idea.
Now, it works for both cases:
But don't you think it's dirty..? Smiley
I believe, now you can maybe see where's the problem.

Yeah, the problem was an elementary mistake on my end. Roll Eyes Try changing your "setValue(...)" method to the following and let me know if it helps.

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void setValue(float newValue) {
        if (this.value != newValue) {
            float multiplier;        
            this.value = Math.min(Math.max(this.minValue, newValue), this.maxValue);    
            multiplier = (this.value-this.MinValue)/(this.maxValue-this.minValue);
            this.percentage = multiplier * 100.0f;
            this.sliderBoxX = Math.round(this.lineX + (this.lineWidth * multiplier) - (this.sliderBoxWidth/2));
        }
}

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline Dicee

Junior Member


Medals: 2



« Reply #37 - Posted 2013-12-19 16:49:58 »

Yep, that works.

This is what I did, when I was trying,
1  
multiplier = (this.value- (this.maxValue / this.minValue));

but, I forgot to subtract and minValue, so that's why it didn't want to work first time.

Thank once again!
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #38 - Posted 2013-12-19 16:53:01 »

That was one of those moments when I smacked myself in the head after I figured out the mistake. Glad to know it worked for you. Have a great one, my friend. Cool

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline KudoDEV

Senior Newbie





« Reply #39 - Posted 2013-12-21 17:20:12 »

Back when I used Slick2d and needed a simple ui I used this: https://code.google.com/p/slick-sui/ its clean(for the most part) and easy to edit to your liking.
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (59 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!