startbutton

This commit is contained in:
Nishi 2025-12-18 11:43:16 +09:00
commit ac809775c8
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 79 additions and 0 deletions

View file

@ -13,6 +13,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
endif()
add_subdirectory(separator)
add_subdirectory(startbutton)
include(GNUInstallDirs)
configure_file(mpanelrc.in mpanelrc)

View file

@ -1,4 +1,7 @@
Modules: (
{
Type = "StartButton";
},
{
Type = "Separator";
}

View file

@ -0,0 +1,6 @@
include(MDEBase)
include(MDEPkgConfig)
mde_setup_library(StartButtonModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
mde_pkg_config_add(StartButtonModule libconfig)

View file

@ -0,0 +1,67 @@
#include "config.h"
#include <stb_image.h>
#include <Mw/Milsko.h>
#include <libconfig.h>
#define TriW 5
void module(MwWidget box, config_setting_t* setting) {
MwLLPixmap closed = NULL;
MwLLPixmap opened = NULL;
int w, h;
unsigned int ch;
unsigned char* rgb;
if((rgb = stbi_load(ICON64DIR "/logo.png", &w, &h, &ch, 4)) != NULL) {
int bw = MwGetInteger(box, MwNheight) - MwDefaultBorderWidth(box) * 2;
unsigned char* data = malloc(bw * bw * 4);
unsigned char* save = malloc(bw * bw * 4);
int y, x;
int max = (TriW - 1) / 2;
memset(data, 0, bw * bw * 4);
for(y = 0; y < h; y++) {
int fy = y * bw / h;
for(x = 0; x < w; x++) {
int fx = x * bw / w;
memcpy(&data[(fy * bw + fx) * 4], &rgb[(y * w + x) * 4], 4);
}
}
memcpy(save, data, bw * bw * 4);
for(y = 0; y < max + 1; y++) {
int tw = y * 2 + 1;
int ix = w - TriW + (max - y);
for(x = 0; x < tw; x++) {
data[4 * (y * bw + x + ix) + 3] = 255;
}
}
closed = MwLoadRaw(box, data, bw, bw);
memcpy(data, save, bw * bw * 4);
max = (TriW - 1) / 2;
for(y = 0; y < max + 1; y++) {
int tw = (max - y) * 2 + 1;
int ix = w - TriW + y;
for(x = 0; x < tw; x++) {
data[4 * (y * bw + x + ix) + 3] = 255;
}
}
opened = MwLoadRaw(box, data, bw, bw);
free(save);
free(data);
free(rgb);
}
MwVaCreateWidget(MwButtonClass, "startbutton", box, 0, 0, 0, 0,
MwNfixedSize, MwGetInteger(box, MwNheight),
MwNflat, 1,
MwNpixmap, closed,
NULL);
}

View file

@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>