How to set the icon at bottom of the screen in Single row in juce?

拜拜、爱过 提交于 2021-01-29 16:11:57

问题


I want to set the three image icon as per in the screens available. i have tried but i cut down from the bottom. Also, i am unable to make the click. can you please help me out. i am new in Juce framework.

#pragma once
#include <JuceHeader.h>


class CameraDemo  : public Component
{
public:
    CameraDemo()
    {
        setOpaque (true);
        updateCameraList();
        openCameraAsync(0);

        imgcaptureimg.setImage(ImageCache::getFromMemory(BinaryData::camicon_64_png,
                                                         BinaryData::camicon_64_pngSize));

        auto db = addToList(new DrawableButton("", DrawableButton::ImageRaw));
        db->setImages(&imgcaptureimg, nullptr, nullptr);
        db->setBounds(150, getParentHeight()-80, 80, 120);
        db->onClick = [this] {
            takeSnapshot();

        };

        imgpreviewimg.setImage(ImageCache::getFromMemory(BinaryData::camicon_32_png,
                                                         BinaryData::camicon_32_pngSize));
        auto db1 = addToList(new DrawableButton("", DrawableButton::ImageRaw));
        db1->setImages(&imgpreviewimg, nullptr, nullptr);
        db1->setBounds(5, getParentHeight()-80, 100, 50);
        db1->onClick = [this] {

        };

        imgchangecamera.setImage(ImageCache::getFromMemory(BinaryData::camicon_32_png,
                                                         BinaryData::camicon_32_pngSize));

        auto db2 = addToList(new DrawableButton("", DrawableButton::ImageRaw));
        db2->setImages(&imgchangecamera, nullptr, nullptr);
        db2->setBounds(310, getParentHeight()-80, 100, 50);
        db2->onClick = [this] {
            DBG("clicked");
        };



        setSize (getWidth(), getHeight());

       #if JUCE_IOS || JUCE_ANDROID
        setPortraitOrientationEnabled (true);
       #endif
    }

    ~CameraDemo() override
    {
       #if JUCE_IOS || JUCE_ANDROID
        setPortraitOrientationEnabled (false);
       #endif
    }

    //==============================================================================
    void paint (Graphics& g) override
    {
        g.fillAll (Colours::black);
    }

    void resized() override
    {

        auto r = getLocalBounds().reduced (5);
        auto previewArea = shouldUseLandscapeLayout() ? r.removeFromLeft (r.getWidth())
                                                      : r.removeFromTop (r.getHeight());

        if (cameraPreviewComp.get() != nullptr)
            cameraPreviewComp->setBounds (previewArea);

    }

private:
    //==============================================================================

    OwnedArray<Component> components;

    template<typename ComponentType>
    ComponentType *addToList(ComponentType *newComp) {
        components.add(newComp);
        addAndMakeVisible(newComp);
        return newComp;
    }
    StringArray devices;
    //Array<int> devices;
    std::unique_ptr<CameraDevice> cameraDevice;
    std::unique_ptr<Component> cameraPreviewComp;


    DrawableImage imgcaptureimg;
    DrawableImage imgpreviewimg;
    DrawableImage imgchangecamera;


    int selected = 0;
    bool isfrontcam = false;

    bool contentSharingPending = false;

    void setPortraitOrientationEnabled (bool shouldBeEnabled)
    {
        auto allowedOrientations = Desktop::getInstance().getOrientationsEnabled();

        if (shouldBeEnabled)
            allowedOrientations |= Desktop::upright;
        else
            allowedOrientations &= ~Desktop::upright;

        Desktop::getInstance().setOrientationsEnabled (allowedOrientations);
    }

    bool shouldUseLandscapeLayout() const noexcept
    {
       #if JUCE_ANDROID || JUCE_IOS
        auto orientation = Desktop::getInstance().getCurrentOrientation();
        return orientation == Desktop::rotatedClockwise || orientation == Desktop::rotatedAntiClockwise;
       #else
        return false;
       #endif
    }

    void updateCameraList()
    {
        devices.clear();

        /*cameraSelectorComboBox.clear();
        cameraSelectorComboBox.addItem ("No camera", 1);
        cameraSelectorComboBox.addSeparator();*/
        devices.add(""+1);
        auto cameras = CameraDevice::getAvailableDevices();

        for (int i = 0; i < cameras.size(); ++i)
           // cameraSelectorComboBox.addItem (cameras[i], i + 2);
            devices.add(""+i);
    }

