2024.8.23
Loading...
Searching...
No Matches
class.splash.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class Splash
12 *
13 * This class represents a splash screen with a progress bar for the Bearsampp application.
14 * It provides methods to initialize the splash screen, set loading text, and increment the progress bar.
15 */
16class Splash
17{
18 /* Set progress bar "loading" modal size. */
19 const WINDOW_WIDTH = 460;
20 const WINDOW_HEIGHT = 90;
21
22 private $wbWindow;
23 private $wbImage;
26
27 private $currentImg;
28
29 /**
30 * Splash constructor.
31 *
32 * Initializes the Splash class and sets the current image to null.
33 */
34 public function __construct()
35 {
36 Util::logInitClass($this);
37 $this->currentImg = null;
38 }
39
40 /**
41 * Initializes the splash screen.
42 *
43 * @param string $title The title of the splash screen window.
44 * @param int $gauge The maximum value for the progress bar.
45 * @param string $text The initial loading text to display.
46 */
47 public function init($title, $gauge, $text)
48 {
49 global $bearsamppCore, $bearsamppWinbinder;
50
51 $bearsamppWinbinder->reset();
52
53 $screenArea = explode(' ', $bearsamppWinbinder->getSystemInfo(WinBinder::SYSINFO_WORKAREA));
54 $screenWidth = intval($screenArea[2]);
55 $screenHeight = intval($screenArea[3]);
56 $xPos = $screenWidth - self::WINDOW_WIDTH;
57 $yPos = $screenHeight - self::WINDOW_HEIGHT - 5;
58
59 $this->wbWindow = $bearsamppWinbinder->createWindow(null, ToolDialog, $title, $xPos, $yPos, self::WINDOW_WIDTH, self::WINDOW_HEIGHT, WBC_TOP | WBC_READONLY, null);
60 $this->wbImage = $bearsamppWinbinder->drawImage($this->wbWindow, $bearsamppCore->getResourcesPath() . '/homepage/img/bearsampp.bmp');
61 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, $gauge + 1, 42, 24, 390, 15);
62
63 $this->setTextLoading($text);
64 $this->incrProgressBar();
65 }
66
67 /**
68 * Sets the loading text on the splash screen.
69 *
70 * @param string $caption The loading text to display.
71 */
72 public function setTextLoading($caption)
73 {
74 global $bearsamppWinbinder;
75
76 $bearsamppWinbinder->drawRect($this->wbWindow, 42, 0, self::WINDOW_WIDTH - 42, self::WINDOW_HEIGHT);
77 $this->wbTextLoading = $bearsamppWinbinder->drawText($this->wbWindow, $caption, 42, 0, self::WINDOW_WIDTH - 44, 25);
78 }
79
80 /**
81 * Increments the progress bar by a specified number of steps.
82 *
83 * @param int $nb The number of steps to increment the progress bar by. Default is 1.
84 */
85 public function incrProgressBar($nb = 1)
86 {
87 global $bearsamppCore, $bearsamppWinbinder;
88
89 for ($i = 0; $i < $nb; $i++) {
90 $bearsamppWinbinder->drawImage($this->wbWindow, $bearsamppCore->getResourcesPath() . '/homepage/img/bearsampp.bmp', 4, 4, 32, 32);
91 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
92 }
93
94 $bearsamppWinbinder->wait();
95 $bearsamppWinbinder->wait($this->wbWindow);
96 }
97
98 /**
99 * Retrieves the window object of the splash screen.
100 *
101 * @return mixed The window object of the splash screen.
102 */
103 public function getWbWindow()
104 {
105 return $this->wbWindow;
106 }
107}
global $bearsamppCore
incrProgressBar($nb=1)
const WINDOW_WIDTH
setTextLoading($caption)
init($title, $gauge, $text)
const WINDOW_HEIGHT
static logInitClass($classInstance)
const SYSINFO_WORKAREA