Render status bar
This commit is contained in:
		
							parent
							
								
									41e2b7286d
								
							
						
					
					
						commit
						a239c94598
					
				
							
								
								
									
										33
									
								
								src/bar.cpp
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/bar.cpp
									
									
									
									
									
								
							| @ -43,6 +43,8 @@ Bar::Bar(const wl_output *output) | |||||||
|     for (auto i=1; i<=4; i++) { |     for (auto i=1; i<=4; i++) { | ||||||
|         _tags.push_back({ QString::number(i), i%2 == 0 }); |         _tags.push_back({ QString::number(i), i%2 == 0 }); | ||||||
|     } |     } | ||||||
|  |     _windowTitle = "Window title"; | ||||||
|  |     _status = "Status"; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Bar::~Bar() | Bar::~Bar() | ||||||
| @ -69,11 +71,15 @@ void Bar::render() | |||||||
|     }; |     }; | ||||||
|     auto painter = QPainter {&img}; |     auto painter = QPainter {&img}; | ||||||
|     _painter = &painter; |     _painter = &painter; | ||||||
|  |     _x = 0; | ||||||
|     painter.setFont(_font); |     painter.setFont(_font); | ||||||
| 
 | 
 | ||||||
|     setColorScheme(colorActive); |     setColorScheme(colorActive); | ||||||
|     painter.fillRect(0, 0, img.width(), img.height(), painter.brush()); |     painter.fillRect(0, 0, img.width(), img.height(), painter.brush()); | ||||||
|     renderTags(painter); |     renderTags(); | ||||||
|  |     setColorScheme(colorActive); | ||||||
|  |     renderText(_windowTitle); | ||||||
|  |     renderStatus(); | ||||||
|      |      | ||||||
|     _painter = nullptr; |     _painter = nullptr; | ||||||
|     wl_surface_attach(_surface, _bufs->buffer(), 0, 0); |     wl_surface_attach(_surface, _bufs->buffer(), 0, 0); | ||||||
| @ -87,18 +93,31 @@ void Bar::setColorScheme(const ColorScheme &scheme) | |||||||
|     _painter->setPen(QPen {QBrush {scheme.fg}, 1}); |     _painter->setPen(QPen {QBrush {scheme.fg}, 1}); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Bar::renderTags(QPainter &painter) | void Bar::renderTags() | ||||||
| { | { | ||||||
|     auto x = 0; |  | ||||||
|     for (const auto &tag : _tags) { |     for (const auto &tag : _tags) { | ||||||
|         auto size = textWidth(tag.name) + paddingX*2; |  | ||||||
|         setColorScheme(tag.active ? colorActive : colorInactive); |         setColorScheme(tag.active ? colorActive : colorInactive); | ||||||
|         painter.fillRect(x, 0, size, _bufs->height, _painter->brush()); |         renderText(tag.name); | ||||||
|         painter.drawText(paddingX+x, _textY, tag.name); |  | ||||||
|         x += size; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Bar::renderText(const QString &text) | ||||||
|  | { | ||||||
|  |     auto size = textWidth(text) + paddingX*2; | ||||||
|  |     _painter->fillRect(_x, 0, size, _bufs->height, _painter->brush()); | ||||||
|  |     _painter->drawText(paddingX+_x, _textY, text); | ||||||
|  |     _x += size; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Bar::renderStatus() | ||||||
|  | { | ||||||
|  |     auto size = textWidth(_status) + paddingX*2; | ||||||
|  |     _x = _bufs->width - size; | ||||||
|  |     _painter->fillRect(_x, 0, size, _bufs->height, _painter->brush()); | ||||||
|  |     _painter->drawText(paddingX+_x, _textY, _status); | ||||||
|  |     _x = _bufs->width; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int Bar::textWidth(const QString &text) | int Bar::textWidth(const QString &text) | ||||||
| { | { | ||||||
|     return _fontMetrics.size(Qt::TextSingleLine, text).width(); |     return _fontMetrics.size(Qt::TextSingleLine, text).width(); | ||||||
|  | |||||||
| @ -26,12 +26,17 @@ class Bar { | |||||||
|     QFont _font; |     QFont _font; | ||||||
|     QFontMetrics _fontMetrics; |     QFontMetrics _fontMetrics; | ||||||
|     std::optional<ShmBuffer> _bufs; |     std::optional<ShmBuffer> _bufs; | ||||||
|  |     int _textY, _x; | ||||||
|  | 
 | ||||||
|     std::vector<Tag> _tags; |     std::vector<Tag> _tags; | ||||||
|     int _textY; |     QString _windowTitle; | ||||||
|  |     QString _status; | ||||||
| 
 | 
 | ||||||
|     void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height); |     void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height); | ||||||
|     void render(); |     void render(); | ||||||
|     void renderTags(QPainter &painter); |     void renderTags(); | ||||||
|  |     void renderStatus(); | ||||||
|  |     void renderText(const QString &text); | ||||||
|     int textWidth(const QString &text); |     int textWidth(const QString &text); | ||||||
|     void setColorScheme(const ColorScheme &scheme); |     void setColorScheme(const ColorScheme &scheme); | ||||||
| public: | public: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user