<commit_before>#include "MeterWnd.h"
#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")
#include <VersionHelpers.h>
#include <sstream>

#include "Animation.h"
#include "AnimationFactory.h"

MeterWnd::MeterWnd(LPCWSTR className, LPCWSTR title, HINSTANCE hInstance) :
LayeredWnd(className, title, hInstance, NULL, WINDOW_STYLES) {

}

MeterWnd::~MeterWnd() {
    delete _hideAnimation;
    delete _composite;

    for (LayeredWnd *clone : _clones) {
        delete clone;
    }
}

void MeterWnd::Update() {
    CLOG(L"Updating meter window");
    using namespace Gdiplus;

    bool dirty = (_composite == NULL);

    for (Meter *meter : _meters) {
        if (meter->Dirty() == true) {
            dirty = true;
            break;
        }
    }

    if (dirty) {
        QCLOG(L"Contents have changed; redrawing");

        if (_composite) {
            delete _composite;
        }

        Rect bgRect(0, 0, _background->GetWidth(), _background->GetHeight());
        _composite = _background->Clone(bgRect, PixelFormat32bppARGB);
        Graphics graphics(_composite);

        for (Meter *meter : _meters) {
            CLOG(L"Drawing meter:\n%s", meter->ToString().c_str());
            meter->Draw(_composite, &graphics);
        }
    }

    Bitmap(_composite);
    UpdateClones();
}

void MeterWnd::AddMeter(Meter *meter) {
    _meters.push_back(meter);
}

void MeterWnd::MeterLevels(float value) {
    for (Meter *meter : _meters) {
        meter->Value(value);
    }
}

void MeterWnd::HideAnimation(AnimationTypes::HideAnimation anim, int speed) {
    delete _hideAnimation;
    _hideAnimation = AnimationFactory::Create(anim, speed);
}

void MeterWnd::VisibleDuration(int duration) {
    _visibleDuration = duration;
}

void MeterWnd::BackgroundImage(Gdiplus::Bitmap *background) {
    _background = background;
}

bool MeterWnd::EnableGlass(Gdiplus::Bitmap *mask) {
    bool result = LayeredWnd::EnableGlass(mask);
    ApplyClonesGlass();
    return result;
}

void MeterWnd::Show(bool animate) {
    if (_visible == false) {
        UpdateWindowPosition();
        ShowWindow(_hWnd, SW_SHOW);
        _visible = true;
    }

    ShowClones();

    if (_visibleDuration > 0) {
        SetTimer(_hWnd, TIMER_HIDE, _visibleDuration, NULL);
        KillTimer(_hWnd, TIMER_OUT);

        if (_hideAnimation) {
            _hideAnimation->Reset(this);
        }
    }
}

void MeterWnd::Hide(bool animate) {
    if (_visible == false) {
        return;
    }

    if (animate && _hideAnimation) {
        SetTimer(_hWnd, TIMER_OUT, _hideAnimation->UpdateInterval(), NULL);
    } else {
        ShowWindow(_hWnd, SW_HIDE);
        _visible = false;
        HideClones();
    }
}

void MeterWnd::AnimateOut() {
    bool animOver = _hideAnimation->Animate(this);
    if (animOver) {
        CLOG(L"Finished hide animation.");
        KillTimer(_hWnd, TIMER_OUT);
        ShowWindow(_hWnd, SW_HIDE);
        _visible = false;
        HideClones();
    }
}

byte MeterWnd::Transparency() {
    return LayeredWnd::Transparency();
}

void MeterWnd::Transparency(byte transparency) {
    LayeredWnd::Transparency(transparency);
    UpdateClonesTransparency(transparency);
}

LayeredWnd *MeterWnd::Clone() {
    int numClones = _clones.size() + 1;
    std::wstringstream cloneClass;
    cloneClass << _className << L":" << numClones;
    std::wstringstream cloneTitle;
    cloneTitle << _title << L":" << numClones;

    LayeredWnd *clone = new LayeredWnd(
        cloneClass.str().c_str(),
        cloneTitle.str().c_str(),
        _hInstance,
        _composite,
        WINDOW_STYLES);

    if (_glassMask) {
        clone->EnableGlass(_glassMask);
    }

    _clones.push_back(clone);
    CLOG(L"Created meter window clone: %s/%s",
        cloneClass.str().c_str(), cloneTitle.str().c_str());
    return clone;
}<commit_msg>Copy current window state to clones instead of using defaults<commit_after>#include "MeterWnd.h"
#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")
#include <VersionHelpers.h>
#include <sstream>