    void cameraChanged(int val)
    {

        // This is called when the user chooses a camera from the drop-down list.
      // #if JUCE_IOS
        // On iOS, when switching camera, open the new camera first, so that it can
        // share the underlying camera session with the old camera. Otherwise, the
        // session would have to be closed first, which can take several seconds.
       /* if (devices == 1)
            cameraDevice.reset();
       #else*/
        cameraDevice.reset();
      // #endif
        cameraPreviewComp.reset();
        //recordingMovie = false;

       // if (cameraSelectorComboBox.getSelectedId() > 1)
      //  {
        //   #if JUCE_ANDROID || JUCE_IOS
            openCameraAsync(val);
         //  #else
         //   cameraDeviceOpenResult (CameraDevice::openDevice (cameraSelectorComboBox.getSelectedId() - 2), {});
          // #endif
       // }
       // else
       // {
        //    snapshotButton   .setEnabled (cameraDevice != nullptr && ! contentSharingPending);
            //recordMovieButton.setEnabled (cameraDevice != nullptr && ! contentSharingPending);
        //    resized();
        //}
    }

    void openCameraAsync(int val)
    {
        SafePointer<CameraDemo> safeThis (this);

        CameraDevice::openDeviceAsync (val,
                                       [safeThis] (CameraDevice* device, const String& error) mutable
                                       {
                                           if (safeThis)
                                               safeThis->cameraDeviceOpenResult (device, error);
                                       });
        isfrontcam = true;

    }

    void cameraDeviceOpenResult (CameraDevice* device, const String& error)
    {
        // If camera opening worked, create a preview component for it..
        cameraDevice.reset (device);

        if (cameraDevice.get() != nullptr)
        {
           #if JUCE_ANDROID
            SafePointer<CameraDemo> safeThis (this);
            cameraDevice->onErrorOccurred = [safeThis] (const String& cameraError) mutable { if (safeThis) safeThis->errorOccurred (cameraError); };
           #endif
            cameraPreviewComp.reset (cameraDevice->createViewerComponent());
            addAndMakeVisible (cameraPreviewComp.get());
        }
        else
        {
            AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Camera open failed",
                                              "Camera open failed, reason: " + error);
        }

     //   snapshotButton   .setEnabled (cameraDevice.get() != nullptr && ! contentSharingPending);
        //recordMovieButton.setEnabled (cameraDevice.get() != nullptr && ! contentSharingPending);
        resized();
    }

    void takeSnapshot()
    {
        SafePointer<CameraDemo> safeThis (this);
        cameraDevice->takeStillPicture ([safeThis] (const Image& image) mutable { safeThis->imageReceived (image); });
    }

    // This is called by the camera device when a new image arrives
    void imageReceived (const Image& image)
    {
        if (! image.isValid())
            return;

      //  lastSnapshot.setImage (image);

       #if JUCE_ANDROID || JUCE_IOS
        auto imageFile = File::getSpecialLocation (File::tempDirectory).getNonexistentChildFile ("JuceCameraPhotoDemo", ".jpg");

        FileOutputStream stream (imageFile);

        if (stream.openedOk()
             && JPEGImageFormat().writeImageToStream (image, stream))
        {
            URL url (imageFile);

           // snapshotButton   .setEnabled (false);

            contentSharingPending = true;

            SafePointer<CameraDemo> safeThis (this);

            juce::ContentSharer::getInstance()->shareFiles ({url},
                                                            [safeThis] (bool success, const String&) mutable
                                                            {
                                                                if (safeThis)
                                                                    safeThis->sharingFinished (success, true);
                                                            });
        }
       #endif
    }

    void errorOccurred (const String& error)
    {
        AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
                                          "Camera Device Error",
                                          "An error has occurred: " + error + " Camera will be closed.");

        cameraDevice.reset();

       // cameraSelectorComboBox.setSelectedId (1);
      //  snapshotButton   .setEnabled (false);

    }

    void sharingFinished (bool success, bool isCapture)
    {
        AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
                                          isCapture ? "Image sharing result" : "Video sharing result",
                                          success ? "Success!" : "Failed!");

        contentSharingPending = false;
       // snapshotButton   .setEnabled (true);

    }

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CameraDemo)
};

来源:https://stackoverflow.com/questions/61379818/how-to-set-the-icon-at-bottom-of-the-screen-in-single-row-in-juce

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!