Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
ASTRO

Change bar height

Question

Hello everyone. So I am running Big Reactors Grid Control program. And it has libGUI library, which draws bars. But they are really tiny and I want to make them bigger. Here is bars code:

I have no clue, how to change height. Can anybody help? :D

local oop = require("oop");
local frame_base = require("libGUI/frame");
local colors = require("libGUI/colors");

local bar_base = {
	mPercentage = 0,
	mBarPalette = nil,
	mBarBackgroundColor = colors.gray,
	mBorderColor = colors.lightGray,
	mBorderWidth = 1,
	mHasChanged = true
};
oop.inherit(bar_base, frame_base);

function bar_base:construct()
	frame_base.construct(self);
	self.mBarPalette = {{1, colors.green}};
end

function bar_base:setBarPalette(palette)
	self.mHasChanged = true;
	self.mBarPalette = palette;
end

function bar_base:setPercentage(percentage, redraw)
	self.mHasChanged = math.floor((math.max(self.mHeight, self.mWidth) - 2 * self.mBorderWidth) * math.min(1, math.max(0, self:getTranslatedPercentage(self.mPercentage))) + 0.5) ~= math.floor((math.max(self.mHeight, self.mWidth) - 2 * self.mBorderWidth) * math.min(1, math.max(0, self:getTranslatedPercentage(percentage))) + 0.5);
	self.mPercentage = percentage;
	if redraw == nil or redraw then
		self:drawBar();
	end
end

function bar_base:setBorderWidth(width)
	self.mHasChanged = self.mBorderWidth ~= width;
	self.mBorderWidth = width;
end

function bar_base:getBarColor()
	local barColor = self.mBarPalette[#self.mBarPalette][2];

	for _, v in pairs(self.mBarPalette) do
		if v[1] >= self.mPercentage then
			barColor = v[2];
			break;
		end
	end

	return barColor or colors.green;
end

function bar_base:getTranslatedPercentage(percentage)
	return percentage or self.mPercentage;
end

function bar_base:drawBarVertical()
	local barColor = self:getBarColor();
	local width, height = self:getSize();
	local barHeight = math.floor((height - 2 * self.mBorderWidth) * math.min(1, math.max(0, self:getTranslatedPercentage())) + 0.5);

	self:setBackground(self.mBarBackgroundColor);
	self:fill(1 + self.mBorderWidth, 1 + self.mBorderWidth, width - 2 * self.mBorderWidth, height - 2 * self.mBorderWidth - barHeight, ' ');
	self:setBackground(barColor);
	self:fill(1 + self.mBorderWidth, 1 + height - barHeight - self.mBorderWidth, width - 2 * self.mBorderWidth, barHeight, ' ');
end

function bar_base:drawBarHorizontal()
	local barColor = self:getBarColor();
	local width, height = self:getSize();
	local barWidth = math.floor((width - 2 * self.mBorderWidth) * math.min(1, math.max(0, self:getTranslatedPercentage())) + 0.5);
	
	self:setBackground(self.mBarBackgroundColor);
	self:fill(1 + self.mBorderWidth + barWidth, 1 + self.mBorderWidth, width - 2 * self.mBorderWidth - barWidth, height - 2 * self.mBorderWidth, ' ');
	self:setBackground(barColor);
	self:fill(1 + self.mBorderWidth, 1 + self.mBorderWidth, barWidth, height - 2 * self.mBorderWidth, ' ');
end

function bar_base:drawBar()
	if self:getWidth() >= self:getHeight() then
		self:drawBarHorizontal();
	else
		self:drawBarVertical();
	end
end

function bar_base:onDraw(allowPartial)
	frame_base.onDraw(self, allowPartial);

	if not allowPartial or self.mHasChanged then
		local width, height = self:getSize();
		if self.mBorderWidth > 0 then
			self:setBackground(self.mBorderColor);
			self:fill(1, 1, width, height, ' ');
		end

		self:drawBar();
		self.mHasChanged = false;
	end
end

return bar_base;

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.