简化全局窗口尺寸变量名

This commit is contained in:
JackLee 2026-03-28 16:23:52 +08:00
parent 050403d971
commit 3153a0f43f
15 changed files with 97 additions and 81 deletions

View File

@ -229,9 +229,22 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *comp, void *win) {
}
auto renderThread = it->second;
float curtX,curtY;
//HILOG_WARN(NATIVE_TAG, "ALLButton:%{public}d",mouseEvent.button);
//HILOG_WARN(NATIVE_TAG, "ALLAction:%{public}d",mouseEvent.action);
//HILOG_WARN(NATIVE_TAG, "ALLTimestamp:%{public}d",mouseEvent.timestamp);
//开发测试模拟器输出鼠标按钮和时间类型,时间戳
bool _log=true;
if(_log){
HILOG_INFO(NATIVE_TAG, "ALLButton:%{public}d",mouseEvent.button);
HILOG_INFO(NATIVE_TAG, "ALLAction:%{public}d",mouseEvent.action);
HILOG_INFO(NATIVE_TAG, "ALLTimestamp:%{public}d",mouseEvent.timestamp);
}
//以下代码为采用按住鼠标右键不放进行Move改变Carmera的旋转视角
//旋转视角分为三种模式:
//自由模式.基于世界坐标系0,0,0
//模型中心.通过边界盒计算模型的中心点,进行旋转
//基于鼠标按下右键点进行旋转
//按住Ctrl不放同时按住鼠标左键不放进行Carmera的移动
//移动模式:均为鼠标点按下后记录坐标增量移动
//鼠标按下并且事件为鼠标中键

View File

