duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

host_interface_progress_callback.cpp (2191B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #include "host_interface_progress_callback.h"
      5 #include "common/log.h"
      6 #include "host.h"
      7 Log_SetChannel(HostInterfaceProgressCallback);
      8 
      9 HostInterfaceProgressCallback::HostInterfaceProgressCallback() : ProgressCallback()
     10 {
     11 }
     12 
     13 void HostInterfaceProgressCallback::PushState()
     14 {
     15   ProgressCallback::PushState();
     16 }
     17 
     18 void HostInterfaceProgressCallback::PopState()
     19 {
     20   ProgressCallback::PopState();
     21   Redraw(true);
     22 }
     23 
     24 void HostInterfaceProgressCallback::SetCancellable(bool cancellable)
     25 {
     26   ProgressCallback::SetCancellable(cancellable);
     27   Redraw(true);
     28 }
     29 
     30 void HostInterfaceProgressCallback::SetTitle(const std::string_view title)
     31 {
     32   // todo?
     33 }
     34 
     35 void HostInterfaceProgressCallback::SetStatusText(const std::string_view text)
     36 {
     37   ProgressCallback::SetStatusText(text);
     38   Redraw(true);
     39 }
     40 
     41 void HostInterfaceProgressCallback::SetProgressRange(u32 range)
     42 {
     43   u32 last_range = m_progress_range;
     44 
     45   ProgressCallback::SetProgressRange(range);
     46 
     47   if (m_progress_range != last_range)
     48     Redraw(false);
     49 }
     50 
     51 void HostInterfaceProgressCallback::SetProgressValue(u32 value)
     52 {
     53   u32 lastValue = m_progress_value;
     54 
     55   ProgressCallback::SetProgressValue(value);
     56 
     57   if (m_progress_value != lastValue)
     58     Redraw(false);
     59 }
     60 
     61 void HostInterfaceProgressCallback::Redraw(bool force)
     62 {
     63   if (m_last_progress_percent < 0 && m_open_time.GetTimeSeconds() < m_open_delay)
     64     return;
     65 
     66   const int percent =
     67     static_cast<int>((static_cast<float>(m_progress_value) / static_cast<float>(m_progress_range)) * 100.0f);
     68   if (percent == m_last_progress_percent && !force)
     69     return;
     70 
     71   m_last_progress_percent = percent;
     72   Host::DisplayLoadingScreen(m_status_text.c_str(), 0, static_cast<int>(m_progress_range),
     73                              static_cast<int>(m_progress_value));
     74 }
     75 
     76 void HostInterfaceProgressCallback::ModalError(const std::string_view message)
     77 {
     78   ERROR_LOG(message);
     79   Host::ReportErrorAsync("Error", message);
     80 }
     81 
     82 bool HostInterfaceProgressCallback::ModalConfirmation(const std::string_view message)
     83 {
     84   INFO_LOG(message);
     85   return Host::ConfirmMessage("Confirm", message);
     86 }