1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { hideFloatWindow } from '../common/ui/floatwindow/utils/FloatWindowUtils' 16import { FloatWindowComponent } from '../common/FloatWindowComponent' 17 18@Entry 19@Component 20struct FpsLineChartPage { 21 data: number[]= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] //数据集合 22 @State random: number= 0 //用于刷新的随机数 23 @State LineFps: number= 0 //数值 24 25 offsetX: number = -1 //悬浮框移动触摸点 X 26 offsetY: number = -1 //悬浮框移动触摸点 X 27 private floatName: string= "FPS" 28 task_state = 1 29 30 aboutToAppear() { 31 globalThis.LineChartCollect = setInterval(() => { 32 if (this.data.length >= 22) { 33 console.log("GestureEvent--------------shift:" + this.data); 34 this.data.shift() //移除第一个元素 35 } 36 if (globalThis.timerFps == undefined) { 37 this.LineFps = 0 38 this.data.push(0) //在末尾填充一个元素 39 } else { 40 this.LineFps = globalThis.timerFps 41 if(this.LineFps==0){ 42 this.data.push(0) 43 }else{ 44 let lineCount: number = this.LineFps / 1.5 45 this.data.push(lineCount)//在末尾填充一个元素 46 } 47 } 48 49 }, 1000) 50 } 51 52 build() { 53 Stack({ alignContent: Alignment.Top }) { 54 FloatWindowComponent({ title: `sp_FPS`, data: this.data }) 55 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 56 Text(this.floatName + ":" ) 57 .fontSize('10fp') 58 .fontColor($r("app.color.color_fff")) 59 .margin({ left: 5, top: 1 }) //文本显示 60 Text( this.LineFps + "fps") 61 .fontSize('20fp') 62 .fontColor('#FF0000') 63 .fontWeight(5) 64 .margin({ left: 1,top: 1 }) //文本显示 65 Text(this.random + "") 66 .fontSize('1fp') 67 .fontColor($r("app.color.color_fff")).visibility(Visibility.None) 68 Image($r("app.media.icon_close_small")).width('15vp').height('15vp').onClick(() => { 69 hideFloatWindow("sp_FPS") 70 console.log("hideFloatWindow---------------------" + this.floatName) 71 }).align(Alignment.TopEnd) 72 }.height('25vp').width('100%') 73 74 } 75 76 } 77}