@ -34,17 +34,17 @@ export default class EntryAbility extends UIAbility {
const mainWindowHeight: number = screenHeight - 200;
console.error(`main window Width: mainWindowWidth, Height: mainWindowHeight`);
//Init&&Save AppStorageV2
const mainDisplayInfo =
const mDispInfo =
AppStorageV2.connect<MainScreenDisplayInfo>(MainScreenDisplayInfo, () => new MainScreenDisplayInfo())!;
const mainWinInfo = AppStorageV2.connect<MainWindowInfo>(MainWindowInfo, () => new MainWindowInfo())!;
const mainWinStage =
const mWinInfo = AppStorageV2.connect<MainWindowInfo>(MainWindowInfo, () => new MainWindowInfo())!;
const mWinStage =
AppStorageV2.connect<MainWindowStageInfo>(MainWindowStageInfo, () => new MainWindowStageInfo())!;
mainDisplayInfo.mainScreenDisplayId = screenDisplayId;
mainDisplayInfo.mainScreenWidth = screenWidth;
mainDisplayInfo.mainScreenHeight = screenHeight;
mainWinInfo.mainWindowWidth = mainWindowWidth;
mainWinInfo.mainWindowHeight = mainWindowHeight;
mainWinStage.ws = windowStage;
mDispInfo.mSDispId = screenDisplayId;
mDispInfo.mSDispWidth = screenWidth;
mDispInfo.mSDispHeight = screenHeight;
mWinInfo.mWinWidth = mainWindowWidth;
mWinInfo.mWinHeight = mainWindowHeight;
mWinStage.mWinStage = windowStage;
//Get Main Window
windowStage.getMainWindow((err, data) => {
@ -53,6 +53,7 @@ export default class EntryAbility extends UIAbility {
return;
}
this.mainWindow = data;
mWinInfo.mWinId = this.mainWindow.getWindowProperties().id;
//moveWindowTo
this.mainWindow.moveWindowTo(50, 50)
//resize mainWindow Size
@ -67,8 +68,8 @@ export default class EntryAbility extends UIAbility {
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
this.mainWindow.on('windowSizeChange', (ListenerData) => {
// if Size Change save to AppStorage
mainWinInfo.mainWindowWidth = ListenerData.width;
mainWinInfo.mainWindowHeight = ListenerData.height;
mWinInfo.mWinWidth = ListenerData.width;
mWinInfo.mWinHeight = ListenerData.height;
console.info('Succeeded in enabling the listener for window size changes. Data:' + ListenerData.width,
ListenerData.height);
});

View File

@ -4,34 +4,37 @@ import { AppStorageV2, window} from '@kit.ArkUI';
//底部有全局信息变量,已导出,其他page只需要import该文件即可调用let变量
@ObservedV2
export class MainScreenDisplayInfo {
@Trace public mainScreenDisplayId: number;
@Trace public mainScreenWidth: number;
@Trace public mainScreenHeight: number;
@Trace public mSDispId: number;
@Trace public mSDispWidth: number;
@Trace public mSDispHeight: number;
constructor(_id?: number, _width?: number,_height?: number) {
this.mainScreenDisplayId = _id ?? 0;
this.mainScreenWidth = _width ?? 0;
this.mainScreenHeight = _height ?? 0;
this.mSDispId = _id ?? 0;
this.mSDispWidth = _width ?? 0;
this.mSDispHeight = _height ?? 0;
}
}
@ObservedV2
export class MainWindowInfo {
@Trace public mainWindowWidth: number;
@Trace public mainWindowHeight: number;
@Trace public mWinId: number;
@Trace public mWinWidth: number;
@Trace public mWinHeight: number;
constructor(_width?: number, _height?: number) {
this.mainWindowWidth = _width ?? 0;
this.mainWindowHeight = _height ?? 0;
constructor(_id?:number,_width?: number, _height?: number) {
this.mWinWidth = _width ?? 0;
this.mWinHeight = _height ?? 0;
this.mWinId=_id?? 0;
}
}
@ObservedV2
export class MainWindowStageInfo {
@Trace public ws: window.WindowStage| undefined;
@Trace public mWinStage: window.WindowStage| undefined;
constructor(_ws?: window.WindowStage) {
this.ws = _ws ?? undefined;
this.mWinStage = _ws ?? undefined;
}
}
//全局保存主窗口信息,屏幕信息.窗口管理器信息

View File

@ -6,10 +6,10 @@ import { TitleTabData } from '../LayoutInterface/Layout/TitleTabData';
import { mwInfo } from '../AppStorageV2Class';
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.02;
let ebHeigth=mwInfo.mainWindowWidth*0.02;
let ebWidth=mwInfo.mWinWidth*0.02;
let ebHeigth=mwInfo.mWinWidth*0.02;
//占位符的高度
let edHeigth=mwInfo.mainWindowWidth*0.005
let edHeigth=mwInfo.mWinWidth*0.005
//单一功能按钮
@ -180,15 +180,15 @@ export struct SubColumnMenu {
Button(){
Row(){
Image($r('app.media.'+(this.icon!=undefined ? this.icon:(this.menus[this.curtIndex]as TitleButton).eIcon)))
.height(mwInfo.mainWindowWidth*0.01)
.height(mwInfo.mWinWidth*0.01)
if(this.name!=undefined){
Text(this.name).fontSize(16)
}
}
}.height(mwInfo.mainWindowWidth*0.01)
}.height(mwInfo.mWinWidth*0.01)
.backgroundColor(Color.Transparent)
.bindMenu(this.BaseMenu)
.type(ButtonType.Normal)
}.width(this.name!=undefined ?mwInfo.mainWindowWidth*0.02:mwInfo.mainWindowWidth*0.01)
}.width(this.name!=undefined ?mwInfo.mWinWidth*0.02:mwInfo.mWinWidth*0.01)
}
}

View File

@ -2,10 +2,10 @@ import { mwInfo } from "../AppStorageV2Class";
import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface";
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.075;
let ebHeigth=mwInfo.mainWindowHeight*0.03;
let ebWidth=mwInfo.mWinWidth*0.075;
let ebHeigth=mwInfo.mWinHeight*0.03;
//占位符的高度
let edHeigth=mwInfo.mainWindowWidth*0.005
let edHeigth=mwInfo.mWinWidth*0.005
@ComponentV2
export struct TextComboBox {
@ -34,10 +34,10 @@ export struct TextComboBox {
.width('50%')
.fontSize(16)
.backgroundColor('#ffe6e6e3')
.height(mwInfo.mainWindowHeight*0.02)
.height(mwInfo.mWinHeight*0.02)
.margin({ top:0, left: 5, bottom: 0, right: 0 })
}.width(ebWidth)
.height(mwInfo.mainWindowWidth*0.01)
.height(mwInfo.mWinWidth*0.01)
}
}
@ComponentV2
@ -61,6 +61,6 @@ export struct TextInputComboBox {
TextInput({placeholder:this.selectIndex.toString()})
.bindMenu(this.EventMenu)
.type(InputType.Number)
}.height(mwInfo.mainWindowWidth*0.01)
}.height(mwInfo.mWinWidth*0.01)
}
}