#include "Animation.h"
#include "AnimationFactory.h"

MeterWnd::MeterWnd(LPCWSTR className, LPCWSTR title, HINSTANCE hInstance) :
LayeredWnd(className, title, hInstance, NULL, WINDOW_STYLES) {

}

MeterWnd::~MeterWnd() {
    delete _hideAnimation;
    delete _composite;

    for (LayeredWnd *clone : _clones) {
        delete clone;
    }
}

void MeterWnd::Update() {
    CLOG(L"Updating meter window");
    using namespace Gdiplus;

    bool dirty = (_composite == NULL);

    for (Meter *meter : _meters) {
        if (meter->Dirty() == true) {
            dirty = true;
            break;
        }
    }

    if (dirty) {
        QCLOG(L"Contents have changed; redrawing");

        if (_composite) {
            delete _composite;
        }

        Rect bgRect(0, 0, _background->GetWidth(), _background->GetHeight());
        _composite = _background->Clone(bgRect, PixelFormat32bppARGB);
        Graphics graphics(_composite);

        for (Meter *meter : _meters) {
            CLOG(L"Drawing meter:\n%s", meter->ToString().c_str());
            meter->Draw(_composite, &graphics);
        }
    }

    Bitmap(_composite);
    UpdateClones();
}

void MeterWnd::AddMeter(Meter *meter) {
    _meters.push_back(meter);
}

void MeterWnd::MeterLevels(float value) {
    for (Meter *meter : _meters) {
        meter->Value(value);
    }
}

void MeterWnd::HideAnimation(AnimationTypes::HideAnimation anim, int speed) {
    delete _hideAnimation;
    _hideAnimation = AnimationFactory::Create(anim, speed);
}

void MeterWnd::VisibleDuration(int duration) {
    _visibleDuration = duration;
}

void MeterWnd::BackgroundImage(Gdiplus::Bitmap *background) {
    _background = background;
}

bool MeterWnd::EnableGlass(Gdiplus::Bitmap *mask) {
    bool result = LayeredWnd::EnableGlass(mask);
    ApplyClonesGlass();
    return result;
}

void MeterWnd::Show(bool animate) {
    if (_visible == false) {
        UpdateWindowPosition();
        ShowWindow(_hWnd, SW_SHOW);
        _visible = true;
    }

    ShowClones();

    if (_visibleDuration > 0) {
        SetTimer(_hWnd, TIMER_HIDE, _visibleDuration, NULL);
        KillTimer(_hWnd, TIMER_OUT);

        if (_hideAnimation) {
            _hideAnimation->Reset(this);
        }
    }
}

void MeterWnd::Hide(bool animate) {
    if (_visible == false) {
        return;
    }

    if (animate && _hideAnimation) {
        SetTimer(_hWnd, TIMER_OUT, _hideAnimation->UpdateInterval(), NULL);
    } else {
        ShowWindow(_hWnd, SW_HIDE);
        _visible = false;
        HideClones();
    }
}

void MeterWnd::AnimateOut() {
    bool animOver = _hideAnimation->Animate(this);
    if (animOver) {
        CLOG(L"Finished hide animation.");
        KillTimer(_hWnd, TIMER_OUT);
        ShowWindow(_hWnd, SW_HIDE);
        _visible = false;
        HideClones();
    }
}

byte MeterWnd::Transparency() {
    return LayeredWnd::Transparency();
}

void MeterWnd::Transparency(byte transparency) {
    LayeredWnd::Transparency(transparency);
    UpdateClonesTransparency(transparency);
}

LayeredWnd *MeterWnd::Clone() {
    int numClones = _clones.size() + 1;
    std::wstringstream cloneClass;
    cloneClass << _className << L":" << numClones;
    std::wstringstream cloneTitle;
    cloneTitle << _title << L":" << numClones;

    LayeredWnd *clone = new LayeredWnd(
        cloneClass.str().c_str(),
        cloneTitle.str().c_str(),
        _hInstance,
        _composite,
        GetWindowLong(_hWnd, GWL_EXSTYLE));

    if (_glassMask) {
        clone->EnableGlass(_glassMask);
    }

    _clones.push_back(clone);
    CLOG(L"Created meter window clone: %s/%s",
        cloneClass.str().c_str(), cloneTitle.str().c_str());
    return clone;
}
{'fraction_non_alphanumeric': 0.1305979808439037, 'fraction_numerical': 0.001553196997152472, 'mean_word_length': 3.0223841749089018, 'pattern_counts': {'":': 4, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6243017', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2574, 'n_words': 492}