CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/UI/JoystickHistoryView.cpp
Views: 1401
#include <algorithm>12#include "UI/JoystickHistoryView.h"34#include "Common/UI/Context.h"5#include "Common/UI/UI.h"67#include "Core/ControlMapper.h"89void JoystickHistoryView::Draw(UIContext &dc) {10const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(ImageID("I_CROSS"));11if (!image) {12return;13}14float minRadius = std::min(bounds_.w, bounds_.h) * 0.5f - image->w;15dc.Begin();16Bounds textBounds(bounds_.x, bounds_.centerY() + minRadius + 5.0, bounds_.w, bounds_.h / 2 - minRadius - 5.0);17dc.DrawTextShadowRect(title_, textBounds, 0xFFFFFFFF, ALIGN_TOP | ALIGN_HCENTER | FLAG_WRAP_TEXT);18dc.Flush();19dc.BeginNoTex();20dc.Draw()->RectOutline(bounds_.centerX() - minRadius, bounds_.centerY() - minRadius, minRadius * 2.0f, minRadius * 2.0f, 0x80FFFFFF);21dc.Flush();22dc.Begin();2324// First draw a grid.25float dx = 1.0f / 10.0f;26for (int ix = -10; ix <= 10; ix++) {27// First draw vertical lines.28float fx = ix * dx;29for (int iy = -10; iy < 10; iy++) {30float ax = fx;31float ay = iy * dx;32float bx = fx;33float by = (iy + 1) * dx;3435if (type_ == StickHistoryViewType::OUTPUT) {36ConvertAnalogStick(ax, ay, &ax, &ay);37ConvertAnalogStick(bx, by, &bx, &by);38}3940ax = ax * minRadius + bounds_.centerX();41ay = ay * minRadius + bounds_.centerY();4243bx = bx * minRadius + bounds_.centerX();44by = by * minRadius + bounds_.centerY();4546dc.Draw()->Line(dc.theme->whiteImage, ax, ay, bx, by, 1.0, 0x70FFFFFF);47}48}4950for (int iy = -10; iy <= 10; iy++) {51// Then horizontal.52float fy = iy * dx;53for (int ix = -10; ix < 10; ix++) {54float ax = ix * dx;55float ay = fy;56float bx = (ix + 1) * dx;57float by = fy;5859if (type_ == StickHistoryViewType::OUTPUT) {60ConvertAnalogStick(ax, ay, &ax, &ay);61ConvertAnalogStick(bx, by, &bx, &by);62}6364ax = ax * minRadius + bounds_.centerX();65ay = ay * minRadius + bounds_.centerY();6667bx = bx * minRadius + bounds_.centerX();68by = by * minRadius + bounds_.centerY();6970dc.Draw()->Line(dc.theme->whiteImage, ax, ay, bx, by, 1.0, 0x70FFFFFF);71}72}737475int a = maxCount_ - (int)locations_.size();76for (auto iter = locations_.begin(); iter != locations_.end(); ++iter) {77float x = bounds_.centerX() + minRadius * iter->x;78float y = bounds_.centerY() - minRadius * iter->y;79float alpha = (float)a / (float)(maxCount_ - 1);80if (alpha < 0.0f) {81alpha = 0.0f;82}83// Emphasize the newest (higher) ones.84alpha = powf(alpha, 3.7f);85// Highlight the output (and OTHER)86if (alpha >= 1.0f && type_ != StickHistoryViewType::INPUT) {87dc.Draw()->DrawImage(ImageID("I_CIRCLE"), x, y, 1.0f, colorAlpha(0xFFFFFF, 1.0), ALIGN_CENTER);88} else {89dc.Draw()->DrawImage(ImageID("I_CIRCLE"), x, y, 0.8f, colorAlpha(0xC0C0C0, alpha * 0.5f), ALIGN_CENTER);90}91a++;92}93dc.Flush();94}9596void JoystickHistoryView::Update() {97locations_.push_back(Location{ curX_, curY_ });98if ((int)locations_.size() > maxCount_) {99locations_.pop_front();100}101}102103104