View File

@ -4,8 +4,8 @@ import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface";
import {SwitchView} from "../LayoutInterface/Layout/SwitchView"
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.02;
let ebHeigth=mwInfo.mainWindowWidth*0.02;
let ebWidth=mwInfo.mWinWidth*0.02;
let ebHeigth=mwInfo.mWinWidth*0.02;
//视图切换弹窗
@CustomDialog
export struct ViewDialog {

View File

@ -6,8 +6,8 @@ import { BaseMenuData } from "../LayoutInterface/Interface/MenuInterface";
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.02;
let ebHeigth=mwInfo.mainWindowWidth*0.02;
let ebWidth=mwInfo.mWinWidth*0.02;
let ebHeigth=mwInfo.mWinWidth*0.02;
@Builder
export function BaseMenu(indexMenu:BaseMenuData) {
@ -66,8 +66,8 @@ export struct GroupTextEventMenu {
.fontColor(Color.Gray)
Blank().width('auto')
Button()
.height(mwInfo.mainWindowWidth*0.005)
.width(mwInfo.mainWindowWidth*0.005)
.height(mwInfo.mWinWidth*0.005)
.width(mwInfo.mWinWidth*0.005)
.padding(1)
.backgroundImage($r('app.media.base_seetings'))
.backgroundImagePosition({ x: '5%', y: '5%' })

View File

@ -5,18 +5,20 @@ import NativeOpenCAX from 'libopencax.so';
import { mwInfo } from '../AppStorageV2Class';
export function ExecuteCommand(event:TitleButton){
//事件处理
if(event?.eEvent=='Execute_LoadModel'){
OCCTLoadModel(undefined,undefined)
}
//窗体打开
if(event?.eEvent=='Execute_CreateSubWindow'){
const winInfo:WinInfo=new WinInfo(event.eName,event.ePage,mwInfo.mainWindowWidth*0.3,mwInfo.mainWindowHeight*0.9);
CreateAndShowSubWindow(winInfo);
const winInfo:WinInfo=new WinInfo(event.eName,event.ePage,mwInfo.mWinWidth*0.3,mwInfo.mWinHeight*0.9);
//CreateAndShowSubWindow(winInfo);
}else if(event?.eEvent=='Execute_ExitSubWindow'){
CloseSubWindow();
} else if(event?.eEvent=='Execute_CreateSubWindow_Options'){
const winInfo:WinInfo=new WinInfo(event.eName,event.ePage,mwInfo.mainWindowWidth*0.6,mwInfo.mainWindowHeight*0.9);
const winInfo:WinInfo=new WinInfo(event.eName,event.ePage,mwInfo.mWinWidth*0.6,mwInfo.mWinHeight*0.9);
CreateAndShowSubWindow(winInfo);
}else if(event?.eEvent=='Execute_ExitSubWindow_Options'){
CloseSubWindow();

View File

@ -19,7 +19,7 @@ export class WinInfo{
export async function CreateAndShowSubWindow(winInfo:WinInfo) {
try {
if(mwsInfo.ws==null){
if(mwsInfo.mWinStage==null){
console.error('Failed to create the subwindow. Cause: windowStage is null');
return;
}
@ -28,15 +28,11 @@ export async function CreateAndShowSubWindow(winInfo:WinInfo) {
decorEnabled: true,
isModal: false,
maximizeSupported: false,
zLevel:-1,
outlineEnabled:true,
};
await mwsInfo.ws.createSubWindowWithOptions('subWindow', options).then((data) => {
await mwsInfo.mWinStage.createSubWindowWithOptions('subWindow', options).then((data) => {
subWindow = data;
subWindow.setResizeByDragEnabled(true, (err: BusinessError) => {
console.log("设置拖拽缩放", `报错信息:${err.code}, ${err.message}`)
})
//子窗口创建成功后,设置子窗口的位置、大小及相关属性等。
subWindow.moveWindowTo(25, 25)
//子窗口重置大小

View File

@ -24,7 +24,7 @@ let Fonts: Array<string> = [
struct Index {
@Local startX:number=0;
@Local isDragging:boolean=false;
@Provider('panelWidth') panelWidth:number=mwInfo.mainWindowWidth * 0.15;
@Provider('panelWidth') panelWidth:number=mwInfo.mWinWidth * 0.15;
//列出资源管理器指定目录下的所有问题件
HilogToDirFile(){
@ -108,7 +108,7 @@ struct Index {
Column({ space: 0 }) {
//头部导航功能区
TitleTab()
.height(mwInfo.mainWindowHeight * 0.08)
.height(mwInfo.mWinHeight * 0.08)
//分割线
Divider().vertical(false).strokeWidth(1).lineCap(LineCapStyle.Round).width('100%').backgroundColor(Color.Grey)
//工具栏
@ -116,7 +116,7 @@ struct Index {
TitleColumnSub();
}
.width('100%')
.height(mwInfo.mainWindowHeight * 0.02)
.height(mwInfo.mWinHeight * 0.02)
.align(Alignment.Start)
//分割线
Divider().vertical(false).strokeWidth(1).lineCap(LineCapStyle.Round).width('100%').backgroundColor(Color.Grey)
@ -147,7 +147,7 @@ struct Index {
}.layoutWeight(1)
.align(Alignment.Center)
}.width('100%')
.height(mwInfo.mainWindowHeight * 0.39)
.height(mwInfo.mWinHeight * 0.39)
//分割线
Divider().vertical(false).strokeWidth(1).lineCap(LineCapStyle.Round).width('100%').backgroundColor(Color.Grey)
///状态栏
@ -156,7 +156,7 @@ struct Index {
}.width('100%')
.align(Alignment.End)
.alignItems(HorizontalAlign.Start)
.height(mwInfo.mainWindowHeight * 0.01)
.height(mwInfo.mWinHeight * 0.01)
}.backgroundColor('#f3f3f0')
.width('100%')
.height('100%')

View File

@ -7,7 +7,7 @@ export struct LeftSideTab {
private leftSideBarTabs: TabsController = new TabsController();
@Local leftSideBarFocusIndex: number = 0;
@Local isExpanded:boolean=true;
@Consumer('panelWidth') panelWidth:number=mwInfo.mainWindowWidth * 0.1;
@Consumer('panelWidth') panelWidth:number=mwInfo.mWinWidth * 0.1;
build() {
Row() {
@ -24,12 +24,12 @@ export struct LeftSideTab {
})
.backgroundImage(this.isExpanded ? $r('app.media.base_expand_on'):$r('app.media.base_expand_off'))
.type(ButtonType.Normal)
.width(mwInfo.mainWindowWidth*0.013)
.height(mwInfo.mainWindowWidth*0.013)
.width(mwInfo.mWinWidth*0.013)
.height(mwInfo.mWinWidth*0.013)
.onClick(()=>{
this.isExpanded = !this.isExpanded;
if(this.isExpanded){
this.panelWidth=mwInfo.mainWindowWidth * 0.1;
this.panelWidth=mwInfo.mWinWidth * 0.1;
}else{
this.panelWidth=0;
}
@ -50,8 +50,8 @@ export struct LeftSideTab {
})
.backgroundImage($r('app.media.'+item.eIcon))
.fontWeight(index === this.leftSideBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.width(mwInfo.mainWindowWidth*0.013)
.height(mwInfo.mainWindowWidth*0.013)
.width(mwInfo.mWinWidth*0.013)
.height(mwInfo.mWinWidth*0.013)
.type(ButtonType.Normal)
.onClick(() => {
this.leftSideBarTabs.changeIndex(index);
@ -64,8 +64,8 @@ export struct LeftSideTab {
.align(Alignment.Start)
.scrollable(ScrollDirection.Vertical)
.scrollBar(BarState.Off)
.width(mwInfo.mainWindowWidth*0.013)
.height(mwInfo.mainWindowWidth*0.013)
.width(mwInfo.mWinWidth*0.013)
.height(mwInfo.mWinWidth*0.013)
.height('100%')
}.borderWidth(1)
.borderColor(Color.Grey)

View File

@ -22,8 +22,8 @@ export struct TitleColumnSub {
private ViewDialog(): CustomDialogController {
return new CustomDialogController({
builder: ViewDialog(), // 确保 ViewDialog 组件已正确定义
width: mwInfo.mainWindowWidth*0.06,
height: mwInfo.mainWindowWidth*0.052,
width: mwInfo.mWinWidth*0.06,
height: mwInfo.mWinWidth*0.052,
borderWidth: 1,
cornerRadius: 5,
isModal: true,
@ -52,8 +52,8 @@ export struct TitleColumnSub {
this.viewDialog=this.ViewDialog();
}
this.viewDialog.open();
}).width(mwInfo.mainWindowWidth*0.01)
.height(mwInfo.mainWindowWidth*0.01)
}).width(mwInfo.mWinWidth*0.01)
.height(mwInfo.mWinWidth*0.01)
.backgroundColor(Color.Transparent)
.backgroundImage($r('app.media.' + SwitchView[0].eIcon))
.backgroundImageSize({

View File

@ -25,8 +25,8 @@ export struct TitleTab {
Button((FileMenuData.aMenus[0] as TitleButton).eName)
.fontSize(16)
.fontColor(Color.Black)
.height(mwInfo.mainWindowHeight*0.025)
.width(mwInfo.mainWindowWidth*0.035)
.height(mwInfo.mWinHeight*0.025)
.width(mwInfo.mWinWidth*0.035)
.bindMenu(BaseMenu(FileMenuData))
.type(ButtonType.Normal)
.backgroundColor('#f3f3f0')
@ -36,8 +36,8 @@ export struct TitleTab {
.fontSize(16)
.fontColor(Color.Black)
.fontWeight(index === this.titleBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.height(mwInfo.mainWindowHeight*0.025)
.width(mwInfo.mainWindowWidth*0.035)
.height(mwInfo.mWinHeight*0.025)
.width(mwInfo.mWinWidth*0.035)
.type(ButtonType.Normal)
.backgroundColor('#f3f3f0')
.onClick(() => {
@ -69,6 +69,6 @@ export struct TitleTab {
}.scrollable(true)
.barHeight(0)
.barMode(BarMode.Fixed)
}.width(mwInfo.mainWindowWidth)
}.width(mwInfo.mWinWidth)
}
}

View File

@ -28,18 +28,18 @@ export struct ModelViewTab {
ForEach(dTab, (item: TaskTab, index: number) => {
Row({ space: 0 }) {
Image($r('app.media.startIcon'))
.width(this.mwInfo.mainWindowWidth*0.012)
.height(this.mwInfo.mainWindowWidth*0.012)
.width(this.mwInfo.mWinWidth*0.012)
.height(this.mwInfo.mWinWidth*0.012)
.objectFit(ImageFit.Contain)
Button(item.str)
.fontWeight(index === this.modelViewBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.width('auto')
.height(this.mwInfo.mainWindowWidth*0.012)
.height(this.mwInfo.mWinWidth*0.012)
.type(ButtonType.Normal)
Button('X')
.fontSize(12)
.width(this.mwInfo.mainWindowWidth*0.012)
.height(this.mwInfo.mainWindowWidth*0.012)
.width(this.mwInfo.mWinWidth*0.012)
.height(this.mwInfo.mWinWidth*0.012)
.type(ButtonType.Normal)
.align(Alignment.Center)
}.onClick(() => {

View File

@ -27,6 +27,7 @@
"minWindowWidth": 1200, // 设置最小宽度
"minWindowHeight": 800, // 设置最小高度
"exported": true,
"launchType":"multiton",
"skills": [
{
"entities": [