Beispiel #1
0
//! Get the current time as a string.
std::string GetLocalTimeString()
{
    Poco::LocalDateTime *time = new Poco::LocalDateTime();
    std::stringstream ss;
    
    ss << std::setw(2) << time->hour() << std::setfill('0') << ":" <<
        std::setw(2) << time->minute() << std::setfill('0') << ":" <<
        std::setw(2) << time->second() << std::setfill('0');
        
    SAFE_DELETE(time);
    
    return ss.str();
}
//--------------------------------------------------------------
void ofApp::draw(){
    
    Poco::LocalDateTime now; //(2015,5,29,17,38);
    
    if(ofGetKeyPressed(OF_KEY_ALT)) {
        // auto step the time of day to proof changes
        int total_min = fabs(sin(ofGetElapsedTimef()*.05)) * 1440; // 1440 == mins per day  60 * 24
        int hr = floor(total_min/60.0);
        int mn = total_min - (hr*60); //now.minute();
        now.assign(now.year(), now.month(), now.day(), hr, mn);
    }
    
    float sun_brightness = ofxSunCalc::getSunBrightness(todayInfo, now);
    
    if(ofGetKeyPressed(OF_KEY_COMMAND)) {
        sun_brightness = fabs(sin(ofGetElapsedTimef()*.1));
    }
    
    // draw background gradient based on sun_brightness
    
    ofColor nightBG(ofColor::black);
    ofColor nightFG(64);
    
    ofColor dayBG(ofColor::skyBlue);
    ofColor dayFG(ofColor::paleGoldenRod);
    
    ofColor background = nightBG.lerp(dayBG, sun_brightness);
    ofColor foreground = nightFG.lerp(dayFG, sun_brightness);
    
    ofBackgroundGradient(foreground, background);
    
    ofDrawBitmapStringHighlight(date_str, 15, 20, ofColor::paleGoldenRod, ofColor::black);
    
    ofDrawBitmapStringHighlight(min_info_str, 15, 45, ofColor::salmon, ofColor::white);
    
    ofDrawBitmapStringHighlight(max_info_str, 15, 125, ofColor::darkorange, ofColor::white);
    
    ofDrawBitmapStringHighlight(latlon_str, 180, 20, ofColor::gold, ofColor::black);
    
    ofDrawBitmapStringHighlight(pos_str, 180, 45, ofColor::cornsilk, ofColor::black);
    
    ofDrawBitmapStringHighlight("Current Brightness " + ofToString(sun_brightness, 3), 180, 70, ofColor::goldenRod, ofColor::white);
    
    float tx = 10 + 110;
    float ty = 320;
    for(int i = 0; i<timelines.size(); i++) {
        
        ofSetColor(255);
        timelines[i].draw(tx, ty);
        
        ofDrawBitmapStringHighlight(labels[i], 10, ty+13);
        
        if(i == 2) { // today
            ofNoFill();
            ofSetLineWidth(1.0);
            ofSetColor(255);
            ofRect(tx, ty, timelines[i].getWidth(), timelines[i].getHeight());
            
            // Draw a current time mark
            float pixels_per_min = (timelines[i].getWidth() / 24) / 60.0;
            float nx = tx + pixels_per_min * (now.hour() * 60 + now.minute());
            ofSetColor(255, 0, 0);
            ofSetLineWidth(2.0);
            ofLine(nx, ty, nx, ty+timelines[i].getHeight());
        }
        
        ty += timelines[i].getHeight() + 25;
    }
    
}