Add mclock
Co-Authored-By: comdlg32 <80153347+comdlg32@users.noreply.github.com>
This commit is contained in:
parent
c92a5e0db4
commit
44f6e9e1ca
5 changed files with 201 additions and 1 deletions
|
|
@ -6,3 +6,4 @@ project(
|
|||
add_subdirectory(mbiff)
|
||||
add_subdirectory(mauplay)
|
||||
add_subdirectory(mcompass)
|
||||
add_subdirectory(mclock)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ static int db_bind(sqlite3_stmt* stmt, const char* path) {
|
|||
const char* s_genre;
|
||||
int s_length;
|
||||
int s_track = 0;
|
||||
char* str;
|
||||
struct stat s;
|
||||
if(sound == NULL) return 1;
|
||||
|
||||
|
|
@ -80,7 +81,11 @@ static int db_bind(sqlite3_stmt* stmt, const char* path) {
|
|||
s_track = sound->context->track;
|
||||
s_length = sound->context->frames / sound->context->sample_rate;
|
||||
|
||||
if(s_title == NULL) s_title = path;
|
||||
#ifdef _WIN32
|
||||
if(s_title == NULL) s_title = (str = strrchr(path, '\\')) != NULL ? (str + 1) : path;
|
||||
#else
|
||||
if(s_title == NULL) s_title = (str = strrchr(path, '/')) != NULL ? (str + 1) : path;
|
||||
#endif
|
||||
if(s_artist == NULL) s_artist = "<unknown>";
|
||||
if(s_album == NULL) s_album = "<unknown>";
|
||||
if(s_genre == NULL) s_genre = "<unknown>";
|
||||
|
|
|
|||
6
mclock/CMakeLists.txt
Normal file
6
mclock/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
include(MDEBase)
|
||||
include(MDEOpenGL)
|
||||
setup_project(mclock ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
opengl_add(mclock)
|
||||
math_add(mclock)
|
||||
167
mclock/clock.c
Normal file
167
mclock/clock.c
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
#include "mclock.h"
|
||||
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
MwWidget window, opengl;
|
||||
int ww, wh;
|
||||
unsigned long last_tick;
|
||||
MwLLPixmap pxclock;
|
||||
|
||||
static void resize(MwWidget handle, void* user, void* client) {
|
||||
ww = MwGetInteger(window, MwNwidth);
|
||||
wh = MwGetInteger(window, MwNheight);
|
||||
|
||||
MwVaApply(opengl,
|
||||
MwNwidth, ww,
|
||||
MwNheight, wh,
|
||||
NULL);
|
||||
|
||||
glViewport(0, 0, ww, wh);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
static void drawHand(float rad, float wid, float leng, int shadow) {
|
||||
int i;
|
||||
|
||||
double n = M_PI / 2;
|
||||
if(shadow) {
|
||||
glPushMatrix();
|
||||
glTranslatef(wid / 1, -(wid / 1), 0);
|
||||
glColor3f(0.45, 0.45, 0.45);
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex2f(cos(rad) * leng, sin(rad) * leng);
|
||||
glVertex2f(cos(rad - n) * wid, sin(rad - n) * wid);
|
||||
glVertex2f(-cos(rad) * leng * .1, -sin(rad) * leng * .1);
|
||||
glVertex2f(-cos(rad - n) * wid, -sin(rad - n) * wid);
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
if(i == 0) {
|
||||
glColor3f(0.65, 0.65, 0.65);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
} else {
|
||||
glColor3f(0.2, 0.2, 0.2);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
}
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex2f(cos(rad) * leng, sin(rad) * leng);
|
||||
glVertex2f(cos(rad - n) * wid, sin(rad - n) * wid);
|
||||
glVertex2f(-cos(rad) * leng * .1, -sin(rad) * leng * .1);
|
||||
glVertex2f(-cos(rad - n) * wid, -sin(rad - n) * wid);
|
||||
glEnd();
|
||||
};
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glColor3f(0.65, 0.65, 0.65);
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle, void* user, void* client) {
|
||||
int i;
|
||||
time_t t;
|
||||
struct tm* tm_info;
|
||||
|
||||
double srad;
|
||||
double mrad;
|
||||
double hrad;
|
||||
double rad;
|
||||
|
||||
double len;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glLineWidth(1);
|
||||
|
||||
t = time(NULL);
|
||||
tm_info = localtime(&t);
|
||||
|
||||
srad = M_PI / 2 - (tm_info->tm_sec / 60.0) * 2 * M_PI;
|
||||
mrad = M_PI / 2 - ((tm_info->tm_min + tm_info->tm_sec / 60.0) / 60.0) * 2 * M_PI;
|
||||
hrad = M_PI / 2 - (((tm_info->tm_hour % 12) + tm_info->tm_min / 60.0 + tm_info->tm_sec / 3600.0) / 12.0) * 2 * M_PI;
|
||||
|
||||
drawHand(srad, 0.01, 0.98, 1);
|
||||
drawHand(mrad, 0.05, 0.98, 1);
|
||||
drawHand(hrad, 0.05, 0.7, 1);
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
for(i = 0; i < 360; i += 6) {
|
||||
rad = i / 180.0 * M_PI;
|
||||
if(!(i % 30)) {
|
||||
glLineWidth(3);
|
||||
len = 0.8;
|
||||
} else {
|
||||
glLineWidth(1);
|
||||
len = 0.85;
|
||||
}
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(cos(rad) * len, sin(rad) * len);
|
||||
glVertex2f(cos(rad) * 0.9, sin(rad) * 0.9);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glLineWidth(1);
|
||||
|
||||
drawHand(hrad, 0.05, 0.7, 0);
|
||||
drawHand(mrad, 0.05, 0.98, 0);
|
||||
drawHand(srad, 0.02, 0.98, 0);
|
||||
|
||||
MwOpenGLSwapBuffer(opengl);
|
||||
}
|
||||
|
||||
static void tick(MwWidget handle, void* user, void* client) {
|
||||
unsigned long tick = MwTimeGetTick();
|
||||
if((tick - last_tick) >= 1000) {
|
||||
draw(opengl, NULL, NULL);
|
||||
last_tick = tick;
|
||||
}
|
||||
}
|
||||
|
||||
static void mouseup(MwWidget handle, void* user, void* client) {
|
||||
MDEAboutDialog(window, "mclock", VERSION, pxclock);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLLColor col;
|
||||
int r, g, b;
|
||||
|
||||
MwLibraryInit();
|
||||
|
||||
last_tick = MwTimeGetTick();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 150, 150,
|
||||
MwNtitle, "mclock",
|
||||
NULL);
|
||||
|
||||
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 0, 0, 150, 150);
|
||||
pxclock = MwLoadImage(window, ICON128DIR "/clock.png");
|
||||
|
||||
MwOpenGLMakeCurrent(opengl);
|
||||
|
||||
col = MwParseColor(window, MwGetText(window, MwNbackground));
|
||||
MwGetColor(col, &r, &g, &b);
|
||||
MwLLFreeColor(col);
|
||||
|
||||
glClearColor(r / 255.0, g / 255.0, b / 255.0, 1);
|
||||
|
||||
resize(window, NULL, NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(opengl, MwNdrawHandler, draw, NULL);
|
||||
MwAddUserHandler(opengl, MwNmouseUpHandler, mouseup, NULL);
|
||||
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
|
||||
|
||||
draw(opengl, NULL, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
21
mclock/mclock.h
Normal file
21
mclock/mclock.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef __MCLOCK_H__
|
||||
#define __MCLOCK_H__
|
||||
|
||||
#define VERSION "0.0.0"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* Milsko */
|
||||
#include <MDE/Foundation.h>
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
/* External */
|
||||
|
||||
/* Standard */
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue