2024.8.23
Loading...
Searching...
No Matches
class.action.loading.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 ActionLoading
12 *
13 * This class handles the loading action, including the creation and management of a progress bar window.
14 */
16{
17 /** @var int The width of the progress bar window. */
18 const WINDOW_WIDTH = 360;
19
20 /** @var int The height of the progress bar window. */
21 const WINDOW_HEIGHT = 90;
22
23 /** @var int The maximum value of the progress bar. */
24 const GAUGE = 20;
25
26 /** @var mixed The window object created by WinBinder. */
27 private $wbWindow;
28
29 /** @var mixed The progress bar object created by WinBinder. */
31
32 /**
33 * ActionLoading constructor.
34 *
35 * Initializes the loading action, creates the progress bar window, and starts the main loop.
36 *
37 * @param array $args The arguments passed to the constructor.
38 */
39 public function __construct($args)
40 {
41 global $bearsamppCore, $bearsamppLang, $bearsamppWinbinder;
42
43 $bearsamppWinbinder->reset();
44 $bearsamppCore->addLoadingPid(Win32Ps::getCurrentPid());
45
46 // Screen information
47 $screenArea = explode(' ', $bearsamppWinbinder->getSystemInfo(WinBinder::SYSINFO_WORKAREA));
48 $screenWidth = intval($screenArea[2]);
49 $screenHeight = intval($screenArea[3]);
50 $xPos = $screenWidth - self::WINDOW_WIDTH;
51 $yPos = $screenHeight - self::WINDOW_HEIGHT - 5;
52
53 // Create the window and progress bar
54 $this->wbWindow = $bearsamppWinbinder->createWindow(null, ToolDialog, null, $xPos, $yPos, self::WINDOW_WIDTH, self::WINDOW_HEIGHT, WBC_TOP, null);
55 $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::LOADING), 42, 2, 295, null, WBC_LEFT);
56 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE, 42, 20, 290, 15);
57
58 // Set the handler and start the main loop
59 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processLoading', 10);
60 $bearsamppWinbinder->mainLoop();
61 }
62
63 /**
64 * Increments the progress bar by a specified number of steps.
65 *
66 * @param int $nb The number of steps to increment the progress bar by. Default is 1.
67 */
68 public function incrProgressBar($nb = 1)
69 {
70 global $bearsamppCore, $bearsamppWinbinder;
71
72 for ($i = 0; $i < $nb; $i++) {
73 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
74 $bearsamppWinbinder->drawImage($this->wbWindow, $bearsamppCore->getResourcesPath() . '/homepage/img/bearsampp.bmp', 4, 2, 32, 32);
75 }
76
77 $bearsamppWinbinder->wait();
78 $bearsamppWinbinder->wait($this->wbWindow);
79 }
80
81 /**
82 * Processes the loading action, including handling window events and updating the progress bar.
83 *
84 * @param mixed $window The window object.
85 * @param int $id The ID of the event.
86 * @param mixed $ctrl The control object.
87 * @param mixed $param1 The first parameter of the event.
88 * @param mixed $param2 The second parameter of the event.
89 */
90 public function processLoading($window, $id, $ctrl, $param1, $param2)
91 {
92 global $bearsamppRoot, $bearsamppWinbinder;
93
94 switch ($id) {
95 case IDCLOSE:
97 break;
98 }
99
100 while (true) {
101 $bearsamppRoot->removeErrorHandling();
102 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
103 usleep(100000);
104 for ($i = 0; $i < self::GAUGE; $i++) {
105 $this->incrProgressBar();
106 usleep(100000);
107 }
108 }
109 }
110}
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
processLoading($window, $id, $ctrl, $param1, $param2)
const LOADING
static getCurrentPid()
static kill($pid)
const SYSINFO_WORKAREA