void ImageGlyph::set(const ImageRGBA& rgba, AlloyContext* context) {
	nvgUpdateImage(context->nvgContext, handle, rgba.ptr());
}
Exemplo n.º 2
0
    void OGUIFileBrowser::draw() {
        // ToDo (damiles): Create scroll for more files in window
        if (_is_file_browser_visible) {
            NVGcontext *vg = (NVGcontext *) _window->vg;
            nvgBeginPath(vg);
            nvgRect(vg, 0, 0, _window->getWindowWidth(), _window->getWindowHeight());
            nvgFillColor(vg, nvgRGBA(28, 30, 34, 255));
            nvgFill(vg);

            // sep line
            nvgBeginPath(vg);
            nvgMoveTo(vg, 200, 40);
            nvgLineTo(vg, 200, _window->getWindowHeight());
            nvgFillColor(vg, nvgRGBA(0,0,0,255));
            nvgFill(vg);

            nvgBeginPath(vg);
            nvgMoveTo(vg, 0, 40);
            nvgLineTo(vg, _window->getWindowWidth(), 40);
            nvgFillColor(vg, nvgRGBA(0,0,0,255));
            nvgFill(vg);

            nvgBeginPath(vg);
            nvgMoveTo(vg, 200, _window->getWindowHeight()-40);
            nvgLineTo(vg, _window->getWindowWidth(), _window->getWindowHeight()-40);
            nvgFillColor(vg, nvgRGBA(0,0,0,255));
            nvgFill(vg);

            // Draw accept and cancel buttons
            if(drawBasicButton(vg, this->_window, "Accept", _window->getWindowWidth()-100, _window->getWindowHeight()-30, 90, 20, _window->mouse_x, _window->mouse_y)){
                _is_file_browser_visible=0;
            }

            if(drawBasicButton(vg, this->_window, "Close", _window->getWindowWidth()-200, _window->getWindowHeight()-30, 90, 20, _window->mouse_x, _window->mouse_y)){
                _file_browser_result= NULL;
                _is_file_browser_visible=0;
            }

            // Draw de devices we found
            drawHeader(vg, "System", 0, 40, 200);

            // Draw system files
            int x=10;
            int y=75;
            for(int i=0; i<_system.size(); i++){
                OGUIFile *file= _system.at(i);
                if( file->draw(vg, x, y, _window->mouse_x, _window->mouse_y) ){ // is clicked
                    _file_browser_result= file;
                    if(_file_browser_result!=NULL) {
                        if (_file_browser_result->_is_dir
                            && _actual_folder.compare(_file_browser_result->_path) != 0) {
                            readFolder(_file_browser_result->_path);
                            _actual_folder= _file_browser_result->_path;
                            _file_browser_result = NULL;
                        }
                    }
                }
                y+=22;

            }



            // Draw files
            x=210;
            y=50;
            int max_height= _window->getWindowHeight()-80;
            for(int i=0; i<_file_list.size(); i++){
                OGUIFile *file= _file_list.at(i);
                if( file->draw(vg, x, y, _window->mouse_x, _window->mouse_y) ){ // is clicked
                    _file_browser_result= file;
                    if(_file_browser_result!=NULL) {
                        if (_file_browser_result->_is_dir
                            && _actual_folder.compare(_file_browser_result->_path) != 0) {
                            readFolder(_file_browser_result->_path);
                            _actual_folder= _file_browser_result->_path;
                            _file_browser_result = NULL;
                        }
                    }
                }
                y+=22;
                if(y>=max_height){
                    x+=202;
                    y=50;
                }
            }

            // Show icon in header
            nvgFontSize(vg, 16.0f);
            nvgFontFace(vg, "icons");
            nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_TOP);
            nvgFillColor(vg, nvgRGBA(0,0,0,255));
            nvgText(vg, 10, 11, "\uF115", NULL);
            nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
            nvgText(vg, 11, 13, "\uF115", NULL);
            nvgFillColor(vg, nvgRGBA(255,255,255,255));

            // show path in header
            nvgFontSize(vg, 18.0f);
            nvgFontFace(vg, "sans-bold");
            nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
            nvgFillColor(vg, nvgRGBA(0, 0, 0, 255));
            nvgText(vg, 35, 10, resolved_path, NULL);
            nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
            nvgText(vg, 36, 12, resolved_path, NULL);

            if(_file_browser_result!=NULL) {
                if (_file_browser_result->_is_dir == false) {
                    // show file in footer
                    nvgFontSize(vg, 18.0f);
                    nvgFontFace(vg, "sans-bold");
                    nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
                    nvgFillColor(vg, nvgRGBA(0, 0, 0, 255));
                    nvgText(vg, 209, _window->getWindowHeight()-32, _file_browser_result->_file_name.c_str(), NULL);
                    nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
                    nvgText(vg, 210, _window->getWindowHeight()-30, _file_browser_result->_file_name.c_str(), NULL);

                    // Draw preview if its image
                    if(_file_browser_result->isImage()){
                        x=0;
                        y=_window->getWindowHeight()-200;

                        drawHeader(vg, "Preview", 0, y-30, 200);


                        int w=200;
                        int h=200;
                        NVGpaint bg;
                        // Box
                        bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32));
                        nvgBeginPath(vg);
                        nvgRoundedRect(vg, x+1,y+1, w-2,h-2, 4-1);
                        nvgFillPaint(vg, bg);
                        nvgFill(vg);

                        nvgBeginPath(vg);
                        nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, 4-0.5f);
                        nvgStrokeColor(vg, nvgRGBA(0,0,0,48));
                        nvgStroke(vg);

                        // Image preview
                        if(_preview_image==-1){
                            _preview_image= nvgCreateImageRGBA(vg, 150, 150, 0, _file_browser_result->getPreview());
                        }else{
                            nvgUpdateImage(vg, _preview_image, _file_browser_result->getPreview());
                        }

                        NVGpaint imgPaint = nvgImagePattern(vg, 25, y+25, 150, 150, 0, _preview_image, 1);
                        nvgBeginPath(vg);
                        nvgRect(vg, 25, y+25, 150,150);
                        nvgFillPaint(vg, imgPaint);
                        nvgFill(vg);
                    }


                }
            }


        }
    }