initial commit

This commit is contained in:
2025-10-09 14:37:45 +03:00
commit 7f98da51da
15 changed files with 309 additions and 0 deletions

51
source/Hands/IHands.mc Normal file
View File

@ -0,0 +1,51 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class IHands extends Drawable {
private var mHoursLength = 1.0;
private var mMinutesLength = 1.0;
private var mSecondsLength = 1.0;
public enum HandType {
HOURS,
MINUTES,
SECONDS,
}
function initialize(options) {
WatchUi.Drawable.initialize(options);
}
function draw(dc as Dc) as Void {
var now = System.getClockTime();
var mid = getCenter(dc);
var length = min(mid[0], mid[1]);
System.println(mid);
System.println(length);
var hourAngle = (now.hour % 12 + now.min / 60.0) * 30.0;
drawHand(dc, mid[0], mid[1], hourAngle, length * mHoursLength, HOURS);
var minutesAngle = now.min * 6.0;
drawHand(dc, mid[0], mid[1], minutesAngle, length * mMinutesLength, MINUTES);
var secondsAngle = now.sec * 6.0;
drawHand(dc, mid[0], mid[1], secondsAngle, length * mSecondsLength, SECONDS);
}
function drawHand(
dc as Graphics.Dc,
x as Float,
y as Float,
angle as Float,
length as Float,
handType as HandType) {}
function getCenter(dc as Dc) as [Float, Float] {
return [dc.getWidth() / 2.0, dc.getHeight() / 2.0];
}
}

View File

@ -0,0 +1,22 @@
import Toybox.Graphics;
import Toybox.Lang;
class SimpleHands extends IHands {
function initialize(options) {
IHands.initialize(options);
}
function drawHand(
dc as Dc,
x as Float,
y as Float,
angle as Float,
length as Float,
handType as IHands.HandType) {
var rad = (angle - 90) * Math.PI / 180.0;
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_WHITE);
dc.drawLine(x, y, x + length * Math.cos(rad), y + length * Math.sin(rad));
}
}

11
source/Utils.mc Normal file
View File

@ -0,0 +1,11 @@
import Toybox.Lang;
typedef Numeric as Number or Float or Long or Double;
function min(left as Numeric, right as Numeric) as Numeric {
if (left < right) {
return left;
} else {
return right;
}
}

33
source/wfApp.mc Normal file
View File

@ -0,0 +1,33 @@
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
class wfApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
}
// onStop() is called when your application is exiting
function onStop(state as Dictionary?) as Void {
}
// Return the initial view of your application here
function getInitialView() as [Views] or [Views, InputDelegates] {
return [ new wfView() ];
}
// New app settings have been received so trigger a UI update
function onSettingsChanged() as Void {
WatchUi.requestUpdate();
}
}
function getApp() as wfApp {
return Application.getApp() as wfApp;
}

22
source/wfBackground.mc Normal file
View File

@ -0,0 +1,22 @@
import Toybox.Application;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class Background extends WatchUi.Drawable {
function initialize() {
var dictionary = {
:identifier => "Background"
};
Drawable.initialize(dictionary);
}
function draw(dc as Dc) as Void {
// Set the background color then call to clear the screen
dc.setColor(Graphics.COLOR_TRANSPARENT, getApp().getProperty("BackgroundColor") as Number);
dc.clear();
}
}

73
source/wfView.mc Normal file
View File

@ -0,0 +1,73 @@
import Toybox.Application;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class wfView extends WatchUi.WatchFace {
private var hands as IHands?;
function initialize() {
WatchFace.initialize();
hands = new SimpleHands({});
}
// Load your resources here
function onLayout(dc as Dc) as Void {
setLayout(Rez.Layouts.WatchFace(dc));
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() as Void {
}
// Update the view
// function onUpdate(dc as Dc) as Void {
// // Get the current time and format it correctly
// var timeFormat = "$1$:$2$";
// var clockTime = System.getClockTime();
// var hours = clockTime.hour;
// if (!System.getDeviceSettings().is24Hour) {
// if (hours > 12) {
// hours = hours - 12;
// }
// } else {
// if (Application.Properties.getValue("UseMilitaryFormat")) {
// timeFormat = "$1$$2$";
// hours = hours.format("%02d");
// }
// }
// var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);
// // Update the view
// var view = View.findDrawableById("TimeLabel") as Text;
// view.setColor(Application.Properties.getValue("ForegroundColor") as Number);
// view.setText(timeString);
// // Call the parent onUpdate function to redraw the layout
// View.onUpdate(dc);
// }
function onUpdate(dc as Dc) as Void {
dc.clear();
dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
hands.draw(dc);
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() as Void {
}
// The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() as Void {
}
// Terminate any active timers and prepare for slow updates.
function onEnterSleep() as Void {
}
}