Esempio n. 1
0
	/*
	** Okay, this function is hideous, but it works
	*/
	void refresh() override {
		frame_.clear();
		if(!empty()) {
			auto selected=selected_idx();
			const auto dime=get_dimension();


			//ensure inrange
			auto max_idx=size()-1;
			if(selected > max_idx) {
				selected=max_idx;
			}


			//iterator to selected position
			const_iterator top, bottom, selected_it=cbegin();
			std::advance(selected_it, selected);
			top=bottom=selected_it;


			//This holds all the compoent pads, deque so we can add to front and back
			std::deque<cons::frame> message_frames;
			
			//the amount of verticle space used by the pads so far
			int y_used=0;

			//start with the selected message
			message_frames.push_back(message_to_pad<stencil_type>(stencil, *selected_it, dime));
			if(selected_colour) {
				//TODO: this must be optimised, by just passing the colour_piar
				message_frames.back().set_background(selected_colour->get_background());
				message_frames.back().set_foreground(selected_colour->get_foreground());
			}

			y_used=message_frames.back().get_dimension().y;
			


			//true whilst there are still more upper & lower values
			//when both are false loop breaks
			bool tdo=true, bdo=true;

			
			//constructs the vector of frames
			while(y_used < dime.y && (tdo || bdo)) {
				//produce a forerunning message
				if(top!=cbegin()) {
					--top;
					message_frames.push_front(message_to_pad<stencil_type>(stencil, *top, dime));
					y_used+=message_frames.front().get_dimension().y;
				}
				else tdo=false;

				//produce a trailng message
				if(bdo) { //stops incrementing ptr once obsolete
					++bottom;
					if(bottom!=cend() && y_used < dime.y) {
						message_frames.push_back(message_to_pad<stencil_type>(stencil, *bottom, dime));
						y_used+=message_frames.back().get_dimension().y;
					}
					else bdo=false;
				}
			}

			//compile vector into single frame
			int y=0;
			for(auto& mfrm : message_frames) {
				auto dime=mfrm.get_dimension();
				copy(mfrm, frame_, {0,0}, {0,y}, dime);
				y+=dime.y;
			}
		}
		frame_.refresh();
	}