private Slider createPercentSlider() {
   final Slider percentSlider = new Slider(1, 100);
   percentSlider.addListener(
       new Property.ValueChangeListener() {
         @Override
         public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
           percentLabel.setValue(Double.toString(percentSlider.getValue()) + " %");
           changePercentage((int) ((double) percentSlider.getValue()));
         }
       });
   percentSlider.setValue(50d);
   return percentSlider;
 }
Beispiel #2
0
  protected ListBox(
      ControlP5 theControlP5,
      ControllerGroup<?> theGroup,
      String theName,
      int theX,
      int theY,
      int theW,
      int theH) {
    super(theControlP5, theGroup, theName, theX, theY, theW, 9);

    items = new ArrayList<ListBoxItem>();

    buttons = new ArrayList<Button>();

    _myWidth = theW;

    _myName = theName;

    // workaround fix see code.goode.com/p/controlp5 issue 7
    _myBackgroundHeight = theH < 10 ? 10 : theH;

    _myScrollbar =
        new Slider(
            cp5,
            _myParent,
            theName + "Scroller",
            0,
            1,
            1,
            _myWidth - _myScrollbarWidth,
            0,
            _myScrollbarWidth,
            _myBackgroundHeight);
    _myScrollbar.setBroadcast(false);
    _myScrollbar.setSliderMode(Slider.FLEXIBLE);
    _myScrollbar.setMoveable(false);
    _myScrollbar.setLabelVisible(false);
    _myScrollbar.setParent(this);
    _myScrollbar.addListener(this);
    _myScrollbar.setVisible(false);
    _myScrollbar.hide();
    _myScrollbar.updateDisplayMode(DEFAULT);
    add(_myScrollbar);
    setHeight(_myBackgroundHeight);
  }
Beispiel #3
0
  private void initalize() {

    //
    // Wygenerowanie buttonow
    //
    sliderR = GuiResource.slider(0, 100, 1, "colorDialogSliderR", skin);
    sliderG = GuiResource.slider(0, 100, 1, "colorDialogSliderG", skin);
    sliderB = GuiResource.slider(0, 100, 1, "colorDialogSliderB", skin);
    sliderA = GuiResource.slider(0, 100, 1, "colorDialogSliderA", skin);

    //
    // Fix slider FixScroll
    //
    sliderR.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
          }
        });

    sliderG.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
          }
        });

    sliderB.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
          }
        });

    sliderA.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
          }
        });

    labelTextR = GuiResource.label("R", "colorTextDialogLabelR", skin);
    labelTextG = GuiResource.label("G", "colorTextDialogLabelG", skin);
    labelTextB = GuiResource.label("B", "colorTextDialogLabelB", skin);
    labelTextA = GuiResource.label("A", "colorTextDialogLabelA", skin);

    labelR = GuiResource.label("red", "colorDialogLabelR", skin);
    labelG = GuiResource.label("green", "colorDialogLabelG", skin);
    labelB = GuiResource.label("blue", "colorDialogLabelB", skin);
    labelA = GuiResource.label("alpha", "colorDialogLabelA", skin);

    color = new Color();

    //
    // Tworzenie image textury podgladu
    //
    pixmap = new Pixmap(128, 32, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888);
    pixmap.setColor(1, 1, 1, 1);
    pixmap.fillRectangle(0, 0, 128, 32);
    texture = new Texture(pixmap);
    region = new TextureRegion(texture);
    imageActor = new Image(region);

    //
    // Podpiecie akcji do buttonow i sliderow
    //
    sliderR.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            float value = sliderR.getValue();
            colorR = value / 100;
            setBtnColorSampleColor();
          }
        });

    sliderG.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            float value = sliderG.getValue();
            colorG = value / 100;
            setBtnColorSampleColor();
          }
        });

    sliderB.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            float value = sliderB.getValue();
            colorB = value / 100;
            setBtnColorSampleColor();
          }
        });

    sliderA.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            float value = sliderA.getValue();
            colorA = value / 100;
            setBtnColorSampleColor();
          }
        });

    add(labelTextR).left().width(10);
    add(sliderR).left().fillX().expandX();
    add(labelR).left().width(20);
    row();
    add(labelTextG).left().width(10);
    add(sliderG).left().fillX().expandX();
    add(labelG).left().width(20);
    row();
    add(labelTextB).left().width(10);
    add(sliderB).left().fillX().expandX();
    add(labelB).left().width(20);

    if (alphaChanel) {
      row();
      add(labelTextA).left().width(10);
      add(sliderA).left().fillX().expandX();
      add(labelA).left().width(20);
    }

    row();
    add().left().width(Cfg.gridX1);
    add(imageActor).left().colspan(2);

    //
    // Inicjacja stanów
    //
    if (colorR < 0) {
      colorR = 0;
    }
    if (colorR > 1) {
      colorR = 1;
    }
    if (colorG < 0) {
      colorG = 0;
    }
    if (colorG > 1) {
      colorG = 1;
    }
    if (colorB < 0) {
      colorB = 0;
    }
    if (colorB > 1) {
      colorB = 1;
    }
    if (colorA < 0) {
      colorA = 0;
    }
    if (colorA > 1) {
      colorA = 1;
    }

    sliderR.setValue(colorR * 100);
    sliderG.setValue(colorG * 100);
    sliderB.setValue(colorB * 100);
    sliderA.setValue(colorA * 100);
    setBtnColorSampleColor();
  }