mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-02 07:30:50 +00:00
better
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@164 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
19
include/Mw/Constants.h
Normal file
19
include/Mw/Constants.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* $Id$ */
|
||||
/*!
|
||||
* %file Mw/Constants.h
|
||||
* %brief Constants
|
||||
*/
|
||||
#ifndef __MW_CONSTANTS_H__
|
||||
#define __MW_CONSTANTS_H__
|
||||
|
||||
/*!
|
||||
* %brief Direction enumeration
|
||||
*/
|
||||
enum MwDIRECTION {
|
||||
MwNORTH = 0,
|
||||
MwSOUTH,
|
||||
MwEAST,
|
||||
MwWEST
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -57,7 +57,6 @@ MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int inve
|
||||
* %param rect Rectangle area
|
||||
* %param color Color
|
||||
* %param invert Invert the 3D border color or not
|
||||
* %warning `rect` gets changed to the area of rectangle inside
|
||||
*/
|
||||
MWDECL void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <setjmp.h>
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/ipc.h>
|
||||
|
||||
227
src/draw.c
227
src/draw.c
@@ -6,6 +6,8 @@
|
||||
#define FontWidth 7
|
||||
#define FontHeight 14
|
||||
#define FontScale 1
|
||||
#define ColorDiff 128
|
||||
#define BorderWidth 2
|
||||
|
||||
static int hex(const char* txt, int len) {
|
||||
int i;
|
||||
@@ -82,16 +84,13 @@ void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) {
|
||||
}
|
||||
|
||||
void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
|
||||
const int border = 2;
|
||||
|
||||
MwDrawFrameEx(handle, rect, color, invert, border);
|
||||
MwDrawFrameEx(handle, rect, color, invert, BorderWidth);
|
||||
}
|
||||
|
||||
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) {
|
||||
MwPoint p[6];
|
||||
const int diff = 128;
|
||||
MwLLColor darker = MwLLAllocColor(handle->lowlevel, color->red - diff, color->green - diff, color->blue - diff);
|
||||
MwLLColor lighter = MwLLAllocColor(handle->lowlevel, color->red + diff, color->green + diff, color->blue + diff);
|
||||
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
|
||||
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
|
||||
|
||||
p[0].x = rect->x;
|
||||
p[0].y = rect->y;
|
||||
@@ -142,6 +141,219 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i
|
||||
rect->height -= border * 2;
|
||||
}
|
||||
|
||||
void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) {
|
||||
MwPoint p1[4], p2[4], p3[4], p4[3];
|
||||
const int border = BorderWidth * 2;
|
||||
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
|
||||
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
|
||||
|
||||
double deg = 30 + ((direction == MwEAST || direction == MwWEST) ? 30 : 0);
|
||||
double c = cos(deg / 180 * M_PI);
|
||||
double s = sin(deg / 180 * M_PI);
|
||||
|
||||
if(direction == MwNORTH) {
|
||||
p1[0].x = rect->x + rect->width / 2;
|
||||
p1[0].y = rect->y;
|
||||
|
||||
p1[1].x = rect->x;
|
||||
p1[1].y = rect->y + rect->height;
|
||||
|
||||
p1[2].x = rect->x + c * border;
|
||||
p1[2].y = rect->y + rect->height - s * border;
|
||||
|
||||
p1[3].x = rect->x + rect->width / 2;
|
||||
p1[3].y = rect->y + border;
|
||||
|
||||
p2[0].x = rect->x + rect->width / 2;
|
||||
p2[0].y = rect->y;
|
||||
|
||||
p2[1].x = rect->x + rect->width;
|
||||
p2[1].y = rect->y + rect->height;
|
||||
|
||||
p2[2].x = rect->x + rect->width - c * border;
|
||||
p2[2].y = rect->y + rect->height - s * border;
|
||||
|
||||
p2[3].x = rect->x + rect->width / 2;
|
||||
p2[3].y = rect->y + border;
|
||||
|
||||
p3[0].x = rect->x + c * border;
|
||||
p3[0].y = rect->y + rect->height - s * border;
|
||||
|
||||
p3[1].x = rect->x;
|
||||
p3[1].y = rect->y + rect->height;
|
||||
|
||||
p3[2].x = rect->x + rect->width;
|
||||
p3[2].y = rect->y + rect->height;
|
||||
|
||||
p3[3].x = rect->x + rect->width - c * border;
|
||||
p3[3].y = rect->y + rect->height - s * border;
|
||||
|
||||
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker);
|
||||
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
|
||||
|
||||
p4[0].x = rect->x + c * border;
|
||||
p4[0].y = rect->y + rect->height - s * border;
|
||||
|
||||
p4[1].x = rect->x + rect->width - c * border;
|
||||
p4[1].y = rect->y + rect->height - s * border;
|
||||
|
||||
p4[2].x = rect->x + rect->width / 2;
|
||||
p4[2].y = rect->y + border;
|
||||
} else if(direction == MwSOUTH) {
|
||||
p1[0].x = rect->x;
|
||||
p1[0].y = rect->y;
|
||||
|
||||
p1[1].x = rect->x + c * border;
|
||||
p1[1].y = rect->y + s * border;
|
||||
|
||||
p1[2].x = rect->x + rect->width - c * border;
|
||||
p1[2].y = rect->y + s * border;
|
||||
|
||||
p1[3].x = rect->x + rect->width;
|
||||
p1[3].y = rect->y;
|
||||
|
||||
p2[0].x = rect->x;
|
||||
p2[0].y = rect->y;
|
||||
|
||||
p2[1].x = rect->x + c * border;
|
||||
p2[1].y = rect->y + s * border;
|
||||
|
||||
p2[2].x = rect->x + rect->width / 2;
|
||||
p2[2].y = rect->y + rect->height - border;
|
||||
|
||||
p2[3].x = rect->x + rect->width / 2;
|
||||
p2[3].y = rect->y + rect->height;
|
||||
|
||||
p3[0].x = rect->x + rect->width;
|
||||
p3[0].y = rect->y;
|
||||
|
||||
p3[1].x = rect->x + rect->width / 2;
|
||||
p3[1].y = rect->y + rect->height;
|
||||
|
||||
p3[2].x = rect->x + rect->width / 2;
|
||||
p3[2].y = rect->y + rect->height - border;
|
||||
|
||||
p3[3].x = rect->x + rect->width - c * border;
|
||||
p3[3].y = rect->y + s * border;
|
||||
|
||||
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
|
||||
|
||||
p4[0].x = rect->x + c * border;
|
||||
p4[0].y = rect->y + s * border;
|
||||
|
||||
p4[1].x = rect->x + rect->width - c * border;
|
||||
p4[1].y = rect->y + s * border;
|
||||
|
||||
p4[2].x = rect->x + rect->width / 2;
|
||||
p4[2].y = rect->y + rect->height - border;
|
||||
} else if(direction == MwEAST) {
|
||||
p1[0].x = rect->x;
|
||||
p1[0].y = rect->y;
|
||||
|
||||
p1[1].x = rect->x + c * border;
|
||||
p1[1].y = rect->y + s * border;
|
||||
|
||||
p1[2].x = rect->x + c * border;
|
||||
p1[2].y = rect->y + rect->height - s * border;
|
||||
|
||||
p1[3].x = rect->x;
|
||||
p1[3].y = rect->y + rect->height;
|
||||
|
||||
p2[0].x = rect->x;
|
||||
p2[0].y = rect->y;
|
||||
|
||||
p2[1].x = rect->x + rect->width;
|
||||
p2[1].y = rect->y + rect->height / 2;
|
||||
|
||||
p2[2].x = rect->x + rect->width - border;
|
||||
p2[2].y = rect->y + rect->height / 2;
|
||||
|
||||
p2[3].x = rect->x + c * border;
|
||||
p2[3].y = rect->y + s * border;
|
||||
|
||||
p3[0].x = rect->x + c * border;
|
||||
p3[0].y = rect->y + rect->height - s * border;
|
||||
|
||||
p3[1].x = rect->x;
|
||||
p3[1].y = rect->y + rect->height;
|
||||
|
||||
p3[2].x = rect->x + rect->width;
|
||||
p3[2].y = rect->y + rect->height / 2;
|
||||
|
||||
p3[3].x = rect->x + rect->width - border;
|
||||
p3[3].y = rect->y + rect->height / 2;
|
||||
|
||||
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p2, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
|
||||
|
||||
p4[0].x = rect->x + rect->width - border;
|
||||
p4[0].y = rect->y + rect->height / 2;
|
||||
|
||||
p4[1].x = rect->x + c * border;
|
||||
p4[1].y = rect->y + rect->height - s * border;
|
||||
|
||||
p4[2].x = rect->x + c * border;
|
||||
p4[2].y = rect->y + s * border;
|
||||
} else if(direction == MwWEST) {
|
||||
p1[0].x = rect->x;
|
||||
p1[0].y = rect->y + rect->height / 2;
|
||||
|
||||
p1[1].x = rect->x + border;
|
||||
p1[1].y = rect->y + rect->height / 2;
|
||||
|
||||
p1[2].x = rect->x + rect->width - c * border;
|
||||
p1[2].y = rect->y + s * border;
|
||||
|
||||
p1[3].x = rect->x + rect->width;
|
||||
p1[3].y = rect->y;
|
||||
|
||||
p2[0].x = rect->x;
|
||||
p2[0].y = rect->y + rect->height / 2;
|
||||
|
||||
p2[1].x = rect->x + border;
|
||||
p2[1].y = rect->y + rect->height / 2;
|
||||
|
||||
p2[2].x = rect->x + rect->width - c * border;
|
||||
p2[2].y = rect->y + rect->height - s * border;
|
||||
|
||||
p2[3].x = rect->x + rect->width;
|
||||
p2[3].y = rect->y + rect->height;
|
||||
|
||||
p3[0].x = rect->x + rect->width;
|
||||
p3[0].y = rect->y;
|
||||
|
||||
p3[1].x = rect->x + rect->width - c * border;
|
||||
p3[1].y = rect->y + s * border;
|
||||
|
||||
p3[2].x = rect->x + rect->width - c * border;
|
||||
p3[2].y = rect->y + rect->height - s * border;
|
||||
|
||||
p3[3].x = rect->x + rect->width;
|
||||
p3[3].y = rect->y + rect->height;
|
||||
|
||||
MwLLPolygon(handle->lowlevel, p1, 4, invert ? darker : lighter);
|
||||
MwLLPolygon(handle->lowlevel, p2, 4, invert ? lighter : darker);
|
||||
MwLLPolygon(handle->lowlevel, p3, 4, invert ? lighter : darker);
|
||||
|
||||
p4[0].x = rect->x + border;
|
||||
p4[0].y = rect->y + rect->height / 2;
|
||||
|
||||
p4[1].x = rect->x + rect->width - c * border;
|
||||
p4[1].y = rect->y + rect->height - s * border;
|
||||
|
||||
p4[2].x = rect->x + rect->width - c * border;
|
||||
p4[2].y = rect->y + s * border;
|
||||
}
|
||||
MwLLPolygon(handle->lowlevel, p4, 3, color);
|
||||
|
||||
MwLLFreeColor(lighter);
|
||||
MwLLFreeColor(darker);
|
||||
}
|
||||
|
||||
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color) {
|
||||
int i, x, y, sx, sy;
|
||||
MwRect r;
|
||||
@@ -192,6 +404,3 @@ MwLLPixmap MwLoadImage(MwWidget handle, const char* path) {
|
||||
|
||||
return px;
|
||||
}
|
||||
|
||||
void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) {
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ static void draw(MwWidget handle) {
|
||||
|
||||
rt = r;
|
||||
rt.height = rt.width;
|
||||
MwDrawTriangle(handle, &r, base, 0, MwNORTH);
|
||||
MwDrawTriangle(handle, &rt, base, 0, MwNORTH);
|
||||
rt.y = r.y + r.height - rt.height;
|
||||
MwDrawTriangle(handle, &rt, base, 0, MwSOUTH);
|
||||
|
||||
MwLLFreeColor(dark);
|
||||
MwLLFreeColor(base);
|
||||
|
||||
@@ -67,20 +67,13 @@ static void draw(MwWidget handle) {
|
||||
MwDrawText(handle, &p, menu->sub[i]->name, 1, text);
|
||||
|
||||
if(arrlen(menu->sub[i]->sub) > 0) {
|
||||
MwPoint pl[3];
|
||||
MwRect tr;
|
||||
|
||||
p.x = 5 + tw + 10;
|
||||
tr.x = p.x + tw / 2 + 5;
|
||||
tr.y = p.y - th / 2 + 2;
|
||||
tr.width = tr.height = 11;
|
||||
|
||||
pl[0].x = p.x - 5;
|
||||
pl[0].y = p.y - th / 2;
|
||||
|
||||
pl[1].x = p.x - 5;
|
||||
pl[1].y = p.y + th / 2;
|
||||
|
||||
pl[2].x = p.x + 5;
|
||||
pl[2].y = p.y;
|
||||
|
||||
MwLLPolygon(handle->lowlevel, pl, 3, text);
|
||||
MwDrawTriangle(handle, &tr, base, menu->sub[i]->wsub != NULL ? 1 : 0, MwEAST);
|
||||
}
|
||||
|
||||
p.y += th / 2 + 3;
|
||||
|
||||
Reference in New Issue
Block a user